33// found in the LICENSE file.
44
55#import " flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h"
6+ #import " flutter/shell/platform/darwin/macos/framework/Source/FlutterFrameBufferProvider.h"
67
78#include < OpenGL/gl.h>
89
@@ -20,9 +21,9 @@ @interface FlutterSurfaceManager () {
2021 CALayer * _contentLayer;
2122
2223 NSOpenGLContext * _openGLContext;
23- uint32_t _frameBufferId[kFlutterSurfaceManagerBufferCount ];
24- uint32_t _backingTexture[kFlutterSurfaceManagerBufferCount ];
24+
2525 IOSurfaceRef _ioSurface[kFlutterSurfaceManagerBufferCount ];
26+ FlutterFrameBufferProvider* _frameBuffers[kFlutterSurfaceManagerBufferCount ];
2627}
2728@end
2829
@@ -39,27 +40,12 @@ - (instancetype)initWithLayer:(CALayer*)containingLayer
3940 _contentLayer = [[CALayer alloc ] init ];
4041 [_containingLayer addSublayer: _contentLayer];
4142
42- MacOSGLContextSwitch context_switch (openGLContext);
43-
44- glGenFramebuffers (2 , _frameBufferId);
45- glGenTextures (2 , _backingTexture);
46-
47- [self createFramebuffer: _frameBufferId[0 ] withBackingTexture: _backingTexture[0 ]];
48- [self createFramebuffer: _frameBufferId[1 ] withBackingTexture: _backingTexture[1 ]];
43+ _frameBuffers[0 ] = [[FlutterFrameBufferProvider alloc ] initWithOpenGLContext: _openGLContext];
44+ _frameBuffers[1 ] = [[FlutterFrameBufferProvider alloc ] initWithOpenGLContext: _openGLContext];
4945 }
5046 return self;
5147}
5248
53- - (void )createFramebuffer : (uint32_t )fbo withBackingTexture : (uint32_t )texture {
54- glBindFramebuffer (GL_FRAMEBUFFER, fbo);
55- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
56- glTexParameterf (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
57- glTexParameterf (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
58- glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
59- glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
60- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0 );
61- }
62-
6349- (void )ensureSurfaceSize : (CGSize)size {
6450 if (CGSizeEqualToSize (size, _surfaceSize)) {
6551 return ;
@@ -88,16 +74,16 @@ - (void)ensureSurfaceSize:(CGSize)size {
8874 };
8975 _ioSurface[i] = IOSurfaceCreate ((CFDictionaryRef)options);
9076
91- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, _backingTexture[i ]);
77+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, [_frameBuffers[i] glTextureId ]);
9278
9379 CGLTexImageIOSurface2D (CGLGetCurrentContext (), GL_TEXTURE_RECTANGLE_ARB, GL_RGBA,
9480 int (size.width ), int (size.height ), GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
9581 _ioSurface[i], 0 /* plane */ );
9682 glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0 );
9783
98- glBindFramebuffer (GL_FRAMEBUFFER, _frameBufferId[i ]);
84+ glBindFramebuffer (GL_FRAMEBUFFER, [_frameBuffers[i] glFrameBufferId ]);
9985 glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB,
100- _backingTexture[i ], 0 );
86+ [_frameBuffers[i] glTextureId ], 0 );
10187
10288 NSAssert (glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE,
10389 @"Framebuffer status check failed");
@@ -114,14 +100,12 @@ - (void)swapBuffers {
114100
115101 std::swap (_ioSurface[kFlutterSurfaceManagerBackBuffer ],
116102 _ioSurface[kFlutterSurfaceManagerFrontBuffer ]);
117- std::swap (_frameBufferId[kFlutterSurfaceManagerBackBuffer ],
118- _frameBufferId[kFlutterSurfaceManagerFrontBuffer ]);
119- std::swap (_backingTexture[kFlutterSurfaceManagerBackBuffer ],
120- _backingTexture[kFlutterSurfaceManagerFrontBuffer ]);
103+ std::swap (_frameBuffers[kFlutterSurfaceManagerBackBuffer ],
104+ _frameBuffers[kFlutterSurfaceManagerFrontBuffer ]);
121105}
122106
123107- (uint32_t )glFrameBufferId {
124- return _frameBufferId[ kFlutterSurfaceManagerBackBuffer ];
108+ return [_frameBuffers[ kFlutterSurfaceManagerBackBuffer ] glFrameBufferId ];
125109}
126110
127111- (void )dealloc {
0 commit comments