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

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

Issue 197123003: Proposed SkCanvas API for preLoading textures to VRAM v2.0 (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: retry upload Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkDevice.cpp ('k') | src/gpu/SkGpuDevice.cpp » ('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"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
181 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fPlayback, &copyI nfo)); 186 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fPlayback, &copyI 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))) {
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
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 279
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 if (pInfo != NULL) { 319 if (pInfo != NULL) {
304 *pInfo = info; 320 *pInfo = info;
305 } 321 }
306 return true; 322 return true;
307 } 323 }
308 324
309 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) 325 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height)
310 : fPlayback(playback) 326 : fPlayback(playback)
311 , fRecord(NULL) 327 , fRecord(NULL)
312 , fWidth(width) 328 , fWidth(width)
313 , fHeight(height) {} 329 , fHeight(height)
330 , fAccelData(NULL) {}
314 331
315 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) { 332 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) {
316 SkPictInfo info; 333 SkPictInfo info;
317 334
318 if (!InternalOnly_StreamIsSKP(stream, &info)) { 335 if (!InternalOnly_StreamIsSKP(stream, &info)) {
319 return NULL; 336 return NULL;
320 } 337 }
321 338
322 SkPicturePlayback* playback; 339 SkPicturePlayback* playback;
323 // Check to see if there is a playback to recreate. 340 // Check to see if there is a playback to recreate.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 // delete playback if it is a local version (i.e. cons'd up just now) 428 // delete playback if it is a local version (i.e. cons'd up just now)
412 if (playback != fPlayback) { 429 if (playback != fPlayback) {
413 SkDELETE(playback); 430 SkDELETE(playback);
414 } 431 }
415 } else { 432 } else {
416 buffer.writeBool(false); 433 buffer.writeBool(false);
417 } 434 }
418 } 435 }
419 436
420 bool SkPicture::willPlayBackBitmaps() const { 437 bool SkPicture::willPlayBackBitmaps() const {
421 if (!fPlayback) return false; 438 if (!fPlayback) {
439 return false;
440 }
422 return fPlayback->containsBitmaps(); 441 return fPlayback->containsBitmaps();
423 } 442 }
424 443
425 #ifdef SK_BUILD_FOR_ANDROID 444 #ifdef SK_BUILD_FOR_ANDROID
426 void SkPicture::abortPlayback() { 445 void SkPicture::abortPlayback() {
427 if (NULL == fPlayback) { 446 if (NULL == fPlayback) {
428 return; 447 return;
429 } 448 }
430 fPlayback->abort(); 449 fPlayback->abort();
431 } 450 }
432 #endif 451 #endif
OLDNEW
« no previous file with comments | « src/core/SkDevice.cpp ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698