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

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

Issue 1199473002: change old picture serialization to really handle images (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * 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
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPictureRecord.h" 8 #include "SkPictureRecord.h"
9 #include "SkDevice.h" 9 #include "SkDevice.h"
10 #include "SkImage_Base.h" 10 #include "SkImage_Base.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 0, // NOOP - no paint 89 0, // NOOP - no paint
90 0, // BEGIN_GROUP - no paint 90 0, // BEGIN_GROUP - no paint
91 0, // COMMENT - no paint 91 0, // COMMENT - no paint
92 0, // END_GROUP - no paint 92 0, // END_GROUP - no paint
93 1, // DRAWDRRECT - right after op code 93 1, // DRAWDRRECT - right after op code
94 0, // PUSH_CULL - no paint 94 0, // PUSH_CULL - no paint
95 0, // POP_CULL - no paint 95 0, // POP_CULL - no paint
96 1, // DRAW_PATCH - right after op code 96 1, // DRAW_PATCH - right after op code
97 1, // DRAW_PICTURE_MATRIX_PAINT - right after op code 97 1, // DRAW_PICTURE_MATRIX_PAINT - right after op code
98 1, // DRAW_TEXT_BLOB- right after op code 98 1, // DRAW_TEXT_BLOB- right after op code
99 1, // DRAW_IMAGE - right after op code
100 1, // DRAW_IMAGE_RECT - right after op code
99 }; 101 };
100 102
101 SK_COMPILE_ASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, 103 SK_COMPILE_ASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1,
102 need_to_be_in_sync); 104 need_to_be_in_sync);
103 SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM); 105 SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM);
104 106
105 int overflow = 0; 107 int overflow = 0;
106 if (0 != (opSize & ~MASK_24) || opSize == MASK_24) { 108 if (0 != (opSize & ~MASK_24) || opSize == MASK_24) {
107 // This op's size overflows so an extra uint32_t will be written 109 // This op's size overflows so an extra uint32_t will be written
108 // after the op code 110 // after the op code
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 this->addPaintPtr(paint); 561 this->addPaintPtr(paint);
560 this->addBitmap(bitmap); 562 this->addBitmap(bitmap);
561 this->addRectPtr(src); // may be null 563 this->addRectPtr(src); // may be null
562 this->addRect(dst); 564 this->addRect(dst);
563 this->addInt(flags); 565 this->addInt(flags);
564 this->validate(initialOffset, size); 566 this->validate(initialOffset, size);
565 } 567 }
566 568
567 void SkPictureRecord::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, 569 void SkPictureRecord::onDrawImage(const SkImage* image, SkScalar x, SkScalar y,
568 const SkPaint* paint) { 570 const SkPaint* paint) {
569 SkBitmap bm; 571 // op + paint_index + image_index + x + y
570 if (as_IB(image)->getROPixels(&bm)) { 572 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar);
571 this->SkPictureRecord::onDrawBitmap(bm, x, y, paint); 573 size_t initialOffset = this->addDraw(DRAW_IMAGE, &size);
572 } 574 SkASSERT(initialOffset+get_paint_offset(DRAW_IMAGE, size) == fWriter.bytesWr itten());
575 this->addPaintPtr(paint);
576 this->addImage(image);
577 this->addScalar(x);
578 this->addScalar(y);
579 this->validate(initialOffset, size);
573 } 580 }
574 581
575 void SkPictureRecord::onDrawImageRect(const SkImage* image, const SkRect* src, c onst SkRect& dst, 582 void SkPictureRecord::onDrawImageRect(const SkImage* image, const SkRect* src, c onst SkRect& dst,
576 const SkPaint* paint) { 583 const SkPaint* paint) {
577 SkBitmap bm; 584 // id + paint_index + bitmap_index + bool_for_src
578 if (as_IB(image)->getROPixels(&bm)) { 585 size_t size = 4 * kUInt32Size;
579 this->SkPictureRecord::onDrawBitmapRect(bm, src, dst, paint, kNone_DrawB itmapRectFlag); 586 if (src) {
587 size += sizeof(*src); // + rect
580 } 588 }
589 size += sizeof(dst); // + rect
590
591 size_t initialOffset = this->addDraw(DRAW_IMAGE_RECT, &size);
592 SkASSERT(initialOffset+get_paint_offset(DRAW_IMAGE_RECT, size)
593 == fWriter.bytesWritten());
594 this->addPaintPtr(paint);
595 this->addImage(image);
596 this->addRectPtr(src); // may be null
597 this->addRect(dst);
598 this->validate(initialOffset, size);
581 } 599 }
582 600
583 void SkPictureRecord::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& ce nter, 601 void SkPictureRecord::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& ce nter,
584 const SkRect& dst, const SkPaint* paint) { 602 const SkRect& dst, const SkPaint* paint) {
585 // op + paint index + bitmap id + center + dst rect 603 // op + paint index + bitmap id + center + dst rect
586 size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); 604 size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst);
587 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); 605 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size);
588 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_NINE, size) == fWriter.b ytesWritten()); 606 SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_NINE, size) == fWriter.b ytesWritten());
589 this->addPaintPtr(paint); 607 this->addPaintPtr(paint);
590 this->addBitmap(bitmap); 608 this->addBitmap(bitmap);
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 } else { 903 } else {
886 // If you see this block on a memory profile, it's a good opportunity to reduce RAM usage. 904 // If you see this block on a memory profile, it's a good opportunity to reduce RAM usage.
887 SkBitmap copy; 905 SkBitmap copy;
888 bitmap.copyTo(&copy); 906 bitmap.copyTo(&copy);
889 copy.setImmutable(); 907 copy.setImmutable();
890 fBitmaps.push_back(copy); 908 fBitmaps.push_back(copy);
891 } 909 }
892 this->addInt(fBitmaps.count()-1); // Remember, 0-based. 910 this->addInt(fBitmaps.count()-1); // Remember, 0-based.
893 } 911 }
894 912
913 void SkPictureRecord::addImage(const SkImage* image) {
914 int index = fImageRefs.find(image);
915 if (index >= 0) {
916 this->addInt(index);
917 } else {
918 *fImageRefs.append() = SkRef(image);
919 this->addInt(fImageRefs.count()-1);
920 }
921 }
922
895 void SkPictureRecord::addMatrix(const SkMatrix& matrix) { 923 void SkPictureRecord::addMatrix(const SkMatrix& matrix) {
896 fWriter.writeMatrix(matrix); 924 fWriter.writeMatrix(matrix);
897 } 925 }
898 926
899 void SkPictureRecord::addPaintPtr(const SkPaint* paint) { 927 void SkPictureRecord::addPaintPtr(const SkPaint* paint) {
900 fContentInfo.onAddPaintPtr(paint); 928 fContentInfo.onAddPaintPtr(paint);
901 929
902 if (paint) { 930 if (paint) {
903 fPaints.push_back(*paint); 931 fPaints.push_back(*paint);
904 this->addInt(fPaints.count()); 932 this->addInt(fPaints.count());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { 1009 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) {
982 int index = fTextBlobRefs.count(); 1010 int index = fTextBlobRefs.count();
983 *fTextBlobRefs.append() = blob; 1011 *fTextBlobRefs.append() = blob;
984 blob->ref(); 1012 blob->ref();
985 // follow the convention of recording a 1-based index 1013 // follow the convention of recording a 1-based index
986 this->addInt(index + 1); 1014 this->addInt(index + 1);
987 } 1015 }
988 1016
989 /////////////////////////////////////////////////////////////////////////////// 1017 ///////////////////////////////////////////////////////////////////////////////
990 1018
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698