10 #include "flutter/fml/mapping.h"
11 #include "flutter/fml/trace_event.h"
23 const auto render_target =
58 reactor_(
std::move(reactor)),
61 is_wrapped_(is_wrapped) {
70 reactor_->GetProcTable().GetCapabilities()->max_texture_size;
71 if (tex_size.Max(max_size) != max_size) {
73 <<
" would exceed max supported size of " << max_size <<
".";
82 reactor_->CollectHandle(handle_);
86 bool TextureGLES::IsValid()
const {
91 void TextureGLES::SetLabel(std::string_view label) {
92 reactor_->SetDebugLabel(handle_, std::string{label.data(), label.size()});
99 std::shared_ptr<const fml::Mapping>
data;
102 switch (pixel_format) {
106 type = GL_UNSIGNED_BYTE;
114 type = GL_UNSIGNED_BYTE;
124 type = GL_HALF_FLOAT;
134 type = GL_UNSIGNED_INT_24_8;
150 std::shared_ptr<const fml::Mapping> mapping)
152 data = std::move(mapping);
158 bool is_valid_ =
false;
162 bool TextureGLES::OnSetContents(
const uint8_t* contents,
169 bool TextureGLES::OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
175 if (mapping->GetSize() == 0u) {
179 if (mapping->GetMapping() ==
nullptr) {
184 VALIDATION_LOG <<
"Incorrect texture usage flags for setting contents on "
185 "this texture object.";
190 VALIDATION_LOG <<
"Cannot set the contents of a wrapped texture.";
196 if (tex_descriptor.size.IsEmpty()) {
200 if (!tex_descriptor.IsValid()) {
204 if (mapping->GetSize() < tex_descriptor.GetByteSizeOfBaseMipLevel()) {
209 GLenum texture_target;
210 switch (tex_descriptor.type) {
212 texture_type = GL_TEXTURE_2D;
213 texture_target = GL_TEXTURE_2D;
216 VALIDATION_LOG <<
"Multisample texture uploading is not supported for "
217 "the OpenGLES backend.";
220 texture_type = GL_TEXTURE_CUBE_MAP;
221 texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
224 texture_type = GL_TEXTURE_EXTERNAL_OES;
225 texture_target = GL_TEXTURE_EXTERNAL_OES;
229 auto data = std::make_shared<TexImage2DData>(tex_descriptor.format,
231 if (!data || !data->IsValid()) {
238 size = tex_descriptor.size,
241 ](
const auto& reactor) {
242 auto gl_handle = reactor.GetGLHandle(handle);
243 if (!gl_handle.has_value()) {
245 <<
"Texture was collected before it could be uploaded to the GPU.";
248 const auto& gl = reactor.GetProcTable();
249 gl.BindTexture(texture_type, gl_handle.value());
250 const GLvoid* tex_data =
nullptr;
252 tex_data = data->data->GetMapping();
256 TRACE_EVENT1(
"impeller",
"TexImage2DUpload",
"Bytes",
257 std::to_string(data->data->GetSize()).c_str());
258 gl.TexImage2D(texture_target,
260 data->internal_format,
264 data->external_format,
271 contents_initialized_ = reactor_->AddOperation(texture_upload);
272 return contents_initialized_;
276 ISize TextureGLES::GetSize()
const {
290 return GL_STENCIL_INDEX8;
292 return GL_DEPTH24_STENCIL8;
294 return GL_DEPTH32F_STENCIL8;
309 void TextureGLES::InitializeContentsIfNecessary()
const {
313 if (contents_initialized_) {
316 contents_initialized_ =
true;
322 auto size = GetSize();
324 if (size.IsEmpty()) {
328 const auto& gl = reactor_->GetProcTable();
329 auto handle = reactor_->GetGLHandle(handle_);
330 if (!handle.has_value()) {
331 VALIDATION_LOG <<
"Could not initialize the contents of texture.";
339 if (!tex_data.IsValid()) {
343 gl.BindTexture(GL_TEXTURE_2D, handle.value());
345 TRACE_EVENT0(
"impeller",
"TexImage2DInitialization");
346 gl.TexImage2D(GL_TEXTURE_2D,
348 tex_data.internal_format,
352 tex_data.external_format,
360 auto render_buffer_format =
362 if (!render_buffer_format.has_value()) {
366 gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
368 TRACE_EVENT0(
"impeller",
"RenderBufferStorageInitialization");
370 gl.RenderbufferStorageMultisampleEXT(
373 render_buffer_format.value(),
378 gl.RenderbufferStorage(
380 render_buffer_format.value(),
394 return reactor_->GetGLHandle(handle_);
399 if (!handle.has_value()) {
402 const auto& gl = reactor_->GetProcTable();
407 if (!target.has_value()) {
411 gl.BindTexture(target.value(), handle.value());
415 gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
418 InitializeContentsIfNecessary();
432 VALIDATION_LOG <<
"Generating mipmaps for multisample textures is not "
433 "supported in the GLES backend.";
446 if (!handle.has_value()) {
450 const auto& gl = reactor_->GetProcTable();
463 return GL_COLOR_ATTACHMENT0;
465 return GL_DEPTH_ATTACHMENT;
467 return GL_STENCIL_ATTACHMENT;
476 InitializeContentsIfNecessary();
478 if (!handle.has_value()) {
481 const auto& gl = reactor_->GetProcTable();
485 gl.FramebufferTexture2D(target,
493 gl.FramebufferTexture2DMultisampleEXT(
504 gl.FramebufferRenderbuffer(target,
516 Scalar TextureGLES::GetYCoordScale()
const {