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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 /////////////////////////////////////////////////////////////////////////////// | 124 /////////////////////////////////////////////////////////////////////////////// |
125 | 125 |
126 SkPicture::SkPicture() | 126 SkPicture::SkPicture() |
127 : fAccelData(NULL) { | 127 : fAccelData(NULL) { |
128 this->needsNewGenID(); | 128 this->needsNewGenID(); |
129 fPlayback = NULL; | 129 fPlayback = NULL; |
130 fWidth = fHeight = 0; | 130 fWidth = fHeight = 0; |
131 } | 131 } |
132 | 132 |
133 // This method makes a SkPicturePlayback object from an in-progress recording. | 133 SkPicture::SkPicture(int width, int height, |
134 // Unfortunately, it does not include the restoreToCount of a real endRecording | 134 SkPictureRecord& record, |
135 // call. | 135 bool deepCopyOps) |
136 SkPicturePlayback* SkPicture::FakeEndRecording(const SkPicture* resourceSrc, | 136 : fWidth(width) |
137 const SkPictureRecord& record) { | 137 , fHeight(height) |
| 138 , fAccelData(NULL) { |
| 139 this->needsNewGenID(); |
| 140 |
| 141 fPathHeap.reset(SkSafeRef(record.pathHeap())); |
| 142 |
138 SkPictInfo info; | 143 SkPictInfo info; |
139 resourceSrc->createHeader(&info); | 144 this->createHeader(&info); |
140 | 145 fPlayback = SkNEW_ARGS(SkPicturePlayback, (this, record, info, deepCopyOps))
; |
141 // FakeEndRecording is only called from partialReplay. For that use case | |
142 // we cannot be certain that the next call to SkWriter32::overwriteTAt | |
143 // will be preceded by an append (i.e., that the required copy on write | |
144 // will occur). In this case just force a deep copy of the operations. | |
145 const bool deepCopyOps = true; | |
146 return SkNEW_ARGS(SkPicturePlayback, (resourceSrc, record, info, deepCopyOps
)); | |
147 } | 146 } |
148 | 147 |
149 SkPicture::SkPicture(const SkPicture& src) | 148 SkPicture::SkPicture(const SkPicture& src) |
150 : INHERITED() | 149 : INHERITED() |
151 , fAccelData(NULL) | 150 , fAccelData(NULL) { |
152 , fContentInfo(src.fContentInfo) { | |
153 this->needsNewGenID(); | 151 this->needsNewGenID(); |
154 fWidth = src.fWidth; | 152 fWidth = src.fWidth; |
155 fHeight = src.fHeight; | 153 fHeight = src.fHeight; |
156 | 154 |
157 /* We want to copy the src's playback. However, if that hasn't been built | 155 /* We want to copy the src's playback. However, if that hasn't been built |
158 yet, we need to fake a call to endRecording() without actually calling | 156 yet, we need to fake a call to endRecording() without actually calling |
159 it (since it is destructive, and we don't want to change src). | 157 it (since it is destructive, and we don't want to change src). |
160 */ | 158 */ |
161 if (src.fPlayback) { | 159 if (src.fPlayback) { |
162 fPlayback = SkNEW_ARGS(SkPicturePlayback, (this, *src.fPlayback)); | 160 fPlayback = SkNEW_ARGS(SkPicturePlayback, (this, *src.fPlayback)); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 SkSafeUnref(fAccelData); | 200 SkSafeUnref(fAccelData); |
203 } | 201 } |
204 | 202 |
205 void SkPicture::swap(SkPicture& other) { | 203 void SkPicture::swap(SkPicture& other) { |
206 SkTSwap(fUniqueID, other.fUniqueID); | 204 SkTSwap(fUniqueID, other.fUniqueID); |
207 SkTSwap(fPlayback, other.fPlayback); | 205 SkTSwap(fPlayback, other.fPlayback); |
208 SkTSwap(fAccelData, other.fAccelData); | 206 SkTSwap(fAccelData, other.fAccelData); |
209 SkTSwap(fWidth, other.fWidth); | 207 SkTSwap(fWidth, other.fWidth); |
210 SkTSwap(fHeight, other.fHeight); | 208 SkTSwap(fHeight, other.fHeight); |
211 fPathHeap.swap(&other.fPathHeap); | 209 fPathHeap.swap(&other.fPathHeap); |
212 fContentInfo.swap(&other.fContentInfo); | |
213 } | 210 } |
214 | 211 |
215 SkPicture* SkPicture::clone() const { | 212 SkPicture* SkPicture::clone() const { |
216 SkPicture* clonedPicture = SkNEW(SkPicture); | 213 SkPicture* clonedPicture = SkNEW(SkPicture); |
217 this->clone(clonedPicture, 1); | 214 this->clone(clonedPicture, 1); |
218 return clonedPicture; | 215 return clonedPicture; |
219 } | 216 } |
220 | 217 |
221 void SkPicture::clone(SkPicture* pictures, int count) const { | 218 void SkPicture::clone(SkPicture* pictures, int count) const { |
222 SkPictCopyInfo copyInfo; | 219 SkPictCopyInfo copyInfo; |
223 | 220 |
224 for (int i = 0; i < count; i++) { | 221 for (int i = 0; i < count; i++) { |
225 SkPicture* clone = &pictures[i]; | 222 SkPicture* clone = &pictures[i]; |
226 | 223 |
227 clone->needsNewGenID(); | 224 clone->needsNewGenID(); |
228 clone->fWidth = fWidth; | 225 clone->fWidth = fWidth; |
229 clone->fHeight = fHeight; | 226 clone->fHeight = fHeight; |
230 SkDELETE(clone->fPlayback); | 227 SkDELETE(clone->fPlayback); |
231 clone->fContentInfo.set(fContentInfo); | |
232 | 228 |
233 /* We want to copy the src's playback. However, if that hasn't been bui
lt | 229 /* We want to copy the src's playback. However, if that hasn't been bui
lt |
234 yet, we need to fake a call to endRecording() without actually calli
ng | 230 yet, we need to fake a call to endRecording() without actually calli
ng |
235 it (since it is destructive, and we don't want to change src). | 231 it (since it is destructive, and we don't want to change src). |
236 */ | 232 */ |
237 if (fPlayback) { | 233 if (fPlayback) { |
238 if (!copyInfo.initialized) { | 234 if (!copyInfo.initialized) { |
239 int paintCount = SafeCount(fPlayback->fPaints); | 235 int paintCount = SafeCount(fPlayback->fPaints); |
240 | 236 |
241 /* The alternative to doing this is to have a clone method on th
e paint and have it | 237 /* The alternative to doing this is to have a clone method on th
e paint and have it |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 if (playback != fPlayback) { | 513 if (playback != fPlayback) { |
518 SkDELETE(playback); | 514 SkDELETE(playback); |
519 } | 515 } |
520 } else { | 516 } else { |
521 buffer.writeBool(false); | 517 buffer.writeBool(false); |
522 } | 518 } |
523 } | 519 } |
524 | 520 |
525 #if SK_SUPPORT_GPU | 521 #if SK_SUPPORT_GPU |
526 bool SkPicture::suitableForGpuRasterization(GrContext* context, const char **rea
son) const { | 522 bool SkPicture::suitableForGpuRasterization(GrContext* context, const char **rea
son) const { |
527 // TODO: the heuristic used here needs to be refined | 523 if (NULL == fPlayback) { |
528 static const int kNumPaintWithPathEffectUsesTol = 1; | 524 if (NULL != reason) { |
529 static const int kNumAAConcavePaths = 5; | 525 *reason = "Missing playback object."; |
| 526 } |
| 527 return false; |
| 528 } |
530 | 529 |
531 SkASSERT(this->numAAHairlineConcavePaths() <= this->numAAConcavePaths()); | 530 return fPlayback->suitableForGpuRasterization(context, reason); |
532 | |
533 bool ret = this->numPaintWithPathEffectUses() < kNumPaintWithPathEffectUsesT
ol && | |
534 (this->numAAConcavePaths()-this->numAAHairlineConcavePaths()) < k
NumAAConcavePaths; | |
535 if (!ret && reason) { | |
536 if (this->numPaintWithPathEffectUses() >= kNumPaintWithPathEffectUsesTol
) | |
537 *reason = "Too many path effects."; | |
538 else if ((this->numAAConcavePaths()-this->numAAHairlineConcavePaths()) >
= kNumAAConcavePaths) | |
539 *reason = "Too many anti-aliased concave paths."; | |
540 else | |
541 *reason = "Unknown reason for GPU unsuitability."; | |
542 } | |
543 return ret; | |
544 } | 531 } |
545 #endif | 532 #endif |
546 | 533 |
547 bool SkPicture::willPlayBackBitmaps() const { | 534 bool SkPicture::willPlayBackBitmaps() const { |
548 if (!fPlayback) { | 535 if (!fPlayback) { |
549 return false; | 536 return false; |
550 } | 537 } |
551 return fPlayback->containsBitmaps(); | 538 return fPlayback->containsBitmaps(); |
552 } | 539 } |
553 | 540 |
(...skipping 16 matching lines...) Expand all Loading... |
570 } while (SK_InvalidGenID == genID); | 557 } while (SK_InvalidGenID == genID); |
571 return genID; | 558 return genID; |
572 } | 559 } |
573 | 560 |
574 uint32_t SkPicture::uniqueID() const { | 561 uint32_t SkPicture::uniqueID() const { |
575 if (SK_InvalidGenID == fUniqueID) { | 562 if (SK_InvalidGenID == fUniqueID) { |
576 fUniqueID = next_picture_generation_id(); | 563 fUniqueID = next_picture_generation_id(); |
577 } | 564 } |
578 return fUniqueID; | 565 return fUniqueID; |
579 } | 566 } |
OLD | NEW |