Flutter Engine
The Flutter Engine
RasterSurfaceManager.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:
20 : SurfaceManager(config, colorInfo, CpuOrGpu::kCPU), fSurface(surface) {}
21
22 sk_sp<SkSurface> getSurface() override { return fSurface; }
23
24private:
25 sk_sp<SkSurface> fSurface;
26};
27
28std::unique_ptr<SurfaceManager> SurfaceManager::FromConfig(std::string config,
29 SurfaceOptions surfaceOptions) {
30 // This config is based on nanobench's "nonrendering" config:
31 // https://skia.googlesource.com/skia/+/a063eaeaf1e09e4d6f42e0f44a5723622a46d21c/bench/nanobench.cpp#663.
32 // It is placed here because RasterSurfaceManager is the SurfaceManager implementation used
33 // when no GPU backend is specified via Bazel's --config flag, which should be the case for all
34 // nonrendering benchmarks.
35 if (config == "nonrendering") {
36 // The surface and color info are never used by nonrendering benchmarks, so their values do
37 // not matter.
38 return std::make_unique<RasterSurfaceManager>(nullptr, config, SkColorInfo());
39 }
40
41 // These configs are based on the RasterSink configs here:
42 // https://skia.googlesource.com/skia/+/faaa8393a68b518ec1f204a60c7c3393e1da2fa2/dm/DM.cpp#1046.
43 if (config == "8888") {
44 SkColorInfo colorInfo(kN32_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
46 SkImageInfo::Make({surfaceOptions.width, surfaceOptions.height}, colorInfo));
48 return std::make_unique<RasterSurfaceManager>(surface, config, colorInfo);
49 }
50 if (config == "565") {
53 SkImageInfo::Make({surfaceOptions.width, surfaceOptions.height}, colorInfo));
55 return std::make_unique<RasterSurfaceManager>(surface, config, colorInfo);
56 }
57 return nullptr;
58}
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:100
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition: SkColorType.h:22
RasterSurfaceManager(sk_sp< SkSurface > surface, std::string config, SkColorInfo colorInfo)
sk_sp< SkSurface > getSurface() override
static sk_sp< SkColorSpace > MakeSRGB()
static std::unique_ptr< SurfaceManager > FromConfig(std::string config, SurfaceOptions surfaceOptions)
VkSurfaceKHR surface
Definition: main.cc:49
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)