aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf/SkPDFCanon.cpp
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.cpp
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.cpp')
-rw-r--r--src/pdf/SkPDFCanon.cpp30
1 files changed, 7 insertions, 23 deletions
diff --git a/src/pdf/SkPDFCanon.cpp b/src/pdf/SkPDFCanon.cpp
index 48f3aef69e..c981217123 100644
--- a/src/pdf/SkPDFCanon.cpp
+++ b/src/pdf/SkPDFCanon.cpp
@@ -27,11 +27,7 @@ void SkPDFCanon::reset() {
fGraphicStateRecords.foreach ([](WrapGS w) { w.fPtr->unref(); });
fGraphicStateRecords.reset();
- fBitmapToImageMap.foreach(
- [](SkBitmapKey, const SkImage** p) { SkSafeUnref(*p); });
- fBitmapToImageMap.reset();
-
- fPDFBitmapMap.foreach([](uint32_t, SkPDFObject** p) { SkSafeUnref(*p); });
+ fPDFBitmapMap.foreach([](SkBitmapKey, SkPDFObject** p) { (*p)->unref(); });
fPDFBitmapMap.reset();
}
@@ -127,28 +123,16 @@ void SkPDFCanon::addGraphicState(const SkPDFGraphicState* state) {
////////////////////////////////////////////////////////////////////////////////
-SkPDFObject* SkPDFCanon::findPDFBitmap(const SkImage* image) const {
- SkPDFObject** ptr = fPDFBitmapMap.find(image->uniqueID());
- return ptr ? *ptr : nullptr;
+sk_sp<SkPDFObject> SkPDFCanon::findPDFBitmap(SkBitmapKey key) const {
+ SkPDFObject** ptr = fPDFBitmapMap.find(key);
+ return ptr ? sk_ref_sp(*ptr) : sk_sp<SkPDFObject>();
}
-void SkPDFCanon::addPDFBitmap(uint32_t imageUniqueID, SkPDFObject* pdfBitmap) {
- fPDFBitmapMap.set(imageUniqueID, SkRef(pdfBitmap));
+void SkPDFCanon::addPDFBitmap(SkBitmapKey key, sk_sp<SkPDFObject> pdfBitmap) {
+ fPDFBitmapMap.set(key, pdfBitmap.release());
}
-const SkImage* SkPDFCanon::bitmapToImage(const SkBitmap& bm) {
- // reference remains owned by the fBitmapToImageMap!
- SkBitmapKey key(bm);
- if (const SkImage** img = fBitmapToImageMap.find(key)) {
- return *img;
- }
- if (SkImage* image = SkImage::MakeFromBitmap(bm).release()) {
- return *fBitmapToImageMap.set(key, image);
- }
- SkBitmap n32bitmap; // SkImage::NewFromBitmap can be finicky.
- bm.copyTo(&n32bitmap, kN32_SkColorType);
- return *fBitmapToImageMap.set(key, SkImage::MakeFromBitmap(n32bitmap).release());
-}
+////////////////////////////////////////////////////////////////////////////////
sk_sp<SkPDFStream> SkPDFCanon::makeInvertFunction() {
if (fInvertFunction) {