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

Unified Diff: src/pdf/SkPDFCanon.cpp

Issue 1372783003: SkPDF: Implement drawImage*() properly (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-09-30 (Wednesday) 21:22:24 EDT Created 5 years, 3 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/SkPDFCanon.h ('k') | src/pdf/SkPDFDevice.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFCanon.cpp
diff --git a/src/pdf/SkPDFCanon.cpp b/src/pdf/SkPDFCanon.cpp
index 6cc39954124b6bfb8e6015b79361f5143f8175e3..4fdaa0db628cf14b27fd4e26b966a913e5a7ead2 100644
--- a/src/pdf/SkPDFCanon.cpp
+++ b/src/pdf/SkPDFCanon.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkImage.h"
#include "SkPDFBitmap.h"
#include "SkPDFCanon.h"
#include "SkPDFFont.h"
@@ -25,8 +26,13 @@ void SkPDFCanon::reset() {
fImageShaderRecords.reset();
fGraphicStateRecords.foreach ([](WrapGS w) { w.fPtr->unref(); });
fGraphicStateRecords.reset();
- fBitmapRecords.unrefAll();
- fBitmapRecords.reset();
+
+ fBitmapToImageMap.foreach(
+ [](SkBitmapKey, const SkImage** p) { SkSafeUnref(*p); });
+ fBitmapToImageMap.reset();
+
+ fPDFBitmapMap.foreach([](uint32_t, SkPDFObject** p) { SkSafeUnref(*p); });
+ fPDFBitmapMap.reset();
}
////////////////////////////////////////////////////////////////////////////////
@@ -121,10 +127,25 @@ void SkPDFCanon::addGraphicState(const SkPDFGraphicState* state) {
////////////////////////////////////////////////////////////////////////////////
-SkPDFBitmap* SkPDFCanon::findBitmap(const SkBitmap& bm) const {
- return find_item(fBitmapRecords, bm);
+SkPDFObject* SkPDFCanon::findPDFBitmap(const SkImage* image) const {
+ SkPDFObject** ptr = fPDFBitmapMap.find(image->uniqueID());
+ return ptr ? *ptr : nullptr;
+}
+
+void SkPDFCanon::addPDFBitmap(uint32_t imageUniqueID, SkPDFObject* pdfBitmap) {
+ fPDFBitmapMap.set(imageUniqueID, SkRef(pdfBitmap));
}
-void SkPDFCanon::addBitmap(SkPDFBitmap* pdfBitmap) {
- fBitmapRecords.push(SkRef(pdfBitmap));
+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::NewFromBitmap(bm)) {
+ return *fBitmapToImageMap.set(key, image);
+ }
+ SkBitmap n32bitmap; // SkImage::NewFromBitmap can be finicky.
+ bm.copyTo(&n32bitmap, kN32_SkColorType);
+ return *fBitmapToImageMap.set(key, SkImage::NewFromBitmap(n32bitmap));
}
« no previous file with comments | « src/pdf/SkPDFCanon.h ('k') | src/pdf/SkPDFDevice.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698