Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GaneshVulkanSurfaceManager.cpp
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
14
15#include <string>
16
18public:
19 GaneshVulkanSurfaceManager(std::unique_ptr<sk_gpu_test::GrContextFactory> contextFactory,
20 sk_gpu_test::ContextInfo contextInfo,
21 GrDirectContext* context,
23 std::string config,
24 SkColorInfo colorInfo)
25 : SurfaceManager(config, colorInfo, CpuOrGpu::kGPU)
26 , fContextFactory(std::move(contextFactory))
27 , fContextInfo(contextInfo)
28 , fContext(context)
29 , fSurface(surface) {}
30
31 sk_sp<SkSurface> getSurface() override { return fSurface; }
32
33 void flush() override { fContext->flushAndSubmit(fSurface.get(), GrSyncCpu::kYes); }
34
35 sk_gpu_test::ContextInfo* getGaneshContextInfo() override { return &fContextInfo; }
36
37private:
38 // The Vulkan context is destroyed when the context factory is destroyed. We prevent early
39 // destruction of the context by grabbing a reference to the context factory. See the
40 // GrContextFactory class documentation for details.
41 std::unique_ptr<sk_gpu_test::GrContextFactory> fContextFactory;
42 sk_gpu_test::ContextInfo fContextInfo;
43 GrDirectContext* fContext;
44 sk_sp<SkSurface> fSurface;
45};
46
48
49std::unique_ptr<SurfaceManager> makeVulkanSurfaceManager(
50 std::string config,
51 SurfaceOptions surfaceOptions,
52 GrContextOptions grContextOptions,
54 SkColorInfo colorInfo,
55 SurfaceType surfaceType,
56 uint32_t surfaceFlags,
57 int sampleCount) {
58 if (surfaceOptions.modifyGrContextOptions) {
59 surfaceOptions.modifyGrContextOptions(&grContextOptions);
60 }
61
62 // Based on
63 // https://skia.googlesource.com/skia/+/8da85ea79d1ba2b3f32d25178eb21f2ebda83437/dm/DMSrcSink.cpp#1579.
64 auto contextFactory = std::make_unique<sk_gpu_test::GrContextFactory>(grContextOptions);
65 sk_gpu_test::ContextInfo contextInfo =
66 contextFactory.get()->getContextInfo(skgpu::ContextType::kVulkan, contextOverrides);
67 GrDirectContext* context = contextInfo.directContext();
68 SkASSERT_RELEASE(context);
69
70 // Based on
71 // https://skia.googlesource.com/skia/+/8da85ea79d1ba2b3f32d25178eb21f2ebda83437/dm/DMSrcSink.cpp#1524.
72 SkImageInfo imageInfo =
73 SkImageInfo::Make({surfaceOptions.width, surfaceOptions.height}, colorInfo);
74 SkSurfaceProps surfaceProps(surfaceFlags, kRGB_H_SkPixelGeometry);
76 switch (surfaceType) {
77 default:
80 context, skgpu::Budgeted::kNo, imageInfo, sampleCount, &surfaceProps);
81 break;
82
85 imageInfo,
87 sampleCount,
88 skgpu::Mipmapped::kNo,
89 skgpu::Protected::kNo,
90 &surfaceProps);
91 break;
92
95 imageInfo,
97 sampleCount,
98 skgpu::Protected::kNo,
99 &surfaceProps);
100 break;
101 }
103
104 return std::make_unique<GaneshVulkanSurfaceManager>(
105 std::move(contextFactory), contextInfo, context, surface, config, colorInfo);
106}
107
108// Based on the configurations defined here[1], the configuration parsing logic here[2], and the
109// sink selection logic here[3].
110//
111// [1]
112// https://skia.googlesource.com/skia/+/8da85ea79d1ba2b3f32d25178eb21f2ebda83437/tools/flags/CommonFlagsConfig.cpp#40
113// [2]
114// https://skia.googlesource.com/skia/+/8da85ea79d1ba2b3f32d25178eb21f2ebda83437/tools/flags/CommonFlagsConfig.cpp#610
115// [3]
116// https://skia.googlesource.com/skia/+/8da85ea79d1ba2b3f32d25178eb21f2ebda83437/dm/DM.cpp#1017
117std::unique_ptr<SurfaceManager> SurfaceManager::FromConfig(std::string config,
118 SurfaceOptions surfaceOptions) {
119 if (config == "vk") {
121 config,
122 surfaceOptions,
128 /* sampleCount= */ 1);
129 }
130 if (config == "vk_1010102") {
132 config,
133 surfaceOptions,
140 /* sampleCount= */ 1);
141 }
142 if (config == "vk_msaa4") {
144 config,
145 surfaceOptions,
151 /* sampleCount= */ 4);
152 }
153 if (config == "vk_msaa8") {
155 config,
156 surfaceOptions,
162 /* sampleCount= */ 8);
163 }
164 if (config == "vk_dmsaa") {
166 config,
167 surfaceOptions,
173 /* sampleCount= */ 1);
174 }
175 if (config == "vk_betex") {
177 config,
178 surfaceOptions,
184 /* sampleCount= */ 1);
185 }
186 if (config == "vk_bert") {
188 config,
189 surfaceOptions,
195 /* sampleCount= */ 1);
196 }
197
198 return nullptr;
199}
@ kBackendRenderTarget
@ kBackendRenderTarget
std::unique_ptr< SurfaceManager > makeVulkanSurfaceManager(std::string config, SurfaceOptions surfaceOptions, GrContextOptions grContextOptions, sk_gpu_test::GrContextFactory::ContextOverrides contextOverrides, SkColorInfo colorInfo, SurfaceType surfaceType, uint32_t surfaceFlags, int sampleCount)
@ kBottomLeft_GrSurfaceOrigin
Definition GrTypes.h:149
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SkASSERT_RELEASE(cond)
Definition SkAssert.h:100
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
Definition SkColorType.h:27
@ kRGB_H_SkPixelGeometry
sk_sp< SkSurface > getSurface() override
GaneshVulkanSurfaceManager(std::unique_ptr< sk_gpu_test::GrContextFactory > contextFactory, sk_gpu_test::ContextInfo contextInfo, GrDirectContext *context, sk_sp< SkSurface > surface, std::string config, SkColorInfo colorInfo)
sk_gpu_test::ContextInfo * getGaneshContextInfo() override
void flushAndSubmit(GrSyncCpu sync=GrSyncCpu::kNo)
static sk_sp< SkColorSpace > MakeSRGB()
static std::unique_ptr< SurfaceManager > FromConfig(std::string config, SurfaceOptions surfaceOptions)
GrDirectContext * directContext() const
T * get() const
Definition SkRefCnt.h:303
VkSurfaceKHR surface
Definition main.cc:49
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
sk_sp< SkSurface > MakeBackendRenderTargetSurface(GrDirectContext *dContext, const SkImageInfo &ii, GrSurfaceOrigin origin, int sampleCnt, GrProtected isProtected, const SkSurfaceProps *props)
sk_sp< SkSurface > MakeBackendTextureSurface(GrDirectContext *dContext, const SkImageInfo &ii, GrSurfaceOrigin origin, int sampleCnt, skgpu::Mipmapped mipmapped, GrProtected isProtected, const SkSurfaceProps *props)
Definition ref_ptr.h:256
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
std::function< void(GrContextOptions *)> modifyGrContextOptions