Switch the renderer to impeller based on the presence of a command line flag. (flutter/engine#31959)
Specifying the `--enable-impeller` flag will switch the renderer to using Impeller instead of Skia. On platforms where Impeller is not supported, this flag is ignored. The notion of the `flutter::SurfaceFrame` has been augmented. Now, in the absence of a Skia surface to render to, the surface frame will render into a display list instead. Impeller variants of the context and surface variants have been added to `shell/gpu` and `shell/platform`. The variants prepare surface frames that don’t/can’t specify a Skia surface thus forcing the surface frame to render to a display list instead. Then, in the submit callback, they forward the display list ops to the Impeller display list dispatcher. This scheme has been chosen as it requires the fewest updates to engine internals which all depend on Skia data structures. Instead of updating all call-sites to be Skia neutral, the display list interface itself is being made graphics package agnostic.
This commit is contained in:
4
DEPS
4
DEPS
@@ -107,10 +107,10 @@ allowed_hosts = [
|
||||
]
|
||||
|
||||
deps = {
|
||||
'src': 'https://github.com/flutter/buildroot.git' + '@' + 'e4cee118fc80c7cd3b8f8959aa02747a67c38a63',
|
||||
'src': 'https://github.com/flutter/buildroot.git' + '@' + '8cbf38af7d48cc298ae86e614533b4b2d0dc6758',
|
||||
|
||||
'src/flutter/impeller':
|
||||
Var('github_git') + '/flutter/impeller' + '@' + '21f922f9d8409d61b32b135298127f4e30d5bbb1',
|
||||
Var('github_git') + '/flutter/impeller' + '@' + 'c54ddfab21691cf5693c15a4f84d9156fb7d8cfb',
|
||||
|
||||
# Fuchsia compatibility
|
||||
#
|
||||
|
||||
@@ -434,6 +434,8 @@ FILE: ../../../flutter/impeller/entity/contents/content_context.cc
|
||||
FILE: ../../../flutter/impeller/entity/contents/content_context.h
|
||||
FILE: ../../../flutter/impeller/entity/contents/contents.cc
|
||||
FILE: ../../../flutter/impeller/entity/contents/contents.h
|
||||
FILE: ../../../flutter/impeller/entity/contents/filter_contents.cc
|
||||
FILE: ../../../flutter/impeller/entity/contents/filter_contents.h
|
||||
FILE: ../../../flutter/impeller/entity/contents/linear_gradient_contents.cc
|
||||
FILE: ../../../flutter/impeller/entity/contents/linear_gradient_contents.h
|
||||
FILE: ../../../flutter/impeller/entity/contents/solid_color_contents.cc
|
||||
@@ -1098,10 +1100,12 @@ FILE: ../../../flutter/shell/gpu/gpu_surface_gl.cc
|
||||
FILE: ../../../flutter/shell/gpu/gpu_surface_gl.h
|
||||
FILE: ../../../flutter/shell/gpu/gpu_surface_gl_delegate.cc
|
||||
FILE: ../../../flutter/shell/gpu/gpu_surface_gl_delegate.h
|
||||
FILE: ../../../flutter/shell/gpu/gpu_surface_metal.h
|
||||
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_metal_impeller.h
|
||||
FILE: ../../../flutter/shell/gpu/gpu_surface_metal_impeller.mm
|
||||
FILE: ../../../flutter/shell/gpu/gpu_surface_metal_skia.h
|
||||
FILE: ../../../flutter/shell/gpu/gpu_surface_metal_skia.mm
|
||||
FILE: ../../../flutter/shell/gpu/gpu_surface_software.cc
|
||||
FILE: ../../../flutter/shell/gpu/gpu_surface_software.h
|
||||
FILE: ../../../flutter/shell/gpu/gpu_surface_software_delegate.cc
|
||||
@@ -1506,8 +1510,10 @@ FILE: ../../../flutter/shell/platform/darwin/ios/ios_context.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_context.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_gl.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_gl.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_metal.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_metal.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_metal_impeller.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_metal_impeller.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_metal_skia.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_metal_skia.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_software.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_software.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_external_texture_gl.h
|
||||
@@ -1522,8 +1528,10 @@ FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_gl.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_gl.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_metal.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_metal.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_metal_skia.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_software.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_software.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/ios_switchable_gl_context.h
|
||||
|
||||
@@ -192,6 +192,10 @@ struct Settings {
|
||||
// Selects the SkParagraph implementation of the text layout engine.
|
||||
bool enable_skparagraph = false;
|
||||
|
||||
// Enable the Impeller renderer on supported platforms. Ignored if Impeller is
|
||||
// not supported on the platform.
|
||||
bool enable_impeller = false;
|
||||
|
||||
// Selects the DisplayList for storage of rendering operations.
|
||||
bool enable_display_list = true;
|
||||
|
||||
|
||||
@@ -211,13 +211,6 @@ void DisplayListCanvasRecorder::onDrawTextBlob(const SkTextBlob* blob,
|
||||
builder_->setAttributesFromPaint(paint, kDrawTextBlobFlags);
|
||||
builder_->drawTextBlob(sk_ref_sp(blob), x, y);
|
||||
}
|
||||
void DisplayListCanvasRecorder::onDrawShadowRec(const SkPath& path,
|
||||
const SkDrawShadowRec& rec) {
|
||||
// Skia does not expose the SkDrawShadowRec structure in a public
|
||||
// header file so we cannot record this operation.
|
||||
// See: https://bugs.chromium.org/p/skia/issues/detail?id=12125
|
||||
FML_DCHECK(false);
|
||||
}
|
||||
|
||||
void DisplayListCanvasRecorder::onDrawPicture(const SkPicture* picture,
|
||||
const SkMatrix* matrix,
|
||||
@@ -228,4 +221,60 @@ void DisplayListCanvasRecorder::onDrawPicture(const SkPicture* picture,
|
||||
builder_->drawPicture(sk_ref_sp(picture), matrix, paint != nullptr);
|
||||
}
|
||||
|
||||
void DisplayListCanvasRecorder::onDrawShadowRec(const SkPath& path,
|
||||
const SkDrawShadowRec& rec) {
|
||||
// Skia does not expose the SkDrawShadowRec structure in a public
|
||||
// header file so we cannot record this operation.
|
||||
// See: https://bugs.chromium.org/p/skia/issues/detail?id=12125
|
||||
FML_DLOG(ERROR) << "Unimplemented DisplayListCanvasRecorder::"
|
||||
<< __FUNCTION__;
|
||||
}
|
||||
|
||||
void DisplayListCanvasRecorder::didSetM44(const SkM44&) {
|
||||
FML_DLOG(ERROR) << "Unimplemented DisplayListCanvasRecorder::"
|
||||
<< __FUNCTION__;
|
||||
}
|
||||
|
||||
void DisplayListCanvasRecorder::onDrawBehind(const SkPaint&) {
|
||||
FML_DLOG(ERROR) << "Unimplemented DisplayListCanvasRecorder::"
|
||||
<< __FUNCTION__;
|
||||
}
|
||||
|
||||
void DisplayListCanvasRecorder::onDrawRegion(const SkRegion& region,
|
||||
const SkPaint& paint) {
|
||||
FML_DLOG(ERROR) << "Unimplemented DisplayListCanvasRecorder::"
|
||||
<< __FUNCTION__;
|
||||
}
|
||||
|
||||
void DisplayListCanvasRecorder::onDrawPatch(const SkPoint cubics[12],
|
||||
const SkColor colors[4],
|
||||
const SkPoint texCoords[4],
|
||||
SkBlendMode mode,
|
||||
const SkPaint& paint) {
|
||||
FML_DLOG(ERROR) << "Unimplemented DisplayListCanvasRecorder::"
|
||||
<< __FUNCTION__;
|
||||
}
|
||||
|
||||
void DisplayListCanvasRecorder::onDrawEdgeAAQuad(const SkRect& rect,
|
||||
const SkPoint clip[4],
|
||||
SkCanvas::QuadAAFlags aaFlags,
|
||||
const SkColor4f& color,
|
||||
SkBlendMode mode) {
|
||||
FML_DLOG(ERROR) << "Unimplemented DisplayListCanvasRecorder::"
|
||||
<< __FUNCTION__;
|
||||
}
|
||||
|
||||
void DisplayListCanvasRecorder::onDrawAnnotation(const SkRect& rect,
|
||||
const char key[],
|
||||
SkData* value) {
|
||||
FML_DLOG(ERROR) << "Unimplemented DisplayListCanvasRecorder::"
|
||||
<< __FUNCTION__;
|
||||
}
|
||||
|
||||
void DisplayListCanvasRecorder::onDrawDrawable(SkDrawable* drawable,
|
||||
const SkMatrix* matrix) {
|
||||
FML_DLOG(ERROR) << "Unimplemented DisplayListCanvasRecorder::"
|
||||
<< __FUNCTION__;
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -33,7 +33,7 @@ class DisplayListCanvasRecorder
|
||||
sk_sp<DisplayList> Build();
|
||||
|
||||
void didConcat44(const SkM44&) override;
|
||||
void didSetM44(const SkM44&) override { FML_DCHECK(false); }
|
||||
void didSetM44(const SkM44&) override;
|
||||
void didTranslate(SkScalar, SkScalar) override;
|
||||
void didScale(SkScalar, SkScalar) override;
|
||||
|
||||
@@ -52,7 +52,7 @@ class DisplayListCanvasRecorder
|
||||
void didRestore() override;
|
||||
|
||||
void onDrawPaint(const SkPaint& paint) override;
|
||||
void onDrawBehind(const SkPaint&) override { FML_DCHECK(false); }
|
||||
void onDrawBehind(const SkPaint&) override;
|
||||
void onDrawRect(const SkRect& rect, const SkPaint& paint) override;
|
||||
void onDrawRRect(const SkRRect& rrect, const SkPaint& paint) override;
|
||||
void onDrawDRRect(const SkRRect& outer,
|
||||
@@ -65,9 +65,7 @@ class DisplayListCanvasRecorder
|
||||
bool useCenter,
|
||||
const SkPaint& paint) override;
|
||||
void onDrawPath(const SkPath& path, const SkPaint& paint) override;
|
||||
void onDrawRegion(const SkRegion& region, const SkPaint& paint) override {
|
||||
FML_DCHECK(false);
|
||||
}
|
||||
void onDrawRegion(const SkRegion& region, const SkPaint& paint) override;
|
||||
|
||||
void onDrawTextBlob(const SkTextBlob* blob,
|
||||
SkScalar x,
|
||||
@@ -78,9 +76,7 @@ class DisplayListCanvasRecorder
|
||||
const SkColor colors[4],
|
||||
const SkPoint texCoords[4],
|
||||
SkBlendMode mode,
|
||||
const SkPaint& paint) override {
|
||||
FML_DCHECK(false);
|
||||
}
|
||||
const SkPaint& paint) override;
|
||||
void onDrawPoints(SkCanvas::PointMode mode,
|
||||
size_t count,
|
||||
const SkPoint pts[],
|
||||
@@ -119,20 +115,14 @@ class DisplayListCanvasRecorder
|
||||
const SkPoint clip[4],
|
||||
SkCanvas::QuadAAFlags aaFlags,
|
||||
const SkColor4f& color,
|
||||
SkBlendMode mode) override {
|
||||
FML_DCHECK(0);
|
||||
}
|
||||
SkBlendMode mode) override;
|
||||
|
||||
void onDrawAnnotation(const SkRect& rect,
|
||||
const char key[],
|
||||
SkData* value) override {
|
||||
FML_DCHECK(false);
|
||||
}
|
||||
SkData* value) override;
|
||||
void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override;
|
||||
|
||||
void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) override {
|
||||
FML_DCHECK(false);
|
||||
}
|
||||
void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) override;
|
||||
void onDrawPicture(const SkPicture* picture,
|
||||
const SkMatrix* matrix,
|
||||
const SkPaint* paint) override;
|
||||
|
||||
@@ -3,19 +3,15 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/flow/surface_frame.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/trace_event.h"
|
||||
#include "third_party/skia/include/utils/SkNWayCanvas.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
SurfaceFrame::SurfaceFrame(sk_sp<SkSurface> surface,
|
||||
FramebufferInfo framebuffer_info,
|
||||
const SubmitCallback& submit_callback)
|
||||
: surface_(surface),
|
||||
framebuffer_info_(std::move(framebuffer_info)),
|
||||
submit_callback_(submit_callback) {
|
||||
FML_DCHECK(submit_callback_);
|
||||
}
|
||||
|
||||
SurfaceFrame::SurfaceFrame(sk_sp<SkSurface> surface,
|
||||
FramebufferInfo framebuffer_info,
|
||||
const SubmitCallback& submit_callback,
|
||||
@@ -26,6 +22,14 @@ SurfaceFrame::SurfaceFrame(sk_sp<SkSurface> surface,
|
||||
submit_callback_(submit_callback),
|
||||
context_result_(std::move(context_result)) {
|
||||
FML_DCHECK(submit_callback_);
|
||||
if (surface_) {
|
||||
canvas_ = surface_->getCanvas();
|
||||
} else {
|
||||
dl_recorder_ = sk_make_sp<DisplayListCanvasRecorder>(
|
||||
SkRect::MakeWH(std::numeric_limits<SkScalar>::max(),
|
||||
std::numeric_limits<SkScalar>::max()));
|
||||
canvas_ = dl_recorder_.get();
|
||||
}
|
||||
}
|
||||
|
||||
SurfaceFrame::~SurfaceFrame() {
|
||||
@@ -50,7 +54,7 @@ bool SurfaceFrame::IsSubmitted() const {
|
||||
}
|
||||
|
||||
SkCanvas* SurfaceFrame::SkiaCanvas() {
|
||||
return surface_ != nullptr ? surface_->getCanvas() : nullptr;
|
||||
return canvas_;
|
||||
}
|
||||
|
||||
sk_sp<SkSurface> SurfaceFrame::SkiaSurface() const {
|
||||
@@ -69,4 +73,9 @@ bool SurfaceFrame::PerformSubmit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
sk_sp<DisplayList> SurfaceFrame::BuildDisplayList() {
|
||||
TRACE_EVENT0("impeller", "SurfaceFrame::BuildDisplayList");
|
||||
return dl_recorder_ ? dl_recorder_->Build() : nullptr;
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <optional>
|
||||
|
||||
#include "flutter/common/graphics/gl_context_switch.h"
|
||||
#include "flutter/display_list/display_list_canvas_recorder.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
#include "third_party/skia/include/core/SkSurface.h"
|
||||
@@ -20,7 +21,7 @@ namespace flutter {
|
||||
class SurfaceFrame {
|
||||
public:
|
||||
using SubmitCallback =
|
||||
std::function<bool(const SurfaceFrame& surface_frame, SkCanvas* canvas)>;
|
||||
std::function<bool(SurfaceFrame& surface_frame, SkCanvas* canvas)>;
|
||||
|
||||
// Information about the underlying framebuffer
|
||||
struct FramebufferInfo {
|
||||
@@ -46,14 +47,10 @@ class SurfaceFrame {
|
||||
std::optional<SkIRect> existing_damage;
|
||||
};
|
||||
|
||||
SurfaceFrame(sk_sp<SkSurface> surface,
|
||||
FramebufferInfo framebuffer_info,
|
||||
const SubmitCallback& submit_callback);
|
||||
|
||||
SurfaceFrame(sk_sp<SkSurface> surface,
|
||||
FramebufferInfo framebuffer_info,
|
||||
const SubmitCallback& submit_callback,
|
||||
std::unique_ptr<GLContextResult> context_result);
|
||||
std::unique_ptr<GLContextResult> context_result = nullptr);
|
||||
|
||||
~SurfaceFrame();
|
||||
|
||||
@@ -76,10 +73,10 @@ class SurfaceFrame {
|
||||
|
||||
bool IsSubmitted() const;
|
||||
|
||||
SkCanvas* SkiaCanvas();
|
||||
|
||||
sk_sp<SkSurface> SkiaSurface() const;
|
||||
|
||||
SkCanvas* SkiaCanvas();
|
||||
|
||||
const FramebufferInfo& framebuffer_info() const { return framebuffer_info_; }
|
||||
|
||||
void set_submit_info(const SubmitInfo& submit_info) {
|
||||
@@ -87,9 +84,14 @@ class SurfaceFrame {
|
||||
}
|
||||
const SubmitInfo& submit_info() const { return submit_info_; }
|
||||
|
||||
sk_sp<DisplayList> BuildDisplayList();
|
||||
|
||||
private:
|
||||
bool submitted_ = false;
|
||||
|
||||
sk_sp<DisplayListCanvasRecorder> dl_recorder_;
|
||||
sk_sp<SkSurface> surface_;
|
||||
SkCanvas* canvas_ = nullptr;
|
||||
FramebufferInfo framebuffer_info_;
|
||||
SubmitInfo submit_info_;
|
||||
SubmitCallback submit_callback_;
|
||||
|
||||
@@ -187,4 +187,8 @@ PlatformView::GetPlatformMessageHandler() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Settings& PlatformView::GetSettings() const {
|
||||
return delegate_.OnPlatformViewGetSettings();
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -308,6 +308,15 @@ class PlatformView {
|
||||
virtual void UpdateAssetResolverByType(
|
||||
std::unique_ptr<AssetResolver> updated_asset_resolver,
|
||||
AssetResolver::AssetResolverType type) = 0;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/// @brief Called by the platform view on the platform thread to get
|
||||
/// the settings object associated with the platform view
|
||||
/// instance.
|
||||
///
|
||||
/// @return The settings.
|
||||
///
|
||||
virtual const Settings& OnPlatformViewGetSettings() const = 0;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -808,6 +817,13 @@ class PlatformView {
|
||||
virtual std::shared_ptr<PlatformMessageHandler> GetPlatformMessageHandler()
|
||||
const;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief Get the settings for this platform view instance.
|
||||
///
|
||||
/// @return The settings.
|
||||
///
|
||||
const Settings& GetSettings() const;
|
||||
|
||||
protected:
|
||||
// This is the only method called on the raster task runner.
|
||||
virtual std::unique_ptr<Surface> CreateRenderingSurface();
|
||||
|
||||
@@ -1079,6 +1079,11 @@ void Shell::OnPlatformViewSetNextFrameCallback(const fml::closure& closure) {
|
||||
});
|
||||
}
|
||||
|
||||
// |PlatformView::Delegate|
|
||||
const Settings& Shell::OnPlatformViewGetSettings() const {
|
||||
return settings_;
|
||||
}
|
||||
|
||||
// |Animator::Delegate|
|
||||
void Shell::OnAnimatorBeginFrame(fml::TimePoint frame_target_time,
|
||||
uint64_t frame_number) {
|
||||
|
||||
@@ -557,6 +557,9 @@ class Shell final : public PlatformView::Delegate,
|
||||
// |PlatformView::Delegate|
|
||||
void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) override;
|
||||
|
||||
// |PlatformView::Delegate|
|
||||
const Settings& OnPlatformViewGetSettings() const override;
|
||||
|
||||
// |PlatformView::Delegate|
|
||||
void LoadDartDeferredLibrary(
|
||||
intptr_t loading_unit_id,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_metal.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_metal_skia.h"
|
||||
#include "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetal.h"
|
||||
|
||||
namespace flutter {
|
||||
@@ -91,7 +91,7 @@ PointerDataDispatcherMaker ShellTestPlatformViewMetal::GetDispatcherMaker() {
|
||||
|
||||
// |PlatformView|
|
||||
std::unique_ptr<Surface> ShellTestPlatformViewMetal::CreateRenderingSurface() {
|
||||
return std::make_unique<GPUSurfaceMetal>(this, [metal_context_->context() mainContext]);
|
||||
return std::make_unique<GPUSurfaceMetalSkia>(this, [metal_context_->context() mainContext]);
|
||||
}
|
||||
|
||||
// |GPUSurfaceMetalDelegate|
|
||||
|
||||
@@ -86,6 +86,11 @@ class MockPlatformViewDelegate : public PlatformView::Delegate {
|
||||
MOCK_METHOD1(OnPlatformViewMarkTextureFrameAvailable,
|
||||
void(int64_t texture_id));
|
||||
|
||||
MOCK_METHOD(const Settings&,
|
||||
OnPlatformViewGetSettings,
|
||||
(),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD3(LoadDartDeferredLibrary,
|
||||
void(intptr_t loading_unit_id,
|
||||
std::unique_ptr<const fml::Mapping> snapshot_data,
|
||||
|
||||
@@ -421,6 +421,9 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
|
||||
FlagForSwitch(Switch::EnableSkParagraph), "");
|
||||
settings.enable_skparagraph = enable_skparagraph != "false";
|
||||
|
||||
settings.enable_impeller =
|
||||
command_line.HasOption(FlagForSwitch(Switch::EnableImpeller));
|
||||
|
||||
settings.prefetched_default_font_manager = command_line.HasOption(
|
||||
FlagForSwitch(Switch::PrefetchedDefaultFontManager));
|
||||
|
||||
|
||||
@@ -223,7 +223,10 @@ DEF_SWITCH(OldGenHeapSize,
|
||||
DEF_SWITCH(EnableSkParagraph,
|
||||
"enable-skparagraph",
|
||||
"Selects the SkParagraph implementation of the text layout engine.")
|
||||
|
||||
DEF_SWITCH(EnableImpeller,
|
||||
"enable-impeller",
|
||||
"Enable the Impeller renderer on supported platforms. Ignored if "
|
||||
"Impeller is not supported on the platform.")
|
||||
DEF_SWITCH(LeakVM,
|
||||
"leak-vm",
|
||||
"When the last shell shuts down, the shared VM is leaked by default "
|
||||
|
||||
@@ -22,7 +22,7 @@ source_set("gpu_surface_software") {
|
||||
"gpu_surface_software_delegate.h",
|
||||
]
|
||||
|
||||
deps = gpu_common_deps
|
||||
public_deps = gpu_common_deps
|
||||
}
|
||||
|
||||
source_set("gpu_surface_gl") {
|
||||
@@ -33,7 +33,7 @@ source_set("gpu_surface_gl") {
|
||||
"gpu_surface_gl_delegate.h",
|
||||
]
|
||||
|
||||
deps = gpu_common_deps
|
||||
public_deps = gpu_common_deps
|
||||
}
|
||||
|
||||
source_set("gpu_surface_vulkan") {
|
||||
@@ -43,18 +43,21 @@ source_set("gpu_surface_vulkan") {
|
||||
"gpu_surface_vulkan_delegate.cc",
|
||||
"gpu_surface_vulkan_delegate.h",
|
||||
]
|
||||
deps = [ "//flutter/shell/platform/embedder:embedder_headers" ]
|
||||
deps += gpu_common_deps
|
||||
public_deps = [ "//flutter/vulkan" ]
|
||||
public_deps = gpu_common_deps + [
|
||||
"//flutter/shell/platform/embedder:embedder_headers",
|
||||
"//flutter/vulkan",
|
||||
]
|
||||
}
|
||||
|
||||
source_set("gpu_surface_metal") {
|
||||
sources = [
|
||||
"gpu_surface_metal.h",
|
||||
"gpu_surface_metal.mm",
|
||||
"gpu_surface_metal_delegate.cc",
|
||||
"gpu_surface_metal_delegate.h",
|
||||
"gpu_surface_metal_impeller.h",
|
||||
"gpu_surface_metal_impeller.mm",
|
||||
"gpu_surface_metal_skia.h",
|
||||
"gpu_surface_metal_skia.mm",
|
||||
]
|
||||
|
||||
deps = gpu_common_deps
|
||||
public_deps = gpu_common_deps + [ "//flutter/impeller" ]
|
||||
}
|
||||
|
||||
51
engine/src/flutter/shell/gpu/gpu_surface_metal_impeller.h
Normal file
51
engine/src/flutter/shell/gpu/gpu_surface_metal_impeller.h
Normal file
@@ -0,0 +1,51 @@
|
||||
// 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_IMPELLER_H_
|
||||
#define FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_IMPELLER_H_
|
||||
|
||||
#include "flutter/flow/surface.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/impeller/aiks/aiks_context.h"
|
||||
#include "flutter/impeller/renderer/renderer.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
class SK_API_AVAILABLE_CA_METAL_LAYER GPUSurfaceMetalImpeller : public Surface {
|
||||
public:
|
||||
GPUSurfaceMetalImpeller(GPUSurfaceMetalDelegate* delegate);
|
||||
|
||||
// |Surface|
|
||||
~GPUSurfaceMetalImpeller();
|
||||
|
||||
// |Surface|
|
||||
bool IsValid() override;
|
||||
|
||||
private:
|
||||
const GPUSurfaceMetalDelegate* delegate_;
|
||||
std::shared_ptr<impeller::Renderer> impeller_renderer_;
|
||||
std::shared_ptr<impeller::AiksContext> aiks_context_;
|
||||
|
||||
// |Surface|
|
||||
std::unique_ptr<SurfaceFrame> AcquireFrame(const SkISize& size) override;
|
||||
|
||||
// |Surface|
|
||||
SkMatrix GetRootTransformation() const override;
|
||||
|
||||
// |Surface|
|
||||
GrDirectContext* GetContext() override;
|
||||
|
||||
// |Surface|
|
||||
std::unique_ptr<GLContextResult> MakeRenderContextCurrent() override;
|
||||
|
||||
// |Surface|
|
||||
bool AllowsDrawingWhenGpuDisabled() const override;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceMetalImpeller);
|
||||
};
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_IMPELLER_H_
|
||||
124
engine/src/flutter/shell/gpu/gpu_surface_metal_impeller.mm
Normal file
124
engine/src/flutter/shell/gpu/gpu_surface_metal_impeller.mm
Normal file
@@ -0,0 +1,124 @@
|
||||
// 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_impeller.h"
|
||||
|
||||
#import <Metal/Metal.h>
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
#include "flutter/fml/make_copyable.h"
|
||||
#include "flutter/fml/mapping.h"
|
||||
#include "flutter/impeller/display_list/display_list_dispatcher.h"
|
||||
#include "flutter/impeller/entity/entity_shaders.h"
|
||||
#include "flutter/impeller/renderer/backend/metal/context_mtl.h"
|
||||
#include "flutter/impeller/renderer/backend/metal/surface_mtl.h"
|
||||
|
||||
static_assert(!__has_feature(objc_arc), "ARC must be disabled.");
|
||||
|
||||
namespace flutter {
|
||||
|
||||
static std::shared_ptr<impeller::Renderer> CreateImpellerRenderer() {
|
||||
std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
|
||||
std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_data,
|
||||
impeller_entity_shaders_length),
|
||||
};
|
||||
auto context = impeller::ContextMTL::Create(shader_mappings, "Impeller Library");
|
||||
if (!context) {
|
||||
FML_LOG(ERROR) << "Could not create Metal Impeller Context.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto renderer = std::make_shared<impeller::Renderer>(std::move(context));
|
||||
if (!renderer->IsValid()) {
|
||||
FML_LOG(ERROR) << "Could not create valid Impeller Renderer.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
GPUSurfaceMetalImpeller::GPUSurfaceMetalImpeller(GPUSurfaceMetalDelegate* delegate)
|
||||
: delegate_(delegate),
|
||||
impeller_renderer_(CreateImpellerRenderer()),
|
||||
aiks_context_(std::make_shared<impeller::AiksContext>(
|
||||
impeller_renderer_ ? impeller_renderer_->GetContext() : nullptr)) {}
|
||||
|
||||
GPUSurfaceMetalImpeller::~GPUSurfaceMetalImpeller() = default;
|
||||
|
||||
// |Surface|
|
||||
bool GPUSurfaceMetalImpeller::IsValid() {
|
||||
return !!aiks_context_;
|
||||
}
|
||||
|
||||
// |Surface|
|
||||
std::unique_ptr<SurfaceFrame> GPUSurfaceMetalImpeller::AcquireFrame(const SkISize& frame_info) {
|
||||
if (!IsValid()) {
|
||||
FML_LOG(ERROR) << "Metal surface was invalid.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto layer = delegate_->GetCAMetalLayer(frame_info);
|
||||
if (!layer) {
|
||||
FML_LOG(ERROR) << "Invalid CAMetalLayer given by the embedder.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto* mtl_layer = (CAMetalLayer*)layer;
|
||||
|
||||
auto surface = impeller::SurfaceMTL::WrapCurrentMetalLayerDrawable(
|
||||
impeller_renderer_->GetContext(), mtl_layer);
|
||||
|
||||
SurfaceFrame::SubmitCallback submit_callback =
|
||||
fml::MakeCopyable([renderer = impeller_renderer_, //
|
||||
aiks_context = aiks_context_, //
|
||||
surface = std::move(surface) //
|
||||
](SurfaceFrame& surface_frame, SkCanvas* canvas) mutable -> bool {
|
||||
if (!aiks_context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto display_list = surface_frame.BuildDisplayList();
|
||||
if (!display_list) {
|
||||
FML_LOG(ERROR) << "Could not build display list for surface frame.";
|
||||
return false;
|
||||
}
|
||||
|
||||
impeller::DisplayListDispatcher impeller_dispatcher;
|
||||
display_list->Dispatch(impeller_dispatcher);
|
||||
auto picture = impeller_dispatcher.EndRecordingAsPicture();
|
||||
|
||||
return renderer->Render(std::move(surface),
|
||||
fml::MakeCopyable([aiks_context, picture = std::move(picture)](
|
||||
impeller::RenderPass& pass) -> bool {
|
||||
return aiks_context->Render(picture, pass);
|
||||
}));
|
||||
});
|
||||
|
||||
return std::make_unique<SurfaceFrame>(nullptr, SurfaceFrame::FramebufferInfo{}, submit_callback,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
// |Surface|
|
||||
SkMatrix GPUSurfaceMetalImpeller::GetRootTransformation() const {
|
||||
// This backend does not currently support root surface transformations. Just
|
||||
// return identity.
|
||||
return {};
|
||||
}
|
||||
|
||||
// |Surface|
|
||||
GrDirectContext* GPUSurfaceMetalImpeller::GetContext() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// |Surface|
|
||||
std::unique_ptr<GLContextResult> GPUSurfaceMetalImpeller::MakeRenderContextCurrent() {
|
||||
// This backend has no such concept.
|
||||
return std::make_unique<GLContextDefaultResult>(true);
|
||||
}
|
||||
|
||||
bool GPUSurfaceMetalImpeller::AllowsDrawingWhenGpuDisabled() const {
|
||||
return delegate_->AllowsDrawingWhenGpuDisabled();
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
@@ -13,14 +13,14 @@
|
||||
|
||||
namespace flutter {
|
||||
|
||||
class SK_API_AVAILABLE_CA_METAL_LAYER GPUSurfaceMetal : public Surface {
|
||||
class SK_API_AVAILABLE_CA_METAL_LAYER GPUSurfaceMetalSkia : public Surface {
|
||||
public:
|
||||
GPUSurfaceMetal(GPUSurfaceMetalDelegate* delegate,
|
||||
sk_sp<GrDirectContext> context,
|
||||
bool render_to_surface = true);
|
||||
GPUSurfaceMetalSkia(GPUSurfaceMetalDelegate* delegate,
|
||||
sk_sp<GrDirectContext> context,
|
||||
bool render_to_surface = true);
|
||||
|
||||
// |Surface|
|
||||
~GPUSurfaceMetal();
|
||||
~GPUSurfaceMetalSkia();
|
||||
|
||||
// |Surface|
|
||||
bool IsValid() override;
|
||||
@@ -34,7 +34,7 @@ class SK_API_AVAILABLE_CA_METAL_LAYER GPUSurfaceMetal : public Surface {
|
||||
// external view embedder may want to render to the root surface. This is a
|
||||
// hack to make avoid allocating resources for the root surface when an
|
||||
// external view embedder is present.
|
||||
bool render_to_surface_;
|
||||
bool render_to_surface_ = true;
|
||||
|
||||
// Accumulated damage for each framebuffer; Key is address of underlying
|
||||
// MTLTexture for each drawable
|
||||
@@ -63,7 +63,7 @@ class SK_API_AVAILABLE_CA_METAL_LAYER GPUSurfaceMetal : public Surface {
|
||||
|
||||
void PrecompileKnownSkSLsIfNecessary();
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceMetal);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceMetalSkia);
|
||||
};
|
||||
|
||||
} // namespace flutter
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_metal_skia.h"
|
||||
|
||||
#import <Metal/Metal.h>
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
@@ -37,22 +37,22 @@ sk_sp<SkSurface> CreateSurfaceFromMetalTexture(GrDirectContext* context,
|
||||
}
|
||||
} // namespace
|
||||
|
||||
GPUSurfaceMetal::GPUSurfaceMetal(GPUSurfaceMetalDelegate* delegate,
|
||||
sk_sp<GrDirectContext> context,
|
||||
bool render_to_surface)
|
||||
GPUSurfaceMetalSkia::GPUSurfaceMetalSkia(GPUSurfaceMetalDelegate* delegate,
|
||||
sk_sp<GrDirectContext> context,
|
||||
bool render_to_surface)
|
||||
: delegate_(delegate),
|
||||
render_target_type_(delegate->GetRenderTargetType()),
|
||||
context_(std::move(context)),
|
||||
render_to_surface_(render_to_surface) {}
|
||||
|
||||
GPUSurfaceMetal::~GPUSurfaceMetal() = default;
|
||||
GPUSurfaceMetalSkia::~GPUSurfaceMetalSkia() = default;
|
||||
|
||||
// |Surface|
|
||||
bool GPUSurfaceMetal::IsValid() {
|
||||
bool GPUSurfaceMetalSkia::IsValid() {
|
||||
return context_ != nullptr;
|
||||
}
|
||||
|
||||
void GPUSurfaceMetal::PrecompileKnownSkSLsIfNecessary() {
|
||||
void GPUSurfaceMetalSkia::PrecompileKnownSkSLsIfNecessary() {
|
||||
auto* current_context = GetContext();
|
||||
if (current_context == precompiled_sksl_context_) {
|
||||
// Known SkSLs have already been prepared in this context.
|
||||
@@ -63,7 +63,7 @@ void GPUSurfaceMetal::PrecompileKnownSkSLsIfNecessary() {
|
||||
}
|
||||
|
||||
// |Surface|
|
||||
std::unique_ptr<SurfaceFrame> GPUSurfaceMetal::AcquireFrame(const SkISize& frame_size) {
|
||||
std::unique_ptr<SurfaceFrame> GPUSurfaceMetalSkia::AcquireFrame(const SkISize& frame_size) {
|
||||
if (!IsValid()) {
|
||||
FML_LOG(ERROR) << "Metal surface was invalid.";
|
||||
return nullptr;
|
||||
@@ -94,7 +94,7 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceMetal::AcquireFrame(const SkISize& frame
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<SurfaceFrame> GPUSurfaceMetal::AcquireFrameFromCAMetalLayer(
|
||||
std::unique_ptr<SurfaceFrame> GPUSurfaceMetalSkia::AcquireFrameFromCAMetalLayer(
|
||||
const SkISize& frame_info) {
|
||||
auto layer = delegate_->GetCAMetalLayer(frame_info);
|
||||
if (!layer) {
|
||||
@@ -167,7 +167,7 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceMetal::AcquireFrameFromCAMetalLayer(
|
||||
return std::make_unique<SurfaceFrame>(std::move(surface), framebuffer_info, submit_callback);
|
||||
}
|
||||
|
||||
std::unique_ptr<SurfaceFrame> GPUSurfaceMetal::AcquireFrameFromMTLTexture(
|
||||
std::unique_ptr<SurfaceFrame> GPUSurfaceMetalSkia::AcquireFrameFromMTLTexture(
|
||||
const SkISize& frame_info) {
|
||||
GPUMTLTextureInfo texture = delegate_->GetMTLTexture(frame_info);
|
||||
id<MTLTexture> mtl_texture = (id<MTLTexture>)(texture.texture);
|
||||
@@ -210,19 +210,19 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceMetal::AcquireFrameFromMTLTexture(
|
||||
}
|
||||
|
||||
// |Surface|
|
||||
SkMatrix GPUSurfaceMetal::GetRootTransformation() const {
|
||||
SkMatrix GPUSurfaceMetalSkia::GetRootTransformation() const {
|
||||
// This backend does not currently support root surface transformations. Just
|
||||
// return identity.
|
||||
return {};
|
||||
}
|
||||
|
||||
// |Surface|
|
||||
GrDirectContext* GPUSurfaceMetal::GetContext() {
|
||||
GrDirectContext* GPUSurfaceMetalSkia::GetContext() {
|
||||
return context_.get();
|
||||
}
|
||||
|
||||
// |Surface|
|
||||
std::unique_ptr<GLContextResult> GPUSurfaceMetal::MakeRenderContextCurrent() {
|
||||
std::unique_ptr<GLContextResult> GPUSurfaceMetalSkia::MakeRenderContextCurrent() {
|
||||
// A context may either be necessary to render to the surface or to snapshot an offscreen
|
||||
// surface. Either way, SkSL precompilation must be attempted.
|
||||
PrecompileKnownSkSLsIfNecessary();
|
||||
@@ -231,7 +231,7 @@ std::unique_ptr<GLContextResult> GPUSurfaceMetal::MakeRenderContextCurrent() {
|
||||
return std::make_unique<GLContextDefaultResult>(true);
|
||||
}
|
||||
|
||||
bool GPUSurfaceMetal::AllowsDrawingWhenGpuDisabled() const {
|
||||
bool GPUSurfaceMetalSkia::AllowsDrawingWhenGpuDisabled() const {
|
||||
return delegate_->AllowsDrawingWhenGpuDisabled();
|
||||
}
|
||||
|
||||
@@ -51,10 +51,10 @@ source_set("surface_mock") {
|
||||
|
||||
deps = [
|
||||
":surface",
|
||||
"//flutter/flow",
|
||||
"//flutter/shell/gpu:gpu_surface_gl",
|
||||
"//third_party/googletest:gmock",
|
||||
"//third_party/googletest:gtest",
|
||||
"//third_party/skia",
|
||||
]
|
||||
|
||||
if (shell_enable_vulkan) {
|
||||
|
||||
@@ -138,12 +138,16 @@ source_set("flutter_framework_source") {
|
||||
|
||||
if (shell_enable_metal) {
|
||||
sources += [
|
||||
"ios_context_metal.h",
|
||||
"ios_context_metal.mm",
|
||||
"ios_context_metal_impeller.h",
|
||||
"ios_context_metal_impeller.mm",
|
||||
"ios_context_metal_skia.h",
|
||||
"ios_context_metal_skia.mm",
|
||||
"ios_external_texture_metal.h",
|
||||
"ios_external_texture_metal.mm",
|
||||
"ios_surface_metal.h",
|
||||
"ios_surface_metal.mm",
|
||||
"ios_surface_metal_impeller.h",
|
||||
"ios_surface_metal_impeller.mm",
|
||||
"ios_surface_metal_skia.h",
|
||||
"ios_surface_metal_skia.mm",
|
||||
]
|
||||
|
||||
deps += [ "//flutter/shell/platform/darwin/graphics" ]
|
||||
|
||||
@@ -24,6 +24,7 @@ class FakeDelegate : public PlatformView::Delegate {
|
||||
void OnPlatformViewScheduleFrame() override {}
|
||||
void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) override {}
|
||||
void OnPlatformViewSetViewportMetrics(const ViewportMetrics& metrics) override {}
|
||||
const flutter::Settings& OnPlatformViewGetSettings() const override { return settings_; }
|
||||
void OnPlatformViewDispatchPlatformMessage(std::unique_ptr<PlatformMessage> message) override {}
|
||||
void OnPlatformViewDispatchPointerDataPacket(std::unique_ptr<PointerDataPacket> packet) override {
|
||||
}
|
||||
@@ -45,6 +46,9 @@ class FakeDelegate : public PlatformView::Delegate {
|
||||
bool transient) override {}
|
||||
void UpdateAssetResolverByType(std::unique_ptr<AssetResolver> updated_asset_resolver,
|
||||
AssetResolver::AssetResolverType type) override {}
|
||||
|
||||
private:
|
||||
flutter::Settings settings_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -93,6 +93,7 @@ class FlutterPlatformViewsTestMockPlatformViewDelegate : public PlatformView::De
|
||||
void OnPlatformViewScheduleFrame() override {}
|
||||
void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) override {}
|
||||
void OnPlatformViewSetViewportMetrics(const ViewportMetrics& metrics) override {}
|
||||
const flutter::Settings& OnPlatformViewGetSettings() const override { return settings_; }
|
||||
void OnPlatformViewDispatchPlatformMessage(std::unique_ptr<PlatformMessage> message) override {}
|
||||
void OnPlatformViewDispatchPointerDataPacket(std::unique_ptr<PointerDataPacket> packet) override {
|
||||
}
|
||||
@@ -114,6 +115,9 @@ class FlutterPlatformViewsTestMockPlatformViewDelegate : public PlatformView::De
|
||||
bool transient) override {}
|
||||
void UpdateAssetResolverByType(std::unique_ptr<flutter::AssetResolver> updated_asset_resolver,
|
||||
flutter::AssetResolver::AssetResolverType type) override {}
|
||||
|
||||
private:
|
||||
flutter::Settings settings_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -77,6 +77,7 @@ class MockDelegate : public PlatformView::Delegate {
|
||||
void OnPlatformViewScheduleFrame() override {}
|
||||
void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) override {}
|
||||
void OnPlatformViewSetViewportMetrics(const ViewportMetrics& metrics) override {}
|
||||
const flutter::Settings& OnPlatformViewGetSettings() const override { return settings_; }
|
||||
void OnPlatformViewDispatchPlatformMessage(std::unique_ptr<PlatformMessage> message) override {}
|
||||
void OnPlatformViewDispatchPointerDataPacket(std::unique_ptr<PointerDataPacket> packet) override {
|
||||
}
|
||||
@@ -98,6 +99,9 @@ class MockDelegate : public PlatformView::Delegate {
|
||||
bool transient) override {}
|
||||
void UpdateAssetResolverByType(std::unique_ptr<flutter::AssetResolver> updated_asset_resolver,
|
||||
flutter::AssetResolver::AssetResolverType type) override {}
|
||||
|
||||
private:
|
||||
flutter::Settings settings_;
|
||||
};
|
||||
|
||||
class MockIosDelegate : public AccessibilityBridge::IosDelegate {
|
||||
|
||||
@@ -39,12 +39,12 @@ class IOSContext {
|
||||
/// In case the engine does not support the specified client
|
||||
/// rendering API, this a `nullptr` may be returned.
|
||||
///
|
||||
/// @param[in] rendering_api A client rendering API supported by the
|
||||
/// engine/platform.
|
||||
/// @param[in] api A client rendering API supported by the
|
||||
/// engine/platform.
|
||||
///
|
||||
/// @return A valid context on success. `nullptr` on failure.
|
||||
///
|
||||
static std::unique_ptr<IOSContext> Create(IOSRenderingAPI rendering_api);
|
||||
static std::unique_ptr<IOSContext> Create(IOSRenderingAPI api, IOSRenderingBackend backend);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief Collects the context object. This must happen on the thread on
|
||||
@@ -52,6 +52,13 @@ class IOSContext {
|
||||
///
|
||||
virtual ~IOSContext();
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief Get the rendering backend used by this context.
|
||||
///
|
||||
/// @return The rendering backend.
|
||||
///
|
||||
virtual IOSRenderingBackend GetBackend() const;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief Create a resource context for use on the IO task runner. This
|
||||
/// resource context is used by Skia to upload texture to
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
#import "flutter/shell/platform/darwin/ios/ios_context_software.h"
|
||||
|
||||
#if SHELL_ENABLE_METAL
|
||||
#import "flutter/shell/platform/darwin/ios/ios_context_metal.h"
|
||||
#import "flutter/shell/platform/darwin/ios/ios_context_metal_impeller.h"
|
||||
#import "flutter/shell/platform/darwin/ios/ios_context_metal_skia.h"
|
||||
#endif // SHELL_ENABLE_METAL
|
||||
|
||||
namespace flutter {
|
||||
@@ -18,15 +19,20 @@ IOSContext::IOSContext() = default;
|
||||
|
||||
IOSContext::~IOSContext() = default;
|
||||
|
||||
std::unique_ptr<IOSContext> IOSContext::Create(IOSRenderingAPI rendering_api) {
|
||||
switch (rendering_api) {
|
||||
std::unique_ptr<IOSContext> IOSContext::Create(IOSRenderingAPI api, IOSRenderingBackend backend) {
|
||||
switch (api) {
|
||||
case IOSRenderingAPI::kOpenGLES:
|
||||
return std::make_unique<IOSContextGL>();
|
||||
case IOSRenderingAPI::kSoftware:
|
||||
return std::make_unique<IOSContextSoftware>();
|
||||
#if SHELL_ENABLE_METAL
|
||||
case IOSRenderingAPI::kMetal:
|
||||
return std::make_unique<IOSContextMetal>();
|
||||
switch (backend) {
|
||||
case IOSRenderingBackend::kSkia:
|
||||
return std::make_unique<IOSContextMetalSkia>();
|
||||
case IOSRenderingBackend::kImpeller:
|
||||
return std::make_unique<IOSContextMetalImpeller>();
|
||||
}
|
||||
#endif // SHELL_ENABLE_METAL
|
||||
default:
|
||||
break;
|
||||
@@ -35,4 +41,8 @@ std::unique_ptr<IOSContext> IOSContext::Create(IOSRenderingAPI rendering_api) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IOSRenderingBackend IOSContext::GetBackend() const {
|
||||
return IOSRenderingBackend::kSkia;
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
// 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_PLATFORM_DARWIN_IOS_IOS_CONTEXT_METAL_IMPELER_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_METAL_IMPELER_H_
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetal.h"
|
||||
#include "flutter/shell/platform/darwin/ios/ios_context.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
class IOSContextMetalImpeller final : public IOSContext {
|
||||
public:
|
||||
IOSContextMetalImpeller();
|
||||
|
||||
~IOSContextMetalImpeller();
|
||||
|
||||
fml::scoped_nsobject<FlutterDarwinContextMetal> GetDarwinContext() const;
|
||||
|
||||
IOSRenderingBackend GetBackend() const override;
|
||||
|
||||
// |IOSContext|
|
||||
sk_sp<GrDirectContext> GetMainContext() const override;
|
||||
|
||||
sk_sp<GrDirectContext> GetResourceContext() const;
|
||||
|
||||
private:
|
||||
// |IOSContext|
|
||||
sk_sp<GrDirectContext> CreateResourceContext() override;
|
||||
|
||||
// |IOSContext|
|
||||
std::unique_ptr<GLContextResult> MakeCurrent() override;
|
||||
|
||||
// |IOSContext|
|
||||
std::unique_ptr<Texture> CreateExternalTexture(
|
||||
int64_t texture_id,
|
||||
fml::scoped_nsobject<NSObject<FlutterTexture>> texture) override;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(IOSContextMetalImpeller);
|
||||
};
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_METAL_IMPELER_H_
|
||||
@@ -0,0 +1,47 @@
|
||||
// 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/ios/ios_context_metal_impeller.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
IOSContextMetalImpeller::IOSContextMetalImpeller() = default;
|
||||
|
||||
IOSContextMetalImpeller::~IOSContextMetalImpeller() = default;
|
||||
|
||||
fml::scoped_nsobject<FlutterDarwinContextMetal> IOSContextMetalImpeller::GetDarwinContext() const {
|
||||
return fml::scoped_nsobject<FlutterDarwinContextMetal>{};
|
||||
}
|
||||
|
||||
IOSRenderingBackend IOSContextMetalImpeller::GetBackend() const {
|
||||
return IOSRenderingBackend::kImpeller;
|
||||
}
|
||||
|
||||
sk_sp<GrDirectContext> IOSContextMetalImpeller::GetMainContext() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sk_sp<GrDirectContext> IOSContextMetalImpeller::GetResourceContext() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// |IOSContext|
|
||||
sk_sp<GrDirectContext> IOSContextMetalImpeller::CreateResourceContext() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// |IOSContext|
|
||||
std::unique_ptr<GLContextResult> IOSContextMetalImpeller::MakeCurrent() {
|
||||
// This only makes sense for contexts that need to be bound to a specific thread.
|
||||
return std::make_unique<GLContextDefaultResult>(true);
|
||||
}
|
||||
|
||||
// |IOSContext|
|
||||
std::unique_ptr<Texture> IOSContextMetalImpeller::CreateExternalTexture(
|
||||
int64_t texture_id,
|
||||
fml::scoped_nsobject<NSObject<FlutterTexture>> texture) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
@@ -2,8 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_METAL_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_METAL_H_
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_METAL_SKIA_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_METAL_SKIA_H_
|
||||
|
||||
#include <Metal/Metal.h>
|
||||
|
||||
@@ -16,14 +16,17 @@
|
||||
|
||||
namespace flutter {
|
||||
|
||||
class IOSContextMetal final : public IOSContext {
|
||||
class IOSContextMetalSkia final : public IOSContext {
|
||||
public:
|
||||
IOSContextMetal();
|
||||
IOSContextMetalSkia();
|
||||
|
||||
~IOSContextMetal();
|
||||
~IOSContextMetalSkia();
|
||||
|
||||
fml::scoped_nsobject<FlutterDarwinContextMetal> GetDarwinContext() const;
|
||||
|
||||
// |IOSContext|
|
||||
IOSRenderingBackend GetBackend() const override;
|
||||
|
||||
// |IOSContext|
|
||||
sk_sp<GrDirectContext> GetMainContext() const override;
|
||||
|
||||
@@ -45,9 +48,9 @@ class IOSContextMetal final : public IOSContext {
|
||||
int64_t texture_id,
|
||||
fml::scoped_nsobject<NSObject<FlutterTexture>> texture) override;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(IOSContextMetal);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(IOSContextMetalSkia);
|
||||
};
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_METAL_H_
|
||||
#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_METAL_SKIA_H_
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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/ios/ios_context_metal.h"
|
||||
#import "flutter/shell/platform/darwin/ios/ios_context_metal_skia.h"
|
||||
|
||||
#include "flutter/common/graphics/persistent_cache.h"
|
||||
#include "flutter/fml/logging.h"
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace flutter {
|
||||
|
||||
IOSContextMetal::IOSContextMetal() {
|
||||
IOSContextMetalSkia::IOSContextMetalSkia() {
|
||||
darwin_context_metal_ = fml::scoped_nsobject<FlutterDarwinContextMetal>{
|
||||
[[FlutterDarwinContextMetal alloc] initWithDefaultMTLDevice]};
|
||||
|
||||
@@ -36,33 +36,37 @@ IOSContextMetal::IOSContextMetal() {
|
||||
texture_cache_.Reset(texture_cache_raw);
|
||||
}
|
||||
|
||||
IOSContextMetal::~IOSContextMetal() = default;
|
||||
IOSContextMetalSkia::~IOSContextMetalSkia() = default;
|
||||
|
||||
fml::scoped_nsobject<FlutterDarwinContextMetal> IOSContextMetal::GetDarwinContext() const {
|
||||
fml::scoped_nsobject<FlutterDarwinContextMetal> IOSContextMetalSkia::GetDarwinContext() const {
|
||||
return darwin_context_metal_;
|
||||
}
|
||||
|
||||
sk_sp<GrDirectContext> IOSContextMetal::GetMainContext() const {
|
||||
IOSRenderingBackend IOSContextMetalSkia::GetBackend() const {
|
||||
return IOSRenderingBackend::kSkia;
|
||||
}
|
||||
|
||||
sk_sp<GrDirectContext> IOSContextMetalSkia::GetMainContext() const {
|
||||
return darwin_context_metal_.get().mainContext;
|
||||
}
|
||||
|
||||
sk_sp<GrDirectContext> IOSContextMetal::GetResourceContext() const {
|
||||
sk_sp<GrDirectContext> IOSContextMetalSkia::GetResourceContext() const {
|
||||
return darwin_context_metal_.get().resourceContext;
|
||||
}
|
||||
|
||||
// |IOSContext|
|
||||
sk_sp<GrDirectContext> IOSContextMetal::CreateResourceContext() {
|
||||
sk_sp<GrDirectContext> IOSContextMetalSkia::CreateResourceContext() {
|
||||
return darwin_context_metal_.get().resourceContext;
|
||||
}
|
||||
|
||||
// |IOSContext|
|
||||
std::unique_ptr<GLContextResult> IOSContextMetal::MakeCurrent() {
|
||||
std::unique_ptr<GLContextResult> IOSContextMetalSkia::MakeCurrent() {
|
||||
// This only makes sense for context that need to be bound to a specific thread.
|
||||
return std::make_unique<GLContextDefaultResult>(true);
|
||||
}
|
||||
|
||||
// |IOSContext|
|
||||
std::unique_ptr<Texture> IOSContextMetal::CreateExternalTexture(
|
||||
std::unique_ptr<Texture> IOSContextMetalSkia::CreateExternalTexture(
|
||||
int64_t texture_id,
|
||||
fml::scoped_nsobject<NSObject<FlutterTexture>> texture) {
|
||||
return std::make_unique<IOSExternalTextureMetal>(
|
||||
@@ -10,7 +10,8 @@
|
||||
#include "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
|
||||
|
||||
#if SHELL_ENABLE_METAL
|
||||
#import "flutter/shell/platform/darwin/ios/ios_surface_metal.h"
|
||||
#import "flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.h"
|
||||
#import "flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h"
|
||||
#endif // SHELL_ENABLE_METAL
|
||||
|
||||
namespace flutter {
|
||||
@@ -31,11 +32,21 @@ std::unique_ptr<IOSSurface> IOSSurface::Create(std::shared_ptr<IOSContext> conte
|
||||
#if SHELL_ENABLE_METAL
|
||||
if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
|
||||
if ([layer.get() isKindOfClass:[CAMetalLayer class]]) {
|
||||
return std::make_unique<IOSSurfaceMetal>(
|
||||
fml::scoped_nsobject<CAMetalLayer>(
|
||||
reinterpret_cast<CAMetalLayer*>([layer.get() retain])), // Metal layer
|
||||
std::move(context) // context
|
||||
);
|
||||
switch (context->GetBackend()) {
|
||||
case IOSRenderingBackend::kSkia:
|
||||
return std::make_unique<IOSSurfaceMetalSkia>(
|
||||
fml::scoped_nsobject<CAMetalLayer>(
|
||||
reinterpret_cast<CAMetalLayer*>([layer.get() retain])), // Metal layer
|
||||
std::move(context) // context
|
||||
);
|
||||
break;
|
||||
case IOSRenderingBackend::kImpeller:
|
||||
return std::make_unique<IOSSurfaceMetalImpeller>(
|
||||
fml::scoped_nsobject<CAMetalLayer>(
|
||||
reinterpret_cast<CAMetalLayer*>([layer.get() retain])), // Metal layer
|
||||
std::move(context) // context
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // SHELL_ENABLE_METAL
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// 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_PLATFORM_DARWIN_IOS_IOS_SURFACE_METAL_IMPELLER_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_METAL_IMPELLER_H_
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
|
||||
#import "flutter/shell/platform/darwin/ios/ios_surface.h"
|
||||
|
||||
@class CAMetalLayer;
|
||||
|
||||
namespace flutter {
|
||||
|
||||
class SK_API_AVAILABLE_CA_METAL_LAYER IOSSurfaceMetalImpeller final
|
||||
: public IOSSurface,
|
||||
public GPUSurfaceMetalDelegate {
|
||||
public:
|
||||
IOSSurfaceMetalImpeller(fml::scoped_nsobject<CAMetalLayer> layer,
|
||||
std::shared_ptr<IOSContext> context);
|
||||
|
||||
// |IOSSurface|
|
||||
~IOSSurfaceMetalImpeller();
|
||||
|
||||
private:
|
||||
fml::scoped_nsobject<CAMetalLayer> layer_;
|
||||
bool is_valid_ = false;
|
||||
|
||||
// |IOSSurface|
|
||||
bool IsValid() const override;
|
||||
|
||||
// |IOSSurface|
|
||||
void UpdateStorageSizeIfNecessary() override;
|
||||
|
||||
// |IOSSurface|
|
||||
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(GPUMTLTextureInfo texture) const override;
|
||||
|
||||
// |GPUSurfaceMetalDelegate|
|
||||
bool AllowsDrawingWhenGpuDisabled() const override;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(IOSSurfaceMetalImpeller);
|
||||
};
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_METAL_IMPELLER_H_
|
||||
@@ -0,0 +1,71 @@
|
||||
// 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/ios/ios_surface_metal_impeller.h"
|
||||
|
||||
#include "flutter/shell/gpu/gpu_surface_metal_impeller.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
IOSSurfaceMetalImpeller::IOSSurfaceMetalImpeller(fml::scoped_nsobject<CAMetalLayer> layer,
|
||||
std::shared_ptr<IOSContext> context)
|
||||
: IOSSurface(std::move(context)),
|
||||
GPUSurfaceMetalDelegate(MTLRenderTargetType::kCAMetalLayer),
|
||||
layer_(std::move(layer)) {}
|
||||
|
||||
// |IOSSurface|
|
||||
IOSSurfaceMetalImpeller::~IOSSurfaceMetalImpeller() = default;
|
||||
|
||||
// |IOSSurface|
|
||||
bool IOSSurfaceMetalImpeller::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
// |IOSSurface|
|
||||
void IOSSurfaceMetalImpeller::UpdateStorageSizeIfNecessary() {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
// |IOSSurface|
|
||||
std::unique_ptr<Surface> IOSSurfaceMetalImpeller::CreateGPUSurface(GrDirectContext*) {
|
||||
return std::make_unique<GPUSurfaceMetalImpeller>(this /* delegate */);
|
||||
}
|
||||
|
||||
// |GPUSurfaceMetalDelegate|
|
||||
GPUCAMetalLayerHandle IOSSurfaceMetalImpeller::GetCAMetalLayer(const SkISize& frame_info) const {
|
||||
CAMetalLayer* layer = layer_.get();
|
||||
const auto drawable_size = CGSizeMake(frame_info.width(), frame_info.height());
|
||||
if (!CGSizeEqualToSize(drawable_size, layer.drawableSize)) {
|
||||
layer.drawableSize = drawable_size;
|
||||
}
|
||||
return layer;
|
||||
}
|
||||
|
||||
// |GPUSurfaceMetalDelegate|
|
||||
bool IOSSurfaceMetalImpeller::PresentDrawable(GrMTLHandle drawable) const {
|
||||
FML_DCHECK(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// |GPUSurfaceMetalDelegate|
|
||||
GPUMTLTextureInfo IOSSurfaceMetalImpeller::GetMTLTexture(const SkISize& frame_info) const {
|
||||
FML_CHECK(false);
|
||||
return GPUMTLTextureInfo{
|
||||
.texture_id = -1, //
|
||||
.texture = nullptr //
|
||||
};
|
||||
}
|
||||
|
||||
// |GPUSurfaceMetalDelegate|
|
||||
bool IOSSurfaceMetalImpeller::PresentTexture(GPUMTLTextureInfo texture) const {
|
||||
FML_CHECK(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// |GPUSurfaceMetalDelegate|
|
||||
bool IOSSurfaceMetalImpeller::AllowsDrawingWhenGpuDisabled() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
@@ -2,8 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_METAL_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_METAL_H_
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_METAL_SKIA_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_METAL_SKIA_H_
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
|
||||
@@ -14,13 +14,14 @@
|
||||
|
||||
namespace flutter {
|
||||
|
||||
class SK_API_AVAILABLE_CA_METAL_LAYER IOSSurfaceMetal final : public IOSSurface,
|
||||
public GPUSurfaceMetalDelegate {
|
||||
class SK_API_AVAILABLE_CA_METAL_LAYER IOSSurfaceMetalSkia final : public IOSSurface,
|
||||
public GPUSurfaceMetalDelegate {
|
||||
public:
|
||||
IOSSurfaceMetal(fml::scoped_nsobject<CAMetalLayer> layer, std::shared_ptr<IOSContext> context);
|
||||
IOSSurfaceMetalSkia(fml::scoped_nsobject<CAMetalLayer> layer,
|
||||
std::shared_ptr<IOSContext> context);
|
||||
|
||||
// |IOSSurface|
|
||||
~IOSSurfaceMetal();
|
||||
~IOSSurfaceMetalSkia();
|
||||
|
||||
private:
|
||||
fml::scoped_nsobject<CAMetalLayer> layer_;
|
||||
@@ -52,9 +53,9 @@ class SK_API_AVAILABLE_CA_METAL_LAYER IOSSurfaceMetal final : public IOSSurface,
|
||||
// |GPUSurfaceMetalDelegate|
|
||||
bool AllowsDrawingWhenGpuDisabled() const override;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(IOSSurfaceMetal);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(IOSSurfaceMetalSkia);
|
||||
};
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_METAL_H_
|
||||
#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_METAL_SKIA_H_
|
||||
@@ -2,20 +2,20 @@
|
||||
// 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/ios/ios_surface_metal.h"
|
||||
#import "flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h"
|
||||
|
||||
#include "flutter/shell/gpu/gpu_surface_metal.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
|
||||
#include "flutter/shell/platform/darwin/ios/ios_context_metal.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_metal_skia.h"
|
||||
#include "flutter/shell/platform/darwin/ios/ios_context_metal_skia.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
static IOSContextMetal* CastToMetalContext(const std::shared_ptr<IOSContext>& context) {
|
||||
return reinterpret_cast<IOSContextMetal*>(context.get());
|
||||
static IOSContextMetalSkia* CastToMetalContext(const std::shared_ptr<IOSContext>& context) {
|
||||
return reinterpret_cast<IOSContextMetalSkia*>(context.get());
|
||||
}
|
||||
|
||||
IOSSurfaceMetal::IOSSurfaceMetal(fml::scoped_nsobject<CAMetalLayer> layer,
|
||||
std::shared_ptr<IOSContext> context)
|
||||
IOSSurfaceMetalSkia::IOSSurfaceMetalSkia(fml::scoped_nsobject<CAMetalLayer> layer,
|
||||
std::shared_ptr<IOSContext> context)
|
||||
: IOSSurface(std::move(context)),
|
||||
GPUSurfaceMetalDelegate(MTLRenderTargetType::kCAMetalLayer),
|
||||
layer_(std::move(layer)) {
|
||||
@@ -27,28 +27,28 @@ IOSSurfaceMetal::IOSSurfaceMetal(fml::scoped_nsobject<CAMetalLayer> layer,
|
||||
}
|
||||
|
||||
// |IOSSurface|
|
||||
IOSSurfaceMetal::~IOSSurfaceMetal() = default;
|
||||
IOSSurfaceMetalSkia::~IOSSurfaceMetalSkia() = default;
|
||||
|
||||
// |IOSSurface|
|
||||
bool IOSSurfaceMetal::IsValid() const {
|
||||
bool IOSSurfaceMetalSkia::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
// |IOSSurface|
|
||||
void IOSSurfaceMetal::UpdateStorageSizeIfNecessary() {
|
||||
void IOSSurfaceMetalSkia::UpdateStorageSizeIfNecessary() {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
// |IOSSurface|
|
||||
std::unique_ptr<Surface> IOSSurfaceMetal::CreateGPUSurface(GrDirectContext* context) {
|
||||
std::unique_ptr<Surface> IOSSurfaceMetalSkia::CreateGPUSurface(GrDirectContext* context) {
|
||||
FML_DCHECK(context);
|
||||
return std::make_unique<GPUSurfaceMetal>(this, // layer
|
||||
sk_ref_sp(context) // context
|
||||
return std::make_unique<GPUSurfaceMetalSkia>(this, // layer
|
||||
sk_ref_sp(context) // context
|
||||
);
|
||||
}
|
||||
|
||||
// |GPUSurfaceMetalDelegate|
|
||||
GPUCAMetalLayerHandle IOSSurfaceMetal::GetCAMetalLayer(const SkISize& frame_info) const {
|
||||
GPUCAMetalLayerHandle IOSSurfaceMetalSkia::GetCAMetalLayer(const SkISize& frame_info) const {
|
||||
CAMetalLayer* layer = layer_.get();
|
||||
layer.device = device_;
|
||||
|
||||
@@ -71,7 +71,7 @@ GPUCAMetalLayerHandle IOSSurfaceMetal::GetCAMetalLayer(const SkISize& frame_info
|
||||
}
|
||||
|
||||
// |GPUSurfaceMetalDelegate|
|
||||
bool IOSSurfaceMetal::PresentDrawable(GrMTLHandle drawable) const {
|
||||
bool IOSSurfaceMetalSkia::PresentDrawable(GrMTLHandle drawable) const {
|
||||
if (drawable == nullptr) {
|
||||
FML_DLOG(ERROR) << "Could not acquire next Metal drawable from the SkSurface.";
|
||||
return false;
|
||||
@@ -87,19 +87,19 @@ bool IOSSurfaceMetal::PresentDrawable(GrMTLHandle drawable) const {
|
||||
}
|
||||
|
||||
// |GPUSurfaceMetalDelegate|
|
||||
GPUMTLTextureInfo IOSSurfaceMetal::GetMTLTexture(const SkISize& frame_info) const {
|
||||
GPUMTLTextureInfo IOSSurfaceMetalSkia::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(GPUMTLTextureInfo texture) const {
|
||||
bool IOSSurfaceMetalSkia::PresentTexture(GPUMTLTextureInfo texture) const {
|
||||
FML_CHECK(false) << "render to texture not supported on ios";
|
||||
return false;
|
||||
}
|
||||
|
||||
// |GPUSurfaceMetalDelegate|
|
||||
bool IOSSurfaceMetal::AllowsDrawingWhenGpuDisabled() const {
|
||||
bool IOSSurfaceMetalSkia::AllowsDrawingWhenGpuDisabled() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,10 @@ PlatformViewIOS::PlatformViewIOS(
|
||||
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller,
|
||||
flutter::TaskRunners task_runners)
|
||||
: PlatformViewIOS(delegate,
|
||||
IOSContext::Create(rendering_api),
|
||||
IOSContext::Create(rendering_api,
|
||||
delegate.OnPlatformViewGetSettings().enable_impeller
|
||||
? IOSRenderingBackend::kImpeller
|
||||
: IOSRenderingBackend::kSkia),
|
||||
platform_views_controller,
|
||||
task_runners) {}
|
||||
|
||||
|
||||
@@ -17,6 +17,11 @@ enum class IOSRenderingAPI {
|
||||
kMetal,
|
||||
};
|
||||
|
||||
enum class IOSRenderingBackend {
|
||||
kSkia,
|
||||
kImpeller,
|
||||
};
|
||||
|
||||
// Pass force_software to force software rendering. This is only respected on
|
||||
// simulators.
|
||||
IOSRenderingAPI GetRenderingAPIForProcess(bool force_software);
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SURFACE_METAL_H_
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_metal.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_metal_skia.h"
|
||||
#include "flutter/shell/platform/embedder/embedder_external_view_embedder.h"
|
||||
#include "flutter/shell/platform/embedder/embedder_surface.h"
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ std::unique_ptr<Surface> EmbedderSurfaceMetal::CreateGPUSurface() API_AVAILABLE(
|
||||
}
|
||||
|
||||
const bool render_to_surface = !external_view_embedder_;
|
||||
auto surface = std::make_unique<GPUSurfaceMetal>(this, main_context_, render_to_surface);
|
||||
auto surface = std::make_unique<GPUSurfaceMetalSkia>(this, main_context_, render_to_surface);
|
||||
|
||||
if (!surface->IsValid()) {
|
||||
return nullptr;
|
||||
|
||||
@@ -94,6 +94,10 @@ class MockPlatformViewDelegate : public flutter::PlatformView::Delegate {
|
||||
metrics_ = metrics;
|
||||
}
|
||||
// |flutter::PlatformView::Delegate|
|
||||
const flutter::Settings& OnPlatformViewGetSettings() const {
|
||||
return settings_;
|
||||
}
|
||||
// |flutter::PlatformView::Delegate|
|
||||
void OnPlatformViewDispatchPlatformMessage(
|
||||
std::unique_ptr<flutter::PlatformMessage> message) {
|
||||
message_ = std::move(message);
|
||||
@@ -164,6 +168,7 @@ class MockPlatformViewDelegate : public flutter::PlatformView::Delegate {
|
||||
std::vector<std::unique_ptr<flutter::PointerDataPacket>> pointer_packets_;
|
||||
int32_t semantics_features_ = 0;
|
||||
bool semantics_enabled_ = false;
|
||||
flutter::Settings settings_;
|
||||
};
|
||||
|
||||
class MockResponse : public flutter::PlatformMessageResponse {
|
||||
|
||||
@@ -93,6 +93,10 @@ class MockPlatformViewDelegate : public flutter::PlatformView::Delegate {
|
||||
metrics_ = metrics;
|
||||
}
|
||||
// |flutter::PlatformView::Delegate|
|
||||
const flutter::Settings& OnPlatformViewGetSettings() const {
|
||||
return settings_;
|
||||
}
|
||||
// |flutter::PlatformView::Delegate|
|
||||
void OnPlatformViewDispatchPlatformMessage(
|
||||
std::unique_ptr<flutter::PlatformMessage> message) {
|
||||
message_ = std::move(message);
|
||||
@@ -167,6 +171,7 @@ class MockPlatformViewDelegate : public flutter::PlatformView::Delegate {
|
||||
std::vector<std::unique_ptr<flutter::PointerDataPacket>> pointer_packets_;
|
||||
int32_t semantics_features_ = 0;
|
||||
bool semantics_enabled_ = false;
|
||||
flutter::Settings settings_;
|
||||
};
|
||||
|
||||
class MockResponse : public flutter::PlatformMessageResponse {
|
||||
|
||||
Reference in New Issue
Block a user