Chromium Code Reviews| 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..e36b6e7f015fdec0d806e88e04504865b779e825 |
| --- /dev/null |
| +++ b/webrtc/sdk/objc/Framework/Classes/Metal/RTCMTLVideoView.m |
| @@ -0,0 +1,62 @@ |
| +/* |
| + * 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 "RTCNV12Renderer.h" |
| + |
| +@interface RTCMTLVideoView () <MTKViewDelegate> |
| +@property(nonatomic) id<RTCMTLRenderer> renderer; |
| +@property(nonatomic, strong) __kindof UIView *metalView; |
| +@end |
| + |
| +@implementation RTCMTLVideoView { |
| + id<RTCMTLRenderer> _renderer; |
| +} |
| + |
| +@synthesize renderer = _renderer; |
| +@synthesize metalView = _metalView; |
| + |
|
tkchin_webrtc
2017/02/16 23:28:04
Probably want initWithCoder for all the folks maki
daniela-webrtc
2017/02/20 15:17:07
Done.
|
| +- (instancetype)initWithFrame:(CGRect)frameRect { |
| + self = [super initWithFrame:frameRect]; |
| +#if defined(__OBJC__) && COREVIDEO_SUPPORTS_METAL |
|
tkchin_webrtc
2017/02/16 23:28:04
ooc why __OBJC__?
daniela-webrtc
2017/02/20 15:17:07
Metal is available only for ObjectiveC for now.
|
| + if (self) { |
| + _metalView = [[MTKView alloc] initWithFrame:frameRect]; |
| + [self addSubview:_metalView]; |
| + ((MTKView *)_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; |
| + }; |
| + } |
| +#endif |
|
tkchin_webrtc
2017/02/16 23:28:04
Probably want to return nil if metal isn't support
daniela-webrtc
2017/02/20 15:17:07
instancetype is nonnull in the declaration.
|
| + return self; |
| +} |
| + |
| +- (void)drawInMTKView:(nonnull MTKView *)view { |
| + if (view == self.metalView) { |
| + [_renderer draw]; |
| + } |
| +} |
| + |
| +- (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size { |
| +} |
| +@end |