Flutter Engine
The Flutter Engine
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
24 switch (target) {
26 return GrTextureType::k2D;
31 }
32 SK_ABORT("Unexpected texture target");
33}
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
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
107 SkASSERT(0 != desc.fID);
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
136 info.fTarget = target_from_texture_type(this->textureType());
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
148}
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
211 texture_id.appendU32(this->textureID());
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
Definition: GrGLDefines.h:152
#define GR_GL_TEXTURE
Definition: GrGLDefines.h:639
#define GR_GL_TEXTURE_RECTANGLE
Definition: GrGLDefines.h:1056
#define GR_GL_TEXTURE_EXTERNAL
Definition: GrGLDefines.h:1052
static GrGLenum target_from_texture_type(GrTextureType type)
Definition: GrGLTexture.cpp:35
#define GL_CALL(X)
Definition: GrGLTexture.cpp:21
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:85
GrIOType
Definition: GrTypesPriv.h:402
@ kRead_GrIOType
Definition: GrTypesPriv.h:403
GrMipmapStatus
Definition: GrTypesPriv.h:523
GrTextureType
Definition: GrTypesPriv.h:268
#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
Definition: SkTraceEvent.h:30
GLenum type
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)
Definition: GrGLTexture.cpp:23
void onAbandon() override
GrGLTexture(GrGLGpu *, skgpu::Budgeted, const Desc &, GrMipmapStatus, std::string_view label)
Definition: GrGLTexture.cpp:50
static sk_sp< GrGLTexture > MakeWrapped(GrGLGpu *, GrMipmapStatus, const Desc &, sk_sp< GrGLTextureParameters >, GrWrapCacheable, GrIOType, std::string_view label)
bool onStealBackendTexture(GrBackendTexture *, SkImages::BackendTextureReleaseProc *) override
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)
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
void onAbandon() override
Definition: GrSurface.cpp:86
int width() const
Definition: GrSurface.h:32
void onRelease() override
Definition: GrSurface.cpp:81
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
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
Definition: SkImageGanesh.h:43
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Budgeted
Definition: GpuTypes.h:35
Protected
Definition: GpuTypes.h:61
Definition: ref_ptr.h:256
GrGLuint fID
Definition: GrGLTypes.h:182
int64_t texture_id
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131