Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SurfaceManager.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SurfaceManager_DEFINED
9#define SurfaceManager_DEFINED
10
12
13#include <map>
14#include <memory>
15#include <string>
16
17struct GrContextOptions;
18
19namespace skgpu::graphite {
20struct ContextOptions;
21}
22
23namespace sk_gpu_test {
24class ContextInfo;
25};
26
27// Gathers the parameters needed by SurfaceManager::FromConfig to construct a surface for a given
28// configuration.
30 int width;
31 int height;
32
33 std::function<void(GrContextOptions*)> modifyGrContextOptions = nullptr;
35};
36
37// Abstract class to create and manage surfaces used by various kinds of tests (GMs, Benchmarks,
38// etc.).
40public:
41 enum class CpuOrGpu { kCPU, kGPU };
42
43 // Constructs a SurfaceManager for the given config name (e.g. "8888", "565", "gles"). It
44 // returns nullptr if the config is unknown, and it aborts execution if the config is known but
45 // we weren't able to construct the surface for any reason.
46 static std::unique_ptr<SurfaceManager> FromConfig(std::string config,
47 SurfaceOptions surfaceOptions);
48
49 // Returns the surface created from the given config. All calls return the same surface.
51
52 // Flushes the surface. This method should be called after the test is done drawing. This
53 // ensures that all commands are flushed to the GPU in the case of Ganesh-backed surfaces.
54 // Failing to do so may lead to blank pixmaps.
55 virtual void flush() {}
56
57 // Returns the subset of Gold key/value pairs that are determined by the surface config. The
58 // returned map includes keys "cpu_or_gpu" and "cpu_or_gpu_value", which are populated based
59 // on the cpuName and gpuName arguments, and whether the surface config is CPU or GPU bound.
60 // The returned map also includes various keys pertaining to color, which are generated from
61 // the SkColorInfo passed to this class' constructor.
62 std::map<std::string, std::string> getGoldKeyValuePairs(std::string cpuName,
63 std::string gpuName) const;
64
65 // Returns the subset of Perf key/value pairs that are determined by the surface config. The
66 // returned map includes keys "cpu_or_gpu" and "cpu_or_gpu_value", which are populated based
67 // on the cpuName and gpuName arguments, and whether the surface config is CPU or GPU bound.
68 std::map<std::string, std::string> getPerfKeyValuePairs(std::string cpuName,
69 std::string gpuName) const;
70
71 // Returns an enum indicating whether the surface is CPU or GPU bound.
73
74 // Returns the Ganesh ContextInfo on SurfaceManager implementations that support it.
76 SK_ABORT("This SurfaceManager implementation does not support the requested operation.");
77 }
78
79 virtual ~SurfaceManager() = default;
80
81protected:
82 // Takes the config name passed to FromConfig(), and the SkColorInfo used by FromConfig() to
83 // create the surface.
84 SurfaceManager(std::string config, SkColorInfo colorInfo, CpuOrGpu cpuOrGpu)
85 : fConfig(config), fColorInfo(colorInfo), fCpuOrGpu(cpuOrGpu) {}
86
87private:
88 std::string fConfig;
89 SkColorInfo fColorInfo;
90 CpuOrGpu fCpuOrGpu;
91
92 std::map<std::string, std::string> getCpuOrGpuKeyValuePairs(std::string cpuName,
93 std::string gpuName) const;
94};
95
96#endif // SurfaceManager_DEFINED
#define SK_ABORT(message,...)
Definition SkAssert.h:70
SurfaceManager(std::string config, SkColorInfo colorInfo, CpuOrGpu cpuOrGpu)
CpuOrGpu isCpuOrGpuBound() const
static std::unique_ptr< SurfaceManager > FromConfig(std::string config, SurfaceOptions surfaceOptions)
std::map< std::string, std::string > getGoldKeyValuePairs(std::string cpuName, std::string gpuName) const
virtual void flush()
std::map< std::string, std::string > getPerfKeyValuePairs(std::string cpuName, std::string gpuName) const
virtual sk_gpu_test::ContextInfo * getGaneshContextInfo()
virtual sk_sp< SkSurface > getSurface()=0
virtual ~SurfaceManager()=default
std::function< void(skgpu::graphite::ContextOptions *)> modifyGraphiteContextOptions
std::function< void(GrContextOptions *)> modifyGrContextOptions