Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Friends | List of all members
impeller::TextureGLES Class Referencefinal

#include <texture_gles.h>

Inheritance diagram for impeller::TextureGLES:
impeller::Texture impeller::BackendCast< TextureGLES, Texture >

Public Types

enum class  Type { kTexture , kTextureMultisampled , kRenderBuffer , kRenderBufferMultisampled }
 
enum class  IsWrapped { kWrapped }
 
enum class  AttachmentType { kColor0 , kDepth , kStencil }
 

Public Member Functions

 TextureGLES (ReactorGLES::Ref reactor, TextureDescriptor desc)
 
 TextureGLES (ReactorGLES::Ref reactor, TextureDescriptor desc, IsWrapped wrapped)
 
 ~TextureGLES () override
 
std::optional< GLuint > GetGLHandle () const
 
bool Bind () const
 
bool GenerateMipmap ()
 
bool SetAsFramebufferAttachment (GLenum target, AttachmentType attachment_type) const
 
Type GetType () const
 
bool IsWrapped () const
 
std::optional< GLuint > GetFBO () const
 
- Public Member Functions inherited from impeller::Texture
virtual ~Texture ()
 
bool SetContents (const uint8_t *contents, size_t length, size_t slice=0, bool is_opaque=false)
 
bool SetContents (std::shared_ptr< const fml::Mapping > mapping, size_t slice=0, bool is_opaque=false)
 
bool IsOpaque () const
 
size_t GetMipCount () const
 
const TextureDescriptorGetTextureDescriptor () const
 
void SetCoordinateSystem (TextureCoordinateSystem coordinate_system)
 
TextureCoordinateSystem GetCoordinateSystem () const
 
bool NeedsMipmapGeneration () const
 

Static Public Member Functions

static std::shared_ptr< TextureGLESWrapFBO (ReactorGLES::Ref reactor, TextureDescriptor desc, GLuint fbo)
 
- Static Public Member Functions inherited from impeller::BackendCast< TextureGLES, Texture >
static TextureGLESCast (Texture &base)
 
static const TextureGLESCast (const Texture &base)
 
static TextureGLESCast (Texture *base)
 
static const TextureGLESCast (const Texture *base)
 

Private Member Functions

void SetLabel (std::string_view label) override
 
bool OnSetContents (const uint8_t *contents, size_t length, size_t slice) override
 
bool OnSetContents (std::shared_ptr< const fml::Mapping > mapping, size_t slice) override
 
bool IsValid () const override
 
ISize GetSize () const override
 
Scalar GetYCoordScale () const override
 

Friends

class AllocatorMTL
 

Additional Inherited Members

- Protected Member Functions inherited from impeller::Texture
 Texture (TextureDescriptor desc)
 
- Protected Attributes inherited from impeller::Texture
bool mipmap_generated_ = false
 

Detailed Description

Definition at line 15 of file texture_gles.h.

Member Enumeration Documentation

◆ AttachmentType

Enumerator
kColor0 
kDepth 
kStencil 

Definition at line 48 of file texture_gles.h.

◆ IsWrapped

Enumerator
kWrapped 

Definition at line 25 of file texture_gles.h.

◆ Type

enum class impeller::TextureGLES::Type
strong
Enumerator
kTexture 
kTextureMultisampled 
kRenderBuffer 
kRenderBufferMultisampled 

Definition at line 18 of file texture_gles.h.

Constructor & Destructor Documentation

◆ TextureGLES() [1/2]

impeller::TextureGLES::TextureGLES ( ReactorGLES::Ref  reactor,
TextureDescriptor  desc 
)

Definition at line 70 of file texture_gles.cc.

71 : TextureGLES(std::move(reactor), desc, false, std::nullopt) {}
TextureGLES(ReactorGLES::Ref reactor, TextureDescriptor desc)

◆ TextureGLES() [2/2]

impeller::TextureGLES::TextureGLES ( ReactorGLES::Ref  reactor,
TextureDescriptor  desc,
IsWrapped  wrapped 
)

Definition at line 73 of file texture_gles.cc.

76 : TextureGLES(std::move(reactor), desc, true, std::nullopt) {}

◆ ~TextureGLES()

impeller::TextureGLES::~TextureGLES ( )
override

Definition at line 114 of file texture_gles.cc.

114 {
115 reactor_->CollectHandle(handle_);
116}

Member Function Documentation

◆ Bind()

bool impeller::TextureGLES::Bind ( ) const

Definition at line 434 of file texture_gles.cc.

434 {
435 auto handle = GetGLHandle();
436 if (!handle.has_value()) {
437 return false;
438 }
439 const auto& gl = reactor_->GetProcTable();
440 switch (type_) {
441 case Type::kTexture:
444 if (!target.has_value()) {
445 VALIDATION_LOG << "Could not bind texture of this type.";
446 return false;
447 }
448 gl.BindTexture(target.value(), handle.value());
449 } break;
452 gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
453 break;
454 }
455 InitializeContentsIfNecessary();
456 return true;
457}
std::optional< GLuint > GetGLHandle() const
const TextureDescriptor & GetTextureDescriptor() const
Definition texture.cc:57
uint32_t * target
constexpr std::optional< GLenum > ToTextureTarget(TextureType type)
#define VALIDATION_LOG
Definition validation.h:73

◆ GenerateMipmap()

bool impeller::TextureGLES::GenerateMipmap ( )

Definition at line 459 of file texture_gles.cc.

459 {
460 if (!IsValid()) {
461 return false;
462 }
463
465 switch (type) {
467 break;
469 VALIDATION_LOG << "Generating mipmaps for multisample textures is not "
470 "supported in the GLES backend.";
471 return false;
473 break;
475 break;
476 }
477
478 if (!Bind()) {
479 return false;
480 }
481
482 auto handle = GetGLHandle();
483 if (!handle.has_value()) {
484 return false;
485 }
486
487 const auto& gl = reactor_->GetProcTable();
488 gl.GenerateMipmap(ToTextureType(type));
489 mipmap_generated_ = true;
490 return true;
491}
bool IsValid() const override
bool mipmap_generated_
Definition texture.h:64
constexpr GLenum ToTextureType(TextureType type)

◆ GetFBO()

std::optional< GLuint > impeller::TextureGLES::GetFBO ( ) const
inline

Definition at line 61 of file texture_gles.h.

61{ return wrapped_fbo_; }

◆ GetGLHandle()

std::optional< GLuint > impeller::TextureGLES::GetGLHandle ( ) const

Definition at line 427 of file texture_gles.cc.

427 {
428 if (!IsValid()) {
429 return std::nullopt;
430 }
431 return reactor_->GetGLHandle(handle_);
432}

◆ GetSize()

ISize impeller::TextureGLES::GetSize ( ) const
overrideprivatevirtual

Implements impeller::Texture.

Definition at line 313 of file texture_gles.cc.

◆ GetType()

TextureGLES::Type impeller::TextureGLES::GetType ( ) const

Definition at line 493 of file texture_gles.cc.

493 {
494 return type_;
495}

◆ GetYCoordScale()

Scalar impeller::TextureGLES::GetYCoordScale ( ) const
overrideprivatevirtual

Reimplemented from impeller::Texture.

Definition at line 555 of file texture_gles.cc.

555 {
556 switch (GetCoordinateSystem()) {
558 return 1.0;
560 return -1.0;
561 }
563}
TextureCoordinateSystem GetCoordinateSystem() const
Definition texture.cc:77
#define FML_UNREACHABLE()
Definition logging.h:109

◆ IsValid()

bool impeller::TextureGLES::IsValid ( ) const
overrideprivatevirtual

Implements impeller::Texture.

Definition at line 119 of file texture_gles.cc.

119 {
120 return is_valid_;
121}

◆ IsWrapped()

bool impeller::TextureGLES::IsWrapped ( ) const
inline

Definition at line 59 of file texture_gles.h.

59{ return is_wrapped_; }

◆ OnSetContents() [1/2]

bool impeller::TextureGLES::OnSetContents ( const uint8_t *  contents,
size_t  length,
size_t  slice 
)
overrideprivatevirtual

Implements impeller::Texture.

Definition at line 199 of file texture_gles.cc.

201 {
202 return OnSetContents(CreateMappingWithCopy(contents, length), slice);
203}
bool OnSetContents(const uint8_t *contents, size_t length, size_t slice) override
size_t length
std::shared_ptr< fml::Mapping > CreateMappingWithCopy(const uint8_t *contents, size_t length)
Definition allocation.cc:83

◆ OnSetContents() [2/2]

bool impeller::TextureGLES::OnSetContents ( std::shared_ptr< const fml::Mapping mapping,
size_t  slice 
)
overrideprivatevirtual

Implements impeller::Texture.

Definition at line 206 of file texture_gles.cc.

207 {
208 if (!mapping) {
209 return false;
210 }
211
212 if (mapping->GetSize() == 0u) {
213 return true;
214 }
215
216 if (mapping->GetMapping() == nullptr) {
217 return false;
218 }
219
220 if (GetType() != Type::kTexture) {
221 VALIDATION_LOG << "Incorrect texture usage flags for setting contents on "
222 "this texture object.";
223 return false;
224 }
225
226 if (is_wrapped_) {
227 VALIDATION_LOG << "Cannot set the contents of a wrapped texture.";
228 return false;
229 }
230
231 const auto& tex_descriptor = GetTextureDescriptor();
232
233 if (tex_descriptor.size.IsEmpty()) {
234 return true;
235 }
236
237 if (!tex_descriptor.IsValid()) {
238 return false;
239 }
240
241 if (mapping->GetSize() < tex_descriptor.GetByteSizeOfBaseMipLevel()) {
242 return false;
243 }
244
245 GLenum texture_type;
246 GLenum texture_target;
247 switch (tex_descriptor.type) {
249 texture_type = GL_TEXTURE_2D;
250 texture_target = GL_TEXTURE_2D;
251 break;
253 VALIDATION_LOG << "Multisample texture uploading is not supported for "
254 "the OpenGLES backend.";
255 return false;
257 texture_type = GL_TEXTURE_CUBE_MAP;
258 texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
259 break;
261 texture_type = GL_TEXTURE_EXTERNAL_OES;
262 texture_target = GL_TEXTURE_EXTERNAL_OES;
263 break;
264 }
265
266 auto data = std::make_shared<TexImage2DData>(tex_descriptor.format,
267 std::move(mapping));
268 if (!data || !data->IsValid()) {
269 VALIDATION_LOG << "Invalid texture format.";
270 return false;
271 }
272
273 ReactorGLES::Operation texture_upload = [handle = handle_, //
274 data, //
275 size = tex_descriptor.size, //
276 texture_type, //
277 texture_target //
278 ](const auto& reactor) {
279 auto gl_handle = reactor.GetGLHandle(handle);
280 if (!gl_handle.has_value()) {
282 << "Texture was collected before it could be uploaded to the GPU.";
283 return;
284 }
285 const auto& gl = reactor.GetProcTable();
286 gl.BindTexture(texture_type, gl_handle.value());
287 const GLvoid* tex_data = nullptr;
288 if (data->data) {
289 tex_data = data->data->GetMapping();
290 }
291
292 {
293 TRACE_EVENT1("impeller", "TexImage2DUpload", "Bytes",
294 std::to_string(data->data->GetSize()).c_str());
295 gl.TexImage2D(texture_target, // target
296 0u, // LOD level
297 data->internal_format, // internal format
298 size.width, // width
299 size.height, // height
300 0u, // border
301 data->external_format, // external format
302 data->type, // type
303 tex_data // data
304 );
305 }
306 };
307
308 contents_initialized_ = reactor_->AddOperation(texture_upload);
309 return contents_initialized_;
310}
std::function< void(const ReactorGLES &reactor)> Operation
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 switches.h:41
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)

◆ SetAsFramebufferAttachment()

bool impeller::TextureGLES::SetAsFramebufferAttachment ( GLenum  target,
AttachmentType  attachment_type 
) const

Definition at line 508 of file texture_gles.cc.

510 {
511 if (!IsValid()) {
512 return false;
513 }
514 InitializeContentsIfNecessary();
515 auto handle = GetGLHandle();
516 if (!handle.has_value()) {
517 return false;
518 }
519 const auto& gl = reactor_->GetProcTable();
520
521 switch (type_) {
522 case Type::kTexture:
523 gl.FramebufferTexture2D(target, // target
524 ToAttachmentType(attachment_type), // attachment
525 GL_TEXTURE_2D, // textarget
526 handle.value(), // texture
527 0 // level
528 );
529 break;
531 gl.FramebufferTexture2DMultisampleEXT(
532 target, // target
533 ToAttachmentType(attachment_type), // attachment
534 GL_TEXTURE_2D, // textarget
535 handle.value(), // texture
536 0, // level
537 4 // samples
538 );
539 break;
542 gl.FramebufferRenderbuffer(
543 target, // target
544 ToAttachmentType(attachment_type), // attachment
545 GL_RENDERBUFFER, // render-buffer target
546 handle.value() // render-buffer
547 );
548 break;
549 }
550
551 return true;
552}
static GLenum ToAttachmentType(TextureGLES::AttachmentType point)

◆ SetLabel()

void impeller::TextureGLES::SetLabel ( std::string_view  label)
overrideprivatevirtual

Implements impeller::Texture.

Definition at line 124 of file texture_gles.cc.

124 {
125 reactor_->SetDebugLabel(handle_, std::string{label.data(), label.size()});
126}

◆ WrapFBO()

std::shared_ptr< TextureGLES > impeller::TextureGLES::WrapFBO ( ReactorGLES::Ref  reactor,
TextureDescriptor  desc,
GLuint  fbo 
)
static

Definition at line 78 of file texture_gles.cc.

80 {
81 return std::shared_ptr<TextureGLES>(
82 new TextureGLES(std::move(reactor), desc, true, fbo));
83}

Friends And Related Symbol Documentation

◆ AllocatorMTL

friend class AllocatorMTL
friend

Definition at line 64 of file texture_gles.h.


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