Flutter Engine
flutter::IOSSurfaceSoftware Class Referencefinal

#include <ios_surface_software.h>

Inheritance diagram for flutter::IOSSurfaceSoftware:
flutter::IOSSurface flutter::GPUSurfaceSoftwareDelegate flutter::GPUSurfaceDelegate

Public Member Functions

 IOSSurfaceSoftware (fml::scoped_nsobject< CALayer > layer, std::shared_ptr< IOSContext > context, FlutterPlatformViewsController *platform_views_controller)
 
 ~IOSSurfaceSoftware () override
 
bool IsValid () const override
 
void UpdateStorageSizeIfNecessary () override
 
std::unique_ptr< SurfaceCreateGPUSurface (GrDirectContext *gr_context=nullptr) override
 
sk_sp< SkSurface > AcquireBackingStore (const SkISize &size) override
 Called when the GPU surface needs a new buffer to render a new frame into. More...
 
bool PresentBackingStore (sk_sp< SkSurface > backing_store) override
 Called by the platform when a frame has been rendered into the backing store and the platform must display it on-screen. More...
 
ExternalViewEmbedderGetExternalViewEmbedder () override
 Gets the view embedder that controls how the Flutter layer hierarchy split into multiple chunks should be composited back on-screen. This field is optional and the Flutter rasterizer will render into a single on-screen surface if this call returns a null external view embedder. This happens on the GPU thread. More...
 
- Public Member Functions inherited from flutter::IOSSurface
std::shared_ptr< IOSContextGetContext () const
 
std::shared_ptr< IOSExternalViewEmbedderGetSurfaceExternalViewEmbedder () const
 
virtual ~IOSSurface ()
 
- Public Member Functions inherited from flutter::GPUSurfaceSoftwareDelegate
 ~GPUSurfaceSoftwareDelegate () override
 
- Public Member Functions inherited from flutter::GPUSurfaceDelegate
virtual ~GPUSurfaceDelegate ()
 

Additional Inherited Members

- Static Public Member Functions inherited from flutter::IOSSurface
static std::unique_ptr< IOSSurfaceCreate (std::shared_ptr< IOSContext > context, fml::scoped_nsobject< CALayer > layer, FlutterPlatformViewsController *platform_views_controller)
 
- Protected Member Functions inherited from flutter::IOSSurface
 IOSSurface (std::shared_ptr< IOSContext > ios_context, FlutterPlatformViewsController *platform_views_controller)
 

Detailed Description

Definition at line 19 of file ios_surface_software.h.

Constructor & Destructor Documentation

◆ IOSSurfaceSoftware()

flutter::IOSSurfaceSoftware::IOSSurfaceSoftware ( fml::scoped_nsobject< CALayer >  layer,
std::shared_ptr< IOSContext context,
FlutterPlatformViewsController platform_views_controller 
)

Definition at line 18 of file ios_surface_software.mm.

References ~IOSSurfaceSoftware().

21  : IOSSurface(std::move(context), platform_views_controller), layer_(std::move(layer)) {}
IOSSurface(std::shared_ptr< IOSContext > ios_context, FlutterPlatformViewsController *platform_views_controller)
Definition: ios_surface.mm:54

◆ ~IOSSurfaceSoftware()

flutter::IOSSurfaceSoftware::~IOSSurfaceSoftware ( )
overridedefault

Referenced by IOSSurfaceSoftware().

Member Function Documentation

◆ AcquireBackingStore()

sk_sp< SkSurface > flutter::IOSSurfaceSoftware::AcquireBackingStore ( const SkISize &  size)
overridevirtual

Called when the GPU surface needs a new buffer to render a new frame into.

Parameters
[in]sizeThe size of the frame.
Returns
A raster surface returned by the platform.

Implements flutter::GPUSurfaceSoftwareDelegate.

Definition at line 50 of file ios_surface_software.mm.

References IsValid(), and TRACE_EVENT0.

50  {
51  TRACE_EVENT0("flutter", "IOSSurfaceSoftware::AcquireBackingStore");
52  if (!IsValid()) {
53  return nullptr;
54  }
55 
56  if (sk_surface_ != nullptr &&
57  SkISize::Make(sk_surface_->width(), sk_surface_->height()) == size) {
58  // The old and new surface sizes are the same. Nothing to do here.
59  return sk_surface_;
60  }
61 
62  SkImageInfo info = SkImageInfo::MakeN32(size.fWidth, size.fHeight, kPremul_SkAlphaType,
63  SkColorSpace::MakeSRGB());
64  sk_surface_ = SkSurface::MakeRaster(info, nullptr);
65  return sk_surface_;
66 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13

◆ CreateGPUSurface()

std::unique_ptr< Surface > flutter::IOSSurfaceSoftware::CreateGPUSurface ( GrDirectContext *  gr_context = nullptr)
overridevirtual

Implements flutter::IOSSurface.

Definition at line 36 of file ios_surface_software.mm.

References IsValid().

36  {
37  if (!IsValid()) {
38  return nullptr;
39  }
40 
41  auto surface = std::make_unique<GPUSurfaceSoftware>(this, true /* render to surface */);
42 
43  if (!surface->IsValid()) {
44  return nullptr;
45  }
46 
47  return surface;
48 }

◆ GetExternalViewEmbedder()

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

Gets the view embedder that controls how the Flutter layer hierarchy split into multiple chunks should be composited back on-screen. This field is optional and the Flutter rasterizer will render into a single on-screen surface if this call returns a null external view embedder. This happens on the GPU thread.

Returns
The external view embedder, or, null if Flutter is rendering into a single on-screen surface.

Reimplemented from flutter::GPUSurfaceSoftwareDelegate.

Definition at line 126 of file ios_surface_software.mm.

References flutter::IOSSurface::GetSurfaceExternalViewEmbedder().

126  {
127  return GetSurfaceExternalViewEmbedder().get();
128 }
std::shared_ptr< IOSExternalViewEmbedder > GetSurfaceExternalViewEmbedder() const
Definition: ios_surface.mm:68

◆ IsValid()

bool flutter::IOSSurfaceSoftware::IsValid ( ) const
overridevirtual

Implements flutter::IOSSurface.

Definition at line 25 of file ios_surface_software.mm.

Referenced by AcquireBackingStore(), CreateGPUSurface(), and PresentBackingStore().

25  {
26  return layer_;
27 }

◆ PresentBackingStore()

bool flutter::IOSSurfaceSoftware::PresentBackingStore ( sk_sp< SkSurface >  backing_store)
overridevirtual

Called by the platform when a frame has been rendered into the backing store and the platform must display it on-screen.

Parameters
[in]backing_storeThe software backing store to present.
Returns
Returns if the platform could present the backing store onto the screen.

Implements flutter::GPUSurfaceSoftwareDelegate.

Definition at line 68 of file ios_surface_software.mm.

References fml::scoped_nsprotocol< NST >::get(), IsValid(), and TRACE_EVENT0.

68  {
69  TRACE_EVENT0("flutter", "IOSSurfaceSoftware::PresentBackingStore");
70  if (!IsValid() || backing_store == nullptr) {
71  return false;
72  }
73 
74  SkPixmap pixmap;
75  if (!backing_store->peekPixels(&pixmap)) {
76  return false;
77  }
78 
79  // Some basic sanity checking.
80  uint64_t expected_pixmap_data_size = pixmap.width() * pixmap.height() * 4;
81 
82  const size_t pixmap_size = pixmap.computeByteSize();
83 
84  if (expected_pixmap_data_size != pixmap_size) {
85  return false;
86  }
87 
88  fml::CFRef<CGColorSpaceRef> colorspace(CGColorSpaceCreateDeviceRGB());
89 
90  // Setup the data provider that gives CG a view into the pixmap.
91  fml::CFRef<CGDataProviderRef> pixmap_data_provider(CGDataProviderCreateWithData(
92  nullptr, // info
93  pixmap.addr32(), // data
94  pixmap_size, // size
95  nullptr // release callback
96  ));
97 
98  if (!pixmap_data_provider) {
99  return false;
100  }
101 
102  // Create the CGImageRef representation on the pixmap.
103  fml::CFRef<CGImageRef> pixmap_image(CGImageCreate(pixmap.width(), // width
104  pixmap.height(), // height
105  8, // bits per component
106  32, // bits per pixel
107  pixmap.rowBytes(), // bytes per row
108  colorspace, // colorspace
109  kCGImageAlphaPremultipliedLast, // bitmap info
110  pixmap_data_provider, // data provider
111  nullptr, // decode array
112  false, // should interpolate
113  kCGRenderingIntentDefault // rendering intent
114  ));
115 
116  if (!pixmap_image) {
117  return false;
118  }
119 
120  layer_.get().contents = reinterpret_cast<id>(static_cast<CGImageRef>(pixmap_image));
121 
122  return true;
123 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75

◆ UpdateStorageSizeIfNecessary()

void flutter::IOSSurfaceSoftware::UpdateStorageSizeIfNecessary ( )
overridevirtual

Implements flutter::IOSSurface.

Definition at line 29 of file ios_surface_software.mm.

29  {
30  // Nothing to do here. We don't need an external entity to tell us when our
31  // backing store needs to be updated. Instead, we let the frame tell us its
32  // size so we can update to match. This method was added to work around
33  // Android oddities.
34 }

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