|
6 | 6 |
|
7 | 7 | #include "flutter/fml/closure.h" |
8 | 8 | #include "impeller/base/validation.h" |
| 9 | +#include "impeller/renderer/backend/gles/device_buffer_gles.h" |
9 | 10 | #include "impeller/renderer/backend/gles/texture_gles.h" |
10 | 11 |
|
11 | 12 | namespace impeller { |
@@ -116,6 +117,44 @@ bool BlitCopyTextureToTextureCommandGLES::Encode( |
116 | 117 | return true; |
117 | 118 | }; |
118 | 119 |
|
| 120 | +BlitCopyTextureToBufferCommandGLES::~BlitCopyTextureToBufferCommandGLES() = |
| 121 | + default; |
| 122 | + |
| 123 | +std::string BlitCopyTextureToBufferCommandGLES::GetLabel() const { |
| 124 | + return label; |
| 125 | +} |
| 126 | + |
| 127 | +bool BlitCopyTextureToBufferCommandGLES::Encode( |
| 128 | + const ReactorGLES& reactor) const { |
| 129 | + if (source->GetTextureDescriptor().format != PixelFormat::kR8G8B8A8UNormInt) { |
| 130 | + VALIDATION_LOG << "Only textures with pixel format RGBA are supported yet."; |
| 131 | + return false; |
| 132 | + } |
| 133 | + |
| 134 | + const auto& gl = reactor.GetProcTable(); |
| 135 | + |
| 136 | + GLuint read_fbo = GL_NONE; |
| 137 | + fml::ScopedCleanupClosure delete_fbos( |
| 138 | + [&gl, &read_fbo]() { DeleteFBO(gl, read_fbo, GL_READ_FRAMEBUFFER); }); |
| 139 | + |
| 140 | + { |
| 141 | + auto read = ConfigureFBO(gl, source, GL_READ_FRAMEBUFFER); |
| 142 | + if (!read.has_value()) { |
| 143 | + return false; |
| 144 | + } |
| 145 | + read_fbo = read.value(); |
| 146 | + } |
| 147 | + |
| 148 | + DeviceBufferGLES::Cast(*destination) |
| 149 | + .UpdateBufferData([&gl, this](uint8_t* data, size_t length) { |
| 150 | + gl.ReadPixels(source_region.origin.x, source_region.origin.y, |
| 151 | + source_region.size.width, source_region.size.height, |
| 152 | + GL_RGBA, GL_UNSIGNED_BYTE, data + destination_offset); |
| 153 | + }); |
| 154 | + |
| 155 | + return true; |
| 156 | +}; |
| 157 | + |
119 | 158 | BlitGenerateMipmapCommandGLES::~BlitGenerateMipmapCommandGLES() = default; |
120 | 159 |
|
121 | 160 | std::string BlitGenerateMipmapCommandGLES::GetLabel() const { |
|
0 commit comments