blob: f2dc739f2d468ec4f2eadb9e7bc12d9953afd1db [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * 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.comac10a2d2010-12-22 21:39:39 +00006 */
7
epoger@google.comec3ed6a2011-07-28 14:26:00 +00008
reed@google.comac10a2d2010-12-22 21:39:39 +00009#ifndef GrGLTexture_DEFINED
10#define GrGLTexture_DEFINED
11
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000012#include "GrGpu.h"
bsalomon37dd3312014-11-03 08:47:23 -080013#include "GrTexture.h"
14#include "GrGLUtil.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000015
jvanverthd1e72872015-04-20 12:29:37 -070016class GrGLGpu;
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000017
bsalomonafbf2d62014-09-30 12:18:44 -070018class GrGLTexture : public GrTexture {
reed@google.comac10a2d2010-12-22 21:39:39 +000019public:
bsalomon@google.comda96ea02010-12-23 16:53:57 +000020 struct TexParams {
commit-bot@chromium.org149f4f52013-07-26 20:40:06 +000021 GrGLenum fMinFilter;
22 GrGLenum fMagFilter;
twiz@google.com0f31ca72011-03-18 17:38:11 +000023 GrGLenum fWrapS;
24 GrGLenum fWrapT;
cblume55f2d2d2016-02-26 13:20:48 -080025 GrGLenum fMaxMipMapLevel;
bsalomon@google.com0a97be22011-11-08 19:20:57 +000026 GrGLenum fSwizzleRGBA[4];
brianosmana6359362016-03-21 06:55:37 -070027 GrGLenum fSRGBDecode;
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000028 void invalidate() { memset(this, 0xff, sizeof(TexParams)); }
bsalomon@google.comda96ea02010-12-23 16:53:57 +000029 };
reed@google.comac10a2d2010-12-22 21:39:39 +000030
bsalomonb15b4c12014-10-29 12:41:57 -070031 struct IDDesc {
bsalomon091f60c2015-11-10 11:54:56 -080032 GrGLTextureInfo fInfo;
kkinnunen2e6055b2016-04-22 01:48:29 -070033 GrBackendObjectOwnership fOwnership;
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000034 };
kkinnunen2e6055b2016-04-22 01:48:29 -070035 GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&);
36 GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&,
Greg Daniel834f1202017-10-09 15:06:20 -040037 bool mipsAllocated, bool wasFullMipMapDataProvided);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000038
Greg Danielcef213c2017-04-21 11:52:27 -040039 ~GrGLTexture() override {
40 // check that invokeReleaseProc has been called (if needed)
41 SkASSERT(!fReleaseProc);
42 }
43
mtklein36352bf2015-03-25 18:17:31 -070044 GrBackendObject getTextureHandle() const override;
junov@chromium.org957ebdd2012-06-12 13:58:36 +000045
mtklein36352bf2015-03-25 18:17:31 -070046 void textureParamsModified() override { fTexParams.invalidate(); }
reed@google.comac10a2d2010-12-22 21:39:39 +000047
Greg Danielcef213c2017-04-21 11:52:27 -040048 void setRelease(ReleaseProc proc, ReleaseCtx ctx) override {
49 fReleaseProc = proc;
50 fReleaseCtx = ctx;
51 }
52
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000053 // These functions are used to track the texture parameters associated with the texture.
bsalomon@google.com80d09b92011-11-05 21:21:13 +000054 const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const {
55 *timestamp = fTexParamsTimestamp;
56 return fTexParams;
57 }
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000058
bsalomon@google.com80d09b92011-11-05 21:21:13 +000059 void setCachedTexParams(const TexParams& texParams,
60 GrGpu::ResetTimestamp timestamp) {
61 fTexParams = texParams;
62 fTexParamsTimestamp = timestamp;
63 }
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000064
bsalomon091f60c2015-11-10 11:54:56 -080065 GrGLuint textureID() const { return fInfo.fID; }
reed@google.comac10a2d2010-12-22 21:39:39 +000066
bsalomon091f60c2015-11-10 11:54:56 -080067 GrGLenum target() const { return fInfo.fTarget; }
bsalomon10528f12015-10-14 12:54:52 -070068
Brian Salomon9bada542017-06-12 12:09:30 -040069 bool hasBaseLevelBeenBoundToFBO() const { return fBaseLevelHasBeenBoundToFBO; }
70 void baseLevelWasBoundToFBO() { fBaseLevelHasBeenBoundToFBO = true; }
71
bungeman6bd52842016-10-27 09:30:08 -070072 static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
Brian Salomon9bada542017-06-12 12:09:30 -040073
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000074protected:
kkinnunen2e6055b2016-04-22 01:48:29 -070075 // Constructor for subclasses.
Greg Daniel834f1202017-10-09 15:06:20 -040076 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&,
77 bool mipsAllocated, bool wasMipMapDataProvided);
kkinnunen2e6055b2016-04-22 01:48:29 -070078
79 enum Wrapped { kWrapped };
80 // Constructor for instances wrapping backend objects.
81 GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, const IDDesc&);
bsalomon37dd3312014-11-03 08:47:23 -080082
83 void init(const GrSurfaceDesc&, const IDDesc&);
84
mtklein36352bf2015-03-25 18:17:31 -070085 void onAbandon() override;
86 void onRelease() override;
ericrk0a5fa482015-09-15 14:16:10 -070087 void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
88 const SkString& dumpName) const override;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000089
reed@google.comac10a2d2010-12-22 21:39:39 +000090private:
Greg Danielcef213c2017-04-21 11:52:27 -040091 void invokeReleaseProc() {
92 if (fReleaseProc) {
93 fReleaseProc(fReleaseCtx);
94 fReleaseProc = nullptr;
95 }
96 }
97
bsalomon@google.com80d09b92011-11-05 21:21:13 +000098 TexParams fTexParams;
99 GrGpu::ResetTimestamp fTexParamsTimestamp;
bsalomon091f60c2015-11-10 11:54:56 -0800100 // 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;
kkinnunen2e6055b2016-04-22 01:48:29 -0700103 GrBackendObjectOwnership fTextureIDOwnership;
Brian Salomon9bada542017-06-12 12:09:30 -0400104 bool fBaseLevelHasBeenBoundToFBO = false;
hendrikw9a0c7ab2014-12-09 14:26:47 -0800105
Greg Danielcef213c2017-04-21 11:52:27 -0400106 ReleaseProc fReleaseProc = nullptr;
107 ReleaseCtx fReleaseCtx = nullptr;
108
bsalomonafbf2d62014-09-30 12:18:44 -0700109 typedef GrTexture INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000110};
111
112#endif