epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 9 | #ifndef GrTexture_DEFINED |
| 10 | #define GrTexture_DEFINED |
| 11 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 12 | #include "GrSurface.h" |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 13 | #include "GrRenderTarget.h" |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 14 | #include "SkPoint.h" |
| 15 | #include "SkRefCnt.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | |
robertphillips@google.com | a1e5795 | 2012-06-04 20:05:28 +0000 | [diff] [blame] | 17 | class GrResourceKey; |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 18 | class GrTextureParams; |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 19 | class GrTexturePriv; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 20 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 21 | class GrTexture : public GrSurface { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 22 | public: |
commit-bot@chromium.org | 59e7d23 | 2014-05-09 18:02:51 +0000 | [diff] [blame] | 23 | /** |
| 24 | * Approximate number of bytes used by the texture |
| 25 | */ |
| 26 | virtual size_t gpuMemorySize() const SK_OVERRIDE; |
| 27 | |
| 28 | // GrSurface overrides |
| 29 | virtual bool readPixels(int left, int top, int width, int height, |
| 30 | GrPixelConfig config, |
| 31 | void* buffer, |
| 32 | size_t rowBytes = 0, |
| 33 | uint32_t pixelOpsFlags = 0) SK_OVERRIDE; |
| 34 | |
| 35 | virtual void writePixels(int left, int top, int width, int height, |
| 36 | GrPixelConfig config, |
| 37 | const void* buffer, |
| 38 | size_t rowBytes = 0, |
| 39 | uint32_t pixelOpsFlags = 0) SK_OVERRIDE; |
| 40 | |
commit-bot@chromium.org | 59e7d23 | 2014-05-09 18:02:51 +0000 | [diff] [blame] | 41 | virtual GrTexture* asTexture() SK_OVERRIDE { return this; } |
| 42 | virtual const GrTexture* asTexture() const SK_OVERRIDE { return this; } |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 43 | virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { return fRenderTarget.get(); } |
| 44 | virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { return fRenderTarget.get(); } |
commit-bot@chromium.org | 59e7d23 | 2014-05-09 18:02:51 +0000 | [diff] [blame] | 45 | |
| 46 | /** |
commit-bot@chromium.org | 59e7d23 | 2014-05-09 18:02:51 +0000 | [diff] [blame] | 47 | * Return the native ID or handle to the texture, depending on the |
| 48 | * platform. e.g. on OpenGL, return the texture ID. |
| 49 | */ |
| 50 | virtual GrBackendObject getTextureHandle() const = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 51 | |
junov@chromium.org | 957ebdd | 2012-06-12 13:58:36 +0000 | [diff] [blame] | 52 | /** |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 53 | * This function indicates that the texture parameters (wrap mode, filtering, ...) have been |
| 54 | * changed externally to Skia. |
junov@chromium.org | 957ebdd | 2012-06-12 13:58:36 +0000 | [diff] [blame] | 55 | */ |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 56 | virtual void textureParamsModified() = 0; |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 57 | |
| 58 | /** |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 59 | * Informational texture flags. This will be removed soon. |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 60 | */ |
| 61 | enum FlagBits { |
| 62 | kFirstBit = (kLastPublic_GrTextureFlagBit << 1), |
| 63 | |
| 64 | /** |
| 65 | * This texture should be returned to the texture cache when |
| 66 | * it is no longer reffed |
| 67 | */ |
| 68 | kReturnToCache_FlagBit = kFirstBit, |
| 69 | }; |
| 70 | |
| 71 | void resetFlag(GrTextureFlags flags) { |
| 72 | fDesc.fFlags = fDesc.fFlags & ~flags; |
| 73 | } |
junov@chromium.org | 957ebdd | 2012-06-12 13:58:36 +0000 | [diff] [blame] | 74 | |
commit-bot@chromium.org | 59e7d23 | 2014-05-09 18:02:51 +0000 | [diff] [blame] | 75 | #ifdef SK_DEBUG |
| 76 | void validate() const { |
| 77 | this->INHERITED::validate(); |
commit-bot@chromium.org | 59e7d23 | 2014-05-09 18:02:51 +0000 | [diff] [blame] | 78 | this->validateDesc(); |
| 79 | } |
| 80 | #endif |
| 81 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 82 | /** Access methods that are only to be used within Skia code. */ |
| 83 | inline GrTexturePriv texturePriv(); |
| 84 | inline const GrTexturePriv texturePriv() const; |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 85 | |
| 86 | protected: |
| 87 | // A texture refs its rt representation but not vice-versa. It is up to |
| 88 | // the subclass constructor to initialize this pointer. |
| 89 | SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 90 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 91 | GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc); |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 92 | |
| 93 | virtual ~GrTexture(); |
| 94 | |
| 95 | // GrResource overrides |
| 96 | virtual void onRelease() SK_OVERRIDE; |
| 97 | virtual void onAbandon() SK_OVERRIDE; |
| 98 | |
| 99 | void validateDesc() const; |
| 100 | |
| 101 | private: |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 102 | void dirtyMipMaps(bool mipMapsDirty); |
| 103 | |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 104 | enum MipMapsStatus { |
| 105 | kNotAllocated_MipMapsStatus, |
| 106 | kAllocated_MipMapsStatus, |
| 107 | kValid_MipMapsStatus |
| 108 | }; |
| 109 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 110 | MipMapsStatus fMipMapsStatus; |
| 111 | // These two shift a fixed-point value into normalized coordinates |
| 112 | // for this texture if the texture is power of two sized. |
| 113 | int fShiftFixedX; |
| 114 | int fShiftFixedY; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 115 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 116 | friend class GrTexturePriv; |
| 117 | |
| 118 | typedef GrSurface INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 121 | /** |
| 122 | * Represents a texture that is intended to be accessed in device coords with an offset. |
| 123 | */ |
| 124 | class GrDeviceCoordTexture { |
| 125 | public: |
| 126 | GrDeviceCoordTexture() { fOffset.set(0, 0); } |
| 127 | |
| 128 | GrDeviceCoordTexture(const GrDeviceCoordTexture& other) { |
| 129 | *this = other; |
| 130 | } |
| 131 | |
| 132 | GrDeviceCoordTexture(GrTexture* texture, const SkIPoint& offset) |
| 133 | : fTexture(SkSafeRef(texture)) |
| 134 | , fOffset(offset) { |
| 135 | } |
| 136 | |
| 137 | GrDeviceCoordTexture& operator=(const GrDeviceCoordTexture& other) { |
| 138 | fTexture.reset(SkSafeRef(other.fTexture.get())); |
| 139 | fOffset = other.fOffset; |
| 140 | return *this; |
| 141 | } |
| 142 | |
| 143 | const SkIPoint& offset() const { return fOffset; } |
| 144 | |
| 145 | void setOffset(const SkIPoint& offset) { fOffset = offset; } |
| 146 | void setOffset(int ox, int oy) { fOffset.set(ox, oy); } |
| 147 | |
| 148 | GrTexture* texture() const { return fTexture.get(); } |
| 149 | |
| 150 | GrTexture* setTexture(GrTexture* texture) { |
| 151 | fTexture.reset(SkSafeRef(texture)); |
| 152 | return texture; |
| 153 | } |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 154 | |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 155 | private: |
| 156 | SkAutoTUnref<GrTexture> fTexture; |
| 157 | SkIPoint fOffset; |
| 158 | }; |
| 159 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 160 | #endif |