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

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

Issue 256653006: Move setup of SkPictCopyInfo into SkPicture::clone (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Fixed overlength lines 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/core/SkPicturePlayback.h » ('j') | 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 fPathHeap.swap(&other.fPathHeap); 210 fPathHeap.swap(&other.fPathHeap);
211 fContentInfo.swap(&other.fContentInfo); 211 fContentInfo.swap(&other.fContentInfo);
212 } 212 }
213 213
214 SkPicture* SkPicture::clone() const { 214 SkPicture* SkPicture::clone() const {
215 SkPicture* clonedPicture = SkNEW(SkPicture); 215 SkPicture* clonedPicture = SkNEW(SkPicture);
216 this->clone(clonedPicture, 1); 216 this->clone(clonedPicture, 1);
217 return clonedPicture; 217 return clonedPicture;
218 } 218 }
219 219
220 static bool needs_deep_copy(const SkPaint& paint) {
221 /*
222 * These fields are known to be immutable, and so can be shallow-copied
223 *
224 * getTypeface()
225 * getAnnotation()
226 * paint.getColorFilter()
227 * getXfermode()
228 * getPathEffect()
229 * getMaskFilter()
230 */
231
232 return paint.getShader() ||
233 #ifdef SK_SUPPORT_LEGACY_LAYERRASTERIZER_API
234 paint.getRasterizer() ||
235 #endif
236 paint.getLooper() || // needs to hide its addLayer...
237 paint.getImageFilter();
238 }
239
220 void SkPicture::clone(SkPicture* pictures, int count) const { 240 void SkPicture::clone(SkPicture* pictures, int count) const {
221 SkPictCopyInfo copyInfo; 241 SkPictCopyInfo copyInfo;
222 SkPictInfo info; 242 SkPictInfo info;
223 this->createHeader(&info); 243 this->createHeader(&info);
224 244
225 for (int i = 0; i < count; i++) { 245 for (int i = 0; i < count; i++) {
226 SkPicture* clone = &pictures[i]; 246 SkPicture* clone = &pictures[i];
227 247
228 clone->needsNewGenID(); 248 clone->needsNewGenID();
229 clone->fWidth = fWidth; 249 clone->fWidth = fWidth;
230 clone->fHeight = fHeight; 250 clone->fHeight = fHeight;
231 SkSafeSetNull(clone->fRecord); 251 SkSafeSetNull(clone->fRecord);
232 SkDELETE(clone->fPlayback); 252 SkDELETE(clone->fPlayback);
233 clone->fContentInfo.set(fContentInfo); 253 clone->fContentInfo.set(fContentInfo);
234 254
235 /* We want to copy the src's playback. However, if that hasn't been bui lt 255 /* We want to copy the src's playback. However, if that hasn't been bui lt
236 yet, we need to fake a call to endRecording() without actually calli ng 256 yet, we need to fake a call to endRecording() without actually calli ng
237 it (since it is destructive, and we don't want to change src). 257 it (since it is destructive, and we don't want to change src).
238 */ 258 */
239 if (fPlayback) { 259 if (fPlayback) {
260 if (!copyInfo.initialized) {
261 int paintCount = SafeCount(fPlayback->fPaints);
262
263 /* The alternative to doing this is to have a clone method on th e paint and have it
264 * make the deep copy of its internal structures as needed. The holdup to doing
265 * that is at this point we would need to pass the SkBitmapHeap so that we don't
266 * unnecessarily flatten the pixels in a bitmap shader.
267 */
268 copyInfo.paintData.setCount(paintCount);
269
270 /* Use an SkBitmapHeap to avoid flattening bitmaps in shaders. I f there already is
271 * one, use it. If this SkPicturePlayback was created from a str eam, fBitmapHeap
272 * will be NULL, so create a new one.
273 */
274 if (fPlayback->fBitmapHeap.get() == NULL) {
275 // FIXME: Put this on the stack inside SkPicture::clone.
276 SkBitmapHeap* heap = SkNEW(SkBitmapHeap);
277 copyInfo.controller.setBitmapStorage(heap);
278 heap->unref();
279 } else {
280 copyInfo.controller.setBitmapStorage(fPlayback->fBitmapHeap) ;
281 }
282
283 SkDEBUGCODE(int heapSize = SafeCount(fPlayback->fBitmapHeap.get( ));)
284 for (int i = 0; i < paintCount; i++) {
285 if (needs_deep_copy(fPlayback->fPaints->at(i))) {
286 copyInfo.paintData[i] =
287 SkFlatData::Create<SkPaint::FlatteningTraits>(&copyI nfo.controller,
288 fPlayback->fPaints ->at(i), 0);
289
290 } else {
291 // this is our sentinel, which we use in the unflatten l oop
292 copyInfo.paintData[i] = NULL;
293 }
294 }
295 SkASSERT(SafeCount(fPlayback->fBitmapHeap.get()) == heapSize);
296
297 // needed to create typeface playback
298 copyInfo.controller.setupPlaybacks();
299 copyInfo.initialized = true;
300 }
301
240 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (clone, *fPlayback, &copyInfo)); 302 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (clone, *fPlayback, &copyInfo));
241 SkASSERT(NULL == fRecord); 303 SkASSERT(NULL == fRecord);
242 clone->fUniqueID = this->uniqueID(); // need to call method to ensur e != 0 304 clone->fUniqueID = this->uniqueID(); // need to call method to ensur e != 0
243 } else if (fRecord) { 305 } else if (fRecord) {
244 // here we do a fake src.endRecording() 306 // here we do a fake src.endRecording()
245 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (clone, *fRecord, i nfo, true)); 307 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (clone, *fRecord, i nfo, true));
246 } else { 308 } else {
247 clone->fPlayback = NULL; 309 clone->fPlayback = NULL;
248 } 310 }
249 311
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 if (NULL != fRecord) { 711 if (NULL != fRecord) {
650 SkASSERT(NULL == fPlayback); 712 SkASSERT(NULL == fPlayback);
651 return SK_InvalidGenID; 713 return SK_InvalidGenID;
652 } 714 }
653 715
654 if (SK_InvalidGenID == fUniqueID) { 716 if (SK_InvalidGenID == fUniqueID) {
655 fUniqueID = next_picture_generation_id(); 717 fUniqueID = next_picture_generation_id();
656 } 718 }
657 return fUniqueID; 719 return fUniqueID;
658 } 720 }
OLDNEW
« no previous file with comments | « no previous file | src/core/SkPicturePlayback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698