10 #include "flutter/fml/logging.h"
11 #include "flutter/fml/mapping.h"
12 #include "flutter/fml/trace_event.h"
82 reactor_(
std::move(reactor)),
85 is_wrapped_(is_wrapped) {
94 reactor_->GetProcTable().GetCapabilities()->max_texture_size;
95 if (tex_size.Max(max_size) != max_size) {
97 <<
" would exceed max supported size of " << max_size <<
".";
106 reactor_->CollectHandle(handle_);
110 bool TextureGLES::IsValid()
const {
115 void TextureGLES::SetLabel(std::string_view label) {
116 reactor_->SetDebugLabel(handle_, std::string{label.data(), label.size()});
123 std::shared_ptr<const fml::Mapping>
data;
126 switch (pixel_format) {
130 type = GL_UNSIGNED_BYTE;
135 type = GL_UNSIGNED_BYTE;
143 type = GL_UNSIGNED_BYTE;
153 type = GL_HALF_FLOAT;
164 type = GL_UNSIGNED_INT_24_8;
178 std::shared_ptr<const fml::Mapping> mapping)
180 data = std::move(mapping);
186 bool is_valid_ =
false;
190 bool TextureGLES::OnSetContents(
const uint8_t* contents,
197 bool TextureGLES::OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
203 if (mapping->GetSize() == 0u) {
207 if (mapping->GetMapping() ==
nullptr) {
212 VALIDATION_LOG <<
"Incorrect texture usage flags for setting contents on "
213 "this texture object.";
218 VALIDATION_LOG <<
"Cannot set the contents of a wrapped texture.";
224 if (tex_descriptor.size.IsEmpty()) {
228 if (!tex_descriptor.IsValid()) {
232 if (mapping->GetSize() < tex_descriptor.GetByteSizeOfBaseMipLevel()) {
237 GLenum texture_target;
238 switch (tex_descriptor.type) {
240 texture_type = GL_TEXTURE_2D;
241 texture_target = GL_TEXTURE_2D;
244 VALIDATION_LOG <<
"Multisample texture uploading is not supported for "
245 "the OpenGLES backend.";
248 texture_type = GL_TEXTURE_CUBE_MAP;
249 texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
252 texture_type = GL_TEXTURE_EXTERNAL_OES;
253 texture_target = GL_TEXTURE_EXTERNAL_OES;
257 auto data = std::make_shared<TexImage2DData>(tex_descriptor.format,
259 if (!data || !data->IsValid()) {
266 size = tex_descriptor.size,
269 ](
const auto& reactor) {
270 auto gl_handle = reactor.GetGLHandle(handle);
271 if (!gl_handle.has_value()) {
273 <<
"Texture was collected before it could be uploaded to the GPU.";
276 const auto& gl = reactor.GetProcTable();
277 gl.BindTexture(texture_type, gl_handle.value());
278 const GLvoid* tex_data =
nullptr;
280 tex_data = data->data->GetMapping();
284 TRACE_EVENT1(
"impeller",
"TexImage2DUpload",
"Bytes",
285 std::to_string(data->data->GetSize()).c_str());
286 gl.TexImage2D(texture_target,
288 data->internal_format,
292 data->external_format,
299 contents_initialized_ = reactor_->AddOperation(texture_upload);
300 return contents_initialized_;
304 ISize TextureGLES::GetSize()
const {
318 return GL_STENCIL_INDEX8;
320 return GL_DEPTH24_STENCIL8;
322 return GL_DEPTH32F_STENCIL8;
337 void TextureGLES::InitializeContentsIfNecessary()
const {
341 if (contents_initialized_) {
344 contents_initialized_ =
true;
350 auto size = GetSize();
352 if (size.IsEmpty()) {
356 const auto& gl = reactor_->GetProcTable();
357 auto handle = reactor_->GetGLHandle(handle_);
358 if (!handle.has_value()) {
359 VALIDATION_LOG <<
"Could not initialize the contents of texture.";
367 if (!tex_data.IsValid()) {
371 gl.BindTexture(GL_TEXTURE_2D, handle.value());
373 TRACE_EVENT0(
"impeller",
"TexImage2DInitialization");
374 gl.TexImage2D(GL_TEXTURE_2D,
376 tex_data.internal_format,
380 tex_data.external_format,
388 auto render_buffer_format =
390 if (!render_buffer_format.has_value()) {
394 gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
396 TRACE_EVENT0(
"impeller",
"RenderBufferStorageInitialization");
398 gl.RenderbufferStorageMultisampleEXT(
401 render_buffer_format.value(),
406 gl.RenderbufferStorage(
408 render_buffer_format.value(),
422 return reactor_->GetGLHandle(handle_);
427 if (!handle.has_value()) {
430 const auto& gl = reactor_->GetProcTable();
435 if (!target.has_value()) {
439 gl.BindTexture(target.value(), handle.value());
443 gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
446 InitializeContentsIfNecessary();
460 VALIDATION_LOG <<
"Generating mipmaps for multisample textures is not "
461 "supported in the GLES backend.";
474 if (!handle.has_value()) {
478 const auto& gl = reactor_->GetProcTable();
491 return GL_COLOR_ATTACHMENT0;
493 return GL_DEPTH_ATTACHMENT;
495 return GL_STENCIL_ATTACHMENT;
505 InitializeContentsIfNecessary();
507 if (!handle.has_value()) {
510 const auto& gl = reactor_->GetProcTable();
514 gl.FramebufferTexture2D(target,
522 gl.FramebufferTexture2DMultisampleEXT(
533 gl.FramebufferRenderbuffer(
546 Scalar TextureGLES::GetYCoordScale()
const {