blob: 0edcbd0e13fd15958ad91e04a4dfc0d35cf52eb0 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
reed@google.comac10a2d2010-12-22 21:39:39 +00009#ifndef GrTexture_DEFINED
10#define GrTexture_DEFINED
11
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000012#include "GrSurface.h"
Brian Salomon514baff2016-11-17 15:17:07 -050013#include "GrSamplerParams.h"
bsalomonc44be0e2014-07-25 07:32:33 -070014#include "SkPoint.h"
15#include "SkRefCnt.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000016
bsalomonafbf2d62014-09-30 12:18:44 -070017class GrTexturePriv;
reed@google.comac10a2d2010-12-22 21:39:39 +000018
bsalomon37dd3312014-11-03 08:47:23 -080019class GrTexture : virtual public GrSurface {
reed@google.comac10a2d2010-12-22 21:39:39 +000020public:
mtklein36352bf2015-03-25 18:17:31 -070021 GrTexture* asTexture() override { return this; }
22 const GrTexture* asTexture() const override { return this; }
commit-bot@chromium.org59e7d232014-05-09 18:02:51 +000023
24 /**
commit-bot@chromium.org59e7d232014-05-09 18:02:51 +000025 * Return the native ID or handle to the texture, depending on the
26 * platform. e.g. on OpenGL, return the texture ID.
27 */
28 virtual GrBackendObject getTextureHandle() const = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +000029
junov@chromium.org957ebdd2012-06-12 13:58:36 +000030 /**
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000031 * This function indicates that the texture parameters (wrap mode, filtering, ...) have been
32 * changed externally to Skia.
junov@chromium.org957ebdd2012-06-12 13:58:36 +000033 */
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000034 virtual void textureParamsModified() = 0;
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000035
commit-bot@chromium.org59e7d232014-05-09 18:02:51 +000036#ifdef SK_DEBUG
37 void validate() const {
38 this->INHERITED::validate();
Greg Daniel4b30a962017-05-18 18:13:40 +000039 this->validateDesc();
commit-bot@chromium.org59e7d232014-05-09 18:02:51 +000040 }
41#endif
42
Greg Danielcef213c2017-04-21 11:52:27 -040043 // These match the definitions in SkImage, for whence they came
44 typedef void* ReleaseCtx;
45 typedef void (*ReleaseProc)(ReleaseCtx);
46
47 virtual void setRelease(ReleaseProc proc, ReleaseCtx ctx) = 0;
48
bsalomonafbf2d62014-09-30 12:18:44 -070049 /** Access methods that are only to be used within Skia code. */
50 inline GrTexturePriv texturePriv();
51 inline const GrTexturePriv texturePriv() const;
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000052
53protected:
Brian Salomon739c5bf2016-11-07 09:53:44 -050054 GrTexture(GrGpu*, const GrSurfaceDesc&, GrSLType samplerType,
Brian Salomon514baff2016-11-17 15:17:07 -050055 GrSamplerParams::FilterMode highestFilterMode, bool wasMipMapDataProvided);
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000056
Greg Daniel4b30a962017-05-18 18:13:40 +000057 void validateDesc() const;
58
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000059private:
kkinnunen2e6055b2016-04-22 01:48:29 -070060 void computeScratchKey(GrScratchKey*) const override;
mtklein36352bf2015-03-25 18:17:31 -070061 size_t onGpuMemorySize() const override;
brianosmanfe199872016-06-13 07:59:48 -070062 void dirtyMipMaps(bool mipMapsDirty);
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000063
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +000064 enum MipMapsStatus {
65 kNotAllocated_MipMapsStatus,
66 kAllocated_MipMapsStatus,
67 kValid_MipMapsStatus
68 };
69
Brian Osman7b8400d2016-11-08 17:08:54 -050070 GrSLType fSamplerType;
Brian Salomon514baff2016-11-17 15:17:07 -050071 GrSamplerParams::FilterMode fHighestFilterMode;
Brian Osman7b8400d2016-11-08 17:08:54 -050072 MipMapsStatus fMipMapsStatus;
73 int fMaxMipMapLevel;
74 SkDestinationSurfaceColorMode fMipColorMode;
bsalomonafbf2d62014-09-30 12:18:44 -070075 friend class GrTexturePriv;
76
77 typedef GrSurface INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +000078};
79
80#endif