Flutter Engine
flutter::GPUSurfaceSoftware Class Reference

#include <gpu_surface_software.h>

Inheritance diagram for flutter::GPUSurfaceSoftware:
flutter::Surface

Public Member Functions

 GPUSurfaceSoftware (GPUSurfaceSoftwareDelegate *delegate, bool render_to_surface)
 
 ~GPUSurfaceSoftware () override
 
bool IsValid () override
 
std::unique_ptr< SurfaceFrameAcquireFrame (const SkISize &size) override
 
SkMatrix GetRootTransformation () const override
 
GrDirectContext * GetContext () override
 
flutter::ExternalViewEmbedderGetExternalViewEmbedder () override
 
- Public Member Functions inherited from flutter::Surface
 Surface ()
 
virtual ~Surface ()
 
virtual std::unique_ptr< GLContextResultMakeRenderContextCurrent ()
 
virtual bool ClearRenderContext ()
 

Detailed Description

Definition at line 15 of file gpu_surface_software.h.

Constructor & Destructor Documentation

◆ GPUSurfaceSoftware()

flutter::GPUSurfaceSoftware::GPUSurfaceSoftware ( GPUSurfaceSoftwareDelegate delegate,
bool  render_to_surface 
)

Definition at line 12 of file gpu_surface_software.cc.

References ~GPUSurfaceSoftware().

14  : delegate_(delegate),
15  render_to_surface_(render_to_surface),
16  weak_factory_(this) {}

◆ ~GPUSurfaceSoftware()

flutter::GPUSurfaceSoftware::~GPUSurfaceSoftware ( )
overridedefault

Referenced by GPUSurfaceSoftware().

Member Function Documentation

◆ AcquireFrame()

std::unique_ptr< SurfaceFrame > flutter::GPUSurfaceSoftware::AcquireFrame ( const SkISize &  size)
overridevirtual

Implements flutter::Surface.

Definition at line 26 of file gpu_surface_software.cc.

References flutter::GPUSurfaceSoftwareDelegate::AcquireBackingStore(), IsValid(), fml::size(), and flutter::SurfaceFrame::SkiaSurface().

27  {
28  // TODO(38466): Refactor GPU surface APIs take into account the fact that an
29  // external view embedder may want to render to the root surface.
30  if (!render_to_surface_) {
31  return std::make_unique<SurfaceFrame>(
32  nullptr, true, [](const SurfaceFrame& surface_frame, SkCanvas* canvas) {
33  return true;
34  });
35  }
36 
37  if (!IsValid()) {
38  return nullptr;
39  }
40 
41  const auto size = SkISize::Make(logical_size.width(), logical_size.height());
42 
43  sk_sp<SkSurface> backing_store = delegate_->AcquireBackingStore(size);
44 
45  if (backing_store == nullptr) {
46  return nullptr;
47  }
48 
49  if (size != SkISize::Make(backing_store->width(), backing_store->height())) {
50  return nullptr;
51  }
52 
53  // If the surface has been scaled, we need to apply the inverse scaling to the
54  // underlying canvas so that coordinates are mapped to the same spot
55  // irrespective of surface scaling.
56  SkCanvas* canvas = backing_store->getCanvas();
57  canvas->resetMatrix();
58 
60  [self = weak_factory_.GetWeakPtr()](const SurfaceFrame& surface_frame,
61  SkCanvas* canvas) -> bool {
62  // If the surface itself went away, there is nothing more to do.
63  if (!self || !self->IsValid() || canvas == nullptr) {
64  return false;
65  }
66 
67  canvas->flush();
68 
69  return self->delegate_->PresentBackingStore(surface_frame.SkiaSurface());
70  };
71 
72  return std::make_unique<SurfaceFrame>(backing_store, true, on_submit);
73 }
std::function< bool(const SurfaceFrame &surface_frame, SkCanvas *canvas)> SubmitCallback
Definition: surface_frame.h:22
virtual sk_sp< SkSurface > AcquireBackingStore(const SkISize &size)=0
Called when the GPU surface needs a new buffer to render a new frame into.
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13

◆ GetContext()

GrDirectContext * flutter::GPUSurfaceSoftware::GetContext ( )
overridevirtual

Implements flutter::Surface.

Definition at line 85 of file gpu_surface_software.cc.

85  {
86  // There is no GrContext associated with a software surface.
87  return nullptr;
88 }

◆ GetExternalViewEmbedder()

flutter::ExternalViewEmbedder * flutter::GPUSurfaceSoftware::GetExternalViewEmbedder ( )
overridevirtual

Reimplemented from flutter::Surface.

Definition at line 91 of file gpu_surface_software.cc.

References flutter::GPUSurfaceSoftwareDelegate::GetExternalViewEmbedder().

91  {
92  return delegate_->GetExternalViewEmbedder();
93 }
ExternalViewEmbedder * GetExternalViewEmbedder() override
Gets the view embedder that controls how the Flutter layer hierarchy split into multiple chunks shoul...

◆ GetRootTransformation()

SkMatrix flutter::GPUSurfaceSoftware::GetRootTransformation ( ) const
overridevirtual

Implements flutter::Surface.

Definition at line 76 of file gpu_surface_software.cc.

76  {
77  // This backend does not currently support root surface transformations. Just
78  // return identity.
79  SkMatrix matrix;
80  matrix.reset();
81  return matrix;
82 }

◆ IsValid()

bool flutter::GPUSurfaceSoftware::IsValid ( )
overridevirtual

Implements flutter::Surface.

Definition at line 21 of file gpu_surface_software.cc.

Referenced by AcquireFrame().

21  {
22  return delegate_ != nullptr;
23 }

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