Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 return [self initWithFrame:frame shader:[[RTCDefaultShader alloc] init]]; | 114 return [self initWithFrame:frame shader:[[RTCDefaultShader alloc] init]]; |
| 115 } | 115 } |
| 116 | 116 |
| 117 - (instancetype)initWithCoder:(NSCoder *)aDecoder { | 117 - (instancetype)initWithCoder:(NSCoder *)aDecoder { |
| 118 return [self initWithCoder:aDecoder shader:[[RTCDefaultShader alloc] init]]; | 118 return [self initWithCoder:aDecoder shader:[[RTCDefaultShader alloc] init]]; |
| 119 } | 119 } |
| 120 | 120 |
| 121 - (instancetype)initWithFrame:(CGRect)frame shader:(id<RTCVideoViewShading>)shad er { | 121 - (instancetype)initWithFrame:(CGRect)frame shader:(id<RTCVideoViewShading>)shad er { |
| 122 if (self = [super initWithFrame:frame]) { | 122 if (self = [super initWithFrame:frame]) { |
| 123 _shader = shader; | 123 _shader = shader; |
| 124 [self configure]; | 124 if (![self configure]) { |
| 125 return nil; | |
| 126 } | |
| 125 } | 127 } |
| 126 return self; | 128 return self; |
| 127 } | 129 } |
| 128 | 130 |
| 129 - (instancetype)initWithCoder:(NSCoder *)aDecoder shader:(id<RTCVideoViewShading >)shader { | 131 - (instancetype)initWithCoder:(NSCoder *)aDecoder shader:(id<RTCVideoViewShading >)shader { |
| 130 if (self = [super initWithCoder:aDecoder]) { | 132 if (self = [super initWithCoder:aDecoder]) { |
| 131 _shader = shader; | 133 _shader = shader; |
| 132 [self configure]; | 134 if (![self configure]) { |
| 135 return nil; | |
| 136 } | |
| 133 } | 137 } |
| 134 return self; | 138 return self; |
| 135 } | 139 } |
| 136 | 140 |
| 137 - (void)configure { | 141 - (BOOL)configure { |
| 138 EAGLContext *glContext = | 142 EAGLContext *glContext = |
| 139 [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; | 143 [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; |
| 140 if (!glContext) { | 144 if (!glContext) { |
| 141 glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; | 145 glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; |
| 142 } | 146 } |
| 147 if (!glContext) { | |
| 148 return NO; | |
|
tkchin_webrtc
2017/07/27 20:42:12
nit: add an error log
magjed_webrtc
2017/07/31 15:23:23
Done.
| |
| 149 } | |
| 143 _glContext = glContext; | 150 _glContext = glContext; |
| 144 | 151 |
| 145 // GLKView manages a framebuffer for us. | 152 // GLKView manages a framebuffer for us. |
| 146 _glkView = [[GLKView alloc] initWithFrame:CGRectZero | 153 _glkView = [[GLKView alloc] initWithFrame:CGRectZero |
| 147 context:_glContext]; | 154 context:_glContext]; |
| 148 _glkView.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888; | 155 _glkView.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888; |
| 149 _glkView.drawableDepthFormat = GLKViewDrawableDepthFormatNone; | 156 _glkView.drawableDepthFormat = GLKViewDrawableDepthFormatNone; |
| 150 _glkView.drawableStencilFormat = GLKViewDrawableStencilFormatNone; | 157 _glkView.drawableStencilFormat = GLKViewDrawableStencilFormatNone; |
| 151 _glkView.drawableMultisample = GLKViewDrawableMultisampleNone; | 158 _glkView.drawableMultisample = GLKViewDrawableMultisampleNone; |
| 152 _glkView.delegate = self; | 159 _glkView.delegate = self; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 169 | 176 |
| 170 // Frames are received on a separate thread, so we poll for current frame | 177 // Frames are received on a separate thread, so we poll for current frame |
| 171 // using a refresh rate proportional to screen refresh frequency. This | 178 // using a refresh rate proportional to screen refresh frequency. This |
| 172 // occurs on the main thread. | 179 // occurs on the main thread. |
| 173 __weak RTCEAGLVideoView *weakSelf = self; | 180 __weak RTCEAGLVideoView *weakSelf = self; |
| 174 _timer = [[RTCDisplayLinkTimer alloc] initWithTimerHandler:^{ | 181 _timer = [[RTCDisplayLinkTimer alloc] initWithTimerHandler:^{ |
| 175 RTCEAGLVideoView *strongSelf = weakSelf; | 182 RTCEAGLVideoView *strongSelf = weakSelf; |
| 176 [strongSelf displayLinkTimerDidFire]; | 183 [strongSelf displayLinkTimerDidFire]; |
| 177 }]; | 184 }]; |
| 178 [self setupGL]; | 185 [self setupGL]; |
| 186 return YES; | |
| 179 } | 187 } |
| 180 | 188 |
| 181 - (void)dealloc { | 189 - (void)dealloc { |
| 182 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 190 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 183 UIApplicationState appState = | 191 UIApplicationState appState = |
| 184 [UIApplication sharedApplication].applicationState; | 192 [UIApplication sharedApplication].applicationState; |
| 185 if (appState == UIApplicationStateActive) { | 193 if (appState == UIApplicationStateActive) { |
| 186 [self teardownGL]; | 194 [self teardownGL]; |
| 187 } | 195 } |
| 188 [_timer invalidate]; | 196 [_timer invalidate]; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 } | 318 } |
| 311 | 319 |
| 312 - (void)ensureGLContext { | 320 - (void)ensureGLContext { |
| 313 NSAssert(_glContext, @"context shouldn't be nil"); | 321 NSAssert(_glContext, @"context shouldn't be nil"); |
| 314 if ([EAGLContext currentContext] != _glContext) { | 322 if ([EAGLContext currentContext] != _glContext) { |
| 315 [EAGLContext setCurrentContext:_glContext]; | 323 [EAGLContext setCurrentContext:_glContext]; |
| 316 } | 324 } |
| 317 } | 325 } |
| 318 | 326 |
| 319 @end | 327 @end |
| OLD | NEW |