Flutter Engine
 
Loading...
Searching...
No Matches
manager.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_SHELL_PLATFORM_WINDOWS_EGL_MANAGER_H_
6#define FLUTTER_SHELL_PLATFORM_WINDOWS_EGL_MANAGER_H_
7
8// OpenGL ES and EGL includes
9#include <EGL/egl.h>
10#include <EGL/eglext.h>
11#include <EGL/eglplatform.h>
12#include <GLES2/gl2.h>
13#include <GLES2/gl2ext.h>
14
15// Windows platform specific includes
16#include <d3d11.h>
17#include <dxgi.h>
18#include <dxgi1_6.h>
19#include <windows.h>
20#include <wrl/client.h>
21#include <memory>
22#include <optional>
23
24#include "flutter/fml/macros.h"
28
29namespace flutter {
30namespace egl {
31
36
37// A manager for initializing ANGLE correctly and using it to create and
38// destroy surfaces
39class Manager {
40 public:
41 static std::unique_ptr<Manager> Create(GpuPreference gpu_preference);
42
43 virtual ~Manager();
44
45 // Whether the manager is currently valid.
46 bool IsValid() const;
47
48 // Creates an EGL surface that can be used to render a Flutter view into a
49 // win32 HWND.
50 //
51 // After the surface is created, |WindowSurface::SetVSyncEnabled| should be
52 // called on a thread that can make the surface current.
53 //
54 // HWND is the window backing the surface. Width and height are the surface's
55 // physical pixel dimensions.
56 //
57 // Returns nullptr on failure.
58 virtual std::unique_ptr<WindowSurface> CreateWindowSurface(HWND hwnd,
59 size_t width,
60 size_t height);
61
62 // Check if the current thread has a context bound.
63 bool HasContextCurrent();
64
65 // Creates a |EGLSurface| from the provided handle.
66 EGLSurface CreateSurfaceFromHandle(EGLenum handle_type,
67 EGLClientBuffer handle,
68 const EGLint* attributes) const;
69
70 // Gets the |EGLDisplay|.
71 EGLDisplay egl_display() const { return display_; };
72
73 // Gets the |ID3D11Device| chosen by ANGLE.
74 bool GetDevice(ID3D11Device** device);
75
76 // Get the EGL context used to render Flutter views.
77 virtual Context* render_context() const;
78
79 // Get the EGL context used for async texture uploads.
80 virtual Context* resource_context() const;
81
82 static std::optional<LUID> GetLowPowerGpuLuid();
83
84 protected:
85 // Creates a new surface manager retaining reference to the passed-in target
86 // for the lifetime of the manager.
87 explicit Manager(GpuPreference gpu_preference);
88
89 private:
90 // Number of active instances of Manager
91 static int instance_count_;
92
93 // Initialize the EGL display.
94 bool InitializeDisplay(GpuPreference gpu_preference);
95
96 // Initialize the EGL configs.
97 bool InitializeConfig();
98
99 // Initialize the EGL render and resource contexts.
100 bool InitializeContexts();
101
102 // Initialize the D3D11 device.
103 bool InitializeDevice();
104
105 void CleanUp();
106
107 // Whether the manager was initialized successfully.
108 bool is_valid_ = false;
109
110 // EGL representation of native display.
111 EGLDisplay display_ = EGL_NO_DISPLAY;
112
113 // EGL framebuffer configuration.
114 EGLConfig config_ = nullptr;
115
116 // The EGL context used to render Flutter views.
117 std::unique_ptr<Context> render_context_;
118
119 // The EGL context used for async texture uploads.
120 std::unique_ptr<Context> resource_context_;
121
122 // The current D3D device.
123 Microsoft::WRL::ComPtr<ID3D11Device> resolved_device_ = nullptr;
124
126};
127
128} // namespace egl
129} // namespace flutter
130
131#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_EGL_MANAGER_H_
virtual Context * resource_context() const
Definition manager.cc:332
EGLSurface CreateSurfaceFromHandle(EGLenum handle_type, EGLClientBuffer handle, const EGLint *attributes) const
Definition manager.cc:310
static std::optional< LUID > GetLowPowerGpuLuid()
Definition manager.cc:336
virtual Context * render_context() const
Definition manager.cc:328
static std::unique_ptr< Manager > Create(GpuPreference gpu_preference)
Definition manager.cc:17
virtual std::unique_ptr< WindowSurface > CreateWindowSurface(HWND hwnd, size_t width, size_t height)
Definition manager.cc:276
bool GetDevice(ID3D11Device **device)
Definition manager.cc:317
EGLDisplay egl_display() const
Definition manager.h:71
bool IsValid() const
Definition manager.cc:272
VkDevice device
Definition main.cc:69
@ LowPowerPreference
@ NoPreference
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
int32_t height
int32_t width