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 "SkAtomics.h" | 11 #include "SkAtomics.h" |
12 #include "SkImage.h" | 12 #include "SkImage.h" |
13 #include "SkSurface.h" | 13 #include "SkSurface.h" |
14 | 14 |
15 #include <new> | 15 #include <new> |
16 | 16 |
17 enum { | 17 enum { |
18 kNeedNewImageUniqueID = 0 | 18 kNeedNewImageUniqueID = 0 |
19 }; | 19 }; |
20 | 20 |
21 class SkImage_Base : public SkImage { | 21 class SkImage_Base : public SkImage { |
22 public: | 22 public: |
23 SkImage_Base(int width, int height, uint32_t uniqueID, const SkSurfaceProps*
props); | 23 SkImage_Base(int width, int height, uint32_t uniqueID); |
24 virtual ~SkImage_Base(); | 24 virtual ~SkImage_Base(); |
25 | 25 |
26 /** | 26 virtual const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const {
return nullptr; } |
27 * If the props weren't know at constructor time, call this but only before
the image is | |
28 * ever released into the wild (since the props field must appear to be imm
utable). | |
29 */ | |
30 void initWithProps(const SkSurfaceProps& props) { | |
31 SkASSERT(this->unique()); // only viewed by one thread | |
32 SkSurfaceProps* mutableProps = const_cast<SkSurfaceProps*>(&fProps); | |
33 SkASSERT(mutableProps != &props); // check for self-assignment | |
34 mutableProps->~SkSurfaceProps(); | |
35 new (mutableProps) SkSurfaceProps(props); | |
36 } | |
37 | |
38 const SkSurfaceProps& props() const { return fProps; } | |
39 | |
40 virtual const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const { | |
41 return nullptr; | |
42 } | |
43 | 27 |
44 // Default impl calls onDraw | 28 // Default impl calls onDraw |
45 virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_
t dstRowBytes, | 29 virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_
t dstRowBytes, |
46 int srcX, int srcY) const; | 30 int srcX, int srcY) const; |
47 | 31 |
48 virtual GrTexture* peekTexture() const { return nullptr; } | 32 virtual GrTexture* peekTexture() const { return nullptr; } |
49 | 33 |
50 // return a read-only copy of the pixels. We promise to not modify them, | 34 // return a read-only copy of the pixels. We promise to not modify them, |
51 // but only inspect them (or encode them). | 35 // but only inspect them (or encode them). |
52 virtual bool getROPixels(SkBitmap*) const = 0; | 36 virtual bool getROPixels(SkBitmap*) const = 0; |
53 | 37 |
54 // Caller must call unref when they are done. | 38 // Caller must call unref when they are done. |
55 virtual GrTexture* asTextureRef(GrContext*, SkImageUsageType) const = 0; | 39 virtual GrTexture* asTextureRef(GrContext*, SkImageUsageType) const = 0; |
56 | 40 |
57 virtual SkImage* onNewSubset(const SkIRect&) const = 0; | 41 virtual SkImage* onNewSubset(const SkIRect&) const = 0; |
58 | 42 |
59 virtual SkData* onRefEncoded() const { return nullptr; } | 43 virtual SkData* onRefEncoded() const { return nullptr; } |
60 | 44 |
61 virtual bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const; | 45 virtual bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const; |
62 | 46 |
63 virtual bool onIsLazyGenerated() const { return false; } | 47 virtual bool onIsLazyGenerated() const { return false; } |
64 | 48 |
65 // Call when this image is part of the key to a resourcecache entry. This al
lows the cache | 49 // Call when this image is part of the key to a resourcecache entry. This al
lows the cache |
66 // to know automatically those entries can be purged when this SkImage delet
ed. | 50 // to know automatically those entries can be purged when this SkImage delet
ed. |
67 void notifyAddedToCache() const { | 51 void notifyAddedToCache() const { |
68 fAddedToCache.store(true); | 52 fAddedToCache.store(true); |
69 } | 53 } |
70 | 54 |
71 private: | 55 private: |
72 const SkSurfaceProps fProps; | |
73 | |
74 // Set true by caches when they cache content that's derived from the curren
t pixels. | 56 // Set true by caches when they cache content that's derived from the curren
t pixels. |
75 mutable SkAtomic<bool> fAddedToCache; | 57 mutable SkAtomic<bool> fAddedToCache; |
76 | 58 |
77 typedef SkImage INHERITED; | 59 typedef SkImage INHERITED; |
78 }; | 60 }; |
79 | 61 |
80 static inline SkImage_Base* as_IB(SkImage* image) { | 62 static inline SkImage_Base* as_IB(SkImage* image) { |
81 return static_cast<SkImage_Base*>(image); | 63 return static_cast<SkImage_Base*>(image); |
82 } | 64 } |
83 | 65 |
84 static inline const SkImage_Base* as_IB(const SkImage* image) { | 66 static inline const SkImage_Base* as_IB(const SkImage* image) { |
85 return static_cast<const SkImage_Base*>(image); | 67 return static_cast<const SkImage_Base*>(image); |
86 } | 68 } |
87 | 69 |
88 #endif | 70 #endif |
OLD | NEW |