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

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

Issue 251533004: First pass at GPU veto (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 SkASSERT(scaleX == 0 || skewX == 0); 115 SkASSERT(scaleX == 0 || skewX == 0);
116 SkASSERT(scaleY == 0 || skewY == 0); 116 SkASSERT(scaleY == 0 || skewY == 0);
117 SkASSERT(perspX == 0); 117 SkASSERT(perspX == 0);
118 SkASSERT(perspY == 0); 118 SkASSERT(perspY == 0);
119 } 119 }
120 #endif 120 #endif
121 121
122 122
123 /////////////////////////////////////////////////////////////////////////////// 123 ///////////////////////////////////////////////////////////////////////////////
124 124
125 SkPicture::SkPicture() { 125 SkPicture::SkPicture()
126 : fAccelData(NULL)
127 , fContentFlags(0) {
126 this->needsNewGenID(); 128 this->needsNewGenID();
127 fRecord = NULL; 129 fRecord = NULL;
128 fPlayback = NULL; 130 fPlayback = NULL;
129 fWidth = fHeight = 0; 131 fWidth = fHeight = 0;
130 fAccelData = NULL;
131 } 132 }
132 133
133 SkPicture::SkPicture(const SkPicture& src) 134 SkPicture::SkPicture(const SkPicture& src)
134 : INHERITED() 135 : INHERITED()
135 , fAccelData(NULL) { 136 , fAccelData(NULL)
137 , fContentFlags(src.fContentFlags) {
136 this->needsNewGenID(); 138 this->needsNewGenID();
137 fWidth = src.fWidth; 139 fWidth = src.fWidth;
138 fHeight = src.fHeight; 140 fHeight = src.fHeight;
139 fRecord = NULL; 141 fRecord = NULL;
140 142
141 /* We want to copy the src's playback. However, if that hasn't been built 143 /* We want to copy the src's playback. However, if that hasn't been built
142 yet, we need to fake a call to endRecording() without actually calling 144 yet, we need to fake a call to endRecording() without actually calling
143 it (since it is destructive, and we don't want to change src). 145 it (since it is destructive, and we don't want to change src).
144 */ 146 */
145 if (src.fPlayback) { 147 if (src.fPlayback) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 202 }
201 203
202 void SkPicture::swap(SkPicture& other) { 204 void SkPicture::swap(SkPicture& other) {
203 SkTSwap(fUniqueID, other.fUniqueID); 205 SkTSwap(fUniqueID, other.fUniqueID);
204 SkTSwap(fRecord, other.fRecord); 206 SkTSwap(fRecord, other.fRecord);
205 SkTSwap(fPlayback, other.fPlayback); 207 SkTSwap(fPlayback, other.fPlayback);
206 SkTSwap(fAccelData, other.fAccelData); 208 SkTSwap(fAccelData, other.fAccelData);
207 SkTSwap(fWidth, other.fWidth); 209 SkTSwap(fWidth, other.fWidth);
208 SkTSwap(fHeight, other.fHeight); 210 SkTSwap(fHeight, other.fHeight);
209 fPathHeap.swap(&other.fPathHeap); 211 fPathHeap.swap(&other.fPathHeap);
212 SkTSwap(fContentFlags, other.fContentFlags);
210 } 213 }
211 214
212 SkPicture* SkPicture::clone() const { 215 SkPicture* SkPicture::clone() const {
213 SkPicture* clonedPicture = SkNEW(SkPicture); 216 SkPicture* clonedPicture = SkNEW(SkPicture);
214 this->clone(clonedPicture, 1); 217 this->clone(clonedPicture, 1);
215 return clonedPicture; 218 return clonedPicture;
216 } 219 }
217 220
218 void SkPicture::clone(SkPicture* pictures, int count) const { 221 void SkPicture::clone(SkPicture* pictures, int count) const {
219 SkPictCopyInfo copyInfo; 222 SkPictCopyInfo copyInfo;
220 SkPictInfo info; 223 SkPictInfo info;
221 this->createHeader(&info); 224 this->createHeader(&info);
222 225
223 for (int i = 0; i < count; i++) { 226 for (int i = 0; i < count; i++) {
224 SkPicture* clone = &pictures[i]; 227 SkPicture* clone = &pictures[i];
225 228
226 clone->needsNewGenID(); 229 clone->needsNewGenID();
227 clone->fWidth = fWidth; 230 clone->fWidth = fWidth;
228 clone->fHeight = fHeight; 231 clone->fHeight = fHeight;
229 SkSafeSetNull(clone->fRecord); 232 SkSafeSetNull(clone->fRecord);
230 SkDELETE(clone->fPlayback); 233 SkDELETE(clone->fPlayback);
234 clone->fContentFlags = fContentFlags;
231 235
232 /* We want to copy the src's playback. However, if that hasn't been bui lt 236 /* We want to copy the src's playback. However, if that hasn't been bui lt
233 yet, we need to fake a call to endRecording() without actually calli ng 237 yet, we need to fake a call to endRecording() without actually calli ng
234 it (since it is destructive, and we don't want to change src). 238 it (since it is destructive, and we don't want to change src).
235 */ 239 */
236 if (fPlayback) { 240 if (fPlayback) {
237 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (clone, *fPlayback, &copyInfo)); 241 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (clone, *fPlayback, &copyInfo));
238 SkASSERT(NULL == fRecord); 242 SkASSERT(NULL == fRecord);
239 clone->fUniqueID = this->uniqueID(); // need to call method to ensur e != 0 243 clone->fUniqueID = this->uniqueID(); // need to call method to ensur e != 0
240 } else if (fRecord) { 244 } else if (fRecord) {
(...skipping 23 matching lines...) Expand all
264 #ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES 268 #ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES
265 269
266 SkCanvas* SkPicture::beginRecording(int width, int height, 270 SkCanvas* SkPicture::beginRecording(int width, int height,
267 uint32_t recordingFlags) { 271 uint32_t recordingFlags) {
268 if (fPlayback) { 272 if (fPlayback) {
269 SkDELETE(fPlayback); 273 SkDELETE(fPlayback);
270 fPlayback = NULL; 274 fPlayback = NULL;
271 } 275 }
272 SkSafeUnref(fAccelData); 276 SkSafeUnref(fAccelData);
273 SkSafeSetNull(fRecord); 277 SkSafeSetNull(fRecord);
278 fContentFlags = 0;
274 279
275 this->needsNewGenID(); 280 this->needsNewGenID();
276 281
277 // Must be set before calling createBBoxHierarchy 282 // Must be set before calling createBBoxHierarchy
278 fWidth = width; 283 fWidth = width;
279 fHeight = height; 284 fHeight = height;
280 285
281 const SkISize size = SkISize::Make(width, height); 286 const SkISize size = SkISize::Make(width, height);
282 287
283 if (recordingFlags & kOptimizeForClippedPlayback_RecordingFlag) { 288 if (recordingFlags & kOptimizeForClippedPlayback_RecordingFlag) {
(...skipping 14 matching lines...) Expand all
298 SkCanvas* SkPicture::beginRecording(int width, int height, 303 SkCanvas* SkPicture::beginRecording(int width, int height,
299 SkBBHFactory* bbhFactory, 304 SkBBHFactory* bbhFactory,
300 uint32_t recordingFlags) { 305 uint32_t recordingFlags) {
301 if (fPlayback) { 306 if (fPlayback) {
302 SkDELETE(fPlayback); 307 SkDELETE(fPlayback);
303 fPlayback = NULL; 308 fPlayback = NULL;
304 } 309 }
305 SkSafeUnref(fAccelData); 310 SkSafeUnref(fAccelData);
306 SkSafeSetNull(fRecord); 311 SkSafeSetNull(fRecord);
307 SkASSERT(NULL == fPathHeap); 312 SkASSERT(NULL == fPathHeap);
313 fContentFlags = 0;
308 314
309 this->needsNewGenID(); 315 this->needsNewGenID();
310 316
311 fWidth = width; 317 fWidth = width;
312 fHeight = height; 318 fHeight = height;
313 319
314 const SkISize size = SkISize::Make(width, height); 320 const SkISize size = SkISize::Make(width, height);
315 321
316 if (NULL != bbhFactory) { 322 if (NULL != bbhFactory) {
317 SkAutoTUnref<SkBBoxHierarchy> tree((*bbhFactory)(width, height)); 323 SkAutoTUnref<SkBBoxHierarchy> tree((*bbhFactory)(width, height));
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 *pInfo = info; 451 *pInfo = info;
446 } 452 }
447 return true; 453 return true;
448 } 454 }
449 455
450 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) 456 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height)
451 : fPlayback(playback) 457 : fPlayback(playback)
452 , fRecord(NULL) 458 , fRecord(NULL)
453 , fWidth(width) 459 , fWidth(width)
454 , fHeight(height) 460 , fHeight(height)
455 , fAccelData(NULL) { 461 , fAccelData(NULL)
462 , fContentFlags(0) {
456 this->needsNewGenID(); 463 this->needsNewGenID();
457 } 464 }
458 465
459 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) { 466 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) {
460 SkPictInfo info; 467 SkPictInfo info;
461 468
462 if (!InternalOnly_StreamIsSKP(stream, &info)) { 469 if (!InternalOnly_StreamIsSKP(stream, &info)) {
463 return NULL; 470 return NULL;
464 } 471 }
465 472
466 SkPicture* newPict = SkNEW_ARGS(SkPicture, (NULL, info.fWidth, info.fHeight) ); 473 SkPicture* newPict = SkNEW_ARGS(SkPicture, (NULL, info.fWidth, info.fHeight) );
467 474
475 newPict->fContentFlags = info.fFlags & ~SkPictInfo::kAll_Mask;
476
468 // Check to see if there is a playback to recreate. 477 // Check to see if there is a playback to recreate.
469 if (stream->readBool()) { 478 if (stream->readBool()) {
470 SkPicturePlayback* playback = SkPicturePlayback::CreateFromStream(newPic t, stream, 479 SkPicturePlayback* playback = SkPicturePlayback::CreateFromStream(newPic t, stream,
471 info, proc); 480 info, proc);
472 if (NULL == playback) { 481 if (NULL == playback) {
473 SkDELETE(newPict); 482 SkDELETE(newPict);
474 return NULL; 483 return NULL;
475 } 484 }
476 newPict->fPlayback = playback; 485 newPict->fPlayback = playback;
477 } 486 }
478 487
479 return newPict; 488 return newPict;
480 } 489 }
481 490
482 SkPicture* SkPicture::CreateFromBuffer(SkReadBuffer& buffer) { 491 SkPicture* SkPicture::CreateFromBuffer(SkReadBuffer& buffer) {
483 SkPictInfo info; 492 SkPictInfo info;
484 493
485 if (!InternalOnly_BufferIsSKP(buffer, &info)) { 494 if (!InternalOnly_BufferIsSKP(buffer, &info)) {
486 return NULL; 495 return NULL;
487 } 496 }
488 497
489 SkPicture* newPict = SkNEW_ARGS(SkPicture, (NULL, info.fWidth, info.fHeight) ); 498 SkPicture* newPict = SkNEW_ARGS(SkPicture, (NULL, info.fWidth, info.fHeight) );
490 499
500 newPict->fContentFlags = info.fFlags & ~SkPictInfo::kAll_Mask;
501
491 // Check to see if there is a playback to recreate. 502 // Check to see if there is a playback to recreate.
492 if (buffer.readBool()) { 503 if (buffer.readBool()) {
493 SkPicturePlayback* playback = SkPicturePlayback::CreateFromBuffer(newPic t, buffer, info); 504 SkPicturePlayback* playback = SkPicturePlayback::CreateFromBuffer(newPic t, buffer, info);
494 if (NULL == playback) { 505 if (NULL == playback) {
495 SkDELETE(newPict); 506 SkDELETE(newPict);
496 return NULL; 507 return NULL;
497 } 508 }
498 newPict->fPlayback = playback; 509 newPict->fPlayback = playback;
499 } 510 }
500 511
501 return newPict; 512 return newPict;
502 } 513 }
503 514
504 void SkPicture::createHeader(SkPictInfo* info) const { 515 void SkPicture::createHeader(SkPictInfo* info) const {
505 // Copy magic bytes at the beginning of the header 516 // Copy magic bytes at the beginning of the header
506 SkASSERT(sizeof(kMagic) == 8); 517 SkASSERT(sizeof(kMagic) == 8);
507 SkASSERT(sizeof(kMagic) == sizeof(info->fMagic)); 518 SkASSERT(sizeof(kMagic) == sizeof(info->fMagic));
508 memcpy(info->fMagic, kMagic, sizeof(kMagic)); 519 memcpy(info->fMagic, kMagic, sizeof(kMagic));
509 520
510 // Set picture info after magic bytes in the header 521 // Set picture info after magic bytes in the header
511 info->fVersion = CURRENT_PICTURE_VERSION; 522 info->fVersion = CURRENT_PICTURE_VERSION;
512 info->fWidth = fWidth; 523 info->fWidth = fWidth;
513 info->fHeight = fHeight; 524 info->fHeight = fHeight;
514 info->fFlags = SkPictInfo::kCrossProcess_Flag; 525 SkASSERT((fContentFlags & SkPictInfo::kAll_Mask) == 0);
526
527 info->fFlags = fContentFlags | SkPictInfo::kCrossProcess_Flag;
515 // TODO: remove this flag, since we're always float (now) 528 // TODO: remove this flag, since we're always float (now)
516 info->fFlags |= SkPictInfo::kScalarIsFloat_Flag; 529 info->fFlags |= SkPictInfo::kScalarIsFloat_Flag;
517 530
518 if (8 == sizeof(void*)) { 531 if (8 == sizeof(void*)) {
519 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag; 532 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag;
520 } 533 }
521 } 534 }
522 535
523 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { 536 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
524 SkPicturePlayback* playback = fPlayback; 537 SkPicturePlayback* playback = fPlayback;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 if (playback != fPlayback) { 608 if (playback != fPlayback) {
596 SkDELETE(playback); 609 SkDELETE(playback);
597 } 610 }
598 } else { 611 } else {
599 buffer.writeBool(false); 612 buffer.writeBool(false);
600 } 613 }
601 } 614 }
602 615
603 #if SK_SUPPORT_GPU 616 #if SK_SUPPORT_GPU
604 bool SkPicture::suitableForGpuRasterization(GrContext* context) const { 617 bool SkPicture::suitableForGpuRasterization(GrContext* context) const {
605 // Stub for now; never veto GPu rasterization. 618 return !this->getHasPathEffects();
606 return true;
607 } 619 }
608 #endif 620 #endif
609 621
610 bool SkPicture::willPlayBackBitmaps() const { 622 bool SkPicture::willPlayBackBitmaps() const {
611 if (!fPlayback) { 623 if (!fPlayback) {
612 return false; 624 return false;
613 } 625 }
614 return fPlayback->containsBitmaps(); 626 return fPlayback->containsBitmaps();
615 } 627 }
616 628
(...skipping 21 matching lines...) Expand all
638 if (NULL != fRecord) { 650 if (NULL != fRecord) {
639 SkASSERT(NULL == fPlayback); 651 SkASSERT(NULL == fPlayback);
640 return SK_InvalidGenID; 652 return SK_InvalidGenID;
641 } 653 }
642 654
643 if (SK_InvalidGenID == fUniqueID) { 655 if (SK_InvalidGenID == fUniqueID) {
644 fUniqueID = next_picture_generation_id(); 656 fUniqueID = next_picture_generation_id();
645 } 657 }
646 return fUniqueID; 658 return fUniqueID;
647 } 659 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698