OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2007 The Android Open Source Project | 2 * Copyright 2007 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #include "SkPictureFlat.h" | 9 #include "SkPictureFlat.h" |
10 #include "SkPictureData.h" | 10 #include "SkPictureData.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 /** SkRecords visitor to determine heuristically whether or not a SkPicture | 130 /** SkRecords visitor to determine heuristically whether or not a SkPicture |
131 will be performant when rasterized on the GPU. | 131 will be performant when rasterized on the GPU. |
132 */ | 132 */ |
133 struct SkPicture::PathCounter { | 133 struct SkPicture::PathCounter { |
134 SK_CREATE_MEMBER_DETECTOR(paint); | 134 SK_CREATE_MEMBER_DETECTOR(paint); |
135 | 135 |
136 PathCounter() : fNumSlowPathsAndDashEffects(0) {} | 136 PathCounter() : fNumSlowPathsAndDashEffects(0) {} |
137 | 137 |
138 // Recurse into nested pictures. | 138 // Recurse into nested pictures. |
139 void operator()(const SkRecords::DrawPicture& op) { | 139 void operator()(const SkRecords::DrawPicture& op) { |
140 const SkPicture::Analysis& analysis = op.picture->fAnalysis; | 140 const SkPicture::Analysis& analysis = op.picture->analysis(); |
141 fNumSlowPathsAndDashEffects += analysis.fNumSlowPathsAndDashEffects; | 141 fNumSlowPathsAndDashEffects += analysis.fNumSlowPathsAndDashEffects; |
142 } | 142 } |
143 | 143 |
144 void checkPaint(const SkPaint* paint) { | 144 void checkPaint(const SkPaint* paint) { |
145 if (paint && paint->getPathEffect()) { | 145 if (paint && paint->getPathEffect()) { |
146 // Initially assume it's slow. | 146 // Initially assume it's slow. |
147 fNumSlowPathsAndDashEffects++; | 147 fNumSlowPathsAndDashEffects++; |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 buffer.writeRect(info.fCullRect); | 431 buffer.writeRect(info.fCullRect); |
432 buffer.writeUInt(info.fFlags); | 432 buffer.writeUInt(info.fFlags); |
433 if (data) { | 433 if (data) { |
434 buffer.writeBool(true); | 434 buffer.writeBool(true); |
435 data->flatten(buffer); | 435 data->flatten(buffer); |
436 } else { | 436 } else { |
437 buffer.writeBool(false); | 437 buffer.writeBool(false); |
438 } | 438 } |
439 } | 439 } |
440 | 440 |
| 441 const SkPicture::Analysis& SkPicture::analysis() const { |
| 442 auto create = [&](){ return SkNEW_ARGS(Analysis, (*fRecord)); }; |
| 443 return *fAnalysis.get(create); |
| 444 } |
| 445 |
441 #if SK_SUPPORT_GPU | 446 #if SK_SUPPORT_GPU |
442 bool SkPicture::suitableForGpuRasterization(GrContext*, const char **reason) con
st { | 447 bool SkPicture::suitableForGpuRasterization(GrContext*, const char **reason) con
st { |
443 return fAnalysis.suitableForGpuRasterization(reason, 0); | 448 return this->analysis().suitableForGpuRasterization(reason, 0); |
444 } | 449 } |
445 #endif | 450 #endif |
446 | 451 |
447 bool SkPicture::hasText() const { return fAnalysis.fHasText; } | 452 bool SkPicture::hasText() const { return this->analysis().fHasText;
} |
448 bool SkPicture::willPlayBackBitmaps() const { return fAnalysis.fWillPlaybackBitm
aps; } | 453 bool SkPicture::willPlayBackBitmaps() const { return this->analysis().fWillPlayb
ackBitmaps; } |
449 int SkPicture::approximateOpCount() const { return fRecord->count(); } | 454 int SkPicture::approximateOpCount() const { return fRecord->count(); } |
450 | 455 |
451 SkPicture::SkPicture(const SkRect& cullRect, | 456 SkPicture::SkPicture(const SkRect& cullRect, |
452 SkRecord* record, | 457 SkRecord* record, |
453 SnapshotArray* drawablePicts, | 458 SnapshotArray* drawablePicts, |
454 SkBBoxHierarchy* bbh, | 459 SkBBoxHierarchy* bbh, |
455 AccelData* accelData, | 460 AccelData* accelData, |
456 size_t approxBytesUsedBySubPictures) | 461 size_t approxBytesUsedBySubPictures) |
457 : fUniqueID(0) | 462 : fUniqueID(0) |
458 , fCullRect(cullRect) | 463 , fCullRect(cullRect) |
459 , fRecord(record) // Take ownership of caller's ref. | 464 , fRecord(record) // Take ownership of caller's ref. |
460 , fDrawablePicts(drawablePicts) // Take ownership. | 465 , fDrawablePicts(drawablePicts) // Take ownership. |
461 , fBBH(bbh) // Take ownership of caller's ref. | 466 , fBBH(bbh) // Take ownership of caller's ref. |
462 , fAccelData(accelData) // Take ownership of caller's ref. | 467 , fAccelData(accelData) // Take ownership of caller's ref. |
463 , fApproxBytesUsedBySubPictures(approxBytesUsedBySubPictures) | 468 , fApproxBytesUsedBySubPictures(approxBytesUsedBySubPictures) |
464 , fAnalysis(*fRecord) | |
465 {} | 469 {} |
466 | 470 |
467 | 471 |
468 static uint32_t gNextID = 1; | 472 static uint32_t gNextID = 1; |
469 uint32_t SkPicture::uniqueID() const { | 473 uint32_t SkPicture::uniqueID() const { |
470 uint32_t id = sk_atomic_load(&fUniqueID, sk_memory_order_relaxed); | 474 uint32_t id = sk_atomic_load(&fUniqueID, sk_memory_order_relaxed); |
471 while (id == 0) { | 475 while (id == 0) { |
472 uint32_t next = sk_atomic_fetch_add(&gNextID, 1u); | 476 uint32_t next = sk_atomic_fetch_add(&gNextID, 1u); |
473 if (sk_atomic_compare_exchange(&fUniqueID, &id, next, | 477 if (sk_atomic_compare_exchange(&fUniqueID, &id, next, |
474 sk_memory_order_relaxed, | 478 sk_memory_order_relaxed, |
475 sk_memory_order_relaxed)) { | 479 sk_memory_order_relaxed)) { |
476 id = next; | 480 id = next; |
477 } else { | 481 } else { |
478 // sk_atomic_compare_exchange replaced id with the current value of
fUniqueID. | 482 // sk_atomic_compare_exchange replaced id with the current value of
fUniqueID. |
479 } | 483 } |
480 } | 484 } |
481 return id; | 485 return id; |
482 } | 486 } |
OLD | NEW |