Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
dl_test_surface_provider.h
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#ifndef FLUTTER_DISPLAY_LIST_TESTING_DL_TEST_SURFACE_PROVIDER_H_
6#define FLUTTER_DISPLAY_LIST_TESTING_DL_TEST_SURFACE_PROVIDER_H_
7
8#include <utility>
9
13#include "flutter/fml/mapping.h"
15
16#include "third_party/skia/include/core/SkSurface.h"
17
18namespace flutter {
19namespace testing {
20
21class DlPixelData : public SkRefCnt {
22 public:
23 virtual ~DlPixelData() = default;
24
25 virtual const uint32_t* addr32(uint32_t x, uint32_t y) const = 0;
26 virtual size_t width() const = 0;
27 virtual size_t height() const = 0;
28 virtual bool write(const std::string& path) const = 0;
29};
30
32 public:
33 virtual ~DlSurfaceInstance() = default;
34
35 /// Clear the entire surface to the indicated color.
36 virtual void Clear(const DlColor& color) = 0;
37
38 /// Return a DlCanvas instance that renders to this surface. Note that
39 /// actual execution of the rendering calls are not guaranteed until the
40 /// FlushSubmitCpuSync method is called. The DlCanvas will also be reset
41 /// by the operations of the sync method so transform and clip state will
42 /// not be carried over to subsequent calls.
43 ///
44 /// Rendering to this canvas does not necessarily render the commands
45 /// immediately in all backends, some backends accumulate the commands
46 /// into a DisplayList and only flush that DisplayList when the
47 /// FlushSubmitCpuSync is called. Tests should strongly prefer using
48 /// RenderDisplayList instead of multiple calls on this canvas object.
49 virtual DlCanvas* GetCanvas() = 0;
50
51 /// Render the indicated DisplayList to the surface. Note that the
52 /// commands may be enqueued by this call and will be rendered at some
53 /// time in the future, but the caller must call FlushSubmitCpuSync to
54 /// be sure they are done being rendered.
55 ///
56 /// In some cases this may be faster than using:
57 /// GetCanvas().DrawDisplayList(display_list);
58 virtual void RenderDisplayList(const sk_sp<DisplayList>& display_list) = 0;
59
60 /// Ensure that all outstanding calls executed on the DlCanvas instance
61 /// are rendered to the surface.
62 virtual void FlushSubmitCpuSync() = 0;
63
64 /// Read back the current contents of the surface and return it as a
65 /// DlPixelData structure.
66 virtual std::unique_ptr<DlPixelData> SnapshotToPixelData() const = 0;
67
68 /// Return the current contents of the surface as a DlImage compatible
69 /// with the DlCanvas that it provides.
70 virtual sk_sp<DlImage> SnapshotToImage() const = 0;
71
72 /// Store a snapshot of this Surface to the file indicated by the filename.
73 virtual bool SnapshotToFile(std::string& filename) const = 0;
74
75 /// The size of the underlying surface.
76 DlISize GetSize() const { return DlISize(width(), height()); }
77
78 /// The width of the underlying surface.
79 virtual int width() const = 0;
80
81 /// The height of the underlying surface.
82 virtual int height() const = 0;
83
84 /// Return a pointer to an underlying SkSurface if the image instance
85 /// has one.
86 /// THIS METHOD IS DEPRECATED AND ONLY USED IN DL_RENDERING_UNITTESTS.
87 virtual sk_sp<SkSurface> sk_surface() { return nullptr; }
88};
89
91 public:
96
104
105 static SkImageInfo MakeInfo(PixelFormat format, int w, int h) {
106 switch (format) {
107 case kN32Premul:
108 return SkImageInfo::MakeN32Premul(w, h);
109 case k565:
110 return SkImageInfo::Make(SkISize::Make(w, h), kRGB_565_SkColorType,
111 kOpaque_SkAlphaType);
112 }
113 FML_DCHECK(false);
114 }
115
116 static std::optional<BackendType> NameToBackend(const std::string& name);
117 static std::string BackendName(BackendType type);
118 static std::unique_ptr<DlSurfaceProvider> Create(BackendType backend_type);
119
120 virtual ~DlSurfaceProvider() = default;
121
122 virtual const std::string GetBackendName() const = 0;
123 virtual BackendType GetBackendType() const = 0;
124 virtual bool SupportsPixelFormat(PixelFormat format) const = 0;
125 virtual bool TargetsImpeller() const = 0;
126 virtual bool InitializeSurface(size_t width,
127 size_t height,
128 PixelFormat format = kN32Premul) = 0;
129 virtual std::shared_ptr<DlSurfaceInstance> GetPrimarySurface() const = 0;
130 virtual std::unique_ptr<DlSurfaceInstance> MakeOffscreenSurface(
131 size_t width,
132 size_t height,
133 PixelFormat format = kN32Premul) const = 0;
134
135 protected:
136 DlSurfaceProvider() = default;
137
138 private:
139 static std::unique_ptr<DlSurfaceProvider> CreateSkiaSoftware();
140 static std::unique_ptr<DlSurfaceProvider> CreateSkiaOpenGL();
141 static std::unique_ptr<DlSurfaceProvider> CreateSkiaMetal();
142 static std::unique_ptr<DlSurfaceProvider> CreateImpellerMetal();
143 static std::unique_ptr<DlSurfaceProvider> CreateImpellerMetalSDF();
144};
145
146} // namespace testing
147} // namespace flutter
148
149#endif // FLUTTER_DISPLAY_LIST_TESTING_DL_TEST_SURFACE_PROVIDER_H_
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:32
virtual size_t height() const =0
virtual ~DlPixelData()=default
virtual const uint32_t * addr32(uint32_t x, uint32_t y) const =0
virtual bool write(const std::string &path) const =0
virtual size_t width() const =0
virtual int height() const =0
The height of the underlying surface.
virtual DlCanvas * GetCanvas()=0
virtual sk_sp< DlImage > SnapshotToImage() const =0
virtual int width() const =0
The width of the underlying surface.
DlISize GetSize() const
The size of the underlying surface.
virtual void Clear(const DlColor &color)=0
Clear the entire surface to the indicated color.
virtual std::unique_ptr< DlPixelData > SnapshotToPixelData() const =0
virtual bool SnapshotToFile(std::string &filename) const =0
Store a snapshot of this Surface to the file indicated by the filename.
virtual void RenderDisplayList(const sk_sp< DisplayList > &display_list)=0
virtual bool TargetsImpeller() const =0
virtual std::shared_ptr< DlSurfaceInstance > GetPrimarySurface() const =0
static std::optional< BackendType > NameToBackend(const std::string &name)
virtual bool InitializeSurface(size_t width, size_t height, PixelFormat format=kN32Premul)=0
virtual std::unique_ptr< DlSurfaceInstance > MakeOffscreenSurface(size_t width, size_t height, PixelFormat format=kN32Premul) const =0
static std::string BackendName(BackendType type)
static SkImageInfo MakeInfo(PixelFormat format, int w, int h)
static std::unique_ptr< DlSurfaceProvider > Create(BackendType backend_type)
virtual bool SupportsPixelFormat(PixelFormat format) const =0
virtual const std::string GetBackendName() const =0
virtual BackendType GetBackendType() const =0
int32_t x
uint32_t uint32_t * format
#define FML_DCHECK(condition)
Definition logging.h:122
double y
impeller::ISize32 DlISize
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switch_defs.h:52
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder h
Definition switch_defs.h:54
impeller::ShaderType type
int32_t height
int32_t width