blob: 40a68eb9e901e292d329745d504d612faf9cc468 [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 {
bsalomon@google.com8fe72472011-03-30 21:26:44 +000019
reed@google.comac10a2d2010-12-22 21:39:39 +000020public:
bsalomon@google.comda96ea02010-12-23 16:53:57 +000021 struct TexParams {
commit-bot@chromium.org149f4f52013-07-26 20:40:06 +000022 GrGLenum fMinFilter;
23 GrGLenum fMagFilter;
twiz@google.com0f31ca72011-03-18 17:38:11 +000024 GrGLenum fWrapS;
25 GrGLenum fWrapT;
bsalomon@google.com0a97be22011-11-08 19:20:57 +000026 GrGLenum fSwizzleRGBA[4];
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000027 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 {
bsalomon10528f12015-10-14 12:54:52 -070031 GrGLenum fTarget;
bsalomon5236cf42015-01-14 10:42:08 -080032 GrGLuint fTextureID;
33 GrGpuResource::LifeCycle fLifeCycle;
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000034 };
35
bsalomon861e1032014-12-16 07:33:49 -080036 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000037
mtklein36352bf2015-03-25 18:17:31 -070038 GrBackendObject getTextureHandle() const override;
junov@chromium.org957ebdd2012-06-12 13:58:36 +000039
mtklein36352bf2015-03-25 18:17:31 -070040 void textureParamsModified() override { fTexParams.invalidate(); }
reed@google.comac10a2d2010-12-22 21:39:39 +000041
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000042 // These functions are used to track the texture parameters associated with the texture.
bsalomon@google.com80d09b92011-11-05 21:21:13 +000043 const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const {
44 *timestamp = fTexParamsTimestamp;
45 return fTexParams;
46 }
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000047
bsalomon@google.com80d09b92011-11-05 21:21:13 +000048 void setCachedTexParams(const TexParams& texParams,
49 GrGpu::ResetTimestamp timestamp) {
50 fTexParams = texParams;
51 fTexParamsTimestamp = timestamp;
52 }
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000053
bsalomonbcaefb02014-11-03 11:07:12 -080054 GrGLuint textureID() const { return fTextureID; }
reed@google.comac10a2d2010-12-22 21:39:39 +000055
bsalomon10528f12015-10-14 12:54:52 -070056 GrGLenum target() const { return fTarget; }
57
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000058protected:
bsalomon37dd3312014-11-03 08:47:23 -080059 // The public constructor registers this object with the cache. However, only the most derived
60 // class should register with the cache. This constructor does not do the registration and
61 // rather moves that burden onto the derived class.
62 enum Derived { kDerived };
bsalomon861e1032014-12-16 07:33:49 -080063 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, Derived);
bsalomon37dd3312014-11-03 08:47:23 -080064
65 void init(const GrSurfaceDesc&, const IDDesc&);
66
mtklein36352bf2015-03-25 18:17:31 -070067 void onAbandon() override;
68 void onRelease() override;
ericrk0a5fa482015-09-15 14:16:10 -070069 void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
70 const SkString& dumpName) const override;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000071
reed@google.comac10a2d2010-12-22 21:39:39 +000072private:
bsalomon@google.com80d09b92011-11-05 21:21:13 +000073 TexParams fTexParams;
74 GrGpu::ResetTimestamp fTexParamsTimestamp;
bsalomon10528f12015-10-14 12:54:52 -070075 GrGLenum fTarget;
bsalomonbcaefb02014-11-03 11:07:12 -080076 GrGLuint fTextureID;
bsalomon@google.comc6cf7232011-02-17 16:43:10 +000077
hendrikw9a0c7ab2014-12-09 14:26:47 -080078 // We track this separately from GrGpuResource because this may be both a texture and a render
79 // target, and the texture may be wrapped while the render target is not.
bsalomon6dc6f5f2015-06-18 09:12:16 -070080 LifeCycle fTextureIDLifecycle;
hendrikw9a0c7ab2014-12-09 14:26:47 -080081
bsalomonafbf2d62014-09-30 12:18:44 -070082 typedef GrTexture INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +000083};
84
85#endif