blob: ecd5e1dba9e572e9908e891a63c0efc9bf7d0243 [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
Brian Salomon2bbdcc42017-09-07 12:36:34 -040012#include "GrSamplerState.h"
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000013#include "GrSurface.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();
commit-bot@chromium.org59e7d232014-05-09 18:02:51 +000039 }
40#endif
41
Greg Danielcef213c2017-04-21 11:52:27 -040042 // These match the definitions in SkImage, for whence they came
43 typedef void* ReleaseCtx;
44 typedef void (*ReleaseProc)(ReleaseCtx);
45
46 virtual void setRelease(ReleaseProc proc, ReleaseCtx ctx) = 0;
47
bsalomonafbf2d62014-09-30 12:18:44 -070048 /** Access methods that are only to be used within Skia code. */
49 inline GrTexturePriv texturePriv();
50 inline const GrTexturePriv texturePriv() const;
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000051
52protected:
Greg Daniel834f1202017-10-09 15:06:20 -040053 // TODO: Once we disable support for mip maps on textures which were not allocated with them at
54 // creation, we can check the highestFilterMode for mip map to see if mip maps were allocated.
55 // Until then we need to explicitly pass in the mipsAllocated bool.
Brian Salomon739c5bf2016-11-07 09:53:44 -050056 GrTexture(GrGpu*, const GrSurfaceDesc&, GrSLType samplerType,
Greg Daniel834f1202017-10-09 15:06:20 -040057 GrSamplerState::Filter highestFilterMode, bool mipsAllocated,
58 bool wasFullMipMapDataProvided);
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000059
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000060private:
kkinnunen2e6055b2016-04-22 01:48:29 -070061 void computeScratchKey(GrScratchKey*) const override;
mtklein36352bf2015-03-25 18:17:31 -070062 size_t onGpuMemorySize() const override;
brianosmanfe199872016-06-13 07:59:48 -070063 void dirtyMipMaps(bool mipMapsDirty);
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000064
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +000065 enum MipMapsStatus {
Greg Daniel834f1202017-10-09 15:06:20 -040066 kNotAllocated_MipMapsStatus, // Mips have not been allocated
67 kInvalid_MipMapsStatus, // Mips have been allocated but nothing written to base level
68 kDirty_MipMapsStatus, // Base level has data but the rest of the levels are dirty
69 kClean_MipMapsStatus // All levels fully allocated and have valid data in them
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +000070 };
71
Brian Osman7b8400d2016-11-08 17:08:54 -050072 GrSLType fSamplerType;
Brian Salomon2bbdcc42017-09-07 12:36:34 -040073 GrSamplerState::Filter fHighestFilterMode;
Brian Osman7b8400d2016-11-08 17:08:54 -050074 MipMapsStatus fMipMapsStatus;
75 int fMaxMipMapLevel;
76 SkDestinationSurfaceColorMode fMipColorMode;
bsalomonafbf2d62014-09-30 12:18:44 -070077 friend class GrTexturePriv;
78
79 typedef GrSurface INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +000080};
81
82#endif