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: |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 20 | // Texture state that overlaps with sampler object state. We don't need to track this if we |
| 21 | // are using sampler objects. |
| 22 | struct SamplerParams { |
| 23 | // These are the OpenGL defaults. |
| 24 | GrGLenum fMinFilter = GR_GL_NEAREST_MIPMAP_LINEAR; |
| 25 | GrGLenum fMagFilter = GR_GL_LINEAR; |
| 26 | GrGLenum fWrapS = GR_GL_REPEAT; |
| 27 | GrGLenum fWrapT = GR_GL_REPEAT; |
| 28 | GrGLfloat fMinLOD = -1000.f; |
| 29 | GrGLfloat fMaxLOD = 1000.f; |
| 30 | void invalidate() { |
| 31 | fMinFilter = ~0U; |
| 32 | fMagFilter = ~0U; |
| 33 | fWrapS = ~0U; |
| 34 | fWrapT = ~0U; |
| 35 | fMinLOD = SK_ScalarNaN; |
| 36 | fMaxLOD = SK_ScalarNaN; |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | // Texture state that does not overlap with sampler object state. |
| 41 | struct NonSamplerParams { |
| 42 | // These are the OpenGL defaults. |
| 43 | uint32_t fSwizzleKey = GrSwizzle::RGBA().asKey(); |
| 44 | GrGLint fBaseMipMapLevel = 0; |
| 45 | GrGLint fMaxMipMapLevel = 1000; |
| 46 | void invalidate() { |
| 47 | fSwizzleKey = ~0U; |
| 48 | fBaseMipMapLevel = ~0; |
| 49 | fMaxMipMapLevel = ~0; |
| 50 | } |
bsalomon@google.com | da96ea0 | 2010-12-23 16:53:57 +0000 | [diff] [blame] | 51 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 52 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 53 | struct IDDesc { |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 54 | GrGLTextureInfo fInfo; |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 55 | GrBackendObjectOwnership fOwnership; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 56 | }; |
Brian Salomon | 7226c23 | 2018-07-30 13:13:17 -0400 | [diff] [blame] | 57 | |
| 58 | static GrTextureType TextureTypeFromTarget(GrGLenum textureTarget); |
| 59 | |
Greg Daniel | 0fc4d2d | 2017-10-12 11:23:36 -0400 | [diff] [blame] | 60 | GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&, GrMipMapsStatus); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 61 | |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 62 | ~GrGLTexture() override { |
| 63 | // check that invokeReleaseProc has been called (if needed) |
Greg Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 64 | SkASSERT(!fReleaseHelper); |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 65 | } |
| 66 | |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 67 | GrBackendTexture getBackendTexture() const override; |
junov@chromium.org | 957ebdd | 2012-06-12 13:58:36 +0000 | [diff] [blame] | 68 | |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 69 | void textureParamsModified() override { |
| 70 | fSamplerParams.invalidate(); |
| 71 | fNonSamplerParams.invalidate(); |
| 72 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 73 | |
Greg Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 74 | void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override { |
| 75 | fReleaseHelper = std::move(releaseHelper); |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 76 | } |
| 77 | |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 78 | // These functions are used to track the texture parameters associated with the texture. |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 79 | GrGpu::ResetTimestamp getCachedParamsTimestamp() const { return fParamsTimestamp; } |
| 80 | const SamplerParams& getCachedSamplerParams() const { return fSamplerParams; } |
| 81 | const NonSamplerParams& getCachedNonSamplerParams() const { return fNonSamplerParams; } |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 82 | |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 83 | void setCachedParams(const SamplerParams* samplerParams, |
| 84 | const NonSamplerParams& nonSamplerParams, |
| 85 | GrGpu::ResetTimestamp currTimestamp) { |
| 86 | if (samplerParams) { |
| 87 | fSamplerParams = *samplerParams; |
| 88 | } |
| 89 | fNonSamplerParams = nonSamplerParams; |
| 90 | fParamsTimestamp = currTimestamp; |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 91 | } |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 92 | |
Brian Salomon | 60dd8c7 | 2018-07-30 10:24:13 -0400 | [diff] [blame] | 93 | GrGLuint textureID() const { return fID; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 94 | |
Brian Salomon | 60dd8c7 | 2018-07-30 10:24:13 -0400 | [diff] [blame] | 95 | GrGLenum target() const; |
bsalomon | 10528f1 | 2015-10-14 12:54:52 -0700 | [diff] [blame] | 96 | |
Brian Salomon | 9bada54 | 2017-06-12 12:09:30 -0400 | [diff] [blame] | 97 | bool hasBaseLevelBeenBoundToFBO() const { return fBaseLevelHasBeenBoundToFBO; } |
| 98 | void baseLevelWasBoundToFBO() { fBaseLevelHasBeenBoundToFBO = true; } |
| 99 | |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 100 | static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, GrMipMapsStatus, |
Greg Daniel | 2268ad2 | 2018-11-15 09:27:38 -0500 | [diff] [blame] | 101 | const IDDesc&, bool purgeImmediately); |
Brian Salomon | 9bada54 | 2017-06-12 12:09:30 -0400 | [diff] [blame] | 102 | |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 103 | void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override; |
| 104 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 105 | protected: |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 106 | // Constructor for subclasses. |
Greg Daniel | 0fc4d2d | 2017-10-12 11:23:36 -0400 | [diff] [blame] | 107 | GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, GrMipMapsStatus); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 108 | |
| 109 | enum Wrapped { kWrapped }; |
| 110 | // Constructor for instances wrapping backend objects. |
Greg Daniel | 2268ad2 | 2018-11-15 09:27:38 -0500 | [diff] [blame] | 111 | GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, GrMipMapsStatus, const IDDesc&, |
| 112 | bool purgeImmediately); |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 113 | |
| 114 | void init(const GrSurfaceDesc&, const IDDesc&); |
| 115 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 116 | void onAbandon() override; |
| 117 | void onRelease() override; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 118 | |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 119 | bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override; |
| 120 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 121 | private: |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 122 | void invokeReleaseProc() { |
Greg Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 123 | if (fReleaseHelper) { |
| 124 | // Depending on the ref count of fReleaseHelper this may or may not actually trigger the |
| 125 | // ReleaseProc to be called. |
| 126 | fReleaseHelper.reset(); |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 130 | SamplerParams fSamplerParams; |
| 131 | NonSamplerParams fNonSamplerParams; |
| 132 | GrGpu::ResetTimestamp fParamsTimestamp; |
| 133 | sk_sp<GrReleaseProcHelper> fReleaseHelper; |
| 134 | GrGLuint fID; |
| 135 | GrGLenum fFormat; |
| 136 | GrBackendObjectOwnership fTextureIDOwnership; |
| 137 | bool fBaseLevelHasBeenBoundToFBO = false; |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 138 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 139 | typedef GrTexture INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | #endif |