1 // Copyright 2014 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.
5 #if !defined(__has_feature) || !__has_feature(objc_arc)
6 #error "This file requires ARC support."
11 @implementation Utility
14 return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
17 + (BOOL)isInLandscapeMode {
18 UIInterfaceOrientation orientation =
19 [UIApplication sharedApplication].statusBarOrientation;
21 if ((orientation == UIInterfaceOrientationLandscapeLeft) ||
22 (orientation == UIInterfaceOrientationLandscapeRight)) {
28 + (CGSize)getOrientatedSize:(CGSize)size
29 shouldWidthBeLongestSide:(BOOL)shouldWidthBeLongestSide {
30 if (shouldWidthBeLongestSide && (size.height > size.width)) {
31 return CGSizeMake(size.height, size.width);
36 + (void)showAlert:(NSString*)title message:(NSString*)message {
38 alert = [[UIAlertView alloc] init];
40 alert.message = message;
42 [alert addButtonWithTitle:@"OK"];
46 + (NSString*)appVersionNumberDisplayString {
47 NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
49 NSString* majorVersion =
50 [infoDictionary objectForKey:@"CFBundleShortVersionString"];
51 NSString* minorVersion = [infoDictionary objectForKey:@"CFBundleVersion"];
54 stringWithFormat:@"Version %@ (%@)", majorVersion, minorVersion];
57 + (void)bindTextureForIOS:(GLuint)glName {
58 glBindTexture(GL_TEXTURE_2D, glName);
59 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
60 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
61 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
62 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
65 + (void)logGLErrorCode:(NSString*)funcName {
68 while (errorCode != 0) {
69 errorCode = glGetError(); // I don't know why this is returning an error
70 // on the first call to this function, but if I
71 // don't read it, then stuff doesn't work...
74 NSLog(@"glerror in %@: %X", funcName, errorCode);
80 + (void)drawSubRectToGLFromRectOfSize:(const webrtc::DesktopSize&)rectSize
81 subRect:(const webrtc::DesktopRect&)subRect
82 data:(const uint8_t*)data {
83 DCHECK(rectSize.width() >= subRect.width());
84 DCHECK(rectSize.height() >= subRect.height());
85 DCHECK(rectSize.width() >= (subRect.left() + subRect.width()));
86 DCHECK(rectSize.height() >= (subRect.top() + subRect.height()));
89 glTexSubImage2D(GL_TEXTURE_2D,
100 + (void)moveMouse:(HostProxy*)controller
101 at:(const webrtc::DesktopVector&)point {
102 [controller mouseAction:point
103 wheelDelta:webrtc::DesktopVector(0, 0)
108 + (void)leftClickOn:(HostProxy*)controller
109 at:(const webrtc::DesktopVector&)point {
110 [controller mouseAction:point
111 wheelDelta:webrtc::DesktopVector(0, 0)
114 [controller mouseAction:point
115 wheelDelta:webrtc::DesktopVector(0, 0)
120 + (void)middleClickOn:(HostProxy*)controller
121 at:(const webrtc::DesktopVector&)point {
122 [controller mouseAction:point
123 wheelDelta:webrtc::DesktopVector(0, 0)
126 [controller mouseAction:point
127 wheelDelta:webrtc::DesktopVector(0, 0)
132 + (void)rightClickOn:(HostProxy*)controller
133 at:(const webrtc::DesktopVector&)point {
134 [controller mouseAction:point
135 wheelDelta:webrtc::DesktopVector(0, 0)
138 [controller mouseAction:point
139 wheelDelta:webrtc::DesktopVector(0, 0)
144 + (void)mouseScroll:(HostProxy*)controller
145 at:(const webrtc::DesktopVector&)point
146 delta:(const webrtc::DesktopVector&)delta {
147 [controller mouseAction:point wheelDelta:delta whichButton:0 buttonDown:NO];