Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 893 | 893 |
| 894 this->validate(initialOffset, size); | 894 this->validate(initialOffset, size); |
| 895 } | 895 } |
| 896 | 896 |
| 897 /////////////////////////////////////////////////////////////////////////////// | 897 /////////////////////////////////////////////////////////////////////////////// |
| 898 | 898 |
| 899 SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info, const SkSurfac eProps&) { | 899 SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info, const SkSurfac eProps&) { |
| 900 return NULL; | 900 return NULL; |
| 901 } | 901 } |
| 902 | 902 |
| 903 int SkPictureRecord::addBitmap(const SkBitmap& bitmap) { | 903 static bool equivalent(const SkBitmap& a, const SkBitmap& b) { |
| 904 if (a.info() != b.info() || a.pixelRefOrigin() != b.pixelRefOrigin()) { | |
| 905 return false; | |
|
reed1
2014/11/12 20:00:55
wonder if we should just compare width/height inst
| |
| 906 } | |
| 907 if (a.pixelRef() == b.pixelRef()) { | |
| 908 return true; | |
| 909 } | |
| 910 SkAutoLockPixels al(a), bl(b); | |
|
reed1
2014/11/12 20:00:56
1. what if a or b is backed by a texture?
2. what
| |
| 911 SkASSERT(a.getSize() == b.getSize()); | |
|
reed1
2014/11/12 20:00:55
a and b can have diff rowbytes, but be "logically"
| |
| 912 return 0 == memcmp(a.getPixels(), b.getPixels(), a.getSize()); | |
|
reed1
2014/11/12 20:00:55
per-scanline is the safe way, given a.rowbytes may
| |
| 913 } | |
| 914 | |
| 915 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) { | |
| 916 // First see if we already have this bitmap. This deduplication should real ly | |
| 917 // only be important for our tests, where bitmaps tend not to be tagged immu table. | |
| 918 // In Chrome (and hopefully Android?) they're typically immutable. | |
| 919 for (int i = 0; i < fBitmaps.count(); i++) { | |
| 920 if (equivalent(fBitmaps[i], bitmap)) { | |
| 921 this->addInt(i); // Unlike the rest, bitmap indices are 0-based. | |
| 922 return; | |
| 923 } | |
| 924 } | |
| 925 // Don't have it. We'll add it to our list, making sure it's tagged as immu table. | |
| 904 if (bitmap.isImmutable()) { | 926 if (bitmap.isImmutable()) { |
| 927 // Shallow copies of bitmaps are cheap, so immutable == fast. | |
| 905 fBitmaps.push_back(bitmap); | 928 fBitmaps.push_back(bitmap); |
| 906 } else { | 929 } else { |
| 930 // If you see this block on a memory profile, it's a good opportunity to reduce RAM usage. | |
| 907 SkBitmap copy; | 931 SkBitmap copy; |
| 908 bitmap.copyTo(©); | 932 bitmap.copyTo(©); |
| 909 copy.setImmutable(); | 933 copy.setImmutable(); |
| 910 fBitmaps.push_back(copy); | 934 fBitmaps.push_back(copy); |
| 911 } | 935 } |
| 912 this->addInt(fBitmaps.count()-1); // Unlike the rest, bitmap indicies are 0 -based. | 936 this->addInt(fBitmaps.count()-1); // Remember, 0-based. |
| 913 return fBitmaps.count(); | |
| 914 } | 937 } |
| 915 | 938 |
| 916 void SkPictureRecord::addMatrix(const SkMatrix& matrix) { | 939 void SkPictureRecord::addMatrix(const SkMatrix& matrix) { |
| 917 fWriter.writeMatrix(matrix); | 940 fWriter.writeMatrix(matrix); |
| 918 } | 941 } |
| 919 | 942 |
| 920 void SkPictureRecord::addPaintPtr(const SkPaint* paint) { | 943 void SkPictureRecord::addPaintPtr(const SkPaint* paint) { |
| 921 fContentInfo.onAddPaintPtr(paint); | 944 fContentInfo.onAddPaintPtr(paint); |
| 922 | 945 |
| 923 if (paint) { | 946 if (paint) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1002 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { | 1025 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { |
| 1003 int index = fTextBlobRefs.count(); | 1026 int index = fTextBlobRefs.count(); |
| 1004 *fTextBlobRefs.append() = blob; | 1027 *fTextBlobRefs.append() = blob; |
| 1005 blob->ref(); | 1028 blob->ref(); |
| 1006 // follow the convention of recording a 1-based index | 1029 // follow the convention of recording a 1-based index |
| 1007 this->addInt(index + 1); | 1030 this->addInt(index + 1); |
| 1008 } | 1031 } |
| 1009 | 1032 |
| 1010 /////////////////////////////////////////////////////////////////////////////// | 1033 /////////////////////////////////////////////////////////////////////////////// |
| 1011 | 1034 |
| OLD | NEW |