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 | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 13 | #include "SkPoint.h" |
| 14 | #include "SkRefCnt.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 15 | |
robertphillips@google.com | a1e5795 | 2012-06-04 20:05:28 +0000 | [diff] [blame] | 16 | class GrResourceKey; |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 17 | class GrTextureParams; |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 18 | class GrTexturePriv; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 19 | |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 20 | class GrTexture : virtual public GrSurface { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 21 | public: |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 22 | GrTexture* asTexture() SK_OVERRIDE { return this; } |
| 23 | const GrTexture* asTexture() const SK_OVERRIDE { return this; } |
commit-bot@chromium.org | 59e7d23 | 2014-05-09 18:02:51 +0000 | [diff] [blame] | 24 | |
| 25 | /** |
commit-bot@chromium.org | 59e7d23 | 2014-05-09 18:02:51 +0000 | [diff] [blame] | 26 | * Return the native ID or handle to the texture, depending on the |
| 27 | * platform. e.g. on OpenGL, return the texture ID. |
| 28 | */ |
| 29 | virtual GrBackendObject getTextureHandle() const = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 30 | |
junov@chromium.org | 957ebdd | 2012-06-12 13:58:36 +0000 | [diff] [blame] | 31 | /** |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 32 | * This function indicates that the texture parameters (wrap mode, filtering, ...) have been |
| 33 | * changed externally to Skia. |
junov@chromium.org | 957ebdd | 2012-06-12 13:58:36 +0000 | [diff] [blame] | 34 | */ |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 35 | virtual void textureParamsModified() = 0; |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 36 | |
commit-bot@chromium.org | 59e7d23 | 2014-05-09 18:02:51 +0000 | [diff] [blame] | 37 | #ifdef SK_DEBUG |
| 38 | void validate() const { |
| 39 | this->INHERITED::validate(); |
commit-bot@chromium.org | 59e7d23 | 2014-05-09 18:02:51 +0000 | [diff] [blame] | 40 | this->validateDesc(); |
| 41 | } |
| 42 | #endif |
| 43 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 44 | /** Access methods that are only to be used within Skia code. */ |
| 45 | inline GrTexturePriv texturePriv(); |
| 46 | inline const GrTexturePriv texturePriv() const; |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 47 | |
| 48 | protected: |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame^] | 49 | GrTexture(GrGpu*, LifeCycle, const GrSurfaceDesc&); |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 50 | |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 51 | void validateDesc() const; |
| 52 | |
| 53 | private: |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 54 | size_t onGpuMemorySize() const SK_OVERRIDE; |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 55 | void dirtyMipMaps(bool mipMapsDirty); |
| 56 | |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 57 | enum MipMapsStatus { |
| 58 | kNotAllocated_MipMapsStatus, |
| 59 | kAllocated_MipMapsStatus, |
| 60 | kValid_MipMapsStatus |
| 61 | }; |
| 62 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 63 | MipMapsStatus fMipMapsStatus; |
| 64 | // These two shift a fixed-point value into normalized coordinates |
| 65 | // for this texture if the texture is power of two sized. |
| 66 | int fShiftFixedX; |
| 67 | int fShiftFixedY; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 68 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 69 | friend class GrTexturePriv; |
| 70 | |
| 71 | typedef GrSurface INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 74 | /** |
| 75 | * Represents a texture that is intended to be accessed in device coords with an offset. |
| 76 | */ |
| 77 | class GrDeviceCoordTexture { |
| 78 | public: |
| 79 | GrDeviceCoordTexture() { fOffset.set(0, 0); } |
| 80 | |
| 81 | GrDeviceCoordTexture(const GrDeviceCoordTexture& other) { |
| 82 | *this = other; |
| 83 | } |
| 84 | |
| 85 | GrDeviceCoordTexture(GrTexture* texture, const SkIPoint& offset) |
| 86 | : fTexture(SkSafeRef(texture)) |
| 87 | , fOffset(offset) { |
| 88 | } |
| 89 | |
| 90 | GrDeviceCoordTexture& operator=(const GrDeviceCoordTexture& other) { |
| 91 | fTexture.reset(SkSafeRef(other.fTexture.get())); |
| 92 | fOffset = other.fOffset; |
| 93 | return *this; |
| 94 | } |
| 95 | |
| 96 | const SkIPoint& offset() const { return fOffset; } |
| 97 | |
| 98 | void setOffset(const SkIPoint& offset) { fOffset = offset; } |
| 99 | void setOffset(int ox, int oy) { fOffset.set(ox, oy); } |
| 100 | |
| 101 | GrTexture* texture() const { return fTexture.get(); } |
| 102 | |
| 103 | GrTexture* setTexture(GrTexture* texture) { |
| 104 | fTexture.reset(SkSafeRef(texture)); |
| 105 | return texture; |
| 106 | } |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 107 | |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 108 | private: |
| 109 | SkAutoTUnref<GrTexture> fTexture; |
| 110 | SkIPoint fOffset; |
| 111 | }; |
| 112 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 113 | #endif |