10 #import <QuartzCore/QuartzCore.h>
24 - (instancetype)initWithMTLDevice:(
id<MTLDevice>)device
25 commandQueue:(
id<MTLCommandQueue>)commandQueue
29 self = [
super initWithFrame:NSZeroRect];
31 [
self setWantsLayer:YES];
32 [
self setBackgroundColor:[NSColor blackColor]];
33 [
self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawDuringViewResize];
34 _viewIdentifier = viewIdentifier;
35 _viewDelegate = delegate;
38 commandQueue:commandQueue
45 - (void)onPresent:(CGSize)frameSize withBlock:(dispatch_block_t)block {
46 [_threadSynchronizer performCommitForView:_viewIdentifier size:frameSize notify:block];
50 return _surfaceManager;
54 CGSize scaledSize = [
self convertSizeToBacking:self.bounds.size];
55 [_threadSynchronizer beginResizeForView:_viewIdentifier
58 [_viewDelegate viewDidReshape:self];
62 - (void)setBackgroundColor:(NSColor*)color {
63 self.layer.backgroundColor = color.CGColor;
66 #pragma mark - NSView overrides
68 - (void)setFrameSize:(NSSize)newSize {
69 [
super setFrameSize:newSize];
88 - (BOOL)acceptsFirstMouse:(NSEvent*)event {
92 - (BOOL)acceptsFirstResponder {
95 return [_viewDelegate viewShouldAcceptFirstResponder:self];
98 - (void)didUpdateMouseCursor:(NSCursor*)cursor {
108 - (void)cursorUpdate:(NSEvent*)event {
110 NSPoint mouseLocation = [[
self superview] convertPoint:event.locationInWindow fromView:nil];
111 NSView* hitTestView = [
self hitTest:mouseLocation];
112 if (hitTestView !=
self) {
120 [[NSRunLoop currentRunLoop] performBlock:^{
125 - (void)viewDidChangeBackingProperties {
126 [
super viewDidChangeBackingProperties];
128 [_viewDelegate viewDidReshape:self];
131 - (BOOL)layer:(CALayer*)layer
132 shouldInheritContentsScale:(CGFloat)newScale
133 fromWindow:(NSWindow*)window {
137 #pragma mark - NSAccessibility overrides
139 - (BOOL)isAccessibilityElement {
143 - (NSAccessibilityRole)accessibilityRole {
144 return NSAccessibilityGroupRole;
147 - (NSString*)accessibilityLabel {
151 NSString* applicationName =
152 [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
153 if (!applicationName) {
154 applicationName = [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleName"];
156 return applicationName;