[Engine] Add no op surface (flutter/engine#54694)

Still needs to be tested in metalless environment. This should probably print out some kind of error message that tells folks that this is WAI, but I'm not sure if that would be too disruptive for g3.

Fixes https://github.com/flutter/flutter/issues/153883
This commit is contained in:
Jonah Williams
2024-08-23 10:06:16 -07:00
committed by GitHub
parent c8fc2ff531
commit 1ba45ac86e
11 changed files with 330 additions and 1 deletions

View File

@@ -293,6 +293,7 @@
../../../flutter/shell/common/variable_refresh_rate_display_unittests.cc
../../../flutter/shell/common/vsync_waiter_unittests.cc
../../../flutter/shell/gpu/gpu_surface_metal_impeller_unittests.mm
../../../flutter/shell/gpu/gpu_surface_noop_unittests.mm
../../../flutter/shell/platform/android/.gitignore
../../../flutter/shell/platform/android/README.md
../../../flutter/shell/platform/android/android_context_gl_impeller_unittests.cc
@@ -337,6 +338,7 @@
../../../flutter/shell/platform/darwin/common/availability_version_check_unittests.cc
../../../flutter/shell/platform/darwin/common/framework/Source/flutter_codecs_unittest.mm
../../../flutter/shell/platform/darwin/common/framework/Source/flutter_standard_codec_unittest.mm
../../../flutter/shell/platform/darwin/ios/ios_surface_noop_unittests.mm
../../../flutter/shell/platform/darwin/macos/README.md
../../../flutter/shell/platform/darwin/macos/framework/Source/fixtures
../../../flutter/shell/platform/embedder/fixtures

View File

@@ -43983,6 +43983,8 @@ ORIGIN: ../../../flutter/shell/gpu/gpu_surface_metal_impeller.h + ../../../flutt
ORIGIN: ../../../flutter/shell/gpu/gpu_surface_metal_impeller.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/gpu/gpu_surface_metal_skia.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/gpu/gpu_surface_metal_skia.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/gpu/gpu_surface_noop.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/gpu/gpu_surface_noop.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/gpu/gpu_surface_software.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/gpu/gpu_surface_software.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/gpu/gpu_surface_software_delegate.cc + ../../../flutter/LICENSE
@@ -44448,6 +44450,8 @@ ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.h
ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_surface_metal_skia.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_surface_noop.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_surface_noop.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_surface_software.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_surface_software.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/ios/platform_message_handler_ios.h + ../../../flutter/LICENSE
@@ -46874,6 +46878,8 @@ 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_noop.h
FILE: ../../../flutter/shell/gpu/gpu_surface_noop.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
@@ -47353,6 +47359,8 @@ 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_noop.h
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_noop.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/platform_message_handler_ios.h

View File

@@ -75,6 +75,8 @@ source_set("gpu_surface_metal") {
"gpu_surface_metal_delegate.h",
"gpu_surface_metal_skia.h",
"gpu_surface_metal_skia.mm",
"gpu_surface_noop.h",
"gpu_surface_noop.mm",
]
public_deps = gpu_common_deps
@@ -93,7 +95,10 @@ if (is_mac) {
impeller_component("gpu_surface_metal_unittests") {
testonly = true
target_type = "executable"
sources = [ "gpu_surface_metal_impeller_unittests.mm" ]
sources = [
"gpu_surface_metal_impeller_unittests.mm",
"gpu_surface_noop_unittests.mm",
]
frameworks = [
"AppKit.framework",

View File

@@ -0,0 +1,68 @@
// 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_NOOP_H_
#define FLUTTER_SHELL_GPU_GPU_SURFACE_NOOP_H_
#include <Metal/Metal.h>
#include "flutter/flow/surface.h"
namespace flutter {
/// @brief A rendering surface that accepts rendering intent but does not render
/// anything.
///
/// This is useful for running on platforms that need an engine instance and
/// don't have the required drivers.
class GPUSurfaceNoop : public Surface {
public:
explicit GPUSurfaceNoop();
// |Surface|
~GPUSurfaceNoop();
// |Surface|
bool IsValid() override;
// |Surface|
Surface::SurfaceData GetSurfaceData() const override;
private:
// |Surface|
std::unique_ptr<SurfaceFrame> AcquireFrame(
const SkISize& frame_size) override;
std::unique_ptr<SurfaceFrame> AcquireFrameFromCAMetalLayer(
const SkISize& frame_size);
std::unique_ptr<SurfaceFrame> AcquireFrameFromMTLTexture(
const SkISize& frame_size);
// |Surface|
SkMatrix GetRootTransformation() const override;
// |Surface|
GrDirectContext* GetContext() override;
// |Surface|
std::unique_ptr<GLContextResult> MakeRenderContextCurrent() override;
// |Surface|
bool AllowsDrawingWhenGpuDisabled() const override;
// |Surface|
bool EnableRasterCache() const override;
// |Surface|
std::shared_ptr<impeller::AiksContext> GetAiksContext() const override;
GPUSurfaceNoop(const GPUSurfaceNoop&) = delete;
GPUSurfaceNoop& operator=(const GPUSurfaceNoop&) = delete;
};
} // namespace flutter
#endif // FLUTTER_SHELL_GPU_GPU_SURFACE_NOOP_H_

View File

@@ -0,0 +1,97 @@
// 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_noop.h"
#import <Metal/Metal.h>
#import <QuartzCore/QuartzCore.h>
#include "flow/surface.h"
#include "flow/surface_frame.h"
#include "flutter/common/settings.h"
#include "flutter/fml/mapping.h"
#include "flutter/fml/trace_event.h"
static_assert(!__has_feature(objc_arc), "ARC must be disabled.");
namespace flutter {
GPUSurfaceNoop::GPUSurfaceNoop() = default;
GPUSurfaceNoop::~GPUSurfaceNoop() = default;
// |Surface|
bool GPUSurfaceNoop::IsValid() {
return true;
}
Surface::SurfaceData GPUSurfaceNoop::GetSurfaceData() const {
return Surface::SurfaceData{};
}
// |Surface|
std::unique_ptr<SurfaceFrame> GPUSurfaceNoop::AcquireFrame(const SkISize& frame_size) {
auto callback = [](const SurfaceFrame&, DlCanvas*) { return true; };
auto submit_callback = [](const SurfaceFrame&) { return true; };
SurfaceFrame::FramebufferInfo framebuffer_info;
return std::make_unique<SurfaceFrame>(
/*surface=*/nullptr,
/*framebuffer_info=*/framebuffer_info,
/*encode_callback=*/callback,
/*submit_callback=*/submit_callback,
/*frame_size=*/frame_size,
/*context_result=*/nullptr,
/*display_list_fallback=*/true);
}
std::unique_ptr<SurfaceFrame> GPUSurfaceNoop::AcquireFrameFromMTLTexture(
const SkISize& frame_size) {
auto callback = [](const SurfaceFrame&, DlCanvas*) { return true; };
auto submit_callback = [](const SurfaceFrame&) { return true; };
SurfaceFrame::FramebufferInfo framebuffer_info;
return std::make_unique<SurfaceFrame>(
/*surface=*/nullptr,
/*framebuffer_info=*/framebuffer_info,
/*encode_callback=*/callback,
/*submit_callback=*/submit_callback,
/*frame_size=*/frame_size,
/*context_result=*/nullptr,
/*display_list_fallback=*/true);
}
// |Surface|
SkMatrix GPUSurfaceNoop::GetRootTransformation() const {
// This backend does not currently support root surface transformations. Just
// return identity.
return {};
}
// |Surface|
GrDirectContext* GPUSurfaceNoop::GetContext() {
return nullptr;
}
// |Surface|
std::unique_ptr<GLContextResult> GPUSurfaceNoop::MakeRenderContextCurrent() {
// This backend has no such concept.
return std::make_unique<GLContextDefaultResult>(true);
}
bool GPUSurfaceNoop::AllowsDrawingWhenGpuDisabled() const {
return true;
}
// |Surface|
bool GPUSurfaceNoop::EnableRasterCache() const {
return false;
}
// |Surface|
std::shared_ptr<impeller::AiksContext> GPUSurfaceNoop::GetAiksContext() const {
return nullptr;
}
} // namespace flutter

View File

@@ -0,0 +1,25 @@
// 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 <Foundation/Foundation.h>
#include <QuartzCore/QuartzCore.h>
#include "flutter/shell/gpu/gpu_surface_noop.h"
#include "gtest/gtest.h"
#include "impeller/entity/mtl/entity_shaders.h"
#include "impeller/entity/mtl/framebuffer_blend_shaders.h"
#include "impeller/entity/mtl/modern_shaders.h"
#include "impeller/renderer/backend/metal/context_mtl.h"
namespace flutter {
namespace testing {
TEST(GPUSurfaceNoop, InvalidImpellerContextCreatesCausesSurfaceToBeInvalid) {
auto surface = std::make_shared<GPUSurfaceNoop>();
EXPECT_TRUE(surface->IsValid());
}
} // namespace testing
} // namespace flutter

View File

@@ -137,6 +137,8 @@ source_set("flutter_framework_source_arc") {
"ios_surface_metal_impeller.mm",
"ios_surface_metal_skia.h",
"ios_surface_metal_skia.mm",
"ios_surface_noop.h",
"ios_surface_noop.mm",
"ios_surface_software.h",
"ios_surface_software.mm",
"platform_message_handler_ios.h",
@@ -284,6 +286,7 @@ shared_library("ios_test_flutter") {
"framework/Source/accessibility_bridge_test.mm",
"framework/Source/availability_version_check_test.mm",
"framework/Source/connection_collection_test.mm",
"ios_surface_noop_unittests.mm",
"platform_message_handler_ios_test.mm",
]
deps = [

View File

@@ -4,8 +4,11 @@
#import "flutter/shell/platform/darwin/ios/ios_surface.h"
#include <memory>
#import "flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.h"
#import "flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h"
#import "flutter/shell/platform/darwin/ios/ios_surface_noop.h"
#import "flutter/shell/platform/darwin/ios/ios_surface_software.h"
#include "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
@@ -40,6 +43,9 @@ std::unique_ptr<IOSSurface> IOSSurface::Create(std::shared_ptr<IOSContext> conte
}
}
}
if (context->GetBackend() == IOSRenderingBackend::kImpeller) {
return std::make_unique<IOSSurfaceNoop>(std::move(context));
}
return std::make_unique<IOSSurfaceSoftware>(layer, // layer
std::move(context) // context

View File

@@ -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_SURFACE_NOOP_H_
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_NOOP_H_
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
#import "flutter/shell/platform/darwin/ios/ios_context.h"
#import "flutter/shell/platform/darwin/ios/ios_surface.h"
#include "third_party/skia/include/core/SkSurface.h"
@class CALayer;
namespace flutter {
/// @brief A rendering surface that accepts rendering intent but does not render
/// anything.
///
/// This is useful for running on platforms that need an engine instance and
/// don't have the required drivers.
class IOSSurfaceNoop final : public IOSSurface {
public:
explicit IOSSurfaceNoop(std::shared_ptr<IOSContext> context);
~IOSSurfaceNoop() override;
// |IOSSurface|
bool IsValid() const override;
// |IOSSurface|
void UpdateStorageSizeIfNecessary() override;
// |IOSSurface|
std::unique_ptr<Surface> CreateGPUSurface(GrDirectContext* gr_context = nullptr) override;
private:
IOSSurfaceNoop(const IOSSurfaceNoop&) = delete;
IOSSurfaceNoop& operator=(const IOSSurfaceNoop&) = delete;
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_NOOP_H_

View File

@@ -0,0 +1,38 @@
// 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_noop.h"
#include "shell/gpu/gpu_surface_noop.h"
#include <QuartzCore/CALayer.h>
#include <memory>
#include "flutter/fml/logging.h"
#include "flutter/fml/platform/darwin/cf_utils.h"
#include "flutter/fml/trace_event.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/utils/mac/SkCGUtils.h"
FLUTTER_ASSERT_ARC
namespace flutter {
IOSSurfaceNoop::IOSSurfaceNoop(std::shared_ptr<IOSContext> context)
: IOSSurface(std::move(context)) {}
IOSSurfaceNoop::~IOSSurfaceNoop() = default;
bool IOSSurfaceNoop::IsValid() const {
return true;
}
void IOSSurfaceNoop::UpdateStorageSizeIfNecessary() {}
std::unique_ptr<Surface> IOSSurfaceNoop::CreateGPUSurface(GrDirectContext* gr_context) {
return std::make_unique<GPUSurfaceNoop>();
}
} // namespace flutter

View File

@@ -0,0 +1,31 @@
// 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 <QuartzCore/QuartzCore.h>
#import <XCTest/XCTest.h>
#import "flutter/shell/platform/darwin/ios/ios_surface_noop.h"
#import "flutter/common/task_runners.h"
#import "flutter/fml/message_loop.h"
#import "flutter/fml/thread.h"
#import "flutter/lib/ui/window/platform_message.h"
#import "flutter/lib/ui/window/platform_message_response.h"
#import "flutter/shell/common/thread_host.h"
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
FLUTTER_ASSERT_ARC
@interface IOSSurfaceNoopTest : XCTestCase
@end
@implementation IOSSurfaceNoopTest
- (void)testCreateSurface {
flutter::IOSSurfaceNoop noop(nullptr);
XCTAssertTrue(noop.IsValid());
XCTAssertTrue(!!noop.CreateGPUSurface());
}
@end