Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: src/core/SkPicture.cpp

Issue 283333007: Add choke point for performing a fake endRecording (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkPicture.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2007 The Android Open Source Project 3 * Copyright 2007 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkPictureFlat.h" 10 #include "SkPictureFlat.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 /////////////////////////////////////////////////////////////////////////////// 124 ///////////////////////////////////////////////////////////////////////////////
125 125
126 SkPicture::SkPicture() 126 SkPicture::SkPicture()
127 : fAccelData(NULL) { 127 : fAccelData(NULL) {
128 this->needsNewGenID(); 128 this->needsNewGenID();
129 fRecord = NULL; 129 fRecord = NULL;
130 fPlayback = NULL; 130 fPlayback = NULL;
131 fWidth = fHeight = 0; 131 fWidth = fHeight = 0;
132 } 132 }
133 133
134 // This method makes a SkPicturePlayback object from an in-progress recording.
135 // Unfortunately, it does not include the restoreToCount of a real endRecording
136 // call.
137 SkPicturePlayback* SkPicture::FakeEndRecording(const SkPicture* resourceSrc,
138 const SkPictureRecord& record,
139 bool deepCopy) {
140 SkPictInfo info;
141 resourceSrc->createHeader(&info);
142 return SkNEW_ARGS(SkPicturePlayback, (resourceSrc, record, info, deepCopy));
143 }
144
134 SkPicture::SkPicture(const SkPicture& src) 145 SkPicture::SkPicture(const SkPicture& src)
135 : INHERITED() 146 : INHERITED()
136 , fAccelData(NULL) 147 , fAccelData(NULL)
137 , fContentInfo(src.fContentInfo) { 148 , fContentInfo(src.fContentInfo) {
138 this->needsNewGenID(); 149 this->needsNewGenID();
139 fWidth = src.fWidth; 150 fWidth = src.fWidth;
140 fHeight = src.fHeight; 151 fHeight = src.fHeight;
141 fRecord = NULL; 152 fRecord = NULL;
142 153
143 /* We want to copy the src's playback. However, if that hasn't been built 154 /* We want to copy the src's playback. However, if that hasn't been built
144 yet, we need to fake a call to endRecording() without actually calling 155 yet, we need to fake a call to endRecording() without actually calling
145 it (since it is destructive, and we don't want to change src). 156 it (since it is destructive, and we don't want to change src).
146 */ 157 */
147 if (src.fPlayback) { 158 if (src.fPlayback) {
148 fPlayback = SkNEW_ARGS(SkPicturePlayback, (this, *src.fPlayback)); 159 fPlayback = SkNEW_ARGS(SkPicturePlayback, (this, *src.fPlayback));
149 SkASSERT(NULL == src.fRecord); 160 SkASSERT(NULL == src.fRecord);
150 fUniqueID = src.uniqueID(); // need to call method to ensure != 0 161 fUniqueID = src.uniqueID(); // need to call method to ensure != 0
151 } else if (src.fRecord) { 162 } else if (src.fRecord) {
152 SkPictInfo info; 163 fPlayback = FakeEndRecording(this, *src.fRecord, false);
153 this->createHeader(&info);
154 // here we do a fake src.endRecording()
155 fPlayback = SkNEW_ARGS(SkPicturePlayback, (this, *src.fRecord, info));
156 } else { 164 } else {
157 fPlayback = NULL; 165 fPlayback = NULL;
158 } 166 }
159 167
160 fPathHeap.reset(SkSafeRef(src.fPathHeap.get())); 168 fPathHeap.reset(SkSafeRef(src.fPathHeap.get()));
161 } 169 }
162 170
163 const SkPath& SkPicture::getPath(int index) const { 171 const SkPath& SkPicture::getPath(int index) const {
164 return (*fPathHeap.get())[index]; 172 return (*fPathHeap.get())[index];
165 } 173 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 221 }
214 222
215 SkPicture* SkPicture::clone() const { 223 SkPicture* SkPicture::clone() const {
216 SkPicture* clonedPicture = SkNEW(SkPicture); 224 SkPicture* clonedPicture = SkNEW(SkPicture);
217 this->clone(clonedPicture, 1); 225 this->clone(clonedPicture, 1);
218 return clonedPicture; 226 return clonedPicture;
219 } 227 }
220 228
221 void SkPicture::clone(SkPicture* pictures, int count) const { 229 void SkPicture::clone(SkPicture* pictures, int count) const {
222 SkPictCopyInfo copyInfo; 230 SkPictCopyInfo copyInfo;
223 SkPictInfo info;
224 this->createHeader(&info);
225 231
226 for (int i = 0; i < count; i++) { 232 for (int i = 0; i < count; i++) {
227 SkPicture* clone = &pictures[i]; 233 SkPicture* clone = &pictures[i];
228 234
229 clone->needsNewGenID(); 235 clone->needsNewGenID();
230 clone->fWidth = fWidth; 236 clone->fWidth = fWidth;
231 clone->fHeight = fHeight; 237 clone->fHeight = fHeight;
232 SkSafeSetNull(clone->fRecord); 238 SkSafeSetNull(clone->fRecord);
233 SkDELETE(clone->fPlayback); 239 SkDELETE(clone->fPlayback);
234 clone->fContentInfo.set(fContentInfo); 240 clone->fContentInfo.set(fContentInfo);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 283
278 // needed to create typeface playback 284 // needed to create typeface playback
279 copyInfo.controller.setupPlaybacks(); 285 copyInfo.controller.setupPlaybacks();
280 copyInfo.initialized = true; 286 copyInfo.initialized = true;
281 } 287 }
282 288
283 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (clone, *fPlayback, &copyInfo)); 289 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (clone, *fPlayback, &copyInfo));
284 SkASSERT(NULL == fRecord); 290 SkASSERT(NULL == fRecord);
285 clone->fUniqueID = this->uniqueID(); // need to call method to ensur e != 0 291 clone->fUniqueID = this->uniqueID(); // need to call method to ensur e != 0
286 } else if (fRecord) { 292 } else if (fRecord) {
287 // here we do a fake src.endRecording() 293 clone->fPlayback = FakeEndRecording(clone, *fRecord, true);
288 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (clone, *fRecord, i nfo, true));
289 } else { 294 } else {
290 clone->fPlayback = NULL; 295 clone->fPlayback = NULL;
291 } 296 }
292 297
293 clone->fPathHeap.reset(SkSafeRef(fPathHeap.get())); 298 clone->fPathHeap.reset(SkSafeRef(fPathHeap.get()));
294 } 299 }
295 } 300 }
296 301
297 SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() { 302 SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() {
298 static int32_t gNextID = 0; 303 static int32_t gNextID = 0;
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 info->fFlags |= SkPictInfo::kScalarIsFloat_Flag; 569 info->fFlags |= SkPictInfo::kScalarIsFloat_Flag;
565 570
566 if (8 == sizeof(void*)) { 571 if (8 == sizeof(void*)) {
567 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag; 572 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag;
568 } 573 }
569 } 574 }
570 575
571 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { 576 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
572 SkPicturePlayback* playback = fPlayback; 577 SkPicturePlayback* playback = fPlayback;
573 578
579 if (NULL == playback && fRecord) {
580 playback = FakeEndRecording(this, *fRecord, false);
581 }
582
574 SkPictInfo info; 583 SkPictInfo info;
575 this->createHeader(&info); 584 this->createHeader(&info);
576 if (NULL == playback && fRecord) {
577 playback = SkNEW_ARGS(SkPicturePlayback, (this, *fRecord, info));
578 }
579
580 stream->write(&info, sizeof(info)); 585 stream->write(&info, sizeof(info));
581 if (playback) { 586 if (playback) {
582 stream->writeBool(true); 587 stream->writeBool(true);
583 playback->serialize(stream, encoder); 588 playback->serialize(stream, encoder);
584 // delete playback if it is a local version (i.e. cons'd up just now) 589 // delete playback if it is a local version (i.e. cons'd up just now)
585 if (playback != fPlayback) { 590 if (playback != fPlayback) {
586 SkDELETE(playback); 591 SkDELETE(playback);
587 } 592 }
588 } else { 593 } else {
589 stream->writeBool(false); 594 stream->writeBool(false);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 627
623 if ((n = SafeCount(fPathHeap.get())) > 0) { 628 if ((n = SafeCount(fPathHeap.get())) > 0) {
624 WriteTagSize(buffer, SK_PICT_PATH_BUFFER_TAG, n); 629 WriteTagSize(buffer, SK_PICT_PATH_BUFFER_TAG, n);
625 fPathHeap->flatten(buffer); 630 fPathHeap->flatten(buffer);
626 } 631 }
627 } 632 }
628 633
629 void SkPicture::flatten(SkWriteBuffer& buffer) const { 634 void SkPicture::flatten(SkWriteBuffer& buffer) const {
630 SkPicturePlayback* playback = fPlayback; 635 SkPicturePlayback* playback = fPlayback;
631 636
637 if (NULL == playback && fRecord) {
638 playback = FakeEndRecording(this, *fRecord, false);
639 }
640
632 SkPictInfo info; 641 SkPictInfo info;
633 this->createHeader(&info); 642 this->createHeader(&info);
634 if (NULL == playback && fRecord) {
635 playback = SkNEW_ARGS(SkPicturePlayback, (this, *fRecord, info));
636 }
637
638 buffer.writeByteArray(&info, sizeof(info)); 643 buffer.writeByteArray(&info, sizeof(info));
639 if (playback) { 644 if (playback) {
640 buffer.writeBool(true); 645 buffer.writeBool(true);
641 playback->flatten(buffer); 646 playback->flatten(buffer);
642 // delete playback if it is a local version (i.e. cons'd up just now) 647 // delete playback if it is a local version (i.e. cons'd up just now)
643 if (playback != fPlayback) { 648 if (playback != fPlayback) {
644 SkDELETE(playback); 649 SkDELETE(playback);
645 } 650 }
646 } else { 651 } else {
647 buffer.writeBool(false); 652 buffer.writeBool(false);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 if (NULL != fRecord) { 697 if (NULL != fRecord) {
693 SkASSERT(NULL == fPlayback); 698 SkASSERT(NULL == fPlayback);
694 return SK_InvalidGenID; 699 return SK_InvalidGenID;
695 } 700 }
696 701
697 if (SK_InvalidGenID == fUniqueID) { 702 if (SK_InvalidGenID == fUniqueID) {
698 fUniqueID = next_picture_generation_id(); 703 fUniqueID = next_picture_generation_id();
699 } 704 }
700 return fUniqueID; 705 return fUniqueID;
701 } 706 }
OLDNEW
« no previous file with comments | « include/core/SkPicture.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698