Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 | 130 |
| 131 // GLKView manages a framebuffer for us. | 131 // GLKView manages a framebuffer for us. |
| 132 _glkView = [[GLKView alloc] initWithFrame:CGRectZero | 132 _glkView = [[GLKView alloc] initWithFrame:CGRectZero |
| 133 context:glContext]; | 133 context:glContext]; |
| 134 _glkView.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888; | 134 _glkView.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888; |
| 135 _glkView.drawableDepthFormat = GLKViewDrawableDepthFormatNone; | 135 _glkView.drawableDepthFormat = GLKViewDrawableDepthFormatNone; |
| 136 _glkView.drawableStencilFormat = GLKViewDrawableStencilFormatNone; | 136 _glkView.drawableStencilFormat = GLKViewDrawableStencilFormatNone; |
| 137 _glkView.drawableMultisample = GLKViewDrawableMultisampleNone; | 137 _glkView.drawableMultisample = GLKViewDrawableMultisampleNone; |
| 138 _glkView.delegate = self; | 138 _glkView.delegate = self; |
| 139 _glkView.layer.masksToBounds = YES; | 139 _glkView.layer.masksToBounds = YES; |
| 140 _glkView.enableSetNeedsDisplay = NO; | |
| 140 [self addSubview:_glkView]; | 141 [self addSubview:_glkView]; |
| 141 | 142 |
| 142 // Listen to application state in order to clean up OpenGL before app goes | 143 // Listen to application state in order to clean up OpenGL before app goes |
| 143 // away. | 144 // away. |
| 144 NSNotificationCenter* notificationCenter = | 145 NSNotificationCenter* notificationCenter = |
| 145 [NSNotificationCenter defaultCenter]; | 146 [NSNotificationCenter defaultCenter]; |
| 146 [notificationCenter addObserver:self | 147 [notificationCenter addObserver:self |
| 147 selector:@selector(willResignActive) | 148 selector:@selector(willResignActive) |
| 148 name:UIApplicationWillResignActiveNotification | 149 name:UIApplicationWillResignActiveNotification |
| 149 object:nil]; | 150 object:nil]; |
| 150 [notificationCenter addObserver:self | 151 [notificationCenter addObserver:self |
| 151 selector:@selector(didBecomeActive) | 152 selector:@selector(didBecomeActive) |
| 152 name:UIApplicationDidBecomeActiveNotification | 153 name:UIApplicationDidBecomeActiveNotification |
| 153 object:nil]; | 154 object:nil]; |
| 154 | 155 |
| 155 // Frames are received on a separate thread, so we poll for current frame | 156 // Frames are received on a separate thread, so we poll for current frame |
| 156 // using a refresh rate proportional to screen refresh frequency. This | 157 // using a refresh rate proportional to screen refresh frequency. This |
| 157 // occurs on the main thread. | 158 // occurs on the main thread. |
| 158 __weak RTCEAGLVideoView* weakSelf = self; | 159 __weak RTCEAGLVideoView* weakSelf = self; |
| 159 _timer = [[RTCDisplayLinkTimer alloc] initWithTimerHandler:^{ | 160 _timer = [[RTCDisplayLinkTimer alloc] initWithTimerHandler:^{ |
| 160 RTCEAGLVideoView* strongSelf = weakSelf; | 161 RTCEAGLVideoView* strongSelf = weakSelf; |
| 161 // Don't render if frame hasn't changed. | 162 [strongSelf displayLinkTimerDidFire]; |
| 162 if (strongSelf.glRenderer.lastDrawnFrame == strongSelf.i420Frame) { | |
| 163 return; | |
| 164 } | |
| 165 // This tells the GLKView that it's dirty, which will then call the | |
| 166 // GLKViewDelegate method implemented below. | |
| 167 [strongSelf.glkView setNeedsDisplay]; | |
| 168 }]; | 163 }]; |
| 169 [self setupGL]; | 164 [self setupGL]; |
| 170 } | 165 } |
| 171 | 166 |
| 172 - (void)dealloc { | 167 - (void)dealloc { |
| 173 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 168 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 174 UIApplicationState appState = | 169 UIApplicationState appState = |
| 175 [UIApplication sharedApplication].applicationState; | 170 [UIApplication sharedApplication].applicationState; |
| 176 if (appState == UIApplicationStateActive) { | 171 if (appState == UIApplicationStateActive) { |
| 177 [self teardownGL]; | 172 [self teardownGL]; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 206 [strongSelf.delegate videoView:strongSelf didChangeVideoSize:size]; | 201 [strongSelf.delegate videoView:strongSelf didChangeVideoSize:size]; |
| 207 }); | 202 }); |
| 208 } | 203 } |
| 209 | 204 |
| 210 - (void)renderFrame:(RTCI420Frame*)frame { | 205 - (void)renderFrame:(RTCI420Frame*)frame { |
| 211 self.i420Frame = frame; | 206 self.i420Frame = frame; |
| 212 } | 207 } |
| 213 | 208 |
| 214 #pragma mark - Private | 209 #pragma mark - Private |
| 215 | 210 |
| 211 - (void)displayLinkTimerDidFire { | |
| 212 // Don't render if frame hasn't changed. | |
| 213 if (_glRenderer.lastDrawnFrame == self.i420Frame) { | |
| 214 return; | |
| 215 } | |
| 216 | |
| 217 // Only call -[GLKView display] if the drawable size is | |
| 218 // non-empty. Calling display will make the GLKView setup it's | |
|
magjed_webrtc
2015/09/18 09:24:14
nit: s/it's/its/g
| |
| 219 // render buffer if necessary, but that will fail with error | |
| 220 // GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT if size is empty. | |
| 221 if (self.bounds.size.width > 0 && self.bounds.size.height > 0) { | |
| 222 [_glkView display]; | |
|
magjed_webrtc
2015/09/18 09:24:14
It looks like you changed setNeedsDisplay to displ
| |
| 223 } | |
| 224 } | |
| 225 | |
| 216 - (void)setupGL { | 226 - (void)setupGL { |
| 217 self.i420Frame = nil; | 227 self.i420Frame = nil; |
| 218 [_glRenderer setupGL]; | 228 [_glRenderer setupGL]; |
| 219 _timer.isPaused = NO; | 229 _timer.isPaused = NO; |
| 220 } | 230 } |
| 221 | 231 |
| 222 - (void)teardownGL { | 232 - (void)teardownGL { |
| 223 self.i420Frame = nil; | 233 self.i420Frame = nil; |
| 224 _timer.isPaused = YES; | 234 _timer.isPaused = YES; |
| 225 [_glkView deleteDrawable]; | 235 [_glkView deleteDrawable]; |
| 226 [_glRenderer teardownGL]; | 236 [_glRenderer teardownGL]; |
| 227 } | 237 } |
| 228 | 238 |
| 229 - (void)didBecomeActive { | 239 - (void)didBecomeActive { |
| 230 [self setupGL]; | 240 [self setupGL]; |
| 231 } | 241 } |
| 232 | 242 |
| 233 - (void)willResignActive { | 243 - (void)willResignActive { |
| 234 [self teardownGL]; | 244 [self teardownGL]; |
| 235 } | 245 } |
| 236 | 246 |
| 237 @end | 247 @end |
| OLD | NEW |