Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: ui/ozone/platform/x11/x11_surface_factory.cc

Issue 750593003: Ozone X11 platform Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup leftover stuff Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/ozone/platform/x11/x11_surface_factory.h ('k') | ui/ozone/public/surface_factory_ozone.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 #include "ui/ozone/platform/x11/x11_surface_factory.h"
6
7 #include "third_party/khronos/EGL/egl.h"
8 #include "ui/gfx/vsync_provider.h"
9 #include "ui/ozone/common/egl_util.h"
10 #include "ui/ozone/public/surface_ozone_egl.h"
11 #include "ui/platform_window/x11/x11_window.h"
12
13 namespace ui {
14
15 class X11SurfaceEGL : public SurfaceOzoneEGL {
16 public:
17 X11SurfaceEGL(gfx::AcceleratedWidget widget) : widget_(widget) {}
18 ~X11SurfaceEGL() {}
19
20 intptr_t GetNativeWindow() override { return widget_; }
21
22 bool OnSwapBuffers() override { return true; }
23
24 bool ResizeNativeWindow(const gfx::Size& viewport_size) override {
25 return true;
26 }
27
28 scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() override {
29 return scoped_ptr<gfx::VSyncProvider>();
30 }
31
32 private:
33 gfx::AcceleratedWidget widget_;
34
35 DISALLOW_COPY_AND_ASSIGN(X11SurfaceEGL);
36 };
37
38 X11SurfaceFactory::X11SurfaceFactory(
39 scoped_refptr<X11WindowManager> window_manager)
40 : window_manager_(window_manager) {
41 }
42
43 X11SurfaceFactory::~X11SurfaceFactory() {
44 }
45
46 // SurfaceFactoryOzone:
47 scoped_ptr<SurfaceOzoneEGL> X11SurfaceFactory::CreateEGLSurfaceForWidget(
48 gfx::AcceleratedWidget widget) {
49 return scoped_ptr<SurfaceOzoneEGL>(new X11SurfaceEGL(widget));
50 }
51
52 bool X11SurfaceFactory::LoadEGLGLES2Bindings(
53 AddGLLibraryCallback add_gl_library,
54 SetGLGetProcAddressProcCallback set_gl_get_proc_address) {
55 return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address);
56 }
57
58 intptr_t X11SurfaceFactory::GetNativeDisplay() {
59 return reinterpret_cast<intptr_t>(gfx::GetXDisplay());
60 }
61
62 void* X11SurfaceFactory::GetEGLSurfaceConfig(const EglConfigInfo& egl,
63 SurfaceOzoneEGL* surface) {
64 // Try matching the window depth with an alpha channel,
65 // because we're worried the destination alpha width could
66 // constrain blending precision.
67 EGLConfig config;
68 const int kBufferSizeOffset = 1;
69 const int kAlphaSizeOffset = 3;
70 EGLint config_attribs[] = {EGL_BUFFER_SIZE,
71 ~0,
72 EGL_ALPHA_SIZE,
73 8,
74 EGL_BLUE_SIZE,
75 8,
76 EGL_GREEN_SIZE,
77 8,
78 EGL_RED_SIZE,
79 8,
80 EGL_RENDERABLE_TYPE,
81 EGL_OPENGL_ES2_BIT,
82 EGL_SURFACE_TYPE,
83 EGL_WINDOW_BIT,
84 EGL_NONE};
85 XWindowAttributes win_attribs;
86 if (XGetWindowAttributes(gfx::GetXDisplay(), surface->GetNativeWindow(),
87 &win_attribs)) {
88 config_attribs[kBufferSizeOffset] = win_attribs.depth;
89 }
90
91 EGLint num_configs;
92 if (!egl.choose_config.Run(config_attribs, &config, 1, &num_configs)) {
93 LOG(ERROR) << "eglChooseConfig failed with error "
94 << egl.get_last_error_string.Run();
95 return NULL;
96 }
97
98 if (num_configs) {
99 EGLint config_depth;
100 if (!egl.get_config_attribute.Run(config, EGL_BUFFER_SIZE, &config_depth)) {
101 LOG(ERROR) << "eglGetConfigAttrib failed with error "
102 << egl.get_last_error_string.Run();
103 return NULL;
104 }
105
106 if (config_depth == config_attribs[kBufferSizeOffset]) {
107 return config;
108 }
109 }
110
111 // Try without an alpha channel.
112 config_attribs[kAlphaSizeOffset] = 0;
113 if (!egl.choose_config.Run(config_attribs, &config, 1, &num_configs)) {
114 LOG(ERROR) << "eglChooseConfig failed with error "
115 << egl.get_last_error_string.Run();
116 return NULL;
117 }
118
119 if (num_configs == 0) {
120 LOG(ERROR) << "No suitable EGL configs found.";
121 return NULL;
122 }
123 return config;
124 }
125
126 X11Window* X11SurfaceFactory::FindWindow(XID id) {
127 return window_manager_->FindWindow(id);
128 }
129
130 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/x11/x11_surface_factory.h ('k') | ui/ozone/public/surface_factory_ozone.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698