| 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 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 void setFlag(GrTextureFlags flags) { | 37 void setFlag(GrTextureFlags flags) { |
| 38 fDesc.fFlags = fDesc.fFlags | flags; | 38 fDesc.fFlags = fDesc.fFlags | flags; |
| 39 } | 39 } |
| 40 void resetFlag(GrTextureFlags flags) { | 40 void resetFlag(GrTextureFlags flags) { |
| 41 fDesc.fFlags = fDesc.fFlags & ~flags; | 41 fDesc.fFlags = fDesc.fFlags & ~flags; |
| 42 } | 42 } |
| 43 bool isSetFlag(GrTextureFlags flags) const { | 43 bool isSetFlag(GrTextureFlags flags) const { |
| 44 return 0 != (fDesc.fFlags & flags); | 44 return 0 != (fDesc.fFlags & flags); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void dirtyMipMaps(bool mipMapsDirty) { | 47 void dirtyMipMaps(bool mipMapsDirty); |
| 48 fMipMapsDirty = mipMapsDirty; | |
| 49 } | |
| 50 | 48 |
| 51 bool mipMapsAreDirty() const { | 49 bool mipMapsAreDirty() const { |
| 52 return fMipMapsDirty; | 50 return kValid_MipMapsStatus != fMipMapsStatus; |
| 53 } | 51 } |
| 54 | 52 |
| 55 /** | 53 /** |
| 56 * Approximate number of bytes used by the texture | 54 * Approximate number of bytes used by the texture |
| 57 */ | 55 */ |
| 58 virtual size_t gpuMemorySize() const SK_OVERRIDE { | 56 virtual size_t gpuMemorySize() const SK_OVERRIDE; |
| 59 return (size_t) fDesc.fWidth * | |
| 60 fDesc.fHeight * | |
| 61 GrBytesPerPixel(fDesc.fConfig); | |
| 62 } | |
| 63 | 57 |
| 64 // GrSurface overrides | 58 // GrSurface overrides |
| 65 virtual bool readPixels(int left, int top, int width, int height, | 59 virtual bool readPixels(int left, int top, int width, int height, |
| 66 GrPixelConfig config, | 60 GrPixelConfig config, |
| 67 void* buffer, | 61 void* buffer, |
| 68 size_t rowBytes = 0, | 62 size_t rowBytes = 0, |
| 69 uint32_t pixelOpsFlags = 0) SK_OVERRIDE; | 63 uint32_t pixelOpsFlags = 0) SK_OVERRIDE; |
| 70 | 64 |
| 71 virtual void writePixels(int left, int top, int width, int height, | 65 virtual void writePixels(int left, int top, int width, int height, |
| 72 GrPixelConfig config, | 66 GrPixelConfig config, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 static bool NeedsBilerp(const GrResourceKey& key); | 131 static bool NeedsBilerp(const GrResourceKey& key); |
| 138 | 132 |
| 139 protected: | 133 protected: |
| 140 // A texture refs its rt representation but not vice-versa. It is up to | 134 // A texture refs its rt representation but not vice-versa. It is up to |
| 141 // the subclass constructor to initialize this pointer. | 135 // the subclass constructor to initialize this pointer. |
| 142 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 136 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 143 | 137 |
| 144 GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc) | 138 GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc) |
| 145 : INHERITED(gpu, isWrapped, desc) | 139 : INHERITED(gpu, isWrapped, desc) |
| 146 , fRenderTarget(NULL) | 140 , fRenderTarget(NULL) |
| 147 , fMipMapsDirty(true) { | 141 , fMipMapsStatus(kNotAllocated_MipMapsStatus) { |
| 148 | 142 |
| 149 // only make sense if alloc size is pow2 | 143 // only make sense if alloc size is pow2 |
| 150 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); | 144 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); |
| 151 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); | 145 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); |
| 152 } | 146 } |
| 153 virtual ~GrTexture(); | 147 virtual ~GrTexture(); |
| 154 | 148 |
| 155 // GrResource overrides | 149 // GrResource overrides |
| 156 virtual void onRelease() SK_OVERRIDE; | 150 virtual void onRelease() SK_OVERRIDE; |
| 157 virtual void onAbandon() SK_OVERRIDE; | 151 virtual void onAbandon() SK_OVERRIDE; |
| 158 | 152 |
| 159 void validateDesc() const; | 153 void validateDesc() const; |
| 160 | 154 |
| 161 private: | 155 private: |
| 156 enum MipMapsStatus { |
| 157 kNotAllocated_MipMapsStatus, |
| 158 kAllocated_MipMapsStatus, |
| 159 kValid_MipMapsStatus |
| 160 }; |
| 161 |
| 162 // these two shift a fixed-point value into normalized coordinates | 162 // these two shift a fixed-point value into normalized coordinates |
| 163 // for this texture if the texture is power of two sized. | 163 // for this texture if the texture is power of two sized. |
| 164 int fShiftFixedX; | 164 int fShiftFixedX; |
| 165 int fShiftFixedY; | 165 int fShiftFixedY; |
| 166 | 166 |
| 167 bool fMipMapsDirty; | 167 MipMapsStatus fMipMapsStatus; |
| 168 | 168 |
| 169 virtual void internal_dispose() const SK_OVERRIDE; | 169 virtual void internal_dispose() const SK_OVERRIDE; |
| 170 | 170 |
| 171 typedef GrSurface INHERITED; | 171 typedef GrSurface INHERITED; |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 /** | 174 /** |
| 175 * Represents a texture that is intended to be accessed in device coords with an
offset. | 175 * Represents a texture that is intended to be accessed in device coords with an
offset. |
| 176 */ | 176 */ |
| 177 class GrDeviceCoordTexture { | 177 class GrDeviceCoordTexture { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 203 GrTexture* setTexture(GrTexture* texture) { | 203 GrTexture* setTexture(GrTexture* texture) { |
| 204 fTexture.reset(SkSafeRef(texture)); | 204 fTexture.reset(SkSafeRef(texture)); |
| 205 return texture; | 205 return texture; |
| 206 } | 206 } |
| 207 private: | 207 private: |
| 208 SkAutoTUnref<GrTexture> fTexture; | 208 SkAutoTUnref<GrTexture> fTexture; |
| 209 SkIPoint fOffset; | 209 SkIPoint fOffset; |
| 210 }; | 210 }; |
| 211 | 211 |
| 212 #endif | 212 #endif |
| OLD | NEW |