Chromium Code Reviews| 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 "SkPoint.h" | 13 #include "SkPoint.h" |
| 14 #include "GrRenderTarget.h" | 14 #include "GrRenderTarget.h" |
| 15 | 15 |
| 16 class GrResourceKey; | 16 class GrResourceKey; |
| 17 class GrTextureParams; | 17 class GrTextureParams; |
| 18 class GrTextureImpl; | |
| 18 | 19 |
| 19 class GrTexture : public GrSurface { | 20 class GrTexture : public GrSurface { |
| 20 | |
| 21 public: | 21 public: |
| 22 SK_DECLARE_INST_COUNT(GrTexture) | |
| 23 // from GrResource | |
| 24 /** | |
| 25 * Informational texture flags | |
| 26 */ | |
| 27 enum FlagBits { | |
| 28 kFirstBit = (kLastPublic_GrTextureFlagBit << 1), | |
| 29 | |
| 30 /** | |
| 31 * This texture should be returned to the texture cache when | |
| 32 * it is no longer reffed | |
| 33 */ | |
| 34 kReturnToCache_FlagBit = kFirstBit, | |
| 35 }; | |
| 36 | |
| 37 void setFlag(GrTextureFlags flags) { | |
| 38 fDesc.fFlags = fDesc.fFlags | flags; | |
| 39 } | |
| 40 void resetFlag(GrTextureFlags flags) { | |
| 41 fDesc.fFlags = fDesc.fFlags & ~flags; | |
| 42 } | |
| 43 bool isSetFlag(GrTextureFlags flags) const { | |
| 44 return 0 != (fDesc.fFlags & flags); | |
| 45 } | |
| 46 | |
| 47 void dirtyMipMaps(bool mipMapsDirty); | |
| 48 | |
| 49 bool mipMapsAreDirty() const { | |
| 50 return kValid_MipMapsStatus != fMipMapsStatus; | |
| 51 } | |
| 52 | |
| 53 /** | 22 /** |
| 54 * Approximate number of bytes used by the texture | 23 * Approximate number of bytes used by the texture |
| 55 */ | 24 */ |
| 56 virtual size_t gpuMemorySize() const SK_OVERRIDE; | 25 virtual size_t gpuMemorySize() const SK_OVERRIDE; |
| 57 | 26 |
| 58 // GrSurface overrides | 27 // GrSurface overrides |
| 59 virtual bool readPixels(int left, int top, int width, int height, | 28 virtual bool readPixels(int left, int top, int width, int height, |
| 60 GrPixelConfig config, | 29 GrPixelConfig config, |
| 61 void* buffer, | 30 void* buffer, |
| 62 size_t rowBytes = 0, | 31 size_t rowBytes = 0, |
| 63 uint32_t pixelOpsFlags = 0) SK_OVERRIDE; | 32 uint32_t pixelOpsFlags = 0) SK_OVERRIDE; |
| 64 | 33 |
| 65 virtual void writePixels(int left, int top, int width, int height, | 34 virtual void writePixels(int left, int top, int width, int height, |
| 66 GrPixelConfig config, | 35 GrPixelConfig config, |
| 67 const void* buffer, | 36 const void* buffer, |
| 68 size_t rowBytes = 0, | 37 size_t rowBytes = 0, |
| 69 uint32_t pixelOpsFlags = 0) SK_OVERRIDE; | 38 uint32_t pixelOpsFlags = 0) SK_OVERRIDE; |
| 70 | 39 |
| 71 /** | |
| 72 * @return this texture | |
| 73 */ | |
| 74 virtual GrTexture* asTexture() SK_OVERRIDE { return this; } | 40 virtual GrTexture* asTexture() SK_OVERRIDE { return this; } |
| 75 virtual const GrTexture* asTexture() const SK_OVERRIDE { return this; } | 41 virtual const GrTexture* asTexture() const SK_OVERRIDE { return this; } |
| 42 virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { return fRenderTarget. get(); } | |
| 43 virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { return fR enderTarget.get(); } | |
| 76 | 44 |
| 77 /** | 45 /** |
| 78 * Retrieves the render target underlying this texture that can be passed to | 46 * Convert from texels to normalized texture coords for POT textures only. P lease don't add |
| 79 * GrGpu::setRenderTarget(). | 47 * new callsites for these functions. They are slated for removal. |
| 80 * | |
| 81 * @return handle to render target or NULL if the texture is not a | |
| 82 * render target | |
| 83 */ | |
| 84 virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { | |
| 85 return fRenderTarget.get(); | |
| 86 } | |
| 87 virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { | |
| 88 return fRenderTarget.get(); | |
| 89 } | |
| 90 | |
| 91 // GrTexture | |
| 92 /** | |
| 93 * Convert from texels to normalized texture coords for POT textures | |
| 94 * only. | |
| 95 */ | 48 */ |
| 96 SkFixed normalizeFixedX(SkFixed x) const { | 49 SkFixed normalizeFixedX(SkFixed x) const { |
| 97 SkASSERT(GrIsPow2(fDesc.fWidth)); | 50 SkASSERT(GrIsPow2(fDesc.fWidth)); |
| 98 return x >> fShiftFixedX; | 51 return x >> fShiftFixedX; |
| 99 } | 52 } |
| 100 SkFixed normalizeFixedY(SkFixed y) const { | 53 SkFixed normalizeFixedY(SkFixed y) const { |
| 101 SkASSERT(GrIsPow2(fDesc.fHeight)); | 54 SkASSERT(GrIsPow2(fDesc.fHeight)); |
| 102 return y >> fShiftFixedY; | 55 return y >> fShiftFixedY; |
| 103 } | 56 } |
| 104 | 57 |
| 105 /** | 58 /** |
| 106 * Return the native ID or handle to the texture, depending on the | 59 * Return the native ID or handle to the texture, depending on the |
| 107 * platform. e.g. on OpenGL, return the texture ID. | 60 * platform. e.g. on OpenGL, return the texture ID. |
| 108 */ | 61 */ |
| 109 virtual GrBackendObject getTextureHandle() const = 0; | 62 virtual GrBackendObject getTextureHandle() const = 0; |
| 110 | 63 |
| 111 /** | |
| 112 * Call this when the state of the native API texture object is | |
| 113 * altered directly, without being tracked by skia. | |
| 114 */ | |
| 115 virtual void invalidateCachedState() = 0; | |
| 116 | |
| 117 #ifdef SK_DEBUG | 64 #ifdef SK_DEBUG |
| 118 void validate() const { | 65 void validate() const { |
| 119 this->INHERITED::validate(); | 66 this->INHERITED::validate(); |
| 120 | 67 |
| 121 this->validateDesc(); | 68 this->validateDesc(); |
| 122 } | 69 } |
| 123 #endif | 70 #endif |
| 124 | 71 |
| 125 static GrResourceKey ComputeKey(const GrGpu* gpu, | 72 GrTextureImpl* impl() { return reinterpret_cast<GrTextureImpl*>(this); } |
|
bsalomon
2014/05/09 14:44:15
This can only be static_cast if GrTextureImpl is a
| |
| 126 const GrTextureParams* params, | 73 const GrTextureImpl* impl() const { return reinterpret_cast<const GrTextureI mpl*>(this); } |
| 127 const GrTextureDesc& desc, | |
| 128 const GrCacheID& cacheID); | |
| 129 static GrResourceKey ComputeScratchKey(const GrTextureDesc& desc); | |
| 130 static bool NeedsResizing(const GrResourceKey& key); | |
| 131 static bool NeedsBilerp(const GrResourceKey& key); | |
| 132 | 74 |
| 133 protected: | 75 protected: |
| 134 // A texture refs its rt representation but not vice-versa. It is up to | 76 // A texture refs its rt representation but not vice-versa. It is up to |
| 135 // the subclass constructor to initialize this pointer. | 77 // the subclass constructor to initialize this pointer. |
| 136 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 78 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 137 | 79 |
| 138 GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc) | 80 GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc) |
| 139 : INHERITED(gpu, isWrapped, desc) | 81 : INHERITED(gpu, isWrapped, desc) |
| 140 , fRenderTarget(NULL) | 82 , fRenderTarget(NULL) { |
| 141 , fMipMapsStatus(kNotAllocated_MipMapsStatus) { | |
| 142 | |
| 143 // only make sense if alloc size is pow2 | 83 // only make sense if alloc size is pow2 |
| 144 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); | 84 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); |
| 145 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); | 85 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); |
| 146 } | 86 } |
| 87 | |
| 147 virtual ~GrTexture(); | 88 virtual ~GrTexture(); |
| 148 | 89 |
| 149 // GrResource overrides | 90 // GrResource overrides |
| 150 virtual void onRelease() SK_OVERRIDE; | 91 virtual void onRelease() SK_OVERRIDE; |
| 151 virtual void onAbandon() SK_OVERRIDE; | 92 virtual void onAbandon() SK_OVERRIDE; |
| 152 | 93 |
| 153 void validateDesc() const; | 94 void validateDesc() const; |
| 154 | 95 |
| 155 private: | 96 private: |
| 97 virtual void internal_dispose() const SK_OVERRIDE; | |
| 98 | |
| 99 // these two shift a fixed-point value into normalized coordinates | |
| 100 // for this texture if the texture is power of two sized. | |
| 101 int fShiftFixedX; | |
| 102 int fShiftFixedY; | |
| 103 | |
| 104 typedef GrSurface INHERITED; | |
| 105 }; | |
| 106 | |
| 107 class GrTextureImpl : public GrTexture { | |
|
bsalomon
2014/05/09 14:44:15
Kept this in the same file for the initial review.
| |
| 108 public: | |
|
robertphillips
2014/05/09 14:57:22
Name here
bsalomon
2014/05/09 15:10:39
Done.
| |
| 109 SK_DECLARE_INST_COUNT(GrTexture) | |
| 110 /** | |
| 111 * Informational texture flags | |
| 112 */ | |
| 113 enum FlagBits { | |
| 114 kFirstBit = (kLastPublic_GrTextureFlagBit << 1), | |
| 115 | |
| 116 /** | |
| 117 * This texture should be returned to the texture cache when | |
| 118 * it is no longer reffed | |
| 119 */ | |
| 120 kReturnToCache_FlagBit = kFirstBit, | |
| 121 }; | |
| 122 | |
| 123 void setFlag(GrTextureFlags flags) { | |
| 124 fDesc.fFlags = fDesc.fFlags | flags; | |
| 125 } | |
| 126 void resetFlag(GrTextureFlags flags) { | |
| 127 fDesc.fFlags = fDesc.fFlags & ~flags; | |
| 128 } | |
| 129 bool isSetFlag(GrTextureFlags flags) const { | |
| 130 return 0 != (fDesc.fFlags & flags); | |
| 131 } | |
| 132 | |
| 133 void dirtyMipMaps(bool mipMapsDirty); | |
| 134 | |
| 135 bool mipMapsAreDirty() const { | |
| 136 return kValid_MipMapsStatus != fMipMapsStatus; | |
| 137 } | |
| 138 | |
| 139 /** | |
| 140 * Call this when the state of the native API texture object is | |
| 141 * altered directly, without being tracked by skia. | |
| 142 */ | |
| 143 virtual void invalidateCachedState() = 0; | |
| 144 | |
| 145 static GrResourceKey ComputeKey(const GrGpu* gpu, | |
| 146 const GrTextureParams* params, | |
| 147 const GrTextureDesc& desc, | |
| 148 const GrCacheID& cacheID); | |
| 149 static GrResourceKey ComputeScratchKey(const GrTextureDesc& desc); | |
| 150 static bool NeedsResizing(const GrResourceKey& key); | |
| 151 static bool NeedsBilerp(const GrResourceKey& key); | |
| 152 | |
| 153 protected: | |
| 154 GrTextureImpl(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc) | |
| 155 : INHERITED(gpu, isWrapped, desc) | |
| 156 , fMipMapsStatus(kNotAllocated_MipMapsStatus) { | |
| 157 } | |
| 158 | |
| 159 private: | |
| 156 enum MipMapsStatus { | 160 enum MipMapsStatus { |
| 157 kNotAllocated_MipMapsStatus, | 161 kNotAllocated_MipMapsStatus, |
| 158 kAllocated_MipMapsStatus, | 162 kAllocated_MipMapsStatus, |
| 159 kValid_MipMapsStatus | 163 kValid_MipMapsStatus |
| 160 }; | 164 }; |
| 161 | 165 |
| 162 // these two shift a fixed-point value into normalized coordinates | |
| 163 // for this texture if the texture is power of two sized. | |
| 164 int fShiftFixedX; | |
| 165 int fShiftFixedY; | |
| 166 | |
| 167 MipMapsStatus fMipMapsStatus; | 166 MipMapsStatus fMipMapsStatus; |
| 168 | 167 |
|
robertphillips
2014/05/09 14:57:22
Can't GrTexture just access fMipMapsStatus via the
bsalomon
2014/05/09 15:10:39
It was accessing the flags enum. But I added a pub
| |
| 169 virtual void internal_dispose() const SK_OVERRIDE; | 168 friend class GrTexture; |
| 170 | 169 typedef GrTexture INHERITED; |
| 171 typedef GrSurface INHERITED; | |
| 172 }; | 170 }; |
| 173 | 171 |
| 174 /** | 172 /** |
| 175 * Represents a texture that is intended to be accessed in device coords with an offset. | 173 * Represents a texture that is intended to be accessed in device coords with an offset. |
| 176 */ | 174 */ |
| 177 class GrDeviceCoordTexture { | 175 class GrDeviceCoordTexture { |
| 178 public: | 176 public: |
| 179 GrDeviceCoordTexture() { fOffset.set(0, 0); } | 177 GrDeviceCoordTexture() { fOffset.set(0, 0); } |
| 180 | 178 |
| 181 GrDeviceCoordTexture(const GrDeviceCoordTexture& other) { | 179 GrDeviceCoordTexture(const GrDeviceCoordTexture& other) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 197 | 195 |
| 198 void setOffset(const SkIPoint& offset) { fOffset = offset; } | 196 void setOffset(const SkIPoint& offset) { fOffset = offset; } |
| 199 void setOffset(int ox, int oy) { fOffset.set(ox, oy); } | 197 void setOffset(int ox, int oy) { fOffset.set(ox, oy); } |
| 200 | 198 |
| 201 GrTexture* texture() const { return fTexture.get(); } | 199 GrTexture* texture() const { return fTexture.get(); } |
| 202 | 200 |
| 203 GrTexture* setTexture(GrTexture* texture) { | 201 GrTexture* setTexture(GrTexture* texture) { |
| 204 fTexture.reset(SkSafeRef(texture)); | 202 fTexture.reset(SkSafeRef(texture)); |
| 205 return texture; | 203 return texture; |
| 206 } | 204 } |
| 205 | |
| 207 private: | 206 private: |
| 208 SkAutoTUnref<GrTexture> fTexture; | 207 SkAutoTUnref<GrTexture> fTexture; |
| 209 SkIPoint fOffset; | 208 SkIPoint fOffset; |
| 210 }; | 209 }; |
| 211 | 210 |
| 212 #endif | 211 #endif |
| OLD | NEW |