Flutter Engine
 
Loading...
Searching...
No Matches
dl_test_surface_provider.cc
Go to the documentation of this file.
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
6
7#include "third_party/skia/include/encode/SkPngEncoder.h"
8#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
9
10namespace flutter::testing {
11
13 switch (type) {
15 return "Software";
16 case kOpenGlBackend:
17 return "OpenGL";
18 case kMetalBackend:
19 return "Metal";
20 }
21}
22
23std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::Create(
24 BackendType backend_type) {
25 switch (backend_type) {
27 return CreateSoftware();
28 case kOpenGlBackend:
29 return CreateOpenGL();
30 case kMetalBackend:
31 return CreateMetal();
32 }
33}
34
35bool DlSurfaceProvider::Snapshot(std::string& filename) const {
36#ifdef BENCHMARKS_NO_SNAPSHOT
37 return false;
38#else
39 auto image = GetPrimarySurface()->sk_surface()->makeImageSnapshot();
40 if (!image) {
41 return false;
42 }
43 auto raster = image->makeRasterImage(nullptr);
44 if (!raster) {
45 return false;
46 }
47 auto data = SkPngEncoder::Encode(nullptr, raster.get(), {});
48 if (!data) {
49 return false;
50 }
51 fml::NonOwnedMapping mapping(static_cast<const uint8_t*>(data->data()),
52 data->size());
53 return WriteAtomically(OpenFixturesDirectory(), filename.c_str(), mapping);
54#endif
55}
56
57#ifndef ENABLE_SOFTWARE_BENCHMARKS
58std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::CreateSoftware() {
59 return nullptr;
60}
61#endif
62#ifndef ENABLE_OPENGL_BENCHMARKS
63std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::CreateOpenGL() {
64 return nullptr;
65}
66#endif
67#ifndef ENABLE_METAL_BENCHMARKS
68std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::CreateMetal() {
69 return nullptr;
70}
71#endif
72
74 auto surface = sk_surface();
75 if (!surface) {
76 return;
77 }
78 if (GrDirectContext* dContext =
79 GrAsDirectContext(surface->recordingContext())) {
80 dContext->flushAndSubmit(surface.get(), GrSyncCpu::kYes);
81 }
82}
83
84} // namespace flutter::testing
GLenum type
virtual sk_sp< SkSurface > sk_surface() const =0
virtual std::shared_ptr< DlSurfaceInstance > GetPrimarySurface() const =0
virtual bool Snapshot(std::string &filename) const
static std::string BackendName(BackendType type)
static std::unique_ptr< DlSurfaceProvider > Create(BackendType backend_type)
virtual BackendType backend_type() const =0
FlutterVulkanImage * image
VkSurfaceKHR surface
Definition main.cc:65
fml::UniqueFD OpenFixturesDirectory()
Opens the fixtures directory for the unit-test harness.
Definition testing.cc:22
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switch_defs.h:36