| 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 530d9a7e6a195e1d00afc10428f9e9a88b093d47..c1942ca39d17356c7ff6078ddc1297685105645b 100644
|
| --- a/webrtc/sdk/objc/Framework/Classes/RTCNSGLVideoView.m
|
| +++ b/webrtc/sdk/objc/Framework/Classes/RTCNSGLVideoView.m
|
| @@ -18,7 +18,8 @@
|
| #import <CoreVideo/CVDisplayLink.h>
|
| #import <OpenGL/gl3.h>
|
|
|
| -#import "RTCShader+Private.h"
|
| +#import "RTCDefaultShader.h"
|
| +#import "RTCI420TextureCache.h"
|
| #import "WebRTC/RTCLogging.h"
|
| #import "WebRTC/RTCVideoFrame.h"
|
|
|
| @@ -26,7 +27,7 @@
|
| // |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) id<RTCShader> i420Shader;
|
| +@property(atomic, strong) RTCI420TextureCache *i420TextureCache;
|
|
|
| - (void)drawFrame;
|
| @end
|
| @@ -45,11 +46,26 @@ static CVReturn OnDisplayLinkFired(CVDisplayLinkRef displayLink,
|
| @implementation RTCNSGLVideoView {
|
| CVDisplayLinkRef _displayLink;
|
| RTCVideoFrame *_lastDrawnFrame;
|
| + id<RTCVideoViewShader> _shaderDelegate;
|
| }
|
|
|
| @synthesize delegate = _delegate;
|
| @synthesize videoFrame = _videoFrame;
|
| -@synthesize i420Shader = _i420Shader;
|
| +@synthesize i420TextureCache = _i420TextureCache;
|
| +
|
| +- (instancetype)initWithFrame:(NSRect)frame pixelFormat:(NSOpenGLPixelFormat *)format {
|
| + return
|
| + [self initWithFrame:frame pixelFormat:format shaderDelegate:[[RTCDefaultShader alloc] init]];
|
| +}
|
| +
|
| +- (instancetype)initWithFrame:(NSRect)frame
|
| + pixelFormat:(NSOpenGLPixelFormat *)format
|
| + shaderDelegate:(id<RTCVideoViewShader>)shaderDelegate {
|
| + if (self = [super initWithFrame:frame pixelFormat:format]) {
|
| + _shaderDelegate = shaderDelegate;
|
| + }
|
| + return self;
|
| +}
|
|
|
| - (void)dealloc {
|
| [self teardownDisplayLink];
|
| @@ -85,7 +101,7 @@ static CVReturn OnDisplayLinkFired(CVDisplayLinkRef displayLink,
|
|
|
| - (void)clearGLContext {
|
| [self ensureGLContext];
|
| - self.i420Shader = nil;
|
| + self.i420TextureCache = nil;
|
| [super clearGLContext];
|
| }
|
|
|
| @@ -118,15 +134,20 @@ static CVReturn OnDisplayLinkFired(CVDisplayLinkRef displayLink,
|
| glClear(GL_COLOR_BUFFER_BIT);
|
|
|
| // Rendering native CVPixelBuffer is not supported on OS X.
|
| + // TODO(magjed): Add support for NV12 texture cache on OS X.
|
| frame = [frame newI420VideoFrame];
|
| - if (!self.i420Shader) {
|
| - self.i420Shader = [[RTCI420Shader alloc] initWithContext:context];
|
| + if (!self.i420TextureCache) {
|
| + self.i420TextureCache = [[RTCI420TextureCache alloc] initWithContext:context];
|
| }
|
| - if (self.i420Shader && [self.i420Shader drawFrame:frame]) {
|
| + RTCI420TextureCache *i420TextureCache = self.i420TextureCache;
|
| + if (i420TextureCache) {
|
| + [i420TextureCache uploadFrameToTextures:frame];
|
| + [_shaderDelegate applyShadingForFrameWithRotation:frame.rotation
|
| + yPlane:i420TextureCache.yTexture
|
| + uPlane:i420TextureCache.uTexture
|
| + vPlane:i420TextureCache.vTexture];
|
| [context flushBuffer];
|
| _lastDrawnFrame = frame;
|
| - } else {
|
| - RTCLog(@"Failed to draw frame.");
|
| }
|
| CGLUnlockContext([context CGLContextObj]);
|
| }
|
|
|