Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43355755
engine
提交
be7f80ef
E
engine
项目概览
weixin_43355755
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
be7f80ef
编写于
11月 19, 2020
作者:
K
Kaushik Iska
提交者:
GitHub
11月 19, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[macOS] Revert breaking change to FlutterEngine public API (#22592)
上级
9e6dae6a
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
186 addition
and
304 deletion
+186
-304
ci/licenses_golden/licenses_flutter
ci/licenses_golden/licenses_flutter
+0
-2
shell/platform/darwin/common/framework/Headers/FlutterTexture.h
...platform/darwin/common/framework/Headers/FlutterTexture.h
+1
-1
shell/platform/darwin/macos/BUILD.gn
shell/platform/darwin/macos/BUILD.gn
+0
-2
shell/platform/darwin/macos/framework/Headers/FlutterEngine.h
...l/platform/darwin/macos/framework/Headers/FlutterEngine.h
+1
-1
shell/platform/darwin/macos/framework/Source/FlutterEngine.mm
...l/platform/darwin/macos/framework/Source/FlutterEngine.mm
+158
-5
shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h
...rm/darwin/macos/framework/Source/FlutterEngine_Internal.h
+3
-4
shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.h
...orm/darwin/macos/framework/Source/FlutterOpenGLRenderer.h
+0
-85
shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.mm
...rm/darwin/macos/framework/Source/FlutterOpenGLRenderer.mm
+0
-187
shell/platform/darwin/macos/framework/Source/FlutterView.h
shell/platform/darwin/macos/framework/Source/FlutterView.h
+9
-4
shell/platform/darwin/macos/framework/Source/FlutterView.mm
shell/platform/darwin/macos/framework/Source/FlutterView.mm
+9
-8
shell/platform/darwin/macos/framework/Source/FlutterViewController.mm
...rm/darwin/macos/framework/Source/FlutterViewController.mm
+5
-5
未找到文件。
ci/licenses_golden/licenses_flutter
浏览文件 @
be7f80ef
...
...
@@ -1054,8 +1054,6 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterExter
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureGL.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/FlutterOpenGLRenderer.h
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.mm
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h
...
...
shell/platform/darwin/common/framework/Headers/FlutterTexture.h
浏览文件 @
be7f80ef
...
...
@@ -39,7 +39,7 @@ FLUTTER_EXPORT
/**
* Registers a `FlutterTexture` for usage in Flutter and returns an id that can be used to reference
* that texture when calling into Flutter with channels. Textures must be registered on the
* platform thread.
On success returns the pointer to the registered texture, else returns 0.
* platform thread.
*/
-
(
int64_t
)
registerTexture
:(
NSObject
<
FlutterTexture
>*
)
texture
;
/**
...
...
shell/platform/darwin/macos/BUILD.gn
浏览文件 @
be7f80ef
...
...
@@ -54,8 +54,6 @@ source_set("flutter_framework_source") {
"framework/Source/FlutterExternalTextureGL.mm",
"framework/Source/FlutterMouseCursorPlugin.h",
"framework/Source/FlutterMouseCursorPlugin.mm",
"framework/Source/FlutterOpenGLRenderer.h",
"framework/Source/FlutterOpenGLRenderer.mm",
"framework/Source/FlutterResizeSynchronizer.h",
"framework/Source/FlutterResizeSynchronizer.mm",
"framework/Source/FlutterSurfaceManager.h",
...
...
shell/platform/darwin/macos/framework/Headers/FlutterEngine.h
浏览文件 @
be7f80ef
...
...
@@ -21,7 +21,7 @@
* Coordinates a single instance of execution of a Flutter engine.
*/
FLUTTER_EXPORT
@interface
FlutterEngine
:
NSObject
<
FlutterPluginRegistry
>
@interface
FlutterEngine
:
NSObject
<
Flutter
TextureRegistry
,
Flutter
PluginRegistry
>
/**
* Initializes an engine with the given viewController.
...
...
shell/platform/darwin/macos/framework/Source/FlutterEngine.mm
浏览文件 @
be7f80ef
...
...
@@ -10,7 +10,6 @@
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h"
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureGL.h"
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.h"
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h"
#import "flutter/shell/platform/embedder/embedder.h"
...
...
@@ -38,11 +37,42 @@ static FlutterLocale FlutterLocaleFromNSLocale(NSLocale* locale) {
*/
-
(
void
)
sendUserLocales
;
/**
* Called by the engine to make the context the engine should draw into current.
*/
-
(
bool
)
engineCallbackOnMakeCurrent
;
/**
* Called by the engine to clear the context the engine should draw into.
*/
-
(
bool
)
engineCallbackOnClearCurrent
;
/**
* Called by the engine when the context's buffers should be swapped.
*/
-
(
bool
)
engineCallbackOnPresent
;
/**
* Called by the engine when framebuffer object ID is requested.
*/
-
(
uint32_t
)
engineCallbackOnFBO
:(
const
FlutterFrameInfo
*
)
info
;
/**
* Makes the resource context the current context.
*/
-
(
bool
)
engineCallbackOnMakeResourceCurrent
;
/**
* Handles a platform message from the engine.
*/
-
(
void
)
engineCallbackOnPlatformMessage
:(
const
FlutterPlatformMessage
*
)
message
;
/**
* Forwards texture copy request to the corresponding texture via |textureID|.
*/
-
(
BOOL
)
populateTextureWithIdentifier
:(
int64_t
)
textureID
openGLTexture
:(
FlutterOpenGLTexture
*
)
openGLTexture
;
/**
* Requests that the task be posted back the to the Flutter engine at the target time. The target
* time is in the clock used by the Flutter engine.
...
...
@@ -89,7 +119,7 @@ static FlutterLocale FlutterLocaleFromNSLocale(NSLocale* locale) {
}
-
(
id
<
FlutterTextureRegistry
>
)
textures
{
return
_flutterEngine
.
openGLRenderer
;
return
_flutterEngine
;
}
-
(
NSView
*
)
view
{
...
...
@@ -108,10 +138,38 @@ static FlutterLocale FlutterLocaleFromNSLocale(NSLocale* locale) {
// Callbacks provided to the engine. See the called methods for documentation.
#pragma mark - Static methods provided to engine configuration
static
bool
OnMakeCurrent
(
FlutterEngine
*
engine
)
{
return
[
engine
engineCallbackOnMakeCurrent
];
}
static
bool
OnClearCurrent
(
FlutterEngine
*
engine
)
{
return
[
engine
engineCallbackOnClearCurrent
];
}
static
bool
OnPresent
(
FlutterEngine
*
engine
)
{
return
[
engine
engineCallbackOnPresent
];
}
static
uint32_t
OnFBO
(
FlutterEngine
*
engine
,
const
FlutterFrameInfo
*
info
)
{
return
[
engine
engineCallbackOnFBO
:
info
];
}
static
bool
OnMakeResourceCurrent
(
FlutterEngine
*
engine
)
{
return
[
engine
engineCallbackOnMakeResourceCurrent
];
}
static
void
OnPlatformMessage
(
const
FlutterPlatformMessage
*
message
,
FlutterEngine
*
engine
)
{
[
engine
engineCallbackOnPlatformMessage
:
message
];
}
static
bool
OnAcquireExternalTexture
(
FlutterEngine
*
engine
,
int64_t
texture_identifier
,
size_t
width
,
size_t
height
,
FlutterOpenGLTexture
*
open_gl_texture
)
{
return
[
engine
populateTextureWithIdentifier
:
texture_identifier
openGLTexture
:
open_gl_texture
];
}
#pragma mark -
@implementation
FlutterEngine
{
...
...
@@ -121,12 +179,22 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
// The project being run by this engine.
FlutterDartProject
*
_project
;
// The context provided to the Flutter engine for resource loading.
NSOpenGLContext
*
_resourceContext
;
// The context that is owned by the currently displayed FlutterView. This is stashed in the engine
// so that the view doesn't need to be accessed from a background thread.
NSOpenGLContext
*
_mainOpenGLContext
;
// A mapping of channel names to the registered handlers for those channels.
NSMutableDictionary
<
NSString
*
,
FlutterBinaryMessageHandler
>*
_messageHandlers
;
// Whether the engine can continue running after the view controller is removed.
BOOL
_allowHeadlessExecution
;
// A mapping of textureID to internal FlutterExternalTextureGL adapter.
NSMutableDictionary
<
NSNumber
*
,
FlutterExternalTextureGL
*>*
_textures
;
// Pointer to the Dart AOT snapshot and instruction data.
_FlutterEngineAOTData
*
_aotData
;
}
...
...
@@ -143,10 +211,10 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
_project
=
project
?:
[[
FlutterDartProject
alloc
]
init
];
_messageHandlers
=
[[
NSMutableDictionary
alloc
]
init
];
_textures
=
[[
NSMutableDictionary
alloc
]
init
];
_allowHeadlessExecution
=
allowHeadlessExecution
;
_embedderAPI
.
struct_size
=
sizeof
(
FlutterEngineProcTable
);
FlutterEngineGetProcAddresses
(
&
_embedderAPI
);
_openGLRenderer
=
[[
FlutterOpenGLRenderer
alloc
]
initWithFlutterEngine
:
_engine
];
NSNotificationCenter
*
notificationCenter
=
[
NSNotificationCenter
defaultCenter
];
[
notificationCenter
addObserver
:
self
...
...
@@ -174,8 +242,17 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
return
NO
;
}
[
_openGLRenderer
attachToFlutterView
:
_viewController
.
flutterView
];
const
FlutterRendererConfig
rendererConfig
=
[
_openGLRenderer
createRendererConfig
];
const
FlutterRendererConfig
rendererConfig
=
{
.
type
=
kOpenGL
,
.
open_gl
.
struct_size
=
sizeof
(
FlutterOpenGLRendererConfig
),
.
open_gl
.
make_current
=
(
BoolCallback
)
OnMakeCurrent
,
.
open_gl
.
clear_current
=
(
BoolCallback
)
OnClearCurrent
,
.
open_gl
.
present
=
(
BoolCallback
)
OnPresent
,
.
open_gl
.
fbo_with_frame_info_callback
=
(
UIntFrameInfoCallback
)
OnFBO
,
.
open_gl
.
fbo_reset_after_present
=
true
,
.
open_gl
.
make_resource_current
=
(
BoolCallback
)
OnMakeResourceCurrent
,
.
open_gl
.
gl_external_texture_frame_callback
=
(
TextureFrameCallback
)
OnAcquireExternalTexture
,
};
// TODO(stuartmorgan): Move internal channel registration from FlutterViewController to here.
...
...
@@ -274,6 +351,15 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
}
}
-
(
void
)
setViewController
:(
FlutterViewController
*
)
controller
{
_viewController
=
controller
;
_mainOpenGLContext
=
controller
.
flutterView
.
openGLContext
;
if
(
!
controller
&&
!
_allowHeadlessExecution
)
{
[
self
shutDownEngine
];
_resourceContext
=
nil
;
}
}
-
(
id
<
FlutterBinaryMessenger
>
)
binaryMessenger
{
// TODO(stuartmorgan): Switch to FlutterBinaryMessengerRelay to avoid plugins
// keeping the engine alive.
...
...
@@ -286,6 +372,17 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
return
_engine
!=
nullptr
;
}
-
(
NSOpenGLContext
*
)
resourceContext
{
if
(
!
_resourceContext
)
{
NSOpenGLPixelFormatAttribute
attributes
[]
=
{
NSOpenGLPFAColorSize
,
24
,
NSOpenGLPFAAlphaSize
,
8
,
0
,
};
NSOpenGLPixelFormat
*
pixelFormat
=
[[
NSOpenGLPixelFormat
alloc
]
initWithAttributes
:
attributes
];
_resourceContext
=
[[
NSOpenGLContext
alloc
]
initWithFormat
:
pixelFormat
shareContext
:
nil
];
}
return
_resourceContext
;
}
-
(
void
)
updateDisplayConfig
{
if
(
!
_engine
)
{
return
;
...
...
@@ -364,6 +461,37 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
_embedderAPI
.
UpdateLocales
(
_engine
,
flutterLocaleList
.
data
(),
flutterLocaleList
.
size
());
}
-
(
bool
)
engineCallbackOnMakeCurrent
{
if
(
!
_mainOpenGLContext
)
{
return
false
;
}
[
_mainOpenGLContext
makeCurrentContext
];
return
true
;
}
-
(
uint32_t
)
engineCallbackOnFBO
:(
const
FlutterFrameInfo
*
)
info
{
CGSize
size
=
CGSizeMake
(
info
->
size
.
width
,
info
->
size
.
height
);
return
[
_viewController
.
flutterView
frameBufferIDForSize
:
size
];
}
-
(
bool
)
engineCallbackOnClearCurrent
{
[
NSOpenGLContext
clearCurrentContext
];
return
true
;
}
-
(
bool
)
engineCallbackOnPresent
{
if
(
!
_mainOpenGLContext
)
{
return
false
;
}
[
self
.
viewController
.
flutterView
present
];
return
true
;
}
-
(
bool
)
engineCallbackOnMakeResourceCurrent
{
[
self
.
resourceContext
makeCurrentContext
];
return
true
;
}
-
(
void
)
engineCallbackOnPlatformMessage
:(
const
FlutterPlatformMessage
*
)
message
{
NSData
*
messageData
=
[
NSData
dataWithBytesNoCopy
:(
void
*
)
message
->
message
length:
message
->
message_size
...
...
@@ -490,6 +618,31 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
return
[[
FlutterEngineRegistrar
alloc
]
initWithPlugin
:
pluginName
flutterEngine
:
self
];
}
#pragma mark - FlutterTextureRegistrar
-
(
BOOL
)
populateTextureWithIdentifier
:(
int64_t
)
textureID
openGLTexture
:(
FlutterOpenGLTexture
*
)
openGLTexture
{
return
[
_textures
[
@
(
textureID
)]
populateTexture
:
openGLTexture
];
}
-
(
int64_t
)
registerTexture
:(
id
<
FlutterTexture
>
)
texture
{
FlutterExternalTextureGL
*
FlutterTexture
=
[[
FlutterExternalTextureGL
alloc
]
initWithFlutterTexture
:
texture
];
int64_t
textureID
=
[
FlutterTexture
textureID
];
_embedderAPI
.
RegisterExternalTexture
(
_engine
,
textureID
);
_textures
[
@
(
textureID
)]
=
FlutterTexture
;
return
textureID
;
}
-
(
void
)
textureFrameAvailable
:(
int64_t
)
textureID
{
_embedderAPI
.
MarkExternalTextureFrameAvailable
(
_engine
,
textureID
);
}
-
(
void
)
unregisterTexture
:(
int64_t
)
textureID
{
_embedderAPI
.
UnregisterExternalTexture
(
_engine
,
textureID
);
[
_textures
removeObjectForKey
:
@
(
textureID
)];
}
#pragma mark - Task runner integration
-
(
void
)
postMainThreadTask
:(
FlutterTask
)
task
targetTimeInNanoseconds
:(
uint64_t
)
targetTime
{
...
...
shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h
浏览文件 @
be7f80ef
...
...
@@ -6,7 +6,6 @@
#import <Cocoa/Cocoa.h>
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.h"
#include "flutter/shell/platform/embedder/embedder.h"
@interface
FlutterEngine
()
...
...
@@ -17,10 +16,10 @@
@property
(
nonatomic
,
readonly
)
BOOL
running
;
/**
*
Provides the renderer config needed to initialize the engine and also handles external texture
*
managemen
t.
*
The resource context used by the engine for texture uploads. FlutterViews associated with this
*
engine should be created to share with this contex
t.
*/
@property
(
nonatomic
,
readonly
,
n
onnull
)
FlutterOpenGLRenderer
*
openGLRenderer
;
@property
(
nonatomic
,
readonly
,
n
ullable
)
NSOpenGLContext
*
resourceContext
;
/**
* Function pointers for interacting with the embedder.h API.
...
...
shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.h
已删除
100644 → 0
浏览文件 @
9e6dae6a
// 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>
#import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterEngine.h"
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
#import "flutter/shell/platform/embedder/embedder.h"
NS_ASSUME_NONNULL_BEGIN
/**
* Provides the renderer config needed to initialize the embedder engine and also handles external
* texture management. This is initialized during FlutterEngine creation and then attached to the
* FlutterView once the FlutterViewController is initializer.
*/
@interface
FlutterOpenGLRenderer
:
NSObject
<
FlutterTextureRegistry
>
/**
* The resource context used by the engine for texture uploads. FlutterViews associated with this
* engine should be created to share with this context.
*/
@property
(
nonatomic
,
readonly
,
nullable
)
NSOpenGLContext
*
resourceContext
;
/**
* The main OpenGL which will be used for rendering contents to the FlutterView.
*/
@property
(
readwrite
,
nonatomic
,
nonnull
)
NSOpenGLContext
*
openGLContext
;
/**
* Intializes the renderer with the given FlutterEngine.
*/
-
(
instancetype
)
initWithFlutterEngine
:(
FLUTTER_API_SYMBOL
(
FlutterEngine
))
engine
;
/**
* Attaches to the FlutterView and sets up the renderers main OpenGL context.
*/
-
(
void
)
attachToFlutterView
:(
FlutterView
*
)
view
;
/**
* Called by the engine to make the context the engine should draw into current.
*/
-
(
bool
)
makeCurrent
;
/**
* Called by the engine to clear the context the engine should draw into.
*/
-
(
bool
)
clearCurrent
;
/**
* Called by the engine when the context's buffers should be swapped.
*/
-
(
bool
)
present
;
/**
* Called by the engine when framebuffer object ID is requested.
*/
-
(
uint32_t
)
getFBO
:(
const
FlutterFrameInfo
*
)
info
;
/**
* Makes the resource context the current context.
*/
-
(
bool
)
makeResourceCurrent
;
/**
* Called by the engine to unset the resource context.
*/
-
(
void
)
clearResourceContext
;
/**
* Populates the texture registry with the provided openGLTexture.
*/
-
(
BOOL
)
populateTextureWithIdentifier
:(
int64_t
)
textureID
openGLTexture
:(
FlutterOpenGLTexture
*
)
openGLTexture
;
/**
* Creates a FlutterRendererConfig that renders using OpenGL context(s) held
* by this class.
*/
-
(
FlutterRendererConfig
)
createRendererConfig
;
@end
NS_ASSUME_NONNULL_END
shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.mm
已删除
100644 → 0
浏览文件 @
9e6dae6a
// 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/FlutterOpenGLRenderer.h"
#include "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
#include "flutter/shell/platform/embedder/embedder.h"
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureGL.h"
#pragma mark - Static methods for openGL callbacks that require the engine.
static
bool
OnMakeCurrent
(
FlutterEngine
*
engine
)
{
return
[
engine
.
openGLRenderer
makeCurrent
];
}
static
bool
OnClearCurrent
(
FlutterEngine
*
engine
)
{
return
[
engine
.
openGLRenderer
clearCurrent
];
}
static
bool
OnPresent
(
FlutterEngine
*
engine
)
{
return
[
engine
.
openGLRenderer
present
];
}
static
uint32_t
OnFBO
(
FlutterEngine
*
engine
,
const
FlutterFrameInfo
*
info
)
{
return
[
engine
.
openGLRenderer
getFBO
:
info
];
}
static
bool
OnMakeResourceCurrent
(
FlutterEngine
*
engine
)
{
return
[
engine
.
openGLRenderer
makeResourceCurrent
];
}
static
bool
OnAcquireExternalTexture
(
FlutterEngine
*
engine
,
int64_t
textureIdentifier
,
size_t
width
,
size_t
height
,
FlutterOpenGLTexture
*
openGlTexture
)
{
return
[
engine
.
openGLRenderer
populateTextureWithIdentifier
:
textureIdentifier
openGLTexture:
openGlTexture
];
}
#pragma mark - FlutterOpenGLRenderer implementation.
@implementation
FlutterOpenGLRenderer
{
// The embedding-API-level engine object.
FLUTTER_API_SYMBOL
(
FlutterEngine
)
_engine
;
FlutterView
*
_flutterView
;
// The context that is owned by the currently displayed FlutterView. This is stashed
// in the renderer so that the view doesn't need to be accessed from a background thread.
NSOpenGLContext
*
_openGLContext
;
// The context provided to the Flutter engine for resource loading.
NSOpenGLContext
*
_resourceContext
;
// A mapping of textureID to internal FlutterExternalTextureGL adapter.
NSMutableDictionary
<
NSNumber
*
,
FlutterExternalTextureGL
*>*
_textures
;
FlutterEngineProcTable
_embedderAPI
;
}
-
(
instancetype
)
initWithFlutterEngine
:(
FLUTTER_API_SYMBOL
(
FlutterEngine
))
engine
{
self
=
[
super
init
];
if
(
self
)
{
_engine
=
engine
;
_textures
=
[[
NSMutableDictionary
alloc
]
init
];
}
return
self
;
}
-
(
void
)
attachToFlutterView
:(
FlutterView
*
)
view
{
_flutterView
=
view
;
}
-
(
bool
)
makeCurrent
{
if
(
!
_openGLContext
)
{
return
false
;
}
[
_openGLContext
makeCurrentContext
];
return
true
;
}
-
(
bool
)
clearCurrent
{
[
NSOpenGLContext
clearCurrentContext
];
return
true
;
}
-
(
bool
)
present
{
if
(
!
_openGLContext
)
{
return
false
;
}
[
_flutterView
present
];
return
true
;
}
-
(
uint32_t
)
getFBO
:(
const
FlutterFrameInfo
*
)
info
{
CGSize
size
=
CGSizeMake
(
info
->
size
.
width
,
info
->
size
.
height
);
return
[
_flutterView
frameBufferIDForSize
:
size
];
}
-
(
NSOpenGLContext
*
)
resourceContext
{
if
(
!
_resourceContext
)
{
NSOpenGLPixelFormatAttribute
attributes
[]
=
{
NSOpenGLPFAColorSize
,
24
,
NSOpenGLPFAAlphaSize
,
8
,
0
,
};
NSOpenGLPixelFormat
*
pixelFormat
=
[[
NSOpenGLPixelFormat
alloc
]
initWithAttributes
:
attributes
];
_resourceContext
=
[[
NSOpenGLContext
alloc
]
initWithFormat
:
pixelFormat
shareContext
:
nil
];
}
return
_resourceContext
;
}
-
(
NSOpenGLContext
*
)
openGLContext
{
if
(
!
_openGLContext
)
{
NSOpenGLContext
*
shareContext
=
[
self
resourceContext
];
_openGLContext
=
[[
NSOpenGLContext
alloc
]
initWithFormat
:
shareContext
.
pixelFormat
shareContext:
shareContext
];
}
return
_openGLContext
;
}
-
(
bool
)
makeResourceCurrent
{
[
self
.
resourceContext
makeCurrentContext
];
return
true
;
}
-
(
void
)
clearResourceContext
{
_resourceContext
=
nil
;
}
#pragma mark - FlutterTextureRegistrar
-
(
BOOL
)
populateTextureWithIdentifier
:(
int64_t
)
textureID
openGLTexture
:(
FlutterOpenGLTexture
*
)
openGLTexture
{
return
[
_textures
[
@
(
textureID
)]
populateTexture
:
openGLTexture
];
}
-
(
int64_t
)
registerTexture
:(
id
<
FlutterTexture
>
)
texture
{
FlutterExternalTextureGL
*
FlutterTexture
=
[[
FlutterExternalTextureGL
alloc
]
initWithFlutterTexture
:
texture
];
int64_t
textureID
=
[
FlutterTexture
textureID
];
auto
success
=
_embedderAPI
.
RegisterExternalTexture
(
_engine
,
textureID
);
if
(
success
==
FlutterEngineResult
::
kSuccess
)
{
_textures
[
@
(
textureID
)]
=
FlutterTexture
;
return
textureID
;
}
else
{
NSLog
(
@"Unable to register the texture with id: %lld."
,
textureID
);
return
0
;
}
}
-
(
void
)
textureFrameAvailable
:(
int64_t
)
textureID
{
auto
success
=
_embedderAPI
.
MarkExternalTextureFrameAvailable
(
_engine
,
textureID
);
if
(
success
!=
FlutterEngineResult
::
kSuccess
)
{
NSLog
(
@"Unable to mark texture with id %lld as available."
,
textureID
);
}
}
-
(
void
)
unregisterTexture
:(
int64_t
)
textureID
{
auto
success
=
_embedderAPI
.
UnregisterExternalTexture
(
_engine
,
textureID
);
if
(
success
==
FlutterEngineResult
::
kSuccess
)
{
[
_textures
removeObjectForKey
:
@
(
textureID
)];
}
else
{
NSLog
(
@"Unable to unregister texture with id: %lld."
,
textureID
);
}
}
#pragma mark - Helper methods to create rendering config for embedder.
-
(
FlutterRendererConfig
)
createRendererConfig
{
const
FlutterRendererConfig
rendererConfig
=
{
.
type
=
kOpenGL
,
.
open_gl
.
struct_size
=
sizeof
(
FlutterOpenGLRendererConfig
),
.
open_gl
.
make_current
=
reinterpret_cast
<
BoolCallback
>
(
OnMakeCurrent
),
.
open_gl
.
clear_current
=
reinterpret_cast
<
BoolCallback
>
(
OnClearCurrent
),
.
open_gl
.
present
=
reinterpret_cast
<
BoolCallback
>
(
OnPresent
),
.
open_gl
.
fbo_with_frame_info_callback
=
reinterpret_cast
<
UIntFrameInfoCallback
>
(
OnFBO
),
.
open_gl
.
fbo_reset_after_present
=
true
,
.
open_gl
.
make_resource_current
=
reinterpret_cast
<
BoolCallback
>
(
OnMakeResourceCurrent
),
.
open_gl
.
gl_external_texture_frame_callback
=
reinterpret_cast
<
TextureFrameCallback
>
(
OnAcquireExternalTexture
),
};
return
rendererConfig
;
}
@end
shell/platform/darwin/macos/framework/Source/FlutterView.h
浏览文件 @
be7f80ef
...
...
@@ -20,14 +20,19 @@
*/
@interface
FlutterView
:
NSView
/**
* The OpenGL context of backing surface.
*/
@property
(
readwrite
,
nonatomic
,
nonnull
)
NSOpenGLContext
*
openGLContext
;
-
(
nullable
instancetype
)
initWithFrame
:(
NSRect
)
frame
mainContext
:(
nonnull
NSOpenGLContext
*
)
main
Context
shareContext
:(
nonnull
NSOpenGLContext
*
)
share
Context
reshapeListener
:(
nonnull
id
<
FlutterViewReshapeListener
>
)
reshapeListener
NS_DESIGNATED_INITIALIZER
;
-
(
nullable
instancetype
)
initWith
MainContext
:(
nonnull
NSOpenGLContext
*
)
main
Context
reshapeListener
:
(
nonnull
id
<
FlutterViewReshapeListener
>
)
reshapeListener
;
-
(
nullable
instancetype
)
initWith
ShareContext
:(
nonnull
NSOpenGLContext
*
)
share
Context
reshapeListener
:
(
nonnull
id
<
FlutterViewReshapeListener
>
)
reshapeListener
;
-
(
nullable
instancetype
)
initWithFrame
:(
NSRect
)
frameRect
pixelFormat
:(
nullable
NSOpenGLPixelFormat
*
)
format
NS_UNAVAILABLE
;
...
...
shell/platform/darwin/macos/framework/Source/FlutterView.mm
浏览文件 @
be7f80ef
...
...
@@ -15,29 +15,30 @@
__weak
id
<
FlutterViewReshapeListener
>
_reshapeListener
;
FlutterResizeSynchronizer
*
_resizeSynchronizer
;
FlutterSurfaceManager
*
_surfaceManager
;
NSOpenGLContext
*
_openGLContext
;
}
@end
@implementation
FlutterView
-
(
instancetype
)
initWith
MainContext
:(
NSOpenGLContext
*
)
main
Context
reshapeListener
:(
id
<
FlutterViewReshapeListener
>
)
reshapeListener
{
return
[
self
initWithFrame
:
NSZeroRect
mainContext
:
main
Context
reshapeListener
:
reshapeListener
];
-
(
instancetype
)
initWith
ShareContext
:(
NSOpenGLContext
*
)
share
Context
reshapeListener
:(
id
<
FlutterViewReshapeListener
>
)
reshapeListener
{
return
[
self
initWithFrame
:
NSZeroRect
shareContext
:
share
Context
reshapeListener
:
reshapeListener
];
}
-
(
instancetype
)
initWithFrame
:(
NSRect
)
frame
mainContext
:(
NSOpenGLContext
*
)
main
Context
shareContext
:(
NSOpenGLContext
*
)
share
Context
reshapeListener
:(
id
<
FlutterViewReshapeListener
>
)
reshapeListener
{
self
=
[
super
initWithFrame
:
frame
];
if
(
self
)
{
_openGLContext
=
mainContext
;
self
.
openGLContext
=
[[
NSOpenGLContext
alloc
]
initWithFormat
:
shareContext
.
pixelFormat
shareContext:
shareContext
];
[
self
setWantsLayer
:
YES
];
_resizeSynchronizer
=
[[
FlutterResizeSynchronizer
alloc
]
initWithDelegate
:
self
];
_surfaceManager
=
[[
FlutterSurfaceManager
alloc
]
initWithLayer
:
self
.
layer
openGLContext:
_
openGLContext
];
openGLContext:
self
.
openGLContext
];
_reshapeListener
=
reshapeListener
;
}
...
...
@@ -45,7 +46,7 @@
}
-
(
void
)
resizeSynchronizerFlush
:(
FlutterResizeSynchronizer
*
)
synchronizer
{
MacOSGLContextSwitch
context_switch
(
_
openGLContext
);
MacOSGLContextSwitch
context_switch
(
self
.
openGLContext
);
glFlush
();
}
...
...
shell/platform/darwin/macos/framework/Source/FlutterViewController.mm
浏览文件 @
be7f80ef
...
...
@@ -239,13 +239,13 @@ static void CommonInit(FlutterViewController* controller) {
}
-
(
void
)
loadView
{
NSOpenGLContext
*
mainContext
=
_engine
.
openGLRenderer
.
openGL
Context
;
if
(
!
main
Context
)
{
NSLog
(
@"Unable to create FlutterView; no
GL
context available."
);
NSOpenGLContext
*
resourceContext
=
_engine
.
resource
Context
;
if
(
!
resource
Context
)
{
NSLog
(
@"Unable to create FlutterView; no
resource
context available."
);
return
;
}
FlutterView
*
flutterView
=
[[
FlutterView
alloc
]
initWith
MainContext
:
main
Context
reshapeListener:
self
];
FlutterView
*
flutterView
=
[[
FlutterView
alloc
]
initWith
ShareContext
:
resource
Context
reshapeListener:
self
];
self
.
view
=
flutterView
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录