| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 SkASSERT(0); | 104 SkASSERT(0); |
| 105 break; | 105 break; |
| 106 } | 106 } |
| 107 SkASSERT(0); | 107 SkASSERT(0); |
| 108 return NULL; | 108 return NULL; |
| 109 } | 109 } |
| 110 #endif | 110 #endif |
| 111 | 111 |
| 112 /////////////////////////////////////////////////////////////////////////////// | 112 /////////////////////////////////////////////////////////////////////////////// |
| 113 | 113 |
| 114 #ifdef SK_SUPPORT_LEGACY_DEFAULT_PICTURE_CTOR |
| 114 // fRecord OK | 115 // fRecord OK |
| 115 SkPicture::SkPicture() | 116 SkPicture::SkPicture() |
| 116 : fWidth(0) | 117 : fWidth(0) |
| 117 , fHeight(0) | 118 , fHeight(0) |
| 118 , fRecordWillPlayBackBitmaps(false) { | 119 , fRecordWillPlayBackBitmaps(false) { |
| 119 this->needsNewGenID(); | 120 this->needsNewGenID(); |
| 120 } | 121 } |
| 122 #endif |
| 121 | 123 |
| 122 // fRecord OK | 124 // fRecord OK |
| 123 SkPicture::SkPicture(int width, int height, | 125 SkPicture::SkPicture(int width, int height, |
| 124 const SkPictureRecord& record, | 126 const SkPictureRecord& record, |
| 125 bool deepCopyOps) | 127 bool deepCopyOps) |
| 126 : fWidth(width) | 128 : fWidth(width) |
| 127 , fHeight(height) | 129 , fHeight(height) |
| 128 , fRecordWillPlayBackBitmaps(false) { | 130 , fRecordWillPlayBackBitmaps(false) { |
| 129 this->needsNewGenID(); | 131 this->needsNewGenID(); |
| 130 | 132 |
| 131 SkPictInfo info; | 133 SkPictInfo info; |
| 132 this->createHeader(&info); | 134 this->createHeader(&info); |
| 133 fData.reset(SkNEW_ARGS(SkPictureData, (record, info, deepCopyOps))); | 135 fData.reset(SkNEW_ARGS(SkPictureData, (record, info, deepCopyOps))); |
| 134 } | 136 } |
| 135 | 137 |
| 136 // Create an SkPictureData-backed SkPicture from an SkRecord. | 138 // Create an SkPictureData-backed SkPicture from an SkRecord. |
| 137 // This for compatibility with serialization code only. This is not cheap. | 139 // This for compatibility with serialization code only. This is not cheap. |
| 138 static SkPicture* backport(const SkRecord& src, int width, int height) { | 140 static SkPicture* backport(const SkRecord& src, int width, int height) { |
| 139 SkPictureRecorder recorder; | 141 SkPictureRecorder recorder; |
| 140 SkRecordDraw(src, recorder.beginRecording(width, height)); | 142 SkRecordDraw(src, recorder.beginRecording(width, height)); |
| 141 return recorder.endRecording(); | 143 return recorder.endRecording(); |
| 142 } | 144 } |
| 143 | 145 |
| 144 // fRecord OK | 146 // fRecord OK |
| 145 SkPicture::~SkPicture() {} | 147 SkPicture::~SkPicture() {} |
| 146 | 148 |
| 147 #ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE | 149 #ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE |
| 148 // fRecord TODO, fix by deleting this method | 150 // fRecord TODO, fix by deleting this method |
| 149 SkPicture* SkPicture::clone() const { | 151 SkPicture* SkPicture::clone() const { |
| 150 SkPicture* clonedPicture = SkNEW(SkPicture); | |
| 151 this->clone(clonedPicture, 1); | |
| 152 return clonedPicture; | |
| 153 } | |
| 154 | 152 |
| 155 // fRecord TODO, fix by deleting this method | 153 SkAutoTDelete<SkPictureData> newData; |
| 156 void SkPicture::clone(SkPicture* pictures, int count) const { | |
| 157 SkPictCopyInfo copyInfo; | |
| 158 | 154 |
| 159 for (int i = 0; i < count; i++) { | 155 if (fData.get()) { |
| 160 SkPicture* clone = &pictures[i]; | 156 SkPictCopyInfo copyInfo; |
| 161 | 157 |
| 162 clone->needsNewGenID(); | 158 int paintCount = SafeCount(fData->fPaints); |
| 163 clone->fWidth = fWidth; | |
| 164 clone->fHeight = fHeight; | |
| 165 clone->fData.reset(NULL); | |
| 166 clone->fRecordWillPlayBackBitmaps = fRecordWillPlayBackBitmaps; | |
| 167 | 159 |
| 168 /* We want to copy the src's playback. However, if that hasn't been bui
lt | 160 /* The alternative to doing this is to have a clone method on the paint
and have it |
| 169 yet, we need to fake a call to endRecording() without actually calli
ng | 161 * make the deep copy of its internal structures as needed. The holdup t
o doing |
| 170 it (since it is destructive, and we don't want to change src). | 162 * that is at this point we would need to pass the SkBitmapHeap so that
we don't |
| 163 * unnecessarily flatten the pixels in a bitmap shader. |
| 171 */ | 164 */ |
| 172 if (fData.get()) { | 165 copyInfo.paintData.setCount(paintCount); |
| 173 if (!copyInfo.initialized) { | |
| 174 int paintCount = SafeCount(fData->fPaints); | |
| 175 | 166 |
| 176 /* The alternative to doing this is to have a clone method on th
e paint and have it | 167 /* Use an SkBitmapHeap to avoid flattening bitmaps in shaders. If there
already is |
| 177 * make the deep copy of its internal structures as needed. The
holdup to doing | 168 * one, use it. If this SkPictureData was created from a stream, fBitmap
Heap |
| 178 * that is at this point we would need to pass the SkBitmapHeap
so that we don't | 169 * will be NULL, so create a new one. |
| 179 * unnecessarily flatten the pixels in a bitmap shader. | 170 */ |
| 180 */ | 171 if (fData->fBitmapHeap.get() == NULL) { |
| 181 copyInfo.paintData.setCount(paintCount); | 172 // FIXME: Put this on the stack inside SkPicture::clone. |
| 173 SkBitmapHeap* heap = SkNEW(SkBitmapHeap); |
| 174 copyInfo.controller.setBitmapStorage(heap); |
| 175 heap->unref(); |
| 176 } else { |
| 177 copyInfo.controller.setBitmapStorage(fData->fBitmapHeap); |
| 178 } |
| 182 | 179 |
| 183 /* Use an SkBitmapHeap to avoid flattening bitmaps in shaders. I
f there already is | 180 SkDEBUGCODE(int heapSize = SafeCount(fData->fBitmapHeap.get());) |
| 184 * one, use it. If this SkPictureData was created from a stream,
fBitmapHeap | 181 for (int i = 0; i < paintCount; i++) { |
| 185 * will be NULL, so create a new one. | 182 if (NeedsDeepCopy(fData->fPaints->at(i))) { |
| 186 */ | 183 copyInfo.paintData[i] = |
| 187 if (fData->fBitmapHeap.get() == NULL) { | 184 SkFlatData::Create<SkPaint::FlatteningTraits>(©Info.cont
roller, |
| 188 // FIXME: Put this on the stack inside SkPicture::clone. | 185 fData->fPaints->at(i), 0); |
| 189 SkBitmapHeap* heap = SkNEW(SkBitmapHeap); | |
| 190 copyInfo.controller.setBitmapStorage(heap); | |
| 191 heap->unref(); | |
| 192 } else { | |
| 193 copyInfo.controller.setBitmapStorage(fData->fBitmapHeap); | |
| 194 } | |
| 195 | 186 |
| 196 SkDEBUGCODE(int heapSize = SafeCount(fData->fBitmapHeap.get());) | 187 } else { |
| 197 for (int i = 0; i < paintCount; i++) { | 188 // this is our sentinel, which we use in the unflatten loop |
| 198 if (NeedsDeepCopy(fData->fPaints->at(i))) { | 189 copyInfo.paintData[i] = NULL; |
| 199 copyInfo.paintData[i] = | 190 } |
| 200 SkFlatData::Create<SkPaint::FlatteningTraits>(©I
nfo.controller, | 191 } |
| 201 fData->fPaints->at
(i), 0); | 192 SkASSERT(SafeCount(fData->fBitmapHeap.get()) == heapSize); |
| 202 | 193 |
| 203 } else { | 194 // needed to create typeface playback |
| 204 // this is our sentinel, which we use in the unflatten l
oop | 195 copyInfo.controller.setupPlaybacks(); |
| 205 copyInfo.paintData[i] = NULL; | |
| 206 } | |
| 207 } | |
| 208 SkASSERT(SafeCount(fData->fBitmapHeap.get()) == heapSize); | |
| 209 | 196 |
| 210 // needed to create typeface playback | 197 newData.reset(SkNEW_ARGS(SkPictureData, (*fData, ©Info))); |
| 211 copyInfo.controller.setupPlaybacks(); | 198 } |
| 212 copyInfo.initialized = true; | |
| 213 } | |
| 214 | 199 |
| 215 clone->fData.reset(SkNEW_ARGS(SkPictureData, (*fData, ©Info))); | 200 SkPicture* clone = SkNEW_ARGS(SkPicture, (newData.detach(), fWidth, fHeight)
); |
| 216 clone->fUniqueID = this->uniqueID(); // need to call method to ensur
e != 0 | 201 clone->fRecordWillPlayBackBitmaps = fRecordWillPlayBackBitmaps; |
| 217 } | 202 clone->fUniqueID = this->uniqueID(); // need to call method to ensure != 0 |
| 218 } | 203 |
| 204 return clone; |
| 219 } | 205 } |
| 220 #endif//SK_SUPPORT_LEGACY_PICTURE_CLONE | 206 #endif//SK_SUPPORT_LEGACY_PICTURE_CLONE |
| 221 | 207 |
| 222 // fRecord OK | 208 // fRecord OK |
| 223 void SkPicture::EXPERIMENTAL_addAccelData(const SkPicture::AccelData* data) cons
t { | 209 void SkPicture::EXPERIMENTAL_addAccelData(const SkPicture::AccelData* data) cons
t { |
| 224 fAccelData.reset(SkRef(data)); | 210 fAccelData.reset(SkRef(data)); |
| 225 } | 211 } |
| 226 | 212 |
| 227 // fRecord OK | 213 // fRecord OK |
| 228 const SkPicture::AccelData* SkPicture::EXPERIMENTAL_getAccelData( | 214 const SkPicture::AccelData* SkPicture::EXPERIMENTAL_getAccelData( |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 } | 485 } |
| 500 | 486 |
| 501 // fRecord OK | 487 // fRecord OK |
| 502 SkPicture::SkPicture(int width, int height, SkRecord* record) | 488 SkPicture::SkPicture(int width, int height, SkRecord* record) |
| 503 : fWidth(width) | 489 : fWidth(width) |
| 504 , fHeight(height) | 490 , fHeight(height) |
| 505 , fRecord(record) | 491 , fRecord(record) |
| 506 , fRecordWillPlayBackBitmaps(SkRecordWillPlaybackBitmaps(*record)) { | 492 , fRecordWillPlayBackBitmaps(SkRecordWillPlaybackBitmaps(*record)) { |
| 507 this->needsNewGenID(); | 493 this->needsNewGenID(); |
| 508 } | 494 } |
| OLD | NEW |