Add initWithCoder to RTCEAGLVideoView.

Allows for proper OpenGL initialization if view is created from
storyboard.

BUG=3896
R=jiayl@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/34549004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7970 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
tkchin@webrtc.org 2014-12-19 20:47:35 +00:00
parent ae643ce280
commit 7ce4a584aa

View File

@ -108,39 +108,52 @@
- (instancetype)initWithFrame:(CGRect)frame { - (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) { if (self = [super initWithFrame:frame]) {
EAGLContext* glContext = [self configure];
[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; }
_glRenderer = [[RTCOpenGLVideoRenderer alloc] initWithContext:glContext]; return self;
}
// GLKView manages a framebuffer for us. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
_glkView = [[GLKView alloc] initWithFrame:CGRectZero if (self = [super initWithCoder:aDecoder]) {
context:glContext]; [self configure];
_glkView.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888; }
_glkView.drawableDepthFormat = GLKViewDrawableDepthFormatNone; return self;
_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 - (void)configure {
// away. EAGLContext* glContext =
NSNotificationCenter* notificationCenter = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
[NSNotificationCenter defaultCenter]; _glRenderer = [[RTCOpenGLVideoRenderer alloc] initWithContext:glContext];
[notificationCenter addObserver:self
selector:@selector(willResignActive)
name:UIApplicationWillResignActiveNotification
object:nil];
[notificationCenter addObserver:self
selector:@selector(didBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
// Frames are received on a separate thread, so we poll for current frame // GLKView manages a framebuffer for us.
// using a refresh rate proportional to screen refresh frequency. This _glkView = [[GLKView alloc] initWithFrame:CGRectZero
// occurs on the main thread. context:glContext];
__weak RTCEAGLVideoView* weakSelf = self; _glkView.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888;
_timer = [[RTCDisplayLinkTimer alloc] initWithTimerHandler:^{ _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 =
[NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self
selector:@selector(willResignActive)
name:UIApplicationWillResignActiveNotification
object:nil];
[notificationCenter addObserver:self
selector:@selector(didBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
// Frames are received on a separate thread, so we poll for current frame
// using a refresh rate proportional to screen refresh frequency. This
// occurs on the main thread.
__weak RTCEAGLVideoView* weakSelf = self;
_timer = [[RTCDisplayLinkTimer alloc] initWithTimerHandler:^{
RTCEAGLVideoView* strongSelf = weakSelf; RTCEAGLVideoView* strongSelf = weakSelf;
// Don't render if frame hasn't changed. // Don't render if frame hasn't changed.
if (strongSelf.glRenderer.lastDrawnFrame == strongSelf.i420Frame) { if (strongSelf.glRenderer.lastDrawnFrame == strongSelf.i420Frame) {
@ -150,9 +163,7 @@
// GLKViewDelegate method implemented below. // GLKViewDelegate method implemented below.
[strongSelf.glkView setNeedsDisplay]; [strongSelf.glkView setNeedsDisplay];
}]; }];
[self setupGL]; [self setupGL];
}
return self;
} }
- (void)dealloc { - (void)dealloc {