diff options
author | reed <reed@google.com> | 2016-08-10 06:37:43 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-10 06:37:43 -0700 |
commit | d5b88a3dc500c16fc56d472acad01e78d56ef14a (patch) | |
tree | 57b5fd475382ca1cb51ca9ffa714e2707165e214 /src | |
parent | 1bd13ca922d6448d595064faee486eaf3fa56e56 (diff) |
remove support for serializing bitmaps in old format
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2230973002
Review-Url: https://codereview.chromium.org/2230973002
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkPictureData.cpp | 10 | ||||
-rw-r--r-- | src/core/SkPictureRecord.cpp | 113 | ||||
-rw-r--r-- | src/core/SkPictureRecord.h | 22 |
3 files changed, 18 insertions, 127 deletions
diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp index 873c0c4a1d..1e946aaa97 100644 --- a/src/core/SkPictureData.cpp +++ b/src/core/SkPictureData.cpp @@ -43,7 +43,7 @@ SkPictureData::SkPictureData(const SkPictureRecord& record, fContentInfo.set(record.fContentInfo); - fBitmaps = record.fBitmaps; + fBitmaps.reset(); // we never make bitmaps (anymore) during recording fPaints = record.fPaints; fPaths.reset(record.fPaths.count()); @@ -223,12 +223,8 @@ void SkPictureData::WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec) { void SkPictureData::flattenToBuffer(SkWriteBuffer& buffer) const { int i, n; - if ((n = fBitmaps.count()) > 0) { - write_tag_size(buffer, SK_PICT_BITMAP_BUFFER_TAG, n); - for (i = 0; i < n; i++) { - buffer.writeBitmap(fBitmaps[i]); - } - } + // we never record bitmaps anymore, only images + SkASSERT(fBitmaps.count() == 0); if ((n = fPaints.count()) > 0) { write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n); diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp index 776e337ff4..4b31758968 100644 --- a/src/core/SkPictureRecord.cpp +++ b/src/core/SkPictureRecord.cpp @@ -468,36 +468,6 @@ void SkPictureRecord::onDrawPath(const SkPath& path, const SkPaint& paint) { this->validate(initialOffset, size); } -void SkPictureRecord::onDrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, - const SkPaint* paint) { - // op + paint index + bitmap index + left + top - size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); - size_t initialOffset = this->addDraw(DRAW_BITMAP, &size); - this->addPaintPtr(paint); - this->addBitmap(bitmap); - this->addScalar(left); - this->addScalar(top); - this->validate(initialOffset, size); -} - -void SkPictureRecord::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, - const SkPaint* paint, SrcRectConstraint constraint) { - // id + paint index + bitmap index + bool for 'src' + flags - size_t size = 5 * kUInt32Size; - if (src) { - size += sizeof(*src); // + rect - } - size += sizeof(dst); // + rect - - size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT, &size); - this->addPaintPtr(paint); - this->addBitmap(bitmap); - this->addRectPtr(src); // may be null - this->addRect(dst); - this->addInt(constraint); - this->validate(initialOffset, size); -} - void SkPictureRecord::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const SkPaint* paint) { // op + paint_index + image_index + x + y @@ -559,18 +529,6 @@ void SkPictureRecord::onDrawImageNine(const SkImage* img, const SkIRect& center, this->validate(initialOffset, size); } -void SkPictureRecord::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, - const SkRect& dst, const SkPaint* paint) { - // op + paint index + bitmap id + center + dst rect - size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); - size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); - this->addPaintPtr(paint); - this->addBitmap(bitmap); - this->addIRect(center); - this->addRect(dst); - this->validate(initialOffset, size); -} - void SkPictureRecord::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint& paint) { // op + paint index + length + 'length' worth of chars + x + y @@ -887,77 +845,6 @@ sk_sp<SkSurface> SkPictureRecord::onNewSurface(const SkImageInfo& info, const Sk return nullptr; } -// If we already have a stored, can we reuse it instead of also storing b? -static bool equivalent(const SkBitmap& a, const SkBitmap& b) { - if (a.info() != b.info() || a.pixelRefOrigin() != b.pixelRefOrigin()) { - // Requiring a.info() == b.info() may be overkill in some cases (alphatype mismatch), - // but it sure makes things easier to reason about below. - return false; - } - if (a.pixelRef() == b.pixelRef()) { - return true; // Same shape and same pixels -> same bitmap. - } - - // From here down we're going to have to look at the bitmap data, so we require pixelRefs(). - if (!a.pixelRef() || !b.pixelRef()) { - return false; - } - - // If the bitmaps have encoded data, check first before locking pixels so they don't decode. - sk_sp<SkData> encA(a.pixelRef()->refEncodedData()), - encB(b.pixelRef()->refEncodedData()); - if (encA && encB) { - return encA->equals(encB.get()); - } else if (encA || encB) { - return false; // One has encoded data but the other does not. - } - - // As a last resort, we have to look at the pixels. This will read back textures. - SkAutoLockPixels al(a), bl(b); - const char* ap = (const char*)a.getPixels(); - const char* bp = (const char*)b.getPixels(); - if (ap && bp) { - // We check row by row; row bytes might differ. - SkASSERT(a.info() == b.info()); // We checked this above. - SkASSERT(a.info().bytesPerPixel() > 0); // If we have pixelRefs, this better be true. - const SkImageInfo info = a.info(); - const size_t bytesToCompare = info.width() * info.bytesPerPixel(); - for (int row = 0; row < info.height(); row++) { - if (0 != memcmp(ap, bp, bytesToCompare)) { - return false; - } - ap += a.rowBytes(); - bp += b.rowBytes(); - } - return true; - } - return false; // Couldn't get pixels for both bitmaps. -} - -void SkPictureRecord::addBitmap(const SkBitmap& bitmap) { - // First see if we already have this bitmap. This deduplication should really - // only be important for our tests, where bitmaps tend not to be tagged immutable. - // In Chrome (and hopefully Android?) they're typically immutable. - for (int i = 0; i < fBitmaps.count(); i++) { - if (equivalent(fBitmaps[i], bitmap)) { - this->addInt(i); // Unlike the rest, bitmap indices are 0-based. - return; - } - } - // Don't have it. We'll add it to our list, making sure it's tagged as immutable. - if (bitmap.isImmutable()) { - // Shallow copies of bitmaps are cheap, so immutable == fast. - fBitmaps.push_back(bitmap); - } else { - // If you see this block on a memory profile, it's a good opportunity to reduce RAM usage. - SkBitmap copy; - bitmap.copyTo(©); - copy.setImmutable(); - fBitmaps.push_back(copy); - } - this->addInt(fBitmaps.count()-1); // Remember, 0-based. -} - void SkPictureRecord::addImage(const SkImage* image) { int index = fImageRefs.find(image); if (index >= 0) { diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h index 637c46dbf8..6891b78081 100644 --- a/src/core/SkPictureRecord.h +++ b/src/core/SkPictureRecord.h @@ -122,7 +122,6 @@ private: fWriter.writeScalar(scalar); } - void addBitmap(const SkBitmap& bitmap); void addImage(const SkImage*); void addMatrix(const SkMatrix& matrix); void addPaint(const SkPaint& paint) { this->addPaintPtr(&paint); } @@ -190,9 +189,6 @@ protected: void onDrawOval(const SkRect&, const SkPaint&) override; void onDrawRRect(const SkRRect&, const SkPaint&) override; void onDrawPath(const SkPath&, const SkPaint&) override; - void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override; - void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*, - SrcRectConstraint) override; void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override; void onDrawImageLattice(const SkImage*, const SkCanvas::Lattice& lattice, const SkRect& dst, const SkPaint*) override; @@ -200,8 +196,6 @@ protected: const SkPaint*, SrcRectConstraint) override; void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst, const SkPaint*) override; - void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, - const SkPaint*) override; void onDrawVertices(VertexMode vmode, int vertexCount, const SkPoint vertices[], const SkPoint texs[], const SkColor colors[], SkXfermode* xmode, @@ -215,6 +209,20 @@ protected: void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override; + // NEVER CALL -- SkRecord should have already turned these into image draws + void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override { + sk_throw(); + } + void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*, + SrcRectConstraint) override { + sk_throw(); + } + void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, + const SkPaint*) override { + sk_throw(); + } + + #ifdef SK_EXPERIMENTAL_SHADOWING void onDrawShadowedPicture(const SkPicture*, const SkMatrix*, @@ -247,7 +255,7 @@ protected: private: SkPictureContentInfo fContentInfo; - SkTArray<SkBitmap> fBitmaps; +// SkTArray<SkBitmap> fBitmaps; SkTArray<SkPaint> fPaints; struct PathHash { |