| 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 24 matching lines...) Expand all Loading... |
| 189 } | 194 } |
| 190 | 195 |
| 191 /////////////////////////////////////////////////////////////////////////////// | 196 /////////////////////////////////////////////////////////////////////////////// |
| 192 | 197 |
| 193 SkCanvas* SkPicture::beginRecording(int width, int height, | 198 SkCanvas* SkPicture::beginRecording(int width, int height, |
| 194 uint32_t recordingFlags) { | 199 uint32_t recordingFlags) { |
| 195 if (fPlayback) { | 200 if (fPlayback) { |
| 196 SkDELETE(fPlayback); | 201 SkDELETE(fPlayback); |
| 197 fPlayback = NULL; | 202 fPlayback = NULL; |
| 198 } | 203 } |
| 199 | 204 SkSafeUnref(fAccelData); |
| 200 SkSafeSetNull(fRecord); | 205 SkSafeSetNull(fRecord); |
| 201 | 206 |
| 202 // Must be set before calling createBBoxHierarchy | 207 // Must be set before calling createBBoxHierarchy |
| 203 fWidth = width; | 208 fWidth = width; |
| 204 fHeight = height; | 209 fHeight = height; |
| 205 | 210 |
| 206 const SkISize size = SkISize::Make(width, height); | 211 const SkISize size = SkISize::Make(width, height); |
| 207 | 212 |
| 208 if (recordingFlags & kOptimizeForClippedPlayback_RecordingFlag) { | 213 if (recordingFlags & kOptimizeForClippedPlayback_RecordingFlag) { |
| 209 SkBBoxHierarchy* tree = this->createBBoxHierarchy(); | 214 SkBBoxHierarchy* tree = this->createBBoxHierarchy(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 fRecord->endRecording(); | 248 fRecord->endRecording(); |
| 244 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); | 249 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); |
| 245 SkSafeSetNull(fRecord); | 250 SkSafeSetNull(fRecord); |
| 246 } | 251 } |
| 247 } | 252 } |
| 248 SkASSERT(NULL == fRecord); | 253 SkASSERT(NULL == fRecord); |
| 249 } | 254 } |
| 250 | 255 |
| 251 void SkPicture::draw(SkCanvas* surface, SkDrawPictureCallback* callback) { | 256 void SkPicture::draw(SkCanvas* surface, SkDrawPictureCallback* callback) { |
| 252 this->endRecording(); | 257 this->endRecording(); |
| 253 if (fPlayback) { | 258 if (NULL != fPlayback) { |
| 254 fPlayback->draw(*surface, callback); | 259 fPlayback->draw(*surface, callback); |
| 255 } | 260 } |
| 256 } | 261 } |
| 257 | 262 |
| 258 /////////////////////////////////////////////////////////////////////////////// | 263 /////////////////////////////////////////////////////////////////////////////// |
| 259 | 264 |
| 260 #include "SkStream.h" | 265 #include "SkStream.h" |
| 261 | 266 |
| 262 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; | 267 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; |
| 263 static const size_t kHeaderSize = sizeof(kMagic) + sizeof(SkPictInfo); | 268 static const size_t kHeaderSize = sizeof(kMagic) + sizeof(SkPictInfo); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 314 |
| 310 if (pInfo != NULL) { | 315 if (pInfo != NULL) { |
| 311 *pInfo = info; | 316 *pInfo = info; |
| 312 } | 317 } |
| 313 return true; | 318 return true; |
| 314 } | 319 } |
| 315 | 320 |
| 316 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) | 321 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) |
| 317 : fPlayback(playback) | 322 : fPlayback(playback) |
| 318 , fRecord(NULL) | 323 , fRecord(NULL) |
| 324 , fAccelData(NULL) |
| 319 , fWidth(width) | 325 , fWidth(width) |
| 320 , fHeight(height) {} | 326 , fHeight(height) {} |
| 321 | 327 |
| 322 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro
c) { | 328 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro
c) { |
| 323 SkPictInfo info; | 329 SkPictInfo info; |
| 324 | 330 |
| 325 if (!InternalOnly_StreamIsSKP(stream, &info)) { | 331 if (!InternalOnly_StreamIsSKP(stream, &info)) { |
| 326 return NULL; | 332 return NULL; |
| 327 } | 333 } |
| 328 | 334 |
| (...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) | 424 // delete playback if it is a local version (i.e. cons'd up just now) |
| 419 if (playback != fPlayback) { | 425 if (playback != fPlayback) { |
| 420 SkDELETE(playback); | 426 SkDELETE(playback); |
| 421 } | 427 } |
| 422 } else { | 428 } else { |
| 423 buffer.writeBool(false); | 429 buffer.writeBool(false); |
| 424 } | 430 } |
| 425 } | 431 } |
| 426 | 432 |
| 427 bool SkPicture::willPlayBackBitmaps() const { | 433 bool SkPicture::willPlayBackBitmaps() const { |
| 428 if (!fPlayback) return false; | 434 if (!fPlayback) { |
| 435 return false; |
| 436 } |
| 429 return fPlayback->containsBitmaps(); | 437 return fPlayback->containsBitmaps(); |
| 430 } | 438 } |
| 431 | 439 |
| 432 #ifdef SK_BUILD_FOR_ANDROID | 440 #ifdef SK_BUILD_FOR_ANDROID |
| 433 void SkPicture::abortPlayback() { | 441 void SkPicture::abortPlayback() { |
| 434 if (NULL == fPlayback) { | 442 if (NULL == fPlayback) { |
| 435 return; | 443 return; |
| 436 } | 444 } |
| 437 fPlayback->abort(); | 445 fPlayback->abort(); |
| 438 } | 446 } |
| 439 #endif | 447 #endif |
| OLD | NEW |