Flutter Engine
The Flutter Engine
third_party
skia
tools
sk_app
ios
main_ios.mm
Go to the documentation of this file.
1
/*
2
* Copyright 2017 Google Inc.
3
*
4
* Use of this source code is governed by a BSD-style license that can be
5
* found in the LICENSE file.
6
*/
7
8
#include "
include/core/SkTypes.h
"
9
#include "
tools/sk_app/Application.h
"
10
#include "
tools/sk_app/ios/Window_ios.h
"
11
12
#import <QuartzCore/QuartzCore.h>
13
#import <UIKit/UIKit.h>
14
15
#if __has_feature(objc_arc)
16
#error "File should not be compiled with ARC."
17
#endif
18
19
namespace
{
20
21
static
int
gArgc;
22
static
char
** gArgv;
23
24
}
25
26
////////////////////////////////////////////////////////////////////
27
28
@interface
AppDelegate
: UIResponder<UIApplicationDelegate>
29
30
@end
31
32
@implementation
AppDelegate
{
33
CADisplayLink* fDisplayLink;
// Owned by the run loop.
34
std::unique_ptr<sk_app::Application>
fApp
;
35
}
36
37
#pragma mark - UIApplicationDelegate
38
39
- (void)applicationWillResignActive:(UIApplication *)sender {
40
sk_app::Window_ios
* mainWindow =
sk_app::Window_ios::MainWindow
();
41
if
(mainWindow) {
42
mainWindow->
onActivate
(
false
);
43
}
44
}
45
46
- (void)applicationDidBecomeActive:(UIApplication *)sender {
47
sk_app::Window_ios
* mainWindow =
sk_app::Window_ios::MainWindow
();
48
if
(mainWindow) {
49
mainWindow->
onActivate
(
true
);
50
}
51
}
52
53
- (void)applicationWillTerminate:(UIApplication *)sender {
54
// Display link retains us, so we break the cycle now.
55
// Note: dealloc is never called.
56
[fDisplayLink invalidate];
57
fDisplayLink = nil;
58
fApp
.reset();
59
}
60
61
- (
BOOL
)application:(UIApplication *)application
62
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
63
fApp
= std::unique_ptr<sk_app::Application>(
sk_app::Application::Create
(gArgc, gArgv,
nullptr
));
64
65
auto
mainWindow =
sk_app::Window_ios::MainWindow
();
66
mainWindow->
onActivate
(application.applicationState == UIApplicationStateActive);
67
68
fDisplayLink = [CADisplayLink displayLinkWithTarget:self
69
selector:@selector(displayLinkFired)];
70
[fDisplayLink addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
71
72
return
YES;
73
}
74
75
- (void)displayLinkFired {
76
// TODO: Hook into CAMetalLayer's drawing event loop or our own run loop observer.
77
// Need to handle animated slides/redraw mode, so we need something that will wake up the
78
// run loop.
79
sk_app::Window_ios::PaintWindow
();
80
81
fApp
->onIdle();
82
}
83
84
@end
85
86
///////////////////////////////////////////////////////////////////
87
88
int
main
(
int
argc,
char
**
argv
) {
89
gArgc = argc;
90
gArgv =
argv
;
91
return
UIApplicationMain(argc,
argv
, nil,
@"AppDelegate"
);
92
}
Application.h
SkTypes.h
Window_ios.h
sk_app::Application::Create
static Application * Create(int argc, char **argv, void *platformData)
Definition:
editor_application.cpp:447
sk_app::Window_ios
Definition:
Window_ios.h:19
sk_app::Window_ios::MainWindow
static Window_ios * MainWindow()
Definition:
Window_ios.h:39
sk_app::Window_ios::PaintWindow
static void PaintWindow()
Definition:
Window_ios.mm:113
sk_app::Window::onActivate
void onActivate(bool isActive)
Definition:
Window.cpp:116
AppDelegate
Definition:
AppDelegate.h:10
argv
char ** argv
Definition:
library.h:9
main
int main(int argc, char **argv)
Definition:
main_ios.mm:88
fApp
std::unique_ptr< sk_app::Application > fApp
Definition:
main_ios.mm:34
BOOL
int BOOL
Definition:
windows_types.h:37
Generated on Sun Jun 23 2024 21:56:50 for Flutter Engine by
1.9.4