OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 | 7 |
8 #ifndef SkBitmapProvider_DEFINED | 8 #ifndef SkBitmapProvider_DEFINED |
9 #define SkBitmapProvider_DEFINED | 9 #define SkBitmapProvider_DEFINED |
10 | 10 |
11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
12 #include "SkImage.h" | 12 #include "SkImage.h" |
13 #include "SkBitmapCache.h" | 13 #include "SkBitmapCache.h" |
14 | 14 |
15 class SkBitmapProvider { | 15 class SkBitmapProvider { |
16 public: | 16 public: |
17 explicit SkBitmapProvider(const SkBitmap& bm) : fBitmap(bm) {} | 17 explicit SkBitmapProvider(const SkBitmap& bm) : fBitmap(bm) {} |
18 explicit SkBitmapProvider(const SkImage* img) : fImage(SkSafeRef(img)) {} | 18 explicit SkBitmapProvider(const SkImage* img) : fImage(img) {} |
19 SkBitmapProvider(const SkBitmapProvider& other) | 19 SkBitmapProvider(const SkBitmapProvider& other) |
20 : fBitmap(other.fBitmap) | 20 : fBitmap(other.fBitmap) |
21 , fImage(SkSafeRef(other.fImage.get())) | 21 , fImage(other.fImage) |
22 {} | 22 {} |
23 | 23 |
24 int width() const; | 24 int width() const; |
25 int height() const; | 25 int height() const; |
26 uint32_t getID() const; | 26 uint32_t getID() const; |
27 | 27 |
28 bool validForDrawing() const; | 28 bool validForDrawing() const; |
29 SkImageInfo info() const; | 29 SkImageInfo info() const; |
30 bool isVolatile() const; | 30 bool isVolatile() const; |
31 | 31 |
32 SkBitmapCacheDesc makeCacheDesc(int w, int h) const; | 32 SkBitmapCacheDesc makeCacheDesc(int w, int h) const; |
33 SkBitmapCacheDesc makeCacheDesc() const; | 33 SkBitmapCacheDesc makeCacheDesc() const; |
34 void notifyAddedToCache() const; | 34 void notifyAddedToCache() const; |
35 | 35 |
36 // Only call this if you're sure you need the bits, since it maybe expensive | 36 // Only call this if you're sure you need the bits, since it maybe expensive |
37 // ... cause a decode and cache, or gpu-readback | 37 // ... cause a decode and cache, or gpu-readback |
38 bool asBitmap(SkBitmap*) const; | 38 bool asBitmap(SkBitmap*) const; |
39 | 39 |
40 private: | 40 private: |
41 SkBitmap fBitmap; | 41 // Stack-allocated only. |
42 SkAutoTUnref<const SkImage> fImage; | 42 void* operator new(size_t) = delete; |
| 43 void* operator new(size_t, void*) = delete; |
| 44 |
| 45 SkBitmap fBitmap; |
| 46 // SkBitmapProvider is always short-lived/stack allocated, and the source im
age is guaranteed |
| 47 // to outlive its scope => we can store a raw ptr to avoid ref churn. |
| 48 const SkImage* fImage; |
43 }; | 49 }; |
44 | 50 |
45 #endif | 51 #endif |
OLD | NEW |