LCOV - code coverage report
Current view: top level - gfx/skia/skia/src/core - SkDocument.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 46 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright 2013 Google Inc.
       3             :  *
       4             :  * Use of this source code is governed by a BSD-style license that can be
       5             :  * found in the LICENSE file.
       6             :  */
       7             : 
       8             : #include "SkDocument.h"
       9             : #include "SkStream.h"
      10             : 
      11           0 : SkDocument::SkDocument(SkWStream* stream, void (*doneProc)(SkWStream*, bool)) {
      12           0 :     fStream = stream;   // we do not own this object.
      13           0 :     fDoneProc = doneProc;
      14           0 :     fState = kBetweenPages_State;
      15           0 : }
      16             : 
      17           0 : SkDocument::~SkDocument() {
      18           0 :     this->close();
      19           0 : }
      20             : 
      21           0 : SkCanvas* SkDocument::beginPage(SkScalar width, SkScalar height,
      22             :                                 const SkRect* content) {
      23           0 :     if (width <= 0 || height <= 0) {
      24           0 :         return nullptr;
      25             :     }
      26             : 
      27           0 :     SkRect outer = SkRect::MakeWH(width, height);
      28             :     SkRect inner;
      29           0 :     if (content) {
      30           0 :         inner = *content;
      31           0 :         if (!inner.intersect(outer)) {
      32           0 :             return nullptr;
      33             :         }
      34             :     } else {
      35           0 :         inner = outer;
      36             :     }
      37             : 
      38             :     for (;;) {
      39           0 :         switch (fState) {
      40             :             case kBetweenPages_State:
      41           0 :                 fState = kInPage_State;
      42           0 :                 return this->onBeginPage(width, height, inner);
      43             :             case kInPage_State:
      44           0 :                 this->endPage();
      45           0 :                 break;
      46             :             case kClosed_State:
      47           0 :                 return nullptr;
      48             :         }
      49             :     }
      50             :     SkDEBUGFAIL("never get here");
      51             :     return nullptr;
      52             : }
      53             : 
      54           0 : void SkDocument::endPage() {
      55           0 :     if (kInPage_State == fState) {
      56           0 :         fState = kBetweenPages_State;
      57           0 :         this->onEndPage();
      58             :     }
      59           0 : }
      60             : 
      61           0 : void SkDocument::close() {
      62             :     for (;;) {
      63           0 :         switch (fState) {
      64             :             case kBetweenPages_State: {
      65           0 :                 fState = kClosed_State;
      66           0 :                 this->onClose(fStream);
      67             : 
      68           0 :                 if (fDoneProc) {
      69           0 :                     fDoneProc(fStream, false);
      70             :                 }
      71             :                 // we don't own the stream, but we mark it nullptr since we can
      72             :                 // no longer write to it.
      73           0 :                 fStream = nullptr;
      74           0 :                 return;
      75             :             }
      76             :             case kInPage_State:
      77           0 :                 this->endPage();
      78           0 :                 break;
      79             :             case kClosed_State:
      80           0 :                 return;
      81             :         }
      82             :     }
      83             : }
      84             : 
      85           0 : void SkDocument::abort() {
      86           0 :     this->onAbort();
      87             : 
      88           0 :     fState = kClosed_State;
      89           0 :     if (fDoneProc) {
      90           0 :         fDoneProc(fStream, true);
      91             :     }
      92             :     // we don't own the stream, but we mark it nullptr since we can
      93             :     // no longer write to it.
      94           0 :     fStream = nullptr;
      95           0 : }

Generated by: LCOV version 1.13