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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/core/SkBitmapCache.h ('k') | src/core/SkBitmapProcState.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkBitmapCache.h"
9 #include "SkRect.h"
10
11 /**
12 This function finds the bounds of the bitmap *within its pixelRef*.
13 If the bitmap lacks a pixelRef, it will return an empty rect, since
14 that doesn't make sense. This may be a useful enough function that
15 it should be somewhere else (in SkBitmap?).
16 */
17 static SkIRect get_bounds_from_bitmap(const SkBitmap& bm) {
18 if (!(bm.pixelRef())) {
19 return SkIRect::MakeEmpty();
20 }
21 SkIPoint origin = bm.pixelRefOrigin();
22 return SkIRect::MakeXYWH(origin.fX, origin.fY, bm.width(), bm.height());
23 }
24
25 struct BitmapKey : public SkScaledImageCache::Key {
26 public:
27 BitmapKey(uint32_t genID, SkScalar scaleX, SkScalar scaleY, const SkIRect& b ounds)
28 : fGenID(genID)
29 , fScaleX(scaleX)
30 , fScaleY(scaleY)
31 , fBounds(bounds)
32 {
33 this->init(sizeof(fGenID) + sizeof(fScaleX) + sizeof(fScaleY) + sizeof(f Bounds));
34 }
35
36 uint32_t fGenID;
37 SkScalar fScaleX;
38 SkScalar fScaleY;
39 SkIRect fBounds;
40 };
41
42 //////////////////////////////////////////////////////////////////////////////// //////////
43
44 SkScaledImageCache::ID* SkBitmapCache::FindAndLock(const SkBitmap& src,
45 SkScalar invScaleX, SkScalar invScaleY,
46 SkBitmap* result) {
47 if (0 == invScaleX || 0 == invScaleY) {
48 // degenerate, and the key we use for mipmaps
49 return NULL;
50 }
51 BitmapKey key(src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_b itmap(src));
52 return SkScaledImageCache::FindAndLock(key, result);
53 }
54
55 SkScaledImageCache::ID* SkBitmapCache::AddAndLock(const SkBitmap& src,
56 SkScalar invScaleX, SkScalar i nvScaleY,
57 const SkBitmap& result) {
58 if (0 == invScaleX || 0 == invScaleY) {
59 // degenerate, and the key we use for mipmaps
60 return NULL;
61 }
62 BitmapKey key(src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_b itmap(src));
63 return SkScaledImageCache::AddAndLock(key, result);
64 }
65
66 ////
67
68 SkScaledImageCache::ID* SkBitmapCache::FindAndLock(uint32_t genID, int width, in t height,
69 SkBitmap* result) {
70 BitmapKey key(genID, SK_Scalar1, SK_Scalar1, SkIRect::MakeWH(width, height)) ;
71 return SkScaledImageCache::FindAndLock(key, result);
72 }
73
74 SkScaledImageCache::ID* SkBitmapCache::AddAndLock(uint32_t genID, int width, int height,
75 const SkBitmap& result) {
76 BitmapKey key(genID, SK_Scalar1, SK_Scalar1, SkIRect::MakeWH(width, height)) ;
77 return SkScaledImageCache::AddAndLock(key, result);
78 }
79
80 ////
81
82 SkScaledImageCache::ID* SkMipMapCache::FindAndLock(const SkBitmap& src, const Sk MipMap** result) {
83 BitmapKey key(src.getGenerationID(), SK_Scalar1, SK_Scalar1, get_bounds_from _bitmap(src));
84 return SkScaledImageCache::FindAndLock(key, result);
85 }
86
87 SkScaledImageCache::ID* SkMipMapCache::AddAndLock(const SkBitmap& src, const SkM ipMap* result) {
88 BitmapKey key(src.getGenerationID(), SK_Scalar1, SK_Scalar1, get_bounds_from _bitmap(src));
89 return SkScaledImageCache::AddAndLock(key, result);
90 }
91
OLDNEW
« 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