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

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

Issue 784643002: Replace EncodeBitmap with an interface. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update comments Created 6 years 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
OLDNEW
1
2 /* 1 /*
3 * Copyright 2007 The Android Open Source Project 2 * Copyright 2007 The Android Open Source Project
4 * 3 *
5 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 5 * found in the LICENSE file.
7 */ 6 */
8 7
9 8
10 #include "SkPictureFlat.h" 9 #include "SkPictureFlat.h"
11 #include "SkPictureData.h" 10 #include "SkPictureData.h"
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 // This for compatibility with serialization code only. This is not cheap. 446 // This for compatibility with serialization code only. This is not cheap.
448 SkPictureData* SkPicture::Backport(const SkRecord& src, const SkPictInfo& info, 447 SkPictureData* SkPicture::Backport(const SkRecord& src, const SkPictInfo& info,
449 SkPicture const* const drawablePicts[], int d rawableCount) { 448 SkPicture const* const drawablePicts[], int d rawableCount) {
450 SkPictureRecord rec(SkISize::Make(info.fCullRect.width(), info.fCullRect.hei ght()), 0/*flags*/); 449 SkPictureRecord rec(SkISize::Make(info.fCullRect.width(), info.fCullRect.hei ght()), 0/*flags*/);
451 rec.beginRecording(); 450 rec.beginRecording();
452 SkRecordDraw(src, &rec, drawablePicts, NULL, drawableCount, NULL/*bbh*/, NULL/*callback*/); 451 SkRecordDraw(src, &rec, drawablePicts, NULL, drawableCount, NULL/*bbh*/, NULL/*callback*/);
453 rec.endRecording(); 452 rec.endRecording();
454 return SkNEW_ARGS(SkPictureData, (rec, info, false/*deep copy ops?*/)); 453 return SkNEW_ARGS(SkPictureData, (rec, info, false/*deep copy ops?*/));
455 } 454 }
456 455
457 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { 456 #ifdef SK_LEGACY_ENCODE_BITMAP
457 // Helper to support the EncodeBitmap version of serialize.
458 // Mimics the old behavior of always accepting the encoded data, and encoding
459 // using EncodeBitmap if there was no encoded data.
460 class EncodeBitmapSerializer : public SkPixelSerializer {
461 public:
462 explicit EncodeBitmapSerializer(SkPicture::EncodeBitmap encoder)
463 : fEncoder(encoder)
464 {
465 SkASSERT(fEncoder);
466 }
467
468 bool useEncodedData(SkData*) SK_OVERRIDE { return true; }
469
470 SkData* encodePixels(const SkImageInfo& info, void* pixels, size_t rowBytes) SK_OVERRIDE {
471 size_t unused;
472 SkBitmap bm;
473 bm.installPixels(info, pixels, rowBytes);
474 return fEncoder(&unused, bm);
475 }
476
477 private:
478 SkPicture::EncodeBitmap fEncoder;
479 };
480
481 void SkPicture::serialize(SkWStream* wStream, SkPicture::EncodeBitmap encoder) c onst {
482 EncodeBitmapSerializer serializer(encoder);
483 this->serialize(wStream, &serializer);
484 }
485
486 #endif
487
488 void SkPicture::serialize(SkWStream* stream, SkPixelSerializer* pixelSerializer) const {
458 SkPictInfo info; 489 SkPictInfo info;
459 this->createHeader(&info); 490 this->createHeader(&info);
460 SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info, this->drawablePic ts(), 491 SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info, this->drawablePic ts(),
461 this->drawableCount())); 492 this->drawableCount()));
462 493
463 stream->write(&info, sizeof(info)); 494 stream->write(&info, sizeof(info));
464 if (data) { 495 if (data) {
465 stream->writeBool(true); 496 stream->writeBool(true);
466 data->serialize(stream, encoder); 497 data->serialize(stream, pixelSerializer);
467 } else { 498 } else {
468 stream->writeBool(false); 499 stream->writeBool(false);
469 } 500 }
470 } 501 }
471 502
472 void SkPicture::flatten(SkWriteBuffer& buffer) const { 503 void SkPicture::flatten(SkWriteBuffer& buffer) const {
473 SkPictInfo info; 504 SkPictInfo info;
474 this->createHeader(&info); 505 this->createHeader(&info);
475 SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info, this->drawablePic ts(), 506 SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info, this->drawablePic ts(),
476 this->drawableCount())); 507 this->drawableCount()));
(...skipping 22 matching lines...) Expand all
499 530
500 SkPicture::SkPicture(const SkRect& cullRect, SkRecord* record, SnapshotArray* dr awablePicts, 531 SkPicture::SkPicture(const SkRect& cullRect, SkRecord* record, SnapshotArray* dr awablePicts,
501 SkBBoxHierarchy* bbh) 532 SkBBoxHierarchy* bbh)
502 : fUniqueID(next_picture_generation_id()) 533 : fUniqueID(next_picture_generation_id())
503 , fCullRect(cullRect) 534 , fCullRect(cullRect)
504 , fRecord(SkRef(record)) 535 , fRecord(SkRef(record))
505 , fBBH(SkSafeRef(bbh)) 536 , fBBH(SkSafeRef(bbh))
506 , fDrawablePicts(drawablePicts) // take ownership 537 , fDrawablePicts(drawablePicts) // take ownership
507 , fAnalysis(*fRecord) 538 , fAnalysis(*fRecord)
508 {} 539 {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698