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 | 14 |
14 #include "SkBBHFactory.h" | 15 #include "SkBBHFactory.h" |
15 #include "SkBitmapDevice.h" | 16 #include "SkBitmapDevice.h" |
16 #include "SkCanvas.h" | 17 #include "SkCanvas.h" |
17 #include "SkChunkAlloc.h" | 18 #include "SkChunkAlloc.h" |
18 #include "SkDrawPictureCallback.h" | 19 #include "SkDrawPictureCallback.h" |
19 #include "SkPaintPriv.h" | 20 #include "SkPaintPriv.h" |
20 #include "SkPicture.h" | 21 #include "SkPicture.h" |
21 #include "SkRegion.h" | 22 #include "SkRegion.h" |
22 #include "SkStream.h" | 23 #include "SkStream.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 150 } |
150 | 151 |
151 // The simplest / safest way to copy an SkRecord is to replay it into a new one. | 152 // The simplest / safest way to copy an SkRecord is to replay it into a new one. |
152 static SkRecord* copy(const SkRecord& src, int width, int height) { | 153 static SkRecord* copy(const SkRecord& src, int width, int height) { |
153 SkRecord* dst = SkNEW(SkRecord); | 154 SkRecord* dst = SkNEW(SkRecord); |
154 SkRecorder recorder(dst, width, height); | 155 SkRecorder recorder(dst, width, height); |
155 SkRecordDraw(src, &recorder); | 156 SkRecordDraw(src, &recorder); |
156 return dst; | 157 return dst; |
157 } | 158 } |
158 | 159 |
| 160 // Create an SkPicturePlayback-backed SkPicture from an SkRecord. |
| 161 // This for compatibility with serialization code only. This is not cheap. |
| 162 static SkPicture* backport(const SkRecord& src, int width, int height) { |
| 163 SkPictureRecorder recorder; |
| 164 SkRecordDraw(src, recorder.beginRecording(width, height)); |
| 165 return recorder.endRecording(); |
| 166 } |
| 167 |
159 // fRecord OK | 168 // fRecord OK |
160 SkPicture::SkPicture(const SkPicture& src) : INHERITED() { | 169 SkPicture::SkPicture(const SkPicture& src) : INHERITED() { |
161 this->needsNewGenID(); | 170 this->needsNewGenID(); |
162 fWidth = src.fWidth; | 171 fWidth = src.fWidth; |
163 fHeight = src.fHeight; | 172 fHeight = src.fHeight; |
164 | 173 |
165 if (NULL != src.fPlayback.get()) { | 174 if (NULL != src.fPlayback.get()) { |
166 fPlayback.reset(SkNEW_ARGS(SkPicturePlayback, (*src.fPlayback))); | 175 fPlayback.reset(SkNEW_ARGS(SkPicturePlayback, (*src.fPlayback))); |
167 fUniqueID = src.uniqueID(); // need to call method to ensure != 0 | 176 fUniqueID = src.uniqueID(); // need to call method to ensure != 0 |
168 } | 177 } |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 info->fHeight = fHeight; | 438 info->fHeight = fHeight; |
430 info->fFlags = SkPictInfo::kCrossProcess_Flag; | 439 info->fFlags = SkPictInfo::kCrossProcess_Flag; |
431 // TODO: remove this flag, since we're always float (now) | 440 // TODO: remove this flag, since we're always float (now) |
432 info->fFlags |= SkPictInfo::kScalarIsFloat_Flag; | 441 info->fFlags |= SkPictInfo::kScalarIsFloat_Flag; |
433 | 442 |
434 if (8 == sizeof(void*)) { | 443 if (8 == sizeof(void*)) { |
435 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag; | 444 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag; |
436 } | 445 } |
437 } | 446 } |
438 | 447 |
439 // fRecord TODO | 448 // fRecord OK |
440 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { | 449 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { |
| 450 const SkPicturePlayback* playback = fPlayback.get(); |
| 451 |
| 452 // If we're a new-format picture, backport to old format for serialization. |
| 453 SkAutoTDelete<SkPicture> oldFormat; |
| 454 if (NULL == playback && NULL != fRecord.get()) { |
| 455 oldFormat.reset(backport(*fRecord, fWidth, fHeight)); |
| 456 playback = oldFormat->fPlayback.get(); |
| 457 SkASSERT(NULL != playback); |
| 458 } |
| 459 |
441 SkPictInfo info; | 460 SkPictInfo info; |
442 this->createHeader(&info); | 461 this->createHeader(&info); |
443 stream->write(&info, sizeof(info)); | 462 stream->write(&info, sizeof(info)); |
444 | 463 |
445 if (NULL != fPlayback.get()) { | 464 if (NULL != playback) { |
446 stream->writeBool(true); | 465 stream->writeBool(true); |
447 fPlayback->serialize(stream, encoder); | 466 playback->serialize(stream, encoder); |
448 } else { | 467 } else { |
449 stream->writeBool(false); | 468 stream->writeBool(false); |
450 } | 469 } |
451 } | 470 } |
452 | 471 |
453 // fRecord OK | 472 // fRecord OK |
454 void SkPicture::WriteTagSize(SkWriteBuffer& buffer, uint32_t tag, size_t size) { | 473 void SkPicture::WriteTagSize(SkWriteBuffer& buffer, uint32_t tag, size_t size) { |
455 buffer.writeUInt(tag); | 474 buffer.writeUInt(tag); |
456 buffer.writeUInt(SkToU32(size)); | 475 buffer.writeUInt(SkToU32(size)); |
457 } | 476 } |
458 | 477 |
459 // fRecord OK | 478 // fRecord OK |
460 void SkPicture::WriteTagSize(SkWStream* stream, uint32_t tag, size_t size) { | 479 void SkPicture::WriteTagSize(SkWStream* stream, uint32_t tag, size_t size) { |
461 stream->write32(tag); | 480 stream->write32(tag); |
462 stream->write32(SkToU32(size)); | 481 stream->write32(SkToU32(size)); |
463 } | 482 } |
464 | 483 |
465 // fRecord TODO | 484 // fRecord OK |
466 void SkPicture::flatten(SkWriteBuffer& buffer) const { | 485 void SkPicture::flatten(SkWriteBuffer& buffer) const { |
| 486 const SkPicturePlayback* playback = fPlayback.get(); |
| 487 |
| 488 // If we're a new-format picture, backport to old format for serialization. |
| 489 SkAutoTDelete<SkPicture> oldFormat; |
| 490 if (NULL == playback && NULL != fRecord.get()) { |
| 491 oldFormat.reset(backport(*fRecord, fWidth, fHeight)); |
| 492 playback = oldFormat->fPlayback.get(); |
| 493 SkASSERT(NULL != playback); |
| 494 } |
| 495 |
467 SkPictInfo info; | 496 SkPictInfo info; |
468 this->createHeader(&info); | 497 this->createHeader(&info); |
469 buffer.writeByteArray(&info, sizeof(info)); | 498 buffer.writeByteArray(&info, sizeof(info)); |
470 | 499 |
471 if (NULL != fPlayback.get()) { | 500 if (NULL != playback) { |
472 buffer.writeBool(true); | 501 buffer.writeBool(true); |
473 fPlayback->flatten(buffer); | 502 playback->flatten(buffer); |
474 } else { | 503 } else { |
475 buffer.writeBool(false); | 504 buffer.writeBool(false); |
476 } | 505 } |
477 } | 506 } |
478 | 507 |
479 #if SK_SUPPORT_GPU | 508 #if SK_SUPPORT_GPU |
480 // fRecord TODO | 509 // fRecord TODO |
481 bool SkPicture::suitableForGpuRasterization(GrContext* context, const char **rea
son) const { | 510 bool SkPicture::suitableForGpuRasterization(GrContext* context, const char **rea
son) const { |
482 if (NULL == fPlayback.get()) { | 511 if (NULL == fPlayback.get()) { |
483 if (NULL != reason) { | 512 if (NULL != reason) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 return fUniqueID; | 557 return fUniqueID; |
529 } | 558 } |
530 | 559 |
531 // fRecord OK | 560 // fRecord OK |
532 SkPicture::SkPicture(int width, int height, SkRecord* record) | 561 SkPicture::SkPicture(int width, int height, SkRecord* record) |
533 : fWidth(width) | 562 : fWidth(width) |
534 , fHeight(height) | 563 , fHeight(height) |
535 , fRecord(record) { | 564 , fRecord(record) { |
536 this->needsNewGenID(); | 565 this->needsNewGenID(); |
537 } | 566 } |
OLD | NEW |