OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #ifndef GrTexture_DEFINED | 9 #ifndef GrTexture_DEFINED |
10 #define GrTexture_DEFINED | 10 #define GrTexture_DEFINED |
11 | 11 |
12 #include "GrSurface.h" | 12 #include "GrSurface.h" |
13 #include "GrRenderTarget.h" | 13 #include "GrRenderTarget.h" |
14 #include "SkPoint.h" | 14 #include "SkPoint.h" |
15 #include "SkRefCnt.h" | 15 #include "SkRefCnt.h" |
16 | 16 |
17 class GrResourceKey; | 17 class GrResourceKey; |
18 class GrTextureParams; | 18 class GrTextureParams; |
19 class GrTexturePriv; | 19 class GrTextureImpl; |
20 | 20 |
21 class GrTexture : public GrSurface { | 21 class GrTexture : public GrSurface { |
22 public: | 22 public: |
23 /** | 23 /** |
24 * Approximate number of bytes used by the texture | 24 * Approximate number of bytes used by the texture |
25 */ | 25 */ |
26 virtual size_t gpuMemorySize() const SK_OVERRIDE; | 26 virtual size_t gpuMemorySize() const SK_OVERRIDE; |
27 | 27 |
28 // GrSurface overrides | 28 // GrSurface overrides |
29 virtual bool readPixels(int left, int top, int width, int height, | 29 virtual bool readPixels(int left, int top, int width, int height, |
30 GrPixelConfig config, | 30 GrPixelConfig config, |
31 void* buffer, | 31 void* buffer, |
32 size_t rowBytes = 0, | 32 size_t rowBytes = 0, |
33 uint32_t pixelOpsFlags = 0) SK_OVERRIDE; | 33 uint32_t pixelOpsFlags = 0) SK_OVERRIDE; |
34 | 34 |
35 virtual void writePixels(int left, int top, int width, int height, | 35 virtual void writePixels(int left, int top, int width, int height, |
36 GrPixelConfig config, | 36 GrPixelConfig config, |
37 const void* buffer, | 37 const void* buffer, |
38 size_t rowBytes = 0, | 38 size_t rowBytes = 0, |
39 uint32_t pixelOpsFlags = 0) SK_OVERRIDE; | 39 uint32_t pixelOpsFlags = 0) SK_OVERRIDE; |
40 | 40 |
41 virtual GrTexture* asTexture() SK_OVERRIDE { return this; } | 41 virtual GrTexture* asTexture() SK_OVERRIDE { return this; } |
42 virtual const GrTexture* asTexture() const SK_OVERRIDE { return this; } | 42 virtual const GrTexture* asTexture() const SK_OVERRIDE { return this; } |
43 virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { return fRenderTarget.
get(); } | 43 virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { return fRenderTarget.
get(); } |
44 virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { return fR
enderTarget.get(); } | 44 virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { return fR
enderTarget.get(); } |
45 | 45 |
46 /** | 46 /** |
| 47 * Convert from texels to normalized texture coords for POT textures only. P
lease don't add |
| 48 * new callsites for these functions. They are slated for removal. |
| 49 */ |
| 50 SkFixed normalizeFixedX(SkFixed x) const { |
| 51 SkASSERT(SkIsPow2(fDesc.fWidth)); |
| 52 return x >> fShiftFixedX; |
| 53 } |
| 54 SkFixed normalizeFixedY(SkFixed y) const { |
| 55 SkASSERT(SkIsPow2(fDesc.fHeight)); |
| 56 return y >> fShiftFixedY; |
| 57 } |
| 58 |
| 59 /** |
47 * Return the native ID or handle to the texture, depending on the | 60 * Return the native ID or handle to the texture, depending on the |
48 * platform. e.g. on OpenGL, return the texture ID. | 61 * platform. e.g. on OpenGL, return the texture ID. |
49 */ | 62 */ |
50 virtual GrBackendObject getTextureHandle() const = 0; | 63 virtual GrBackendObject getTextureHandle() const = 0; |
51 | 64 |
52 /** | 65 /** |
53 * This function indicates that the texture parameters (wrap mode, filtering
, ...) have been | 66 * This function indicates that the texture parameters (wrap mode, filtering
, ...) have been |
54 * changed externally to Skia. | 67 * changed externally to Skia. |
55 */ | 68 */ |
56 virtual void textureParamsModified() = 0; | 69 virtual void textureParamsModified() = 0; |
| 70 SK_ATTR_DEPRECATED("Renamed to textureParamsModified.") |
| 71 void invalidateCachedState() { this->textureParamsModified(); } |
57 | 72 |
58 /** | 73 /** |
59 * Informational texture flags. This will be removed soon. | 74 * Informational texture flags. This will be moved to the private GrTextureI
mpl class soon. |
60 */ | 75 */ |
61 enum FlagBits { | 76 enum FlagBits { |
62 kFirstBit = (kLastPublic_GrTextureFlagBit << 1), | 77 kFirstBit = (kLastPublic_GrTextureFlagBit << 1), |
63 | 78 |
64 /** | 79 /** |
65 * This texture should be returned to the texture cache when | 80 * This texture should be returned to the texture cache when |
66 * it is no longer reffed | 81 * it is no longer reffed |
67 */ | 82 */ |
68 kReturnToCache_FlagBit = kFirstBit, | 83 kReturnToCache_FlagBit = kFirstBit, |
69 }; | 84 }; |
70 | 85 |
71 void resetFlag(GrTextureFlags flags) { | 86 void resetFlag(GrTextureFlags flags) { |
72 fDesc.fFlags = fDesc.fFlags & ~flags; | 87 fDesc.fFlags = fDesc.fFlags & ~flags; |
73 } | 88 } |
74 | 89 |
75 #ifdef SK_DEBUG | 90 #ifdef SK_DEBUG |
76 void validate() const { | 91 void validate() const { |
77 this->INHERITED::validate(); | 92 this->INHERITED::validate(); |
78 this->validateDesc(); | 93 this->validateDesc(); |
79 } | 94 } |
80 #endif | 95 #endif |
81 | 96 |
82 /** Access methods that are only to be used within Skia code. */ | 97 GrTextureImpl* impl() { return reinterpret_cast<GrTextureImpl*>(this); } |
83 inline GrTexturePriv texturePriv(); | 98 const GrTextureImpl* impl() const { return reinterpret_cast<const GrTextureI
mpl*>(this); } |
84 inline const GrTexturePriv texturePriv() const; | |
85 | 99 |
86 protected: | 100 protected: |
87 // A texture refs its rt representation but not vice-versa. It is up to | 101 // A texture refs its rt representation but not vice-versa. It is up to |
88 // the subclass constructor to initialize this pointer. | 102 // the subclass constructor to initialize this pointer. |
89 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 103 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
90 | 104 |
91 GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc); | 105 GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc) |
| 106 : INHERITED(gpu, isWrapped, desc) |
| 107 , fRenderTarget(NULL) { |
| 108 // only make sense if alloc size is pow2 |
| 109 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); |
| 110 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); |
| 111 } |
92 | 112 |
93 virtual ~GrTexture(); | 113 virtual ~GrTexture(); |
94 | 114 |
95 // GrResource overrides | 115 // GrResource overrides |
96 virtual void onRelease() SK_OVERRIDE; | 116 virtual void onRelease() SK_OVERRIDE; |
97 virtual void onAbandon() SK_OVERRIDE; | 117 virtual void onAbandon() SK_OVERRIDE; |
98 | 118 |
99 void validateDesc() const; | 119 void validateDesc() const; |
100 | 120 |
101 private: | 121 private: |
102 void abandonReleaseCommon(); | 122 void abandonReleaseCommon(); |
103 virtual void internal_dispose() const SK_OVERRIDE; | 123 virtual void internal_dispose() const SK_OVERRIDE; |
| 124 |
| 125 // these two shift a fixed-point value into normalized coordinates |
| 126 // for this texture if the texture is power of two sized. |
| 127 int fShiftFixedX; |
| 128 int fShiftFixedY; |
| 129 |
| 130 typedef GrSurface INHERITED; |
| 131 }; |
| 132 |
| 133 class GrTextureImpl : public GrTexture { |
| 134 public: |
| 135 SK_DECLARE_INST_COUNT(GrTextureImpl) |
| 136 |
| 137 void setFlag(GrTextureFlags flags) { |
| 138 fDesc.fFlags = fDesc.fFlags | flags; |
| 139 } |
| 140 void resetFlag(GrTextureFlags flags) { |
| 141 fDesc.fFlags = fDesc.fFlags & ~flags; |
| 142 } |
| 143 bool isSetFlag(GrTextureFlags flags) const { |
| 144 return 0 != (fDesc.fFlags & flags); |
| 145 } |
| 146 |
104 void dirtyMipMaps(bool mipMapsDirty); | 147 void dirtyMipMaps(bool mipMapsDirty); |
105 | 148 |
| 149 bool mipMapsAreDirty() const { |
| 150 return kValid_MipMapsStatus != fMipMapsStatus; |
| 151 } |
| 152 |
| 153 bool hasMipMaps() const { |
| 154 return kNotAllocated_MipMapsStatus != fMipMapsStatus; |
| 155 } |
| 156 |
| 157 static GrResourceKey ComputeKey(const GrGpu* gpu, |
| 158 const GrTextureParams* params, |
| 159 const GrTextureDesc& desc, |
| 160 const GrCacheID& cacheID); |
| 161 static GrResourceKey ComputeScratchKey(const GrTextureDesc& desc); |
| 162 static bool NeedsResizing(const GrResourceKey& key); |
| 163 static bool NeedsBilerp(const GrResourceKey& key); |
| 164 |
| 165 protected: |
| 166 GrTextureImpl(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc); |
| 167 |
| 168 private: |
106 enum MipMapsStatus { | 169 enum MipMapsStatus { |
107 kNotAllocated_MipMapsStatus, | 170 kNotAllocated_MipMapsStatus, |
108 kAllocated_MipMapsStatus, | 171 kAllocated_MipMapsStatus, |
109 kValid_MipMapsStatus | 172 kValid_MipMapsStatus |
110 }; | 173 }; |
111 | 174 |
112 MipMapsStatus fMipMapsStatus; | 175 MipMapsStatus fMipMapsStatus; |
113 // These two shift a fixed-point value into normalized coordinates» | |
114 // for this texture if the texture is power of two sized. | |
115 int fShiftFixedX; | |
116 int fShiftFixedY; | |
117 | 176 |
118 friend class GrTexturePriv; | 177 typedef GrTexture INHERITED; |
119 | |
120 typedef GrSurface INHERITED; | |
121 }; | 178 }; |
122 | 179 |
123 /** | 180 /** |
124 * Represents a texture that is intended to be accessed in device coords with an
offset. | 181 * Represents a texture that is intended to be accessed in device coords with an
offset. |
125 */ | 182 */ |
126 class GrDeviceCoordTexture { | 183 class GrDeviceCoordTexture { |
127 public: | 184 public: |
128 GrDeviceCoordTexture() { fOffset.set(0, 0); } | 185 GrDeviceCoordTexture() { fOffset.set(0, 0); } |
129 | 186 |
130 GrDeviceCoordTexture(const GrDeviceCoordTexture& other) { | 187 GrDeviceCoordTexture(const GrDeviceCoordTexture& other) { |
(...skipping 22 matching lines...) Expand all Loading... |
153 fTexture.reset(SkSafeRef(texture)); | 210 fTexture.reset(SkSafeRef(texture)); |
154 return texture; | 211 return texture; |
155 } | 212 } |
156 | 213 |
157 private: | 214 private: |
158 SkAutoTUnref<GrTexture> fTexture; | 215 SkAutoTUnref<GrTexture> fTexture; |
159 SkIPoint fOffset; | 216 SkIPoint fOffset; |
160 }; | 217 }; |
161 | 218 |
162 #endif | 219 #endif |
OLD | NEW |