Flutter Engine
The Flutter Engine
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
5#include "flutter/display_list/testing/dl_test_surface_provider.h"
6
12
13#ifdef ENABLE_SOFTWARE_BENCHMARKS
14#include "flutter/display_list/testing/dl_test_surface_software.h"
15#endif
16#ifdef ENABLE_OPENGL_BENCHMARKS
17#include "flutter/display_list/testing/dl_test_surface_gl.h"
18#endif
19#ifdef ENABLE_METAL_BENCHMARKS
20#include "flutter/display_list/testing/dl_test_surface_metal.h"
21#endif
22
23namespace flutter {
24namespace testing {
25
27 switch (type) {
28 case kMetalBackend:
29 return "Metal";
30 case kOpenGlBackend:
31 return "OpenGL";
33 return "Software";
34 }
35}
36
37std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::Create(
38 BackendType backend_type) {
39 switch (backend_type) {
40#ifdef ENABLE_SOFTWARE_BENCHMARKS
42 return std::make_unique<DlSoftwareSurfaceProvider>();
43#endif
44#ifdef ENABLE_OPENGL_BENCHMARKS
45 case kOpenGLBackend:
46 return std::make_unique<DlOpenGLSurfaceProvider>();
47#endif
48#ifdef ENABLE_METAL_BENCHMARKS
49 case kMetalBackend:
50 return std::make_unique<DlMetalSurfaceProvider>();
51#endif
52 default:
53 return nullptr;
54 }
55
56 return nullptr;
57}
58
59bool DlSurfaceProvider::Snapshot(std::string& filename) const {
60#ifdef BENCHMARKS_NO_SNAPSHOT
61 return false;
62#else
63 auto image = GetPrimarySurface()->sk_surface()->makeImageSnapshot();
64 if (!image) {
65 return false;
66 }
67 auto raster = image->makeRasterImage();
68 if (!raster) {
69 return false;
70 }
71 auto data = SkPngEncoder::Encode(nullptr, raster.get(), {});
72 if (!data) {
73 return false;
74 }
75 fml::NonOwnedMapping mapping(static_cast<const uint8_t*>(data->data()),
76 data->size());
77 return WriteAtomically(OpenFixturesDirectory(), filename.c_str(), mapping);
78#endif
79}
80
81} // namespace testing
82} // namespace flutter
GLenum type
sk_sp< SkImage > makeRasterImage(GrDirectContext *, CachingHint cachingHint=kDisallow_CachingHint) const
Definition: SkImage.cpp:267
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
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
sk_sp< const SkImage > image
Definition: SkRecords.h:269
fml::UniqueFD OpenFixturesDirectory()
Opens the fixtures directory for the unit-test harness.
Definition: testing.cc:23
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: switches.h:41
bool WriteAtomically(const fml::UniqueFD &base_directory, const char *file_name, const Mapping &mapping)
Definition: file_posix.cc:191