Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: src/core/SkPicture.cpp

Issue 366443002: Implement SkRecord::willPlaybackBitmaps, cache in SkPicture (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkRecordAnalysis.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkPictureData.h" 11 #include "SkPictureData.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
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 fData.reset(SkNEW_ARGS(SkPictureData, (record, info, deepCopyOps))); 152 fData.reset(SkNEW_ARGS(SkPictureData, (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 SkPictureData-backed SkPicture from an SkRecord. 163 // Create an SkPictureData-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.fData.get()) { 178 if (NULL != src.fData.get()) {
175 fData.reset(SkNEW_ARGS(SkPictureData, (*src.fData))); 179 fData.reset(SkNEW_ARGS(SkPictureData, (*src.fData)));
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 14 matching lines...) Expand all
197 void SkPicture::clone(SkPicture* pictures, int count) const { 201 void SkPicture::clone(SkPicture* pictures, int count) const {
198 SkPictCopyInfo copyInfo; 202 SkPictCopyInfo copyInfo;
199 203
200 for (int i = 0; i < count; i++) { 204 for (int i = 0; i < count; i++) {
201 SkPicture* clone = &pictures[i]; 205 SkPicture* clone = &pictures[i];
202 206
203 clone->needsNewGenID(); 207 clone->needsNewGenID();
204 clone->fWidth = fWidth; 208 clone->fWidth = fWidth;
205 clone->fHeight = fHeight; 209 clone->fHeight = fHeight;
206 clone->fData.reset(NULL); 210 clone->fData.reset(NULL);
211 clone->fRecordWillPlayBackBitmaps = fRecordWillPlayBackBitmaps;
207 212
208 /* We want to copy the src's playback. However, if that hasn't been bui lt 213 /* We want to copy the src's playback. However, if that hasn't been bui lt
209 yet, we need to fake a call to endRecording() without actually calli ng 214 yet, we need to fake a call to endRecording() without actually calli ng
210 it (since it is destructive, and we don't want to change src). 215 it (since it is destructive, and we don't want to change src).
211 */ 216 */
212 if (fData.get()) { 217 if (fData.get()) {
213 if (!copyInfo.initialized) { 218 if (!copyInfo.initialized) {
214 int paintCount = SafeCount(fData->fPaints); 219 int paintCount = SafeCount(fData->fPaints);
215 220
216 /* The alternative to doing this is to have a clone method on th e paint and have it 221 /* The alternative to doing this is to have a clone method on th e paint and have it
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 if (pInfo != NULL) { 379 if (pInfo != NULL) {
375 *pInfo = info; 380 *pInfo = info;
376 } 381 }
377 return true; 382 return true;
378 } 383 }
379 384
380 // fRecord OK 385 // fRecord OK
381 SkPicture::SkPicture(SkPictureData* data, int width, int height) 386 SkPicture::SkPicture(SkPictureData* data, int width, int height)
382 : fData(data) 387 : fData(data)
383 , fWidth(width) 388 , fWidth(width)
384 , fHeight(height) { 389 , fHeight(height)
390 , fRecordWillPlayBackBitmaps(false) {
385 this->needsNewGenID(); 391 this->needsNewGenID();
386 } 392 }
387 393
388 // fRecord OK 394 // fRecord OK
389 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) { 395 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) {
390 SkPictInfo info; 396 SkPictInfo info;
391 397
392 if (!InternalOnly_StreamIsSKP(stream, &info)) { 398 if (!InternalOnly_StreamIsSKP(stream, &info)) {
393 return NULL; 399 return NULL;
394 } 400 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 if (NULL != reason) { 520 if (NULL != reason) {
515 *reason = "Missing internal data."; 521 *reason = "Missing internal data.";
516 } 522 }
517 return false; 523 return false;
518 } 524 }
519 525
520 return fData->suitableForGpuRasterization(context, reason); 526 return fData->suitableForGpuRasterization(context, reason);
521 } 527 }
522 #endif 528 #endif
523 529
524 // fRecord TODO 530 // fRecord OK
525 bool SkPicture::willPlayBackBitmaps() const { 531 bool SkPicture::willPlayBackBitmaps() const {
532 if (fRecord.get()) {
533 return fRecordWillPlayBackBitmaps;
534 }
526 if (!fData.get()) { 535 if (!fData.get()) {
527 return false; 536 return false;
528 } 537 }
529 return fData->containsBitmaps(); 538 return fData->containsBitmaps();
530 } 539 }
531 540
532 #ifdef SK_BUILD_FOR_ANDROID 541 #ifdef SK_BUILD_FOR_ANDROID
533 // fRecord TODO, fix by switching Android to SkDrawPictureCallback, then deletin g this method 542 // fRecord TODO, fix by switching Android to SkDrawPictureCallback, then deletin g this method
534 void SkPicture::abortPlayback() { 543 void SkPicture::abortPlayback() {
535 if (NULL == fData.get()) { 544 if (NULL == fData.get()) {
(...skipping 20 matching lines...) Expand all
556 if (SK_InvalidGenID == fUniqueID) { 565 if (SK_InvalidGenID == fUniqueID) {
557 fUniqueID = next_picture_generation_id(); 566 fUniqueID = next_picture_generation_id();
558 } 567 }
559 return fUniqueID; 568 return fUniqueID;
560 } 569 }
561 570
562 // fRecord OK 571 // fRecord OK
563 SkPicture::SkPicture(int width, int height, SkRecord* record) 572 SkPicture::SkPicture(int width, int height, SkRecord* record)
564 : fWidth(width) 573 : fWidth(width)
565 , fHeight(height) 574 , fHeight(height)
566 , fRecord(record) { 575 , fRecord(record)
576 , fRecordWillPlayBackBitmaps(SkRecordWillPlaybackBitmaps(*record)) {
567 this->needsNewGenID(); 577 this->needsNewGenID();
568 } 578 }
OLDNEW
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkRecordAnalysis.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698