Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrGLTexture.cpp
Go to the documentation of this file.
1/*
2 * 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.
6 */
7
9
19
20#define GPUGL static_cast<GrGLGpu*>(this->getGpu())
21#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
22
34
36 switch (type) {
38 return GR_GL_TEXTURE_2D;
43 default:
44 SK_ABORT("Unexpected texture target");
45 }
46 SK_ABORT("Unexpected texture type");
47}
48
49// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
51 skgpu::Budgeted budgeted,
52 const Desc& desc,
53 GrMipmapStatus mipmapStatus,
54 std::string_view label)
55 : GrSurface(gpu, desc.fSize, desc.fIsProtected, label)
56 , GrTexture(gpu,
57 desc.fSize,
58 desc.fIsProtected,
59 TextureTypeFromTarget(desc.fTarget),
60 mipmapStatus,
61 label)
62 , fParameters(sk_make_sp<GrGLTextureParameters>()) {
63 this->init(desc);
64 this->registerWithCache(budgeted);
65 if (GrGLFormatIsCompressed(desc.fFormat)) {
66 this->setReadOnly();
67 }
68}
69
70GrGLTexture::GrGLTexture(GrGLGpu* gpu, const Desc& desc, GrMipmapStatus mipmapStatus,
72 GrIOType ioType, std::string_view label)
73 : GrSurface(gpu, desc.fSize, desc.fIsProtected, label)
74 , GrTexture(gpu,
75 desc.fSize,
76 desc.fIsProtected,
77 TextureTypeFromTarget(desc.fTarget),
78 mipmapStatus,
79 label)
80 , fParameters(std::move(parameters)) {
81 SkASSERT(fParameters);
82 this->init(desc);
83 this->registerWithCacheWrapped(cacheable);
84 if (ioType == kRead_GrIOType) {
85 this->setReadOnly();
86 }
87}
88
90 const Desc& desc,
92 GrMipmapStatus mipmapStatus,
93 std::string_view label)
94 : GrSurface(gpu, desc.fSize, desc.fIsProtected, label)
95 , GrTexture(gpu,
96 desc.fSize,
97 desc.fIsProtected,
98 TextureTypeFromTarget(desc.fTarget),
99 mipmapStatus,
100 label) {
102 fParameters = parameters ? std::move(parameters) : sk_make_sp<GrGLTextureParameters>();
103 this->init(desc);
104}
105
106void GrGLTexture::init(const Desc& desc) {
107 SkASSERT(0 != desc.fID);
108 SkASSERT(GrGLFormat::kUnknown != desc.fFormat);
109 fID = desc.fID;
110 fFormat = desc.fFormat;
111 fTextureIDOwnership = desc.fOwnership;
112}
113
115
117 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
118 ATRACE_ANDROID_FRAMEWORK_ALWAYS("Texture release(%u)", this->uniqueID().asUInt());
119
120 if (fID) {
121 if (GrBackendObjectOwnership::kBorrowed != fTextureIDOwnership) {
122 GL_CALL(DeleteTextures(1, &fID));
123 }
124 fID = 0;
125 }
127}
128
130 fID = 0;
132}
133
137 info.fID = fID;
138 info.fFormat = GrGLFormatToEnum(fFormat);
139 info.fProtected = skgpu::Protected(this->isProtected());
140
142 this->width(), this->height(), this->mipmapped(), info, fParameters);
143}
144
149
151 GrMipmapStatus mipmapStatus,
152 const Desc& desc,
154 GrWrapCacheable cacheable,
155 GrIOType ioType,
156 std::string_view label) {
158 gpu, desc, mipmapStatus, std::move(parameters), cacheable, ioType, label));
159}
160
163 *backendTexture = this->getBackendTexture();
164 // Set the release proc to a no-op function. GL doesn't require any special cleanup.
165 *releaseProc = [](GrBackendTexture){};
166
167 // It's important that we only abandon this texture's objects, not subclass objects such as
168 // those held by GrGLTextureRenderTarget. Those objects are not being stolen and need to be
169 // cleaned up by us.
171 return true;
172}
173
175 SkASSERT(fID);
176 SkASSERT(fTextureIDOwnership == GrBackendObjectOwnership::kOwned);
177 if (!this->getLabel().empty()) {
178 const std::string label = "_Skia_" + this->getLabel();
179 GrGLGpu* glGpu = static_cast<GrGLGpu*>(this->getGpu());
180 if (glGpu->glCaps().debugSupport()) {
181 GR_GL_CALL(glGpu->glInterface(), ObjectLabel(GR_GL_TEXTURE, fID, -1, label.c_str()));
182 }
183 }
184}
185
187 // Don't check this->fRefsWrappedObjects, as we might be the base of a GrGLTextureRenderTarget
188 // which is multiply inherited from both ourselves and a texture. In these cases, one part
189 // (texture, rt) may be wrapped, while the other is owned by Skia.
190 bool refsWrappedTextureObjects =
191 this->fTextureIDOwnership == GrBackendObjectOwnership::kBorrowed;
192 if (refsWrappedTextureObjects && !traceMemoryDump->shouldDumpWrappedObjects()) {
193 return;
194 }
195
196 size_t size = GrSurface::ComputeSize(this->backendFormat(), this->dimensions(), 1,
197 this->mipmapped());
198
199 // Dump as skia/gpu_resources/resource_#/texture, to avoid conflicts in the
200 // GrGLTextureRenderTarget case, where multiple things may dump to the same resource. This
201 // has no downside in the normal case.
202 SkString resourceName = this->getResourceName();
203 resourceName.append("/texture");
204
205 // As we are only dumping our texture memory (not any additional memory tracked by classes
206 // which may inherit from us), specifically call GrGLTexture::gpuMemorySize to avoid
207 // hitting an override.
208 this->dumpMemoryStatisticsPriv(traceMemoryDump, resourceName, "Texture", size);
209
212 traceMemoryDump->setMemoryBacking(resourceName.c_str(), "gl_texture", texture_id.c_str());
213}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
#define GR_GL_TEXTURE_2D
#define GR_GL_TEXTURE
#define GR_GL_TEXTURE_RECTANGLE
#define GR_GL_TEXTURE_EXTERNAL
#define GL_CALL(X)
static GrGLenum target_from_texture_type(GrTextureType type)
unsigned int GrGLenum
Definition GrGLTypes.h:102
bool GrGLFormatIsCompressed(GrGLFormat format)
Definition GrGLUtil.cpp:812
#define GR_GL_CALL(IFACE, X)
Definition GrGLUtil.h:381
static constexpr GrGLenum GrGLFormatToEnum(GrGLFormat format)
Definition GrGLUtil.h:445
GrWrapCacheable
Definition GrTypesPriv.h:84
GrIOType
@ kRead_GrIOType
GrMipmapStatus
GrTextureType
#define SK_ABORT(message,...)
Definition SkAssert.h:70
#define SkASSERT(cond)
Definition SkAssert.h:116
static void releaseProc(const void *ptr, void *context)
sk_sp< T > sk_make_sp(Args &&... args)
Definition SkRefCnt.h:371
#define ATRACE_ANDROID_FRAMEWORK_ALWAYS(fmt,...)
#define TRACE_FUNC
bool debugSupport() const
Is there support for GL_KHR_debug?
Definition GrGLCaps.h:359
const GrGLCaps & glCaps() const
Definition GrGLGpu.h:108
const GrGLInterface * glInterface() const
Definition GrGLGpu.h:103
GrBackendFormat backendFormat() const override
void init(const Desc &)
GrGLenum target() const
GrGLuint textureID() const
Definition GrGLTexture.h:46
GrGLTextureParameters * parameters()
Definition GrGLTexture.h:44
void onRelease() override
void onSetLabel() override
void dumpMemoryStatistics(SkTraceMemoryDump *traceMemoryDump) const override
GrBackendTexture getBackendTexture() const override
static GrTextureType TextureTypeFromTarget(GrGLenum textureTarget)
void onAbandon() override
GrGLTexture(GrGLGpu *, skgpu::Budgeted, const Desc &, GrMipmapStatus, std::string_view label)
static sk_sp< GrGLTexture > MakeWrapped(GrGLGpu *, GrMipmapStatus, const Desc &, sk_sp< GrGLTextureParameters >, GrWrapCacheable, GrIOType, std::string_view label)
bool onStealBackendTexture(GrBackendTexture *, SkImages::BackendTextureReleaseProc *) override
virtual void onAbandon()
std::string getLabel() const
GrGpu * getGpu() const
void dumpMemoryStatisticsPriv(SkTraceMemoryDump *traceMemoryDump, const SkString &resourceName, const char *type, size_t size) const
UniqueID uniqueID() const
SkString getResourceName() const
void registerWithCacheWrapped(GrWrapCacheable)
void registerWithCache(skgpu::Budgeted)
virtual void onRelease()
SkISize dimensions() const
Definition GrSurface.h:27
bool isProtected() const
Definition GrSurface.h:87
int height() const
Definition GrSurface.h:37
static size_t ComputeSize(const GrBackendFormat &, SkISize dimensions, int colorSamplesPerPixel, skgpu::Mipmapped, bool binSize=false)
Definition GrSurface.cpp:21
void setReadOnly()
Definition GrSurface.h:130
int width() const
Definition GrSurface.h:32
skgpu::Mipmapped mipmapped() const
Definition GrTexture.h:62
GrMipmapStatus mipmapStatus() const
Definition GrTexture.h:66
GrTextureType textureType() const
Definition GrTexture.h:55
void append(const char text[])
Definition SkString.h:203
void appendU32(uint32_t value)
Definition SkString.h:210
const char * c_str() const
Definition SkString.h:133
virtual void setMemoryBacking(const char *dumpName, const char *backingType, const char *backingObjectId)=0
virtual bool shouldDumpWrappedObjects() const
EMSCRIPTEN_KEEPALIVE void empty()
uint32_t * target
SK_API GrBackendFormat MakeGL(GrGLenum format, GrGLenum target)
SK_API GrBackendTexture MakeGL(int width, int height, skgpu::Mipmapped, const GrGLTextureInfo &glInfo, std::string_view label={})
std::function< void(GrBackendTexture)> BackendTextureReleaseProc
Budgeted
Definition GpuTypes.h:35
Protected
Definition GpuTypes.h:61
Definition ref_ptr.h:256
GrGLenum fTarget
Definition GrGLTypes.h:181
int64_t texture_id
#define TRACE_EVENT0(category_group, name)