change pixelref to not inherit from SkFlattenable
If I can "inline" MallocPixelRef unflatten, then I think we can delete this code. The only caller today should be unflattening in the legacy path for bitmaps.
R=robertphillips@google.com
Author: reed@google.com
Review URL: https://codereview.chromium.org/320873003
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 316878b..e525ea2 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -1292,6 +1292,7 @@
};
void SkBitmap::legacyUnflatten(SkReadBuffer& buffer) {
+#ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE
this->reset();
SkImageInfo info;
@@ -1317,7 +1318,7 @@
origin.fX = buffer.readInt();
origin.fY = buffer.readInt();
size_t offset = origin.fY * rowBytes + origin.fX * info.bytesPerPixel();
- SkPixelRef* pr = buffer.readPixelRef();
+ SkPixelRef* pr = buffer.readFlattenable<SkPixelRef>();
if (!buffer.validate((NULL == pr) ||
(pr->getAllocatedSizeInBytes() >= (offset + this->getSafeSize())))) {
origin.setZero();
@@ -1332,6 +1333,9 @@
sk_throw();
}
}
+#else
+ sk_throw();
+#endif
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp
index d51fb7c..447083a 100644
--- a/src/core/SkMallocPixelRef.cpp
+++ b/src/core/SkMallocPixelRef.cpp
@@ -200,21 +200,7 @@
return this->info().getSafeSize(fRB);
}
-void SkMallocPixelRef::flatten(SkWriteBuffer& buffer) const {
- this->INHERITED::flatten(buffer);
-
- buffer.write32(SkToU32(fRB));
-
- // TODO: replace this bulk write with a chunky one that can trim off any
- // trailing bytes on each scanline (in case rowbytes > width*size)
- size_t size = this->info().getSafeSize(fRB);
- buffer.writeByteArray(fStorage, size);
- buffer.writeBool(fCTable != NULL);
- if (fCTable) {
- fCTable->writeToBuffer(buffer);
- }
-}
-
+#ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE
SkMallocPixelRef::SkMallocPixelRef(SkReadBuffer& buffer)
: INHERITED(buffer, NULL)
, fReleaseProc(sk_free_releaseproc)
@@ -237,6 +223,7 @@
this->setPreLocked(fStorage, fRB, fCTable);
}
+#endif
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp
index 829c3f1..3664dfa 100644
--- a/src/core/SkPixelRef.cpp
+++ b/src/core/SkPixelRef.cpp
@@ -108,6 +108,7 @@
fPreLocked = false;
}
+#ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE
static SkImageInfo read_info(SkReadBuffer& buffer) {
SkImageInfo info;
info.unflatten(buffer);
@@ -130,6 +131,7 @@
fUniqueGenerationID = false; // Conservatively assuming the original still exists.
fPreLocked = false;
}
+#endif
SkPixelRef::~SkPixelRef() {
this->callGenIDChangeListeners();
@@ -159,23 +161,6 @@
#endif
}
-void SkPixelRef::flatten(SkWriteBuffer& buffer) const {
- this->INHERITED::flatten(buffer);
- fInfo.flatten(buffer);
- buffer.writeBool(fIsImmutable);
- // We write the gen ID into the picture for within-process recording. This
- // is safe since the same genID will never refer to two different sets of
- // pixels (barring overflow). However, each process has its own "namespace"
- // of genIDs. So for cross-process recording we write a zero which will
- // trigger assignment of a new genID in playback.
- if (buffer.isCrossProcess()) {
- buffer.writeUInt(0);
- } else {
- buffer.writeUInt(fGenerationID);
- fUniqueGenerationID = false; // Conservative, a copy is probably about to exist.
- }
-}
-
bool SkPixelRef::lockPixels(LockRec* rec) {
SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount);
diff --git a/src/core/SkScaledImageCache.cpp b/src/core/SkScaledImageCache.cpp
index a030248..eda4871 100644
--- a/src/core/SkScaledImageCache.cpp
+++ b/src/core/SkScaledImageCache.cpp
@@ -183,7 +183,9 @@
SkOneShotDiscardablePixelRef(const SkImageInfo&, SkDiscardableMemory*, size_t rowBytes);
~SkOneShotDiscardablePixelRef();
+#ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE
SK_DECLARE_UNFLATTENABLE_OBJECT()
+#endif
protected:
virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
diff --git a/src/lazy/SkCachingPixelRef.h b/src/lazy/SkCachingPixelRef.h
index 9fc71c3..193fe45 100644
--- a/src/lazy/SkCachingPixelRef.h
+++ b/src/lazy/SkCachingPixelRef.h
@@ -48,12 +48,15 @@
virtual SkData* onRefEncodedData() SK_OVERRIDE {
return fImageGenerator->refEncodedData();
}
+
+#ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE
// No need to flatten this object. When flattening an SkBitmap,
// SkWriteBuffer will check the encoded data and write that
// instead.
// Future implementations of SkWriteBuffer will need to
// special case for onRefEncodedData as well.
SK_DECLARE_UNFLATTENABLE_OBJECT()
+#endif
private:
SkImageGenerator* const fImageGenerator;
diff --git a/src/lazy/SkDiscardablePixelRef.h b/src/lazy/SkDiscardablePixelRef.h
index 52a1d6c..ae955d6 100644
--- a/src/lazy/SkDiscardablePixelRef.h
+++ b/src/lazy/SkDiscardablePixelRef.h
@@ -21,7 +21,9 @@
class SkDiscardablePixelRef : public SkPixelRef {
public:
SK_DECLARE_INST_COUNT(SkDiscardablePixelRef)
+#ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE
SK_DECLARE_UNFLATTENABLE_OBJECT()
+#endif
protected:
~SkDiscardablePixelRef();
diff --git a/src/ports/SkGlobalInitialization_default.cpp b/src/ports/SkGlobalInitialization_default.cpp
index b08906a..5c693af 100644
--- a/src/ports/SkGlobalInitialization_default.cpp
+++ b/src/ports/SkGlobalInitialization_default.cpp
@@ -106,7 +106,9 @@
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkMergeImageFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkColorFilterImageFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDownSampleImageFilter)
+#ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkMallocPixelRef)
+#endif
SkArithmeticMode::InitializeFlattenables();
SkBlurMaskFilter::InitializeFlattenables();