OLD | NEW |
| (Empty) |
1 // Copyright 2017 The Chromium 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 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
6 #error "This file requires ARC support." | |
7 #endif | |
8 | |
9 #import "remoting/client/ios/app/example_view_controller.h" | |
10 | |
11 #import "remoting/client/display/sys_opengl.h" | |
12 | |
13 #include "base/message_loop/message_loop.h" | |
14 #include "remoting/protocol/frame_stats.h" | |
15 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | |
16 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | |
17 | |
18 @interface ExampleViewController () | |
19 | |
20 // Helper functions dealing with the GL Context. | |
21 - (void)setupGL; | |
22 - (void)tearDownGL; | |
23 | |
24 @end | |
25 | |
26 @implementation ExampleViewController | |
27 | |
28 #pragma mark - UIViewController | |
29 | |
30 - (void)viewDidLoad { | |
31 [super viewDidLoad]; | |
32 _gestures = [[ClientGestures alloc] initWithView:self.view]; | |
33 // TODO(nicholss): For prod code, make sure to check for ES3 support and | |
34 // fall back to ES2 if needed. | |
35 _context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; | |
36 _runtime = new remoting::ios::AppRuntime(); | |
37 static_cast<GLKView*>(self.view).context = _context; | |
38 [self setupGL]; | |
39 } | |
40 | |
41 - (void)viewDidUnload { | |
42 [super viewDidUnload]; | |
43 [self tearDownGL]; | |
44 | |
45 if ([EAGLContext currentContext] == _context) { | |
46 [EAGLContext setCurrentContext:nil]; | |
47 } | |
48 _context = nil; | |
49 } | |
50 | |
51 - (void)setupGL { | |
52 _display_handler = [[GlDisplayHandler alloc] initWithRuntime:_runtime]; | |
53 [_display_handler created]; | |
54 } | |
55 | |
56 - (void)tearDownGL { | |
57 // TODO(nicholss): Implement this in a real application. | |
58 } | |
59 | |
60 - (void)viewWillAppear:(BOOL)animated { | |
61 [super viewWillAppear:animated]; | |
62 } | |
63 | |
64 - (void)viewDidAppear:(BOOL)animated { | |
65 _video_renderer = | |
66 (remoting::SoftwareVideoRenderer*)[_display_handler CreateVideoRenderer] | |
67 .get(); | |
68 } | |
69 | |
70 - (void)viewWillDisappear:(BOOL)animated { | |
71 [super viewWillDisappear:NO]; | |
72 } | |
73 | |
74 - (void)viewDidLayoutSubviews { | |
75 [super viewDidLayoutSubviews]; | |
76 } | |
77 | |
78 #pragma mark - GLKViewDelegate | |
79 | |
80 // In general, avoid expensive work in this function to maximize frame rate. | |
81 - (void)glkView:(GLKView*)view drawInRect:(CGRect)rect { | |
82 if (_display_handler) { | |
83 [_display_handler glkView:view drawInRect:rect]; | |
84 } | |
85 } | |
86 | |
87 @end | |
OLD | NEW |