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 "SkImage.h" | 12 #include "SkImage.h" |
12 #include "SkSurface.h" | 13 #include "SkSurface.h" |
13 | 14 |
14 #include <new> | 15 #include <new> |
15 | 16 |
16 enum { | 17 enum { |
17 kNeedNewImageUniqueID = 0 | 18 kNeedNewImageUniqueID = 0 |
18 }; | 19 }; |
19 | 20 |
20 static SkSurfaceProps copy_or_safe_defaults(const SkSurfaceProps* props) { | |
21 return props ? *props : SkSurfaceProps(0, kUnknown_SkPixelGeometry); | |
22 } | |
23 | |
24 class SkImage_Base : public SkImage { | 21 class SkImage_Base : public SkImage { |
25 public: | 22 public: |
26 SkImage_Base(int width, int height, uint32_t uniqueID, const SkSurfaceProps*
props) | 23 SkImage_Base(int width, int height, uint32_t uniqueID, const SkSurfaceProps*
props); |
27 : INHERITED(width, height, uniqueID) | 24 virtual ~SkImage_Base(); |
28 , fProps(copy_or_safe_defaults(props)) | |
29 {} | |
30 | 25 |
31 /** | 26 /** |
32 * If the props weren't know at constructor time, call this but only before
the image is | 27 * If the props weren't know at constructor time, call this but only before
the image is |
33 * ever released into the wild (since the props field must appear to be imm
utable). | 28 * ever released into the wild (since the props field must appear to be imm
utable). |
34 */ | 29 */ |
35 void initWithProps(const SkSurfaceProps& props) { | 30 void initWithProps(const SkSurfaceProps& props) { |
36 SkASSERT(this->unique()); // only viewed by one thread | 31 SkASSERT(this->unique()); // only viewed by one thread |
37 SkSurfaceProps* mutableProps = const_cast<SkSurfaceProps*>(&fProps); | 32 SkSurfaceProps* mutableProps = const_cast<SkSurfaceProps*>(&fProps); |
38 SkASSERT(mutableProps != &props); // check for self-assignment | 33 SkASSERT(mutableProps != &props); // check for self-assignment |
39 mutableProps->~SkSurfaceProps(); | 34 mutableProps->~SkSurfaceProps(); |
(...skipping 27 matching lines...) Expand all Loading... |
67 | 62 |
68 // newWidth > 0, newHeight > 0, subset either nullptr or a proper subset of
this bounds | 63 // newWidth > 0, newHeight > 0, subset either nullptr or a proper subset of
this bounds |
69 virtual SkImage* onNewImage(int newWidth, int newHeight, const SkIRect* subs
et, | 64 virtual SkImage* onNewImage(int newWidth, int newHeight, const SkIRect* subs
et, |
70 SkFilterQuality) const; | 65 SkFilterQuality) const; |
71 virtual SkData* onRefEncoded() const { return nullptr; } | 66 virtual SkData* onRefEncoded() const { return nullptr; } |
72 | 67 |
73 virtual bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const; | 68 virtual bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const; |
74 | 69 |
75 virtual bool onIsLazyGenerated() const { return false; } | 70 virtual bool onIsLazyGenerated() const { return false; } |
76 | 71 |
| 72 // Call when this image is part of the key to a resourcecache entry. This al
lows the cache |
| 73 // to know automatically those entries can be purged when this SkImage delet
ed. |
| 74 void notifyAddedToCache() const { |
| 75 fAddedToCache.store(true); |
| 76 } |
| 77 |
77 private: | 78 private: |
78 const SkSurfaceProps fProps; | 79 const SkSurfaceProps fProps; |
79 | 80 |
| 81 // Set true by caches when they cache content that's derived from the curren
t pixels. |
| 82 mutable SkAtomic<bool> fAddedToCache; |
| 83 |
80 typedef SkImage INHERITED; | 84 typedef SkImage INHERITED; |
81 }; | 85 }; |
82 | 86 |
83 static inline SkImage_Base* as_IB(SkImage* image) { | 87 static inline SkImage_Base* as_IB(SkImage* image) { |
84 return static_cast<SkImage_Base*>(image); | 88 return static_cast<SkImage_Base*>(image); |
85 } | 89 } |
86 | 90 |
87 static inline const SkImage_Base* as_IB(const SkImage* image) { | 91 static inline const SkImage_Base* as_IB(const SkImage* image) { |
88 return static_cast<const SkImage_Base*>(image); | 92 return static_cast<const SkImage_Base*>(image); |
89 } | 93 } |
90 | 94 |
91 #endif | 95 #endif |
OLD | NEW |