blob: cb3f1581ce29f9e062ea687b7bb9d94c7753cc26 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/gpu/GrTexture.h"
Brian Salomone2826ab2019-06-04 15:58:31 -040013#include "include/private/GrGLTypesPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrGpu.h"
15#include "src/gpu/gl/GrGLUtil.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000016
jvanverthd1e72872015-04-20 12:29:37 -070017class GrGLGpu;
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000018
bsalomonafbf2d62014-09-30 12:18:44 -070019class GrGLTexture : public GrTexture {
reed@google.comac10a2d2010-12-22 21:39:39 +000020public:
bsalomonb15b4c12014-10-29 12:41:57 -070021 struct IDDesc {
bsalomon091f60c2015-11-10 11:54:56 -080022 GrGLTextureInfo fInfo;
kkinnunen2e6055b2016-04-22 01:48:29 -070023 GrBackendObjectOwnership fOwnership;
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000024 };
Brian Salomon7226c232018-07-30 13:13:17 -040025
26 static GrTextureType TextureTypeFromTarget(GrGLenum textureTarget);
27
Greg Daniel0fc4d2d2017-10-12 11:23:36 -040028 GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&, GrMipMapsStatus);
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000029
Greg Daniel2d35a1c2019-02-01 14:48:10 -050030 ~GrGLTexture() override {}
Greg Danielcef213c2017-04-21 11:52:27 -040031
Robert Phillipsb67821d2017-12-13 15:00:45 -050032 GrBackendTexture getBackendTexture() const override;
junov@chromium.org957ebdd2012-06-12 13:58:36 +000033
Greg Daniel4065d452018-11-16 15:43:41 -050034 GrBackendFormat backendFormat() const override;
35
Brian Salomone2826ab2019-06-04 15:58:31 -040036 // TODO: Remove once clients are no longer calling this.
37 void textureParamsModified() override { fParameters->invalidate(); }
reed@google.comac10a2d2010-12-22 21:39:39 +000038
Brian Salomone2826ab2019-06-04 15:58:31 -040039 GrGLTextureParameters* parameters() { return fParameters.get(); }
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000040
Brian Salomon60dd8c72018-07-30 10:24:13 -040041 GrGLuint textureID() const { return fID; }
reed@google.comac10a2d2010-12-22 21:39:39 +000042
Brian Salomon60dd8c72018-07-30 10:24:13 -040043 GrGLenum target() const;
bsalomon10528f12015-10-14 12:54:52 -070044
Brian Salomon9bada542017-06-12 12:09:30 -040045 bool hasBaseLevelBeenBoundToFBO() const { return fBaseLevelHasBeenBoundToFBO; }
46 void baseLevelWasBoundToFBO() { fBaseLevelHasBeenBoundToFBO = true; }
47
Greg Daniel177e6952017-10-12 12:27:11 -040048 static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, GrMipMapsStatus,
Brian Salomone2826ab2019-06-04 15:58:31 -040049 const IDDesc&, sk_sp<GrGLTextureParameters>,
50 GrWrapCacheable, GrIOType);
Brian Salomon9bada542017-06-12 12:09:30 -040051
Eric Karlaf770022018-03-19 13:04:03 -070052 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
53
bsalomon@google.com5877ffd2011-04-11 17:58:48 +000054protected:
kkinnunen2e6055b2016-04-22 01:48:29 -070055 // Constructor for subclasses.
Brian Salomone2826ab2019-06-04 15:58:31 -040056 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, sk_sp<GrGLTextureParameters>,
57 GrMipMapsStatus);
kkinnunen2e6055b2016-04-22 01:48:29 -070058
kkinnunen2e6055b2016-04-22 01:48:29 -070059 // Constructor for instances wrapping backend objects.
Brian Salomone2826ab2019-06-04 15:58:31 -040060 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, GrMipMapsStatus, const IDDesc&,
61 sk_sp<GrGLTextureParameters>, GrWrapCacheable, GrIOType);
bsalomon37dd3312014-11-03 08:47:23 -080062
63 void init(const GrSurfaceDesc&, const IDDesc&);
64
mtklein36352bf2015-03-25 18:17:31 -070065 void onAbandon() override;
66 void onRelease() override;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000067
Eric Karl914a36b2017-10-12 12:44:50 -070068 bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override;
69
reed@google.comac10a2d2010-12-22 21:39:39 +000070private:
Brian Salomone2826ab2019-06-04 15:58:31 -040071 sk_sp<GrGLTextureParameters> fParameters;
Brian Salomondc829942018-10-23 16:07:24 -040072 GrGLuint fID;
73 GrGLenum fFormat;
74 GrBackendObjectOwnership fTextureIDOwnership;
75 bool fBaseLevelHasBeenBoundToFBO = false;
Greg Danielcef213c2017-04-21 11:52:27 -040076
bsalomonafbf2d62014-09-30 12:18:44 -070077 typedef GrTexture INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +000078};
79
80#endif