7#include "flutter/fml/closure.h"
20 gl.BindFramebuffer(
type, GL_NONE);
21 gl.DeleteFramebuffers(1u, &fbo);
27 const std::shared_ptr<Texture>&
texture,
30 if (!handle.has_value()) {
37 gl.BindFramebuffer(fbo_type, 0);
42 gl.GenFramebuffers(1u, &fbo);
43 gl.BindFramebuffer(fbo_type, fbo);
52 if (
gl.CheckFramebufferStatus(fbo_type) != GL_FRAMEBUFFER_COMPLETE) {
74 if (!
gl.BlitFramebuffer.IsAvailable()) {
76 FML_LOG(
ERROR) <<
"Texture blit fallback not implemented yet for GLES2.";
80 GLuint read_fbo = GL_NONE;
81 GLuint draw_fbo = GL_NONE;
89 if (!
read.has_value()) {
92 read_fbo =
read.value();
97 if (!
draw.has_value()) {
100 draw_fbo =
draw.value();
103 gl.Disable(GL_SCISSOR_TEST);
104 gl.Disable(GL_DEPTH_TEST);
105 gl.Disable(GL_STENCIL_TEST);
123struct TexImage2DData {
129 explicit TexImage2DData(
PixelFormat pixel_format) {
130 switch (pixel_format) {
134 type = GL_UNSIGNED_BYTE;
139 type = GL_UNSIGNED_BYTE;
147 type = GL_UNSIGNED_BYTE;
157 type = GL_HALF_FLOAT;
168 type = GL_UNSIGNED_INT_24_8;
181 TexImage2DData(
PixelFormat pixel_format, BufferView p_buffer_view)
182 : TexImage2DData(pixel_format) {
186 bool IsValid()
const {
return is_valid_; }
189 bool is_valid_ =
false;
205 VALIDATION_LOG <<
"Incorrect texture usage flags for setting contents on "
206 "this texture object.";
211 VALIDATION_LOG <<
"Cannot set the contents of a wrapped texture.";
217 if (tex_descriptor.size.IsEmpty()) {
221 if (!tex_descriptor.IsValid() ||
231 GLenum texture_target;
232 switch (tex_descriptor.type) {
234 texture_type = GL_TEXTURE_2D;
235 texture_target = GL_TEXTURE_2D;
238 VALIDATION_LOG <<
"Multisample texture uploading is not supported for "
239 "the OpenGLES backend.";
242 texture_type = GL_TEXTURE_CUBE_MAP;
243 texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X +
slice;
246 texture_type = GL_TEXTURE_EXTERNAL_OES;
247 texture_target = GL_TEXTURE_EXTERNAL_OES;
251 TexImage2DData
data = TexImage2DData(tex_descriptor.format,
source);
252 if (!
data.IsValid()) {
258 if (!gl_handle.has_value()) {
260 <<
"Texture was collected before it could be uploaded to the GPU.";
264 gl.BindTexture(texture_type, gl_handle.value());
265 const GLvoid* tex_data =
266 data.buffer_view.buffer->OnGetContents() +
data.buffer_view.range.offset;
271 gl.TexImage2D(texture_target,
273 data.internal_format,
274 tex_descriptor.size.width,
275 tex_descriptor.size.height,
277 data.external_format,
287 gl.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
288 gl.TexSubImage2D(texture_target,
294 data.external_format,
313 VALIDATION_LOG <<
"Only textures with pixel format RGBA are supported yet.";
319 GLuint read_fbo = GL_NONE;
321 [&
gl, &read_fbo]() {
DeleteFBO(
gl, read_fbo, GL_READ_FRAMEBUFFER); });
325 if (!
read.has_value()) {
328 read_fbo =
read.value();
349 if (!texture_gles->GenerateMipmap()) {
static bool read(SkStream *stream, void *buffer, size_t amount)
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
const char * c_str() const
Wraps a closure that is invoked in the destructor unless released by the caller.
static TextureGLES & Cast(Texture &base)
void UpdateBufferData(const std::function< void(uint8_t *, size_t length)> &update_buffer_data)
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
std::optional< GLuint > GetGLHandle() const
const TextureDescriptor & GetTextureDescriptor() const
#define FML_LOG(severity)
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
static std::optional< GLuint > ConfigureFBO(const ProcTableGLES &gl, const std::shared_ptr< Texture > &texture, GLenum fbo_type)
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)
static SkString to_string(int n)
~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
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 Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
std::shared_ptr< const fml::Mapping > data
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)