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

Unified Diff: webrtc/sdk/objc/Framework/Classes/Metal/RTCMTLVideoView.m

Issue 2651743007: Add metal view, shaders and renderer. (Closed)
Patch Set: Move RTCVideoRender implementation to view Created 3 years, 10 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/Metal/RTCMTLVideoView.m
diff --git a/webrtc/sdk/objc/Framework/Classes/Metal/RTCMTLVideoView.m b/webrtc/sdk/objc/Framework/Classes/Metal/RTCMTLVideoView.m
new file mode 100644
index 0000000000000000000000000000000000000000..0bd2c652689892e4a771364763fa2e2840c3efe7
--- /dev/null
+++ b/webrtc/sdk/objc/Framework/Classes/Metal/RTCMTLVideoView.m
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2017 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#import "WebRTC/RTCMTLVideoView.h"
+
+#import <Metal/Metal.h>
+#import <MetalKit/MetalKit.h>
+
+#import "WebRTC/RTCVideoFrame.h"
+
+#import "RTCMTLNV12Renderer.h"
+
+@interface RTCMTLVideoView () <MTKViewDelegate>
+@property(nonatomic) id<RTCMTLRenderer> renderer;
tkchin_webrtc 2017/02/22 00:22:27 nit: be consistent with doco of strong or not usu
daniela-webrtc 2017/02/22 14:50:22 Done.
+@property(nonatomic, strong) MTKView *metalView;
+@property(atomic, strong) RTCVideoFrame *videoFrame;
+@end
+
+@implementation RTCMTLVideoView {
+ id<RTCMTLRenderer> _renderer;
+}
+
+@synthesize renderer = _renderer;
+@synthesize metalView = _metalView;
+@synthesize videoFrame = _videoFrame;
+
+- (instancetype)initWithFrame:(CGRect)frameRect {
+ self = [super initWithFrame:frameRect];
+ if (self) {
+ [self configure];
+ }
+ return self;
+}
+
+- (instancetype)initWithCoder:(NSCoder *)aCoder {
+ self = [super initWithCoder:aCoder];
+ if (self) {
+ [self configure];
+ }
+ return self;
+}
+
+#pragma mark - Private
+
++ (BOOL)isMetalAvailable {
+#if defined(__OBJC__) && COREVIDEO_SUPPORTS_METAL
+ return YES;
+#endif
+ return NO;
kthelgason 2017/02/21 08:09:12 nit: I'd prefer the return NO to be within an else
daniela-webrtc 2017/02/22 14:50:23 Done.
+}
+
+- (void)configure {
+ if ([RTCMTLVideoView isMetalAvailable]) {
+ _metalView = [[MTKView alloc] initWithFrame:self.bounds];
+ [self addSubview:_metalView];
+ _metalView.delegate = self;
+ _metalView.contentMode = UIViewContentModeScaleAspectFit;
+ _metalView.translatesAutoresizingMaskIntoConstraints = NO;
+ UILayoutGuide *margins = self.layoutMarginsGuide;
+ [_metalView.topAnchor constraintEqualToAnchor:margins.topAnchor].active = YES;
+ [_metalView.bottomAnchor constraintEqualToAnchor:margins.bottomAnchor].active = YES;
+ [_metalView.leftAnchor constraintEqualToAnchor:margins.leftAnchor].active = YES;
+ [_metalView.rightAnchor constraintEqualToAnchor:margins.rightAnchor].active = YES;
+
+ _renderer = [[RTCNV12Renderer alloc] init];
+ if (![(RTCNV12Renderer *)_renderer addRenderingDestination:_metalView]) {
+ _renderer = nil;
+ };
+ }
+}
tkchin_webrtc 2017/02/22 00:22:27 if we know at end of configure whether or not it w
daniela-webrtc 2017/02/22 14:50:23 UIView's declaration of init explicitly states non
+#pragma mark - MTKViewDelegate methods
tkchin_webrtc 2017/02/22 00:22:27 nit: add blank line after pragma
daniela-webrtc 2017/02/22 14:50:23 Done.
+- (void)drawInMTKView:(nonnull MTKView *)view {
+ if (view == self.metalView) {
+ [_renderer drawFrame:self.videoFrame];
+ }
tkchin_webrtc 2017/02/22 00:22:27 If this is an unexpected scenario, feel free to as
daniela-webrtc 2017/02/22 14:50:22 Done.
+}
+
+- (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size {
+}
+
+#pragma mark - RTCVideoRenderer
+
+- (void)setSize:(CGSize)size {
+ _metalView.drawableSize = size;
+ [_metalView draw];
+}
+
+- (void)renderFrame:(nullable RTCVideoFrame *)frame {
+ if (frame == nil) {
tkchin_webrtc 2017/02/22 00:22:27 return or draw black?
daniela-webrtc 2017/02/22 14:50:22 That functionality should not be included in the v
+ return;
+ }
+ self.videoFrame = frame;
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698