 Chromium Code Reviews
 Chromium Code Reviews Issue 2651743007:
  Add metal view, shaders and renderer.  (Closed)
    
  
    Issue 2651743007:
  Add metal view, shaders and renderer.  (Closed) 
  | OLD | NEW | 
|---|---|
| (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 "RTCNV12Renderer.h" | |
| 17 | |
| 18 @interface RTCMTLVideoView () <MTKViewDelegate> | |
| 19 @property(nonatomic) id<RTCMTLRenderer> renderer; | |
| 20 @property(nonatomic, strong) __kindof UIView *metalView; | |
| 21 @end | |
| 22 | |
| 23 @implementation RTCMTLVideoView { | |
| 24 id<RTCMTLRenderer> _renderer; | |
| 25 } | |
| 26 | |
| 27 @synthesize renderer = _renderer; | |
| 28 @synthesize metalView = _metalView; | |
| 29 | |
| 
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.
 | |
| 30 - (instancetype)initWithFrame:(CGRect)frameRect { | |
| 31 self = [super initWithFrame:frameRect]; | |
| 32 #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.
 | |
| 33 if (self) { | |
| 34 _metalView = [[MTKView alloc] initWithFrame:frameRect]; | |
| 35 [self addSubview:_metalView]; | |
| 36 ((MTKView *)_metalView).delegate = self; | |
| 37 _metalView.contentMode = UIViewContentModeScaleAspectFit; | |
| 38 _metalView.translatesAutoresizingMaskIntoConstraints = NO; | |
| 39 UILayoutGuide *margins = self.layoutMarginsGuide; | |
| 40 [_metalView.topAnchor constraintEqualToAnchor:margins.topAnchor].active = YE S; | |
| 41 [_metalView.bottomAnchor constraintEqualToAnchor:margins.bottomAnchor].activ e = YES; | |
| 42 [_metalView.leftAnchor constraintEqualToAnchor:margins.leftAnchor].active = YES; | |
| 43 [_metalView.rightAnchor constraintEqualToAnchor:margins.rightAnchor].active = YES; | |
| 44 | |
| 45 _renderer = [[RTCNV12Renderer alloc] init]; | |
| 46 if (![(RTCNV12Renderer *)_renderer addRenderingDestination:_metalView]) { | |
| 47 _renderer = nil; | |
| 48 }; | |
| 49 } | |
| 50 #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.
 | |
| 51 return self; | |
| 52 } | |
| 53 | |
| 54 - (void)drawInMTKView:(nonnull MTKView *)view { | |
| 55 if (view == self.metalView) { | |
| 56 [_renderer draw]; | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 - (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size { | |
| 61 } | |
| 62 @end | |
| OLD | NEW |