Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: remoting/client/ios/app/host_view_controller.mm

Issue 2848143002: [Remoting iOS] Fix screen tearing and screen dimensions (Closed)
Patch Set: Add comments about not inheriting GLKViewController Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <GLKit/GLKit.h>
12
11 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" 13 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
12 #import "remoting/client/ios/session/remoting_client.h" 14 #import "remoting/client/ios/session/remoting_client.h"
13 15
14 static const CGFloat kFabInset = 15.f; 16 static const CGFloat kFabInset = 15.f;
15 17
16 @interface HostViewController () { 18 @interface HostViewController () {
17 RemotingClient* _client; 19 RemotingClient* _client;
20 MDCFloatingButton* _floatingButton;
18 } 21 }
19 @end 22 @end
20 23
21 @implementation HostViewController 24 @implementation HostViewController
22 25
23 - (id)initWithClient:(RemotingClient*)client { 26 - (id)initWithClient:(RemotingClient*)client {
24 self = [super init]; 27 self = [super init];
25 if (self) { 28 if (self) {
26 _client = client; 29 _client = client;
27 } 30 }
28 return self; 31 return self;
29 } 32 }
30 33
31 #pragma mark - UIViewController 34 #pragma mark - UIViewController
32 35
36 - (void)loadView {
37 self.view = [[GLKView alloc] initWithFrame:CGRectZero];
38 }
39
33 - (void)viewDidLoad { 40 - (void)viewDidLoad {
34 [super viewDidLoad]; 41 [super viewDidLoad];
35 MDCFloatingButton* floatingButton = 42 _floatingButton =
36 [MDCFloatingButton floatingButtonWithShape:MDCFloatingButtonShapeMini]; 43 [MDCFloatingButton floatingButtonWithShape:MDCFloatingButtonShapeMini];
37 [floatingButton setTitle:@"+" forState:UIControlStateNormal]; 44 [_floatingButton setTitle:@"+" forState:UIControlStateNormal];
38 [floatingButton addTarget:self 45 [_floatingButton addTarget:self
39 action:@selector(didTap:) 46 action:@selector(didTap:)
40 forControlEvents:UIControlEventTouchUpInside]; 47 forControlEvents:UIControlEventTouchUpInside];
41 48
42 UIImage* settingsImage = [UIImage imageNamed:@"Settings"]; 49 UIImage* settingsImage = [UIImage imageNamed:@"Settings"];
43 [floatingButton setImage:settingsImage forState:UIControlStateNormal]; 50 [_floatingButton setImage:settingsImage forState:UIControlStateNormal];
44 [floatingButton sizeToFit]; 51 [_floatingButton sizeToFit];
45 CGSize btnSize = floatingButton.frame.size; 52 [self.view addSubview:_floatingButton];
46 floatingButton.frame =
47 CGRectMake(self.view.frame.size.width - btnSize.width - kFabInset,
48 self.view.frame.size.height - btnSize.height - kFabInset,
49 btnSize.width, btnSize.height);
50
51 [self.view addSubview:floatingButton];
52 } 53 }
53 54
54 - (void)viewDidUnload { 55 - (void)viewDidUnload {
55 [super viewDidUnload]; 56 [super viewDidUnload];
56 // TODO(nicholss): There needs to be a hook to tell the client we are done. 57 // TODO(nicholss): There needs to be a hook to tell the client we are done.
57 } 58 }
58 59
59 - (BOOL)prefersStatusBarHidden { 60 - (BOOL)prefersStatusBarHidden {
60 return YES; 61 return YES;
61 } 62 }
62 63
63 - (void)viewDidAppear:(BOOL)animated { 64 - (void)viewDidAppear:(BOOL)animated {
64 [super viewDidAppear:animated]; 65 [super viewDidAppear:animated];
65 GLKView* view = (GLKView*)self.view; 66 GLKView* glView = (GLKView*)self.view;
66 view.context = [_client.displayHandler GetEAGLContext]; 67 glView.context = [_client.displayHandler GetEAGLContext];
68 [_client.displayHandler onSurfaceCreated:glView];
69
70 // viewDidLayoutSubviews may be called before viewDidAppear, in which case
71 // the surface is not ready and onSurfaceChanged will be no-op.
72 // Call onSurfaceChanged here to cover that case.
73 [_client.displayHandler onSurfaceChanged:glView.frame];
74 }
75
76 - (void)viewWillAppear:(BOOL)animated {
77 [super viewWillAppear:animated];
78 ((GLKView*)self.view).enableSetNeedsDisplay = true;
67 } 79 }
68 80
69 - (void)viewWillDisappear:(BOOL)animated { 81 - (void)viewWillDisappear:(BOOL)animated {
70 [super viewWillDisappear:animated]; 82 [super viewWillDisappear:animated];
71 } 83 }
72 84
73 #pragma mark - GLKViewDelegate 85 - (void)viewDidLayoutSubviews {
86 [super viewDidLayoutSubviews];
74 87
75 - (void)glkView:(GLKView*)view drawInRect:(CGRect)rect { 88 [_client.displayHandler onSurfaceChanged:((GLKView*)self.view).frame];
76 // Nothing to do that is synchronous yet. 89
90 const CGSize& btnSize = _floatingButton.frame.size;
91 _floatingButton.frame =
92 CGRectMake(self.view.frame.size.width - btnSize.width - kFabInset,
93 self.view.frame.size.height - btnSize.height - kFabInset,
94 btnSize.width, btnSize.height);
77 } 95 }
78 96
79 #pragma mark - Private 97 #pragma mark - Private
80 98
81 - (void)didTap:(id)sender { 99 - (void)didTap:(id)sender {
82 // TODO(nicholss): The FAB is being used to close the window at the moment 100 // TODO(nicholss): The FAB is being used to close the window at the moment
83 // just as a demo as the integration continues. This will not be the case 101 // just as a demo as the integration continues. This will not be the case
84 // in the final app. 102 // in the final app.
85 [self dismissViewControllerAnimated:YES completion:nil]; 103 [self dismissViewControllerAnimated:YES completion:nil];
86 } 104 }
87 105
88 @end 106 @end
OLDNEW
« no previous file with comments | « remoting/client/ios/app/host_view_controller.h ('k') | remoting/client/ios/display/gl_display_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698