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" |
| 11 #include "SkPicturePlayback.h" | 11 #include "SkPicturePlayback.h" |
| 12 #include "SkPictureRecord.h" | 12 #include "SkPictureRecord.h" |
| 13 #include "SkPictureRecorder.h" | 13 #include "SkPictureRecorder.h" |
| 14 | 14 |
| 15 #include "SkBBHFactory.h" | 15 #include "SkBBHFactory.h" |
| 16 #include "SkBitmapDevice.h" | 16 #include "SkBitmapDevice.h" |
| 17 #include "SkCanvas.h" | 17 #include "SkCanvas.h" |
| 18 #include "SkChunkAlloc.h" | 18 #include "SkChunkAlloc.h" |
| 19 #include "SkDrawPictureCallback.h" | 19 #include "SkDrawPictureCallback.h" |
| 20 #include "SkPaintPriv.h" | 20 #include "SkPaintPriv.h" |
| 21 #include "SkPicture.h" | 21 #include "SkPicture.h" |
| 22 #include "SkRecordAnalysis.h" | |
| 22 #include "SkRegion.h" | 23 #include "SkRegion.h" |
| 23 #include "SkStream.h" | 24 #include "SkStream.h" |
| 24 #include "SkTDArray.h" | 25 #include "SkTDArray.h" |
| 25 #include "SkTSearch.h" | 26 #include "SkTSearch.h" |
| 26 #include "SkTime.h" | 27 #include "SkTime.h" |
| 27 | 28 |
| 28 #include "SkReader32.h" | 29 #include "SkReader32.h" |
| 29 #include "SkWriter32.h" | 30 #include "SkWriter32.h" |
| 30 #include "SkRTree.h" | 31 #include "SkRTree.h" |
| 31 #include "SkBBoxHierarchyRecord.h" | 32 #include "SkBBoxHierarchyRecord.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 SkASSERT(perspY == 0); | 126 SkASSERT(perspY == 0); |
| 126 } | 127 } |
| 127 #endif | 128 #endif |
| 128 | 129 |
| 129 | 130 |
| 130 /////////////////////////////////////////////////////////////////////////////// | 131 /////////////////////////////////////////////////////////////////////////////// |
| 131 | 132 |
| 132 // fRecord OK | 133 // fRecord OK |
| 133 SkPicture::SkPicture() | 134 SkPicture::SkPicture() |
| 134 : fWidth(0) | 135 : fWidth(0) |
| 135 , fHeight(0) { | 136 , fHeight(0) |
| 137 , fRecordWillPlayBackBitmaps(false) { | |
| 136 this->needsNewGenID(); | 138 this->needsNewGenID(); |
| 137 } | 139 } |
| 138 | 140 |
| 139 // fRecord OK | 141 // fRecord OK |
| 140 SkPicture::SkPicture(int width, int height, | 142 SkPicture::SkPicture(int width, int height, |
| 141 const SkPictureRecord& record, | 143 const SkPictureRecord& record, |
| 142 bool deepCopyOps) | 144 bool deepCopyOps) |
| 143 : fWidth(width) | 145 : fWidth(width) |
| 144 , fHeight(height) { | 146 , fHeight(height) |
| 147 , fRecordWillPlayBackBitmaps(false) { | |
| 145 this->needsNewGenID(); | 148 this->needsNewGenID(); |
| 146 | 149 |
| 147 SkPictInfo info; | 150 SkPictInfo info; |
| 148 this->createHeader(&info); | 151 this->createHeader(&info); |
| 149 fPlayback.reset(SkNEW_ARGS(SkPicturePlayback, (record, info, deepCopyOps))); | 152 fPlayback.reset(SkNEW_ARGS(SkPicturePlayback, (record, info, deepCopyOps))); |
| 150 } | 153 } |
| 151 | 154 |
| 152 // The simplest / safest way to copy an SkRecord is to replay it into a new one. | 155 // The simplest / safest way to copy an SkRecord is to replay it into a new one. |
| 153 static SkRecord* copy(const SkRecord& src, int width, int height) { | 156 static SkRecord* copy(const SkRecord& src, int width, int height) { |
| 154 SkRecord* dst = SkNEW(SkRecord); | 157 SkRecord* dst = SkNEW(SkRecord); |
| 155 SkRecorder recorder(dst, width, height); | 158 SkRecorder recorder(dst, width, height); |
| 156 SkRecordDraw(src, &recorder); | 159 SkRecordDraw(src, &recorder); |
| 157 return dst; | 160 return dst; |
| 158 } | 161 } |
| 159 | 162 |
| 160 // Create an SkPicturePlayback-backed SkPicture from an SkRecord. | 163 // Create an SkPicturePlayback-backed SkPicture from an SkRecord. |
| 161 // This for compatibility with serialization code only. This is not cheap. | 164 // This for compatibility with serialization code only. This is not cheap. |
| 162 static SkPicture* backport(const SkRecord& src, int width, int height) { | 165 static SkPicture* backport(const SkRecord& src, int width, int height) { |
| 163 SkPictureRecorder recorder; | 166 SkPictureRecorder recorder; |
| 164 SkRecordDraw(src, recorder.beginRecording(width, height)); | 167 SkRecordDraw(src, recorder.beginRecording(width, height)); |
| 165 return recorder.endRecording(); | 168 return recorder.endRecording(); |
| 166 } | 169 } |
| 167 | 170 |
| 168 // fRecord OK | 171 // fRecord OK |
| 169 SkPicture::SkPicture(const SkPicture& src) : INHERITED() { | 172 SkPicture::SkPicture(const SkPicture& src) : INHERITED() { |
| 170 this->needsNewGenID(); | 173 this->needsNewGenID(); |
| 171 fWidth = src.fWidth; | 174 fWidth = src.fWidth; |
| 172 fHeight = src.fHeight; | 175 fHeight = src.fHeight; |
| 176 fRecordWillPlayBackBitmaps = src.fRecordWillPlayBackBitmaps; | |
| 173 | 177 |
| 174 if (NULL != src.fPlayback.get()) { | 178 if (NULL != src.fPlayback.get()) { |
| 175 fPlayback.reset(SkNEW_ARGS(SkPicturePlayback, (*src.fPlayback))); | 179 fPlayback.reset(SkNEW_ARGS(SkPicturePlayback, (*src.fPlayback))); |
| 176 fUniqueID = src.uniqueID(); // need to call method to ensure != 0 | 180 fUniqueID = src.uniqueID(); // need to call method to ensure != 0 |
| 177 } | 181 } |
| 178 | 182 |
| 179 if (NULL != src.fRecord.get()) { | 183 if (NULL != src.fRecord.get()) { |
| 180 fRecord.reset(copy(*src.fRecord, fWidth, fHeight)); | 184 fRecord.reset(copy(*src.fRecord, fWidth, fHeight)); |
| 181 fUniqueID = src.uniqueID(); // need to call method to ensure != 0 | 185 fUniqueID = src.uniqueID(); // need to call method to ensure != 0 |
| 182 } | 186 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 195 // fRecord TODO, fix by deleting this method | 199 // fRecord TODO, fix by deleting this method |
| 196 void SkPicture::clone(SkPicture* pictures, int count) const { | 200 void SkPicture::clone(SkPicture* pictures, int count) const { |
| 197 SkPictCopyInfo copyInfo; | 201 SkPictCopyInfo copyInfo; |
| 198 | 202 |
| 199 for (int i = 0; i < count; i++) { | 203 for (int i = 0; i < count; i++) { |
| 200 SkPicture* clone = &pictures[i]; | 204 SkPicture* clone = &pictures[i]; |
| 201 | 205 |
| 202 clone->needsNewGenID(); | 206 clone->needsNewGenID(); |
| 203 clone->fWidth = fWidth; | 207 clone->fWidth = fWidth; |
| 204 clone->fHeight = fHeight; | 208 clone->fHeight = fHeight; |
| 209 clone->fRecordWillPlayBackBitmaps = fRecordWillPlayBackBitmaps; | |
| 205 clone->fPlayback.reset(NULL); | 210 clone->fPlayback.reset(NULL); |
| 206 | 211 |
| 207 /* We want to copy the src's playback. However, if that hasn't been bui lt | 212 /* We want to copy the src's playback. However, if that hasn't been bui lt |
| 208 yet, we need to fake a call to endRecording() without actually calli ng | 213 yet, we need to fake a call to endRecording() without actually calli ng |
| 209 it (since it is destructive, and we don't want to change src). | 214 it (since it is destructive, and we don't want to change src). |
| 210 */ | 215 */ |
| 211 if (fPlayback.get()) { | 216 if (fPlayback.get()) { |
| 212 if (!copyInfo.initialized) { | 217 if (!copyInfo.initialized) { |
| 213 int paintCount = SafeCount(fPlayback->fPaints); | 218 int paintCount = SafeCount(fPlayback->fPaints); |
| 214 | 219 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 if (pInfo != NULL) { | 377 if (pInfo != NULL) { |
| 373 *pInfo = info; | 378 *pInfo = info; |
| 374 } | 379 } |
| 375 return true; | 380 return true; |
| 376 } | 381 } |
| 377 | 382 |
| 378 // fRecord OK | 383 // fRecord OK |
| 379 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) | 384 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) |
| 380 : fPlayback(playback) | 385 : fPlayback(playback) |
| 381 , fWidth(width) | 386 , fWidth(width) |
| 382 , fHeight(height) { | 387 , fHeight(height) |
| 388 , fRecordWillPlayBackBitmaps(false) { | |
| 383 this->needsNewGenID(); | 389 this->needsNewGenID(); |
| 384 } | 390 } |
| 385 | 391 |
| 386 // fRecord OK | 392 // fRecord OK |
| 387 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) { | 393 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) { |
| 388 SkPictInfo info; | 394 SkPictInfo info; |
| 389 | 395 |
| 390 if (!InternalOnly_StreamIsSKP(stream, &info)) { | 396 if (!InternalOnly_StreamIsSKP(stream, &info)) { |
| 391 return NULL; | 397 return NULL; |
| 392 } | 398 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 if (NULL != reason) { | 518 if (NULL != reason) { |
| 513 *reason = "Missing playback object."; | 519 *reason = "Missing playback object."; |
| 514 } | 520 } |
| 515 return false; | 521 return false; |
| 516 } | 522 } |
| 517 | 523 |
| 518 return fPlayback->suitableForGpuRasterization(context, reason); | 524 return fPlayback->suitableForGpuRasterization(context, reason); |
| 519 } | 525 } |
| 520 #endif | 526 #endif |
| 521 | 527 |
| 522 // fRecord TODO | 528 // fRecord OK |
| 523 bool SkPicture::willPlayBackBitmaps() const { | 529 bool SkPicture::willPlayBackBitmaps() const { |
| 530 if (fRecord.get()) { | |
| 531 return fRecordWillPlayBackBitmaps; | |
| 532 } | |
| 524 if (!fPlayback.get()) { | 533 if (!fPlayback.get()) { |
| 525 return false; | 534 return false; |
| 526 } | 535 } |
| 527 return fPlayback->containsBitmaps(); | 536 return fPlayback->containsBitmaps(); |
| 528 } | 537 } |
| 529 | 538 |
| 530 #ifdef SK_BUILD_FOR_ANDROID | 539 #ifdef SK_BUILD_FOR_ANDROID |
| 531 // fRecord TODO, fix by switching Android to SkDrawPictureCallback, then deletin g this method | 540 // fRecord TODO, fix by switching Android to SkDrawPictureCallback, then deletin g this method |
| 532 void SkPicture::abortPlayback() { | 541 void SkPicture::abortPlayback() { |
| 533 if (NULL == fPlayback.get()) { | 542 if (NULL == fPlayback.get()) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 554 if (SK_InvalidGenID == fUniqueID) { | 563 if (SK_InvalidGenID == fUniqueID) { |
| 555 fUniqueID = next_picture_generation_id(); | 564 fUniqueID = next_picture_generation_id(); |
| 556 } | 565 } |
| 557 return fUniqueID; | 566 return fUniqueID; |
| 558 } | 567 } |
| 559 | 568 |
| 560 // fRecord OK | 569 // fRecord OK |
| 561 SkPicture::SkPicture(int width, int height, SkRecord* record) | 570 SkPicture::SkPicture(int width, int height, SkRecord* record) |
| 562 : fWidth(width) | 571 : fWidth(width) |
| 563 , fHeight(height) | 572 , fHeight(height) |
| 564 , fRecord(record) { | 573 , fRecord(record) |
| 574 , fRecordWillPlayBackBitmaps(record ? SkRecordWillPlaybackBitmaps(*record) : false) { | |
|
mtklein
2014/07/02 15:53:08
You can assume record != NULL here. If you'd like
tomhudson
2014/07/02 19:21:34
Since this is in the initializer, by the time we h
mtklein
2014/07/02 19:23:03
Yeah, so doesn't make much of a difference if we g
| |
| 565 this->needsNewGenID(); | 575 this->needsNewGenID(); |
| 566 } | 576 } |
| OLD | NEW |