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

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

Issue 222683002: Add generation ID to SkPicture (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Fix Ubuntu compiler complaint Created 6 years, 8 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 | Annotate | Revision Log
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 SkASSERT(scaleY == 0 || skewY == 0); 111 SkASSERT(scaleY == 0 || skewY == 0);
112 SkASSERT(perspX == 0); 112 SkASSERT(perspX == 0);
113 SkASSERT(perspY == 0); 113 SkASSERT(perspY == 0);
114 } 114 }
115 #endif 115 #endif
116 116
117 117
118 /////////////////////////////////////////////////////////////////////////////// 118 ///////////////////////////////////////////////////////////////////////////////
119 119
120 SkPicture::SkPicture() { 120 SkPicture::SkPicture() {
121 this->needsNewGenID();
121 fRecord = NULL; 122 fRecord = NULL;
122 fPlayback = NULL; 123 fPlayback = NULL;
123 fWidth = fHeight = 0; 124 fWidth = fHeight = 0;
124 fAccelData = NULL; 125 fAccelData = NULL;
125 } 126 }
126 127
127 SkPicture::SkPicture(const SkPicture& src) 128 SkPicture::SkPicture(const SkPicture& src)
128 : INHERITED() 129 : INHERITED()
129 , fAccelData(NULL) { 130 , fAccelData(NULL) {
131 this->needsNewGenID();
130 fWidth = src.fWidth; 132 fWidth = src.fWidth;
131 fHeight = src.fHeight; 133 fHeight = src.fHeight;
132 fRecord = NULL; 134 fRecord = NULL;
133 135
134 /* We want to copy the src's playback. However, if that hasn't been built 136 /* We want to copy the src's playback. However, if that hasn't been built
135 yet, we need to fake a call to endRecording() without actually calling 137 yet, we need to fake a call to endRecording() without actually calling
136 it (since it is destructive, and we don't want to change src). 138 it (since it is destructive, and we don't want to change src).
137 */ 139 */
138 if (src.fPlayback) { 140 if (src.fPlayback) {
139 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fPlayback)); 141 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fPlayback));
142 SkASSERT(NULL == src.fRecord);
143 fGenerationID = src.getGenerationID(); // need to call method to ens ure != 0
140 } else if (src.fRecord) { 144 } else if (src.fRecord) {
141 SkPictInfo info; 145 SkPictInfo info;
142 this->createHeader(&info); 146 this->createHeader(&info);
143 // here we do a fake src.endRecording() 147 // here we do a fake src.endRecording()
144 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fRecord, info)); 148 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fRecord, info));
145 } else { 149 } else {
146 fPlayback = NULL; 150 fPlayback = NULL;
147 } 151 }
148 } 152 }
149 153
150 SkPicture::~SkPicture() { 154 SkPicture::~SkPicture() {
151 SkSafeUnref(fRecord); 155 SkSafeUnref(fRecord);
152 SkDELETE(fPlayback); 156 SkDELETE(fPlayback);
153 SkSafeUnref(fAccelData); 157 SkSafeUnref(fAccelData);
154 } 158 }
155 159
156 void SkPicture::internalOnly_EnableOpts(bool enableOpts) { 160 void SkPicture::internalOnly_EnableOpts(bool enableOpts) {
157 if (NULL != fRecord) { 161 if (NULL != fRecord) {
158 fRecord->internalOnly_EnableOpts(enableOpts); 162 fRecord->internalOnly_EnableOpts(enableOpts);
159 } 163 }
160 } 164 }
161 165
162 void SkPicture::swap(SkPicture& other) { 166 void SkPicture::swap(SkPicture& other) {
167 SkTSwap(fGenerationID, other.fGenerationID);
163 SkTSwap(fRecord, other.fRecord); 168 SkTSwap(fRecord, other.fRecord);
164 SkTSwap(fPlayback, other.fPlayback); 169 SkTSwap(fPlayback, other.fPlayback);
165 SkTSwap(fAccelData, other.fAccelData); 170 SkTSwap(fAccelData, other.fAccelData);
166 SkTSwap(fWidth, other.fWidth); 171 SkTSwap(fWidth, other.fWidth);
167 SkTSwap(fHeight, other.fHeight); 172 SkTSwap(fHeight, other.fHeight);
168 } 173 }
169 174
170 SkPicture* SkPicture::clone() const { 175 SkPicture* SkPicture::clone() const {
171 SkPicture* clonedPicture = SkNEW(SkPicture); 176 SkPicture* clonedPicture = SkNEW(SkPicture);
172 clone(clonedPicture, 1); 177 this->clone(clonedPicture, 1);
173 return clonedPicture; 178 return clonedPicture;
174 } 179 }
175 180
176 void SkPicture::clone(SkPicture* pictures, int count) const { 181 void SkPicture::clone(SkPicture* pictures, int count) const {
177 SkPictCopyInfo copyInfo; 182 SkPictCopyInfo copyInfo;
178 SkPictInfo info; 183 SkPictInfo info;
179 this->createHeader(&info); 184 this->createHeader(&info);
180 185
181 for (int i = 0; i < count; i++) { 186 for (int i = 0; i < count; i++) {
182 SkPicture* clone = &pictures[i]; 187 SkPicture* clone = &pictures[i];
183 188
189 clone->needsNewGenID();
184 clone->fWidth = fWidth; 190 clone->fWidth = fWidth;
185 clone->fHeight = fHeight; 191 clone->fHeight = fHeight;
186 SkSafeSetNull(clone->fRecord); 192 SkSafeSetNull(clone->fRecord);
187 SkDELETE(clone->fPlayback); 193 SkDELETE(clone->fPlayback);
188 194
189 /* We want to copy the src's playback. However, if that hasn't been bui lt 195 /* We want to copy the src's playback. However, if that hasn't been bui lt
190 yet, we need to fake a call to endRecording() without actually calli ng 196 yet, we need to fake a call to endRecording() without actually calli ng
191 it (since it is destructive, and we don't want to change src). 197 it (since it is destructive, and we don't want to change src).
192 */ 198 */
193 if (fPlayback) { 199 if (fPlayback) {
194 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fPlayback, &copyI nfo)); 200 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fPlayback, &copyI nfo));
201 SkASSERT(NULL == fRecord);
202 clone->fGenerationID = this->getGenerationID(); // need to call meth od to ensure != 0
195 } else if (fRecord) { 203 } else if (fRecord) {
196 // here we do a fake src.endRecording() 204 // here we do a fake src.endRecording()
197 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fRecord, info, tr ue)); 205 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fRecord, info, tr ue));
198 } else { 206 } else {
199 clone->fPlayback = NULL; 207 clone->fPlayback = NULL;
200 } 208 }
201 } 209 }
202 } 210 }
203 211
204 SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() { 212 SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() {
(...skipping 11 matching lines...) Expand all
216 224
217 SkCanvas* SkPicture::beginRecording(int width, int height, 225 SkCanvas* SkPicture::beginRecording(int width, int height,
218 uint32_t recordingFlags) { 226 uint32_t recordingFlags) {
219 if (fPlayback) { 227 if (fPlayback) {
220 SkDELETE(fPlayback); 228 SkDELETE(fPlayback);
221 fPlayback = NULL; 229 fPlayback = NULL;
222 } 230 }
223 SkSafeUnref(fAccelData); 231 SkSafeUnref(fAccelData);
224 SkSafeSetNull(fRecord); 232 SkSafeSetNull(fRecord);
225 233
234 this->needsNewGenID();
235
226 // Must be set before calling createBBoxHierarchy 236 // Must be set before calling createBBoxHierarchy
227 fWidth = width; 237 fWidth = width;
228 fHeight = height; 238 fHeight = height;
229 239
230 const SkISize size = SkISize::Make(width, height); 240 const SkISize size = SkISize::Make(width, height);
231 241
232 if (recordingFlags & kOptimizeForClippedPlayback_RecordingFlag) { 242 if (recordingFlags & kOptimizeForClippedPlayback_RecordingFlag) {
233 SkBBoxHierarchy* tree = this->createBBoxHierarchy(); 243 SkBBoxHierarchy* tree = this->createBBoxHierarchy();
234 SkASSERT(NULL != tree); 244 SkASSERT(NULL != tree);
235 fRecord = SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordingFlags, tree) ); 245 fRecord = SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordingFlags, tree) );
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 *pInfo = info; 360 *pInfo = info;
351 } 361 }
352 return true; 362 return true;
353 } 363 }
354 364
355 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) 365 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height)
356 : fPlayback(playback) 366 : fPlayback(playback)
357 , fRecord(NULL) 367 , fRecord(NULL)
358 , fWidth(width) 368 , fWidth(width)
359 , fHeight(height) 369 , fHeight(height)
360 , fAccelData(NULL) {} 370 , fAccelData(NULL) {
371 this->needsNewGenID();
372 }
361 373
362 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) { 374 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) {
363 SkPictInfo info; 375 SkPictInfo info;
364 376
365 if (!InternalOnly_StreamIsSKP(stream, &info)) { 377 if (!InternalOnly_StreamIsSKP(stream, &info)) {
366 return NULL; 378 return NULL;
367 } 379 }
368 380
369 SkPicturePlayback* playback; 381 SkPicturePlayback* playback;
370 // Check to see if there is a playback to recreate. 382 // Check to see if there is a playback to recreate.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } 491 }
480 492
481 #ifdef SK_BUILD_FOR_ANDROID 493 #ifdef SK_BUILD_FOR_ANDROID
482 void SkPicture::abortPlayback() { 494 void SkPicture::abortPlayback() {
483 if (NULL == fPlayback) { 495 if (NULL == fPlayback) {
484 return; 496 return;
485 } 497 }
486 fPlayback->abort(); 498 fPlayback->abort();
487 } 499 }
488 #endif 500 #endif
501
502 static int32_t next_picture_generation_id() {
503 static int32_t gPictureGenerationID = 0;
504 // do a loop in case our global wraps around, as we never want to
505 // return a 0
506 int32_t genID;
507 do {
508 genID = sk_atomic_inc(&gPictureGenerationID) + 1;
509 } while (((int32_t)SkPicture::kInvalidGenID) == genID);
510 return genID;
511 }
512
513 uint32_t SkPicture::getGenerationID() const {
514 if (NULL != fRecord) {
515 SkASSERT(NULL == fPlayback);
516 return kInvalidGenID;
517 }
518
519 if (kInvalidGenID == fGenerationID) {
520 fGenerationID = next_picture_generation_id();
521 }
522 return fGenerationID;
523 }
OLDNEW
« include/core/SkPicture.h ('K') | « include/core/SkPicture.h ('k') | tests/PictureTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698