Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
adb3312f
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,发现更多精彩内容 >>
未验证
提交
adb3312f
编写于
11月 30, 2020
作者:
K
Kaushik Iska
提交者:
GitHub
11月 30, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "Introduce a delegate class for gpu metal rendering (#22611)" (#22775)
This reverts commit
5bf65335
.
上级
a35e3fe4
变更
18
显示空白变更内容
内联
并排
Showing
18 changed file
with
164 addition
and
505 deletion
+164
-505
ci/licenses_golden/licenses_flutter
ci/licenses_golden/licenses_flutter
+0
-4
shell/common/animator.cc
shell/common/animator.cc
+3
-3
shell/gpu/BUILD.gn
shell/gpu/BUILD.gn
+0
-2
shell/gpu/gpu_surface_metal.h
shell/gpu/gpu_surface_metal.h
+14
-15
shell/gpu/gpu_surface_metal.mm
shell/gpu/gpu_surface_metal.mm
+49
-84
shell/gpu/gpu_surface_metal_delegate.cc
shell/gpu/gpu_surface_metal_delegate.cc
+0
-19
shell/gpu/gpu_surface_metal_delegate.h
shell/gpu/gpu_surface_metal_delegate.h
+0
-100
shell/platform/darwin/graphics/BUILD.gn
shell/platform/darwin/graphics/BUILD.gn
+0
-26
shell/platform/darwin/graphics/FlutterDarwinContextMetal.h
shell/platform/darwin/graphics/FlutterDarwinContextMetal.h
+0
-57
shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm
shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm
+0
-70
shell/platform/darwin/ios/BUILD.gn
shell/platform/darwin/ios/BUILD.gn
+5
-14
shell/platform/darwin/ios/ios_context.mm
shell/platform/darwin/ios/ios_context.mm
+4
-4
shell/platform/darwin/ios/ios_context_metal.h
shell/platform/darwin/ios/ios_context_metal.h
+9
-4
shell/platform/darwin/ios/ios_context_metal.mm
shell/platform/darwin/ios/ios_context_metal.mm
+53
-13
shell/platform/darwin/ios/ios_surface.mm
shell/platform/darwin/ios/ios_surface.mm
+4
-4
shell/platform/darwin/ios/ios_surface_metal.h
shell/platform/darwin/ios/ios_surface_metal.h
+1
-17
shell/platform/darwin/ios/ios_surface_metal.mm
shell/platform/darwin/ios/ios_surface_metal.mm
+15
-62
shell/platform/darwin/ios/rendering_api_selection.mm
shell/platform/darwin/ios/rendering_api_selection.mm
+7
-7
未找到文件。
ci/licenses_golden/licenses_flutter
浏览文件 @
adb3312f
...
@@ -673,8 +673,6 @@ FILE: ../../../flutter/shell/gpu/gpu_surface_gl_delegate.cc
...
@@ -673,8 +673,6 @@ FILE: ../../../flutter/shell/gpu/gpu_surface_gl_delegate.cc
FILE: ../../../flutter/shell/gpu/gpu_surface_gl_delegate.h
FILE: ../../../flutter/shell/gpu/gpu_surface_gl_delegate.h
FILE: ../../../flutter/shell/gpu/gpu_surface_metal.h
FILE: ../../../flutter/shell/gpu/gpu_surface_metal.h
FILE: ../../../flutter/shell/gpu/gpu_surface_metal.mm
FILE: ../../../flutter/shell/gpu/gpu_surface_metal.mm
FILE: ../../../flutter/shell/gpu/gpu_surface_metal_delegate.cc
FILE: ../../../flutter/shell/gpu/gpu_surface_metal_delegate.h
FILE: ../../../flutter/shell/gpu/gpu_surface_software.cc
FILE: ../../../flutter/shell/gpu/gpu_surface_software.cc
FILE: ../../../flutter/shell/gpu/gpu_surface_software.h
FILE: ../../../flutter/shell/gpu/gpu_surface_software.h
FILE: ../../../flutter/shell/gpu/gpu_surface_software_delegate.cc
FILE: ../../../flutter/shell/gpu/gpu_surface_software_delegate.cc
...
@@ -934,8 +932,6 @@ FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStan
...
@@ -934,8 +932,6 @@ FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStan
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodec_Internal.h
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodec_Internal.h
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/flutter_codecs_unittest.mm
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/flutter_codecs_unittest.mm
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/flutter_standard_codec_unittest.mm
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/flutter_standard_codec_unittest.mm
FILE: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetal.h
FILE: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Flutter.podspec
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Flutter.podspec
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/Flutter.h
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/Flutter.h
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h
...
...
shell/common/animator.cc
浏览文件 @
adb3312f
...
@@ -29,9 +29,9 @@ Animator::Animator(Delegate& delegate,
...
@@ -29,9 +29,9 @@ Animator::Animator(Delegate& delegate,
last_vsync_start_time_
(),
last_vsync_start_time_
(),
last_frame_target_time_
(),
last_frame_target_time_
(),
dart_frame_deadline_
(
0
),
dart_frame_deadline_
(
0
),
#if SHELL_ENABLE_METAL
#if
FLUTTER_
SHELL_ENABLE_METAL
layer_tree_pipeline_
(
fml
::
MakeRefCounted
<
LayerTreePipeline
>
(
2
)),
layer_tree_pipeline_
(
fml
::
MakeRefCounted
<
LayerTreePipeline
>
(
2
)),
#else // SHELL_ENABLE_METAL
#else //
FLUTTER_
SHELL_ENABLE_METAL
// TODO(dnfield): We should remove this logic and set the pipeline depth
// TODO(dnfield): We should remove this logic and set the pipeline depth
// back to 2 in this case. See
// back to 2 in this case. See
// https://github.com/flutter/engine/pull/9132 for discussion.
// https://github.com/flutter/engine/pull/9132 for discussion.
...
@@ -40,7 +40,7 @@ Animator::Animator(Delegate& delegate,
...
@@ -40,7 +40,7 @@ Animator::Animator(Delegate& delegate,
task_runners
.
GetRasterTaskRunner
()
task_runners
.
GetRasterTaskRunner
()
?
1
?
1
:
2
)),
:
2
)),
#endif // SHELL_ENABLE_METAL
#endif //
FLUTTER_
SHELL_ENABLE_METAL
pending_frame_semaphore_
(
1
),
pending_frame_semaphore_
(
1
),
frame_number_
(
1
),
frame_number_
(
1
),
paused_
(
false
),
paused_
(
false
),
...
...
shell/gpu/BUILD.gn
浏览文件 @
adb3312f
...
@@ -51,8 +51,6 @@ source_set("gpu_surface_metal") {
...
@@ -51,8 +51,6 @@ source_set("gpu_surface_metal") {
sources = [
sources = [
"gpu_surface_metal.h",
"gpu_surface_metal.h",
"gpu_surface_metal.mm",
"gpu_surface_metal.mm",
"gpu_surface_metal_delegate.cc",
"gpu_surface_metal_delegate.h",
]
]
deps = gpu_common_deps
deps = gpu_common_deps
...
...
shell/gpu/gpu_surface_metal.h
浏览文件 @
adb3312f
...
@@ -5,30 +5,35 @@
...
@@ -5,30 +5,35 @@
#ifndef FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_H_
#ifndef FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_H_
#define FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_H_
#define FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_H_
#include <Metal/Metal.h>
#include "flutter/flow/surface.h"
#include "flutter/flow/surface.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/macros.h"
#include "flutter/
shell/gpu/gpu_surface_metal_delegate
.h"
#include "flutter/
fml/platform/darwin/scoped_nsobject
.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/mtl/GrMtlTypes.h"
#include "third_party/skia/include/gpu/mtl/GrMtlTypes.h"
@
class
CAMetalLayer
;
namespace
flutter
{
namespace
flutter
{
class
SK_API_AVAILABLE_CA_METAL_LAYER
GPUSurfaceMetal
:
public
Surface
{
class
SK_API_AVAILABLE_CA_METAL_LAYER
GPUSurfaceMetal
:
public
Surface
{
public:
public:
GPUSurfaceMetal
(
GPUSurfaceMetalDelegate
*
delegate
,
GPUSurfaceMetal
(
fml
::
scoped_nsobject
<
CAMetalLayer
>
layer
,
sk_sp
<
GrDirectContext
>
context
);
sk_sp
<
GrDirectContext
>
context
,
fml
::
scoped_nsprotocol
<
id
<
MTLCommandQueue
>>
command_queue
);
// |Surface|
// |Surface|
~
GPUSurfaceMetal
();
~
GPUSurfaceMetal
();
// |Surface|
bool
IsValid
()
override
;
private:
private:
const
GPUSurfaceMetalDelegate
*
delegate_
;
fml
::
scoped_nsobject
<
CAMetalLayer
>
layer_
;
const
MTLRenderTargetType
render_target_type_
;
GrMTLHandle
next_drawable_
=
nullptr
;
sk_sp
<
GrDirectContext
>
context_
;
sk_sp
<
GrDirectContext
>
context_
;
fml
::
scoped_nsprotocol
<
id
<
MTLCommandQueue
>>
command_queue_
;
GrMTLHandle
next_drawable_
=
nullptr
;
// |Surface|
bool
IsValid
()
override
;
// |Surface|
// |Surface|
std
::
unique_ptr
<
SurfaceFrame
>
AcquireFrame
(
const
SkISize
&
size
)
override
;
std
::
unique_ptr
<
SurfaceFrame
>
AcquireFrame
(
const
SkISize
&
size
)
override
;
...
@@ -42,12 +47,6 @@ class SK_API_AVAILABLE_CA_METAL_LAYER GPUSurfaceMetal : public Surface {
...
@@ -42,12 +47,6 @@ class SK_API_AVAILABLE_CA_METAL_LAYER GPUSurfaceMetal : public Surface {
// |Surface|
// |Surface|
std
::
unique_ptr
<
GLContextResult
>
MakeRenderContextCurrent
()
override
;
std
::
unique_ptr
<
GLContextResult
>
MakeRenderContextCurrent
()
override
;
std
::
unique_ptr
<
SurfaceFrame
>
AcquireFrameFromCAMetalLayer
(
const
SkISize
&
frame_info
);
std
::
unique_ptr
<
SurfaceFrame
>
AcquireFrameFromMTLTexture
(
const
SkISize
&
frame_info
);
void
ReleaseUnusedDrawableIfNecessary
();
void
ReleaseUnusedDrawableIfNecessary
();
FML_DISALLOW_COPY_AND_ASSIGN
(
GPUSurfaceMetal
);
FML_DISALLOW_COPY_AND_ASSIGN
(
GPUSurfaceMetal
);
...
...
shell/gpu/gpu_surface_metal.mm
浏览文件 @
adb3312f
...
@@ -4,12 +4,9 @@
...
@@ -4,12 +4,9 @@
#include "flutter/shell/gpu/gpu_surface_metal.h"
#include "flutter/shell/gpu/gpu_surface_metal.h"
#i
mport <Metal/Metal
.h>
#i
nclude <QuartzCore/CAMetalLayer
.h>
#include "flutter/fml/make_copyable.h"
#include "flutter/fml/platform/darwin/cf_utils.h"
#include "flutter/fml/trace_event.h"
#include "flutter/fml/trace_event.h"
#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/ports/SkCFObject.h"
#include "third_party/skia/include/ports/SkCFObject.h"
...
@@ -18,10 +15,17 @@ static_assert(!__has_feature(objc_arc), "ARC must be disabled.");
...
@@ -18,10 +15,17 @@ static_assert(!__has_feature(objc_arc), "ARC must be disabled.");
namespace
flutter
{
namespace
flutter
{
GPUSurfaceMetal
::
GPUSurfaceMetal
(
GPUSurfaceMetalDelegate
*
delegate
,
sk_sp
<
GrDirectContext
>
context
)
GPUSurfaceMetal
::
GPUSurfaceMetal
(
fml
::
scoped_nsobject
<
CAMetalLayer
>
layer
,
:
delegate_
(
delegate
),
sk_sp
<
GrDirectContext
>
context
,
render_target_type_
(
delegate
->
GetRenderTargetType
()),
fml
::
scoped_nsprotocol
<
id
<
MTLCommandQueue
>>
command_queue
)
context_
(
std
::
move
(
context
))
{}
:
layer_
(
std
::
move
(
layer
)),
context_
(
std
::
move
(
context
)),
command_queue_
(
std
::
move
(
command_queue
))
{
layer_
.
get
().
pixelFormat
=
MTLPixelFormatBGRA8Unorm
;
// Flutter needs to read from the color attachment in cases where there are effects such as
// backdrop filters.
layer_
.
get
().
framebufferOnly
=
NO
;
}
GPUSurfaceMetal
::~
GPUSurfaceMetal
()
{
GPUSurfaceMetal
::~
GPUSurfaceMetal
()
{
ReleaseUnusedDrawableIfNecessary
();
ReleaseUnusedDrawableIfNecessary
();
...
@@ -29,7 +33,7 @@ GPUSurfaceMetal::~GPUSurfaceMetal() {
...
@@ -29,7 +33,7 @@ GPUSurfaceMetal::~GPUSurfaceMetal() {
// |Surface|
// |Surface|
bool
GPUSurfaceMetal
::
IsValid
()
{
bool
GPUSurfaceMetal
::
IsValid
()
{
return
context_
!=
nullptr
;
return
layer_
&&
context_
&&
command_queue_
;
}
}
// |Surface|
// |Surface|
...
@@ -44,30 +48,21 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceMetal::AcquireFrame(const SkISize& frame
...
@@ -44,30 +48,21 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceMetal::AcquireFrame(const SkISize& frame
return
nullptr
;
return
nullptr
;
}
}
switch
(
render_target_type_
)
{
const
auto
drawable_size
=
CGSizeMake
(
frame_size
.
width
(),
frame_size
.
height
());
case
MTLRenderTargetType
::
kCAMetalLayer
:
return
AcquireFrameFromCAMetalLayer
(
frame_size
);
case
MTLRenderTargetType
::
kMTLTexture
:
return
AcquireFrameFromMTLTexture
(
frame_size
);
default:
FML_CHECK
(
false
)
<<
"Unknown MTLRenderTargetType type."
;
}
return
nullptr
;
}
std
::
unique_ptr
<
SurfaceFrame
>
GPUSurfaceMetal
::
AcquireFrameFromCAMetalLayer
(
if
(
!
CGSizeEqualToSize
(
drawable_size
,
layer_
.
get
().
drawableSize
))
{
const
SkISize
&
frame_info
)
{
layer_
.
get
().
drawableSize
=
drawable_size
;
auto
layer
=
delegate_
->
GetCAMetalLayer
(
frame_info
);
if
(
!
layer
)
{
FML_LOG
(
ERROR
)
<<
"Invalid CAMetalLayer given by the embedder."
;
return
nullptr
;
}
}
ReleaseUnusedDrawableIfNecessary
();
ReleaseUnusedDrawableIfNecessary
();
sk_sp
<
SkSurface
>
surface
=
SkSurface
::
MakeFromCAMetalLayer
(
context_
.
get
(),
// context
// When there are platform views in the scene, the drawable needs to be presented in the same
layer
,
// layer
// transaction as the one created for platform views. When the drawable are being presented from
// the raster thread, there is no such transaction.
layer_
.
get
().
presentsWithTransaction
=
[[
NSThread
currentThread
]
isMainThread
];
auto
surface
=
SkSurface
::
MakeFromCAMetalLayer
(
context_
.
get
(),
// context
layer_
.
get
(),
// layer
kTopLeft_GrSurfaceOrigin
,
// origin
kTopLeft_GrSurfaceOrigin
,
// origin
1
,
// sample count
1
,
// sample count
kBGRA_8888_SkColorType
,
// color type
kBGRA_8888_SkColorType
,
// color type
...
@@ -77,13 +72,11 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceMetal::AcquireFrameFromCAMetalLayer(
...
@@ -77,13 +72,11 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceMetal::AcquireFrameFromCAMetalLayer(
);
);
if
(
!
surface
)
{
if
(
!
surface
)
{
FML_LOG
(
ERROR
)
<<
"Could not create the SkSurface from the
CAMetalLayer
."
;
FML_LOG
(
ERROR
)
<<
"Could not create the SkSurface from the
metal texture
."
;
return
nullptr
;
return
nullptr
;
}
}
auto
submit_callback
=
auto
submit_callback
=
[
this
](
const
SurfaceFrame
&
surface_frame
,
SkCanvas
*
canvas
)
->
bool
{
fml
::
MakeCopyable
([
drawable
=
next_drawable_
,
delegate
=
delegate_
](
const
SurfaceFrame
&
surface_frame
,
SkCanvas
*
canvas
)
->
bool
{
TRACE_EVENT0
(
"flutter"
,
"GPUSurfaceMetal::Submit"
);
TRACE_EVENT0
(
"flutter"
,
"GPUSurfaceMetal::Submit"
);
if
(
canvas
==
nullptr
)
{
if
(
canvas
==
nullptr
)
{
FML_DLOG
(
ERROR
)
<<
"Canvas not available."
;
FML_DLOG
(
ERROR
)
<<
"Canvas not available."
;
...
@@ -92,51 +85,23 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceMetal::AcquireFrameFromCAMetalLayer(
...
@@ -92,51 +85,23 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceMetal::AcquireFrameFromCAMetalLayer(
canvas
->
flush
();
canvas
->
flush
();
if
(
!
drawable
)
{
if
(
next_drawable_
==
nullptr
)
{
FML_DLOG
(
ERROR
)
<<
"Unable to obtain a metal drawabl
e."
;
FML_DLOG
(
ERROR
)
<<
"Could not acquire next Metal drawable from the SkSurfac
e."
;
return
false
;
return
false
;
}
}
return
delegate
->
PresentDrawable
(
drawable
);
auto
command_buffer
=
});
fml
::
scoped_nsprotocol
<
id
<
MTLCommandBuffer
>>
([[
command_queue_
.
get
()
commandBuffer
]
retain
]);
return
std
::
make_unique
<
SurfaceFrame
>
(
std
::
move
(
surface
),
true
,
submit_callback
);
}
std
::
unique_ptr
<
SurfaceFrame
>
GPUSurfaceMetal
::
AcquireFrameFromMTLTexture
(
const
SkISize
&
frame_info
)
{
GPUMTLTextureInfo
texture
=
delegate_
->
GetMTLTexture
(
frame_info
);
id
<
MTLTexture
>
mtl_texture
=
(
id
<
MTLTexture
>
)(
texture
.
texture
);
if
(
!
mtl_texture
)
{
FML_LOG
(
ERROR
)
<<
"Invalid MTLTexture given by the embedder."
;
return
nullptr
;
}
GrMtlTextureInfo
info
;
info
.
fTexture
.
reset
([
mtl_texture
retain
]);
GrBackendTexture
backend_texture
(
frame_info
.
width
(),
frame_info
.
height
(),
GrMipmapped
::
kNo
,
info
);
sk_sp
<
SkSurface
>
surface
=
SkSurface
::
MakeFromBackendTexture
(
context_
.
get
(),
backend_texture
,
kTopLeft_GrSurfaceOrigin
,
1
,
kBGRA_8888_SkColorType
,
nullptr
,
nullptr
);
if
(
!
surface
)
{
fml
::
scoped_nsprotocol
<
id
<
CAMetalDrawable
>>
drawable
(
FML_LOG
(
ERROR
)
<<
"Could not create the SkSurface from the metal texture."
;
reinterpret_cast
<
id
<
CAMetalDrawable
>>
(
next_drawable_
));
return
nullptr
;
next_drawable_
=
nullptr
;
}
auto
submit_callback
=
[
texture_id
=
texture
.
texture_id
,
delegate
=
delegate_
](
const
SurfaceFrame
&
surface_frame
,
SkCanvas
*
canvas
)
->
bool
{
TRACE_EVENT0
(
"flutter"
,
"GPUSurfaceMetal::PresentTexture"
);
if
(
canvas
==
nullptr
)
{
FML_DLOG
(
ERROR
)
<<
"Canvas not available."
;
return
false
;
}
canvas
->
flush
();
[
command_buffer
.
get
()
commit
];
[
command_buffer
.
get
()
waitUntilScheduled
];
[
drawable
.
get
()
present
];
return
delegate
->
PresentTexture
(
texture_id
)
;
return
true
;
};
};
return
std
::
make_unique
<
SurfaceFrame
>
(
std
::
move
(
surface
),
true
,
submit_callback
);
return
std
::
make_unique
<
SurfaceFrame
>
(
std
::
move
(
surface
),
true
,
submit_callback
);
...
...
shell/gpu/gpu_surface_metal_delegate.cc
已删除
100644 → 0
浏览文件 @
a35e3fe4
// 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.
#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
namespace
flutter
{
GPUSurfaceMetalDelegate
::
GPUSurfaceMetalDelegate
(
MTLRenderTargetType
render_target_type
)
:
render_target_type_
(
render_target_type
)
{}
GPUSurfaceMetalDelegate
::~
GPUSurfaceMetalDelegate
()
=
default
;
MTLRenderTargetType
GPUSurfaceMetalDelegate
::
GetRenderTargetType
()
{
return
render_target_type_
;
}
}
// namespace flutter
shell/gpu/gpu_surface_metal_delegate.h
已删除
100644 → 0
浏览文件 @
a35e3fe4
// 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.
#ifndef FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_DELEGATE_H_
#define FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_DELEGATE_H_
#include <stdint.h>
#include "flutter/fml/macros.h"
#include "third_party/skia/include/core/SkSize.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/mtl/GrMtlTypes.h"
namespace
flutter
{
// expected to be id<MTLDevice>
typedef
void
*
GPUMTLDeviceHandle
;
// expected to be id<MTLCommandQueues>
typedef
void
*
GPUMTLCommandQueueHandle
;
// expected to be CAMetalLayer*
typedef
void
*
GPUCAMetalLayerHandle
;
// expected to be id<MTLTexture>
typedef
void
*
GPUMTLTextureHandle
;
struct
GPUMTLTextureInfo
{
intptr_t
texture_id
;
GPUMTLTextureHandle
texture
;
};
enum
class
MTLRenderTargetType
{
kMTLTexture
,
kCAMetalLayer
};
//------------------------------------------------------------------------------
/// @brief Interface implemented by all platform surfaces that can present
/// a metal backing store to the "screen". The GPU surface
/// abstraction (which abstracts the client rendering API) uses this
/// delegation pattern to tell the platform surface (which abstracts
/// how backing stores fulfilled by the selected client rendering
/// API end up on the "screen" on a particular platform) when the
/// rasterizer needs to allocate and present the software backing
/// store.
///
/// @see |IOSurfaceMetal| and |EmbedderSurfaceMetal|.
///
class
GPUSurfaceMetalDelegate
{
public:
//------------------------------------------------------------------------------
/// @brief Construct a new GPUSurfaceMetalDelegate object with the specified
/// render_target type.
///
/// @see |MTLRenderTargetType|
///
explicit
GPUSurfaceMetalDelegate
(
MTLRenderTargetType
render_target
);
virtual
~
GPUSurfaceMetalDelegate
();
//------------------------------------------------------------------------------
/// @brief Returns the handle to the CAMetalLayer to render to. This is only
/// called when the specifed render target type is `kCAMetalLayer`.
///
virtual
GPUCAMetalLayerHandle
GetCAMetalLayer
(
const
SkISize
&
frame_info
)
const
=
0
;
//------------------------------------------------------------------------------
/// @brief Presents the drawable to the "screen". The drawable is obtained
/// from the CAMetalLayer that given by `GetCAMetalLayer` call. This is only
/// called when the specified render target type in `kCAMetalLayer`.
///
/// @see |GPUSurfaceMetalDelegate::GetCAMetalLayer|
///
virtual
bool
PresentDrawable
(
GrMTLHandle
drawable
)
const
=
0
;
//------------------------------------------------------------------------------
/// @brief Returns the handle to the MTLTexture to render to. This is only
/// called when the specefied render target type is `kMTLTexture`.
///
virtual
GPUMTLTextureInfo
GetMTLTexture
(
const
SkISize
&
frame_info
)
const
=
0
;
//------------------------------------------------------------------------------
/// @brief Presents the texture with `texture_id` to the "screen".
/// `texture_id` corresponds to a texture that has been obtained by an earlier
/// call to `GetMTLTexture`. This is only called when the specefied render
/// target type is `kMTLTexture`.
///
/// @see |GPUSurfaceMetalDelegate::GetMTLTexture|
///
virtual
bool
PresentTexture
(
intptr_t
texture_id
)
const
=
0
;
MTLRenderTargetType
GetRenderTargetType
();
private:
const
MTLRenderTargetType
render_target_type_
;
};
}
// namespace flutter
#endif // FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_DELEGATE_H_
shell/platform/darwin/graphics/BUILD.gn
已删除
100644 → 0
浏览文件 @
a35e3fe4
# 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.
assert(is_ios || is_mac)
import("//flutter/common/config.gni")
source_set("graphics") {
cflags_objc = flutter_cflags_objc
cflags_objcc = flutter_cflags_objcc
sources = [
"FlutterDarwinContextMetal.h",
"FlutterDarwinContextMetal.mm",
]
deps = [
"//flutter/common/graphics",
"//flutter/fml",
]
public_deps = [ "//third_party/skia" ]
public_configs = [ "//flutter:config" ]
}
shell/platform/darwin/graphics/FlutterDarwinContextMetal.h
已删除
100644 → 0
浏览文件 @
a35e3fe4
// 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.
#ifndef SHELL_PLATFORM_DARWIN_GRAPHICS_DARWIN_CONTEXT_METAL_H_
#define SHELL_PLATFORM_DARWIN_GRAPHICS_DARWIN_CONTEXT_METAL_H_
#import <Foundation/Foundation.h>
#import <Metal/Metal.h>
#include "third_party/skia/include/gpu/GrDirectContext.h"
NS_ASSUME_NONNULL_BEGIN
/**
* Provides skia GrContexts that are shared between iOS and macOS embeddings.
*/
@interface
FlutterDarwinContextMetal
:
NSObject
/**
* Initializes a FlutterDarwinContextMetal with the system default MTLDevice and a new
* MTLCommandQueue.
*/
-
(
instancetype
)
initWithDefaultMTLDevice
;
/**
* Initializes a FlutterDarwinContextMetal with provided MTLDevice and MTLCommandQueue.
*/
-
(
instancetype
)
initWithMTLDevice
:(
id
<
MTLDevice
>
)
mtlDevice
commandQueue
:(
id
<
MTLCommandQueue
>
)
commandQueue
;
/**
* MTLDevice that is backing this context.s
*/
@property
(
nonatomic
,
readonly
)
id
<
MTLDevice
>
mtlDevice
;
/**
* MTLCommandQueue that is acquired from the `mtlDevice`. This queue is used both for rendering and
* resource related commands.
*/
@property
(
nonatomic
,
readonly
)
id
<
MTLCommandQueue
>
mtlCommandQueue
;
/**
* Skia GrContext that is used for rendering.
*/
@property
(
nonatomic
,
readonly
)
sk_sp
<
GrDirectContext
>
mainContext
;
/**
* Skia GrContext that is used for resources (uploading textures etc).
*/
@property
(
nonatomic
,
readonly
)
sk_sp
<
GrDirectContext
>
resourceContext
;
@end
NS_ASSUME_NONNULL_END
#endif // SHELL_PLATFORM_DARWIN_GRAPHICS_DARWIN_CONTEXT_METAL_H_
shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm
已删除
100644 → 0
浏览文件 @
a35e3fe4
// 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/graphics/FlutterDarwinContextMetal.h"
#include "flutter/common/graphics/persistent_cache.h"
#include "flutter/fml/logging.h"
#include "third_party/skia/include/gpu/GrContextOptions.h"
static
GrContextOptions
CreateMetalGrContextOptions
()
{
GrContextOptions
options
=
{};
if
(
flutter
::
PersistentCache
::
cache_sksl
())
{
options
.
fShaderCacheStrategy
=
GrContextOptions
::
ShaderCacheStrategy
::
kSkSL
;
}
flutter
::
PersistentCache
::
MarkStrategySet
();
options
.
fPersistentCache
=
flutter
::
PersistentCache
::
GetCacheForProcess
();
return
options
;
}
@implementation
FlutterDarwinContextMetal
-
(
instancetype
)
initWithDefaultMTLDevice
{
id
<
MTLDevice
>
mtlDevice
=
MTLCreateSystemDefaultDevice
();
return
[
self
initWithMTLDevice
:
mtlDevice
commandQueue
:[
mtlDevice
newCommandQueue
]];
}
-
(
instancetype
)
initWithMTLDevice
:(
id
<
MTLDevice
>
)
mtlDevice
commandQueue
:(
id
<
MTLCommandQueue
>
)
commandQueue
{
self
=
[
super
init
];
if
(
self
!=
nil
)
{
_mtlDevice
=
mtlDevice
;
if
(
!
_mtlDevice
)
{
FML_DLOG
(
ERROR
)
<<
"Could not acquire Metal device."
;
[
self
release
];
return
nil
;
}
_mtlCommandQueue
=
commandQueue
;
if
(
!
_mtlCommandQueue
)
{
FML_DLOG
(
ERROR
)
<<
"Could not create Metal command queue."
;
[
self
release
];
return
nil
;
}
[
_mtlCommandQueue
setLabel
:
@"Flutter Main Queue"
];
auto
contextOptions
=
CreateMetalGrContextOptions
();
// Skia expect arguments to `MakeMetal` transfer ownership of the reference in for release later
// when the GrDirectContext is collected.
_mainContext
=
GrDirectContext
::
MakeMetal
([
_mtlDevice
retain
],
[
_mtlCommandQueue
retain
],
contextOptions
);
_resourceContext
=
GrDirectContext
::
MakeMetal
([
_mtlDevice
retain
],
[
_mtlCommandQueue
retain
],
contextOptions
);
if
(
!
_mainContext
||
!
_resourceContext
)
{
FML_DLOG
(
ERROR
)
<<
"Could not create Skia Metal contexts."
;
[
self
release
];
return
nil
;
}
_resourceContext
->
setResourceCacheLimits
(
0u
,
0u
);
}
return
self
;
}
@end
shell/platform/darwin/ios/BUILD.gn
浏览文件 @
adb3312f
...
@@ -42,8 +42,6 @@ source_set("flutter_framework_source") {
...
@@ -42,8 +42,6 @@ source_set("flutter_framework_source") {
cflags_objc = flutter_cflags_objc
cflags_objc = flutter_cflags_objc
cflags_objcc = flutter_cflags_objcc
cflags_objcc = flutter_cflags_objcc
deps = []
sources = [
sources = [
"framework/Source/FlutterAppDelegate.mm",
"framework/Source/FlutterAppDelegate.mm",
"framework/Source/FlutterBinaryMessengerRelay.mm",
"framework/Source/FlutterBinaryMessengerRelay.mm",
...
@@ -118,6 +116,8 @@ source_set("flutter_framework_source") {
...
@@ -118,6 +116,8 @@ source_set("flutter_framework_source") {
defines = [ "FLUTTER_FRAMEWORK=1" ]
defines = [ "FLUTTER_FRAMEWORK=1" ]
if (shell_enable_metal) {
if (shell_enable_metal) {
defines += [ "FLUTTER_SHELL_ENABLE_METAL=1" ]
sources += [
sources += [
"ios_context_metal.h",
"ios_context_metal.h",
"ios_context_metal.mm",
"ios_context_metal.mm",
...
@@ -126,11 +126,9 @@ source_set("flutter_framework_source") {
...
@@ -126,11 +126,9 @@ source_set("flutter_framework_source") {
"ios_surface_metal.h",
"ios_surface_metal.h",
"ios_surface_metal.mm",
"ios_surface_metal.mm",
]
]
deps += [ "//flutter/shell/platform/darwin/graphics" ]
}
}
deps
+
= [
deps = [
":ios_gpu_configuration",
":ios_gpu_configuration",
"//flutter/common",
"//flutter/common",
"//flutter/common/graphics",
"//flutter/common/graphics",
...
@@ -146,10 +144,7 @@ source_set("flutter_framework_source") {
...
@@ -146,10 +144,7 @@ source_set("flutter_framework_source") {
"//third_party/skia",
"//third_party/skia",
]
]
public_configs = [
public_configs = [ "//flutter:config" ]
":ios_gpu_configuration_config",
"//flutter:config",
]
libs = [
libs = [
"AudioToolbox.framework",
"AudioToolbox.framework",
...
@@ -224,7 +219,6 @@ shared_library("ios_test_flutter") {
...
@@ -224,7 +219,6 @@ shared_library("ios_test_flutter") {
]
]
deps = [
deps = [
":flutter_framework_source",
":flutter_framework_source",
":ios_gpu_configuration",
":ios_test_flutter_mrc",
":ios_test_flutter_mrc",
"//flutter/common:common",
"//flutter/common:common",
"//flutter/shell/platform/darwin/common:framework_shared",
"//flutter/shell/platform/darwin/common:framework_shared",
...
@@ -234,10 +228,7 @@ shared_library("ios_test_flutter") {
...
@@ -234,10 +228,7 @@ shared_library("ios_test_flutter") {
"//third_party/rapidjson",
"//third_party/rapidjson",
"//third_party/skia",
"//third_party/skia",
]
]
public_configs = [
public_configs = [ "//flutter:config" ]
":ios_gpu_configuration_config",
"//flutter:config",
]
}
}
shared_library("create_flutter_framework_dylib") {
shared_library("create_flutter_framework_dylib") {
...
...
shell/platform/darwin/ios/ios_context.mm
浏览文件 @
adb3312f
...
@@ -8,9 +8,9 @@
...
@@ -8,9 +8,9 @@
#import "flutter/shell/platform/darwin/ios/ios_context_gl.h"
#import "flutter/shell/platform/darwin/ios/ios_context_gl.h"
#import "flutter/shell/platform/darwin/ios/ios_context_software.h"
#import "flutter/shell/platform/darwin/ios/ios_context_software.h"
#if SHELL_ENABLE_METAL
#if
FLUTTER_
SHELL_ENABLE_METAL
#import "flutter/shell/platform/darwin/ios/ios_context_metal.h"
#import "flutter/shell/platform/darwin/ios/ios_context_metal.h"
#endif // SHELL_ENABLE_METAL
#endif //
FLUTTER_
SHELL_ENABLE_METAL
namespace
flutter
{
namespace
flutter
{
...
@@ -24,10 +24,10 @@ std::unique_ptr<IOSContext> IOSContext::Create(IOSRenderingAPI rendering_api) {
...
@@ -24,10 +24,10 @@ std::unique_ptr<IOSContext> IOSContext::Create(IOSRenderingAPI rendering_api) {
return
std
::
make_unique
<
IOSContextGL
>
();
return
std
::
make_unique
<
IOSContextGL
>
();
case
IOSRenderingAPI
::
kSoftware
:
case
IOSRenderingAPI
::
kSoftware
:
return
std
::
make_unique
<
IOSContextSoftware
>
();
return
std
::
make_unique
<
IOSContextSoftware
>
();
#if SHELL_ENABLE_METAL
#if
FLUTTER_
SHELL_ENABLE_METAL
case
IOSRenderingAPI
::
kMetal
:
case
IOSRenderingAPI
::
kMetal
:
return
std
::
make_unique
<
IOSContextMetal
>
();
return
std
::
make_unique
<
IOSContextMetal
>
();
#endif // SHELL_ENABLE_METAL
#endif //
FLUTTER_
SHELL_ENABLE_METAL
default:
default:
break
;
break
;
}
}
...
...
shell/platform/darwin/ios/ios_context_metal.h
浏览文件 @
adb3312f
...
@@ -10,7 +10,6 @@
...
@@ -10,7 +10,6 @@
#include "flutter/fml/macros.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/platform/darwin/cf_utils.h"
#include "flutter/fml/platform/darwin/cf_utils.h"
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
#import "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetal.h"
#import "flutter/shell/platform/darwin/ios/ios_context.h"
#import "flutter/shell/platform/darwin/ios/ios_context.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
...
@@ -22,15 +21,21 @@ class IOSContextMetal final : public IOSContext {
...
@@ -22,15 +21,21 @@ class IOSContextMetal final : public IOSContext {
~
IOSContextMetal
();
~
IOSContextMetal
();
fml
::
scoped_nsobject
<
FlutterDarwinContextMetal
>
GetDarwinContext
()
const
;
fml
::
scoped_nsprotocol
<
id
<
MTLDevice
>>
GetDevice
()
const
;
fml
::
scoped_nsprotocol
<
id
<
MTLCommandQueue
>>
GetMainCommandQueue
()
const
;
fml
::
scoped_nsprotocol
<
id
<
MTLCommandQueue
>>
GetResourceCommandQueue
()
const
;
sk_sp
<
GrDirectContext
>
GetMainContext
()
const
;
sk_sp
<
GrDirectContext
>
GetMainContext
()
const
;
sk_sp
<
GrDirectContext
>
GetResourceContext
()
const
;
sk_sp
<
GrDirectContext
>
GetResourceContext
()
const
;
private:
private:
fml
::
scoped_nsobject
<
FlutterDarwinContextMetal
>
darwin_context_metal_
;
fml
::
scoped_nsprotocol
<
id
<
MTLDevice
>>
device_
;
fml
::
scoped_nsprotocol
<
id
<
MTLCommandQueue
>>
main_command_queue_
;
fml
::
scoped_nsprotocol
<
id
<
MTLCommandQueue
>>
main_queue_
;
sk_sp
<
GrDirectContext
>
main_context_
;
sk_sp
<
GrDirectContext
>
resource_context_
;
fml
::
CFRef
<
CVMetalTextureCacheRef
>
texture_cache_
;
fml
::
CFRef
<
CVMetalTextureCacheRef
>
texture_cache_
;
// |IOSContext|
// |IOSContext|
...
...
shell/platform/darwin/ios/ios_context_metal.mm
浏览文件 @
adb3312f
...
@@ -6,26 +6,57 @@
...
@@ -6,26 +6,57 @@
#include "flutter/common/graphics/persistent_cache.h"
#include "flutter/common/graphics/persistent_cache.h"
#include "flutter/fml/logging.h"
#include "flutter/fml/logging.h"
#import "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetal.h"
#import "flutter/shell/platform/darwin/ios/ios_external_texture_metal.h"
#import "flutter/shell/platform/darwin/ios/ios_external_texture_metal.h"
#include "third_party/skia/include/gpu/GrContextOptions.h"
#include "third_party/skia/include/gpu/GrContextOptions.h"
namespace
flutter
{
namespace
flutter
{
static
GrContextOptions
CreateMetalGrContextOptions
()
{
GrContextOptions
options
=
{};
if
(
PersistentCache
::
cache_sksl
())
{
options
.
fShaderCacheStrategy
=
GrContextOptions
::
ShaderCacheStrategy
::
kSkSL
;
}
PersistentCache
::
MarkStrategySet
();
options
.
fPersistentCache
=
PersistentCache
::
GetCacheForProcess
();
return
options
;
}
IOSContextMetal
::
IOSContextMetal
()
{
IOSContextMetal
::
IOSContextMetal
()
{
darwin_context_metal_
=
fml
::
scoped_nsobject
<
FlutterDarwinContextMetal
>
{
device_
.
reset
([
MTLCreateSystemDefaultDevice
()
retain
]);
[[[
FlutterDarwinContextMetal
alloc
]
initWithDefaultMTLDevice
]
retain
]};
if
(
!
device_
)
{
FML_DLOG
(
ERROR
)
<<
"Could not acquire Metal device."
;
return
;
}
main_queue_
.
reset
([
device_
newCommandQueue
]);
if
(
!
main_queue_
)
{
FML_DLOG
(
ERROR
)
<<
"Could not create Metal command queue."
;
return
;
}
[
main_queue_
setLabel
:
@"Flutter Main Queue"
];
const
auto
&
context_options
=
CreateMetalGrContextOptions
();
// Skia expect arguments to `MakeMetal` transfer ownership of the reference in for release later
// when the GrDirectContext is collected.
main_context_
=
GrDirectContext
::
MakeMetal
([
device_
retain
],
[
main_queue_
retain
],
context_options
);
resource_context_
=
GrDirectContext
::
MakeMetal
([
device_
retain
],
[
main_queue_
retain
],
context_options
);
if
(
!
darwin_context_metal_
)
{
if
(
!
main_context_
||
!
resource_context_
)
{
FML_DLOG
(
ERROR
)
<<
"Could not create Skia Metal contexts."
;
return
;
return
;
}
}
main_command_queue_
.
reset
([
darwin_context_metal_
.
get
().
mtlCommandQueue
retain
]
);
resource_context_
->
setResourceCacheLimits
(
0u
,
0u
);
CVMetalTextureCacheRef
texture_cache_raw
=
NULL
;
CVMetalTextureCacheRef
texture_cache_raw
=
NULL
;
auto
cv_return
=
CVMetalTextureCacheCreate
(
kCFAllocatorDefault
,
// allocator
auto
cv_return
=
CVMetalTextureCacheCreate
(
kCFAllocatorDefault
,
// allocator
NULL
,
// cache attributes (NULL default)
NULL
,
// cache attributes (NULL default)
d
arwin_context_metal_
.
get
().
mtlDevice
,
// metal device
d
evice_
.
get
()
,
// metal device
NULL
,
// texture attributes (NULL default)
NULL
,
// texture attributes (NULL default)
&
texture_cache_raw
// [out] cache
&
texture_cache_raw
// [out] cache
);
);
...
@@ -38,21 +69,30 @@ IOSContextMetal::IOSContextMetal() {
...
@@ -38,21 +69,30 @@ IOSContextMetal::IOSContextMetal() {
IOSContextMetal
::~
IOSContextMetal
()
=
default
;
IOSContextMetal
::~
IOSContextMetal
()
=
default
;
fml
::
scoped_nsobject
<
FlutterDarwinContextMetal
>
IOSContextMetal
::
GetDarwinContext
()
const
{
fml
::
scoped_nsprotocol
<
id
<
MTLDevice
>>
IOSContextMetal
::
GetDevice
()
const
{
return
darwin_context_metal_
;
return
device_
;
}
fml
::
scoped_nsprotocol
<
id
<
MTLCommandQueue
>>
IOSContextMetal
::
GetMainCommandQueue
()
const
{
return
main_queue_
;
}
fml
::
scoped_nsprotocol
<
id
<
MTLCommandQueue
>>
IOSContextMetal
::
GetResourceCommandQueue
()
const
{
// TODO(52150): Create a dedicated resource queue once multiple queues are supported in Skia.
return
main_queue_
;
}
}
sk_sp
<
GrDirectContext
>
IOSContextMetal
::
GetMainContext
()
const
{
sk_sp
<
GrDirectContext
>
IOSContextMetal
::
GetMainContext
()
const
{
return
darwin_context_metal_
.
get
().
mainContext
;
return
main_context_
;
}
}
sk_sp
<
GrDirectContext
>
IOSContextMetal
::
GetResourceContext
()
const
{
sk_sp
<
GrDirectContext
>
IOSContextMetal
::
GetResourceContext
()
const
{
return
darwin_context_metal_
.
get
().
resourceContext
;
return
resource_context_
;
}
}
// |IOSContext|
// |IOSContext|
sk_sp
<
GrDirectContext
>
IOSContextMetal
::
CreateResourceContext
()
{
sk_sp
<
GrDirectContext
>
IOSContextMetal
::
CreateResourceContext
()
{
return
darwin_context_metal_
.
get
().
resourceContext
;
return
resource_context_
;
}
}
// |IOSContext|
// |IOSContext|
...
...
shell/platform/darwin/ios/ios_surface.mm
浏览文件 @
adb3312f
...
@@ -9,9 +9,9 @@
...
@@ -9,9 +9,9 @@
#include "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
#include "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
#if SHELL_ENABLE_METAL
#if
FLUTTER_
SHELL_ENABLE_METAL
#import "flutter/shell/platform/darwin/ios/ios_surface_metal.h"
#import "flutter/shell/platform/darwin/ios/ios_surface_metal.h"
#endif // SHELL_ENABLE_METAL
#endif //
FLUTTER_
SHELL_ENABLE_METAL
namespace
flutter
{
namespace
flutter
{
...
@@ -28,7 +28,7 @@ std::unique_ptr<IOSSurface> IOSSurface::Create(std::shared_ptr<IOSContext> conte
...
@@ -28,7 +28,7 @@ std::unique_ptr<IOSSurface> IOSSurface::Create(std::shared_ptr<IOSContext> conte
);
);
}
}
#if SHELL_ENABLE_METAL
#if
FLUTTER_
SHELL_ENABLE_METAL
if
(
@available
(
iOS
METAL_IOS_VERSION_BASELINE
,
*
))
{
if
(
@available
(
iOS
METAL_IOS_VERSION_BASELINE
,
*
))
{
if
([
layer
.
get
()
isKindOfClass
:[
CAMetalLayer
class
]])
{
if
([
layer
.
get
()
isKindOfClass
:[
CAMetalLayer
class
]])
{
return
std
::
make_unique
<
IOSSurfaceMetal
>
(
return
std
::
make_unique
<
IOSSurfaceMetal
>
(
...
@@ -38,7 +38,7 @@ std::unique_ptr<IOSSurface> IOSSurface::Create(std::shared_ptr<IOSContext> conte
...
@@ -38,7 +38,7 @@ std::unique_ptr<IOSSurface> IOSSurface::Create(std::shared_ptr<IOSContext> conte
);
);
}
}
}
}
#endif // SHELL_ENABLE_METAL
#endif //
FLUTTER_
SHELL_ENABLE_METAL
return
std
::
make_unique
<
IOSSurfaceSoftware
>
(
std
::
move
(
layer
),
// layer
return
std
::
make_unique
<
IOSSurfaceSoftware
>
(
std
::
move
(
layer
),
// layer
std
::
move
(
context
)
// context
std
::
move
(
context
)
// context
...
...
shell/platform/darwin/ios/ios_surface_metal.h
浏览文件 @
adb3312f
...
@@ -6,7 +6,6 @@
...
@@ -6,7 +6,6 @@
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_METAL_H_
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_METAL_H_
#include "flutter/fml/macros.h"
#include "flutter/fml/macros.h"
#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
#import "flutter/shell/platform/darwin/ios/ios_surface.h"
#import "flutter/shell/platform/darwin/ios/ios_surface.h"
#include "third_party/skia/include/gpu/mtl/GrMtlTypes.h"
#include "third_party/skia/include/gpu/mtl/GrMtlTypes.h"
...
@@ -14,8 +13,7 @@
...
@@ -14,8 +13,7 @@
namespace
flutter
{
namespace
flutter
{
class
SK_API_AVAILABLE_CA_METAL_LAYER
IOSSurfaceMetal
final
:
public
IOSSurface
,
class
SK_API_AVAILABLE_CA_METAL_LAYER
IOSSurfaceMetal
final
:
public
IOSSurface
{
public
GPUSurfaceMetalDelegate
{
public:
public:
IOSSurfaceMetal
(
fml
::
scoped_nsobject
<
CAMetalLayer
>
layer
,
std
::
shared_ptr
<
IOSContext
>
context
);
IOSSurfaceMetal
(
fml
::
scoped_nsobject
<
CAMetalLayer
>
layer
,
std
::
shared_ptr
<
IOSContext
>
context
);
...
@@ -24,8 +22,6 @@ class SK_API_AVAILABLE_CA_METAL_LAYER IOSSurfaceMetal final : public IOSSurface,
...
@@ -24,8 +22,6 @@ class SK_API_AVAILABLE_CA_METAL_LAYER IOSSurfaceMetal final : public IOSSurface,
private:
private:
fml
::
scoped_nsobject
<
CAMetalLayer
>
layer_
;
fml
::
scoped_nsobject
<
CAMetalLayer
>
layer_
;
id
<
MTLDevice
>
device_
;
id
<
MTLCommandQueue
>
command_queue_
;
bool
is_valid_
=
false
;
bool
is_valid_
=
false
;
// |IOSSurface|
// |IOSSurface|
...
@@ -37,18 +33,6 @@ class SK_API_AVAILABLE_CA_METAL_LAYER IOSSurfaceMetal final : public IOSSurface,
...
@@ -37,18 +33,6 @@ class SK_API_AVAILABLE_CA_METAL_LAYER IOSSurfaceMetal final : public IOSSurface,
// |IOSSurface|
// |IOSSurface|
std
::
unique_ptr
<
Surface
>
CreateGPUSurface
(
GrDirectContext
*
gr_context
)
override
;
std
::
unique_ptr
<
Surface
>
CreateGPUSurface
(
GrDirectContext
*
gr_context
)
override
;
// |GPUSurfaceMetalDelegate|
GPUCAMetalLayerHandle
GetCAMetalLayer
(
const
SkISize
&
frame_info
)
const
override
;
// |GPUSurfaceMetalDelegate|
bool
PresentDrawable
(
GrMTLHandle
drawable
)
const
override
;
// |GPUSurfaceMetalDelegate|
GPUMTLTextureInfo
GetMTLTexture
(
const
SkISize
&
frame_info
)
const
override
;
// |GPUSurfaceMetalDelegate|
bool
PresentTexture
(
intptr_t
texture_id
)
const
override
;
FML_DISALLOW_COPY_AND_ASSIGN
(
IOSSurfaceMetal
);
FML_DISALLOW_COPY_AND_ASSIGN
(
IOSSurfaceMetal
);
};
};
...
...
shell/platform/darwin/ios/ios_surface_metal.mm
浏览文件 @
adb3312f
...
@@ -5,8 +5,7 @@
...
@@ -5,8 +5,7 @@
#import "flutter/shell/platform/darwin/ios/ios_surface_metal.h"
#import "flutter/shell/platform/darwin/ios/ios_surface_metal.h"
#include "flutter/shell/gpu/gpu_surface_metal.h"
#include "flutter/shell/gpu/gpu_surface_metal.h"
#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
#import "flutter/shell/platform/darwin/ios/ios_context_metal.h"
#include "flutter/shell/platform/darwin/ios/ios_context_metal.h"
namespace
flutter
{
namespace
flutter
{
...
@@ -16,14 +15,17 @@ static IOSContextMetal* CastToMetalContext(const std::shared_ptr<IOSContext>& co
...
@@ -16,14 +15,17 @@ static IOSContextMetal* CastToMetalContext(const std::shared_ptr<IOSContext>& co
IOSSurfaceMetal
::
IOSSurfaceMetal
(
fml
::
scoped_nsobject
<
CAMetalLayer
>
layer
,
IOSSurfaceMetal
::
IOSSurfaceMetal
(
fml
::
scoped_nsobject
<
CAMetalLayer
>
layer
,
std
::
shared_ptr
<
IOSContext
>
context
)
std
::
shared_ptr
<
IOSContext
>
context
)
:
IOSSurface
(
std
::
move
(
context
)),
:
IOSSurface
(
std
::
move
(
context
)),
layer_
(
std
::
move
(
layer
))
{
GPUSurfaceMetalDelegate
(
MTLRenderTargetType
::
kCAMetalLayer
),
if
(
!
layer_
)
{
layer_
(
std
::
move
(
layer
))
{
return
;
is_valid_
=
layer_
;
}
auto
metal_context
=
CastToMetalContext
(
GetContext
());
auto
metal_context
=
CastToMetalContext
(
GetContext
());
auto
darwin_context
=
metal_context
->
GetDarwinContext
().
get
();
command_queue_
=
darwin_context
.
mtlCommandQueue
;
layer_
.
get
().
device
=
metal_context
->
GetDevice
().
get
();
device_
=
darwin_context
.
mtlDevice
;
layer_
.
get
().
presentsWithTransaction
=
YES
;
is_valid_
=
true
;
}
}
// |IOSSurface|
// |IOSSurface|
...
@@ -42,60 +44,11 @@ void IOSSurfaceMetal::UpdateStorageSizeIfNecessary() {
...
@@ -42,60 +44,11 @@ void IOSSurfaceMetal::UpdateStorageSizeIfNecessary() {
// |IOSSurface|
// |IOSSurface|
std
::
unique_ptr
<
Surface
>
IOSSurfaceMetal
::
CreateGPUSurface
(
GrDirectContext
*
/* unused */
)
{
std
::
unique_ptr
<
Surface
>
IOSSurfaceMetal
::
CreateGPUSurface
(
GrDirectContext
*
/* unused */
)
{
auto
metal_context
=
CastToMetalContext
(
GetContext
());
auto
metal_context
=
CastToMetalContext
(
GetContext
());
return
std
::
make_unique
<
GPUSurfaceMetal
>
(
this
,
// layer
metal_context
->
GetMainContext
()
// context
);
}
// |GPUSurfaceMetalDelegate|
GPUCAMetalLayerHandle
IOSSurfaceMetal
::
GetCAMetalLayer
(
const
SkISize
&
frame_info
)
const
{
CAMetalLayer
*
layer
=
layer_
.
get
();
layer
.
device
=
device_
;
layer
.
pixelFormat
=
MTLPixelFormatBGRA8Unorm
;
// Flutter needs to read from the color attachment in cases where there are effects such as
// backdrop filters.
layer
.
framebufferOnly
=
NO
;
const
auto
drawable_size
=
CGSizeMake
(
frame_info
.
width
(),
frame_info
.
height
());
if
(
!
CGSizeEqualToSize
(
drawable_size
,
layer
.
drawableSize
))
{
layer
.
drawableSize
=
drawable_size
;
}
// When there are platform views in the scene, the drawable needs to be presented in the same
// transaction as the one created for platform views. When the drawable are being presented from
// the raster thread, there is no such transaction.
layer
.
presentsWithTransaction
=
[[
NSThread
currentThread
]
isMainThread
];
return
layer
;
return
std
::
make_unique
<
GPUSurfaceMetal
>
(
layer_
,
// layer
}
metal_context
->
GetMainContext
(),
// context
metal_context
->
GetMainCommandQueue
()
// command queue
// |GPUSurfaceMetalDelegate|
);
bool
IOSSurfaceMetal
::
PresentDrawable
(
GrMTLHandle
drawable
)
const
{
if
(
drawable
==
nullptr
)
{
FML_DLOG
(
ERROR
)
<<
"Could not acquire next Metal drawable from the SkSurface."
;
return
false
;
}
auto
command_buffer
=
fml
::
scoped_nsprotocol
<
id
<
MTLCommandBuffer
>>
([[
command_queue_
commandBuffer
]
retain
]);
[
command_buffer
.
get
()
commit
];
[
command_buffer
.
get
()
waitUntilScheduled
];
[
reinterpret_cast
<
id
<
CAMetalDrawable
>>
(
drawable
)
present
];
return
true
;
}
// |GPUSurfaceMetalDelegate|
GPUMTLTextureInfo
IOSSurfaceMetal
::
GetMTLTexture
(
const
SkISize
&
frame_info
)
const
{
FML_CHECK
(
false
)
<<
"render to texture not supported on ios"
;
return
{.
texture_id
=
-
1
,
.
texture
=
nullptr
};
}
// |GPUSurfaceMetalDelegate|
bool
IOSSurfaceMetal
::
PresentTexture
(
intptr_t
texture_id
)
const
{
FML_CHECK
(
false
)
<<
"render to texture not supported on ios"
;
return
false
;
}
}
}
// namespace flutter
}
// namespace flutter
shell/platform/darwin/ios/rendering_api_selection.mm
浏览文件 @
adb3312f
...
@@ -6,17 +6,17 @@
...
@@ -6,17 +6,17 @@
#include <Foundation/Foundation.h>
#include <Foundation/Foundation.h>
#include <QuartzCore/CAEAGLLayer.h>
#include <QuartzCore/CAEAGLLayer.h>
#i
mport
<QuartzCore/CAMetalLayer.h>
#i
nclude
<QuartzCore/CAMetalLayer.h>
#if SHELL_ENABLE_METAL
#if
FLUTTER_
SHELL_ENABLE_METAL
#include <Metal/Metal.h>
#include <Metal/Metal.h>
#endif // SHELL_ENABLE_METAL
#endif //
FLUTTER_
SHELL_ENABLE_METAL
#import <TargetConditionals.h>
#import <TargetConditionals.h>
#include "flutter/fml/logging.h"
#include "flutter/fml/logging.h"
namespace
flutter
{
namespace
flutter
{
#if SHELL_ENABLE_METAL
#if
FLUTTER_
SHELL_ENABLE_METAL
bool
ShouldUseMetalRenderer
()
{
bool
ShouldUseMetalRenderer
()
{
bool
ios_version_supports_metal
=
false
;
bool
ios_version_supports_metal
=
false
;
if
(
@available
(
iOS
METAL_IOS_VERSION_BASELINE
,
*
))
{
if
(
@available
(
iOS
METAL_IOS_VERSION_BASELINE
,
*
))
{
...
@@ -25,7 +25,7 @@ bool ShouldUseMetalRenderer() {
...
@@ -25,7 +25,7 @@ bool ShouldUseMetalRenderer() {
}
}
return
ios_version_supports_metal
;
return
ios_version_supports_metal
;
}
}
#endif // SHELL_ENABLE_METAL
#endif //
FLUTTER_
SHELL_ENABLE_METAL
IOSRenderingAPI
GetRenderingAPIForProcess
(
bool
force_software
)
{
IOSRenderingAPI
GetRenderingAPIForProcess
(
bool
force_software
)
{
#if TARGET_OS_SIMULATOR
#if TARGET_OS_SIMULATOR
...
@@ -39,12 +39,12 @@ IOSRenderingAPI GetRenderingAPIForProcess(bool force_software) {
...
@@ -39,12 +39,12 @@ IOSRenderingAPI GetRenderingAPIForProcess(bool force_software) {
}
}
#endif // TARGET_OS_SIMULATOR
#endif // TARGET_OS_SIMULATOR
#if SHELL_ENABLE_METAL
#if
FLUTTER_
SHELL_ENABLE_METAL
static
bool
should_use_metal
=
ShouldUseMetalRenderer
();
static
bool
should_use_metal
=
ShouldUseMetalRenderer
();
if
(
should_use_metal
)
{
if
(
should_use_metal
)
{
return
IOSRenderingAPI
::
kMetal
;
return
IOSRenderingAPI
::
kMetal
;
}
}
#endif // SHELL_ENABLE_METAL
#endif //
FLUTTER_
SHELL_ENABLE_METAL
// OpenGL will be emulated using software rendering by Apple on the simulator, so we use the
// OpenGL will be emulated using software rendering by Apple on the simulator, so we use the
// Skia software rendering since it performs a little better than the emulated OpenGL.
// Skia software rendering since it performs a little better than the emulated OpenGL.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录