OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #ifndef SkBitmapKey_DEFINED | 7 #ifndef SkBitmapKey_DEFINED |
8 #define SkBitmapKey_DEFINED | 8 #define SkBitmapKey_DEFINED |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
11 #include "SkImage.h" | 11 #include "SkImage.h" |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
13 | 13 |
14 class SkBitmapKey { | 14 class SkBitmapKey { |
15 public: | 15 public: |
16 SkBitmapKey() : fSubset(SkIRect::MakeEmpty()), fID(0) {} | 16 SkBitmapKey() : fSubset(SkIRect::MakeEmpty()), fID(0) {} |
17 explicit SkBitmapKey(const SkBitmap& bm) | 17 explicit SkBitmapKey(const SkBitmap& bm) |
18 : fSubset(bm.getSubset()), fID(bm.getGenerationID()) {} | 18 : fSubset(bm.getSubset()), fID(bm.getGenerationID()) {} |
19 explicit SkBitmapKey(const SkImage* img) | 19 explicit SkBitmapKey(const SkImage* img) |
20 : fSubset(img ? img->bounds() : SkIRect::MakeEmpty()) | 20 : fSubset(img ? img->bounds() : SkIRect::MakeEmpty()) |
21 , fID(img ? img->uniqueID() : 0) {} | 21 , fID(img ? img->uniqueID() : 0) {} |
22 explicit SkBitmapKey(const sk_sp<SkImage> img) | 22 explicit SkBitmapKey(const sk_sp<SkImage> img) |
23 : fSubset(img->bounds()), fID(img->uniqueID()) {} | 23 : fSubset(img->bounds()), fID(img->uniqueID()) {} |
24 bool operator==(const SkBitmapKey& rhs) const { | 24 bool operator==(const SkBitmapKey& rhs) const { |
25 return fID == rhs.fID && fSubset == rhs.fSubset; | 25 return fID == rhs.fID && fSubset == rhs.fSubset; |
26 } | 26 } |
27 bool operator!=(const SkBitmapKey& rhs) const { return !(*this == rhs); } | 27 bool operator!=(const SkBitmapKey& rhs) const { return !(*this == rhs); } |
| 28 uint32_t id() const { return fID; } |
28 | 29 |
29 private: | 30 private: |
30 SkIRect fSubset; | 31 SkIRect fSubset; |
31 uint32_t fID; | 32 uint32_t fID; |
32 }; | 33 }; |
33 | 34 |
34 /** | 35 /** |
35 This wraps a thing that could either be a bitmap or a image and | 36 This wraps a thing that could either be a bitmap or a image and |
36 abstracts out some common tasks. | 37 abstracts out some common tasks. |
37 */ | 38 */ |
(...skipping 19 matching lines...) Expand all Loading... |
57 } | 58 } |
58 } | 59 } |
59 | 60 |
60 private: | 61 private: |
61 SkBitmap fBitmap; | 62 SkBitmap fBitmap; |
62 SkImage* fImage; // non-owning; when drawImage starts passing a sk_sp<>, | 63 SkImage* fImage; // non-owning; when drawImage starts passing a sk_sp<>, |
63 // we can take a const ref to that sk_sp<>. | 64 // we can take a const ref to that sk_sp<>. |
64 }; | 65 }; |
65 | 66 |
66 #endif // SkBitmapKey_DEFINED | 67 #endif // SkBitmapKey_DEFINED |
OLD | NEW |