| 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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 #include "SkRecord.h" | 39 #include "SkRecord.h" |
| 40 #include "SkRecordDraw.h" | 40 #include "SkRecordDraw.h" |
| 41 #include "SkRecordOpts.h" | 41 #include "SkRecordOpts.h" |
| 42 #include "SkRecorder.h" | 42 #include "SkRecorder.h" |
| 43 | 43 |
| 44 template <typename T> int SafeCount(const T* obj) { | 44 template <typename T> int SafeCount(const T* obj) { |
| 45 return obj ? obj->count() : 0; | 45 return obj ? obj->count() : 0; |
| 46 } | 46 } |
| 47 | 47 |
| 48 static int32_t gPictureGenerationID; |
| 49 |
| 50 // never returns a 0 |
| 51 static int32_t next_picture_generation_id() { |
| 52 // Loop in case our global wraps around. |
| 53 int32_t genID; |
| 54 do { |
| 55 genID = sk_atomic_inc(&gPictureGenerationID) + 1; |
| 56 } while (0 == genID); |
| 57 return genID; |
| 58 } |
| 59 |
| 48 /////////////////////////////////////////////////////////////////////////////// | 60 /////////////////////////////////////////////////////////////////////////////// |
| 49 | 61 |
| 50 namespace { | 62 namespace { |
| 51 | 63 |
| 52 // Some commands have a paint, some have an optional paint. Either way, get bac
k a pointer. | 64 // Some commands have a paint, some have an optional paint. Either way, get bac
k a pointer. |
| 53 static const SkPaint* AsPtr(const SkPaint& p) { return &p; } | 65 static const SkPaint* AsPtr(const SkPaint& p) { return &p; } |
| 54 static const SkPaint* AsPtr(const SkRecords::Optional<SkPaint>& p) { return p; } | 66 static const SkPaint* AsPtr(const SkRecords::Optional<SkPaint>& p) { return p; } |
| 55 | 67 |
| 56 /** SkRecords visitor to determine whether an instance may require an | 68 /** SkRecords visitor to determine whether an instance may require an |
| 57 "external" bitmap to rasterize. May return false positives. | 69 "external" bitmap to rasterize. May return false positives. |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 #if SK_SUPPORT_GPU | 517 #if SK_SUPPORT_GPU |
| 506 bool SkPicture::suitableForGpuRasterization(GrContext*, const char **reason) con
st { | 518 bool SkPicture::suitableForGpuRasterization(GrContext*, const char **reason) con
st { |
| 507 return fAnalysis.suitableForGpuRasterization(reason, 0); | 519 return fAnalysis.suitableForGpuRasterization(reason, 0); |
| 508 } | 520 } |
| 509 #endif | 521 #endif |
| 510 | 522 |
| 511 bool SkPicture::hasText() const { return fAnalysis.fHasText; } | 523 bool SkPicture::hasText() const { return fAnalysis.fHasText; } |
| 512 bool SkPicture::willPlayBackBitmaps() const { return fAnalysis.fWillPlaybackBitm
aps; } | 524 bool SkPicture::willPlayBackBitmaps() const { return fAnalysis.fWillPlaybackBitm
aps; } |
| 513 int SkPicture::approximateOpCount() const { return fRecord->count(); } | 525 int SkPicture::approximateOpCount() const { return fRecord->count(); } |
| 514 | 526 |
| 515 static int32_t gPictureGenerationID = SK_InvalidGenID; // This will be set at l
ink time. | |
| 516 | |
| 517 static int32_t next_picture_generation_id() { | |
| 518 // Loop in case our global wraps around. | |
| 519 int32_t genID; | |
| 520 do { | |
| 521 genID = sk_atomic_inc(&gPictureGenerationID) + 1; | |
| 522 } while (SK_InvalidGenID == genID); | |
| 523 return genID; | |
| 524 } | |
| 525 | |
| 526 uint32_t SkPicture::uniqueID() const { | |
| 527 if (SK_InvalidGenID == fUniqueID) { | |
| 528 fUniqueID = next_picture_generation_id(); | |
| 529 } | |
| 530 return fUniqueID; | |
| 531 } | |
| 532 | |
| 533 SkPicture::SkPicture(const SkRect& cullRect, SkRecord* record, SkData* drawableP
icts, | 527 SkPicture::SkPicture(const SkRect& cullRect, SkRecord* record, SkData* drawableP
icts, |
| 534 SkBBoxHierarchy* bbh) | 528 SkBBoxHierarchy* bbh) |
| 535 : fCullRect(cullRect) | 529 : fUniqueID(next_picture_generation_id()) |
| 530 , fCullRect(cullRect) |
| 536 , fRecord(record) | 531 , fRecord(record) |
| 537 , fBBH(SkSafeRef(bbh)) | 532 , fBBH(SkSafeRef(bbh)) |
| 538 , fDrawablePicts(SkSafeRef(drawablePicts)) | 533 , fDrawablePicts(SkSafeRef(drawablePicts)) |
| 539 , fAnalysis(*fRecord) { | 534 , fAnalysis(*fRecord) |
| 540 this->needsNewGenID(); | 535 {} |
| 541 } | |
| 542 | 536 |
| 543 // Note that we are assuming that this entry point will only be called from | 537 // Note that we are assuming that this entry point will only be called from |
| 544 // one thread. Currently the only client of this method is | 538 // one thread. Currently the only client of this method is |
| 545 // SkGpuDevice::EXPERIMENTAL_optimize which should be only called from a single | 539 // SkGpuDevice::EXPERIMENTAL_optimize which should be only called from a single |
| 546 // thread. | 540 // thread. |
| 547 void SkPicture::addDeletionListener(DeletionListener* listener) const { | 541 void SkPicture::addDeletionListener(DeletionListener* listener) const { |
| 548 SkASSERT(listener); | 542 SkASSERT(listener); |
| 549 | 543 |
| 550 *fDeletionListeners.append() = SkRef(listener); | 544 *fDeletionListeners.append() = SkRef(listener); |
| 551 } | 545 } |
| 552 | 546 |
| 553 void SkPicture::callDeletionListeners() { | 547 void SkPicture::callDeletionListeners() { |
| 554 for (int i = 0; i < fDeletionListeners.count(); ++i) { | 548 for (int i = 0; i < fDeletionListeners.count(); ++i) { |
| 555 fDeletionListeners[i]->onDeletion(this->uniqueID()); | 549 fDeletionListeners[i]->onDeletion(this->uniqueID()); |
| 556 } | 550 } |
| 557 | 551 |
| 558 fDeletionListeners.unrefAll(); | 552 fDeletionListeners.unrefAll(); |
| 559 } | 553 } |
| OLD | NEW |