1 // Copyright 2020 The Chromium 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 UI_GL_INIT_GL_FACTORY_LINUX_X11_H_
6 #define UI_GL_INIT_GL_FACTORY_LINUX_X11_H_
7 
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 #include "base/memory/ref_counted.h"
13 #include "ui/gfx/geometry/size.h"
14 #include "ui/gfx/native_widget_types.h"
15 #include "ui/gl/gl_implementation.h"
16 #include "ui/gl/gl_surface_format.h"
17 #include "ui/gl/gpu_preference.h"
18 
19 namespace gl {
20 
21 class GLContext;
22 class GLShareGroup;
23 class GLSurface;
24 
25 struct GLContextAttribs;
26 struct GLVersionInfo;
27 
28 // Note that this is a temporary implementation for Linux/X11 GL. It is called
29 // through GLFactoryOzone, and will be removed as soon as Linux/Ozone is
30 // the default. Comments have been copied from gl_factory.h
31 //
32 // TODO(msisov): remove this once Ozone is the default on Linux.
33 namespace init {
34 
35 // Returns a list of allowed GL implementations. The default implementation will
36 // be the first item.
37 std::vector<GLImplementation> GetAllowedGLImplementationsX11();
38 
39 // Initializes GL bindings and extension settings.
40 bool InitializeGLOneOffX11();
41 
42 // Initializes GL bindings without initializing extension settings.
43 bool InitializeGLNoExtensionsOneOffX11(bool init_bindings);
44 
45 // Initializes GL bindings - load dlls and get proc address according to gl
46 // command line switch.
47 bool InitializeStaticGLBindingsOneOffX11();
48 
49 // Initialize plaiform dependent extension settings, including bindings,
50 // capabilities, etc.
51 bool InitializeExtensionSettingsOneOffPlatformX11();
52 
53 // Initializes GL bindings using the provided parameters. This might be required
54 // for use in tests.
55 bool InitializeStaticGLBindingsImplementationX11(GLImplementation impl,
56                                                  bool fallback_to_software_gl);
57 
58 // Initializes GL platform using the provided parameters. This might be required
59 // for use in tests. This should be called only after GL bindings are initilzed
60 // successfully.
61 bool InitializeGLOneOffPlatformImplementationX11(bool fallback_to_software_gl,
62                                                  bool disable_gl_drawing,
63                                                  bool init_extensions);
64 
65 // Clears GL bindings and resets GL implementation.
66 void ShutdownGLX11(bool due_to_fallback);
67 
68 // Return information about the GL window system binding implementation (e.g.,
69 // EGL, GLX, WGL). Returns true if the information was retrieved successfully.
70 bool GetGLWindowSystemBindingInfoX11(const GLVersionInfo& gl_info,
71                                      GLWindowSystemBindingInfo* info);
72 
73 // Creates a GL context that is compatible with the given surface.
74 // |share_group|, if non-null, is a group of contexts which the internally
75 // created OpenGL context shares textures and other resources.
76 scoped_refptr<GLContext> CreateGLContextX11(GLShareGroup* share_group,
77                                             GLSurface* compatible_surface,
78                                             const GLContextAttribs& attribs);
79 
80 // Creates a GL surface that renders directly to a view.
81 scoped_refptr<GLSurface> CreateViewGLSurfaceX11(gfx::AcceleratedWidget window);
82 
83 // Creates a GL surface used for offscreen rendering.
84 scoped_refptr<GLSurface> CreateOffscreenGLSurfaceX11(const gfx::Size& size);
85 
86 scoped_refptr<GLSurface> CreateOffscreenGLSurfaceWithFormatX11(
87     const gfx::Size& size,
88     GLSurfaceFormat format);
89 
90 // Set platform dependent disabled extensions and re-initialize extension
91 // bindings.
92 void SetDisabledExtensionsPlatformX11(const std::string& disabled_extensions);
93 
94 }  // namespace init
95 
96 }  // namespace gl
97 
98 #endif  // UI_GL_INIT_GL_FACTORY_LINUX_X11_H_
99