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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #import "WebRTC/RTCMTLVideoView.h"
12
13 #import <Metal/Metal.h>
14 #import <MetalKit/MetalKit.h>
15
16 #import "WebRTC/RTCVideoFrame.h"
17
18 #import "RTCMTLNV12Renderer.h"
19
20 @interface RTCMTLVideoView () <MTKViewDelegate>
21 @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.
22 @property(nonatomic, strong) MTKView *metalView;
23 @property(atomic, strong) RTCVideoFrame *videoFrame;
24 @end
25
26 @implementation RTCMTLVideoView {
27 id<RTCMTLRenderer> _renderer;
28 }
29
30 @synthesize renderer = _renderer;
31 @synthesize metalView = _metalView;
32 @synthesize videoFrame = _videoFrame;
33
34 - (instancetype)initWithFrame:(CGRect)frameRect {
35 self = [super initWithFrame:frameRect];
36 if (self) {
37 [self configure];
38 }
39 return self;
40 }
41
42 - (instancetype)initWithCoder:(NSCoder *)aCoder {
43 self = [super initWithCoder:aCoder];
44 if (self) {
45 [self configure];
46 }
47 return self;
48 }
49
50 #pragma mark - Private
51
52 + (BOOL)isMetalAvailable {
53 #if defined(__OBJC__) && COREVIDEO_SUPPORTS_METAL
54 return YES;
55 #endif
56 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.
57 }
58
59 - (void)configure {
60 if ([RTCMTLVideoView isMetalAvailable]) {
61 _metalView = [[MTKView alloc] initWithFrame:self.bounds];
62 [self addSubview:_metalView];
63 _metalView.delegate = self;
64 _metalView.contentMode = UIViewContentModeScaleAspectFit;
65 _metalView.translatesAutoresizingMaskIntoConstraints = NO;
66 UILayoutGuide *margins = self.layoutMarginsGuide;
67 [_metalView.topAnchor constraintEqualToAnchor:margins.topAnchor].active = YE S;
68 [_metalView.bottomAnchor constraintEqualToAnchor:margins.bottomAnchor].activ e = YES;
69 [_metalView.leftAnchor constraintEqualToAnchor:margins.leftAnchor].active = YES;
70 [_metalView.rightAnchor constraintEqualToAnchor:margins.rightAnchor].active = YES;
71
72 _renderer = [[RTCNV12Renderer alloc] init];
73 if (![(RTCNV12Renderer *)_renderer addRenderingDestination:_metalView]) {
74 _renderer = nil;
75 };
76 }
77 }
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
78 #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.
79 - (void)drawInMTKView:(nonnull MTKView *)view {
80 if (view == self.metalView) {
81 [_renderer drawFrame:self.videoFrame];
82 }
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.
83 }
84
85 - (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size {
86 }
87
88 #pragma mark - RTCVideoRenderer
89
90 - (void)setSize:(CGSize)size {
91 _metalView.drawableSize = size;
92 [_metalView draw];
93 }
94
95 - (void)renderFrame:(nullable RTCVideoFrame *)frame {
96 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
97 return;
98 }
99 self.videoFrame = frame;
100 }
101
102 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698