blob: 899b3ed58ca7f7d8af67642cc335a70e2b10b8a8 [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
Eric Karl914a36b2017-10-12 12:44:50 -070012#include "GrBackendSurface.h"
Brian Salomon2bbdcc42017-09-07 12:36:34 -040013#include "GrSamplerState.h"
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000014#include "GrSurface.h"
Eric Karl914a36b2017-10-12 12:44:50 -070015#include "SkImage.h"
bsalomonc44be0e2014-07-25 07:32:33 -070016#include "SkPoint.h"
17#include "SkRefCnt.h"
Greg Daniel0fc4d2d2017-10-12 11:23:36 -040018#include "../private/GrTypesPriv.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000019
bsalomonafbf2d62014-09-30 12:18:44 -070020class GrTexturePriv;
reed@google.comac10a2d2010-12-22 21:39:39 +000021
bsalomon37dd3312014-11-03 08:47:23 -080022class GrTexture : virtual public GrSurface {
reed@google.comac10a2d2010-12-22 21:39:39 +000023public:
mtklein36352bf2015-03-25 18:17:31 -070024 GrTexture* asTexture() override { return this; }
25 const GrTexture* asTexture() const override { return this; }
commit-bot@chromium.org59e7d232014-05-09 18:02:51 +000026
27 /**
commit-bot@chromium.org59e7d232014-05-09 18:02:51 +000028 * Return the native ID or handle to the texture, depending on the
29 * platform. e.g. on OpenGL, return the texture ID.
30 */
31 virtual GrBackendObject getTextureHandle() const = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +000032
Robert Phillipsb67821d2017-12-13 15:00:45 -050033 virtual GrBackendTexture getBackendTexture() const = 0;
34
junov@chromium.org957ebdd2012-06-12 13:58:36 +000035 /**
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000036 * This function indicates that the texture parameters (wrap mode, filtering, ...) have been
37 * changed externally to Skia.
junov@chromium.org957ebdd2012-06-12 13:58:36 +000038 */
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000039 virtual void textureParamsModified() = 0;
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000040
Eric Karl914a36b2017-10-12 12:44:50 -070041 /**
42 * This function steals the backend texture from a uniquely owned GrTexture with no pending
43 * IO, passing it out to the caller. The GrTexture is deleted in the process.
Greg Daniel6a0176b2018-01-30 09:28:44 -050044 *
Eric Karl914a36b2017-10-12 12:44:50 -070045 * Note that if the GrTexture is not uniquely owned (no other refs), or has pending IO, this
46 * function will fail.
47 */
48 static bool StealBackendTexture(sk_sp<GrTexture>&&,
49 GrBackendTexture*,
50 SkImage::BackendTextureReleaseProc*);
51
commit-bot@chromium.org59e7d232014-05-09 18:02:51 +000052#ifdef SK_DEBUG
53 void validate() const {
54 this->INHERITED::validate();
commit-bot@chromium.org59e7d232014-05-09 18:02:51 +000055 }
56#endif
57
Greg Daniel6a0176b2018-01-30 09:28:44 -050058 virtual void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) = 0;
59
60 // These match the definitions in SkImage, from whence they came.
61 // TODO: Either move Chrome over to new api or remove their need to call this on GrTexture
Greg Danielcef213c2017-04-21 11:52:27 -040062 typedef void* ReleaseCtx;
63 typedef void (*ReleaseProc)(ReleaseCtx);
Greg Daniel6a0176b2018-01-30 09:28:44 -050064 void setRelease(ReleaseProc proc, ReleaseCtx ctx) {
65 sk_sp<GrReleaseProcHelper> helper(new GrReleaseProcHelper(proc, ctx));
66 this->setRelease(std::move(helper));
67 }
Greg Danielcef213c2017-04-21 11:52:27 -040068
bsalomonafbf2d62014-09-30 12:18:44 -070069 /** Access methods that are only to be used within Skia code. */
70 inline GrTexturePriv texturePriv();
71 inline const GrTexturePriv texturePriv() const;
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000072
73protected:
Brian Salomon739c5bf2016-11-07 09:53:44 -050074 GrTexture(GrGpu*, const GrSurfaceDesc&, GrSLType samplerType,
Greg Daniel0fc4d2d2017-10-12 11:23:36 -040075 GrSamplerState::Filter highestFilterMode, GrMipMapsStatus);
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000076
Eric Karl914a36b2017-10-12 12:44:50 -070077 virtual bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) = 0;
78
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000079private:
kkinnunen2e6055b2016-04-22 01:48:29 -070080 void computeScratchKey(GrScratchKey*) const override;
mtklein36352bf2015-03-25 18:17:31 -070081 size_t onGpuMemorySize() const override;
Greg Daniel0fc4d2d2017-10-12 11:23:36 -040082 void markMipMapsDirty();
83 void markMipMapsClean();
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +000084
Brian Osman7b8400d2016-11-08 17:08:54 -050085 GrSLType fSamplerType;
Brian Salomon2bbdcc42017-09-07 12:36:34 -040086 GrSamplerState::Filter fHighestFilterMode;
Greg Daniel0fc4d2d2017-10-12 11:23:36 -040087 GrMipMapsStatus fMipMapsStatus;
Brian Osman7b8400d2016-11-08 17:08:54 -050088 int fMaxMipMapLevel;
89 SkDestinationSurfaceColorMode fMipColorMode;
bsalomonafbf2d62014-09-30 12:18:44 -070090 friend class GrTexturePriv;
91
92 typedef GrSurface INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +000093};
94
95#endif