21static void FlipImage(uint8_t* buffer,
25 if (buffer ==
nullptr || stride == 0) {
29 const auto byte_width =
width * stride;
31 for (
size_t top = 0; top <
height; top++) {
32 size_t bottom =
height - top - 1;
36 auto* top_row =
buffer + byte_width * top;
37 auto* bottom_row =
buffer + byte_width * bottom;
38 std::swap_ranges(top_row, top_row + byte_width, bottom_row);
47 gl.BindFramebuffer(
type, GL_NONE);
48 gl.DeleteFramebuffers(1u, &fbo);
54 const std::shared_ptr<Texture>&
texture,
57 if (!handle.has_value()) {
64 gl.BindFramebuffer(fbo_type, 0);
69 gl.GenFramebuffers(1u, &fbo);
70 gl.BindFramebuffer(fbo_type, fbo);
79 GLenum status = gl.CheckFramebufferStatus(fbo_type);
80 if (status != GL_FRAMEBUFFER_COMPLETE) {
103 if (!gl.BlitFramebuffer.IsAvailable()) {
105 VALIDATION_LOG <<
"Texture blit fallback not implemented yet for GLES2.";
109 GLuint read_fbo = GL_NONE;
110 GLuint draw_fbo = GL_NONE;
112 DeleteFBO(gl, read_fbo, GL_READ_FRAMEBUFFER);
113 DeleteFBO(gl, draw_fbo, GL_DRAW_FRAMEBUFFER);
118 if (!read.has_value()) {
121 read_fbo = read.value();
126 if (!draw.has_value()) {
129 draw_fbo = draw.value();
132 gl.Disable(GL_SCISSOR_TEST);
133 gl.Disable(GL_DEPTH_TEST);
134 gl.Disable(GL_STENCIL_TEST);
163 VALIDATION_LOG <<
"Incorrect texture usage flags for setting contents on "
164 "this texture object.";
169 VALIDATION_LOG <<
"Cannot set the contents of a wrapped texture.";
175 if (tex_descriptor.size.IsEmpty()) {
179 if (!tex_descriptor.IsValid() ||
189 GLenum texture_target;
190 switch (tex_descriptor.type) {
192 texture_type = GL_TEXTURE_2D;
193 texture_target = GL_TEXTURE_2D;
196 VALIDATION_LOG <<
"Multisample texture uploading is not supported for "
197 "the OpenGLES backend.";
200 texture_type = GL_TEXTURE_CUBE_MAP;
201 texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X +
slice;
204 texture_type = GL_TEXTURE_EXTERNAL_OES;
205 texture_target = GL_TEXTURE_EXTERNAL_OES;
209 std::optional<PixelFormatGLES> gles_format =
213 "GL_EXT_texture_format_BGRA8888"));
214 if (!gles_format.has_value()) {
220 if (!gl_handle.has_value()) {
222 <<
"Texture was collected before it could be uploaded to the GPU.";
226 gl.BindTexture(texture_type, gl_handle.value());
227 const GLvoid* tex_data =
237 const auto level_width =
238 std::max<int32_t>(1, tex_descriptor.size.width >>
mip_level);
239 const auto level_height =
240 std::max<int32_t>(1, tex_descriptor.size.height >>
mip_level);
241 gl.TexImage2D(texture_target,
243 gles_format->internal_format,
247 gles_format->external_format,
254 gl.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
255 gl.TexSubImage2D(texture_target,
261 gles_format->external_format,
280 std::optional<PixelFormatGLES> gles_format =
284 "GL_EXT_texture_format_BGRA8888"));
286 if (!gles_format.has_value()) {
293 GLuint read_fbo = GL_NONE;
295 [&gl, &read_fbo]() {
DeleteFBO(gl, read_fbo, GL_FRAMEBUFFER); });
299 if (!read.has_value()) {
302 read_fbo = read.value();
309 format = gles_format->external_format,
310 type = gles_format->type,
313 ](uint8_t* data,
size_t length) {
317 switch (coord_system) {
339 if (!texture_gles->GenerateMipmap()) {
352 return "Resize Texture";
360 if (!gl.BlitFramebuffer.IsAvailable()) {
362 VALIDATION_LOG <<
"Texture blit fallback not implemented yet for GLES2.";
368 GLuint read_fbo = GL_NONE;
369 GLuint draw_fbo = GL_NONE;
371 DeleteFBO(gl, read_fbo, GL_READ_FRAMEBUFFER);
372 DeleteFBO(gl, draw_fbo, GL_DRAW_FRAMEBUFFER);
377 if (!read.has_value()) {
380 read_fbo = read.value();
385 if (!draw.has_value()) {
388 draw_fbo = draw.value();
391 gl.Disable(GL_SCISSOR_TEST);
392 gl.Disable(GL_DEPTH_TEST);
393 gl.Disable(GL_STENCIL_TEST);
398 gl.BlitFramebuffer(source_region.
GetX(),
399 source_region.
GetY(),
402 destination_region.
GetX(),
403 destination_region.
GetY(),
Wraps a closure that is invoked in the destructor unless released by the caller.
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 SetAsFramebufferAttachment(GLenum target, AttachmentType attachment_type)
bool IsSliceMipLevelInitialized(size_t slice, size_t mip_level) const
void MarkSliceMipLevelInitialized(size_t slice, size_t mip_level)
Indicates that storage for mip_level of slice has been allocated by a glTexImage2D call (or equivalen...
std::optional< GLuint > GetGLHandle() const
const TextureDescriptor & GetTextureDescriptor() const
uint32_t uint32_t * format
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
std::optional< PixelFormatGLES > ToPixelFormatGLES(PixelFormat pixel_format, bool supports_bgra)
std::string DebugToFramebufferError(int status)
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)
impeller::ShaderType 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|.
static constexpr TRect MakeSize(const TSize< U > &size)
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.