Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(908)

Unified Diff: webrtc/sdk/objc/Framework/Classes/RTCNSGLVideoView.m

Issue 2812613003: ObjC: Remove RTCOpenGLVideoRenderer (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/sdk/objc/Framework/Classes/RTCNSGLVideoView.m
diff --git a/webrtc/sdk/objc/Framework/Classes/RTCNSGLVideoView.m b/webrtc/sdk/objc/Framework/Classes/RTCNSGLVideoView.m
index 18dc4d1315aad0c9906dddfefe55c8c948b8cc02..6f94b1b8c334d54f415d24614f3c72d085223424 100644
--- a/webrtc/sdk/objc/Framework/Classes/RTCNSGLVideoView.m
+++ b/webrtc/sdk/objc/Framework/Classes/RTCNSGLVideoView.m
@@ -14,17 +14,17 @@
#import "WebRTC/RTCNSGLVideoView.h"
+#import <AppKit/NSOpenGL.h>
#import <CoreVideo/CVDisplayLink.h>
#import <OpenGL/gl3.h>
-#import "RTCOpenGLVideoRenderer.h"
+#import "RTCShader+Private.h"
#import "WebRTC/RTCVideoFrame.h"
@interface RTCNSGLVideoView ()
// |videoFrame| is set when we receive a frame from a worker thread and is read
// from the display link callback so atomicity is required.
@property(atomic, strong) RTCVideoFrame *videoFrame;
-@property(atomic, strong) RTCOpenGLVideoRenderer *glRenderer;
- (void)drawFrame;
@end
@@ -41,11 +41,12 @@ static CVReturn OnDisplayLinkFired(CVDisplayLinkRef displayLink,
@implementation RTCNSGLVideoView {
CVDisplayLinkRef _displayLink;
+ id<RTCShader> _i420Shader;
+ RTCVideoFrame *_lastDrawnFrame;
}
@synthesize delegate = _delegate;
@synthesize videoFrame = _videoFrame;
-@synthesize glRenderer = _glRenderer;
- (void)dealloc {
[self teardownDisplayLink];
@@ -74,17 +75,13 @@ static CVReturn OnDisplayLinkFired(CVDisplayLinkRef displayLink,
- (void)prepareOpenGL {
[super prepareOpenGL];
- if (!self.glRenderer) {
- self.glRenderer =
- [[RTCOpenGLVideoRenderer alloc] initWithContext:[self openGLContext]];
- }
- [self.glRenderer setupGL];
+ [self ensureGLContext];
[self setupDisplayLink];
}
- (void)clearGLContext {
- [self.glRenderer teardownGL];
- self.glRenderer = nil;
+ [self ensureGLContext];
+ _i420Shader = nil;
[super clearGLContext];
}
@@ -104,14 +101,29 @@ static CVReturn OnDisplayLinkFired(CVDisplayLinkRef displayLink,
#pragma mark - Private
- (void)drawFrame {
- RTCVideoFrame *videoFrame = self.videoFrame;
- if (self.glRenderer.lastDrawnFrame != videoFrame) {
- // This method may be called from CVDisplayLink callback which isn't on the
- // main thread so we have to lock the GL context before drawing.
- CGLLockContext([[self openGLContext] CGLContextObj]);
- [self.glRenderer drawFrame:videoFrame];
- CGLUnlockContext([[self openGLContext] CGLContextObj]);
+ RTCVideoFrame *frame = self.videoFrame;
+ if (!frame || frame == _lastDrawnFrame) {
+ return;
+ }
+ // This method may be called from CVDisplayLink callback which isn't on the
+ // main thread so we have to lock the GL context before drawing.
+ NSOpenGLContext *context = [self openGLContext];
+ CGLLockContext([context CGLContextObj]);
+
+ [self ensureGLContext];
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ // Rendering native CVPixelBuffer is not supported on OS X.
+ frame = [frame newI420VideoFrame];
+ if (!_i420Shader) {
+ _i420Shader = [[RTCI420Shader alloc] initWithContext:context];
+ NSAssert(_i420Shader, @"couldn't create i420 shader");
}
+ [_i420Shader drawFrame:frame];
+ [context flushBuffer];
+ _lastDrawnFrame = frame;
+
+ CGLUnlockContext([context CGLContextObj]);
}
- (void)setupDisplayLink {
@@ -143,6 +155,14 @@ static CVReturn OnDisplayLinkFired(CVDisplayLinkRef displayLink,
_displayLink = NULL;
}
+- (void)ensureGLContext {
+ NSOpenGLContext* context = [self openGLContext];
+ NSAssert(context, @"context shouldn't be nil");
+ if ([NSOpenGLContext currentContext] != context) {
+ [context makeCurrentContext];
+ }
+}
+
@end
#endif // !TARGET_OS_IPHONE

Powered by Google App Engine
This is Rietveld 408576698