7 #include <QuartzCore/CALayer.h>
11 #include "flutter/fml/logging.h"
12 #include "flutter/fml/platform/darwin/cf_utils.h"
13 #include "flutter/fml/trace_event.h"
15 #include "third_party/skia/include/core/SkSurface.h"
16 #include "third_party/skia/include/utils/mac/SkCGUtils.h"
21 std::shared_ptr<IOSContext> context)
22 :
IOSSurface(std::move(context)), layer_(layer) {}
42 auto surface = std::make_unique<GPUSurfaceSoftware>(
this,
true );
44 if (!surface->IsValid()) {
52 TRACE_EVENT0(
"flutter",
"IOSSurfaceSoftware::AcquireBackingStore");
57 if (sk_surface_ !=
nullptr &&
58 SkISize::Make(sk_surface_->width(), sk_surface_->height()) == size) {
63 SkImageInfo info = SkImageInfo::MakeN32(size.fWidth, size.fHeight, kPremul_SkAlphaType,
64 SkColorSpace::MakeSRGB());
65 sk_surface_ = SkSurfaces::Raster(info,
nullptr);
70 TRACE_EVENT0(
"flutter",
"IOSSurfaceSoftware::PresentBackingStore");
71 if (!
IsValid() || backing_store ==
nullptr) {
76 if (!backing_store->peekPixels(&pixmap)) {
81 uint64_t expected_pixmap_data_size = pixmap.width() * pixmap.height() * 4;
83 const size_t pixmap_size = pixmap.computeByteSize();
85 if (expected_pixmap_data_size != pixmap_size) {
89 fml::CFRef<CGColorSpaceRef> colorspace(CGColorSpaceCreateDeviceRGB());
92 fml::CFRef<CGDataProviderRef> pixmap_data_provider(CGDataProviderCreateWithData(
99 if (!pixmap_data_provider) {
104 fml::CFRef<CGImageRef> pixmap_image(CGImageCreate(pixmap.width(),
110 kCGImageAlphaPremultipliedLast,
111 pixmap_data_provider,
114 kCGRenderingIntentDefault
121 layer_.get().contents =
reinterpret_cast<id>(
static_cast<CGImageRef
>(pixmap_image));