2019-08-29 18:59:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "tools/sk_app/Application.h"
|
|
|
|
#include "tools/sk_app/ios/Window_ios.h"
|
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
#import <QuartzCore/QuartzCore.h>
|
2019-08-29 18:59:17 +00:00
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
#if __has_feature(objc_arc)
|
|
|
|
#error "File should not be compiled with ARC."
|
|
|
|
#endif
|
2019-08-29 18:59:17 +00:00
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
namespace {
|
2019-08-29 18:59:17 +00:00
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
static int gArgc;
|
|
|
|
static char** gArgv;
|
2019-08-29 18:59:17 +00:00
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
}
|
2019-08-29 18:59:17 +00:00
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
2019-08-29 18:59:17 +00:00
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
@interface AppDelegate : UIResponder<UIApplicationDelegate>
|
2019-08-29 18:59:17 +00:00
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
@end
|
2019-08-29 18:59:17 +00:00
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
@implementation AppDelegate {
|
|
|
|
CADisplayLink* fDisplayLink; // Owned by the run loop.
|
|
|
|
std::unique_ptr<sk_app::Application> fApp;
|
2019-08-29 18:59:17 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
#pragma mark - UIApplicationDelegate
|
|
|
|
|
2020-11-16 16:06:58 +00:00
|
|
|
- (void)applicationWillResignActive:(UIApplication *)sender {
|
|
|
|
sk_app::Window_ios* mainWindow = sk_app::Window_ios::MainWindow();
|
|
|
|
if (mainWindow) {
|
|
|
|
mainWindow->onActivate(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationDidBecomeActive:(UIApplication *)sender {
|
|
|
|
sk_app::Window_ios* mainWindow = sk_app::Window_ios::MainWindow();
|
|
|
|
if (mainWindow) {
|
|
|
|
mainWindow->onActivate(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
- (void)applicationWillTerminate:(UIApplication *)sender {
|
|
|
|
// Display link retains us, so we break the cycle now.
|
|
|
|
// Note: dealloc is never called.
|
|
|
|
[fDisplayLink invalidate];
|
|
|
|
fDisplayLink = nil;
|
|
|
|
fApp.reset();
|
|
|
|
}
|
2019-11-04 20:02:00 +00:00
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
- (BOOL)application:(UIApplication *)application
|
|
|
|
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
|
|
|
fApp = std::unique_ptr<sk_app::Application>(sk_app::Application::Create(gArgc, gArgv, nullptr));
|
2019-08-29 18:59:17 +00:00
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
auto mainWindow = sk_app::Window_ios::MainWindow();
|
|
|
|
mainWindow->onActivate(application.applicationState == UIApplicationStateActive);
|
2019-08-29 18:59:17 +00:00
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
fDisplayLink = [CADisplayLink displayLinkWithTarget:self
|
|
|
|
selector:@selector(displayLinkFired)];
|
|
|
|
[fDisplayLink addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
|
2019-08-29 18:59:17 +00:00
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
return YES;
|
2019-08-29 18:59:17 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
- (void)displayLinkFired {
|
|
|
|
// TODO: Hook into CAMetalLayer's drawing event loop or our own run loop observer.
|
|
|
|
// Need to handle animated slides/redraw mode, so we need something that will wake up the
|
|
|
|
// run loop.
|
|
|
|
sk_app::Window_ios::PaintWindow();
|
2019-08-29 18:59:17 +00:00
|
|
|
|
2020-11-20 19:21:23 +00:00
|
|
|
fApp->onIdle();
|
2019-08-29 18:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2020-11-20 19:21:23 +00:00
|
|
|
gArgc = argc;
|
|
|
|
gArgv = argv;
|
|
|
|
return UIApplicationMain(argc, argv, nil, @"AppDelegate");
|
2019-08-29 18:59:17 +00:00
|
|
|
}
|