Flutter iOS Embedder
flutter::IOSSurfaceSoftware Class Referencefinal

#include <ios_surface_software.h>

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

Public Member Functions

 IOSSurfaceSoftware (const fml::scoped_nsobject< CALayer > &layer, std::shared_ptr< IOSContext > context)
 
 ~IOSSurfaceSoftware () override
 
bool IsValid () const override
 
void UpdateStorageSizeIfNecessary () override
 
std::unique_ptr< Surface > CreateGPUSurface (GrDirectContext *gr_context=nullptr) override
 
sk_sp< SkSurface > AcquireBackingStore (const SkISize &size) override
 
bool PresentBackingStore (sk_sp< SkSurface > backing_store) override
 
- Public Member Functions inherited from flutter::IOSSurface
std::shared_ptr< IOSContextGetContext () const
 
virtual ~IOSSurface ()
 

Additional Inherited Members

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

Detailed Description

Definition at line 21 of file ios_surface_software.h.

Constructor & Destructor Documentation

◆ IOSSurfaceSoftware()

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

Definition at line 20 of file ios_surface_software.mm.

22  : IOSSurface(std::move(context)), layer_(layer) {}

◆ ~IOSSurfaceSoftware()

flutter::IOSSurfaceSoftware::~IOSSurfaceSoftware ( )
overridedefault

Member Function Documentation

◆ AcquireBackingStore()

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

Definition at line 51 of file ios_surface_software.mm.

51  {
52  TRACE_EVENT0("flutter", "IOSSurfaceSoftware::AcquireBackingStore");
53  if (!IsValid()) {
54  return nullptr;
55  }
56 
57  if (sk_surface_ != nullptr &&
58  SkISize::Make(sk_surface_->width(), sk_surface_->height()) == size) {
59  // The old and new surface sizes are the same. Nothing to do here.
60  return sk_surface_;
61  }
62 
63  SkImageInfo info = SkImageInfo::MakeN32(size.fWidth, size.fHeight, kPremul_SkAlphaType,
64  SkColorSpace::MakeSRGB());
65  sk_surface_ = SkSurfaces::Raster(info, nullptr);
66  return sk_surface_;
67 }

References IsValid().

◆ CreateGPUSurface()

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

Implements flutter::IOSSurface.

Definition at line 37 of file ios_surface_software.mm.

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

References IsValid().

◆ IsValid()

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

Implements flutter::IOSSurface.

Definition at line 26 of file ios_surface_software.mm.

26  {
27  return layer_;
28 }

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

◆ PresentBackingStore()

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

Definition at line 69 of file ios_surface_software.mm.

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

References IsValid().

◆ UpdateStorageSizeIfNecessary()

void flutter::IOSSurfaceSoftware::UpdateStorageSizeIfNecessary ( )
overridevirtual

Implements flutter::IOSSurface.

Definition at line 30 of file ios_surface_software.mm.

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

The documentation for this class was generated from the following files:
flutter::IOSSurfaceSoftware::IsValid
bool IsValid() const override
Definition: ios_surface_software.mm:26
flutter::IOSSurface::IOSSurface
IOSSurface(std::shared_ptr< IOSContext > ios_context)
Definition: ios_surface.mm:50