Flutter Engine
flutter::IOSSurfaceSoftware Class Referencefinal

#include <ios_surface_software.h>

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

Public Member Functions

 IOSSurfaceSoftware (fml::scoped_nsobject< CALayer > layer, std::shared_ptr< IOSContext > context)
 
 ~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...
 
- Public Member Functions inherited from flutter::IOSSurface
std::shared_ptr< IOSContextGetContext () const
 
virtual ~IOSSurface ()
 
- Public Member Functions inherited from flutter::GPUSurfaceSoftwareDelegate
 ~GPUSurfaceSoftwareDelegate ()
 

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)
 
- Protected Member Functions inherited from flutter::IOSSurface
 IOSSurface (std::shared_ptr< IOSContext > ios_context)
 

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 
)

Definition at line 18 of file ios_surface_software.mm.

References ~IOSSurfaceSoftware().

20  : IOSSurface(std::move(context)), layer_(std::move(layer)) {}
IOSSurface(std::shared_ptr< IOSContext > ios_context)
Definition: ios_surface.mm:48

◆ ~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 49 of file ios_surface_software.mm.

References IsValid(), and TRACE_EVENT0.

49  {
50  TRACE_EVENT0("flutter", "IOSSurfaceSoftware::AcquireBackingStore");
51  if (!IsValid()) {
52  return nullptr;
53  }
54 
55  if (sk_surface_ != nullptr &&
56  SkISize::Make(sk_surface_->width(), sk_surface_->height()) == size) {
57  // The old and new surface sizes are the same. Nothing to do here.
58  return sk_surface_;
59  }
60 
61  SkImageInfo info = SkImageInfo::MakeN32(size.fWidth, size.fHeight, kPremul_SkAlphaType,
62  SkColorSpace::MakeSRGB());
63  sk_surface_ = SkSurface::MakeRaster(info, nullptr);
64  return sk_surface_;
65 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
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 35 of file ios_surface_software.mm.

References IsValid().

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

◆ IsValid()

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

Implements flutter::IOSSurface.

Definition at line 24 of file ios_surface_software.mm.

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

24  {
25  return layer_;
26 }

◆ 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 67 of file ios_surface_software.mm.

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

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

◆ UpdateStorageSizeIfNecessary()

void flutter::IOSSurfaceSoftware::UpdateStorageSizeIfNecessary ( )
overridevirtual

Implements flutter::IOSSurface.

Definition at line 28 of file ios_surface_software.mm.

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

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