blob: bc0ca1780d318e150f6e926004b6132687858f0d [file] [log] [blame]
thomasanderson62ba78ff2016-10-01 02:03:421// Copyright 2016 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_GL_VISUAL_PICKER_GLX_H_
6#define UI_GL_GL_VISUAL_PICKER_GLX_H_
7
8#include <X11/Xutil.h>
9
10#include <vector>
11
12#include "base/macros.h"
13#include "ui/gfx/x/x11_types.h"
14#include "ui/gl/gl_export.h"
15
16namespace base {
17template <typename T>
18struct DefaultSingletonTraits;
19}
20
21namespace gl {
22
23// Picks the best X11 visuals to use for GL. This class is adapted from GTK's
24// pick_better_visual_for_gl. Tries to find visuals that
25// 1. Support GL
26// 2. Support double buffer
27// 3. Have an alpha channel only if we want one
28class GL_EXPORT GLVisualPickerGLX {
29 public:
30 static GLVisualPickerGLX* GetInstance();
31
32 ~GLVisualPickerGLX();
33
34 const XVisualInfo& system_visual() { return system_visual_; };
35
36 const XVisualInfo& rgba_visual() { return rgba_visual_; };
37
38 private:
39 friend struct base::DefaultSingletonTraits<GLVisualPickerGLX>;
40
41 XVisualInfo PickBestGlVisual(const std::vector<XVisualInfo>& visuals,
42 bool want_alpha) const;
43
44 XVisualInfo PickBestSystemVisual(
45 const std::vector<XVisualInfo>& visuals) const;
46
47 XVisualInfo PickBestRgbaVisual(const std::vector<XVisualInfo>& visuals) const;
48
49 XDisplay* display_;
50
51 bool has_glx_visual_rating_;
52 bool has_glx_multisample_;
53
54 XVisualInfo system_visual_;
55 XVisualInfo rgba_visual_;
56
57 GLVisualPickerGLX();
58
59 DISALLOW_COPY_AND_ASSIGN(GLVisualPickerGLX);
60};
61
62} // namespace gl
63
64#endif // UI_GL_GL_VISUAL_PICKER_GLX_H_