Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ios_surface_software.mm
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#import "flutter/shell/platform/darwin/ios/ios_surface_software.h"
6
7#include <QuartzCore/CALayer.h>
8
9#include <memory>
10
11#include "flutter/fml/logging.h"
12#include "flutter/fml/platform/darwin/cf_utils.h"
13#include "flutter/fml/trace_event.h"
14
17
19
20namespace flutter {
21
23 std::shared_ptr<IOSContext> context)
24 : IOSSurface(std::move(context)), layer_(layer) {}
25
27
29 return layer_;
30}
31
33 // Nothing to do here. We don't need an external entity to tell us when our
34 // backing store needs to be updated. Instead, we let the frame tell us its
35 // size so we can update to match. This method was added to work around
36 // Android oddities.
37}
38
39std::unique_ptr<Surface> IOSSurfaceSoftware::CreateGPUSurface(GrDirectContext* gr_context) {
40 if (!IsValid()) {
41 return nullptr;
42 }
43
44 auto surface = std::make_unique<GPUSurfaceSoftware>(this, true /* render to surface */);
45
46 if (!surface->IsValid()) {
47 return nullptr;
48 }
49
50 return surface;
51}
52
54 TRACE_EVENT0("flutter", "IOSSurfaceSoftware::AcquireBackingStore");
55 if (!IsValid()) {
56 return nullptr;
57 }
58
59 if (sk_surface_ != nullptr &&
60 SkISize::Make(sk_surface_->width(), sk_surface_->height()) == size) {
61 // The old and new surface sizes are the same. Nothing to do here.
62 return sk_surface_;
63 }
64
67 sk_surface_ = SkSurfaces::Raster(info, nullptr);
68 return sk_surface_;
69}
70
72 TRACE_EVENT0("flutter", "IOSSurfaceSoftware::PresentBackingStore");
73 if (!IsValid() || backing_store == nullptr) {
74 return false;
75 }
76
77 SkPixmap pixmap;
78 if (!backing_store->peekPixels(&pixmap)) {
79 return false;
80 }
81
82 // Some basic sanity checking.
83 uint64_t expected_pixmap_data_size = pixmap.width() * pixmap.height() * 4;
84
85 const size_t pixmap_size = pixmap.computeByteSize();
86
87 if (expected_pixmap_data_size != pixmap_size) {
88 return false;
89 }
90
91 fml::CFRef<CGColorSpaceRef> colorspace(CGColorSpaceCreateDeviceRGB());
92
93 // Setup the data provider that gives CG a view into the pixmap.
94 fml::CFRef<CGDataProviderRef> pixmap_data_provider(CGDataProviderCreateWithData(
95 nullptr, // info
96 pixmap.addr32(), // data
97 pixmap_size, // size
98 nullptr // release callback
99 ));
100
101 if (!pixmap_data_provider) {
102 return false;
103 }
104
105 // Create the CGImageRef representation on the pixmap.
106 fml::CFRef<CGImageRef> pixmap_image(CGImageCreate(pixmap.width(), // width
107 pixmap.height(), // height
108 8, // bits per component
109 32, // bits per pixel
110 pixmap.rowBytes(), // bytes per row
111 colorspace, // colorspace
112 kCGImageAlphaPremultipliedLast, // bitmap info
113 pixmap_data_provider, // data provider
114 nullptr, // decode array
115 false, // should interpolate
116 kCGRenderingIntentDefault // rendering intent
117 ));
118
119 if (!pixmap_image) {
120 return false;
121 }
122
123 layer_.get().contents = (__bridge id)(static_cast<CGImageRef>(pixmap_image));
124
125 return true;
126}
127
128} // namespace flutter
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
static sk_sp< SkColorSpace > MakeSRGB()
const uint32_t * addr32() const
Definition SkPixmap.h:352
size_t rowBytes() const
Definition SkPixmap.h:145
int width() const
Definition SkPixmap.h:160
size_t computeByteSize() const
Definition SkPixmap.h:231
int height() const
Definition SkPixmap.h:166
int width() const
Definition SkSurface.h:178
int height() const
Definition SkSurface.h:184
IOSSurfaceSoftware(const fml::scoped_nsobject< CALayer > &layer, std::shared_ptr< IOSContext > context)
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 di...
sk_sp< SkSurface > AcquireBackingStore(const SkISize &size) override
Called when the GPU surface needs a new buffer to render a new frame into.
std::unique_ptr< Surface > CreateGPUSurface(GrDirectContext *gr_context=nullptr) override
T get() const __attribute((ns_returns_not_retained))
VkSurfaceKHR surface
Definition main.cc:49
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
Definition ref_ptr.h:256
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)
const uintptr_t id
#define TRACE_EVENT0(category_group, name)