Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
texture.h File Reference

Go to the source code of this file.

Classes

class  flutter::gpu::Texture
 

Namespaces

namespace  flutter
 
namespace  flutter::gpu
 

Functions

FLUTTER_GPU_EXPORT 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)
 
FLUTTER_GPU_EXPORT bool InternalFlutterGpu_Texture_Overwrite (flutter::gpu::Texture *wrapper, flutter::gpu::Context *gpu_context, Dart_Handle source_byte_data, int mip_level, int slice)
 
FLUTTER_GPU_EXPORT Dart_Handle InternalFlutterGpu_Texture_AsImage (flutter::gpu::Texture *wrapper)
 
FLUTTER_GPU_EXPORT Dart_Handle InternalFlutterGpu_Texture_ImageTextureInfo (flutter::gpu::Context *gpu_context, Dart_Handle image_wrapper)
 
FLUTTER_GPU_EXPORT bool InternalFlutterGpu_Texture_InitializeFromImage (Dart_Handle wrapper, flutter::gpu::Context *gpu_context, Dart_Handle image_wrapper)
 

Function Documentation

◆ InternalFlutterGpu_Texture_AsImage()

FLUTTER_GPU_EXPORT Dart_Handle InternalFlutterGpu_Texture_AsImage ( flutter::gpu::Texture wrapper)
extern

Definition at line 276 of file texture.cc.

276 {
277 return wrapper->AsImage();
278}
Dart_Handle AsImage() const
Definition texture.cc:181

References flutter::gpu::Texture::AsImage().

◆ InternalFlutterGpu_Texture_ImageTextureInfo()

FLUTTER_GPU_EXPORT Dart_Handle InternalFlutterGpu_Texture_ImageTextureInfo ( flutter::gpu::Context gpu_context,
Dart_Handle  image_wrapper 
)
extern

Definition at line 280 of file texture.cc.

282 {
283#if IMPELLER_SUPPORTS_RENDERING
284 auto texture = flutter::gpu::GetTextureFromImage(gpu_context, image_wrapper);
285 if (!texture) {
286 return Dart_NewTypedData(Dart_TypedData_kInt32, 0);
287 }
288 const impeller::TextureDescriptor& desc = texture->GetTextureDescriptor();
289 const impeller::TextureUsageMask usage = desc.usage;
290
291 // Layout must match the parsing in the Dart `Texture._fromImage`.
292 int32_t values[10];
293 values[0] = static_cast<int32_t>(
295 values[1] =
296 static_cast<int32_t>(flutter::gpu::FromImpellerPixelFormat(desc.format));
297 values[2] = static_cast<int32_t>(desc.size.width);
298 values[3] = static_cast<int32_t>(desc.size.height);
299 values[4] = static_cast<int32_t>(desc.sample_count);
300 // The Flutter GPU `TextureType` enum mirrors `impeller::TextureType`.
301 values[5] = static_cast<int32_t>(desc.type);
302 values[6] = (usage & impeller::TextureUsage::kRenderTarget) ? 1 : 0;
303 values[7] = (usage & impeller::TextureUsage::kShaderRead) ? 1 : 0;
304 values[8] = (usage & impeller::TextureUsage::kShaderWrite) ? 1 : 0;
305 values[9] = static_cast<int32_t>(desc.mip_count);
306
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)) {
310 return list;
311 }
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;
319 }
320 std::memcpy(data, values, sizeof(values));
321 Dart_TypedDataReleaseData(list);
322 return list;
323#else
324 return Dart_NewTypedData(Dart_TypedData_kInt32, 0);
325#endif
326}
size_t length
FlTexture * texture
constexpr FlutterGPUStorageMode FromImpellerStorageMode(impeller::StorageMode value)
Definition formats.h:41
constexpr FlutterGPUPixelFormat FromImpellerPixelFormat(impeller::PixelFormat value)
Definition formats.h:188
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switch_defs.h:36
impeller::ShaderType type
Type height
Definition size.h:29
Type width
Definition size.h:28
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...

References impeller::TextureDescriptor::format, flutter::gpu::FromImpellerPixelFormat(), flutter::gpu::FromImpellerStorageMode(), impeller::TSize< T >::height, impeller::kRenderTarget, impeller::kShaderRead, impeller::kShaderWrite, length, impeller::TextureDescriptor::mip_count, impeller::TextureDescriptor::sample_count, impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, texture, impeller::TextureDescriptor::type, type, impeller::TextureDescriptor::usage, and impeller::TSize< T >::width.

◆ InternalFlutterGpu_Texture_Initialize()

FLUTTER_GPU_EXPORT 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 
)
extern

Exports

Definition at line 203 of file texture.cc.

214 {
215 if (mip_level_count < 1) {
216 return false;
217 }
220 desc.size = {width, height};
222 desc.mip_count = static_cast<size_t>(mip_level_count);
223 desc.usage = {};
224 if (enable_render_target_usage) {
226 }
227 if (enable_shader_read_usage) {
229 }
230 if (enable_shader_write_usage) {
232 }
233 switch (sample_count) {
234 case 1:
236 break;
237 case 4:
239 break;
240 default:
241 return false;
242 }
243 desc.type = static_cast<impeller::TextureType>(texture_type);
246 return false;
247 }
248
249 auto texture =
250 gpu_context->GetContext().GetResourceAllocator()->CreateTexture(desc,
251 true);
252 if (!texture) {
253 FML_LOG(ERROR) << "Failed to create texture.";
254 return false;
255 }
256
257 auto res = fml::MakeRefCounted<flutter::gpu::Texture>(std::move(texture));
258 res->AssociateWithDartWrapper(wrapper);
259
260 return true;
261}
impeller::Context & GetContext()
Definition context.cc:87
virtual std::shared_ptr< Allocator > GetResourceAllocator() const =0
Returns the allocator used to create textures and buffers on the device.
#define FML_LOG(severity)
Definition logging.h:101
constexpr impeller::PixelFormat ToImpellerPixelFormat(FlutterGPUPixelFormat value)
Definition formats.h:116
constexpr impeller::StorageMode ToImpellerStorageMode(FlutterGPUStorageMode value)
Definition formats.h:25
constexpr bool IsMultisampleCapable(TextureType type)
Definition formats.h:471
int32_t height
int32_t width

References FML_LOG, impeller::TextureDescriptor::format, format, flutter::gpu::Context::GetContext(), impeller::Context::GetResourceAllocator(), height, impeller::IsMultisampleCapable(), impeller::kCount1, impeller::kCount4, impeller::kRenderTarget, impeller::kShaderRead, impeller::kShaderWrite, impeller::TextureDescriptor::mip_count, impeller::TextureDescriptor::sample_count, impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, texture, flutter::gpu::ToImpellerPixelFormat(), flutter::gpu::ToImpellerStorageMode(), impeller::TextureDescriptor::type, impeller::TextureDescriptor::usage, and width.

◆ InternalFlutterGpu_Texture_InitializeFromImage()

FLUTTER_GPU_EXPORT bool InternalFlutterGpu_Texture_InitializeFromImage ( Dart_Handle  wrapper,
flutter::gpu::Context gpu_context,
Dart_Handle  image_wrapper 
)
extern

Definition at line 328 of file texture.cc.

331 {
332#if IMPELLER_SUPPORTS_RENDERING
333 auto texture = flutter::gpu::GetTextureFromImage(gpu_context, image_wrapper);
334 if (!texture) {
335 return false;
336 }
337 auto res = fml::MakeRefCounted<flutter::gpu::Texture>(std::move(texture));
338 res->AssociateWithDartWrapper(wrapper);
339 return true;
340#else
341 return false;
342#endif
343}

References texture.

◆ InternalFlutterGpu_Texture_Overwrite()

FLUTTER_GPU_EXPORT bool InternalFlutterGpu_Texture_Overwrite ( flutter::gpu::Texture wrapper,
flutter::gpu::Context gpu_context,
Dart_Handle  source_byte_data,
int  mip_level,
int  slice 
)
extern

Definition at line 263 of file texture.cc.

267 {
268 if (mip_level < 0 || slice < 0) {
269 return false;
270 }
271 return texture->Overwrite(*gpu_context, tonic::DartByteData(source_byte_data),
272 static_cast<uint32_t>(mip_level),
273 static_cast<uint32_t>(slice));
274}

References texture.