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 | |
jvanverth | d1e7287 | 2015-04-20 12:29:37 -0700 | [diff] [blame] | 16 | class GrGLGpu; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 17 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 18 | class GrGLTexture : public GrTexture { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 19 | public: |
bsalomon@google.com | da96ea0 | 2010-12-23 16:53:57 +0000 | [diff] [blame] | 20 | struct TexParams { |
commit-bot@chromium.org | 149f4f5 | 2013-07-26 20:40:06 +0000 | [diff] [blame] | 21 | GrGLenum fMinFilter; |
| 22 | GrGLenum fMagFilter; |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 23 | GrGLenum fWrapS; |
| 24 | GrGLenum fWrapT; |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 25 | GrGLenum fMaxMipMapLevel; |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 26 | GrGLenum fSwizzleRGBA[4]; |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 27 | GrGLenum fSRGBDecode; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 28 | void invalidate() { memset(this, 0xff, sizeof(TexParams)); } |
bsalomon@google.com | da96ea0 | 2010-12-23 16:53:57 +0000 | [diff] [blame] | 29 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 30 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 31 | struct IDDesc { |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 32 | GrGLTextureInfo fInfo; |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 33 | GrBackendObjectOwnership fOwnership; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 34 | }; |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 35 | GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&); |
| 36 | GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&, |
Greg Daniel | 834f120 | 2017-10-09 15:06:20 -0400 | [diff] [blame] | 37 | bool mipsAllocated, bool wasFullMipMapDataProvided); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 38 | |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 39 | ~GrGLTexture() override { |
| 40 | // check that invokeReleaseProc has been called (if needed) |
| 41 | SkASSERT(!fReleaseProc); |
| 42 | } |
| 43 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 44 | GrBackendObject getTextureHandle() const override; |
junov@chromium.org | 957ebdd | 2012-06-12 13:58:36 +0000 | [diff] [blame] | 45 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 46 | void textureParamsModified() override { fTexParams.invalidate(); } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 47 | |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 48 | void setRelease(ReleaseProc proc, ReleaseCtx ctx) override { |
| 49 | fReleaseProc = proc; |
| 50 | fReleaseCtx = ctx; |
| 51 | } |
| 52 | |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 53 | // 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] | 54 | const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const { |
| 55 | *timestamp = fTexParamsTimestamp; |
| 56 | return fTexParams; |
| 57 | } |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 58 | |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 59 | void setCachedTexParams(const TexParams& texParams, |
| 60 | GrGpu::ResetTimestamp timestamp) { |
| 61 | fTexParams = texParams; |
| 62 | fTexParamsTimestamp = timestamp; |
| 63 | } |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 64 | |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 65 | GrGLuint textureID() const { return fInfo.fID; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 66 | |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 67 | GrGLenum target() const { return fInfo.fTarget; } |
bsalomon | 10528f1 | 2015-10-14 12:54:52 -0700 | [diff] [blame] | 68 | |
Brian Salomon | 9bada54 | 2017-06-12 12:09:30 -0400 | [diff] [blame] | 69 | bool hasBaseLevelBeenBoundToFBO() const { return fBaseLevelHasBeenBoundToFBO; } |
| 70 | void baseLevelWasBoundToFBO() { fBaseLevelHasBeenBoundToFBO = true; } |
| 71 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 72 | static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&); |
Brian Salomon | 9bada54 | 2017-06-12 12:09:30 -0400 | [diff] [blame] | 73 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 74 | protected: |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 75 | // Constructor for subclasses. |
Greg Daniel | 834f120 | 2017-10-09 15:06:20 -0400 | [diff] [blame] | 76 | GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, |
| 77 | bool mipsAllocated, bool wasMipMapDataProvided); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 78 | |
| 79 | enum Wrapped { kWrapped }; |
| 80 | // Constructor for instances wrapping backend objects. |
| 81 | GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, const IDDesc&); |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 82 | |
| 83 | void init(const GrSurfaceDesc&, const IDDesc&); |
| 84 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 85 | void onAbandon() override; |
| 86 | void onRelease() override; |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 87 | void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, |
| 88 | const SkString& dumpName) const override; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 89 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 90 | private: |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 91 | void invokeReleaseProc() { |
| 92 | if (fReleaseProc) { |
| 93 | fReleaseProc(fReleaseCtx); |
| 94 | fReleaseProc = nullptr; |
| 95 | } |
| 96 | } |
| 97 | |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 98 | TexParams fTexParams; |
| 99 | GrGpu::ResetTimestamp fTexParamsTimestamp; |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 100 | // Holds the texture target and ID. A pointer to this may be shared to external clients for |
| 101 | // direct interaction with the GL object. |
| 102 | GrGLTextureInfo fInfo; |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 103 | GrBackendObjectOwnership fTextureIDOwnership; |
Brian Salomon | 9bada54 | 2017-06-12 12:09:30 -0400 | [diff] [blame] | 104 | bool fBaseLevelHasBeenBoundToFBO = false; |
hendrikw | 9a0c7ab | 2014-12-09 14:26:47 -0800 | [diff] [blame] | 105 | |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 106 | ReleaseProc fReleaseProc = nullptr; |
| 107 | ReleaseCtx fReleaseCtx = nullptr; |
| 108 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 109 | typedef GrTexture INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | #endif |