| 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 | 15 |
| 15 class GrRenderTarget; | |
| 16 class GrResourceKey; | 16 class GrResourceKey; |
| 17 class GrTextureParams; | 17 class GrTextureParams; |
| 18 | 18 |
| 19 class GrTexture : public GrSurface { | 19 class GrTexture : public GrSurface { |
| 20 | 20 |
| 21 public: | 21 public: |
| 22 SK_DECLARE_INST_COUNT(GrTexture) | 22 SK_DECLARE_INST_COUNT(GrTexture) |
| 23 // from GrResource | 23 // from GrResource |
| 24 /** | 24 /** |
| 25 * Informational texture flags | 25 * Informational texture flags |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 virtual const GrTexture* asTexture() const SK_OVERRIDE { return this; } | 73 virtual const GrTexture* asTexture() const SK_OVERRIDE { return this; } |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * Retrieves the render target underlying this texture that can be passed to | 76 * Retrieves the render target underlying this texture that can be passed to |
| 77 * GrGpu::setRenderTarget(). | 77 * GrGpu::setRenderTarget(). |
| 78 * | 78 * |
| 79 * @return handle to render target or NULL if the texture is not a | 79 * @return handle to render target or NULL if the texture is not a |
| 80 * render target | 80 * render target |
| 81 */ | 81 */ |
| 82 virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { | 82 virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { |
| 83 return fRenderTarget; | 83 return fRenderTarget.get(); |
| 84 } | 84 } |
| 85 virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { | 85 virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { |
| 86 return fRenderTarget; | 86 return fRenderTarget.get(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 // GrTexture | 89 // GrTexture |
| 90 /** | 90 /** |
| 91 * Convert from texels to normalized texture coords for POT textures | 91 * Convert from texels to normalized texture coords for POT textures |
| 92 * only. | 92 * only. |
| 93 */ | 93 */ |
| 94 GrFixed normalizeFixedX(GrFixed x) const { | 94 GrFixed normalizeFixedX(GrFixed x) const { |
| 95 GrAssert(GrIsPow2(fDesc.fWidth)); | 95 GrAssert(GrIsPow2(fDesc.fWidth)); |
| 96 return x >> fShiftFixedX; | 96 return x >> fShiftFixedX; |
| 97 } | 97 } |
| 98 GrFixed normalizeFixedY(GrFixed y) const { | 98 GrFixed normalizeFixedY(GrFixed y) const { |
| 99 GrAssert(GrIsPow2(fDesc.fHeight)); | 99 GrAssert(GrIsPow2(fDesc.fHeight)); |
| 100 return y >> fShiftFixedY; | 100 return y >> fShiftFixedY; |
| 101 } | 101 } |
| 102 | 102 |
| 103 /** | 103 /** |
| 104 * Removes the reference on the associated GrRenderTarget held by this | |
| 105 * texture. Afterwards asRenderTarget() will return NULL. The | |
| 106 * GrRenderTarget survives the release if another ref is held on it. | |
| 107 */ | |
| 108 void releaseRenderTarget(); | |
| 109 | |
| 110 /** | |
| 111 * Return the native ID or handle to the texture, depending on the | 104 * Return the native ID or handle to the texture, depending on the |
| 112 * platform. e.g. on OpenGL, return the texture ID. | 105 * platform. e.g. on OpenGL, return the texture ID. |
| 113 */ | 106 */ |
| 114 virtual GrBackendObject getTextureHandle() const = 0; | 107 virtual GrBackendObject getTextureHandle() const = 0; |
| 115 | 108 |
| 116 /** | 109 /** |
| 117 * Call this when the state of the native API texture object is | 110 * Call this when the state of the native API texture object is |
| 118 * altered directly, without being tracked by skia. | 111 * altered directly, without being tracked by skia. |
| 119 */ | 112 */ |
| 120 virtual void invalidateCachedState() = 0; | 113 virtual void invalidateCachedState() = 0; |
| 121 | 114 |
| 122 #if GR_DEBUG | 115 #if GR_DEBUG |
| 123 void validate() const { | 116 void validate() const { |
| 124 this->INHERITED::validate(); | 117 this->INHERITED::validate(); |
| 125 | 118 |
| 126 this->validateDesc(); | 119 this->validateDesc(); |
| 127 } | 120 } |
| 128 #else | 121 #else |
| 129 void validate() const {} | 122 void validate() const {} |
| 130 #endif | 123 #endif |
| 131 static GrResourceKey ComputeKey(const GrGpu* gpu, | 124 static GrResourceKey ComputeKey(const GrGpu* gpu, |
| 132 const GrTextureParams* params, | 125 const GrTextureParams* params, |
| 133 const GrTextureDesc& desc, | 126 const GrTextureDesc& desc, |
| 134 const GrCacheID& cacheID); | 127 const GrCacheID& cacheID); |
| 135 static GrResourceKey ComputeScratchKey(const GrTextureDesc& desc); | 128 static GrResourceKey ComputeScratchKey(const GrTextureDesc& desc); |
| 136 static bool NeedsResizing(const GrResourceKey& key); | 129 static bool NeedsResizing(const GrResourceKey& key); |
| 137 static bool NeedsFiltering(const GrResourceKey& key); | 130 static bool NeedsFiltering(const GrResourceKey& key); |
| 138 | 131 |
| 139 protected: | 132 protected: |
| 140 GrRenderTarget* fRenderTarget; // texture refs its rt representation | 133 // A texture refs its rt representation but not vice-versa. It is up to |
| 141 // base class cons sets to NULL | 134 // the subclass constructor to initialize this pointer. |
| 142 // subclass cons can create and set | 135 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 143 | 136 |
| 144 GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc) | 137 GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc) |
| 145 : INHERITED(gpu, isWrapped, desc) | 138 : INHERITED(gpu, isWrapped, desc) |
| 146 , fRenderTarget(NULL) { | 139 , fRenderTarget(NULL) { |
| 147 | 140 |
| 148 // only make sense if alloc size is pow2 | 141 // only make sense if alloc size is pow2 |
| 149 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); | 142 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); |
| 150 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); | 143 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); |
| 151 } | 144 } |
| 152 | 145 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 GrTexture* setTexture(GrTexture* texture) { | 192 GrTexture* setTexture(GrTexture* texture) { |
| 200 fTexture.reset(SkSafeRef(texture)); | 193 fTexture.reset(SkSafeRef(texture)); |
| 201 return texture; | 194 return texture; |
| 202 } | 195 } |
| 203 private: | 196 private: |
| 204 SkAutoTUnref<GrTexture> fTexture; | 197 SkAutoTUnref<GrTexture> fTexture; |
| 205 SkIPoint fOffset; | 198 SkIPoint fOffset; |
| 206 }; | 199 }; |
| 207 | 200 |
| 208 #endif | 201 #endif |
| OLD | NEW |