Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
shell_test_platform_view_gl.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/shell/common/shell_test_platform_view_gl.h"
6
7#include <utility>
8
9#include <EGL/egl.h>
10
11#include "flutter/shell/gpu/gpu_surface_gl_skia.h"
12#include "impeller/entity/gles/entity_shaders_gles.h"
13
14#if IMPELLER_ENABLE_3D
15#include "impeller/scene/shaders/gles/scene_shaders_gles.h" // nogncheck
16#endif
17
18namespace flutter {
19namespace testing {
20
21static std::vector<std::shared_ptr<fml::Mapping>> ShaderLibraryMappings() {
22 return {
23 std::make_shared<fml::NonOwnedMapping>(
24 impeller_entity_shaders_gles_data,
25 impeller_entity_shaders_gles_length),
26#if IMPELLER_ENABLE_3D
27 std::make_shared<fml::NonOwnedMapping>(
28 impeller_scene_shaders_gles_data, impeller_scene_shaders_gles_length),
29#endif
30 };
31}
32
34 PlatformView::Delegate& delegate,
35 const TaskRunners& task_runners,
36 std::shared_ptr<ShellTestVsyncClock> vsync_clock,
37 CreateVsyncWaiter create_vsync_waiter,
38 std::shared_ptr<ShellTestExternalViewEmbedder>
39 shell_test_external_view_embedder)
40 : ShellTestPlatformView(delegate, task_runners),
41 gl_surface_(SkISize::Make(800, 600)),
42 create_vsync_waiter_(std::move(create_vsync_waiter)),
43 vsync_clock_(std::move(vsync_clock)),
44 shell_test_external_view_embedder_(
45 std::move(shell_test_external_view_embedder)) {
46 if (GetSettings().enable_impeller) {
47 auto resolver = [](const char* name) -> void* {
48 return reinterpret_cast<void*>(::eglGetProcAddress(name));
49 };
50 // ANGLE needs this to initialize version strings checked by
51 // impeller::ProcTableGLES.
52 gl_surface_.MakeCurrent();
53 auto gl = std::make_unique<impeller::ProcTableGLES>(resolver);
54 if (!gl->IsValid()) {
55 FML_LOG(ERROR) << "Proc table when a shell unittests invalid.";
56 return;
57 }
58 impeller_context_ = impeller::ContextGLES::Create(
59 std::move(gl), ShaderLibraryMappings(), true);
60 }
61}
62
64
65std::unique_ptr<VsyncWaiter> ShellTestPlatformViewGL::CreateVSyncWaiter() {
66 return create_vsync_waiter_();
67}
68
69// |ShellTestPlatformView|
71 vsync_clock_->SimulateVSync();
72}
73
74// |PlatformView|
76 return std::make_unique<GPUSurfaceGLSkia>(this, true);
77}
78
79// |PlatformView|
80std::shared_ptr<ExternalViewEmbedder>
82 return shell_test_external_view_embedder_;
83}
84
85// |PlatformView|
87 return [](DefaultPointerDataDispatcher::Delegate& delegate) {
88 return std::make_unique<SmoothPointerDataDispatcher>(delegate);
89 };
90}
91
92// |GPUSurfaceGLDelegate|
93std::unique_ptr<GLContextResult>
95 return std::make_unique<GLContextDefaultResult>(gl_surface_.MakeCurrent());
96}
97
98// |GPUSurfaceGLDelegate|
100 return gl_surface_.ClearCurrent();
101}
102
103// |GPUSurfaceGLDelegate|
105 const GLPresentInfo& present_info) {
106 return gl_surface_.Present();
107}
108
109// |GPUSurfaceGLDelegate|
111 return GLFBOInfo{
112 .fbo_id = gl_surface_.GetFramebuffer(frame_info.width, frame_info.height),
113 };
114}
115
116// |GPUSurfaceGLDelegate|
119 return [surface = &gl_surface_](const char* name) -> void* {
120 return surface->GetProcAddress(name);
121 };
122}
123
124} // namespace testing
125} // namespace flutter
static std::unique_ptr< SkEncoder > Make(SkWStream *dst, const SkPixmap *src, const SkYUVAPixmaps *srcYUVA, const SkColorSpace *srcYUVAColorSpace, const SkJpegEncoder::Options &options)
std::function< void *(const char *)> GLProcResolver
Used to forward events from the platform view to interested subsystems. This forwarding is done by th...
const Settings & GetSettings() const
Get the settings for this platform view instance.
The interface for Engine to implement.
ShellTestPlatformViewGL(PlatformView::Delegate &delegate, const TaskRunners &task_runners, std::shared_ptr< ShellTestVsyncClock > vsync_clock, CreateVsyncWaiter create_vsync_waiter, std::shared_ptr< ShellTestExternalViewEmbedder > shell_test_external_view_embedder)
bool GLContextPresent(const GLPresentInfo &present_info) override
std::unique_ptr< VsyncWaiter > CreateVSyncWaiter() override
Invoked by the shell to obtain a platform specific vsync waiter. It is optional for platforms to over...
std::unique_ptr< Surface > CreateRenderingSurface() override
GLFBOInfo GLContextFBO(GLFrameInfo frame_info) const override
std::shared_ptr< ExternalViewEmbedder > CreateExternalViewEmbedder() override
std::unique_ptr< GLContextResult > GLContextMakeCurrent() override
PointerDataDispatcherMaker GetDispatcherMaker() override
Returns a platform-specific PointerDataDispatcherMaker so the Engine can construct the PointerDataPac...
uint32_t GetFramebuffer(uint32_t width, uint32_t height) const
static std::shared_ptr< ContextGLES > Create(std::unique_ptr< ProcTableGLES > gl, const std::vector< std::shared_ptr< fml::Mapping > > &shader_libraries, bool enable_gpu_tracing)
VkSurfaceKHR surface
Definition main.cc:49
#define FML_LOG(severity)
Definition logging.h:82
std::function< std::unique_ptr< VsyncWaiter >()> CreateVsyncWaiter
static std::vector< std::shared_ptr< fml::Mapping > > ShaderLibraryMappings()
std::function< std::unique_ptr< PointerDataDispatcher >(PointerDataDispatcher::Delegate &)> PointerDataDispatcherMaker
Signature for constructing PointerDataDispatcher.
DEF_SWITCHES_START aot vmservice shared library name
Definition switches.h:32
Definition ref_ptr.h:256
#define ERROR(message)