7 #include "flutter/fml/closure.h"
19 static void FlipImage(uint8_t* buffer,
23 if (buffer ==
nullptr || stride == 0) {
27 const auto byte_width = width * stride;
29 for (
size_t top = 0; top < height; top++) {
30 size_t bottom = height - top - 1;
34 auto* top_row = buffer + byte_width * top;
35 auto* bottom_row = buffer + byte_width * bottom;
36 std::swap_ranges(top_row, top_row + byte_width, bottom_row);
45 gl.BindFramebuffer(type, GL_NONE);
46 gl.DeleteFramebuffers(1u, &fbo);
52 const std::shared_ptr<Texture>& texture,
55 if (!handle.has_value()) {
62 gl.BindFramebuffer(fbo_type, 0);
67 gl.GenFramebuffers(1u, &fbo);
68 gl.BindFramebuffer(fbo_type, fbo);
77 GLenum status = gl.CheckFramebufferStatus(fbo_type);
78 if (status != GL_FRAMEBUFFER_COMPLETE) {
101 if (!gl.BlitFramebuffer.IsAvailable()) {
103 VALIDATION_LOG <<
"Texture blit fallback not implemented yet for GLES2.";
107 GLuint read_fbo = GL_NONE;
108 GLuint draw_fbo = GL_NONE;
109 fml::ScopedCleanupClosure delete_fbos([&gl, &read_fbo, &draw_fbo]() {
110 DeleteFBO(gl, read_fbo, GL_READ_FRAMEBUFFER);
111 DeleteFBO(gl, draw_fbo, GL_DRAW_FRAMEBUFFER);
116 if (!read.has_value()) {
119 read_fbo = read.value();
124 if (!draw.has_value()) {
127 draw_fbo = draw.value();
130 gl.Disable(GL_SCISSOR_TEST);
131 gl.Disable(GL_DEPTH_TEST);
132 gl.Disable(GL_STENCIL_TEST);
161 VALIDATION_LOG <<
"Incorrect texture usage flags for setting contents on "
162 "this texture object.";
167 VALIDATION_LOG <<
"Cannot set the contents of a wrapped texture.";
173 if (tex_descriptor.size.IsEmpty()) {
177 if (!tex_descriptor.IsValid() ||
187 GLenum texture_target;
188 switch (tex_descriptor.type) {
190 texture_type = GL_TEXTURE_2D;
191 texture_target = GL_TEXTURE_2D;
194 VALIDATION_LOG <<
"Multisample texture uploading is not supported for "
195 "the OpenGLES backend.";
198 texture_type = GL_TEXTURE_CUBE_MAP;
199 texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X +
slice;
202 texture_type = GL_TEXTURE_EXTERNAL_OES;
203 texture_target = GL_TEXTURE_EXTERNAL_OES;
207 std::optional<PixelFormatGLES> gles_format =
211 "GL_EXT_texture_format_BGRA8888"));
212 if (!gles_format.has_value()) {
218 if (!gl_handle.has_value()) {
220 <<
"Texture was collected before it could be uploaded to the GPU.";
224 gl.BindTexture(texture_type, gl_handle.value());
225 const GLvoid* tex_data =
231 gl.TexImage2D(texture_target,
233 gles_format->internal_format,
234 tex_descriptor.size.width,
235 tex_descriptor.size.height,
237 gles_format->external_format,
244 gl.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
245 gl.TexSubImage2D(texture_target,
251 gles_format->external_format,
270 std::optional<PixelFormatGLES> gles_format =
274 "GL_EXT_texture_format_BGRA8888"));
276 if (!gles_format.has_value()) {
283 GLuint read_fbo = GL_NONE;
284 fml::ScopedCleanupClosure delete_fbos(
285 [&gl, &read_fbo]() {
DeleteFBO(gl, read_fbo, GL_FRAMEBUFFER); });
289 if (!read.has_value()) {
292 read_fbo = read.value();
299 format = gles_format->external_format,
300 type = gles_format->type,
303 ](uint8_t* data,
size_t length) {
307 switch (coord_system) {
329 if (!texture_gles->GenerateMipmap()) {
342 return "Resize Texture";
350 if (!gl.BlitFramebuffer.IsAvailable()) {
352 VALIDATION_LOG <<
"Texture blit fallback not implemented yet for GLES2.";
358 GLuint read_fbo = GL_NONE;
359 GLuint draw_fbo = GL_NONE;
360 fml::ScopedCleanupClosure delete_fbos([&gl, &read_fbo, &draw_fbo]() {
361 DeleteFBO(gl, read_fbo, GL_READ_FRAMEBUFFER);
362 DeleteFBO(gl, draw_fbo, GL_DRAW_FRAMEBUFFER);
367 if (!read.has_value()) {
370 read_fbo = read.value();
375 if (!draw.has_value()) {
378 draw_fbo = draw.value();
381 gl.Disable(GL_SCISSOR_TEST);
382 gl.Disable(GL_DEPTH_TEST);
383 gl.Disable(GL_STENCIL_TEST);
388 gl.BlitFramebuffer(source_region.
GetX(),
389 source_region.
GetY(),
392 destination_region.
GetX(),
393 destination_region.
GetY(),
static TextureGLES & Cast(Texture &base)
bool HasExtension(const std::string &ext) const
void UpdateBufferData(const std::function< void(uint8_t *, size_t length)> &update_buffer_data)
virtual uint8_t * OnGetContents() const =0
const DescriptionGLES * GetDescription() const
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
const ProcTableGLES & GetProcTable() const
Get the OpenGL proc. table the reactor uses to manage handles.
bool IsSliceInitialized(size_t slice) const
bool SetAsFramebufferAttachment(GLenum target, AttachmentType attachment_type) const
void MarkSliceInitialized(size_t slice) const
Indicates that a specific texture slice has been initialized.
std::optional< GLuint > GetGLHandle() const
const TextureDescriptor & GetTextureDescriptor() const
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
std::optional< PixelFormatGLES > ToPixelFormatGLES(PixelFormat pixel_format, bool supports_bgra)
static std::optional< GLuint > ConfigureFBO(const ProcTableGLES &gl, const std::shared_ptr< Texture > &texture, GLenum fbo_type)
std::string DebugToFramebufferError(int status)
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
static void DeleteFBO(const ProcTableGLES &gl, GLuint fbo, GLenum type)
~BlitCopyBufferToTextureCommandGLES() override
std::string GetLabel() const override
bool Encode(const ReactorGLES &reactor) const override
std::shared_ptr< Texture > destination
~BlitCopyTextureToBufferCommandGLES() override
bool Encode(const ReactorGLES &reactor) const override
std::string GetLabel() const override
std::shared_ptr< DeviceBuffer > destination
std::shared_ptr< Texture > source
size_t destination_offset
bool Encode(const ReactorGLES &reactor) const override
std::string GetLabel() const override
~BlitCopyTextureToTextureCommandGLES() override
IPoint destination_origin
std::shared_ptr< Texture > destination
std::shared_ptr< Texture > source
virtual ~BlitEncodeGLES()
~BlitGenerateMipmapCommandGLES() override
bool Encode(const ReactorGLES &reactor) const override
std::string GetLabel() const override
std::shared_ptr< Texture > texture
~BlitResizeTextureCommandGLES() override
bool Encode(const ReactorGLES &reactor) const override
std::string GetLabel() const override
std::shared_ptr< Texture > destination
std::shared_ptr< Texture > source
const DeviceBuffer * GetBuffer() const
constexpr Type GetY() const
Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|.
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
constexpr T Area() const
Get the area of the rectangle, equivalent to |GetSize().Area()|.
constexpr Type GetX() const
Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.
constexpr static TRect MakeSize(const TSize< U > &size)
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.