| 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 RTCLogError(@"Failed to create EAGLContext"); |
| 149 return NO; |
| 150 } |
| 143 _glContext = glContext; | 151 _glContext = glContext; |
| 144 | 152 |
| 145 // GLKView manages a framebuffer for us. | 153 // GLKView manages a framebuffer for us. |
| 146 _glkView = [[GLKView alloc] initWithFrame:CGRectZero | 154 _glkView = [[GLKView alloc] initWithFrame:CGRectZero |
| 147 context:_glContext]; | 155 context:_glContext]; |
| 148 _glkView.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888; | 156 _glkView.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888; |
| 149 _glkView.drawableDepthFormat = GLKViewDrawableDepthFormatNone; | 157 _glkView.drawableDepthFormat = GLKViewDrawableDepthFormatNone; |
| 150 _glkView.drawableStencilFormat = GLKViewDrawableStencilFormatNone; | 158 _glkView.drawableStencilFormat = GLKViewDrawableStencilFormatNone; |
| 151 _glkView.drawableMultisample = GLKViewDrawableMultisampleNone; | 159 _glkView.drawableMultisample = GLKViewDrawableMultisampleNone; |
| 152 _glkView.delegate = self; | 160 _glkView.delegate = self; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 169 | 177 |
| 170 // Frames are received on a separate thread, so we poll for current frame | 178 // Frames are received on a separate thread, so we poll for current frame |
| 171 // using a refresh rate proportional to screen refresh frequency. This | 179 // using a refresh rate proportional to screen refresh frequency. This |
| 172 // occurs on the main thread. | 180 // occurs on the main thread. |
| 173 __weak RTCEAGLVideoView *weakSelf = self; | 181 __weak RTCEAGLVideoView *weakSelf = self; |
| 174 _timer = [[RTCDisplayLinkTimer alloc] initWithTimerHandler:^{ | 182 _timer = [[RTCDisplayLinkTimer alloc] initWithTimerHandler:^{ |
| 175 RTCEAGLVideoView *strongSelf = weakSelf; | 183 RTCEAGLVideoView *strongSelf = weakSelf; |
| 176 [strongSelf displayLinkTimerDidFire]; | 184 [strongSelf displayLinkTimerDidFire]; |
| 177 }]; | 185 }]; |
| 178 [self setupGL]; | 186 [self setupGL]; |
| 187 return YES; |
| 179 } | 188 } |
| 180 | 189 |
| 181 - (void)dealloc { | 190 - (void)dealloc { |
| 182 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 191 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 183 UIApplicationState appState = | 192 UIApplicationState appState = |
| 184 [UIApplication sharedApplication].applicationState; | 193 [UIApplication sharedApplication].applicationState; |
| 185 if (appState == UIApplicationStateActive) { | 194 if (appState == UIApplicationStateActive) { |
| 186 [self teardownGL]; | 195 [self teardownGL]; |
| 187 } | 196 } |
| 188 [_timer invalidate]; | 197 [_timer invalidate]; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 } | 319 } |
| 311 | 320 |
| 312 - (void)ensureGLContext { | 321 - (void)ensureGLContext { |
| 313 NSAssert(_glContext, @"context shouldn't be nil"); | 322 NSAssert(_glContext, @"context shouldn't be nil"); |
| 314 if ([EAGLContext currentContext] != _glContext) { | 323 if ([EAGLContext currentContext] != _glContext) { |
| 315 [EAGLContext setCurrentContext:_glContext]; | 324 [EAGLContext setCurrentContext:_glContext]; |
| 316 } | 325 } |
| 317 } | 326 } |
| 318 | 327 |
| 319 @end | 328 @end |
| OLD | NEW |