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 ()
 
bool Overwrite (Context &gpu_context, const tonic::DartByteData &source_bytes, uint32_t mip_level, uint32_t slice)
 
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 143 of file texture.cc.

143 {
144 // DlImageImpeller isn't compiled in builds with Impeller disabled. If
145 // Impeller is disabled, it's impossible to get here anyhow, so just ifdef it
146 // out.
147#if IMPELLER_SUPPORTS_RENDERING
149 auto dl_image = impeller::DlImageImpeller::Make(texture_);
150 image->set_image(dl_image);
151 auto wrapped = image->CreateOuterWrapping();
152 return wrapped;
153#else
154 return Dart_Null();
155#endif
156}
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().

◆ GetTexture()

◆ Overwrite()

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

Definition at line 86 of file texture.cc.

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


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