OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 SkImage_Base_DEFINED | 8 #ifndef SkImage_Base_DEFINED |
9 #define SkImage_Base_DEFINED | 9 #define SkImage_Base_DEFINED |
10 | 10 |
| 11 #include "GrTexture.h" |
11 #include "SkAtomics.h" | 12 #include "SkAtomics.h" |
12 #include "SkImage.h" | 13 #include "SkImage.h" |
13 #include "SkSurface.h" | 14 #include "SkSurface.h" |
14 | 15 |
15 #include <new> | 16 #include <new> |
16 | 17 |
17 class GrTextureParams; | 18 class GrTextureParams; |
18 class SkImageCacherator; | 19 class SkImageCacherator; |
19 | 20 |
20 enum { | 21 enum { |
(...skipping 12 matching lines...) Expand all Loading... |
33 | 34 |
34 virtual bool onPeekPixels(SkPixmap*) const { return false; } | 35 virtual bool onPeekPixels(SkPixmap*) const { return false; } |
35 | 36 |
36 virtual const SkBitmap* onPeekBitmap() const { return nullptr; } | 37 virtual const SkBitmap* onPeekBitmap() const { return nullptr; } |
37 | 38 |
38 // Default impl calls onDraw | 39 // Default impl calls onDraw |
39 virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_
t dstRowBytes, | 40 virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_
t dstRowBytes, |
40 int srcX, int srcY, CachingHint) const; | 41 int srcX, int srcY, CachingHint) const; |
41 | 42 |
42 virtual GrTexture* peekTexture() const { return nullptr; } | 43 virtual GrTexture* peekTexture() const { return nullptr; } |
| 44 virtual sk_sp<GrTexture> refPinnedTexture(uint32_t* uniqueID) const { return
nullptr; } |
43 virtual SkImageCacherator* peekCacherator() const { return nullptr; } | 45 virtual SkImageCacherator* peekCacherator() const { return nullptr; } |
44 | 46 |
45 // return a read-only copy of the pixels. We promise to not modify them, | 47 // return a read-only copy of the pixels. We promise to not modify them, |
46 // but only inspect them (or encode them). | 48 // but only inspect them (or encode them). |
47 virtual bool getROPixels(SkBitmap*, CachingHint = kAllow_CachingHint) const
= 0; | 49 virtual bool getROPixels(SkBitmap*, CachingHint = kAllow_CachingHint) const
= 0; |
48 | 50 |
49 virtual sk_sp<SkSurface> onNewSurface(const SkImageInfo& info) const { | 51 virtual sk_sp<SkSurface> onNewSurface(const SkImageInfo& info) const { |
50 return SkSurface::MakeRaster(info); | 52 return SkSurface::MakeRaster(info); |
51 } | 53 } |
52 | 54 |
53 // Caller must call unref when they are done. | 55 // Caller must call unref when they are done. |
54 virtual GrTexture* asTextureRef(GrContext*, const GrTextureParams&, | 56 virtual GrTexture* asTextureRef(GrContext*, const GrTextureParams&, |
55 SkSourceGammaTreatment) const = 0; | 57 SkSourceGammaTreatment) const = 0; |
56 | 58 |
57 virtual sk_sp<SkImage> onMakeSubset(const SkIRect&) const = 0; | 59 virtual sk_sp<SkImage> onMakeSubset(const SkIRect&) const = 0; |
58 | 60 |
59 // If a ctx is specified, then only gpu-specific formats are requested. | 61 // If a ctx is specified, then only gpu-specific formats are requested. |
60 virtual SkData* onRefEncoded(GrContext*) const { return nullptr; } | 62 virtual SkData* onRefEncoded(GrContext*) const { return nullptr; } |
61 | 63 |
62 virtual bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const; | 64 virtual bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const; |
63 | 65 |
64 virtual bool onIsLazyGenerated() const { return false; } | 66 virtual bool onIsLazyGenerated() const { return false; } |
65 | 67 |
66 // Call when this image is part of the key to a resourcecache entry. This al
lows the cache | 68 // Call when this image is part of the key to a resourcecache entry. This al
lows the cache |
67 // to know automatically those entries can be purged when this SkImage delet
ed. | 69 // to know automatically those entries can be purged when this SkImage delet
ed. |
68 void notifyAddedToCache() const { | 70 void notifyAddedToCache() const { |
69 fAddedToCache.store(true); | 71 fAddedToCache.store(true); |
70 } | 72 } |
71 | 73 |
| 74 virtual void onPinAsTexture(GrContext*) const {} |
| 75 virtual void onUnpinAsTexture(GrContext*) const {} |
| 76 |
72 private: | 77 private: |
73 // Set true by caches when they cache content that's derived from the curren
t pixels. | 78 // Set true by caches when they cache content that's derived from the curren
t pixels. |
74 mutable SkAtomic<bool> fAddedToCache; | 79 mutable SkAtomic<bool> fAddedToCache; |
75 | 80 |
76 typedef SkImage INHERITED; | 81 typedef SkImage INHERITED; |
77 }; | 82 }; |
78 | 83 |
79 static inline SkImage_Base* as_IB(SkImage* image) { | 84 static inline SkImage_Base* as_IB(SkImage* image) { |
80 return static_cast<SkImage_Base*>(image); | 85 return static_cast<SkImage_Base*>(image); |
81 } | 86 } |
82 | 87 |
83 static inline SkImage_Base* as_IB(const sk_sp<SkImage>& image) { | 88 static inline SkImage_Base* as_IB(const sk_sp<SkImage>& image) { |
84 return static_cast<SkImage_Base*>(image.get()); | 89 return static_cast<SkImage_Base*>(image.get()); |
85 } | 90 } |
86 | 91 |
87 static inline const SkImage_Base* as_IB(const SkImage* image) { | 92 static inline const SkImage_Base* as_IB(const SkImage* image) { |
88 return static_cast<const SkImage_Base*>(image); | 93 return static_cast<const SkImage_Base*>(image); |
89 } | 94 } |
90 | 95 |
91 #endif | 96 #endif |
OLD | NEW |