OLD | NEW |
---|---|
(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 GenWHKey : public SkScaledImageCache::Key { | |
mtklein
2014/08/21 15:29:18
Might want to consider just CacheKey? GenWHKey is
reed1
2014/08/21 15:58:10
Done.
| |
26 public: | |
27 GenWHKey(uint32_t genID, SkScalar scaleX, SkScalar scaleY, const SkIRect& bo unds) | |
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 GenWHKey key(src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_bi tmap(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 GenWHKey key(src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_bi tmap(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 GenWHKey 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 GenWHKey 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, SkMipMap const** result) { | |
83 GenWHKey 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 GenWHKey key(src.getGenerationID(), SK_Scalar1, SK_Scalar1, get_bounds_from_ bitmap(src)); | |
89 return SkScaledImageCache::AddAndLock(key, result); | |
90 } | |
91 | |
OLD | NEW |