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

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

Issue 715413002: More cleanup: streamline paths and bitmaps. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 1 month 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 | « src/core/SkPictureRecord.h ('k') | no next file » | 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 * 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 "SkPatchUtils.h" 10 #include "SkPatchUtils.h"
(...skipping 13 matching lines...) Expand all
24 static int const kUInt32Size = 4; 24 static int const kUInt32Size = 4;
25 25
26 static const uint32_t kSaveSize = kUInt32Size; 26 static const uint32_t kSaveSize = kUInt32Size;
27 #ifdef SK_DEBUG 27 #ifdef SK_DEBUG
28 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; 28 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size;
29 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect ); 29 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect );
30 #endif//SK_DEBUG 30 #endif//SK_DEBUG
31 31
32 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) 32 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags)
33 : INHERITED(dimensions.width(), dimensions.height()) 33 : INHERITED(dimensions.width(), dimensions.height())
34 , fRecordFlags(flags) { 34 , fFirstSavedLayerIndex(kNoSavedLayerIndex)
35 35 , fRecordFlags(flags)
36 fBitmapHeap = SkNEW(SkBitmapHeap); 36 , fInitialSaveCount(kNoInitialSave) {
37
38 fFirstSavedLayerIndex = kNoSavedLayerIndex;
39 fInitialSaveCount = kNoInitialSave;
40 } 37 }
41 38
42 SkPictureRecord::~SkPictureRecord() { 39 SkPictureRecord::~SkPictureRecord() {
43 SkSafeUnref(fBitmapHeap);
44 fPictureRefs.unrefAll(); 40 fPictureRefs.unrefAll();
45 fTextBlobRefs.unrefAll(); 41 fTextBlobRefs.unrefAll();
46 } 42 }
47 43
48 /////////////////////////////////////////////////////////////////////////////// 44 ///////////////////////////////////////////////////////////////////////////////
49 45
50 #ifdef SK_DEBUG 46 #ifdef SK_DEBUG
51 // Return the offset of the paint inside a given op's byte stream. A zero 47 // Return the offset of the paint inside a given op's byte stream. A zero
52 // return value means there is no paint (and you really shouldn't be calling 48 // return value means there is no paint (and you really shouldn't be calling
53 // this method) 49 // this method)
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 this->validate(initialOffset, size); 894 this->validate(initialOffset, size);
899 } 895 }
900 896
901 /////////////////////////////////////////////////////////////////////////////// 897 ///////////////////////////////////////////////////////////////////////////////
902 898
903 SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info, const SkSurfac eProps&) { 899 SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info, const SkSurfac eProps&) {
904 return NULL; 900 return NULL;
905 } 901 }
906 902
907 int SkPictureRecord::addBitmap(const SkBitmap& bitmap) { 903 int SkPictureRecord::addBitmap(const SkBitmap& bitmap) {
908 const int index = fBitmapHeap->insert(bitmap); 904 if (bitmap.isImmutable()) {
909 // In debug builds, a bad return value from insert() will crash, allowing fo r debugging. In 905 fBitmaps.push_back(bitmap);
910 // release builds, the invalid value will be recorded so that the reader wil l know that there 906 } else {
911 // was a problem. 907 SkBitmap copy;
912 SkASSERT(index != SkBitmapHeap::INVALID_SLOT); 908 bitmap.copyTo(&copy);
913 this->addInt(index); 909 copy.setImmutable();
914 return index; 910 fBitmaps.push_back(copy);
911 }
912 this->addInt(fBitmaps.count()-1); // Unlike the rest, bitmap indicies are 0 -based.
913 return fBitmaps.count();
915 } 914 }
916 915
917 void SkPictureRecord::addMatrix(const SkMatrix& matrix) { 916 void SkPictureRecord::addMatrix(const SkMatrix& matrix) {
918 fWriter.writeMatrix(matrix); 917 fWriter.writeMatrix(matrix);
919 } 918 }
920 919
921 void SkPictureRecord::addPaintPtr(const SkPaint* paint) { 920 void SkPictureRecord::addPaintPtr(const SkPaint* paint) {
922 fContentInfo.onAddPaintPtr(paint); 921 fContentInfo.onAddPaintPtr(paint);
923 922
924 if (paint) { 923 if (paint) {
925 fPaints.push_back(*paint); 924 fPaints.push_back(*paint);
926 this->addInt(fPaints.count()); 925 this->addInt(fPaints.count());
927 } else { 926 } else {
928 this->addInt(0); 927 this->addInt(0);
929 } 928 }
930 } 929 }
931 930
932 int SkPictureRecord::addPathToHeap(const SkPath& path) { 931 int SkPictureRecord::addPathToHeap(const SkPath& path) {
933 if (NULL == fPathHeap) { 932 fPaths.push_back(path);
934 fPathHeap.reset(SkNEW(SkPathHeap)); 933 return fPaths.count();
935 }
936 #ifdef SK_DEDUP_PICTURE_PATHS
937 return fPathHeap->insert(path);
938 #else
939 return fPathHeap->append(path);
940 #endif
941 } 934 }
942 935
943 void SkPictureRecord::addPath(const SkPath& path) { 936 void SkPictureRecord::addPath(const SkPath& path) {
944 this->addInt(this->addPathToHeap(path)); 937 this->addInt(this->addPathToHeap(path));
945 } 938 }
946 939
947 void SkPictureRecord::addPatch(const SkPoint cubics[12]) { 940 void SkPictureRecord::addPatch(const SkPoint cubics[12]) {
948 fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint)); 941 fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint));
949 } 942 }
950 943
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { 1002 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) {
1010 int index = fTextBlobRefs.count(); 1003 int index = fTextBlobRefs.count();
1011 *fTextBlobRefs.append() = blob; 1004 *fTextBlobRefs.append() = blob;
1012 blob->ref(); 1005 blob->ref();
1013 // follow the convention of recording a 1-based index 1006 // follow the convention of recording a 1-based index
1014 this->addInt(index + 1); 1007 this->addInt(index + 1);
1015 } 1008 }
1016 1009
1017 /////////////////////////////////////////////////////////////////////////////// 1010 ///////////////////////////////////////////////////////////////////////////////
1018 1011
OLDNEW
« no previous file with comments | « src/core/SkPictureRecord.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698