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"
23 std::shared_ptr<IOSContext> context)
24 :
IOSSurface(std::move(context)), layer_(layer) {}
44 auto surface = std::make_unique<GPUSurfaceSoftware>(
this,
true );
46 if (!surface->IsValid()) {
54 TRACE_EVENT0(
"flutter",
"IOSSurfaceSoftware::AcquireBackingStore");
59 if (sk_surface_ !=
nullptr &&
60 SkISize::Make(sk_surface_->width(), sk_surface_->height()) == size) {
65 SkImageInfo info = SkImageInfo::MakeN32(size.fWidth, size.fHeight, kPremul_SkAlphaType,
66 SkColorSpace::MakeSRGB());
67 sk_surface_ = SkSurfaces::Raster(info,
nullptr);
72 TRACE_EVENT0(
"flutter",
"IOSSurfaceSoftware::PresentBackingStore");
73 if (!
IsValid() || backing_store ==
nullptr) {
78 if (!backing_store->peekPixels(&pixmap)) {
83 uint64_t expected_pixmap_data_size = pixmap.width() * pixmap.height() * 4;
85 const size_t pixmap_size = pixmap.computeByteSize();
87 if (expected_pixmap_data_size != pixmap_size) {
91 fml::CFRef<CGColorSpaceRef> colorspace(CGColorSpaceCreateDeviceRGB());
94 fml::CFRef<CGDataProviderRef> pixmap_data_provider(CGDataProviderCreateWithData(
101 if (!pixmap_data_provider) {
106 fml::CFRef<CGImageRef> pixmap_image(CGImageCreate(pixmap.width(),
112 kCGImageAlphaPremultipliedLast,
113 pixmap_data_provider,
116 kCGRenderingIntentDefault
123 layer_.get().contents = (__bridge id)(
static_cast<CGImageRef
>(pixmap_image));