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

Unified Diff: src/core/SkBitmapCache.cpp

Issue 483493003: expose generalized imagecache key (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove more dead code Created 6 years, 4 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/core/SkBitmapCache.h ('k') | src/core/SkBitmapProcState.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkBitmapCache.cpp
diff --git a/src/core/SkBitmapCache.cpp b/src/core/SkBitmapCache.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..de52b63b5e7eda5209f21d87e99eb8a42b66877a
--- /dev/null
+++ b/src/core/SkBitmapCache.cpp
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkBitmapCache.h"
+#include "SkRect.h"
+
+/**
+ This function finds the bounds of the bitmap *within its pixelRef*.
+ If the bitmap lacks a pixelRef, it will return an empty rect, since
+ that doesn't make sense. This may be a useful enough function that
+ it should be somewhere else (in SkBitmap?).
+ */
+static SkIRect get_bounds_from_bitmap(const SkBitmap& bm) {
+ if (!(bm.pixelRef())) {
+ return SkIRect::MakeEmpty();
+ }
+ SkIPoint origin = bm.pixelRefOrigin();
+ return SkIRect::MakeXYWH(origin.fX, origin.fY, bm.width(), bm.height());
+}
+
+struct BitmapKey : public SkScaledImageCache::Key {
+public:
+ BitmapKey(uint32_t genID, SkScalar scaleX, SkScalar scaleY, const SkIRect& bounds)
+ : fGenID(genID)
+ , fScaleX(scaleX)
+ , fScaleY(scaleY)
+ , fBounds(bounds)
+ {
+ this->init(sizeof(fGenID) + sizeof(fScaleX) + sizeof(fScaleY) + sizeof(fBounds));
+ }
+
+ uint32_t fGenID;
+ SkScalar fScaleX;
+ SkScalar fScaleY;
+ SkIRect fBounds;
+};
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
+SkScaledImageCache::ID* SkBitmapCache::FindAndLock(const SkBitmap& src,
+ SkScalar invScaleX, SkScalar invScaleY,
+ SkBitmap* result) {
+ if (0 == invScaleX || 0 == invScaleY) {
+ // degenerate, and the key we use for mipmaps
+ return NULL;
+ }
+ BitmapKey key(src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_bitmap(src));
+ return SkScaledImageCache::FindAndLock(key, result);
+}
+
+SkScaledImageCache::ID* SkBitmapCache::AddAndLock(const SkBitmap& src,
+ SkScalar invScaleX, SkScalar invScaleY,
+ const SkBitmap& result) {
+ if (0 == invScaleX || 0 == invScaleY) {
+ // degenerate, and the key we use for mipmaps
+ return NULL;
+ }
+ BitmapKey key(src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_bitmap(src));
+ return SkScaledImageCache::AddAndLock(key, result);
+}
+
+////
+
+SkScaledImageCache::ID* SkBitmapCache::FindAndLock(uint32_t genID, int width, int height,
+ SkBitmap* result) {
+ BitmapKey key(genID, SK_Scalar1, SK_Scalar1, SkIRect::MakeWH(width, height));
+ return SkScaledImageCache::FindAndLock(key, result);
+}
+
+SkScaledImageCache::ID* SkBitmapCache::AddAndLock(uint32_t genID, int width, int height,
+ const SkBitmap& result) {
+ BitmapKey key(genID, SK_Scalar1, SK_Scalar1, SkIRect::MakeWH(width, height));
+ return SkScaledImageCache::AddAndLock(key, result);
+}
+
+////
+
+SkScaledImageCache::ID* SkMipMapCache::FindAndLock(const SkBitmap& src, const SkMipMap** result) {
+ BitmapKey key(src.getGenerationID(), SK_Scalar1, SK_Scalar1, get_bounds_from_bitmap(src));
+ return SkScaledImageCache::FindAndLock(key, result);
+}
+
+SkScaledImageCache::ID* SkMipMapCache::AddAndLock(const SkBitmap& src, const SkMipMap* result) {
+ BitmapKey key(src.getGenerationID(), SK_Scalar1, SK_Scalar1, get_bounds_from_bitmap(src));
+ return SkScaledImageCache::AddAndLock(key, result);
+}
+
« no previous file with comments | « src/core/SkBitmapCache.h ('k') | src/core/SkBitmapProcState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698