blob: cb029cca81bcc5a94521336b719fc28cb2fd1ff6 [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:
Brian Salomon327955b2018-10-22 15:39:22 +000020 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.comda96ea02010-12-23 16:53:57 +000028 };
reed@google.comac10a2d2010-12-22 21:39:39 +000029
bsalomonb15b4c12014-10-29 12:41:57 -070030 struct IDDesc {
bsalomon091f60c2015-11-10 11:54:56 -080031 GrGLTextureInfo fInfo;
kkinnunen2e6055b2016-04-22 01:48:29 -070032 GrBackendObjectOwnership fOwnership;
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000033 };
Brian Salomon7226c232018-07-30 13:13:17 -040034
35 static GrTextureType TextureTypeFromTarget(GrGLenum textureTarget);
36
Greg Daniel0fc4d2d2017-10-12 11:23:36 -040037 GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&, GrMipMapsStatus);
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)
Greg Daniel6a0176b2018-01-30 09:28:44 -050041 SkASSERT(!fReleaseHelper);
Greg Danielcef213c2017-04-21 11:52:27 -040042 }
43
Robert Phillipsb67821d2017-12-13 15:00:45 -050044 GrBackendTexture getBackendTexture() const override;
junov@chromium.org957ebdd2012-06-12 13:58:36 +000045
Brian Salomon327955b2018-10-22 15:39:22 +000046 void textureParamsModified() override { fTexParams.invalidate(); }
reed@google.comac10a2d2010-12-22 21:39:39 +000047
Greg Daniel6a0176b2018-01-30 09:28:44 -050048 void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {
49 fReleaseHelper = std::move(releaseHelper);
Greg Danielcef213c2017-04-21 11:52:27 -040050 }
51
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000052 // These functions are used to track the texture parameters associated with the texture.
Brian Salomon327955b2018-10-22 15:39:22 +000053 const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const {
54 *timestamp = fTexParamsTimestamp;
55 return fTexParams;
56 }
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000057
Brian Salomon327955b2018-10-22 15:39:22 +000058 void setCachedTexParams(const TexParams& texParams,
59 GrGpu::ResetTimestamp timestamp) {
60 fTexParams = texParams;
61 fTexParamsTimestamp = timestamp;
bsalomon@google.com80d09b92011-11-05 21:21:13 +000062 }
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000063
Brian Salomon60dd8c72018-07-30 10:24:13 -040064 GrGLuint textureID() const { return fID; }
reed@google.comac10a2d2010-12-22 21:39:39 +000065
Brian Salomon60dd8c72018-07-30 10:24:13 -040066 GrGLenum target() const;
bsalomon10528f12015-10-14 12:54:52 -070067
Brian Salomon9bada542017-06-12 12:09:30 -040068 bool hasBaseLevelBeenBoundToFBO() const { return fBaseLevelHasBeenBoundToFBO; }
69 void baseLevelWasBoundToFBO() { fBaseLevelHasBeenBoundToFBO = true; }
70
Greg Daniel177e6952017-10-12 12:27:11 -040071 static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, GrMipMapsStatus,
72 const IDDesc&);
Brian Salomon9bada542017-06-12 12:09:30 -040073
Eric Karlaf770022018-03-19 13:04:03 -070074 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
75
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000076protected:
kkinnunen2e6055b2016-04-22 01:48:29 -070077 // Constructor for subclasses.
Greg Daniel0fc4d2d2017-10-12 11:23:36 -040078 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, GrMipMapsStatus);
kkinnunen2e6055b2016-04-22 01:48:29 -070079
80 enum Wrapped { kWrapped };
81 // Constructor for instances wrapping backend objects.
Greg Daniel177e6952017-10-12 12:27:11 -040082 GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, GrMipMapsStatus, const IDDesc&);
bsalomon37dd3312014-11-03 08:47:23 -080083
84 void init(const GrSurfaceDesc&, const IDDesc&);
85
mtklein36352bf2015-03-25 18:17:31 -070086 void onAbandon() override;
87 void onRelease() override;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000088
Eric Karl914a36b2017-10-12 12:44:50 -070089 bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override;
90
reed@google.comac10a2d2010-12-22 21:39:39 +000091private:
Greg Danielcef213c2017-04-21 11:52:27 -040092 void invokeReleaseProc() {
Greg Daniel6a0176b2018-01-30 09:28:44 -050093 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 Danielcef213c2017-04-21 11:52:27 -040097 }
98 }
99
Brian Salomon327955b2018-10-22 15:39:22 +0000100 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 Danielcef213c2017-04-21 11:52:27 -0400108
bsalomonafbf2d62014-09-30 12:18:44 -0700109 typedef GrTexture INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000110};
111
112#endif