25#if IMPELLER_SUPPORTS_RENDERING
53 const int32_t shifted = base_dimension >> mip_level;
54 return shifted > 0 ? shifted : 1;
63 const std::shared_ptr<impeller::Texture>&
texture,
64 const std::shared_ptr<impeller::DeviceBuffer>& staging_buffer,
71 FML_LOG(ERROR) <<
"Failed to create command buffer for texture overwrite.";
76 FML_LOG(ERROR) <<
"Failed to create blit pass for texture overwrite.";
81 if (!blit_pass->AddCopy(std::move(buffer_view),
texture, destination_region,
82 "Texture.overwrite", mip_level, slice)) {
85 if (!blit_pass->EncodeCommands()) {
95 const uint8_t*
data =
static_cast<const uint8_t*
>(source_bytes.
data());
98 auto& impeller_context = gpu_context.
GetContext();
102 if (!staging_buffer) {
103 FML_LOG(ERROR) <<
"Failed to allocate staging buffer for texture "
121 if (impeller_context.GetBackendType() ==
124 auto& task_runners = dart_state->GetTaskRunners();
128 destination_region, mip_level, slice]()
mutable {
131 destination_region, mip_level, slice)) {
132 FML_LOG(ERROR) <<
"Failed to encode texture overwrite blit on the "
135 context_shared->DisposeThreadLocalCachedResources();
141 length, destination_region, mip_level, slice)) {
144 impeller_context.DisposeThreadLocalCachedResources();
148#if IMPELLER_SUPPORTS_RENDERING
153static std::shared_ptr<impeller::Texture> GetTextureFromImage(
155 Dart_Handle image_wrapper) {
156 if (gpu_context ==
nullptr || Dart_IsNull(image_wrapper)) {
160 Dart_Handle inner = Dart_GetField(image_wrapper,
tonic::ToDart(
"_image"));
161 if (Dart_IsError(inner) || Dart_IsNull(inner)) {
169 sk_sp<flutter::DlImage> dl_image = canvas_image->image();
174 if (!impeller_image) {
185#if IMPELLER_SUPPORTS_RENDERING
188 image->set_image(dl_image);
189 auto wrapped =
image->CreateOuterWrapping();
211 bool enable_render_target_usage,
212 bool enable_shader_read_usage,
213 bool enable_shader_write_usage,
214 int mip_level_count) {
215 if (mip_level_count < 1) {
222 desc.
mip_count =
static_cast<size_t>(mip_level_count);
224 if (enable_render_target_usage) {
227 if (enable_shader_read_usage) {
230 if (enable_shader_write_usage) {
233 switch (sample_count) {
253 FML_LOG(ERROR) <<
"Failed to create texture.";
257 auto res = fml::MakeRefCounted<flutter::gpu::Texture>(std::move(
texture));
258 res->AssociateWithDartWrapper(wrapper);
265 Dart_Handle source_byte_data,
268 if (mip_level < 0 || slice < 0) {
272 static_cast<uint32_t
>(mip_level),
273 static_cast<uint32_t
>(slice));
282 Dart_Handle image_wrapper) {
283#if IMPELLER_SUPPORTS_RENDERING
284 auto texture = flutter::gpu::GetTextureFromImage(gpu_context, image_wrapper);
286 return Dart_NewTypedData(Dart_TypedData_kInt32, 0);
293 values[0] =
static_cast<int32_t
>(
297 values[2] =
static_cast<int32_t
>(desc.
size.
width);
298 values[3] =
static_cast<int32_t
>(desc.
size.
height);
301 values[5] =
static_cast<int32_t
>(desc.
type);
305 values[9] =
static_cast<int32_t
>(desc.
mip_count);
307 const intptr_t
length =
sizeof(values) /
sizeof(values[0]);
308 Dart_Handle list = Dart_NewTypedData(Dart_TypedData_kInt32,
length);
309 if (Dart_IsError(list)) {
312 Dart_TypedData_Type
type;
313 void* data =
nullptr;
314 intptr_t data_length = 0;
315 Dart_Handle acquire_result =
316 Dart_TypedDataAcquireData(list, &
type, &data, &data_length);
317 if (Dart_IsError(acquire_result)) {
318 return acquire_result;
320 std::memcpy(data, values,
sizeof(values));
321 Dart_TypedDataReleaseData(list);
324 return Dart_NewTypedData(Dart_TypedData_kInt32, 0);
331 Dart_Handle image_wrapper) {
332#if IMPELLER_SUPPORTS_RENDERING
333 auto texture = flutter::gpu::GetTextureFromImage(gpu_context, image_wrapper);
337 auto res = fml::MakeRefCounted<flutter::gpu::Texture>(std::move(
texture));
338 res->AssociateWithDartWrapper(wrapper);
static fml::RefPtr< CanvasImage > Create()
static UIDartState * Current()
std::shared_ptr< impeller::Context > & GetContextShared()
impeller::Context & GetContext()
Texture(std::shared_ptr< impeller::Texture > texture)
bool Overwrite(Context &gpu_context, const tonic::DartByteData &source_bytes, uint32_t mip_level, uint32_t slice)
std::shared_ptr< impeller::Texture > GetTexture()
Dart_Handle AsImage() const
To do anything rendering related with Impeller, you need a context.
virtual std::shared_ptr< Allocator > GetResourceAllocator() const =0
Returns the allocator used to create textures and buffers on the device.
virtual std::shared_ptr< Texture > GetImpellerTexture(const std::shared_ptr< Context > &context) const =0
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
const DlImageImpeller * asImpellerImage() const override
Safe downcast to DlImageImpeller.
const void * data() const
size_t length_in_bytes() const
#define IMPLEMENT_WRAPPERTYPEINFO(LibraryName, ClassName)
FlutterVulkanImage * image
uint32_t uint32_t * format
#define FML_LOG(severity)
bool InternalFlutterGpu_Texture_Overwrite(flutter::gpu::Texture *texture, flutter::gpu::Context *gpu_context, Dart_Handle source_byte_data, int mip_level, int slice)
bool InternalFlutterGpu_Texture_InitializeFromImage(Dart_Handle wrapper, flutter::gpu::Context *gpu_context, Dart_Handle image_wrapper)
Dart_Handle InternalFlutterGpu_Texture_AsImage(flutter::gpu::Texture *wrapper)
Dart_Handle InternalFlutterGpu_Texture_ImageTextureInfo(flutter::gpu::Context *gpu_context, Dart_Handle image_wrapper)
bool InternalFlutterGpu_Texture_Initialize(Dart_Handle wrapper, flutter::gpu::Context *gpu_context, int storage_mode, int format, int width, int height, int sample_count, int texture_type, bool enable_render_target_usage, bool enable_shader_read_usage, bool enable_shader_write_usage, int mip_level_count)
constexpr impeller::PixelFormat ToImpellerPixelFormat(FlutterGPUPixelFormat value)
constexpr FlutterGPUStorageMode FromImpellerStorageMode(impeller::StorageMode value)
constexpr FlutterGPUPixelFormat FromImpellerPixelFormat(impeller::PixelFormat value)
static int32_t MipDimensionAtLevel(int32_t base_dimension, uint32_t mip_level)
static bool EncodeAndSubmitOverwrite(impeller::Context &context, const std::shared_ptr< impeller::Texture > &texture, const std::shared_ptr< impeller::DeviceBuffer > &staging_buffer, size_t source_length, impeller::IRect destination_region, uint32_t mip_level, uint32_t slice)
constexpr impeller::StorageMode ToImpellerStorageMode(FlutterGPUStorageMode value)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
internal::CopyableLambda< T > MakeCopyable(T lambda)
constexpr bool IsMultisampleCapable(TextureType type)
Dart_Handle ToDart(const T &object)
std::shared_ptr< ContextGLES > context
std::shared_ptr< CommandBuffer > command_buffer
impeller::ShaderType type
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...