OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if !defined(__has_feature) || !__has_feature(objc_arc) | 5 #if !defined(__has_feature) || !__has_feature(objc_arc) |
6 #error "This file requires ARC support." | 6 #error "This file requires ARC support." |
7 #endif | 7 #endif |
8 | 8 |
9 #import "remoting/client/ios/example_view_controller.h" | 9 #import "remoting/client/ios/app/example_view_controller.h" |
10 | 10 |
11 #import "remoting/client/display/sys_opengl.h" | 11 #import "remoting/client/display/sys_opengl.h" |
12 | 12 |
13 @interface ExampleViewController() | 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 () |
14 | 19 |
15 // Helper functions dealing with the GL Context. | 20 // Helper functions dealing with the GL Context. |
16 - (void)setupGL; | 21 - (void)setupGL; |
17 - (void)tearDownGL; | 22 - (void)tearDownGL; |
18 | 23 |
19 @end | 24 @end |
20 | 25 |
21 @implementation ExampleViewController | 26 @implementation ExampleViewController |
22 | 27 |
23 #pragma mark - UIViewController | 28 #pragma mark - UIViewController |
24 | 29 |
25 - (void)viewDidLoad { | 30 - (void)viewDidLoad { |
26 [super viewDidLoad]; | 31 [super viewDidLoad]; |
27 | 32 _gestures = [[ClientGestures alloc] initWithView:self.view]; |
28 _context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; | 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(); |
29 static_cast<GLKView*>(self.view).context = _context; | 37 static_cast<GLKView*>(self.view).context = _context; |
30 | |
31 [self setupGL]; | 38 [self setupGL]; |
32 } | 39 } |
33 | 40 |
34 - (void)viewDidUnload { | 41 - (void)viewDidUnload { |
35 [super viewDidUnload]; | 42 [super viewDidUnload]; |
36 [self tearDownGL]; | 43 [self tearDownGL]; |
37 | 44 |
38 if ([EAGLContext currentContext] == _context) { | 45 if ([EAGLContext currentContext] == _context) { |
39 [EAGLContext setCurrentContext:nil]; | 46 [EAGLContext setCurrentContext:nil]; |
40 } | 47 } |
41 _context = nil; | 48 _context = nil; |
42 } | 49 } |
43 | 50 |
44 - (void)setupGL { | 51 - (void)setupGL { |
45 [EAGLContext setCurrentContext:_context]; | 52 _display_handler = [[GlDisplayHandler alloc] initWithRuntime:_runtime]; |
| 53 [_display_handler created]; |
46 } | 54 } |
47 | 55 |
48 - (void)tearDownGL { | 56 - (void)tearDownGL { |
49 [EAGLContext setCurrentContext:_context]; | 57 // TODO(nicholss): Implement this in a real application. |
50 } | 58 } |
51 | 59 |
52 - (void)viewWillAppear:(BOOL)animated { | 60 - (void)viewWillAppear:(BOOL)animated { |
53 [super viewWillAppear:animated]; | 61 [super viewWillAppear:animated]; |
54 } | 62 } |
55 | 63 |
56 - (void)viewDidAppear:(BOOL)animated { | 64 - (void)viewDidAppear:(BOOL)animated { |
| 65 _video_renderer = |
| 66 (remoting::SoftwareVideoRenderer*)[_display_handler CreateVideoRenderer] |
| 67 .get(); |
57 } | 68 } |
58 | 69 |
59 - (void)viewWillDisappear:(BOOL)animated { | 70 - (void)viewWillDisappear:(BOOL)animated { |
60 [super viewWillDisappear:NO]; | 71 [super viewWillDisappear:NO]; |
61 } | 72 } |
62 | 73 |
63 - (void)viewDidLayoutSubviews { | 74 - (void)viewDidLayoutSubviews { |
64 [super viewDidLayoutSubviews]; | 75 [super viewDidLayoutSubviews]; |
65 } | 76 } |
66 | 77 |
67 #pragma mark - GLKViewDelegate | 78 #pragma mark - GLKViewDelegate |
68 | 79 |
69 // In general, avoid expensive work in this function to maximize frame rate. | 80 // In general, avoid expensive work in this function to maximize frame rate. |
70 - (void)glkView:(GLKView*)view drawInRect:(CGRect)rect { | 81 - (void)glkView:(GLKView*)view drawInRect:(CGRect)rect { |
71 // Clear to give the background color. | 82 if (_display_handler) { |
72 glClearColor(0.0, 40.0, 0.0, 1.0); | 83 [_display_handler glkView:view drawInRect:rect]; |
73 glClear(GL_COLOR_BUFFER_BIT); | 84 } |
74 } | 85 } |
75 | 86 |
76 @end | 87 @end |
OLD | NEW |