Chromium Code Reviews| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 } | 110 } |
| 111 #endif | 111 #endif |
| 112 | 112 |
| 113 | 113 |
| 114 /////////////////////////////////////////////////////////////////////////////// | 114 /////////////////////////////////////////////////////////////////////////////// |
| 115 | 115 |
| 116 SkPicture::SkPicture() { | 116 SkPicture::SkPicture() { |
| 117 fRecord = NULL; | 117 fRecord = NULL; |
| 118 fPlayback = NULL; | 118 fPlayback = NULL; |
| 119 fWidth = fHeight = 0; | 119 fWidth = fHeight = 0; |
| 120 fAccelData = NULL; | |
| 120 } | 121 } |
| 121 | 122 |
| 122 SkPicture::SkPicture(const SkPicture& src) : INHERITED() { | 123 SkPicture::SkPicture(const SkPicture& src) |
| 124 : INHERITED() | |
| 125 , fAccelData(NULL) { | |
| 123 fWidth = src.fWidth; | 126 fWidth = src.fWidth; |
| 124 fHeight = src.fHeight; | 127 fHeight = src.fHeight; |
| 125 fRecord = NULL; | 128 fRecord = NULL; |
| 126 | 129 |
| 127 /* We want to copy the src's playback. However, if that hasn't been built | 130 /* We want to copy the src's playback. However, if that hasn't been built |
| 128 yet, we need to fake a call to endRecording() without actually calling | 131 yet, we need to fake a call to endRecording() without actually calling |
| 129 it (since it is destructive, and we don't want to change src). | 132 it (since it is destructive, and we don't want to change src). |
| 130 */ | 133 */ |
| 131 if (src.fPlayback) { | 134 if (src.fPlayback) { |
| 132 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fPlayback)); | 135 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fPlayback)); |
| 133 } else if (src.fRecord) { | 136 } else if (src.fRecord) { |
| 134 // here we do a fake src.endRecording() | 137 // here we do a fake src.endRecording() |
| 135 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fRecord)); | 138 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fRecord)); |
| 136 } else { | 139 } else { |
| 137 fPlayback = NULL; | 140 fPlayback = NULL; |
| 138 } | 141 } |
| 139 } | 142 } |
| 140 | 143 |
| 141 SkPicture::~SkPicture() { | 144 SkPicture::~SkPicture() { |
| 142 SkSafeUnref(fRecord); | 145 SkSafeUnref(fRecord); |
| 143 SkDELETE(fPlayback); | 146 SkDELETE(fPlayback); |
| 147 SkSafeUnref(fAccelData); | |
| 144 } | 148 } |
| 145 | 149 |
| 146 void SkPicture::internalOnly_EnableOpts(bool enableOpts) { | 150 void SkPicture::internalOnly_EnableOpts(bool enableOpts) { |
| 147 if (NULL != fRecord) { | 151 if (NULL != fRecord) { |
| 148 fRecord->internalOnly_EnableOpts(enableOpts); | 152 fRecord->internalOnly_EnableOpts(enableOpts); |
| 149 } | 153 } |
| 150 } | 154 } |
| 151 | 155 |
| 152 void SkPicture::swap(SkPicture& other) { | 156 void SkPicture::swap(SkPicture& other) { |
| 153 SkTSwap(fRecord, other.fRecord); | 157 SkTSwap(fRecord, other.fRecord); |
| 154 SkTSwap(fPlayback, other.fPlayback); | 158 SkTSwap(fPlayback, other.fPlayback); |
| 159 SkTSwap(fAccelData, other.fAccelData); | |
| 155 SkTSwap(fWidth, other.fWidth); | 160 SkTSwap(fWidth, other.fWidth); |
| 156 SkTSwap(fHeight, other.fHeight); | 161 SkTSwap(fHeight, other.fHeight); |
| 157 } | 162 } |
| 158 | 163 |
| 159 SkPicture* SkPicture::clone() const { | 164 SkPicture* SkPicture::clone() const { |
| 160 SkPicture* clonedPicture = SkNEW(SkPicture); | 165 SkPicture* clonedPicture = SkNEW(SkPicture); |
| 161 clone(clonedPicture, 1); | 166 clone(clonedPicture, 1); |
| 162 return clonedPicture; | 167 return clonedPicture; |
| 163 } | 168 } |
| 164 | 169 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 181 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fPlayback, ©I nfo)); | 186 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fPlayback, ©I nfo)); |
| 182 } else if (fRecord) { | 187 } else if (fRecord) { |
| 183 // here we do a fake src.endRecording() | 188 // here we do a fake src.endRecording() |
| 184 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fRecord, true)); | 189 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fRecord, true)); |
| 185 } else { | 190 } else { |
| 186 clone->fPlayback = NULL; | 191 clone->fPlayback = NULL; |
| 187 } | 192 } |
| 188 } | 193 } |
| 189 } | 194 } |
| 190 | 195 |
| 196 SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() { | |
| 197 static int32_t gNextID = 0; | |
| 198 | |
| 199 int32_t id = sk_atomic_inc(&gNextID); | |
| 200 if (id >= 1 << (8 * sizeof(Domain))) { | |
|
bsalomon
2014/03/14 13:59:43
Ben will be so unhappy with you for making these b
| |
| 201 SK_CRASH(); | |
| 202 } | |
| 203 | |
| 204 return static_cast<Domain>(id); | |
| 205 } | |
| 206 | |
| 191 /////////////////////////////////////////////////////////////////////////////// | 207 /////////////////////////////////////////////////////////////////////////////// |
| 192 | 208 |
| 193 SkCanvas* SkPicture::beginRecording(int width, int height, | 209 SkCanvas* SkPicture::beginRecording(int width, int height, |
| 194 uint32_t recordingFlags) { | 210 uint32_t recordingFlags) { |
| 195 if (fPlayback) { | 211 if (fPlayback) { |
| 196 SkDELETE(fPlayback); | 212 SkDELETE(fPlayback); |
| 197 fPlayback = NULL; | 213 fPlayback = NULL; |
| 198 } | 214 } |
| 199 | 215 SkSafeUnref(fAccelData); |
| 200 SkSafeSetNull(fRecord); | 216 SkSafeSetNull(fRecord); |
| 201 | 217 |
| 202 // Must be set before calling createBBoxHierarchy | 218 // Must be set before calling createBBoxHierarchy |
| 203 fWidth = width; | 219 fWidth = width; |
| 204 fHeight = height; | 220 fHeight = height; |
| 205 | 221 |
| 206 const SkISize size = SkISize::Make(width, height); | 222 const SkISize size = SkISize::Make(width, height); |
| 207 | 223 |
| 208 if (recordingFlags & kOptimizeForClippedPlayback_RecordingFlag) { | 224 if (recordingFlags & kOptimizeForClippedPlayback_RecordingFlag) { |
| 209 SkBBoxHierarchy* tree = this->createBBoxHierarchy(); | 225 SkBBoxHierarchy* tree = this->createBBoxHierarchy(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 fRecord->endRecording(); | 259 fRecord->endRecording(); |
| 244 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); | 260 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); |
| 245 SkSafeSetNull(fRecord); | 261 SkSafeSetNull(fRecord); |
| 246 } | 262 } |
| 247 } | 263 } |
| 248 SkASSERT(NULL == fRecord); | 264 SkASSERT(NULL == fRecord); |
| 249 } | 265 } |
| 250 | 266 |
| 251 void SkPicture::draw(SkCanvas* surface, SkDrawPictureCallback* callback) { | 267 void SkPicture::draw(SkCanvas* surface, SkDrawPictureCallback* callback) { |
| 252 this->endRecording(); | 268 this->endRecording(); |
| 253 if (fPlayback) { | 269 if (NULL != fPlayback) { |
| 254 fPlayback->draw(*surface, callback); | 270 fPlayback->draw(*surface, callback); |
| 255 } | 271 } |
| 256 } | 272 } |
| 257 | 273 |
| 258 /////////////////////////////////////////////////////////////////////////////// | 274 /////////////////////////////////////////////////////////////////////////////// |
| 259 | 275 |
| 260 #include "SkStream.h" | 276 #include "SkStream.h" |
| 261 | 277 |
| 262 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; | 278 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; |
| 263 static const size_t kHeaderSize = sizeof(kMagic) + sizeof(SkPictInfo); | 279 static const size_t kHeaderSize = sizeof(kMagic) + sizeof(SkPictInfo); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 | 325 |
| 310 if (pInfo != NULL) { | 326 if (pInfo != NULL) { |
| 311 *pInfo = info; | 327 *pInfo = info; |
| 312 } | 328 } |
| 313 return true; | 329 return true; |
| 314 } | 330 } |
| 315 | 331 |
| 316 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) | 332 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) |
| 317 : fPlayback(playback) | 333 : fPlayback(playback) |
| 318 , fRecord(NULL) | 334 , fRecord(NULL) |
| 335 , fAccelData(NULL) | |
| 319 , fWidth(width) | 336 , fWidth(width) |
| 320 , fHeight(height) {} | 337 , fHeight(height) {} |
| 321 | 338 |
| 322 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) { | 339 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) { |
| 323 SkPictInfo info; | 340 SkPictInfo info; |
| 324 | 341 |
| 325 if (!InternalOnly_StreamIsSKP(stream, &info)) { | 342 if (!InternalOnly_StreamIsSKP(stream, &info)) { |
| 326 return NULL; | 343 return NULL; |
| 327 } | 344 } |
| 328 | 345 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 // delete playback if it is a local version (i.e. cons'd up just now) | 435 // delete playback if it is a local version (i.e. cons'd up just now) |
| 419 if (playback != fPlayback) { | 436 if (playback != fPlayback) { |
| 420 SkDELETE(playback); | 437 SkDELETE(playback); |
| 421 } | 438 } |
| 422 } else { | 439 } else { |
| 423 buffer.writeBool(false); | 440 buffer.writeBool(false); |
| 424 } | 441 } |
| 425 } | 442 } |
| 426 | 443 |
| 427 bool SkPicture::willPlayBackBitmaps() const { | 444 bool SkPicture::willPlayBackBitmaps() const { |
| 428 if (!fPlayback) return false; | 445 if (!fPlayback) { |
| 446 return false; | |
| 447 } | |
| 429 return fPlayback->containsBitmaps(); | 448 return fPlayback->containsBitmaps(); |
| 430 } | 449 } |
| 431 | 450 |
| 432 #ifdef SK_BUILD_FOR_ANDROID | 451 #ifdef SK_BUILD_FOR_ANDROID |
| 433 void SkPicture::abortPlayback() { | 452 void SkPicture::abortPlayback() { |
| 434 if (NULL == fPlayback) { | 453 if (NULL == fPlayback) { |
| 435 return; | 454 return; |
| 436 } | 455 } |
| 437 fPlayback->abort(); | 456 fPlayback->abort(); |
| 438 } | 457 } |
| 439 #endif | 458 #endif |
| OLD | NEW |