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

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

Issue 214413008: Thread picture version through to SkReadBuffer. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: debugger too 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
« no previous file with comments | « include/core/SkReadBuffer.h ('k') | src/core/SkPicturePlayback.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"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 fHeight = src.fHeight; 131 fHeight = src.fHeight;
132 fRecord = NULL; 132 fRecord = NULL;
133 133
134 /* We want to copy the src's playback. However, if that hasn't been built 134 /* We want to copy the src's playback. However, if that hasn't been built
135 yet, we need to fake a call to endRecording() without actually calling 135 yet, we need to fake a call to endRecording() without actually calling
136 it (since it is destructive, and we don't want to change src). 136 it (since it is destructive, and we don't want to change src).
137 */ 137 */
138 if (src.fPlayback) { 138 if (src.fPlayback) {
139 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fPlayback)); 139 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fPlayback));
140 } else if (src.fRecord) { 140 } else if (src.fRecord) {
141 SkPictInfo info;
142 this->createHeader(&info);
141 // here we do a fake src.endRecording() 143 // here we do a fake src.endRecording()
142 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fRecord)); 144 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fRecord, info));
143 } else { 145 } else {
144 fPlayback = NULL; 146 fPlayback = NULL;
145 } 147 }
146 } 148 }
147 149
148 SkPicture::~SkPicture() { 150 SkPicture::~SkPicture() {
149 SkSafeUnref(fRecord); 151 SkSafeUnref(fRecord);
150 SkDELETE(fPlayback); 152 SkDELETE(fPlayback);
151 SkSafeUnref(fAccelData); 153 SkSafeUnref(fAccelData);
152 } 154 }
(...skipping 13 matching lines...) Expand all
166 } 168 }
167 169
168 SkPicture* SkPicture::clone() const { 170 SkPicture* SkPicture::clone() const {
169 SkPicture* clonedPicture = SkNEW(SkPicture); 171 SkPicture* clonedPicture = SkNEW(SkPicture);
170 clone(clonedPicture, 1); 172 clone(clonedPicture, 1);
171 return clonedPicture; 173 return clonedPicture;
172 } 174 }
173 175
174 void SkPicture::clone(SkPicture* pictures, int count) const { 176 void SkPicture::clone(SkPicture* pictures, int count) const {
175 SkPictCopyInfo copyInfo; 177 SkPictCopyInfo copyInfo;
178 SkPictInfo info;
179 this->createHeader(&info);
176 180
177 for (int i = 0; i < count; i++) { 181 for (int i = 0; i < count; i++) {
178 SkPicture* clone = &pictures[i]; 182 SkPicture* clone = &pictures[i];
179 183
180 clone->fWidth = fWidth; 184 clone->fWidth = fWidth;
181 clone->fHeight = fHeight; 185 clone->fHeight = fHeight;
182 SkSafeSetNull(clone->fRecord); 186 SkSafeSetNull(clone->fRecord);
183 SkDELETE(clone->fPlayback); 187 SkDELETE(clone->fPlayback);
184 188
185 /* We want to copy the src's playback. However, if that hasn't been bui lt 189 /* We want to copy the src's playback. However, if that hasn't been bui lt
186 yet, we need to fake a call to endRecording() without actually calli ng 190 yet, we need to fake a call to endRecording() without actually calli ng
187 it (since it is destructive, and we don't want to change src). 191 it (since it is destructive, and we don't want to change src).
188 */ 192 */
189 if (fPlayback) { 193 if (fPlayback) {
190 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fPlayback, &copyI nfo)); 194 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fPlayback, &copyI nfo));
191 } else if (fRecord) { 195 } else if (fRecord) {
192 // here we do a fake src.endRecording() 196 // here we do a fake src.endRecording()
193 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fRecord, true)); 197 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fRecord, info, tr ue));
194 } else { 198 } else {
195 clone->fPlayback = NULL; 199 clone->fPlayback = NULL;
196 } 200 }
197 } 201 }
198 } 202 }
199 203
200 SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() { 204 SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() {
201 static int32_t gNextID = 0; 205 static int32_t gNextID = 0;
202 206
203 int32_t id = sk_atomic_inc(&gNextID); 207 int32_t id = sk_atomic_inc(&gNextID);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 258
255 SkCanvas* SkPicture::getRecordingCanvas() const { 259 SkCanvas* SkPicture::getRecordingCanvas() const {
256 // will be null if we are not recording 260 // will be null if we are not recording
257 return fRecord; 261 return fRecord;
258 } 262 }
259 263
260 void SkPicture::endRecording() { 264 void SkPicture::endRecording() {
261 if (NULL == fPlayback) { 265 if (NULL == fPlayback) {
262 if (NULL != fRecord) { 266 if (NULL != fRecord) {
263 fRecord->endRecording(); 267 fRecord->endRecording();
264 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); 268 SkPictInfo info;
269 this->createHeader(&info);
270 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fRecord, info));
265 SkSafeSetNull(fRecord); 271 SkSafeSetNull(fRecord);
266 } 272 }
267 } 273 }
268 SkASSERT(NULL == fRecord); 274 SkASSERT(NULL == fRecord);
269 } 275 }
270 276
271 const SkPicture::OperationList& SkPicture::OperationList::InvalidList() { 277 const SkPicture::OperationList& SkPicture::OperationList::InvalidList() {
272 static OperationList gInvalid; 278 static OperationList gInvalid;
273 return gInvalid; 279 return gInvalid;
274 } 280 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 SkPicture* SkPicture::CreateFromBuffer(SkReadBuffer& buffer) { 383 SkPicture* SkPicture::CreateFromBuffer(SkReadBuffer& buffer) {
378 SkPictInfo info; 384 SkPictInfo info;
379 385
380 if (!InternalOnly_BufferIsSKP(buffer, &info)) { 386 if (!InternalOnly_BufferIsSKP(buffer, &info)) {
381 return NULL; 387 return NULL;
382 } 388 }
383 389
384 SkPicturePlayback* playback; 390 SkPicturePlayback* playback;
385 // Check to see if there is a playback to recreate. 391 // Check to see if there is a playback to recreate.
386 if (buffer.readBool()) { 392 if (buffer.readBool()) {
387 playback = SkPicturePlayback::CreateFromBuffer(buffer); 393 playback = SkPicturePlayback::CreateFromBuffer(buffer, info);
388 if (NULL == playback) { 394 if (NULL == playback) {
389 return NULL; 395 return NULL;
390 } 396 }
391 } else { 397 } else {
392 playback = NULL; 398 playback = NULL;
393 } 399 }
394 400
395 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight)); 401 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight));
396 } 402 }
397 403
(...skipping 12 matching lines...) Expand all
410 info->fFlags |= SkPictInfo::kScalarIsFloat_Flag; 416 info->fFlags |= SkPictInfo::kScalarIsFloat_Flag;
411 417
412 if (8 == sizeof(void*)) { 418 if (8 == sizeof(void*)) {
413 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag; 419 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag;
414 } 420 }
415 } 421 }
416 422
417 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { 423 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
418 SkPicturePlayback* playback = fPlayback; 424 SkPicturePlayback* playback = fPlayback;
419 425
426 SkPictInfo info;
427 this->createHeader(&info);
420 if (NULL == playback && fRecord) { 428 if (NULL == playback && fRecord) {
421 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); 429 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord, info));
422 } 430 }
423 431
424 SkPictInfo header; 432 stream->write(&info, sizeof(info));
425 this->createHeader(&header);
426 stream->write(&header, sizeof(header));
427 if (playback) { 433 if (playback) {
428 stream->writeBool(true); 434 stream->writeBool(true);
429 playback->serialize(stream, encoder); 435 playback->serialize(stream, encoder);
430 // delete playback if it is a local version (i.e. cons'd up just now) 436 // delete playback if it is a local version (i.e. cons'd up just now)
431 if (playback != fPlayback) { 437 if (playback != fPlayback) {
432 SkDELETE(playback); 438 SkDELETE(playback);
433 } 439 }
434 } else { 440 } else {
435 stream->writeBool(false); 441 stream->writeBool(false);
436 } 442 }
437 } 443 }
438 444
439 void SkPicture::flatten(SkWriteBuffer& buffer) const { 445 void SkPicture::flatten(SkWriteBuffer& buffer) const {
440 SkPicturePlayback* playback = fPlayback; 446 SkPicturePlayback* playback = fPlayback;
441 447
448 SkPictInfo info;
449 this->createHeader(&info);
442 if (NULL == playback && fRecord) { 450 if (NULL == playback && fRecord) {
443 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); 451 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord, info));
444 } 452 }
445 453
446 SkPictInfo header; 454 buffer.writeByteArray(&info, sizeof(info));
447 this->createHeader(&header);
448 buffer.writeByteArray(&header, sizeof(header));
449 if (playback) { 455 if (playback) {
450 buffer.writeBool(true); 456 buffer.writeBool(true);
451 playback->flatten(buffer); 457 playback->flatten(buffer);
452 // delete playback if it is a local version (i.e. cons'd up just now) 458 // delete playback if it is a local version (i.e. cons'd up just now)
453 if (playback != fPlayback) { 459 if (playback != fPlayback) {
454 SkDELETE(playback); 460 SkDELETE(playback);
455 } 461 }
456 } else { 462 } else {
457 buffer.writeBool(false); 463 buffer.writeBool(false);
458 } 464 }
(...skipping 14 matching lines...) Expand all
473 } 479 }
474 480
475 #ifdef SK_BUILD_FOR_ANDROID 481 #ifdef SK_BUILD_FOR_ANDROID
476 void SkPicture::abortPlayback() { 482 void SkPicture::abortPlayback() {
477 if (NULL == fPlayback) { 483 if (NULL == fPlayback) {
478 return; 484 return;
479 } 485 }
480 fPlayback->abort(); 486 fPlayback->abort();
481 } 487 }
482 #endif 488 #endif
OLDNEW
« no previous file with comments | « include/core/SkReadBuffer.h ('k') | src/core/SkPicturePlayback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698