Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(475)

Side by Side Diff: include/gpu/GrTexture.h

Issue 596053002: Make "priv" classes for GrTexure and GrSurface. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address comments Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 GrTextureImpl; 19 class GrTexturePriv;
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 /**
60 * Return the native ID or handle to the texture, depending on the 47 * Return the native ID or handle to the texture, depending on the
61 * platform. e.g. on OpenGL, return the texture ID. 48 * platform. e.g. on OpenGL, return the texture ID.
62 */ 49 */
63 virtual GrBackendObject getTextureHandle() const = 0; 50 virtual GrBackendObject getTextureHandle() const = 0;
64 51
65 /** 52 /**
66 * This function indicates that the texture parameters (wrap mode, filtering , ...) have been 53 * This function indicates that the texture parameters (wrap mode, filtering , ...) have been
67 * changed externally to Skia. 54 * changed externally to Skia.
68 */ 55 */
69 virtual void textureParamsModified() = 0; 56 virtual void textureParamsModified() = 0;
70 SK_ATTR_DEPRECATED("Renamed to textureParamsModified.")
71 void invalidateCachedState() { this->textureParamsModified(); }
72 57
73 /** 58 /**
74 * Informational texture flags. This will be moved to the private GrTextureI mpl class soon. 59 * Informational texture flags. This will be removed soon.
75 */ 60 */
76 enum FlagBits { 61 enum FlagBits {
77 kFirstBit = (kLastPublic_GrTextureFlagBit << 1), 62 kFirstBit = (kLastPublic_GrTextureFlagBit << 1),
78 63
79 /** 64 /**
80 * This texture should be returned to the texture cache when 65 * This texture should be returned to the texture cache when
81 * it is no longer reffed 66 * it is no longer reffed
82 */ 67 */
83 kReturnToCache_FlagBit = kFirstBit, 68 kReturnToCache_FlagBit = kFirstBit,
84 }; 69 };
85 70
86 void resetFlag(GrTextureFlags flags) { 71 void resetFlag(GrTextureFlags flags) {
87 fDesc.fFlags = fDesc.fFlags & ~flags; 72 fDesc.fFlags = fDesc.fFlags & ~flags;
88 } 73 }
89 74
90 #ifdef SK_DEBUG 75 #ifdef SK_DEBUG
91 void validate() const { 76 void validate() const {
92 this->INHERITED::validate(); 77 this->INHERITED::validate();
93 this->validateDesc(); 78 this->validateDesc();
94 } 79 }
95 #endif 80 #endif
96 81
97 GrTextureImpl* impl() { return reinterpret_cast<GrTextureImpl*>(this); } 82 /** Access methods that are only to be used within Skia code. */
98 const GrTextureImpl* impl() const { return reinterpret_cast<const GrTextureI mpl*>(this); } 83 inline GrTexturePriv texturePriv();
84 inline const GrTexturePriv texturePriv() const;
99 85
100 protected: 86 protected:
101 // A texture refs its rt representation but not vice-versa. It is up to 87 // A texture refs its rt representation but not vice-versa. It is up to
102 // the subclass constructor to initialize this pointer. 88 // the subclass constructor to initialize this pointer.
103 SkAutoTUnref<GrRenderTarget> fRenderTarget; 89 SkAutoTUnref<GrRenderTarget> fRenderTarget;
104 90
105 GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc) 91 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 }
112 92
113 virtual ~GrTexture(); 93 virtual ~GrTexture();
114 94
115 // GrResource overrides 95 // GrResource overrides
116 virtual void onRelease() SK_OVERRIDE; 96 virtual void onRelease() SK_OVERRIDE;
117 virtual void onAbandon() SK_OVERRIDE; 97 virtual void onAbandon() SK_OVERRIDE;
118 98
119 void validateDesc() const; 99 void validateDesc() const;
120 100
121 private: 101 private:
122 void abandonReleaseCommon(); 102 void abandonReleaseCommon();
123 virtual void internal_dispose() const SK_OVERRIDE; 103 virtual void internal_dispose() const SK_OVERRIDE;
124 104
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
147 void dirtyMipMaps(bool mipMapsDirty);
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:
169 enum MipMapsStatus { 105 enum MipMapsStatus {
170 kNotAllocated_MipMapsStatus, 106 kNotAllocated_MipMapsStatus,
171 kAllocated_MipMapsStatus, 107 kAllocated_MipMapsStatus,
172 kValid_MipMapsStatus 108 kValid_MipMapsStatus
173 }; 109 };
174 110
175 MipMapsStatus fMipMapsStatus; 111 MipMapsStatus fMipMapsStatus;
112 // These two shift a fixed-point value into normalized coordinates»
113 // for this texture if the texture is power of two sized.
114 int fShiftFixedX;
115 int fShiftFixedY;
176 116
177 typedef GrTexture INHERITED; 117 friend class GrTexturePriv;
118
119 typedef GrSurface INHERITED;
178 }; 120 };
179 121
180 /** 122 /**
181 * Represents a texture that is intended to be accessed in device coords with an offset. 123 * Represents a texture that is intended to be accessed in device coords with an offset.
182 */ 124 */
183 class GrDeviceCoordTexture { 125 class GrDeviceCoordTexture {
184 public: 126 public:
185 GrDeviceCoordTexture() { fOffset.set(0, 0); } 127 GrDeviceCoordTexture() { fOffset.set(0, 0); }
186 128
187 GrDeviceCoordTexture(const GrDeviceCoordTexture& other) { 129 GrDeviceCoordTexture(const GrDeviceCoordTexture& other) {
(...skipping 22 matching lines...) Expand all
210 fTexture.reset(SkSafeRef(texture)); 152 fTexture.reset(SkSafeRef(texture));
211 return texture; 153 return texture;
212 } 154 }
213 155
214 private: 156 private:
215 SkAutoTUnref<GrTexture> fTexture; 157 SkAutoTUnref<GrTexture> fTexture;
216 SkIPoint fOffset; 158 SkIPoint fOffset;
217 }; 159 };
218 160
219 #endif 161 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698