Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

display_list: Extract backend-specific surface providers #56711

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions display_list/testing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ source_set("display_list_surface_provider") {

if (surface_provider_include_software) {
sources += [
"dl_test_surface_provider_software.cc",
"dl_test_surface_software.cc",
"dl_test_surface_software.h",
]
Expand All @@ -95,6 +96,7 @@ source_set("display_list_surface_provider") {
sources += [
"dl_test_surface_gl.cc",
"dl_test_surface_gl.h",
"dl_test_surface_provider_gl.cc",
]
deps += [ "//flutter/testing:opengl" ]
}
Expand All @@ -103,6 +105,7 @@ source_set("display_list_surface_provider") {
sources += [
"dl_test_surface_metal.h",
"dl_test_surface_metal.mm",
"dl_test_surface_provider_metal.mm",
]
deps += [
"//flutter/impeller/display_list",
Expand Down
58 changes: 26 additions & 32 deletions display_list/testing/dl_test_surface_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,29 @@
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/encode/SkPngEncoder.h"

#ifdef ENABLE_SOFTWARE_BENCHMARKS
#include "flutter/display_list/testing/dl_test_surface_software.h"
#endif
#ifdef ENABLE_OPENGL_BENCHMARKS
#include "flutter/display_list/testing/dl_test_surface_gl.h"
#endif
#ifdef ENABLE_METAL_BENCHMARKS
#include "flutter/display_list/testing/dl_test_surface_metal.h"
#endif

namespace flutter {
namespace testing {
namespace flutter::testing {

std::string DlSurfaceProvider::BackendName(BackendType type) {
switch (type) {
case kMetalBackend:
return "Metal";
case kOpenGlBackend:
return "OpenGL";
case kSoftwareBackend:
return "Software";
case kOpenGlBackend:
return "OpenGL";
case kMetalBackend:
return "Metal";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reordered for consistency with elsewhere in the file, and with the declaration order in the enum.

}
}

std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::Create(
BackendType backend_type) {
switch (backend_type) {
#ifdef ENABLE_SOFTWARE_BENCHMARKS
case kSoftwareBackend:
return std::make_unique<DlSoftwareSurfaceProvider>();
#endif
#ifdef ENABLE_OPENGL_BENCHMARKS
case kOpenGLBackend:
return std::make_unique<DlOpenGLSurfaceProvider>();
#endif
#ifdef ENABLE_METAL_BENCHMARKS
return CreateSoftware();
case kOpenGlBackend:
return CreateOpenGL();
case kMetalBackend:
return std::make_unique<DlMetalSurfaceProvider>();
#endif
default:
return nullptr;
return CreateMetal();
}

return nullptr;
}

bool DlSurfaceProvider::Snapshot(std::string& filename) const {
Expand All @@ -78,5 +57,20 @@ bool DlSurfaceProvider::Snapshot(std::string& filename) const {
#endif
}

} // namespace testing
} // namespace flutter
#ifndef ENABLE_SOFTWARE_BENCHMARKS
std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::CreateSoftware() {
return nullptr;
}
#endif
#ifndef ENABLE_OPENGL_BENCHMARKS
std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::CreateOpenGL() {
return nullptr;
}
#endif
#ifndef ENABLE_METAL_BENCHMARKS
std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::CreateMetal() {
return nullptr;
}
#endif

} // namespace flutter::testing
5 changes: 5 additions & 0 deletions display_list/testing/dl_test_surface_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ class DlSurfaceProvider {

protected:
DlSurfaceProvider() = default;

private:
static std::unique_ptr<DlSurfaceProvider> CreateSoftware();
static std::unique_ptr<DlSurfaceProvider> CreateMetal();
static std::unique_ptr<DlSurfaceProvider> CreateOpenGL();
};

} // namespace testing
Expand Down
15 changes: 15 additions & 0 deletions display_list/testing/dl_test_surface_provider_gl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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/display_list/testing/dl_test_surface_provider.h"

#include "flutter/display_list/testing/dl_test_surface_gl.h"

namespace flutter::testing {

std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::CreateOpenGL() {
return std::make_unique<DlOpenGLSurfaceProvider>();
}

} // namespace flutter::testing
15 changes: 15 additions & 0 deletions display_list/testing/dl_test_surface_provider_metal.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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/display_list/testing/dl_test_surface_provider.h"

#include "flutter/display_list/testing/dl_test_surface_metal.h"

namespace flutter::testing {

std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::CreateMetal() {
return std::make_unique<DlMetalSurfaceProvider>();
}

} // namespace flutter::testing
15 changes: 15 additions & 0 deletions display_list/testing/dl_test_surface_provider_software.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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/display_list/testing/dl_test_surface_provider.h"

#include "flutter/display_list/testing/dl_test_surface_software.h"

namespace flutter::testing {

std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::CreateSoftware() {
return std::make_unique<DlSoftwareSurfaceProvider>();
}

} // namespace flutter::testing