Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 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/app/host_view_controller.h" | 9 #import "remoting/client/ios/app/host_view_controller.h" |
| 10 | 10 |
| 11 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" | 11 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" |
| 12 #import "remoting/client/display/sys_opengl.h" | 12 #import "remoting/client/ios/session/remoting_client.h" |
| 13 #import "remoting/client/ios/display/gl_display_handler.h" | |
| 14 #import "remoting/client/ios/facade/remoting_service.h" | |
| 15 | 13 |
| 16 #include "remoting/client/chromoting_client_runtime.h" | 14 static const CGFloat kFabInset = 15.f; |
|
Jamie
2017/04/24 21:54:11
This doesn't look related to the CL description. I
nicholss
2017/04/24 22:03:07
The host view has a FAB on it, in seeing the rende
Jamie
2017/04/24 22:07:42
It should still at least be called out in the CL d
| |
| 17 #include "remoting/client/software_video_renderer.h" | |
| 18 | |
| 19 static const CGFloat kFabInset = 45.f; | |
| 20 | 15 |
| 21 @interface HostViewController () { | 16 @interface HostViewController () { |
| 22 EAGLContext* _context; | 17 RemotingClient* _client; |
| 23 GlDisplayHandler* _display_handler; | |
| 24 remoting::SoftwareVideoRenderer* _video_renderer; | |
| 25 } | 18 } |
| 26 @end | 19 @end |
| 27 | 20 |
| 28 @implementation HostViewController | 21 @implementation HostViewController |
| 29 | 22 |
| 30 - (id)init { | 23 - (id)initWithClient:(RemotingClient*)client { |
| 31 self = [super init]; | 24 self = [super init]; |
| 32 if (self) { | 25 if (self) { |
| 33 // TODO(nicholss): For prod code, make sure to check for ES3 support and | 26 _client = client; |
| 34 // fall back to ES2 if needed. | |
| 35 _context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; | |
| 36 } | 27 } |
| 37 return self; | 28 return self; |
| 38 } | 29 } |
| 39 | 30 |
| 40 #pragma mark - UIViewController | 31 #pragma mark - UIViewController |
| 41 | 32 |
| 42 - (void)viewDidLoad { | 33 - (void)viewDidLoad { |
| 43 [super viewDidLoad]; | 34 [super viewDidLoad]; |
| 44 // TODO(nicholss): Take a look at the following: | 35 MDCFloatingButton* floatingButton = |
| 45 // components/Snackbar/examples/SnackbarOverlayViewExample.m | 36 [MDCFloatingButton floatingButtonWithShape:MDCFloatingButtonShapeMini]; |
| 46 // to add the toast overlay. | |
| 47 MDCFloatingButton* floatingButton = [MDCFloatingButton new]; | |
| 48 [floatingButton setTitle:@"+" forState:UIControlStateNormal]; | 37 [floatingButton setTitle:@"+" forState:UIControlStateNormal]; |
| 49 [floatingButton sizeToFit]; | |
| 50 [floatingButton addTarget:self | 38 [floatingButton addTarget:self |
| 51 action:@selector(didTap:) | 39 action:@selector(didTap:) |
| 52 forControlEvents:UIControlEventTouchUpInside]; | 40 forControlEvents:UIControlEventTouchUpInside]; |
| 53 | 41 |
| 54 UIImage* settingsImage = [UIImage imageNamed:@"Settings"]; | 42 UIImage* settingsImage = [UIImage imageNamed:@"Settings"]; |
| 55 [floatingButton setImage:settingsImage forState:UIControlStateNormal]; | 43 [floatingButton setImage:settingsImage forState:UIControlStateNormal]; |
| 56 | 44 [floatingButton sizeToFit]; |
| 57 floatingButton.frame = CGRectMake( | 45 CGSize btnSize = floatingButton.frame.size; |
| 58 self.view.frame.size.width - floatingButton.frame.size.width - kFabInset, | 46 floatingButton.frame = |
| 59 self.view.frame.size.height - floatingButton.frame.size.height - | 47 CGRectMake(self.view.frame.size.width - btnSize.width - kFabInset, |
| 60 kFabInset, | 48 self.view.frame.size.height - btnSize.height - kFabInset, |
| 61 floatingButton.frame.size.width, floatingButton.frame.size.height); | 49 btnSize.width, btnSize.height); |
| 62 | 50 |
| 63 [self.view addSubview:floatingButton]; | 51 [self.view addSubview:floatingButton]; |
| 64 | |
| 65 static_cast<GLKView*>(self.view).context = _context; | |
| 66 [self setupGL]; | |
| 67 } | 52 } |
| 68 | 53 |
| 69 - (void)viewDidUnload { | 54 - (void)viewDidUnload { |
| 70 [super viewDidUnload]; | 55 [super viewDidUnload]; |
| 71 [self tearDownGL]; | 56 // TODO(nicholss): There needs to be a hook to tell the client we are done. |
| 72 | |
| 73 if ([EAGLContext currentContext] == _context) { | |
| 74 [EAGLContext setCurrentContext:nil]; | |
| 75 } | |
| 76 _context = nil; | |
| 77 } | 57 } |
| 78 | 58 |
| 79 - (BOOL)prefersStatusBarHidden { | 59 - (BOOL)prefersStatusBarHidden { |
| 80 return YES; | 60 return YES; |
| 81 } | 61 } |
| 82 | 62 |
| 83 - (void)viewDidAppear:(BOOL)animated { | 63 - (void)viewDidAppear:(BOOL)animated { |
| 84 _video_renderer = | 64 [super viewDidAppear:animated]; |
| 85 (remoting::SoftwareVideoRenderer*)[_display_handler CreateVideoRenderer] | 65 GLKView* view = (GLKView*)self.view; |
| 86 .get(); | 66 view.context = [_client.displayHandler GetEAGLContext]; |
| 87 } | 67 } |
| 88 | 68 |
| 89 - (void)viewWillDisappear:(BOOL)animated { | 69 - (void)viewWillDisappear:(BOOL)animated { |
| 90 [super viewWillDisappear:NO]; | 70 [super viewWillDisappear:animated]; |
| 91 } | 71 } |
| 92 | 72 |
| 93 #pragma mark - GLKViewDelegate | 73 #pragma mark - GLKViewDelegate |
| 94 | 74 |
| 95 // In general, avoid expensive work in this function to maximize frame rate. | |
| 96 - (void)glkView:(GLKView*)view drawInRect:(CGRect)rect { | 75 - (void)glkView:(GLKView*)view drawInRect:(CGRect)rect { |
| 97 if (_display_handler) { | 76 // Nothing to do that is synchronous yet. |
| 98 [_display_handler glkView:view drawInRect:rect]; | |
| 99 } | |
| 100 } | 77 } |
| 101 | 78 |
| 102 #pragma mark - Private | 79 #pragma mark - Private |
| 103 | 80 |
| 104 - (void)setupGL { | |
| 105 _display_handler = [[GlDisplayHandler alloc] | |
| 106 initWithRuntime:[[RemotingService SharedInstance] runtime]]; | |
| 107 [_display_handler created]; | |
| 108 } | |
| 109 | |
| 110 - (void)tearDownGL { | |
| 111 // TODO(nicholss): Implement tearDownGL for the real application. | |
| 112 [_display_handler stop]; | |
| 113 _display_handler = nil; | |
| 114 _video_renderer = nil; | |
| 115 } | |
| 116 | |
| 117 - (void)didTap:(id)sender { | 81 - (void)didTap:(id)sender { |
| 118 // TODO(nicholss): The FAB is being used to close the window at the moment | 82 // TODO(nicholss): The FAB is being used to close the window at the moment |
| 119 // just as a demo as the integration continues. This will not be the case | 83 // just as a demo as the integration continues. This will not be the case |
| 120 // in the final app. | 84 // in the final app. |
| 121 [self tearDownGL]; | |
| 122 [self dismissViewControllerAnimated:YES completion:nil]; | 85 [self dismissViewControllerAnimated:YES completion:nil]; |
| 123 } | 86 } |
| 124 | 87 |
| 125 @end | 88 @end |
| OLD | NEW |