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 | 327955b | 2018-10-22 15:39:22 +0000 | [diff] [blame] | 20 | struct TexParams { |
| 21 | GrGLenum fMinFilter; |
| 22 | GrGLenum fMagFilter; |
| 23 | GrGLenum fWrapS; |
| 24 | GrGLenum fWrapT; |
| 25 | GrGLenum fMaxMipMapLevel; |
| 26 | GrGLenum fSwizzleRGBA[4]; |
| 27 | void invalidate() { memset(this, 0xff, sizeof(TexParams)); } |
bsalomon@google.com | da96ea0 | 2010-12-23 16:53:57 +0000 | [diff] [blame] | 28 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 29 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 30 | struct IDDesc { |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 31 | GrGLTextureInfo fInfo; |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 32 | GrBackendObjectOwnership fOwnership; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 33 | }; |
Brian Salomon | 7226c23 | 2018-07-30 13:13:17 -0400 | [diff] [blame] | 34 | |
| 35 | static GrTextureType TextureTypeFromTarget(GrGLenum textureTarget); |
| 36 | |
Greg Daniel | 0fc4d2d | 2017-10-12 11:23:36 -0400 | [diff] [blame] | 37 | GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&, GrMipMapsStatus); |
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) |
Greg Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 41 | SkASSERT(!fReleaseHelper); |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 42 | } |
| 43 | |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 44 | GrBackendTexture getBackendTexture() const override; |
junov@chromium.org | 957ebdd | 2012-06-12 13:58:36 +0000 | [diff] [blame] | 45 | |
Brian Salomon | 327955b | 2018-10-22 15:39:22 +0000 | [diff] [blame] | 46 | void textureParamsModified() override { fTexParams.invalidate(); } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 47 | |
Greg Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 48 | void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override { |
| 49 | fReleaseHelper = std::move(releaseHelper); |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 50 | } |
| 51 | |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 52 | // These functions are used to track the texture parameters associated with the texture. |
Brian Salomon | 327955b | 2018-10-22 15:39:22 +0000 | [diff] [blame] | 53 | const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const { |
| 54 | *timestamp = fTexParamsTimestamp; |
| 55 | return fTexParams; |
| 56 | } |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 57 | |
Brian Salomon | 327955b | 2018-10-22 15:39:22 +0000 | [diff] [blame] | 58 | void setCachedTexParams(const TexParams& texParams, |
| 59 | GrGpu::ResetTimestamp timestamp) { |
| 60 | fTexParams = texParams; |
| 61 | fTexParamsTimestamp = timestamp; |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 62 | } |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 63 | |
Brian Salomon | 60dd8c7 | 2018-07-30 10:24:13 -0400 | [diff] [blame] | 64 | GrGLuint textureID() const { return fID; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 65 | |
Brian Salomon | 60dd8c7 | 2018-07-30 10:24:13 -0400 | [diff] [blame] | 66 | GrGLenum target() const; |
bsalomon | 10528f1 | 2015-10-14 12:54:52 -0700 | [diff] [blame] | 67 | |
Brian Salomon | 9bada54 | 2017-06-12 12:09:30 -0400 | [diff] [blame] | 68 | bool hasBaseLevelBeenBoundToFBO() const { return fBaseLevelHasBeenBoundToFBO; } |
| 69 | void baseLevelWasBoundToFBO() { fBaseLevelHasBeenBoundToFBO = true; } |
| 70 | |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 71 | static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, GrMipMapsStatus, |
| 72 | const IDDesc&); |
Brian Salomon | 9bada54 | 2017-06-12 12:09:30 -0400 | [diff] [blame] | 73 | |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 74 | void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override; |
| 75 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 76 | protected: |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 77 | // Constructor for subclasses. |
Greg Daniel | 0fc4d2d | 2017-10-12 11:23:36 -0400 | [diff] [blame] | 78 | GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, GrMipMapsStatus); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 79 | |
| 80 | enum Wrapped { kWrapped }; |
| 81 | // Constructor for instances wrapping backend objects. |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 82 | GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, GrMipMapsStatus, const IDDesc&); |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 83 | |
| 84 | void init(const GrSurfaceDesc&, const IDDesc&); |
| 85 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 86 | void onAbandon() override; |
| 87 | void onRelease() override; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 88 | |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 89 | bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override; |
| 90 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 91 | private: |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 92 | void invokeReleaseProc() { |
Greg Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 93 | if (fReleaseHelper) { |
| 94 | // Depending on the ref count of fReleaseHelper this may or may not actually trigger the |
| 95 | // ReleaseProc to be called. |
| 96 | fReleaseHelper.reset(); |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
Brian Salomon | 327955b | 2018-10-22 15:39:22 +0000 | [diff] [blame] | 100 | TexParams fTexParams; |
| 101 | GrGpu::ResetTimestamp fTexParamsTimestamp; |
| 102 | GrGLuint fID; |
| 103 | GrGLenum fFormat; |
| 104 | GrBackendObjectOwnership fTextureIDOwnership; |
| 105 | bool fBaseLevelHasBeenBoundToFBO = false; |
| 106 | |
| 107 | sk_sp<GrReleaseProcHelper> fReleaseHelper; |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 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 |