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

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: rebase 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
41 virtual GrTexture* asTexture() SK_OVERRIDE { return this; } 40 virtual GrTexture* asTexture() SK_OVERRIDE { return this; }
42 virtual const GrTexture* asTexture() const SK_OVERRIDE { return this; } 41 virtual const GrTexture* asTexture() const SK_OVERRIDE { return this; }
43 virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { return fRenderTarget. get(); } 42 virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { return fRenderTarget. get(); }
44 virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { return fR enderTarget.get(); } 43 virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { return fR enderTarget.get(); }
45 44
46 /** 45 /**
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 46 * Return the native ID or handle to the texture, depending on the
61 * platform. e.g. on OpenGL, return the texture ID. 47 * platform. e.g. on OpenGL, return the texture ID.
62 */ 48 */
63 virtual GrBackendObject getTextureHandle() const = 0; 49 virtual GrBackendObject getTextureHandle() const = 0;
64 50
65 /** 51 /**
66 * This function indicates that the texture parameters (wrap mode, filtering , ...) have been 52 * This function indicates that the texture parameters (wrap mode, filtering , ...) have been
67 * changed externally to Skia. 53 * changed externally to Skia.
68 */ 54 */
69 virtual void textureParamsModified() = 0; 55 virtual void textureParamsModified() = 0;
70 SK_ATTR_DEPRECATED("Renamed to textureParamsModified.")
71 void invalidateCachedState() { this->textureParamsModified(); }
72 56
73 /** 57 /**
74 * Informational texture flags. This will be moved to the private GrTextureI mpl class soon. 58 * Informational texture flags. This will be removed soon.
75 */ 59 */
76 enum FlagBits { 60 enum FlagBits {
77 kFirstBit = (kLastPublic_GrTextureFlagBit << 1), 61 kFirstBit = (kLastPublic_GrTextureFlagBit << 1),
78 62
79 /** 63 /**
80 * This texture should be returned to the texture cache when 64 * This texture should be returned to the texture cache when
81 * it is no longer reffed 65 * it is no longer reffed
82 */ 66 */
83 kReturnToCache_FlagBit = kFirstBit, 67 kReturnToCache_FlagBit = kFirstBit,
84 }; 68 };
85 69
86 void resetFlag(GrTextureFlags flags) { 70 void resetFlag(GrTextureFlags flags) {
87 fDesc.fFlags = fDesc.fFlags & ~flags; 71 fDesc.fFlags = fDesc.fFlags & ~flags;
88 } 72 }
89 73
90 #ifdef SK_DEBUG 74 #ifdef SK_DEBUG
91 void validate() const { 75 void validate() const {
92 this->INHERITED::validate(); 76 this->INHERITED::validate();
93 this->validateDesc(); 77 this->validateDesc();
94 } 78 }
95 #endif 79 #endif
96 80
97 GrTextureImpl* impl() { return reinterpret_cast<GrTextureImpl*>(this); } 81 /** Access methods that are only to be used within Skia code. */
98 const GrTextureImpl* impl() const { return reinterpret_cast<const GrTextureI mpl*>(this); } 82 inline GrTexturePriv texturePriv();
83 inline const GrTexturePriv texturePriv() const;
99 84
100 protected: 85 protected:
101 // A texture refs its rt representation but not vice-versa. It is up to 86 // A texture refs its rt representation but not vice-versa. It is up to
102 // the subclass constructor to initialize this pointer. 87 // the subclass constructor to initialize this pointer.
103 SkAutoTUnref<GrRenderTarget> fRenderTarget; 88 SkAutoTUnref<GrRenderTarget> fRenderTarget;
104 89
105 GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc) 90 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 91
113 virtual ~GrTexture(); 92 virtual ~GrTexture();
114 93
115 // GrResource overrides 94 // GrResource overrides
116 virtual void onRelease() SK_OVERRIDE; 95 virtual void onRelease() SK_OVERRIDE;
117 virtual void onAbandon() SK_OVERRIDE; 96 virtual void onAbandon() SK_OVERRIDE;
118 97
119 void validateDesc() const; 98 void validateDesc() const;
120 99
121 private: 100 private:
122 void abandonReleaseCommon(); 101 void abandonReleaseCommon();
123 virtual void internal_dispose() const SK_OVERRIDE; 102 virtual void internal_dispose() const SK_OVERRIDE;
124 103
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 { 104 enum MipMapsStatus {
170 kNotAllocated_MipMapsStatus, 105 kNotAllocated_MipMapsStatus,
171 kAllocated_MipMapsStatus, 106 kAllocated_MipMapsStatus,
172 kValid_MipMapsStatus 107 kValid_MipMapsStatus
173 }; 108 };
174 109
175 MipMapsStatus fMipMapsStatus; 110 MipMapsStatus fMipMapsStatus;
robertphillips 2014/09/29 13:34:27 Preserve old comment if these are going to stay ?
bsalomon 2014/09/29 18:42:10 Done.
111 int fShiftFixedX;
112 int fShiftFixedY;
176 113
177 typedef GrTexture INHERITED; 114 friend class GrTexturePriv;
115
116 typedef GrSurface INHERITED;
178 }; 117 };
179 118
180 /** 119 /**
181 * Represents a texture that is intended to be accessed in device coords with an offset. 120 * Represents a texture that is intended to be accessed in device coords with an offset.
182 */ 121 */
183 class GrDeviceCoordTexture { 122 class GrDeviceCoordTexture {
184 public: 123 public:
185 GrDeviceCoordTexture() { fOffset.set(0, 0); } 124 GrDeviceCoordTexture() { fOffset.set(0, 0); }
186 125
187 GrDeviceCoordTexture(const GrDeviceCoordTexture& other) { 126 GrDeviceCoordTexture(const GrDeviceCoordTexture& other) {
(...skipping 22 matching lines...) Expand all
210 fTexture.reset(SkSafeRef(texture)); 149 fTexture.reset(SkSafeRef(texture));
211 return texture; 150 return texture;
212 } 151 }
213 152
214 private: 153 private:
215 SkAutoTUnref<GrTexture> fTexture; 154 SkAutoTUnref<GrTexture> fTexture;
216 SkIPoint fOffset; 155 SkIPoint fOffset;
217 }; 156 };
218 157
219 #endif 158 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrSurface.h ('k') | src/gpu/GrBitmapTextContext.cpp » ('j') | src/gpu/GrSurface.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698