Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(831)

Unified Diff: src/pdf/SkPDFBitmap.cpp

Issue 1829693002: SkPDF: draw{Image,Bitmap} always serializes early (Closed) Base URL: https://skia.googlesource.com/skia.git@r1823683005
Patch Set: rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pdf/SkPDFBitmap.h ('k') | src/pdf/SkPDFCanon.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFBitmap.cpp
diff --git a/src/pdf/SkPDFBitmap.cpp b/src/pdf/SkPDFBitmap.cpp
index 5e617decf4feb749d510975020fa2836bd64b6ec..24f5c6a00fc0d6a93311299d86ea8727dd1d1b3a 100644
--- a/src/pdf/SkPDFBitmap.cpp
+++ b/src/pdf/SkPDFBitmap.cpp
@@ -382,7 +382,7 @@ namespace {
// This SkPDFObject only outputs the alpha layer of the given bitmap.
class PDFAlphaBitmap final : public SkPDFObject {
public:
- PDFAlphaBitmap(const SkImage* image) : fImage(SkRef(image)) { SkASSERT(image); }
+ PDFAlphaBitmap(sk_sp<SkImage> image) : fImage(std::move(image)) { SkASSERT(fImage); }
void emitObject(SkWStream* stream,
const SkPDFObjNumMap& objNumMap,
const SkPDFSubstituteMap& subs) const override {
@@ -392,7 +392,7 @@ public:
void drop() override { fImage = nullptr; }
private:
- sk_sp<const SkImage> fImage;
+ sk_sp<SkImage> fImage;
};
} // namespace
@@ -418,11 +418,11 @@ public:
}
}
void drop() override { fImage = nullptr; fSMask = nullptr; }
- PDFDefaultBitmap(const SkImage* image, SkPDFObject* smask)
- : fImage(SkRef(image)), fSMask(smask) { SkASSERT(fImage); }
+ PDFDefaultBitmap(sk_sp<SkImage> image, sk_sp<SkPDFObject> smask)
+ : fImage(std::move(image)), fSMask(std::move(smask)) { SkASSERT(fImage); }
private:
- sk_sp<const SkImage> fImage;
+ sk_sp<SkImage> fImage;
sk_sp<SkPDFObject> fSMask;
};
} // namespace
@@ -474,8 +474,9 @@ void PDFJpegBitmap::emitObject(SkWStream* stream,
////////////////////////////////////////////////////////////////////////////////
-SkPDFObject* SkPDFCreateBitmapObject(const SkImage* image,
- SkPixelSerializer* pixelSerializer) {
+sk_sp<SkPDFObject> SkPDFCreateBitmapObject(sk_sp<SkImage> image,
+ SkPixelSerializer* pixelSerializer) {
+ SkASSERT(image);
sk_sp<SkData> data(image->refEncoded());
SkJFIFInfo info;
if (data && SkIsJFIF(data.get(), &info) &&
@@ -490,28 +491,30 @@ SkPDFObject* SkPDFCreateBitmapObject(const SkImage* image,
#ifdef SK_PDF_IMAGE_STATS
gJpegImageObjects.fetch_add(1);
#endif
- return new PDFJpegBitmap(info.fSize, data.get(), yuv);
+ return sk_make_sp<PDFJpegBitmap>(info.fSize, data.get(), yuv);
}
}
if (pixelSerializer) {
SkBitmap bm;
SkAutoPixmapUnlock apu;
- if (as_IB(image)->getROPixels(&bm) && bm.requestLock(&apu)) {
+ if (as_IB(image.get())->getROPixels(&bm) && bm.requestLock(&apu)) {
data.reset(pixelSerializer->encode(apu.pixmap()));
if (data && SkIsJFIF(data.get(), &info)) {
bool yuv = info.fType == SkJFIFInfo::kYCbCr;
if (info.fSize == image->dimensions()) { // Sanity check.
- return new PDFJpegBitmap(info.fSize, data.get(), yuv);
+ return sk_make_sp<PDFJpegBitmap>(info.fSize, data.get(), yuv);
}
}
}
}
- SkPDFObject* smask =
- image_compute_is_opaque(image) ? nullptr : new PDFAlphaBitmap(image);
+ sk_sp<SkPDFObject> smask;
+ if (!image_compute_is_opaque(image.get())) {
+ smask = sk_make_sp<PDFAlphaBitmap>(image);
+ }
#ifdef SK_PDF_IMAGE_STATS
gRegularImageObjects.fetch_add(1);
#endif
- return new PDFDefaultBitmap(image, smask);
+ return sk_make_sp<PDFDefaultBitmap>(std::move(image), std::move(smask));
}
« no previous file with comments | « src/pdf/SkPDFBitmap.h ('k') | src/pdf/SkPDFCanon.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698