Skip to content

Commit 055f3d8

Browse files
authored
display_list: Extract backend-specific surface providers (flutter/engine#56711)
Extracts backend-specific code in DlSurfaceProvider to separate translation units. In particular, this allows for less conditional header includes, and more specifically, allows code relating to the Metal backend to include headers that include ARC-managed Objective-C types. Today we cast these all to void* (and manage refcounting manually) since these headers are included in dl_surface_provider.cc, which is a pure C++ translation unit. No test changes since this patch includes no semantic changes. Issue: flutter#137801 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent d343448 commit 055f3d8

6 files changed

+79
-32
lines changed

engine/src/flutter/display_list/testing/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ source_set("display_list_surface_provider") {
8686

8787
if (surface_provider_include_software) {
8888
sources += [
89+
"dl_test_surface_provider_software.cc",
8990
"dl_test_surface_software.cc",
9091
"dl_test_surface_software.h",
9192
]
@@ -95,6 +96,7 @@ source_set("display_list_surface_provider") {
9596
sources += [
9697
"dl_test_surface_gl.cc",
9798
"dl_test_surface_gl.h",
99+
"dl_test_surface_provider_gl.cc",
98100
]
99101
deps += [ "//flutter/testing:opengl" ]
100102
}
@@ -103,6 +105,7 @@ source_set("display_list_surface_provider") {
103105
sources += [
104106
"dl_test_surface_metal.h",
105107
"dl_test_surface_metal.mm",
108+
"dl_test_surface_provider_metal.mm",
106109
]
107110
deps += [
108111
"//flutter/impeller/display_list",

engine/src/flutter/display_list/testing/dl_test_surface_provider.cc

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,29 @@
1010
#include "third_party/skia/include/core/SkSurface.h"
1111
#include "third_party/skia/include/encode/SkPngEncoder.h"
1212

13-
#ifdef ENABLE_SOFTWARE_BENCHMARKS
14-
#include "flutter/display_list/testing/dl_test_surface_software.h"
15-
#endif
16-
#ifdef ENABLE_OPENGL_BENCHMARKS
17-
#include "flutter/display_list/testing/dl_test_surface_gl.h"
18-
#endif
19-
#ifdef ENABLE_METAL_BENCHMARKS
20-
#include "flutter/display_list/testing/dl_test_surface_metal.h"
21-
#endif
22-
23-
namespace flutter {
24-
namespace testing {
13+
namespace flutter::testing {
2514

2615
std::string DlSurfaceProvider::BackendName(BackendType type) {
2716
switch (type) {
28-
case kMetalBackend:
29-
return "Metal";
30-
case kOpenGlBackend:
31-
return "OpenGL";
3217
case kSoftwareBackend:
3318
return "Software";
19+
case kOpenGlBackend:
20+
return "OpenGL";
21+
case kMetalBackend:
22+
return "Metal";
3423
}
3524
}
3625

3726
std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::Create(
3827
BackendType backend_type) {
3928
switch (backend_type) {
40-
#ifdef ENABLE_SOFTWARE_BENCHMARKS
4129
case kSoftwareBackend:
42-
return std::make_unique<DlSoftwareSurfaceProvider>();
43-
#endif
44-
#ifdef ENABLE_OPENGL_BENCHMARKS
45-
case kOpenGLBackend:
46-
return std::make_unique<DlOpenGLSurfaceProvider>();
47-
#endif
48-
#ifdef ENABLE_METAL_BENCHMARKS
30+
return CreateSoftware();
31+
case kOpenGlBackend:
32+
return CreateOpenGL();
4933
case kMetalBackend:
50-
return std::make_unique<DlMetalSurfaceProvider>();
51-
#endif
52-
default:
53-
return nullptr;
34+
return CreateMetal();
5435
}
55-
56-
return nullptr;
5736
}
5837

5938
bool DlSurfaceProvider::Snapshot(std::string& filename) const {
@@ -78,5 +57,20 @@ bool DlSurfaceProvider::Snapshot(std::string& filename) const {
7857
#endif
7958
}
8059

81-
} // namespace testing
82-
} // namespace flutter
60+
#ifndef ENABLE_SOFTWARE_BENCHMARKS
61+
std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::CreateSoftware() {
62+
return nullptr;
63+
}
64+
#endif
65+
#ifndef ENABLE_OPENGL_BENCHMARKS
66+
std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::CreateOpenGL() {
67+
return nullptr;
68+
}
69+
#endif
70+
#ifndef ENABLE_METAL_BENCHMARKS
71+
std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::CreateMetal() {
72+
return nullptr;
73+
}
74+
#endif
75+
76+
} // namespace flutter::testing

engine/src/flutter/display_list/testing/dl_test_surface_provider.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ class DlSurfaceProvider {
9797

9898
protected:
9999
DlSurfaceProvider() = default;
100+
101+
private:
102+
static std::unique_ptr<DlSurfaceProvider> CreateSoftware();
103+
static std::unique_ptr<DlSurfaceProvider> CreateMetal();
104+
static std::unique_ptr<DlSurfaceProvider> CreateOpenGL();
100105
};
101106

102107
} // namespace testing
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/display_list/testing/dl_test_surface_provider.h"
6+
7+
#include "flutter/display_list/testing/dl_test_surface_gl.h"
8+
9+
namespace flutter::testing {
10+
11+
std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::CreateOpenGL() {
12+
return std::make_unique<DlOpenGLSurfaceProvider>();
13+
}
14+
15+
} // namespace flutter::testing
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/display_list/testing/dl_test_surface_provider.h"
6+
7+
#include "flutter/display_list/testing/dl_test_surface_metal.h"
8+
9+
namespace flutter::testing {
10+
11+
std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::CreateMetal() {
12+
return std::make_unique<DlMetalSurfaceProvider>();
13+
}
14+
15+
} // namespace flutter::testing
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/display_list/testing/dl_test_surface_provider.h"
6+
7+
#include "flutter/display_list/testing/dl_test_surface_software.h"
8+
9+
namespace flutter::testing {
10+
11+
std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::CreateSoftware() {
12+
return std::make_unique<DlSoftwareSurfaceProvider>();
13+
}
14+
15+
} // namespace flutter::testing

0 commit comments

Comments
 (0)