Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
acc24667
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
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,发现更多精彩内容 >>
未验证
提交
acc24667
编写于
11月 04, 2020
作者:
M
Matej Knopp
提交者:
GitHub
11月 04, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix code style issues in MacOS embedder (#22270)
上级
122f2425
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
262 addition
and
194 deletion
+262
-194
ci/licenses_golden/licenses_flutter
ci/licenses_golden/licenses_flutter
+2
-2
shell/platform/darwin/macos/BUILD.gn
shell/platform/darwin/macos/BUILD.gn
+2
-4
shell/platform/darwin/macos/framework/Source/FlutterEngine.mm
...l/platform/darwin/macos/framework/Source/FlutterEngine.mm
+11
-2
shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h
...darwin/macos/framework/Source/FlutterResizeSynchronizer.h
+60
-41
shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm
...arwin/macos/framework/Source/FlutterResizeSynchronizer.mm
+64
-50
shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h
...orm/darwin/macos/framework/Source/FlutterSurfaceManager.h
+6
-1
shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm
...rm/darwin/macos/framework/Source/FlutterSurfaceManager.mm
+42
-35
shell/platform/darwin/macos/framework/Source/FlutterView.h
shell/platform/darwin/macos/framework/Source/FlutterView.h
+18
-1
shell/platform/darwin/macos/framework/Source/FlutterView.mm
shell/platform/darwin/macos/framework/Source/FlutterView.mm
+18
-18
shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h
...form/darwin/macos/framework/Source/MacOSGLContextSwitch.h
+21
-0
shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.mm
...orm/darwin/macos/framework/Source/MacOSGLContextSwitch.mm
+18
-0
shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.h
.../darwin/macos/framework/Source/MacOSSwitchableGLContext.h
+0
-21
shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.mm
...darwin/macos/framework/Source/MacOSSwitchableGLContext.mm
+0
-19
未找到文件。
ci/licenses_golden/licenses_flutter
浏览文件 @
acc24667
...
...
@@ -1068,8 +1068,8 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/MacOS
SwitchableGLContext
.h
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/MacOS
SwitchableGLContext
.mm
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/MacOS
GLContextSwitch
.h
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/MacOS
GLContextSwitch
.mm
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/fixtures/flutter_desktop_test.dart
FILE: ../../../flutter/shell/platform/darwin/macos/framework/module.modulemap
FILE: ../../../flutter/shell/platform/embedder/assets/EmbedderInfo.plist
...
...
shell/platform/darwin/macos/BUILD.gn
浏览文件 @
acc24667
...
...
@@ -66,15 +66,13 @@ source_set("flutter_framework_source") {
"framework/Source/FlutterView.mm",
"framework/Source/FlutterViewController.mm",
"framework/Source/FlutterViewController_Internal.h",
"framework/Source/MacOS
SwitchableGLContext
.h",
"framework/Source/MacOS
SwitchableGLContext
.mm",
"framework/Source/MacOS
GLContextSwitch
.h",
"framework/Source/MacOS
GLContextSwitch
.mm",
]
sources += _flutter_framework_headers
deps = [
"//flutter/flow:flow",
"//flutter/fml:fml",
"//flutter/shell/platform/common/cpp:common_cpp_switches",
"//flutter/shell/platform/darwin/common:framework_shared",
"//flutter/shell/platform/embedder:embedder_as_internal_library",
...
...
shell/platform/darwin/macos/framework/Source/FlutterEngine.mm
浏览文件 @
acc24667
...
...
@@ -52,6 +52,11 @@ static FlutterLocale FlutterLocaleFromNSLocale(NSLocale* locale) {
*/
-
(
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.
*/
...
...
@@ -146,8 +151,7 @@ static bool OnPresent(FlutterEngine* engine) {
}
static
uint32_t
OnFBO
(
FlutterEngine
*
engine
,
const
FlutterFrameInfo
*
info
)
{
CGSize
size
=
CGSizeMake
(
info
->
size
.
width
,
info
->
size
.
height
);
return
[
engine
.
viewController
.
flutterView
getFrameBufferIdForSize
:
size
];
return
[
engine
engineCallbackOnFBO
:
info
];
}
static
bool
OnMakeResourceCurrent
(
FlutterEngine
*
engine
)
{
...
...
@@ -469,6 +473,11 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
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
;
...
...
shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h
浏览文件 @
acc24667
// 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>
@class
FlutterResizeSynchronizer
;
/**
* Implemented by FlutterView.
*/
@protocol
FlutterResizeSynchronizerDelegate
// Invoked on raster thread; Delegate should flush the OpenGL context
-
(
void
)
resizeSynchronizerFlush
:(
FlutterResizeSynchronizer
*
)
synchronizer
;
/**
* Invoked on raster thread; Delegate should flush the OpenGL context.
*/
-
(
void
)
resizeSynchronizerFlush
:(
nonnull
FlutterResizeSynchronizer
*
)
synchronizer
;
// Invoked on platform thread; Delegate should flip the surfaces
-
(
void
)
resizeSynchronizerCommit
:(
FlutterResizeSynchronizer
*
)
synchronizer
;
/**
* Invoked on platform thread; Delegate should flip the surfaces.
*/
-
(
void
)
resizeSynchronizerCommit
:(
nonnull
FlutterResizeSynchronizer
*
)
synchronizer
;
@end
// Encapsulates the logic for blocking platform thread during window resize as
// well as synchronizing the raster and platform thread during commit (presenting frame)
//
// Flow during window resize
//
// 1. Platform thread calls [synchronizer beginResize:notify:]
// This will hold the platform thread until we're ready to display contents.
// 2. Raster thread calls [synchronizer shouldEnsureSurfaceForSize:] with target size
// This will return false for any size other than target size
// 3. Raster thread calls [synchronizer requestCommit]
// Any commit calls before shouldEnsureSurfaceForSize: is called with the right
// size are simply ignored; There's no point rasterizing and displaying frames
// with wrong size.
// Both delegate methods (flush/commit) will be invoked before beginResize returns
//
// Flow during regular operation (no resizing)
//
// 1. Raster thread calls [synchronizer requestCommit]
// This will invoke [delegate flush:] on raster thread and
// [delegate commit:] on platform thread. The requestCommit call will be blocked
// until this is done. This is necessary to ensure that rasterizer won't start
// rasterizing next frame before we flipped the surface, which must be performed
// on platform thread
/**
* Encapsulates the logic for blocking platform thread during window resize as
* well as synchronizing the raster and platform thread during commit (presenting frame).
*
* Flow during window resize
*
* 1. Platform thread calls [synchronizer beginResize:notify:]
* This will hold the platform thread until we're ready to display contents.
* 2. Raster thread calls [synchronizer shouldEnsureSurfaceForSize:] with target size
* This will return false for any size other than target size
* 3. Raster thread calls [synchronizer requestCommit]
* Any commit calls before shouldEnsureSurfaceForSize: is called with the right
* size are simply ignored; There's no point rasterizing and displaying frames
* with wrong size.
* Both delegate methods (flush/commit) will be invoked before beginResize returns
*
* Flow during regular operation (no resizing)
*
* 1. Raster thread calls [synchronizer requestCommit]
* This will invoke [delegate flush:] on raster thread and
* [delegate commit:] on platform thread. The requestCommit call will be blocked
* until this is done. This is necessary to ensure that rasterizer won't start
* rasterizing next frame before we flipped the surface, which must be performed
* on platform thread
*/
@interface
FlutterResizeSynchronizer
:
NSObject
-
(
instancetype
)
initWithDelegate
:(
id
<
FlutterResizeSynchronizerDelegate
>
)
delegate
;
-
(
nullable
instancetype
)
initWithDelegate
:(
nonnull
id
<
FlutterResizeSynchronizerDelegate
>
)
delegate
;
// Blocks the platform thread until
// - shouldEnsureSurfaceForSize is called with proper size and
// - requestCommit is called
// All requestCommit calls before `shouldEnsureSurfaceForSize` is called with
// expected size are ignored;
// The notify block is invoked immediately after synchronizer mutex is acquired
-
(
void
)
beginResize
:(
CGSize
)
size
notify
:(
dispatch_block_t
)
notify
;
/**
* Blocks the platform thread until
* - shouldEnsureSurfaceForSize is called with proper size and
* - requestCommit is called
* All requestCommit calls before `shouldEnsureSurfaceForSize` is called with
* expected size are ignored;
* The notify block is invoked immediately after synchronizer mutex is acquired.
*/
-
(
void
)
beginResize
:(
CGSize
)
size
notify
:(
nonnull
dispatch_block_t
)
notify
;
// Returns whether the view should ensure surfaces with given size;
// This will be false during resizing for any size other than size specified
// during beginResize
-
(
bool
)
shouldEnsureSurfaceForSize
:(
CGSize
)
size
;
/**
* Returns whether the view should ensure surfaces with given size;
* This will be false during resizing for any size other than size specified
* during beginResize.
*/
-
(
BOOL
)
shouldEnsureSurfaceForSize
:(
CGSize
)
size
;
// Called from rasterizer thread, will block until delegate resizeSynchronizerCommit:
// method is called (on platform thread)
/**
* Called from rasterizer thread, will block until delegate resizeSynchronizerCommit:
* method is called (on platform thread).
*/
-
(
void
)
requestCommit
;
@end
shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm
浏览文件 @
acc24667
// 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/FlutterResizeSynchronizer.h"
#i
mport
<mutex>
#i
nclude
<mutex>
@interface
FlutterResizeSynchronizer
()
{
uint32_t
cookie
;
// counter to detect stale callbacks
// Counter to detect stale callbacks.
uint32_t
_cookie
;
std
::
mutex
_mutex
;
// Used to block [beginResize:].
std
::
condition_variable
_condBlockBeginResize
;
// Used to block [requestCommit].
std
::
condition_variable
_condBlockRequestCommit
;
// If NO, requestCommit calls are ignored until shouldEnsureSurfaceForSize is called with
// proper size.
BOOL
_acceptingCommit
;
// Waiting for resize to finish.
BOOL
_waiting
;
std
::
mutex
mutex
;
std
::
condition_variable
condBlockBeginResize
;
// used to block [beginResize:]
std
::
condition_variable
condBlockRequestCommit
;
// used to block [requestCommit]
// RequestCommit was called and [delegate commit:] must be performed on platform thread.
BOOL
_pendingCommit
;
bool
acceptingCommit
;
// if false, requestCommit calls are ignored until
// shouldEnsureSurfaceForSize is called with proper size
bool
waiting
;
// waiting for resize to finish
bool
pendingCommit
;
// requestCommit was called and [delegate commit:] must be performed on
// platform thread
CGSize
newSize
;
// target size for resizing
// Target size for resizing.
CGSize
_newSize
;
__weak
id
<
FlutterResizeSynchronizerDelegate
>
delegate
;
__weak
id
<
FlutterResizeSynchronizerDelegate
>
_
delegate
;
}
@end
@implementation
FlutterResizeSynchronizer
-
(
instancetype
)
initWithDelegate
:(
id
<
FlutterResizeSynchronizerDelegate
>
)
delegate
_
{
-
(
instancetype
)
initWithDelegate
:(
id
<
FlutterResizeSynchronizerDelegate
>
)
delegate
{
if
(
self
=
[
super
init
])
{
acceptingCommit
=
true
;
delegate
=
delegate_
;
_acceptingCommit
=
YES
;
_delegate
=
delegate
;
}
return
self
;
}
-
(
void
)
beginResize
:(
CGSize
)
size
notify
:(
dispatch_block_t
)
notify
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex
);
if
(
!
delegate
)
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
_
mutex
);
if
(
!
_
delegate
)
{
return
;
}
++
cookie
;
++
_
cookie
;
// from now on, ignore all incoming commits until the block below gets
// scheduled on raster thread
acceptingCommit
=
false
;
_acceptingCommit
=
NO
;
// let pending commits finish to unblock the raster thread
pendingCommit
=
false
;
condBlockBeginResize
.
notify_all
();
_pendingCommit
=
NO
;
_
condBlockBeginResize
.
notify_all
();
// let the engine send resize notification
notify
();
newSize
=
size
;
_
newSize
=
size
;
waiting
=
true
;
_waiting
=
YES
;
condBlockRequestCommit
.
wait
(
lock
,
[
&
]
{
return
pendingCommit
;
});
_condBlockRequestCommit
.
wait
(
lock
,
[
&
]
{
return
_
pendingCommit
;
});
[
delegate
resizeSynchronizerFlush
:
self
];
[
delegate
resizeSynchronizerCommit
:
self
];
pendingCommit
=
false
;
condBlockBeginResize
.
notify_all
();
[
_
delegate
resizeSynchronizerFlush
:
self
];
[
_
delegate
resizeSynchronizerCommit
:
self
];
_pendingCommit
=
NO
;
_
condBlockBeginResize
.
notify_all
();
waiting
=
false
;
_waiting
=
NO
;
}
-
(
bool
)
shouldEnsureSurfaceForSize
:(
CGSize
)
size
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex
);
if
(
!
acceptingCommit
)
{
if
(
CGSizeEqualToSize
(
newSize
,
size
))
{
acceptingCommit
=
true
;
-
(
BOOL
)
shouldEnsureSurfaceForSize
:(
CGSize
)
size
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
_
mutex
);
if
(
!
_
acceptingCommit
)
{
if
(
CGSizeEqualToSize
(
_
newSize
,
size
))
{
_acceptingCommit
=
YES
;
}
}
return
acceptingCommit
;
return
_
acceptingCommit
;
}
-
(
void
)
requestCommit
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex
);
if
(
!
acceptingCommit
)
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
_
mutex
);
if
(
!
_
acceptingCommit
)
{
return
;
}
pendingCommit
=
true
;
if
(
waiting
)
{
// BeginResize is in progress, interrupt it and schedule commit call
condBlockRequestCommit
.
notify_all
();
condBlockBeginResize
.
wait
(
lock
,
[
&
]()
{
return
!
pendingCommit
;
});
_pendingCommit
=
YES
;
if
(
_
waiting
)
{
// BeginResize is in progress, interrupt it and schedule commit call
_
condBlockRequestCommit
.
notify_all
();
_condBlockBeginResize
.
wait
(
lock
,
[
&
]()
{
return
!
_
pendingCommit
;
});
}
else
{
// No resize, schedule commit on platform thread and wait until either done
// or interrupted by incoming BeginResize
[
delegate
resizeSynchronizerFlush
:
self
];
dispatch_async
(
dispatch_get_main_queue
(),
[
self
,
cookie
_
=
cookie
]
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex
);
if
(
cookie
_
==
cookie
)
{
if
(
delegate
)
{
[
delegate
resizeSynchronizerCommit
:
self
];
[
_
delegate
resizeSynchronizerFlush
:
self
];
dispatch_async
(
dispatch_get_main_queue
(),
[
self
,
cookie
=
_
cookie
]
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
_
mutex
);
if
(
cookie
==
_
cookie
)
{
if
(
_
delegate
)
{
[
_
delegate
resizeSynchronizerCommit
:
self
];
}
pendingCommit
=
false
;
condBlockBeginResize
.
notify_all
();
_pendingCommit
=
NO
;
_
condBlockBeginResize
.
notify_all
();
}
});
condBlockBeginResize
.
wait
(
lock
,
[
&
]()
{
return
!
pendingCommit
;
});
_condBlockBeginResize
.
wait
(
lock
,
[
&
]()
{
return
!
_
pendingCommit
;
});
}
}
...
...
shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h
浏览文件 @
acc24667
// 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>
// Manages the IOSurfaces for FlutterView
@interface
FlutterSurfaceManager
:
NSObject
-
(
instancetype
)
initWithLayer
:(
CALayer
*
)
layer
openGLContext
:(
NSOpenGLContext
*
)
opengLContext
;
-
(
nullable
instancetype
)
initWithLayer
:(
nonnull
CALayer
*
)
containingLayer
openGLContext
:(
nonnull
NSOpenGLContext
*
)
opengLContext
;
-
(
void
)
ensureSurfaceSize
:(
CGSize
)
size
;
-
(
void
)
swapBuffers
;
...
...
shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm
浏览文件 @
acc24667
// 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/FlutterSurfaceManager.h"
#import "flutter/fml/logging.h"
#import "flutter/shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.h"
#include <OpenGL/gl.h>
#import "flutter/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h"
enum
{
kF
ront
=
0
,
k
Back
=
1
,
kBufferCount
,
kF
lutterSurfaceManagerFrontBuffer
=
0
,
k
FlutterSurfaceManagerBackBuffer
=
1
,
k
FlutterSurfaceManager
BufferCount
,
};
@interface
FlutterSurfaceManager
()
{
CGSize
surfaceSize
;
CALayer
*
l
ayer
;
// provided (parent layer)
CALayer
*
contentLayer
;
NSOpenGLContext
*
openGLContext
;
uint32_t
_frameBufferId
[
kBufferCount
];
uint32_t
_backingTexture
[
kBufferCount
];
IOSurfaceRef
_ioSurface
[
kBufferCount
];
CGSize
_
surfaceSize
;
CALayer
*
_containingL
ayer
;
// provided (parent layer)
CALayer
*
_
contentLayer
;
NSOpenGLContext
*
_
openGLContext
;
uint32_t
_frameBufferId
[
k
FlutterSurfaceManager
BufferCount
];
uint32_t
_backingTexture
[
k
FlutterSurfaceManager
BufferCount
];
IOSurfaceRef
_ioSurface
[
k
FlutterSurfaceManager
BufferCount
];
}
@end
@implementation
FlutterSurfaceManager
-
(
instancetype
)
initWithLayer
:(
CALayer
*
)
layer_
openGLContext
:(
NSOpenGLContext
*
)
opengLContext_
{
-
(
instancetype
)
initWithLayer
:(
CALayer
*
)
containingLayer
openGLContext
:(
NSOpenGLContext
*
)
openGLContext
{
if
(
self
=
[
super
init
])
{
layer
=
layer_
;
openGLContext
=
opengLContext_
;
_containingLayer
=
containingLayer
;
_openGLContext
=
openGLContext
;
// Layer for content. This is separate from provided layer, because it needs to be flipped
// vertically if we render to OpenGL texture
contentLayer
=
[[
CALayer
alloc
]
init
];
[
layer_
addSublayer
:
contentLayer
];
_
contentLayer
=
[[
CALayer
alloc
]
init
];
[
_containingLayer
addSublayer
:
_
contentLayer
];
flutter
::
GLContextSwitch
context_switch
(
std
::
make_unique
<
MacOSSwitchableGLContext
>
(
opengLContext_
));
MacOSGLContextSwitch
context_switch
(
openGLContext
);
glGenFramebuffers
(
2
,
_frameBufferId
);
glGenTextures
(
2
,
_backingTexture
);
...
...
@@ -57,15 +61,14 @@ enum {
}
-
(
void
)
ensureSurfaceSize
:(
CGSize
)
size
{
if
(
CGSizeEqualToSize
(
size
,
surfaceSize
))
{
if
(
CGSizeEqualToSize
(
size
,
_
surfaceSize
))
{
return
;
}
surfaceSize
=
size
;
_
surfaceSize
=
size
;
flutter
::
GLContextSwitch
context_switch
(
std
::
make_unique
<
MacOSSwitchableGLContext
>
(
openGLContext
));
MacOSGLContextSwitch
context_switch
(
_openGLContext
);
for
(
int
i
=
0
;
i
<
kBufferCount
;
++
i
)
{
for
(
int
i
=
0
;
i
<
k
FlutterSurfaceManager
BufferCount
;
++
i
)
{
if
(
_ioSurface
[
i
])
{
CFRelease
(
_ioSurface
[
i
]);
}
...
...
@@ -96,29 +99,33 @@ enum {
glFramebufferTexture2D
(
GL_FRAMEBUFFER
,
GL_COLOR_ATTACHMENT0
,
GL_TEXTURE_RECTANGLE_ARB
,
_backingTexture
[
i
],
0
);
FML_DCHECK
(
glCheckFramebufferStatus
(
GL_FRAMEBUFFER
)
==
GL_FRAMEBUFFER_COMPLETE
);
NSAssert
(
glCheckFramebufferStatus
(
GL_FRAMEBUFFER
)
==
GL_FRAMEBUFFER_COMPLETE
,
@"Framebuffer status check failed"
);
}
}
-
(
void
)
swapBuffers
{
contentLayer
.
frame
=
l
ayer
.
bounds
;
_contentLayer
.
frame
=
_containingL
ayer
.
bounds
;
// The surface is an OpenGL texture, which means it has origin in bottom left corner
// and needs to be flipped vertically
contentLayer
.
transform
=
CATransform3DMakeScale
(
1
,
-
1
,
1
);
[
contentLayer
setContents
:(
__bridge
id
)
_ioSurface
[
kBack
]];
std
::
swap
(
_ioSurface
[
kBack
],
_ioSurface
[
kFront
]);
std
::
swap
(
_frameBufferId
[
kBack
],
_frameBufferId
[
kFront
]);
std
::
swap
(
_backingTexture
[
kBack
],
_backingTexture
[
kFront
]);
_contentLayer
.
transform
=
CATransform3DMakeScale
(
1
,
-
1
,
1
);
[
_contentLayer
setContents
:(
__bridge
id
)
_ioSurface
[
kFlutterSurfaceManagerBackBuffer
]];
std
::
swap
(
_ioSurface
[
kFlutterSurfaceManagerBackBuffer
],
_ioSurface
[
kFlutterSurfaceManagerFrontBuffer
]);
std
::
swap
(
_frameBufferId
[
kFlutterSurfaceManagerBackBuffer
],
_frameBufferId
[
kFlutterSurfaceManagerFrontBuffer
]);
std
::
swap
(
_backingTexture
[
kFlutterSurfaceManagerBackBuffer
],
_backingTexture
[
kFlutterSurfaceManagerFrontBuffer
]);
}
-
(
uint32_t
)
glFrameBufferId
{
return
_frameBufferId
[
k
Back
];
return
_frameBufferId
[
k
FlutterSurfaceManagerBackBuffer
];
}
-
(
void
)
dealloc
{
for
(
int
i
=
0
;
i
<
kBufferCount
;
++
i
)
{
for
(
int
i
=
0
;
i
<
k
FlutterSurfaceManager
BufferCount
;
++
i
)
{
if
(
_ioSurface
[
i
])
{
CFRelease
(
_ioSurface
[
i
]);
}
...
...
shell/platform/darwin/macos/framework/Source/FlutterView.h
浏览文件 @
acc24667
...
...
@@ -20,7 +20,16 @@
*/
@interface
FlutterView
:
NSView
/**
* The OpenGL context of backing surface.
*/
@property
(
readwrite
,
nonatomic
,
nonnull
)
NSOpenGLContext
*
openGLContext
;
/**
* Controls whether view resizing synchronously updates contents. This can only be enabled
* after the engine is running and producing frames, because during synchronous view resizing the
* platform thread is blocked until engine produces frame with requested size.
*/
@property
(
readwrite
,
nonatomic
)
BOOL
synchronousResizing
;
-
(
nullable
instancetype
)
initWithFrame
:(
NSRect
)
frame
...
...
@@ -38,7 +47,15 @@
-
(
nullable
instancetype
)
initWithCoder
:(
nonnull
NSCoder
*
)
coder
NS_UNAVAILABLE
;
-
(
nonnull
instancetype
)
init
NS_UNAVAILABLE
;
/**
* Flushes the OpenGL context and flips the surfaces. Expected to be called on raster thread.
*/
-
(
void
)
present
;
-
(
int
)
getFrameBufferIdForSize
:(
CGSize
)
size
;
/**
* Ensures that framebuffer with requested size exists and returns the ID. Expected to be called on
* raster thread.
*/
-
(
int
)
frameBufferIDForSize
:(
CGSize
)
size
;
@end
shell/platform/darwin/macos/framework/Source/FlutterView.mm
浏览文件 @
acc24667
...
...
@@ -3,17 +3,18 @@
// found in the LICENSE file.
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h"
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h"
#import "flutter/shell/platform/darwin/macos/framework/Source/MacOS
SwitchableGLContext
.h"
#import "flutter/shell/platform/darwin/macos/framework/Source/MacOS
GLContextSwitch
.h"
#import <OpenGL/gl.h>
#import <QuartzCore/QuartzCore.h>
@interface
FlutterView
()
<
FlutterResizeSynchronizerDelegate
>
{
__weak
id
<
FlutterViewReshapeListener
>
_reshapeListener
;
FlutterResizeSynchronizer
*
resizeSynchronizer
;
FlutterSurfaceManager
*
surfaceManager
;
FlutterResizeSynchronizer
*
_
resizeSynchronizer
;
FlutterSurfaceManager
*
_
surfaceManager
;
}
@end
...
...
@@ -35,9 +36,9 @@
[
self
setWantsLayer
:
YES
];
resizeSynchronizer
=
[[
FlutterResizeSynchronizer
alloc
]
initWithDelegate
:
self
];
surfaceManager
=
[[
FlutterSurfaceManager
alloc
]
initWithLayer
:
self
.
layer
openGLContext:
self
.
openGLContext
];
_
resizeSynchronizer
=
[[
FlutterResizeSynchronizer
alloc
]
initWithDelegate
:
self
];
_
surfaceManager
=
[[
FlutterSurfaceManager
alloc
]
initWithLayer
:
self
.
layer
openGLContext:
self
.
openGLContext
];
_reshapeListener
=
reshapeListener
;
}
...
...
@@ -45,8 +46,7 @@
}
-
(
void
)
resizeSynchronizerFlush
:(
FlutterResizeSynchronizer
*
)
synchronizer
{
flutter
::
GLContextSwitch
context_switch
(
std
::
make_unique
<
MacOSSwitchableGLContext
>
(
self
.
openGLContext
));
MacOSGLContextSwitch
context_switch
(
self
.
openGLContext
);
glFlush
();
}
...
...
@@ -54,29 +54,29 @@
[
CATransaction
begin
];
[
CATransaction
setDisableActions
:
YES
];
[
surfaceManager
swapBuffers
];
[
_
surfaceManager
swapBuffers
];
[
CATransaction
commit
];
}
-
(
int
)
getFrameBufferId
ForSize
:(
CGSize
)
size
{
if
([
resizeSynchronizer
shouldEnsureSurfaceForSize
:
size
])
{
[
surfaceManager
ensureSurfaceSize
:
size
];
-
(
int
)
frameBufferID
ForSize
:(
CGSize
)
size
{
if
([
_
resizeSynchronizer
shouldEnsureSurfaceForSize
:
size
])
{
[
_
surfaceManager
ensureSurfaceSize
:
size
];
}
return
[
surfaceManager
glFrameBufferId
];
return
[
_
surfaceManager
glFrameBufferId
];
}
-
(
void
)
present
{
[
resizeSynchronizer
requestCommit
];
[
_
resizeSynchronizer
requestCommit
];
}
-
(
void
)
reshaped
{
if
(
self
.
synchronousResizing
)
{
CGSize
scaledSize
=
[
self
convertSizeToBacking
:
self
.
bounds
.
size
];
[
resizeSynchronizer
beginResize
:
scaledSize
notify:
^
{
[
_reshapeListener
viewDidReshape
:
self
];
}];
[
_
resizeSynchronizer
beginResize
:
scaledSize
notify:
^
{
[
_reshapeListener
viewDidReshape
:
self
];
}];
}
else
{
[
_reshapeListener
viewDidReshape
:
self
];
}
...
...
shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h
0 → 100644
浏览文件 @
acc24667
// 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>
/**
* RAII wrapper that sets provided NSOpenGLContext as current and restores
* original context on scope exit.
*/
class
MacOSGLContextSwitch
{
public:
explicit
MacOSGLContextSwitch
(
NSOpenGLContext
*
context
);
~
MacOSGLContextSwitch
();
MacOSGLContextSwitch
(
const
MacOSGLContextSwitch
&
)
=
delete
;
MacOSGLContextSwitch
(
MacOSGLContextSwitch
&&
)
=
delete
;
private:
NSOpenGLContext
*
previous_
;
};
shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.mm
0 → 100644
浏览文件 @
acc24667
// 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/MacOSGLContextSwitch.h"
MacOSGLContextSwitch
::
MacOSGLContextSwitch
(
NSOpenGLContext
*
context
)
{
previous_
=
[
NSOpenGLContext
currentContext
];
[
context
makeCurrentContext
];
}
MacOSGLContextSwitch
::~
MacOSGLContextSwitch
()
{
if
(
previous_
)
{
[
previous_
makeCurrentContext
];
}
else
{
[
NSOpenGLContext
clearCurrentContext
];
}
}
shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.h
已删除
100644 → 0
浏览文件 @
122f2425
#include "flutter/flow/gl_context_switch.h"
#include "flutter/fml/memory/thread_checker.h"
#import <Cocoa/Cocoa.h>
class
MacOSSwitchableGLContext
final
:
public
flutter
::
SwitchableGLContext
{
public:
explicit
MacOSSwitchableGLContext
(
NSOpenGLContext
*
context
);
bool
SetCurrent
()
override
;
bool
RemoveCurrent
()
override
;
private:
NSOpenGLContext
*
context_
;
NSOpenGLContext
*
previous_context_
;
FML_DECLARE_THREAD_CHECKER
(
checker
);
FML_DISALLOW_COPY_AND_ASSIGN
(
MacOSSwitchableGLContext
);
};
shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.mm
已删除
100644 → 0
浏览文件 @
122f2425
#import "flutter/shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.h"
MacOSSwitchableGLContext
::
MacOSSwitchableGLContext
(
NSOpenGLContext
*
context
)
:
context_
(
context
)
{}
bool
MacOSSwitchableGLContext
::
SetCurrent
()
{
FML_DCHECK_CREATION_THREAD_IS_CURRENT
(
checker
);
previous_context_
=
[
NSOpenGLContext
currentContext
];
[
context_
makeCurrentContext
];
return
true
;
}
bool
MacOSSwitchableGLContext
::
RemoveCurrent
()
{
if
(
previous_context_
)
{
[
previous_context_
makeCurrentContext
];
}
else
{
[
NSOpenGLContext
clearCurrentContext
];
}
return
true
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录