 Chromium Code Reviews
 Chromium Code Reviews Issue 1347013002:
  RTCEAGLVideoView: Fix GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT error.  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master
    
  
    Issue 1347013002:
  RTCEAGLVideoView: Fix GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT error.  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 } | 114 } | 
| 115 | 115 | 
| 116 - (instancetype)initWithCoder:(NSCoder *)aDecoder { | 116 - (instancetype)initWithCoder:(NSCoder *)aDecoder { | 
| 117 if (self = [super initWithCoder:aDecoder]) { | 117 if (self = [super initWithCoder:aDecoder]) { | 
| 118 [self configure]; | 118 [self configure]; | 
| 119 } | 119 } | 
| 120 return self; | 120 return self; | 
| 121 } | 121 } | 
| 122 | 122 | 
| 123 - (void)configure { | 123 - (void)configure { | 
| 124 EAGLContext* glContext = | |
| 125 [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; | |
| 126 if (!glContext) { | |
| 127 glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; | |
| 128 } | |
| 129 _glRenderer = [[RTCOpenGLVideoRenderer alloc] initWithContext:glContext]; | |
| 
magjed_webrtc
2015/09/17 08:59:46
Why can't _glRenderer alloc stay in this function?
 | |
| 130 | |
| 131 // GLKView manages a framebuffer for us. | |
| 132 _glkView = [[GLKView alloc] initWithFrame:CGRectZero | |
| 133 context:glContext]; | |
| 134 _glkView.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888; | |
| 135 _glkView.drawableDepthFormat = GLKViewDrawableDepthFormatNone; | |
| 136 _glkView.drawableStencilFormat = GLKViewDrawableStencilFormatNone; | |
| 137 _glkView.drawableMultisample = GLKViewDrawableMultisampleNone; | |
| 138 _glkView.delegate = self; | |
| 139 _glkView.layer.masksToBounds = YES; | |
| 140 [self addSubview:_glkView]; | |
| 141 | |
| 142 // Listen to application state in order to clean up OpenGL before app goes | 124 // Listen to application state in order to clean up OpenGL before app goes | 
| 143 // away. | 125 // away. | 
| 144 NSNotificationCenter* notificationCenter = | 126 NSNotificationCenter* notificationCenter = | 
| 145 [NSNotificationCenter defaultCenter]; | 127 [NSNotificationCenter defaultCenter]; | 
| 146 [notificationCenter addObserver:self | 128 [notificationCenter addObserver:self | 
| 147 selector:@selector(willResignActive) | 129 selector:@selector(willResignActive) | 
| 148 name:UIApplicationWillResignActiveNotification | 130 name:UIApplicationWillResignActiveNotification | 
| 149 object:nil]; | 131 object:nil]; | 
| 150 [notificationCenter addObserver:self | 132 [notificationCenter addObserver:self | 
| 151 selector:@selector(didBecomeActive) | 133 selector:@selector(didBecomeActive) | 
| 152 name:UIApplicationDidBecomeActiveNotification | 134 name:UIApplicationDidBecomeActiveNotification | 
| 153 object:nil]; | 135 object:nil]; | 
| 154 | 136 | 
| 155 // Frames are received on a separate thread, so we poll for current frame | 137 // Frames are received on a separate thread, so we poll for current frame | 
| 156 // using a refresh rate proportional to screen refresh frequency. This | 138 // using a refresh rate proportional to screen refresh frequency. This | 
| 157 // occurs on the main thread. | 139 // occurs on the main thread. | 
| 158 __weak RTCEAGLVideoView* weakSelf = self; | 140 __weak RTCEAGLVideoView* weakSelf = self; | 
| 159 _timer = [[RTCDisplayLinkTimer alloc] initWithTimerHandler:^{ | 141 _timer = [[RTCDisplayLinkTimer alloc] initWithTimerHandler:^{ | 
| 160 RTCEAGLVideoView* strongSelf = weakSelf; | 142 RTCEAGLVideoView* strongSelf = weakSelf; | 
| 161 // Don't render if frame hasn't changed. | 143 // Don't render if frame hasn't changed. | 
| 162 if (strongSelf.glRenderer.lastDrawnFrame == strongSelf.i420Frame) { | 144 if (strongSelf.glRenderer.lastDrawnFrame == strongSelf.i420Frame) { | 
| 163 return; | 145 return; | 
| 164 } | 146 } | 
| 165 // This tells the GLKView that it's dirty, which will then call the | 147 // This tells the GLKView that it's dirty, which will then call the | 
| 166 // GLKViewDelegate method implemented below. | 148 // GLKViewDelegate method implemented below. | 
| 167 [strongSelf.glkView setNeedsDisplay]; | 149 [strongSelf.glkView setNeedsDisplay]; | 
| 168 }]; | 150 }]; | 
| 151 } | |
| 152 | |
| 153 - (BOOL)isGLConfigured { | |
| 154 return (_glkView != nil) && (_glRenderer != nil); | |
| 155 } | |
| 156 | |
| 157 - (void)configureGLIfApplicable { | |
| 158 NSAssert([NSThread isMainThread], @"should only configure on main thread"); | |
| 159 if ((![self isGLConfigured]) && (!CGRectIsEmpty(self.bounds))) { | |
| 160 [self configureGL]; | |
| 161 NSAssert([self isGLConfigured], @"GL components should have been configured" ); | |
| 162 } | |
| 163 } | |
| 164 | |
| 165 - (void)configureGL { | |
| 166 NSAssert((self.bounds.size.width > 0) && (self.bounds.size.height > 0), | |
| 167 @"Don't attempt to configure GLKView and renderer until a size is spe cified"); | |
| 168 EAGLContext *glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpe nGLES3]; | |
| 169 if (!glContext) { | |
| 170 glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; | |
| 171 } | |
| 172 _glRenderer = [[RTCOpenGLVideoRenderer alloc] initWithContext:glContext]; | |
| 173 | |
| 174 // GLKView manages a framebuffer for us. | |
| 175 _glkView = [[GLKView alloc] initWithFrame:self.bounds context:glContext]; | |
| 176 _glkView.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888; | |
| 177 _glkView.drawableDepthFormat = GLKViewDrawableDepthFormatNone; | |
| 178 _glkView.drawableStencilFormat = GLKViewDrawableStencilFormatNone; | |
| 179 _glkView.drawableMultisample = GLKViewDrawableMultisampleNone; | |
| 180 _glkView.delegate = self; | |
| 181 _glkView.layer.masksToBounds = YES; | |
| 182 [self addSubview:_glkView]; | |
| 183 | |
| 169 [self setupGL]; | 184 [self setupGL]; | 
| 170 } | 185 } | 
| 171 | 186 | 
| 172 - (void)dealloc { | 187 - (void)dealloc { | 
| 173 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 188 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 
| 174 UIApplicationState appState = | 189 UIApplicationState appState = | 
| 175 [UIApplication sharedApplication].applicationState; | 190 [UIApplication sharedApplication].applicationState; | 
| 176 if (appState == UIApplicationStateActive) { | 191 if (appState == UIApplicationStateActive) { | 
| 177 [self teardownGL]; | 192 [self teardownGL]; | 
| 178 } | 193 } | 
| 179 [_timer invalidate]; | 194 [_timer invalidate]; | 
| 180 } | 195 } | 
| 181 | 196 | 
| 182 #pragma mark - UIView | 197 #pragma mark - UIView | 
| 183 | 198 | 
| 199 - (void)setFrame:(CGRect)frame { | |
| 200 [super setFrame:frame]; | |
| 201 [self configureGLIfApplicable]; | |
| 202 } | |
| 203 | |
| 204 - (void)setBounds:(CGRect)bounds { | |
| 205 [super setBounds:bounds]; | |
| 206 [self configureGLIfApplicable]; | |
| 207 } | |
| 208 | |
| 184 - (void)layoutSubviews { | 209 - (void)layoutSubviews { | 
| 185 [super layoutSubviews]; | 210 [super layoutSubviews]; | 
| 186 _glkView.frame = self.bounds; | 211 _glkView.frame = self.bounds; | 
| 187 } | 212 } | 
| 188 | 213 | 
| 189 #pragma mark - GLKViewDelegate | 214 #pragma mark - GLKViewDelegate | 
| 190 | 215 | 
| 191 // This method is called when the GLKView's content is dirty and needs to be | 216 // This method is called when the GLKView's content is dirty and needs to be | 
| 192 // redrawn. This occurs on main thread. | 217 // redrawn. This occurs on main thread. | 
| 193 - (void)glkView:(GLKView*)view drawInRect:(CGRect)rect { | 218 - (void)glkView:(GLKView*)view drawInRect:(CGRect)rect { | 
| 194 // The renderer will draw the frame to the framebuffer corresponding to the | 219 // The renderer will draw the frame to the framebuffer corresponding to the | 
| 195 // one used by |view|. | 220 // one used by |view|. | 
| 196 [_glRenderer drawFrame:self.i420Frame]; | 221 [_glRenderer drawFrame:self.i420Frame]; | 
| 
magjed_webrtc
2015/09/17 08:59:46
Maybe drop frames here if framebuffer is not compl
 | |
| 197 } | 222 } | 
| 198 | 223 | 
| 199 #pragma mark - RTCVideoRenderer | 224 #pragma mark - RTCVideoRenderer | 
| 200 | 225 | 
| 201 // These methods may be called on non-main thread. | 226 // These methods may be called on non-main thread. | 
| 202 - (void)setSize:(CGSize)size { | 227 - (void)setSize:(CGSize)size { | 
| 203 __weak RTCEAGLVideoView* weakSelf = self; | 228 __weak RTCEAGLVideoView* weakSelf = self; | 
| 204 dispatch_async(dispatch_get_main_queue(), ^{ | 229 dispatch_async(dispatch_get_main_queue(), ^{ | 
| 205 RTCEAGLVideoView* strongSelf = weakSelf; | 230 RTCEAGLVideoView* strongSelf = weakSelf; | 
| 206 [strongSelf.delegate videoView:strongSelf didChangeVideoSize:size]; | 231 [strongSelf.delegate videoView:strongSelf didChangeVideoSize:size]; | 
| (...skipping 21 matching lines...) Expand all Loading... | |
| 228 | 253 | 
| 229 - (void)didBecomeActive { | 254 - (void)didBecomeActive { | 
| 230 [self setupGL]; | 255 [self setupGL]; | 
| 231 } | 256 } | 
| 232 | 257 | 
| 233 - (void)willResignActive { | 258 - (void)willResignActive { | 
| 234 [self teardownGL]; | 259 [self teardownGL]; | 
| 235 } | 260 } | 
| 236 | 261 | 
| 237 @end | 262 @end | 
| OLD | NEW |