Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
flutter::gpu::Texture Class Reference

#include <texture.h>

Inheritance diagram for flutter::gpu::Texture:
flutter::RefCountedDartWrappable< Texture > fml::RefCountedThreadSafe< T > tonic::DartWrappable fml::internal::RefCountedThreadSafeBase

Public Member Functions

 Texture (std::shared_ptr< impeller::Texture > texture)
 
 ~Texture () override
 
std::shared_ptr< impeller::TextureGetTexture ()
 
void SetCoordinateSystem (impeller::TextureCoordinateSystem coordinate_system)
 
bool Overwrite (Context &gpu_context, const tonic::DartByteData &source_bytes, uint32_t mip_level, uint32_t slice)
 
size_t GetBytesPerTexel ()
 
Dart_Handle AsImage () const
 
- Public Member Functions inherited from flutter::RefCountedDartWrappable< Texture >
virtual void RetainDartWrappableReference () const override
 
virtual void ReleaseDartWrappableReference () const override
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< T >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 
- Public Member Functions inherited from tonic::DartWrappable
 DartWrappable ()
 
virtual const DartWrapperInfoGetDartWrapperInfo () const =0
 
Dart_Handle CreateDartWrapper (DartState *dart_state)
 
void AssociateWithDartWrapper (Dart_Handle wrappable)
 
void ClearDartWrapper ()
 
Dart_WeakPersistentHandle dart_wrapper () const
 

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields {
  kPeerIndex ,
  kNumberOfNativeFields
}
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< T >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 
- Protected Member Functions inherited from tonic::DartWrappable
virtual ~DartWrappable ()
 
- Static Protected Member Functions inherited from tonic::DartWrappable
static Dart_PersistentHandle GetTypeForWrapper (tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)
 

Detailed Description

Definition at line 17 of file texture.h.

Constructor & Destructor Documentation

◆ Texture()

flutter::gpu::Texture::Texture ( std::shared_ptr< impeller::Texture texture)
explicit

Definition at line 33 of file texture.cc.

34 : texture_(std::move(texture)) {}
FlTexture * texture

◆ ~Texture()

flutter::gpu::Texture::~Texture ( )
overridedefault

Member Function Documentation

◆ AsImage()

Dart_Handle flutter::gpu::Texture::AsImage ( ) const

Definition at line 153 of file texture.cc.

153 {
154 // DlImageImpeller isn't compiled in builds with Impeller disabled. If
155 // Impeller is disabled, it's impossible to get here anyhow, so just ifdef it
156 // out.
157#if IMPELLER_SUPPORTS_RENDERING
159 auto dl_image = impeller::DlImageImpeller::Make(texture_);
160 image->set_image(dl_image);
161 auto wrapped = image->CreateOuterWrapping();
162 return wrapped;
163#else
164 return Dart_Null();
165#endif
166}
static fml::RefPtr< CanvasImage > Create()
Definition image.h:36
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
FlutterVulkanImage * image

References flutter::CanvasImage::Create(), image, and impeller::DlImageImpeller::Make().

Referenced by InternalFlutterGpu_Texture_AsImage().

◆ GetBytesPerTexel()

size_t flutter::gpu::Texture::GetBytesPerTexel ( )

Definition at line 148 of file texture.cc.

148 {
150 texture_->GetTextureDescriptor().format);
151}
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition formats.h:469

References impeller::BytesPerPixelForPixelFormat().

Referenced by InternalFlutterGpu_Texture_BytesPerTexel().

◆ GetTexture()

std::shared_ptr< impeller::Texture > flutter::gpu::Texture::GetTexture ( )

Definition at line 38 of file texture.cc.

38 {
39 return texture_;
40}

Referenced by InternalFlutterGpu_RenderPass_SetColorAttachment().

◆ Overwrite()

bool flutter::gpu::Texture::Overwrite ( Context gpu_context,
const tonic::DartByteData source_bytes,
uint32_t  mip_level,
uint32_t  slice 
)

Definition at line 91 of file texture.cc.

94 {
95 const uint8_t* data = static_cast<const uint8_t*>(source_bytes.data());
96 const size_t length = source_bytes.length_in_bytes();
97
98 auto& impeller_context = gpu_context.GetContext();
99 auto staging_buffer =
100 impeller_context.GetResourceAllocator()->CreateBufferWithCopy(data,
101 length);
102 if (!staging_buffer) {
103 FML_LOG(ERROR) << "Failed to allocate staging buffer for texture "
104 "overwrite.";
105 return false;
106 }
107
108 // Compute the destination region for the requested mip level. The
109 // BlitPass::AddCopy validation requires the region to fit within the base
110 // texture size, and the actual GPU copy uses this rectangle as the
111 // destination on the chosen mip level. The same `max(1, dim >> level)`
112 // formula is used by `Texture.getMipLevelSizeInBytes` on the Dart side; if
113 // either is updated, both must be kept in sync.
114 const impeller::ISize base_size = texture_->GetSize();
115 const impeller::IRect destination_region = impeller::IRect::MakeXYWH(
116 0, 0, MipDimensionAtLevel(base_size.width, mip_level),
117 MipDimensionAtLevel(base_size.height, mip_level));
118
119 // For the GLES backend, command queue submission just flushes the reactor,
120 // which needs to happen on the raster thread.
121 if (impeller_context.GetBackendType() ==
123 auto dart_state = flutter::UIDartState::Current();
124 auto& task_runners = dart_state->GetTaskRunners();
125 auto context_shared = gpu_context.GetContextShared();
126 task_runners.GetRasterTaskRunner()->PostTask(fml::MakeCopyable(
127 [context_shared, texture = texture_, staging_buffer, length,
128 destination_region, mip_level, slice]() mutable {
129 if (!EncodeAndSubmitOverwrite(*context_shared, texture,
130 staging_buffer, length,
131 destination_region, mip_level, slice)) {
132 FML_LOG(ERROR) << "Failed to encode texture overwrite blit on the "
133 "raster thread.";
134 }
135 context_shared->DisposeThreadLocalCachedResources();
136 }));
137 return true;
138 }
139
140 if (!EncodeAndSubmitOverwrite(impeller_context, texture_, staging_buffer,
141 length, destination_region, mip_level, slice)) {
142 return false;
143 }
144 impeller_context.DisposeThreadLocalCachedResources();
145 return true;
146}
static UIDartState * Current()
const void * data() const
size_t length_in_bytes() const
#define FML_LOG(severity)
Definition logging.h:101
size_t length
static int32_t MipDimensionAtLevel(int32_t base_dimension, uint32_t mip_level)
Definition texture.cc:52
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)
Definition texture.cc:61
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
internal::CopyableLambda< T > MakeCopyable(T lambda)
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
Definition rect.h:136
Type height
Definition size.h:29
Type width
Definition size.h:28

References flutter::UIDartState::Current(), flutter::data, tonic::DartByteData::data(), flutter::gpu::EncodeAndSubmitOverwrite(), FML_LOG, flutter::gpu::Context::GetContext(), flutter::gpu::Context::GetContextShared(), impeller::Context::GetResourceAllocator(), impeller::TSize< T >::height, impeller::Context::kOpenGLES, length, tonic::DartByteData::length_in_bytes(), fml::MakeCopyable(), impeller::TRect< T >::MakeXYWH(), flutter::gpu::MipDimensionAtLevel(), texture, and impeller::TSize< T >::width.

◆ SetCoordinateSystem()

void flutter::gpu::Texture::SetCoordinateSystem ( impeller::TextureCoordinateSystem  coordinate_system)

Definition at line 42 of file texture.cc.

43 {
44 texture_->SetCoordinateSystem(coordinate_system);
45}

Referenced by InternalFlutterGpu_Texture_SetCoordinateSystem().


The documentation for this class was generated from the following files: