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

Unified Diff: src/pdf/SkBitmapKey.h

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 | « gyp/pdf.gypi ('k') | src/pdf/SkPDFBitmap.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkBitmapKey.h
diff --git a/src/pdf/SkBitmapKey.h b/src/pdf/SkBitmapKey.h
new file mode 100644
index 0000000000000000000000000000000000000000..4723debac26b49c7c1459f11cddcdf7898c51ecc
--- /dev/null
+++ b/src/pdf/SkBitmapKey.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#ifndef SkBitmapKey_DEFINED
+#define SkBitmapKey_DEFINED
+
+#include "SkBitmap.h"
+#include "SkImage.h"
+#include "SkCanvas.h"
+
+class SkBitmapKey {
+public:
+ SkBitmapKey() : fSubset(SkIRect::MakeEmpty()), fID(0) {}
+ explicit SkBitmapKey(const SkBitmap& bm)
+ : fSubset(bm.getSubset()), fID(bm.getGenerationID()) {}
+ explicit SkBitmapKey(const SkImage* img)
+ : fSubset(img ? img->bounds() : SkIRect::MakeEmpty())
+ , fID(img ? img->uniqueID() : 0) {}
+ explicit SkBitmapKey(const sk_sp<SkImage> img)
+ : fSubset(img->bounds()), fID(img->uniqueID()) {}
+ bool operator==(const SkBitmapKey& rhs) const {
+ return fID == rhs.fID && fSubset == rhs.fSubset;
+ }
+ bool operator!=(const SkBitmapKey& rhs) const { return !(*this == rhs); }
+
+private:
+ SkIRect fSubset;
+ uint32_t fID;
+};
+
+/**
+ This wraps a thing that could either be a bitmap or a image and
+ abstracts out some common tasks.
+ */
+class SkImageBitmap {
+public:
+ explicit SkImageBitmap(const SkBitmap& b) : fBitmap(b), fImage(nullptr) {}
+ explicit SkImageBitmap(SkImage* i) : fImage(i) { SkASSERT(fImage); }
+ SkIRect bounds() const { return fImage ? fImage->bounds() : fBitmap.bounds(); }
+ SkISize dimensions() const {
+ return fImage ? fImage->dimensions() : fBitmap.dimensions();
+ }
+ sk_sp<SkImage> makeImage() const {
+ return fImage ? sk_ref_sp(fImage) : SkImage::MakeFromBitmap(fBitmap);
+ }
+ SkBitmapKey getKey() const {
+ return fImage ? SkBitmapKey(fImage) : SkBitmapKey(fBitmap);
+ }
+ void draw(SkCanvas* canvas, SkPaint* paint) const {
+ if (fImage) {
+ canvas->drawImage(fImage, 0, 0, paint);
+ } else {
+ canvas->drawBitmap(fBitmap, 0, 0, paint);
+ }
+ }
+
+private:
+ SkBitmap fBitmap;
+ SkImage* fImage; // non-owning; when drawImage starts passing a sk_sp<>,
+ // we can take a const ref to that sk_sp<>.
+};
+
+#endif // SkBitmapKey_DEFINED
« no previous file with comments | « gyp/pdf.gypi ('k') | src/pdf/SkPDFBitmap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698