Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GaneshGLSurfaceManager.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
12#include "include/gpu/GrTypes.h"
18
19#include <string>
20
22public:
23 GaneshGLSurfaceManager(std::unique_ptr<sk_gpu_test::GrContextFactory> contextFactory,
24 sk_gpu_test::ContextInfo contextInfo,
25 GrDirectContext* context,
27 std::string config,
28 SkColorInfo colorInfo)
29 : SurfaceManager(config, colorInfo, CpuOrGpu::kGPU)
30 , fContextFactory(std::move(contextFactory))
31 , fContextInfo(contextInfo)
32 , fContext(context)
33 , fSurface(surface) {}
34
35 sk_sp<SkSurface> getSurface() override { return fSurface; }
36
37 void flush() override { fContext->flushAndSubmit(fSurface.get(), GrSyncCpu::kYes); }
38
39 sk_gpu_test::ContextInfo* getGaneshContextInfo() override { return &fContextInfo; }
40
41private:
42 // The GL context is destroyed when the context factory is destroyed. We prevent early
43 // destruction of the context by grabbing a reference to the context factory. See the
44 // GrContextFactory class documentation for details.
45 std::unique_ptr<sk_gpu_test::GrContextFactory> fContextFactory;
46 sk_gpu_test::ContextInfo fContextInfo;
47 GrDirectContext* fContext;
48 sk_sp<SkSurface> fSurface;
49};
50
52
53std::unique_ptr<SurfaceManager> makeGLESSurfaceManager(
54 std::string config,
55 SurfaceOptions surfaceOptions,
56 GrContextOptions grContextOptions,
58 SkColorInfo colorInfo,
59 SurfaceType surfaceType,
60 uint32_t surfaceFlags,
61 int sampleCount) {
62 if (surfaceOptions.modifyGrContextOptions) {
63 surfaceOptions.modifyGrContextOptions(&grContextOptions);
64 }
65
66 // Based on
67 // https://skia.googlesource.com/skia/+/8da85ea79d1ba2b3f32d25178eb21f2ebda83437/dm/DMSrcSink.cpp#1579.
68 auto contextFactory = std::make_unique<sk_gpu_test::GrContextFactory>(grContextOptions);
69 sk_gpu_test::ContextInfo contextInfo =
70 contextFactory.get()->getContextInfo(skgpu::ContextType::kGLES, contextOverrides);
71 GrDirectContext* context = contextInfo.directContext();
72 SkASSERT_RELEASE(context);
73
74 // Based on
75 // https://skia.googlesource.com/skia/+/8da85ea79d1ba2b3f32d25178eb21f2ebda83437/dm/DMSrcSink.cpp#1524.
76 SkImageInfo imageInfo = SkImageInfo::Make({surfaceOptions.width, surfaceOptions.height}, colorInfo);
77 SkSurfaceProps surfaceProps(surfaceFlags, kRGB_H_SkPixelGeometry);
79 switch (surfaceType) {
80 default:
83 context, skgpu::Budgeted::kNo, imageInfo, sampleCount, &surfaceProps);
84 break;
85
88 imageInfo,
90 sampleCount,
91 skgpu::Mipmapped::kNo,
92 skgpu::Protected::kNo,
93 &surfaceProps);
94 break;
95
98 imageInfo,
100 sampleCount,
101 skgpu::Protected::kNo,
102 &surfaceProps);
103 break;
104 }
106
107 return std::make_unique<GaneshGLSurfaceManager>(
108 std::move(contextFactory), contextInfo, context, surface, config, colorInfo);
109}
110
111// Based on the configurations defined here[1], the configuration parsing logic here[2], and the
112// sink selection logic here[3].
113//
114// [1]
115// https://skia.googlesource.com/skia/+/8da85ea79d1ba2b3f32d25178eb21f2ebda83437/tools/flags/CommonFlagsConfig.cpp#40
116// [2]
117// https://skia.googlesource.com/skia/+/8da85ea79d1ba2b3f32d25178eb21f2ebda83437/tools/flags/CommonFlagsConfig.cpp#610
118// [3]
119// https://skia.googlesource.com/skia/+/8da85ea79d1ba2b3f32d25178eb21f2ebda83437/dm/DM.cpp#1017
120std::unique_ptr<SurfaceManager> SurfaceManager::FromConfig(std::string config,
121 SurfaceOptions surfaceOptions) {
122 if (config == "gles") {
124 config,
125 surfaceOptions,
131 /* sampleCount= */ 1);
132 }
133 if (config == "gles_msaa4") {
135 config,
136 surfaceOptions,
142 /* sampleCount= */ 4);
143 }
144 if (config == "gles_msaa8") {
146 config,
147 surfaceOptions,
153 /* sampleCount= */ 8);
154 }
155 if (config == "gles_msaa8_noReduceOpsTaskSplitting") {
156 GrContextOptions grContextOptions;
159 config,
160 surfaceOptions,
161 grContextOptions,
166 /* sampleCount= */ 8);
167 }
168 return nullptr;
169}
std::unique_ptr< SurfaceManager > makeGLESSurfaceManager(std::string config, SurfaceOptions surfaceOptions, GrContextOptions grContextOptions, sk_gpu_test::GrContextFactory::ContextOverrides contextOverrides, SkColorInfo colorInfo, SurfaceType surfaceType, uint32_t surfaceFlags, int sampleCount)
@ kBackendRenderTarget
@ 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
@ kRGB_H_SkPixelGeometry
GaneshGLSurfaceManager(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_sp< SkSurface > getSurface() override
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