OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkDocument.h" | 8 #include "SkDocument.h" |
9 #include "SkStream.h" | 9 #include "SkStream.h" |
10 | 10 |
11 SK_DEFINE_INST_COUNT(SkDocument) | 11 SK_DEFINE_INST_COUNT(SkDocument) |
12 | 12 |
13 SkDocument::SkDocument(SkWStream* stream, void (*doneProc)(SkWStream*)) { | 13 SkDocument::SkDocument(SkWStream* stream, void (*doneProc)(SkWStream*, bool)) { |
14 fStream = stream; // we do not own this object. | 14 fStream = stream; // we do not own this object. |
15 fDoneProc = doneProc; | 15 fDoneProc = doneProc; |
16 fState = kBetweenPages_State; | 16 fState = kBetweenPages_State; |
17 } | 17 } |
18 | 18 |
19 SkDocument::~SkDocument() { | 19 SkDocument::~SkDocument() { |
20 this->close(); | 20 this->close(); |
21 } | 21 } |
22 | 22 |
23 SkCanvas* SkDocument::beginPage(SkScalar width, SkScalar height, | 23 SkCanvas* SkDocument::beginPage(SkScalar width, SkScalar height, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } | 61 } |
62 | 62 |
63 bool SkDocument::close() { | 63 bool SkDocument::close() { |
64 for (;;) { | 64 for (;;) { |
65 switch (fState) { | 65 switch (fState) { |
66 case kBetweenPages_State: { | 66 case kBetweenPages_State: { |
67 fState = kClosed_State; | 67 fState = kClosed_State; |
68 bool success = this->onClose(fStream); | 68 bool success = this->onClose(fStream); |
69 | 69 |
70 if (fDoneProc) { | 70 if (fDoneProc) { |
71 fDoneProc(fStream); | 71 fDoneProc(fStream, false); |
72 } | 72 } |
73 // we don't own the stream, but we mark it NULL since we can | 73 // we don't own the stream, but we mark it NULL since we can |
74 // no longer write to it. | 74 // no longer write to it. |
75 fStream = NULL; | 75 fStream = NULL; |
76 return success; | 76 return success; |
77 } | 77 } |
78 case kInPage_State: | 78 case kInPage_State: |
79 this->endPage(); | 79 this->endPage(); |
80 break; | 80 break; |
81 case kClosed_State: | 81 case kClosed_State: |
82 return false; | 82 return false; |
83 } | 83 } |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 void SkDocument::abort() { | 87 void SkDocument::abort() { |
| 88 this->onAbort(); |
| 89 |
88 fState = kClosed_State; | 90 fState = kClosed_State; |
| 91 if (fDoneProc) { |
| 92 fDoneProc(fStream, true); |
| 93 } |
| 94 // we don't own the stream, but we mark it NULL since we can |
| 95 // no longer write to it. |
| 96 fStream = NULL; |
89 } | 97 } |
OLD | NEW |