• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
6
7@implementation FlutterView {
8  __weak id<FlutterViewReshapeListener> _reshapeListener;
9}
10
11- (instancetype)initWithShareContext:(NSOpenGLContext*)shareContext
12                     reshapeListener:(id<FlutterViewReshapeListener>)reshapeListener {
13  return [self initWithFrame:NSZeroRect shareContext:shareContext reshapeListener:reshapeListener];
14}
15
16- (instancetype)initWithFrame:(NSRect)frame
17                 shareContext:(NSOpenGLContext*)shareContext
18              reshapeListener:(id<FlutterViewReshapeListener>)reshapeListener {
19  self = [super initWithFrame:frame];
20  if (self) {
21    self.openGLContext = [[NSOpenGLContext alloc] initWithFormat:shareContext.pixelFormat
22                                                    shareContext:shareContext];
23    _reshapeListener = reshapeListener;
24    self.wantsBestResolutionOpenGLSurface = YES;
25  }
26  return self;
27}
28
29- (void)makeCurrentContext {
30  [self.openGLContext makeCurrentContext];
31}
32
33- (void)onPresent {
34  [self.openGLContext flushBuffer];
35}
36
37#pragma mark - NSView overrides
38
39/**
40 * Declares that the view uses a flipped coordinate system, consistent with Flutter conventions.
41 */
42- (BOOL)isFlipped {
43  return YES;
44}
45
46- (BOOL)isOpaque {
47  return YES;
48}
49
50- (void)reshape {
51  [super reshape];
52  [_reshapeListener viewDidReshape:self];
53}
54
55- (BOOL)acceptsFirstResponder {
56  return YES;
57}
58
59@end
60