10#include "flutter/fml/logging.h"
11#include "flutter/fml/mapping.h"
12#include "flutter/fml/trace_event.h"
81 return std::shared_ptr<TextureGLES>(
82 new TextureGLES(std::move(reactor), desc,
true, fbo));
88 std::optional<GLuint> fbo)
90 reactor_(
std::move(reactor)),
93 is_wrapped_(is_wrapped),
102 const auto max_size =
103 reactor_->GetProcTable().GetCapabilities()->max_texture_size;
104 if (tex_size.Max(max_size) != max_size) {
106 <<
" would exceed max supported size of " << max_size <<
".";
115 reactor_->CollectHandle(handle_);
125 reactor_->SetDebugLabel(handle_, std::string{label.data(), label.size()});
132 std::shared_ptr<const fml::Mapping>
data;
135 switch (pixel_format) {
139 type = GL_UNSIGNED_BYTE;
144 type = GL_UNSIGNED_BYTE;
152 type = GL_UNSIGNED_BYTE;
162 type = GL_HALF_FLOAT;
173 type = GL_UNSIGNED_INT_24_8;
187 std::shared_ptr<const fml::Mapping> mapping)
189 data = std::move(mapping);
195 bool is_valid_ =
false;
212 if (mapping->GetSize() == 0u) {
216 if (mapping->GetMapping() ==
nullptr) {
221 VALIDATION_LOG <<
"Incorrect texture usage flags for setting contents on "
222 "this texture object.";
227 VALIDATION_LOG <<
"Cannot set the contents of a wrapped texture.";
233 if (tex_descriptor.size.IsEmpty()) {
237 if (!tex_descriptor.IsValid()) {
241 if (mapping->GetSize() < tex_descriptor.GetByteSizeOfBaseMipLevel()) {
246 GLenum texture_target;
247 switch (tex_descriptor.type) {
249 texture_type = GL_TEXTURE_2D;
250 texture_target = GL_TEXTURE_2D;
253 VALIDATION_LOG <<
"Multisample texture uploading is not supported for "
254 "the OpenGLES backend.";
257 texture_type = GL_TEXTURE_CUBE_MAP;
258 texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
261 texture_type = GL_TEXTURE_EXTERNAL_OES;
262 texture_target = GL_TEXTURE_EXTERNAL_OES;
266 auto data = std::make_shared<TexImage2DData>(tex_descriptor.format,
268 if (!data || !data->IsValid()) {
275 size = tex_descriptor.size,
278 ](
const auto& reactor) {
279 auto gl_handle = reactor.GetGLHandle(handle);
280 if (!gl_handle.has_value()) {
282 <<
"Texture was collected before it could be uploaded to the GPU.";
285 const auto& gl = reactor.GetProcTable();
286 gl.BindTexture(texture_type, gl_handle.value());
287 const GLvoid* tex_data =
nullptr;
289 tex_data = data->data->GetMapping();
294 std::to_string(data->data->GetSize()).c_str());
295 gl.TexImage2D(texture_target,
297 data->internal_format,
301 data->external_format,
308 contents_initialized_ = reactor_->AddOperation(texture_upload);
309 return contents_initialized_;
327 return GL_STENCIL_INDEX8;
329 return GL_DEPTH24_STENCIL8;
331 return GL_DEPTH32F_STENCIL8;
346void TextureGLES::InitializeContentsIfNecessary()
const {
350 if (contents_initialized_) {
353 contents_initialized_ =
true;
361 if (
size.IsEmpty()) {
365 const auto&
gl = reactor_->GetProcTable();
366 auto handle = reactor_->GetGLHandle(handle_);
367 if (!handle.has_value()) {
368 VALIDATION_LOG <<
"Could not initialize the contents of texture.";
376 if (!tex_data.IsValid()) {
380 gl.BindTexture(GL_TEXTURE_2D, handle.value());
383 gl.TexImage2D(GL_TEXTURE_2D,
385 tex_data.internal_format,
389 tex_data.external_format,
397 auto render_buffer_format =
399 if (!render_buffer_format.has_value()) {
403 gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
405 TRACE_EVENT0(
"impeller",
"RenderBufferStorageInitialization");
407 gl.RenderbufferStorageMultisampleEXT(
410 render_buffer_format.value(),
415 gl.RenderbufferStorage(
417 render_buffer_format.value(),
431 return reactor_->GetGLHandle(handle_);
436 if (!handle.has_value()) {
439 const auto& gl = reactor_->GetProcTable();
444 if (!
target.has_value()) {
448 gl.BindTexture(
target.value(), handle.value());
452 gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
455 InitializeContentsIfNecessary();
469 VALIDATION_LOG <<
"Generating mipmaps for multisample textures is not "
470 "supported in the GLES backend.";
483 if (!handle.has_value()) {
487 const auto& gl = reactor_->GetProcTable();
500 return GL_COLOR_ATTACHMENT0;
502 return GL_DEPTH_ATTACHMENT;
504 return GL_STENCIL_ATTACHMENT;
514 InitializeContentsIfNecessary();
516 if (!handle.has_value()) {
519 const auto& gl = reactor_->GetProcTable();
523 gl.FramebufferTexture2D(
target,
531 gl.FramebufferTexture2DMultisampleEXT(
542 gl.FramebufferRenderbuffer(
static sk_sp< GrTextureProxy > wrapped(skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
std::function< void(const ReactorGLES &reactor)> Operation
std::shared_ptr< ReactorGLES > Ref
TextureGLES(ReactorGLES::Ref reactor, TextureDescriptor desc)
@ kRenderBufferMultisampled
bool IsValid() const override
void SetLabel(std::string_view label) override
bool SetAsFramebufferAttachment(GLenum target, AttachmentType attachment_type) const
static std::shared_ptr< TextureGLES > WrapFBO(ReactorGLES::Ref reactor, TextureDescriptor desc, GLuint fbo)
std::optional< GLuint > GetGLHandle() const
bool OnSetContents(const uint8_t *contents, size_t length, size_t slice) override
ISize GetSize() const override
Scalar GetYCoordScale() const override
const TextureDescriptor & GetTextureDescriptor() const
TextureCoordinateSystem GetCoordinateSystem() const
uint32_t uint32_t * format
#define FML_UNREACHABLE()
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
constexpr std::optional< GLenum > ToTextureTarget(TextureType type)
std::shared_ptr< fml::Mapping > CreateMappingWithCopy(const uint8_t *contents, size_t length)
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
constexpr GLenum ToTextureType(TextureType type)
static TextureGLES::Type GetTextureTypeFromDescriptor(const TextureDescriptor &desc)
static std::optional< GLenum > ToRenderBufferFormat(PixelFormat format)
static bool IsDepthStencilFormat(PixelFormat format)
static GLenum ToAttachmentType(TextureGLES::AttachmentType point)
HandleType ToHandleType(TextureGLES::Type type)
static void usage(char *argv0)
TexImage2DData(PixelFormat pixel_format, std::shared_ptr< const fml::Mapping > mapping)
std::shared_ptr< const fml::Mapping > data
TexImage2DData(PixelFormat pixel_format)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
#define TRACE_EVENT0(category_group, name)
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)