forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlutterResizableBackingStoreProvider.mm
96 lines (75 loc) · 2.84 KB
/
FlutterResizableBackingStoreProvider.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterResizableBackingStoreProvider.h"
#import <OpenGL/gl.h>
#import <QuartzCore/QuartzCore.h>
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h"
#import "flutter/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h"
@implementation FlutterOpenGLResizableBackingStoreProvider {
NSOpenGLContext* _mainContext;
id<FlutterSurfaceManager> _surfaceManager;
}
- (instancetype)initWithMainContext:(NSOpenGLContext*)mainContext layer:(CALayer*)layer {
self = [super init];
if (self) {
_mainContext = mainContext;
_surfaceManager = [[FlutterGLSurfaceManager alloc] initWithLayer:layer
openGLContext:_mainContext];
}
return self;
}
- (void)onBackingStoreResized:(CGSize)size {
[_surfaceManager ensureSurfaceSize:size];
}
- (FlutterRenderBackingStore*)backingStore {
return [_surfaceManager renderBuffer];
}
- (void)resizeSynchronizerFlush:(nonnull FlutterResizeSynchronizer*)synchronizer {
MacOSGLContextSwitch context_switch(_mainContext);
glFlush();
}
- (void)resizeSynchronizerCommit:(nonnull FlutterResizeSynchronizer*)synchronizer {
[CATransaction begin];
[CATransaction setDisableActions:YES];
[_surfaceManager swapBuffers];
[CATransaction commit];
}
@end
@implementation FlutterMetalResizableBackingStoreProvider {
id<MTLDevice> _device;
id<MTLCommandQueue> _commandQueue;
id<FlutterSurfaceManager> _surfaceManager;
}
- (instancetype)initWithDevice:(id<MTLDevice>)device
commandQueue:(id<MTLCommandQueue>)commandQueue
metalLayer:(CAMetalLayer*)layer {
self = [super init];
if (self) {
_device = device;
_commandQueue = commandQueue;
_surfaceManager = [[FlutterMetalSurfaceManager alloc] initWithDevice:device
commandQueue:commandQueue
metalLayer:layer];
}
return self;
}
- (void)onBackingStoreResized:(CGSize)size {
[_surfaceManager ensureSurfaceSize:size];
}
- (FlutterRenderBackingStore*)backingStore {
return [_surfaceManager renderBuffer];
}
- (void)resizeSynchronizerFlush:(nonnull FlutterResizeSynchronizer*)synchronizer {
// no-op when using Metal rendering backend.
}
- (void)resizeSynchronizerCommit:(nonnull FlutterResizeSynchronizer*)synchronizer {
[CATransaction begin];
[CATransaction setDisableActions:YES];
id<MTLCommandBuffer> commandBuffer = [_commandQueue commandBuffer];
[commandBuffer commit];
[commandBuffer waitUntilScheduled];
[_surfaceManager swapBuffers];
[CATransaction commit];
}
@end