Flutter Engine
The Flutter Engine
SkiaUIContext.mm
Go to the documentation of this file.
1// Copyright 2020 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3
5
10#include "src/base/SkTime.h"
11
12#import <UIKit/UIKit.h>
13
14// A UIView that uses a CPU-backed SkSurface to draw.
15@interface SkiaUIView : UIView
16 @property (strong) SkiaViewController* controller;
17
18 // Override of the UIView interface.
19 - (void)drawRect:(CGRect)rect;
20@end
21
22@implementation SkiaUIView {
23 SkBitmap fBackBuffer;
24}
25
26- (void)drawRect:(CGRect)rect {
28 static constexpr double kFrameRate = 1.0 / 30.0;
29 double next = [viewController isPaused] ? 0 : kFrameRate + SkTime::GetNSecs() * 1e-9;
30 [super drawRect:rect];
31 CGSize size = [self bounds].size;
32 SkISize iSize = {(int)size.width, (int)size.height};
33 if (fBackBuffer.drawsNothing() || iSize != fBackBuffer.dimensions()) {
34 fBackBuffer.allocN32Pixels(iSize.fWidth, iSize.fHeight);
35 }
36 fBackBuffer.eraseColor(SK_ColorTRANSPARENT);
37 {
38 SkCanvas canvas(fBackBuffer);
39 [viewController draw:rect toCanvas:&canvas atSize:size];
40 }
41 SkCGDrawBitmap(UIGraphicsGetCurrentContext(), fBackBuffer, 0, 0);
42 if (next) {
43 [NSTimer scheduledTimerWithTimeInterval:std::max(0.0, next - SkTime::GetNSecs() * 1e-9)
44 target:self
45 selector:@selector(setNeedsDisplay)
46 userInfo:nil
47 repeats:NO];
48 }
49}
50@end
51
53 - (UIView*) makeViewWithController:(SkiaViewController*)vc withFrame:(CGRect)frame;
54 - (SkiaViewController*) getViewController:(UIView*)view;
55@end
56
57@implementation SkiaUIContext
58- (UIView*) makeViewWithController:(SkiaViewController*)vc withFrame:(CGRect)frame {
59 SkiaUIView* skiaView = [[SkiaUIView alloc] initWithFrame:frame];
60 [skiaView setController:vc];
61 return skiaView;
62}
63- (SkiaViewController*) getViewController:(UIView*)view {
64 return [view isKindOfClass:[SkiaUIView class]] ? [(SkiaUIView*)view controller] : nil;
65}
66@end
67
68SkiaContext* MakeSkiaUIContext() { return [[SkiaUIContext alloc] init]; }
static float next(float f)
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
SkiaContext * MakeSkiaUIContext()
SkiaViewController * controller
void draw:toCanvas:atSize:(CGRect rect,[toCanvas] SkCanvas *canvas,[atSize] CGSize size)
FlutterViewController * viewController
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
double GetNSecs()
Definition: SkTime.cpp:17
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: SkSize.h:16
int32_t fHeight
Definition: SkSize.h:18
int32_t fWidth
Definition: SkSize.h:17