forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 2
/
display_list_benchmarks_canvas_provider.h
52 lines (44 loc) · 1.56 KB
/
display_list_benchmarks_canvas_provider.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_FLOW_DISPLAY_LIST_BENCHMARKS_CANVAS_PROVIDER_H_
#define FLUTTER_FLOW_DISPLAY_LIST_BENCHMARKS_CANVAS_PROVIDER_H_
#include "flutter/fml/mapping.h"
#include "flutter/testing/testing.h"
#include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkSurface.h"
namespace flutter {
namespace testing {
class CanvasProvider {
public:
virtual ~CanvasProvider() = default;
virtual const std::string BackendName() = 0;
virtual void InitializeSurface(const size_t width, const size_t height) = 0;
virtual sk_sp<SkSurface> GetSurface() = 0;
virtual sk_sp<SkSurface> MakeOffscreenSurface(const size_t width,
const size_t height) = 0;
virtual bool Snapshot(std::string filename) {
#ifdef BENCHMARKS_NO_SNAPSHOT
return false;
#else
auto image = GetSurface()->makeImageSnapshot();
if (!image) {
return false;
}
auto raster = image->makeRasterImage();
if (!raster) {
return false;
}
auto data = raster->encodeToData();
if (!data) {
return false;
}
fml::NonOwnedMapping mapping(static_cast<const uint8_t*>(data->data()),
data->size());
return WriteAtomically(OpenFixturesDirectory(), filename.c_str(), mapping);
#endif
}
};
} // namespace testing
} // namespace flutter
#endif // FLUTTER_FLOW_DISPLAY_LIST_BENCHMARKS_CANVAS_PROVIDER_H_