Index: talk/app/webrtc/objc/RTCEAGLVideoView.m |
diff --git a/talk/app/webrtc/objc/RTCEAGLVideoView.m b/talk/app/webrtc/objc/RTCEAGLVideoView.m |
index 61040ba1025c2f23eed07f916df93d36b2955d76..bd3ada5c8f3a4d4fafc6a164b1fdbff586020d18 100644 |
--- a/talk/app/webrtc/objc/RTCEAGLVideoView.m |
+++ b/talk/app/webrtc/objc/RTCEAGLVideoView.m |
@@ -121,24 +121,6 @@ |
} |
- (void)configure { |
- EAGLContext* glContext = |
- [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; |
- if (!glContext) { |
- glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; |
- } |
- _glRenderer = [[RTCOpenGLVideoRenderer alloc] initWithContext:glContext]; |
magjed_webrtc
2015/09/17 08:59:46
Why can't _glRenderer alloc stay in this function?
|
- |
- // GLKView manages a framebuffer for us. |
- _glkView = [[GLKView alloc] initWithFrame:CGRectZero |
- context:glContext]; |
- _glkView.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888; |
- _glkView.drawableDepthFormat = GLKViewDrawableDepthFormatNone; |
- _glkView.drawableStencilFormat = GLKViewDrawableStencilFormatNone; |
- _glkView.drawableMultisample = GLKViewDrawableMultisampleNone; |
- _glkView.delegate = self; |
- _glkView.layer.masksToBounds = YES; |
- [self addSubview:_glkView]; |
- |
// Listen to application state in order to clean up OpenGL before app goes |
// away. |
NSNotificationCenter* notificationCenter = |
@@ -166,6 +148,39 @@ |
// GLKViewDelegate method implemented below. |
[strongSelf.glkView setNeedsDisplay]; |
}]; |
+} |
+ |
+- (BOOL)isGLConfigured { |
+ return (_glkView != nil) && (_glRenderer != nil); |
+} |
+ |
+- (void)configureGLIfApplicable { |
+ NSAssert([NSThread isMainThread], @"should only configure on main thread"); |
+ if ((![self isGLConfigured]) && (!CGRectIsEmpty(self.bounds))) { |
+ [self configureGL]; |
+ NSAssert([self isGLConfigured], @"GL components should have been configured"); |
+ } |
+} |
+ |
+- (void)configureGL { |
+ NSAssert((self.bounds.size.width > 0) && (self.bounds.size.height > 0), |
+ @"Don't attempt to configure GLKView and renderer until a size is specified"); |
+ EAGLContext *glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; |
+ if (!glContext) { |
+ glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; |
+ } |
+ _glRenderer = [[RTCOpenGLVideoRenderer alloc] initWithContext:glContext]; |
+ |
+ // GLKView manages a framebuffer for us. |
+ _glkView = [[GLKView alloc] initWithFrame:self.bounds context:glContext]; |
+ _glkView.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888; |
+ _glkView.drawableDepthFormat = GLKViewDrawableDepthFormatNone; |
+ _glkView.drawableStencilFormat = GLKViewDrawableStencilFormatNone; |
+ _glkView.drawableMultisample = GLKViewDrawableMultisampleNone; |
+ _glkView.delegate = self; |
+ _glkView.layer.masksToBounds = YES; |
+ [self addSubview:_glkView]; |
+ |
[self setupGL]; |
} |
@@ -181,6 +196,16 @@ |
#pragma mark - UIView |
+- (void)setFrame:(CGRect)frame { |
+ [super setFrame:frame]; |
+ [self configureGLIfApplicable]; |
+} |
+ |
+- (void)setBounds:(CGRect)bounds { |
+ [super setBounds:bounds]; |
+ [self configureGLIfApplicable]; |
+} |
+ |
- (void)layoutSubviews { |
[super layoutSubviews]; |
_glkView.frame = self.bounds; |