reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 8 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 9 | #ifndef GrGLTexture_DEFINED |
| 10 | #define GrGLTexture_DEFINED |
| 11 | |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 12 | #include "GrGpu.h" |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame^] | 13 | #include "GrTexture.h" |
| 14 | #include "GrGLUtil.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 15 | |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 16 | /** |
| 17 | * A ref counted tex id that deletes the texture in its destructor. |
| 18 | */ |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 19 | class GrGLTexID : public SkRefCnt { |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 20 | public: |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 21 | SK_DECLARE_INST_COUNT(GrGLTexID) |
| 22 | |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 23 | GrGLTexID(const GrGLInterface* gl, GrGLuint texID, bool isWrapped) |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 24 | : fGL(gl) |
| 25 | , fTexID(texID) |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 26 | , fIsWrapped(isWrapped) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 27 | } |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 28 | |
| 29 | virtual ~GrGLTexID() { |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 30 | if (0 != fTexID && !fIsWrapped) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 31 | GR_GL_CALL(fGL, DeleteTextures(1, &fTexID)); |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 32 | } |
| 33 | } |
| 34 | |
| 35 | void abandon() { fTexID = 0; } |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 36 | GrGLuint id() const { return fTexID; } |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 37 | |
| 38 | private: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 39 | const GrGLInterface* fGL; |
| 40 | GrGLuint fTexID; |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 41 | bool fIsWrapped; |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 42 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 43 | typedef SkRefCnt INHERITED; |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 46 | //////////////////////////////////////////////////////////////////////////////// |
| 47 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 48 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 49 | class GrGLTexture : public GrTexture { |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 50 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 51 | public: |
bsalomon@google.com | da96ea0 | 2010-12-23 16:53:57 +0000 | [diff] [blame] | 52 | struct TexParams { |
commit-bot@chromium.org | 149f4f5 | 2013-07-26 20:40:06 +0000 | [diff] [blame] | 53 | GrGLenum fMinFilter; |
| 54 | GrGLenum fMagFilter; |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 55 | GrGLenum fWrapS; |
| 56 | GrGLenum fWrapT; |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 57 | GrGLenum fSwizzleRGBA[4]; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 58 | void invalidate() { memset(this, 0xff, sizeof(TexParams)); } |
bsalomon@google.com | da96ea0 | 2010-12-23 16:53:57 +0000 | [diff] [blame] | 59 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 60 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 61 | struct IDDesc { |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 62 | GrGLuint fTextureID; |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 63 | bool fIsWrapped; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame^] | 66 | GrGLTexture(GrGpuGL*, const GrSurfaceDesc&, const IDDesc&); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 67 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 68 | virtual ~GrGLTexture() { this->release(); } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 69 | |
bsalomon@google.com | 08afc84 | 2012-10-25 18:56:10 +0000 | [diff] [blame] | 70 | virtual GrBackendObject getTextureHandle() const SK_OVERRIDE; |
junov@chromium.org | 957ebdd | 2012-06-12 13:58:36 +0000 | [diff] [blame] | 71 | |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 72 | virtual void textureParamsModified() SK_OVERRIDE { fTexParams.invalidate(); } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 73 | |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 74 | // These functions are used to track the texture parameters associated with the texture. |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 75 | const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const { |
| 76 | *timestamp = fTexParamsTimestamp; |
| 77 | return fTexParams; |
| 78 | } |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 79 | |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 80 | void setCachedTexParams(const TexParams& texParams, |
| 81 | GrGpu::ResetTimestamp timestamp) { |
| 82 | fTexParams = texParams; |
| 83 | fTexParamsTimestamp = timestamp; |
| 84 | } |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 85 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 86 | GrGLuint textureID() const { return (fTexIDObj.get()) ? fTexIDObj->id() : 0; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 87 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 88 | protected: |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame^] | 89 | // The public constructor registers this object with the cache. However, only the most derived |
| 90 | // class should register with the cache. This constructor does not do the registration and |
| 91 | // rather moves that burden onto the derived class. |
| 92 | enum Derived { kDerived }; |
| 93 | GrGLTexture(GrGpuGL*, const GrSurfaceDesc&, const IDDesc&, Derived); |
| 94 | |
| 95 | void init(const GrSurfaceDesc&, const IDDesc&); |
| 96 | |
junov@chromium.org | 957ebdd | 2012-06-12 13:58:36 +0000 | [diff] [blame] | 97 | virtual void onAbandon() SK_OVERRIDE; |
| 98 | virtual void onRelease() SK_OVERRIDE; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 99 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 100 | private: |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 101 | TexParams fTexParams; |
| 102 | GrGpu::ResetTimestamp fTexParamsTimestamp; |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 103 | SkAutoTUnref<GrGLTexID> fTexIDObj; |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 104 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 105 | typedef GrTexture INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | #endif |