aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf/SkPDFCanon.h
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2016-03-25 11:57:49 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-25 11:57:49 -0700
commita50151dcb5a0b8bfdef383e363e519c91d2d2c7a (patch)
tree65adb59528a3fa047f939129d6b3c764be202e1c /src/pdf/SkPDFCanon.h
parentb3c9e4faaaea99ca8c428f0cadc2945c330f1461 (diff)
SkPDF: draw{Image,Bitmap} always serializes early
Before this change, the PDFCanon held a map from BitmapKeys to SkImages for de-duping bitmaps. Even if the PDFDocument serialized images early, the Canon still held a ref to that image inside the map. With this change, the Canon holds a single map from BitmapKeys to PDFObjects. Now, Images are only held by the PDFObject, which the document serializes and drops early. This change also: - Moves SkBitmapKey into its own header (for possible reuse); it now can operate with images as well as bitmaps. - Creates SkImageBitmap, which wraps a pointer to a bitmap or an image and abstracts out some common tasks so that drawBitmap and drawImage behave the same. - Modifies SkPDFCreateBitmapObject to take and return a sk_sp<T>, not a T*. - Refactors SkPDFDevice::internalDrawImage to use bitmaps or images (via a SkImageBitmap). - Turns on pre-serialization of all images. BUG=skia:5087 GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1829693002 Review URL: https://codereview.chromium.org/1829693002
Diffstat (limited to 'src/pdf/SkPDFCanon.h')
-rw-r--r--src/pdf/SkPDFCanon.h30
1 files changed, 8 insertions, 22 deletions
diff --git a/src/pdf/SkPDFCanon.h b/src/pdf/SkPDFCanon.h
index 9ca8a261d6..0af0bbf88a 100644
--- a/src/pdf/SkPDFCanon.h
+++ b/src/pdf/SkPDFCanon.h
@@ -7,39 +7,26 @@
#ifndef SkPDFCanon_DEFINED
#define SkPDFCanon_DEFINED
-#include "SkBitmap.h"
#include "SkPDFGraphicState.h"
#include "SkPDFShader.h"
#include "SkPixelSerializer.h"
#include "SkTDArray.h"
#include "SkTHash.h"
+#include "SkBitmapKey.h"
class SkPDFFont;
class SkPaint;
class SkImage;
-class SkBitmapKey {
-public:
- SkBitmapKey() : fSubset(SkIRect::MakeEmpty()), fGenID(0) {}
- explicit SkBitmapKey(const SkBitmap& bm)
- : fSubset(bm.getSubset()), fGenID(bm.getGenerationID()) {}
- bool operator==(const SkBitmapKey& rhs) const {
- return fGenID == rhs.fGenID && fSubset == rhs.fSubset;
- }
-
-private:
- SkIRect fSubset;
- uint32_t fGenID;
-};
-
/**
- * The SkPDFCanon canonicalizes objects across PDF pages(SkPDFDevices).
+ * The SkPDFCanon canonicalizes objects across PDF pages
+ * (SkPDFDevices) and across draw calls.
*
* The PDF backend works correctly if:
* - There is no more than one SkPDFCanon for each thread.
* - Every SkPDFDevice is given a pointer to a SkPDFCanon on creation.
* - All SkPDFDevices in a document share the same SkPDFCanon.
- * The SkDocument_PDF class makes this happen by owning a single
+ * The SkPDFDocument class makes this happen by owning a single
* SkPDFCanon.
*
* The addFoo() methods will ref the Foo; the canon's destructor will
@@ -75,9 +62,8 @@ public:
const SkPDFGraphicState* findGraphicState(const SkPDFGraphicState&) const;
void addGraphicState(const SkPDFGraphicState*);
- SkPDFObject* findPDFBitmap(const SkImage* image) const;
- void addPDFBitmap(uint32_t imageUniqueID, SkPDFObject*);
- const SkImage* bitmapToImage(const SkBitmap&);
+ sk_sp<SkPDFObject> findPDFBitmap(SkBitmapKey key) const;
+ void addPDFBitmap(SkBitmapKey key, sk_sp<SkPDFObject>);
SkTHashMap<uint32_t, bool> fCanEmbedTypeface;
@@ -119,8 +105,8 @@ private:
};
SkTHashSet<WrapGS, WrapGS::Hash> fGraphicStateRecords;
- SkTHashMap<SkBitmapKey, const SkImage*> fBitmapToImageMap;
- SkTHashMap<uint32_t /*ImageUniqueID*/, SkPDFObject*> fPDFBitmapMap;
+ // TODO(halcanary): make SkTHashMap<K, sk_sp<V>> work correctly.
+ SkTHashMap<SkBitmapKey, SkPDFObject*> fPDFBitmapMap;
sk_sp<SkPixelSerializer> fPixelSerializer;
sk_sp<SkPDFStream> fInvertFunction;