10#include "flutter/fml/logging.h"
11#include "flutter/fml/mapping.h"
12#include "flutter/fml/trace_event.h"
47 const TextureDescriptor&
desc) {
51 if (
usage == render_target && IsDepthStencilFormat(
desc.format)) {
59struct TexImage2DData {
63 std::shared_ptr<const fml::Mapping>
data;
66 switch (pixel_format) {
70 type = GL_UNSIGNED_BYTE;
75 type = GL_UNSIGNED_BYTE;
83 type = GL_UNSIGNED_BYTE;
104 type = GL_UNSIGNED_INT_24_8;
118 std::shared_ptr<const fml::Mapping> mapping)
119 : TexImage2DData(pixel_format) {
120 data = std::move(mapping);
123 bool IsValid()
const {
return is_valid_; }
126 bool is_valid_ =
false;
153 return std::shared_ptr<TextureGLES>(
160 std::optional<GLuint> fbo)
162 reactor_(
std::move(reactor)),
163 type_(GetTextureTypeFromDescriptor(GetTextureDescriptor())),
165 is_wrapped_(is_wrapped),
174 const auto max_size =
175 reactor_->GetProcTable().GetCapabilities()->max_texture_size;
176 if (tex_size.Max(max_size) != max_size) {
178 <<
" would exceed max supported size of " << max_size <<
".";
187 reactor_->CollectHandle(handle_);
191bool TextureGLES::IsValid()
const {
196void TextureGLES::SetLabel(std::string_view label) {
197 reactor_->SetDebugLabel(handle_, std::string{label.data(), label.size()});
201bool TextureGLES::OnSetContents(
const uint8_t* contents,
208bool TextureGLES::OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
214 if (mapping->GetSize() == 0u) {
218 if (mapping->GetMapping() ==
nullptr) {
223 VALIDATION_LOG <<
"Incorrect texture usage flags for setting contents on "
224 "this texture object.";
229 VALIDATION_LOG <<
"Cannot set the contents of a wrapped texture.";
235 if (tex_descriptor.size.IsEmpty()) {
239 if (!tex_descriptor.IsValid() ||
240 mapping->GetSize() < tex_descriptor.GetByteSizeOfBaseMipLevel()) {
245 GLenum texture_target;
246 switch (tex_descriptor.type) {
248 texture_type = GL_TEXTURE_2D;
249 texture_target = GL_TEXTURE_2D;
252 VALIDATION_LOG <<
"Multisample texture uploading is not supported for "
253 "the OpenGLES backend.";
256 texture_type = GL_TEXTURE_CUBE_MAP;
257 texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
260 texture_type = GL_TEXTURE_EXTERNAL_OES;
261 texture_target = GL_TEXTURE_EXTERNAL_OES;
265 auto data = std::make_shared<TexImage2DData>(tex_descriptor.format,
274 size = tex_descriptor.size,
277 ](
const auto& reactor) {
278 auto gl_handle = reactor.GetGLHandle(handle);
279 if (!gl_handle.has_value()) {
281 <<
"Texture was collected before it could be uploaded to the GPU.";
284 const auto&
gl = reactor.GetProcTable();
285 gl.BindTexture(texture_type, gl_handle.value());
286 const GLvoid* tex_data =
nullptr;
288 tex_data =
data->data->GetMapping();
294 gl.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
295 gl.TexImage2D(texture_target,
297 data->internal_format,
301 data->external_format,
308 slices_initialized_ = reactor_->AddOperation(texture_upload);
309 return slices_initialized_[0];
313ISize TextureGLES::GetSize()
const {
327 return GL_STENCIL_INDEX8;
329 return GL_DEPTH24_STENCIL8;
331 return GL_DEPTH32F_STENCIL8;
346void TextureGLES::InitializeContentsIfNecessary()
const {
347 if (!IsValid() || slices_initialized_[0]) {
350 slices_initialized_[0] =
true;
356 auto size = GetSize();
358 if (
size.IsEmpty()) {
362 const auto&
gl = reactor_->GetProcTable();
363 auto handle = reactor_->GetGLHandle(handle_);
364 if (!handle.has_value()) {
365 VALIDATION_LOG <<
"Could not initialize the contents of texture.";
373 if (!tex_data.IsValid()) {
377 gl.BindTexture(GL_TEXTURE_2D, handle.value());
380 gl.TexImage2D(GL_TEXTURE_2D,
382 tex_data.internal_format,
386 tex_data.external_format,
394 auto render_buffer_format =
396 if (!render_buffer_format.has_value()) {
400 gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
402 TRACE_EVENT0(
"impeller",
"RenderBufferStorageInitialization");
404 gl.RenderbufferStorageMultisampleEXT(
407 render_buffer_format.value(),
412 gl.RenderbufferStorage(
414 render_buffer_format.value(),
428 return reactor_->GetGLHandle(handle_);
433 if (!handle.has_value()) {
436 const auto&
gl = reactor_->GetProcTable();
441 if (!
target.has_value()) {
445 gl.BindTexture(
target.value(), handle.value());
449 gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
452 InitializeContentsIfNecessary();
457 slices_initialized_[slice] =
true;
461 return slices_initialized_[slice];
474 VALIDATION_LOG <<
"Generating mipmaps for multisample textures is not "
475 "supported in the GLES backend.";
488 if (!handle.has_value()) {
492 const auto&
gl = reactor_->GetProcTable();
505 return GL_COLOR_ATTACHMENT0;
507 return GL_DEPTH_ATTACHMENT;
509 return GL_STENCIL_ATTACHMENT;
519 InitializeContentsIfNecessary();
521 if (!handle.has_value()) {
524 const auto&
gl = reactor_->GetProcTable();
536 gl.FramebufferTexture2DMultisampleEXT(
547 gl.FramebufferRenderbuffer(
560Scalar TextureGLES::GetYCoordScale()
const {
static sk_sp< GrTextureProxy > wrapped(skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
const char * c_str() const
std::function< void(const ReactorGLES &reactor)> Operation
std::shared_ptr< ReactorGLES > Ref
bool IsSliceInitialized(size_t slice) const
TextureGLES(ReactorGLES::Ref reactor, TextureDescriptor desc)
@ kRenderBufferMultisampled
bool SetAsFramebufferAttachment(GLenum target, AttachmentType attachment_type) const
void MarkSliceInitialized(size_t slice) const
static std::shared_ptr< TextureGLES > WrapFBO(ReactorGLES::Ref reactor, TextureDescriptor desc, GLuint fbo)
std::optional< GLuint > GetGLHandle() const
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 std::optional< GLenum > ToRenderBufferFormat(PixelFormat format)
static GLenum ToAttachmentType(TextureGLES::AttachmentType point)
Mask< TextureUsage > TextureUsageMask
HandleType ToHandleType(TextureGLES::Type type)
static SkString to_string(int n)
static void usage(char *argv0)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
std::shared_ptr< const fml::Mapping > data
#define TRACE_EVENT0(category_group, name)
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)