Create FlutterFrameBufferProvider class. (flutter/engine#22656)
This commit is contained in:
@@ -1054,6 +1054,8 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEngin
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureGL.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureGL.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterFrameBufferProvider.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterFrameBufferProvider.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMouseCursorPlugin.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMouseCursorPlugin.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h
|
||||
|
||||
@@ -52,6 +52,8 @@ source_set("flutter_framework_source") {
|
||||
"framework/Source/FlutterEngine_Internal.h",
|
||||
"framework/Source/FlutterExternalTextureGL.h",
|
||||
"framework/Source/FlutterExternalTextureGL.mm",
|
||||
"framework/Source/FlutterFrameBufferProvider.h",
|
||||
"framework/Source/FlutterFrameBufferProvider.mm",
|
||||
"framework/Source/FlutterMouseCursorPlugin.h",
|
||||
"framework/Source/FlutterMouseCursorPlugin.mm",
|
||||
"framework/Source/FlutterResizeSynchronizer.h",
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// 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 <Cocoa/Cocoa.h>
|
||||
|
||||
/**
|
||||
* Creates framebuffers and their backing textures.
|
||||
*/
|
||||
@interface FlutterFrameBufferProvider : NSObject
|
||||
|
||||
- (nullable instancetype)initWithOpenGLContext:(nonnull NSOpenGLContext*)opengLContext;
|
||||
|
||||
/**
|
||||
* Returns the id of the framebuffer.
|
||||
*/
|
||||
- (uint32_t)glFrameBufferId;
|
||||
|
||||
/**
|
||||
* Returns the id of the backing texture..
|
||||
*/
|
||||
- (uint32_t)glTextureId;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,53 @@
|
||||
// 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/FlutterFrameBufferProvider.h"
|
||||
|
||||
#include <OpenGL/gl.h>
|
||||
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h"
|
||||
|
||||
@interface FlutterFrameBufferProvider () {
|
||||
uint32_t _frameBufferId;
|
||||
uint32_t _backingTexture;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation FlutterFrameBufferProvider
|
||||
- (instancetype)initWithOpenGLContext:(NSOpenGLContext*)openGLContext {
|
||||
if (self = [super init]) {
|
||||
MacOSGLContextSwitch context_switch(openGLContext);
|
||||
|
||||
glGenFramebuffers(1, &_frameBufferId);
|
||||
glGenTextures(1, &_backingTexture);
|
||||
|
||||
[self createFramebuffer];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)createFramebuffer {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _frameBufferId);
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, _backingTexture);
|
||||
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
|
||||
}
|
||||
|
||||
- (uint32_t)glFrameBufferId {
|
||||
return _frameBufferId;
|
||||
}
|
||||
|
||||
- (uint32_t)glTextureId {
|
||||
return _backingTexture;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
glDeleteFramebuffers(1, &_frameBufferId);
|
||||
glDeleteTextures(1, &_backingTexture);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterFrameBufferProvider.h"
|
||||
|
||||
#include <OpenGL/gl.h>
|
||||
|
||||
@@ -20,9 +21,9 @@ enum {
|
||||
CALayer* _contentLayer;
|
||||
|
||||
NSOpenGLContext* _openGLContext;
|
||||
uint32_t _frameBufferId[kFlutterSurfaceManagerBufferCount];
|
||||
uint32_t _backingTexture[kFlutterSurfaceManagerBufferCount];
|
||||
|
||||
IOSurfaceRef _ioSurface[kFlutterSurfaceManagerBufferCount];
|
||||
FlutterFrameBufferProvider* _frameBuffers[kFlutterSurfaceManagerBufferCount];
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -39,27 +40,12 @@ enum {
|
||||
_contentLayer = [[CALayer alloc] init];
|
||||
[_containingLayer addSublayer:_contentLayer];
|
||||
|
||||
MacOSGLContextSwitch context_switch(openGLContext);
|
||||
|
||||
glGenFramebuffers(2, _frameBufferId);
|
||||
glGenTextures(2, _backingTexture);
|
||||
|
||||
[self createFramebuffer:_frameBufferId[0] withBackingTexture:_backingTexture[0]];
|
||||
[self createFramebuffer:_frameBufferId[1] withBackingTexture:_backingTexture[1]];
|
||||
_frameBuffers[0] = [[FlutterFrameBufferProvider alloc] initWithOpenGLContext:_openGLContext];
|
||||
_frameBuffers[1] = [[FlutterFrameBufferProvider alloc] initWithOpenGLContext:_openGLContext];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)createFramebuffer:(uint32_t)fbo withBackingTexture:(uint32_t)texture {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture);
|
||||
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
|
||||
}
|
||||
|
||||
- (void)ensureSurfaceSize:(CGSize)size {
|
||||
if (CGSizeEqualToSize(size, _surfaceSize)) {
|
||||
return;
|
||||
@@ -88,16 +74,16 @@ enum {
|
||||
};
|
||||
_ioSurface[i] = IOSurfaceCreate((CFDictionaryRef)options);
|
||||
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, _backingTexture[i]);
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, [_frameBuffers[i] glTextureId]);
|
||||
|
||||
CGLTexImageIOSurface2D(CGLGetCurrentContext(), GL_TEXTURE_RECTANGLE_ARB, GL_RGBA,
|
||||
int(size.width), int(size.height), GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
|
||||
_ioSurface[i], 0 /* plane */);
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _frameBufferId[i]);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, [_frameBuffers[i] glFrameBufferId]);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB,
|
||||
_backingTexture[i], 0);
|
||||
[_frameBuffers[i] glTextureId], 0);
|
||||
|
||||
NSAssert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE,
|
||||
@"Framebuffer status check failed");
|
||||
@@ -114,14 +100,12 @@ enum {
|
||||
|
||||
std::swap(_ioSurface[kFlutterSurfaceManagerBackBuffer],
|
||||
_ioSurface[kFlutterSurfaceManagerFrontBuffer]);
|
||||
std::swap(_frameBufferId[kFlutterSurfaceManagerBackBuffer],
|
||||
_frameBufferId[kFlutterSurfaceManagerFrontBuffer]);
|
||||
std::swap(_backingTexture[kFlutterSurfaceManagerBackBuffer],
|
||||
_backingTexture[kFlutterSurfaceManagerFrontBuffer]);
|
||||
std::swap(_frameBuffers[kFlutterSurfaceManagerBackBuffer],
|
||||
_frameBuffers[kFlutterSurfaceManagerFrontBuffer]);
|
||||
}
|
||||
|
||||
- (uint32_t)glFrameBufferId {
|
||||
return _frameBufferId[kFlutterSurfaceManagerBackBuffer];
|
||||
return [_frameBuffers[kFlutterSurfaceManagerBackBuffer] glFrameBufferId];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
|
||||
Reference in New Issue
Block a user