PDF: Add (low-memory) SkPDFBitmap class
Also: Add SkDeflateWStream and associated unit tests.
SkPDFBitmap is a replacement for SkPDFImage. As of now, it only
supports 8888 bitmaps (the most common case).
SkPDFBitmap takes very little extra memory (aside from refing the
bitmap's pixels), and its emitObject() does not cache any data.
The SkPDFBitmap::Create function will check the canon for duplicates.
This can reduce the size of the output PDF.
Motivation: this gives another ~40% decrease in PDF memory overhead
TODO: Support other ColorTypes and scrap SkPDFImage.
BUG=skia:3030
Review URL: https://codereview.chromium.org/918813002
diff --git a/src/pdf/SkPDFCanon.cpp b/src/pdf/SkPDFCanon.cpp
index 6b52018..268a53a8 100644
--- a/src/pdf/SkPDFCanon.cpp
+++ b/src/pdf/SkPDFCanon.cpp
@@ -6,6 +6,7 @@
*/
#include "SkLazyPtr.h"
+#include "SkPDFBitmap.h"
#include "SkPDFCanon.h"
#include "SkPDFFont.h"
#include "SkPDFGraphicState.h"
@@ -16,10 +17,12 @@
SK_DECLARE_STATIC_MUTEX(gSkPDFCanonFontMutex);
SK_DECLARE_STATIC_MUTEX(gSkPDFCanonShaderMutex);
SK_DECLARE_STATIC_MUTEX(gSkPDFCanonPaintMutex);
+SK_DECLARE_STATIC_MUTEX(gSkPDFCanonBitmapMutex);
SkBaseMutex& SkPDFCanon::GetFontMutex() { return gSkPDFCanonFontMutex; }
SkBaseMutex& SkPDFCanon::GetShaderMutex() { return gSkPDFCanonShaderMutex; }
SkBaseMutex& SkPDFCanon::GetPaintMutex() { return gSkPDFCanonPaintMutex; }
+SkBaseMutex& SkPDFCanon::GetBitmapMutex() { return gSkPDFCanonBitmapMutex; }
SkPDFCanon::SkPDFCanon() {}
@@ -168,3 +171,20 @@
assert_mutex_held(this, gSkPDFCanonPaintMutex);
SkAssertResult(remove_item(&fGraphicStateRecords, pdfGraphicState));
}
+
+////////////////////////////////////////////////////////////////////////////////
+
+SkPDFBitmap* SkPDFCanon::findBitmap(const SkBitmap& bm) const {
+ assert_mutex_held(this, gSkPDFCanonBitmapMutex);
+ return find_item(fBitmapRecords, bm);
+}
+
+void SkPDFCanon::addBitmap(SkPDFBitmap* pdfBitmap) {
+ assert_mutex_held(this, gSkPDFCanonBitmapMutex);
+ fBitmapRecords.push(assert_ptr(pdfBitmap));
+}
+
+void SkPDFCanon::removeBitmap(SkPDFBitmap* pdfBitmap) {
+ assert_mutex_held(this, gSkPDFCanonBitmapMutex);
+ SkAssertResult(remove_item(&fBitmapRecords, pdfBitmap));
+}