| OLD | NEW |
| 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" |
| 11 #include "SkPictureData.h" | 11 #include "SkPictureData.h" |
| 12 #include "SkPicturePlayback.h" | 12 #include "SkPicturePlayback.h" |
| 13 #include "SkPictureRecord.h" | 13 #include "SkPictureRecord.h" |
| 14 #include "SkPictureRecorder.h" | 14 #include "SkPictureRecorder.h" |
| 15 #include "SkPictureStateTree.h" | 15 #include "SkPictureStateTree.h" |
| 16 | 16 |
| 17 #include "SkBitmapDevice.h" | 17 #include "SkBitmapDevice.h" |
| 18 #include "SkCanvas.h" | 18 #include "SkCanvas.h" |
| 19 #include "SkChunkAlloc.h" | 19 #include "SkChunkAlloc.h" |
| 20 #include "SkDrawPictureCallback.h" | 20 #include "SkDrawPictureCallback.h" |
| 21 #include "SkPaintPriv.h" | 21 #include "SkPaintPriv.h" |
| 22 #include "SkPicture.h" | 22 #include "SkPicture.h" |
| 23 #include "SkRecordAnalysis.h" | |
| 24 #include "SkRegion.h" | 23 #include "SkRegion.h" |
| 25 #include "SkStream.h" | 24 #include "SkStream.h" |
| 26 #include "SkTDArray.h" | 25 #include "SkTDArray.h" |
| 27 #include "SkTSearch.h" | 26 #include "SkTSearch.h" |
| 28 #include "SkTime.h" | 27 #include "SkTime.h" |
| 29 | 28 |
| 30 #include "SkReader32.h" | 29 #include "SkReader32.h" |
| 31 #include "SkWriter32.h" | 30 #include "SkWriter32.h" |
| 32 #include "SkRTree.h" | 31 #include "SkRTree.h" |
| 33 #include "SkBBoxHierarchyRecord.h" | 32 #include "SkBBoxHierarchyRecord.h" |
| 34 | 33 |
| 35 #if SK_SUPPORT_GPU | 34 #if SK_SUPPORT_GPU |
| 36 #include "GrContext.h" | 35 #include "GrContext.h" |
| 37 #endif | 36 #endif |
| 38 | 37 |
| 39 #include "SkRecord.h" | 38 #include "SkRecord.h" |
| 40 #include "SkRecordDraw.h" | 39 #include "SkRecordDraw.h" |
| 41 #include "SkRecorder.h" | 40 #include "SkRecorder.h" |
| 42 | 41 |
| 43 template <typename T> int SafeCount(const T* obj) { | 42 template <typename T> int SafeCount(const T* obj) { |
| 44 return obj ? obj->count() : 0; | 43 return obj ? obj->count() : 0; |
| 45 } | 44 } |
| 46 | 45 |
| 47 /////////////////////////////////////////////////////////////////////////////// | 46 /////////////////////////////////////////////////////////////////////////////// |
| 48 | 47 |
| 49 #ifdef SK_SUPPORT_LEGACY_DEFAULT_PICTURE_CTOR | 48 #ifdef SK_SUPPORT_LEGACY_DEFAULT_PICTURE_CTOR |
| 50 // fRecord OK | 49 // fRecord OK |
| 51 SkPicture::SkPicture() | 50 SkPicture::SkPicture() |
| 52 : fWidth(0) | 51 : fWidth(0) |
| 53 , fHeight(0) | 52 , fHeight(0) { |
| 54 , fRecordWillPlayBackBitmaps(false) { | |
| 55 this->needsNewGenID(); | 53 this->needsNewGenID(); |
| 56 } | 54 } |
| 57 #endif | 55 #endif |
| 58 | 56 |
| 59 // fRecord OK | 57 // fRecord OK |
| 60 SkPicture::SkPicture(int width, int height, | 58 SkPicture::SkPicture(int width, int height, |
| 61 const SkPictureRecord& record, | 59 const SkPictureRecord& record, |
| 62 bool deepCopyOps) | 60 bool deepCopyOps) |
| 63 : fWidth(width) | 61 : fWidth(width) |
| 64 , fHeight(height) | 62 , fHeight(height) { |
| 65 , fRecordWillPlayBackBitmaps(false) { | |
| 66 this->needsNewGenID(); | 63 this->needsNewGenID(); |
| 67 | 64 |
| 68 SkPictInfo info; | 65 SkPictInfo info; |
| 69 this->createHeader(&info); | 66 this->createHeader(&info); |
| 70 fData.reset(SkNEW_ARGS(SkPictureData, (record, info, deepCopyOps))); | 67 fData.reset(SkNEW_ARGS(SkPictureData, (record, info, deepCopyOps))); |
| 71 } | 68 } |
| 72 | 69 |
| 73 // Create an SkPictureData-backed SkPicture from an SkRecord. | 70 // Create an SkPictureData-backed SkPicture from an SkRecord. |
| 74 // This for compatibility with serialization code only. This is not cheap. | 71 // This for compatibility with serialization code only. This is not cheap. |
| 75 static SkPicture* backport(const SkRecord& src, int width, int height) { | 72 static SkPicture* backport(const SkRecord& src, int width, int height) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } | 127 } |
| 131 SkASSERT(SafeCount(fData->fBitmapHeap.get()) == heapSize); | 128 SkASSERT(SafeCount(fData->fBitmapHeap.get()) == heapSize); |
| 132 | 129 |
| 133 // needed to create typeface playback | 130 // needed to create typeface playback |
| 134 copyInfo.controller.setupPlaybacks(); | 131 copyInfo.controller.setupPlaybacks(); |
| 135 | 132 |
| 136 newData.reset(SkNEW_ARGS(SkPictureData, (*fData, ©Info))); | 133 newData.reset(SkNEW_ARGS(SkPictureData, (*fData, ©Info))); |
| 137 } | 134 } |
| 138 | 135 |
| 139 SkPicture* clone = SkNEW_ARGS(SkPicture, (newData.detach(), fWidth, fHeight)
); | 136 SkPicture* clone = SkNEW_ARGS(SkPicture, (newData.detach(), fWidth, fHeight)
); |
| 140 clone->fRecordWillPlayBackBitmaps = fRecordWillPlayBackBitmaps; | |
| 141 clone->fUniqueID = this->uniqueID(); // need to call method to ensure != 0 | 137 clone->fUniqueID = this->uniqueID(); // need to call method to ensure != 0 |
| 142 | 138 |
| 143 return clone; | 139 return clone; |
| 144 #endif | 140 #endif |
| 145 } | 141 } |
| 146 #endif//SK_SUPPORT_LEGACY_PICTURE_CLONE | 142 #endif//SK_SUPPORT_LEGACY_PICTURE_CLONE |
| 147 | 143 |
| 148 // fRecord OK | 144 // fRecord OK |
| 149 void SkPicture::EXPERIMENTAL_addAccelData(const SkPicture::AccelData* data) cons
t { | 145 void SkPicture::EXPERIMENTAL_addAccelData(const SkPicture::AccelData* data) cons
t { |
| 150 fAccelData.reset(SkRef(data)); | 146 fAccelData.reset(SkRef(data)); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 if (pInfo != NULL) { | 253 if (pInfo != NULL) { |
| 258 *pInfo = info; | 254 *pInfo = info; |
| 259 } | 255 } |
| 260 return true; | 256 return true; |
| 261 } | 257 } |
| 262 | 258 |
| 263 // fRecord OK | 259 // fRecord OK |
| 264 SkPicture::SkPicture(SkPictureData* data, int width, int height) | 260 SkPicture::SkPicture(SkPictureData* data, int width, int height) |
| 265 : fData(data) | 261 : fData(data) |
| 266 , fWidth(width) | 262 , fWidth(width) |
| 267 , fHeight(height) | 263 , fHeight(height) { |
| 268 , fRecordWillPlayBackBitmaps(false) { | |
| 269 this->needsNewGenID(); | 264 this->needsNewGenID(); |
| 270 } | 265 } |
| 271 | 266 |
| 272 // fRecord OK | 267 // fRecord OK |
| 273 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro
c) { | 268 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro
c) { |
| 274 SkPictInfo info; | 269 SkPictInfo info; |
| 275 | 270 |
| 276 if (!InternalOnly_StreamIsSKP(stream, &info)) { | 271 if (!InternalOnly_StreamIsSKP(stream, &info)) { |
| 277 return NULL; | 272 return NULL; |
| 278 } | 273 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 return false; | 384 return false; |
| 390 } | 385 } |
| 391 | 386 |
| 392 return fData->suitableForGpuRasterization(context, reason); | 387 return fData->suitableForGpuRasterization(context, reason); |
| 393 } | 388 } |
| 394 #endif | 389 #endif |
| 395 | 390 |
| 396 // fRecord OK | 391 // fRecord OK |
| 397 bool SkPicture::willPlayBackBitmaps() const { | 392 bool SkPicture::willPlayBackBitmaps() const { |
| 398 if (fRecord.get()) { | 393 if (fRecord.get()) { |
| 399 return fRecordWillPlayBackBitmaps; | 394 return fRecord->fAccelerationInfo.fWillPlaybackBitmaps; |
| 400 } | 395 } |
| 401 if (!fData.get()) { | 396 if (!fData.get()) { |
| 402 return false; | 397 return false; |
| 403 } | 398 } |
| 404 return fData->containsBitmaps(); | 399 return fData->containsBitmaps(); |
| 405 } | 400 } |
| 406 | 401 |
| 407 // fRecord OK | 402 // fRecord OK |
| 408 static int32_t next_picture_generation_id() { | 403 static int32_t next_picture_generation_id() { |
| 409 static int32_t gPictureGenerationID = 0; | 404 static int32_t gPictureGenerationID = 0; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 422 fUniqueID = next_picture_generation_id(); | 417 fUniqueID = next_picture_generation_id(); |
| 423 } | 418 } |
| 424 return fUniqueID; | 419 return fUniqueID; |
| 425 } | 420 } |
| 426 | 421 |
| 427 // fRecord OK | 422 // fRecord OK |
| 428 SkPicture::SkPicture(int width, int height, SkRecord* record, SkBBoxHierarchy* b
bh) | 423 SkPicture::SkPicture(int width, int height, SkRecord* record, SkBBoxHierarchy* b
bh) |
| 429 : fWidth(width) | 424 : fWidth(width) |
| 430 , fHeight(height) | 425 , fHeight(height) |
| 431 , fRecord(record) | 426 , fRecord(record) |
| 432 , fBBH(SkSafeRef(bbh)) | 427 , fBBH(SkSafeRef(bbh)) { |
| 433 , fRecordWillPlayBackBitmaps(SkRecordWillPlaybackBitmaps(*record)) { | |
| 434 // TODO: delay as much of this work until just before first playback? | 428 // TODO: delay as much of this work until just before first playback? |
| 435 if (fBBH.get()) { | 429 if (fBBH.get()) { |
| 436 SkRecordFillBounds(*record, fBBH.get()); | 430 SkRecordFillBounds(*record, fBBH.get()); |
| 437 } | 431 } |
| 438 this->needsNewGenID(); | 432 this->needsNewGenID(); |
| 439 } | 433 } |
| 440 | 434 |
| 441 // Note that we are assuming that this entry point will only be called from | 435 // Note that we are assuming that this entry point will only be called from |
| 442 // one thread. Currently the only client of this method is | 436 // one thread. Currently the only client of this method is |
| 443 // SkGpuDevice::EXPERIMENTAL_optimize which should be only called from a single | 437 // SkGpuDevice::EXPERIMENTAL_optimize which should be only called from a single |
| 444 // thread. | 438 // thread. |
| 445 void SkPicture::addDeletionListener(DeletionListener* listener) const { | 439 void SkPicture::addDeletionListener(DeletionListener* listener) const { |
| 446 SkASSERT(NULL != listener); | 440 SkASSERT(NULL != listener); |
| 447 | 441 |
| 448 *fDeletionListeners.append() = SkRef(listener); | 442 *fDeletionListeners.append() = SkRef(listener); |
| 449 } | 443 } |
| 450 | 444 |
| 451 void SkPicture::callDeletionListeners() { | 445 void SkPicture::callDeletionListeners() { |
| 452 for (int i = 0; i < fDeletionListeners.count(); ++i) { | 446 for (int i = 0; i < fDeletionListeners.count(); ++i) { |
| 453 fDeletionListeners[i]->onDeletion(this->uniqueID()); | 447 fDeletionListeners[i]->onDeletion(this->uniqueID()); |
| 454 } | 448 } |
| 455 | 449 |
| 456 fDeletionListeners.unrefAll(); | 450 fDeletionListeners.unrefAll(); |
| 457 } | 451 } |
| OLD | NEW |