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; | |
mtklein
2014/11/21 15:51:56
If find the loop below less clear without "= SK_In
reed1
2014/11/21 15:56:57
Done.
| |
49 static int32_t next_picture_generation_id() { | |
50 // Loop in case our global wraps around. | |
51 int32_t genID; | |
52 do { | |
53 genID = sk_atomic_inc(&gPictureGenerationID) + 1; | |
54 } while (SK_InvalidGenID == genID); | |
55 return genID; | |
56 } | |
57 | |
48 /////////////////////////////////////////////////////////////////////////////// | 58 /////////////////////////////////////////////////////////////////////////////// |
49 | 59 |
50 namespace { | 60 namespace { |
51 | 61 |
52 // Some commands have a paint, some have an optional paint. Either way, get bac k a pointer. | 62 // 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; } | 63 static const SkPaint* AsPtr(const SkPaint& p) { return &p; } |
54 static const SkPaint* AsPtr(const SkRecords::Optional<SkPaint>& p) { return p; } | 64 static const SkPaint* AsPtr(const SkRecords::Optional<SkPaint>& p) { return p; } |
55 | 65 |
56 /** SkRecords visitor to determine whether an instance may require an | 66 /** SkRecords visitor to determine whether an instance may require an |
57 "external" bitmap to rasterize. May return false positives. | 67 "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 | 515 #if SK_SUPPORT_GPU |
506 bool SkPicture::suitableForGpuRasterization(GrContext*, const char **reason) con st { | 516 bool SkPicture::suitableForGpuRasterization(GrContext*, const char **reason) con st { |
507 return fAnalysis.suitableForGpuRasterization(reason, 0); | 517 return fAnalysis.suitableForGpuRasterization(reason, 0); |
508 } | 518 } |
509 #endif | 519 #endif |
510 | 520 |
511 bool SkPicture::hasText() const { return fAnalysis.fHasText; } | 521 bool SkPicture::hasText() const { return fAnalysis.fHasText; } |
512 bool SkPicture::willPlayBackBitmaps() const { return fAnalysis.fWillPlaybackBitm aps; } | 522 bool SkPicture::willPlayBackBitmaps() const { return fAnalysis.fWillPlaybackBitm aps; } |
513 int SkPicture::approximateOpCount() const { return fRecord->count(); } | 523 int SkPicture::approximateOpCount() const { return fRecord->count(); } |
514 | 524 |
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, | 525 SkPicture::SkPicture(const SkRect& cullRect, SkRecord* record, SkData* drawableP icts, |
534 SkBBoxHierarchy* bbh) | 526 SkBBoxHierarchy* bbh) |
535 : fCullRect(cullRect) | 527 : fUniqueID(next_picture_generation_id()) |
528 , fCullRect(cullRect) | |
536 , fRecord(record) | 529 , fRecord(record) |
537 , fBBH(SkSafeRef(bbh)) | 530 , fBBH(SkSafeRef(bbh)) |
538 , fDrawablePicts(SkSafeRef(drawablePicts)) | 531 , fDrawablePicts(SkSafeRef(drawablePicts)) |
539 , fAnalysis(*fRecord) { | 532 , fAnalysis(*fRecord) |
540 this->needsNewGenID(); | 533 {} |
541 } | |
542 | 534 |
543 // Note that we are assuming that this entry point will only be called from | 535 // 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 | 536 // one thread. Currently the only client of this method is |
545 // SkGpuDevice::EXPERIMENTAL_optimize which should be only called from a single | 537 // SkGpuDevice::EXPERIMENTAL_optimize which should be only called from a single |
546 // thread. | 538 // thread. |
547 void SkPicture::addDeletionListener(DeletionListener* listener) const { | 539 void SkPicture::addDeletionListener(DeletionListener* listener) const { |
548 SkASSERT(listener); | 540 SkASSERT(listener); |
549 | 541 |
550 *fDeletionListeners.append() = SkRef(listener); | 542 *fDeletionListeners.append() = SkRef(listener); |
551 } | 543 } |
552 | 544 |
553 void SkPicture::callDeletionListeners() { | 545 void SkPicture::callDeletionListeners() { |
554 for (int i = 0; i < fDeletionListeners.count(); ++i) { | 546 for (int i = 0; i < fDeletionListeners.count(); ++i) { |
555 fDeletionListeners[i]->onDeletion(this->uniqueID()); | 547 fDeletionListeners[i]->onDeletion(this->uniqueID()); |
556 } | 548 } |
557 | 549 |
558 fDeletionListeners.unrefAll(); | 550 fDeletionListeners.unrefAll(); |
559 } | 551 } |
OLD | NEW |