Flutter Engine
 
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(int x, int y) const = 0;
26 virtual size_t width() const = 0;
27 virtual size_t height() const = 0;
28 virtual void write(const std::string& path) const = 0;
29};
30
32 public:
33 virtual ~DlSurfaceInstance() = default;
34
35 virtual sk_sp<SkSurface> sk_surface() const = 0;
36 virtual DlCanvas* GetCanvas() = 0;
37 void FlushSubmitCpuSync();
38
39 int width() const { return sk_surface()->width(); }
40 int height() const { return sk_surface()->height(); }
41};
42
44 public:
45 explicit DlSurfaceInstanceBase(sk_sp<SkSurface> surface)
46 : surface_(std::move(surface)), adapter_(surface_->getCanvas()) {}
48
49 sk_sp<SkSurface> sk_surface() const override { return surface_; }
50 DlCanvas* GetCanvas() override { return &adapter_; }
51
52 private:
53 sk_sp<SkSurface> surface_;
54 DlSkCanvasAdapter adapter_;
55};
56
58 public:
61
62 static SkImageInfo MakeInfo(PixelFormat format, int w, int h) {
63 switch (format) {
65 return SkImageInfo::MakeN32Premul(w, h);
66 case k565PixelFormat:
67 return SkImageInfo::Make(SkISize::Make(w, h), kRGB_565_SkColorType,
68 kOpaque_SkAlphaType);
69 }
70 FML_DCHECK(false);
71 }
72
73 static std::string BackendName(BackendType type);
74 static std::unique_ptr<DlSurfaceProvider> Create(BackendType backend_type);
75
76 virtual ~DlSurfaceProvider() = default;
77 virtual const std::string backend_name() const = 0;
78 virtual BackendType backend_type() const = 0;
79 virtual bool supports(PixelFormat format) const = 0;
80 virtual bool supports_impeller() const { return false; }
81 virtual bool InitializeSurface(
82 size_t width,
83 size_t height,
85 virtual std::shared_ptr<DlSurfaceInstance> GetPrimarySurface() const = 0;
86 virtual std::shared_ptr<DlSurfaceInstance> MakeOffscreenSurface(
87 size_t width,
88 size_t height,
89 PixelFormat format = kN32PremulPixelFormat) const = 0;
90
91 virtual bool Snapshot(std::string& filename) const;
92 virtual sk_sp<DlPixelData> ImpellerSnapshot(const sk_sp<DisplayList>& list,
93 int width,
94 int height) const {
95 return nullptr;
96 }
97 virtual sk_sp<DlImage> MakeImpellerImage(const sk_sp<DisplayList>& list,
98 int width,
99 int height) const {
100 return nullptr;
101 }
102
103 protected:
104 DlSurfaceProvider() = default;
105
106 private:
107 static std::unique_ptr<DlSurfaceProvider> CreateSoftware();
108 static std::unique_ptr<DlSurfaceProvider> CreateMetal();
109 static std::unique_ptr<DlSurfaceProvider> CreateOpenGL();
110};
111
112} // namespace testing
113} // namespace flutter
114
115#endif // FLUTTER_DISPLAY_LIST_TESTING_DL_TEST_SURFACE_PROVIDER_H_
GLenum type
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:32
Backend implementation of |DlCanvas| for |SkCanvas|.
virtual size_t height() const =0
virtual ~DlPixelData()=default
virtual void write(const std::string &path) const =0
virtual const uint32_t * addr32(int x, int y) const =0
virtual size_t width() const =0
sk_sp< SkSurface > sk_surface() const override
virtual DlCanvas * GetCanvas()=0
virtual sk_sp< SkSurface > sk_surface() const =0
virtual bool supports(PixelFormat format) const =0
virtual std::shared_ptr< DlSurfaceInstance > GetPrimarySurface() const =0
virtual sk_sp< DlImage > MakeImpellerImage(const sk_sp< DisplayList > &list, int width, int height) const
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 sk_sp< DlPixelData > ImpellerSnapshot(const sk_sp< DisplayList > &list, int width, int height) const
virtual std::shared_ptr< DlSurfaceInstance > MakeOffscreenSurface(size_t width, size_t height, PixelFormat format=kN32PremulPixelFormat) const =0
virtual BackendType backend_type() const =0
virtual bool InitializeSurface(size_t width, size_t height, PixelFormat format=kN32PremulPixelFormat)=0
virtual const std::string backend_name() const =0
int32_t x
VkSurfaceKHR surface
Definition main.cc:65
uint32_t uint32_t * format
#define FML_DCHECK(condition)
Definition logging.h:122
double y
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 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
Definition ref_ptr.h:261
int32_t height
int32_t width
Represents a texture and its intended draw transform/sampler configuration.
Definition snapshot.h:24