blob: 11d63531cf48225c06bd52188105cf4adafb7119 [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"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000013#include "GrGLRenderTarget.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000014
bsalomon@google.com1da07462011-03-10 14:51:57 +000015/**
16 * A ref counted tex id that deletes the texture in its destructor.
17 */
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000018class GrGLTexID : public SkRefCnt {
bsalomon@google.com1da07462011-03-10 14:51:57 +000019public:
reed@google.comfa35e3d2012-06-26 20:16:17 +000020 SK_DECLARE_INST_COUNT(GrGLTexID)
21
bsalomon@google.com72830222013-01-23 20:25:22 +000022 GrGLTexID(const GrGLInterface* gl, GrGLuint texID, bool isWrapped)
bsalomon@google.com0b77d682011-08-19 13:28:54 +000023 : fGL(gl)
24 , fTexID(texID)
bsalomon@google.com72830222013-01-23 20:25:22 +000025 , fIsWrapped(isWrapped) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000026 }
bsalomon@google.com1da07462011-03-10 14:51:57 +000027
28 virtual ~GrGLTexID() {
bsalomon@google.com72830222013-01-23 20:25:22 +000029 if (0 != fTexID && !fIsWrapped) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000030 GR_GL_CALL(fGL, DeleteTextures(1, &fTexID));
bsalomon@google.com1da07462011-03-10 14:51:57 +000031 }
32 }
33
34 void abandon() { fTexID = 0; }
twiz@google.com0f31ca72011-03-18 17:38:11 +000035 GrGLuint id() const { return fTexID; }
bsalomon@google.com1da07462011-03-10 14:51:57 +000036
37private:
bsalomon@google.com0b77d682011-08-19 13:28:54 +000038 const GrGLInterface* fGL;
39 GrGLuint fTexID;
bsalomon@google.com72830222013-01-23 20:25:22 +000040 bool fIsWrapped;
reed@google.comfa35e3d2012-06-26 20:16:17 +000041
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000042 typedef SkRefCnt INHERITED;
bsalomon@google.com1da07462011-03-10 14:51:57 +000043};
44
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000045////////////////////////////////////////////////////////////////////////////////
46
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000047
bsalomonafbf2d62014-09-30 12:18:44 -070048class GrGLTexture : public GrTexture {
bsalomon@google.com8fe72472011-03-30 21:26:44 +000049
reed@google.comac10a2d2010-12-22 21:39:39 +000050public:
bsalomon@google.comda96ea02010-12-23 16:53:57 +000051 struct TexParams {
commit-bot@chromium.org149f4f52013-07-26 20:40:06 +000052 GrGLenum fMinFilter;
53 GrGLenum fMagFilter;
twiz@google.com0f31ca72011-03-18 17:38:11 +000054 GrGLenum fWrapS;
55 GrGLenum fWrapT;
bsalomon@google.com0a97be22011-11-08 19:20:57 +000056 GrGLenum fSwizzleRGBA[4];
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000057 void invalidate() { memset(this, 0xff, sizeof(TexParams)); }
bsalomon@google.comda96ea02010-12-23 16:53:57 +000058 };
reed@google.comac10a2d2010-12-22 21:39:39 +000059
bsalomonb15b4c12014-10-29 12:41:57 -070060 struct IDDesc {
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000061 GrGLuint fTextureID;
bsalomon@google.com72830222013-01-23 20:25:22 +000062 bool fIsWrapped;
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000063 };
64
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000065 // creates a texture that is also an RT
bsalomonb15b4c12014-10-29 12:41:57 -070066 GrGLTexture(GrGpuGL* gpu, const GrSurfaceDesc&, const IDDesc&, const GrGLRenderTarget::IDDesc&);
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000067
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000068 // creates a non-RT texture
bsalomonb15b4c12014-10-29 12:41:57 -070069 GrGLTexture(GrGpuGL* gpu, const GrSurfaceDesc&, const IDDesc&);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000070
bsalomon@google.com8fe72472011-03-30 21:26:44 +000071 virtual ~GrGLTexture() { this->release(); }
reed@google.comac10a2d2010-12-22 21:39:39 +000072
bsalomon@google.com08afc842012-10-25 18:56:10 +000073 virtual GrBackendObject getTextureHandle() const SK_OVERRIDE;
junov@chromium.org957ebdd2012-06-12 13:58:36 +000074
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000075 virtual void textureParamsModified() SK_OVERRIDE { fTexParams.invalidate(); }
reed@google.comac10a2d2010-12-22 21:39:39 +000076
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000077 // These functions are used to track the texture parameters associated with the texture.
bsalomon@google.com80d09b92011-11-05 21:21:13 +000078 const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const {
79 *timestamp = fTexParamsTimestamp;
80 return fTexParams;
81 }
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000082
bsalomon@google.com80d09b92011-11-05 21:21:13 +000083 void setCachedTexParams(const TexParams& texParams,
84 GrGpu::ResetTimestamp timestamp) {
85 fTexParams = texParams;
86 fTexParamsTimestamp = timestamp;
87 }
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000088
bsalomon49f085d2014-09-05 13:34:00 -070089 GrGLuint textureID() const { return (fTexIDObj.get()) ? fTexIDObj->id() : 0; }
reed@google.comac10a2d2010-12-22 21:39:39 +000090
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000091protected:
bsalomon@google.com6dcf4992011-04-05 21:16:14 +000092 // overrides of GrTexture
junov@chromium.org957ebdd2012-06-12 13:58:36 +000093 virtual void onAbandon() SK_OVERRIDE;
94 virtual void onRelease() SK_OVERRIDE;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000095
reed@google.comac10a2d2010-12-22 21:39:39 +000096private:
bsalomon@google.com80d09b92011-11-05 21:21:13 +000097 TexParams fTexParams;
98 GrGpu::ResetTimestamp fTexParamsTimestamp;
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000099 SkAutoTUnref<GrGLTexID> fTexIDObj;
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000100
bsalomonb15b4c12014-10-29 12:41:57 -0700101 void init(GrGpuGL* gpu, const GrSurfaceDesc&, const IDDesc&, const GrGLRenderTarget::IDDesc*);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +0000102
bsalomonafbf2d62014-09-30 12:18:44 -0700103 typedef GrTexture INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000104};
105
106#endif