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

Side by Side Diff: ui/gl/gl_surface_x11.cc

Issue 1723303002: Implement GLX for Ozone X11. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move refactor to new CL. Created 4 years, 8 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gl/gl_surface.h" 5 #include "ui/gl/gl_surface.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <X11/Xlib.h>
8 9
9 #include <memory> 10 #include <memory>
10 11
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
14 #include "base/trace_event/trace_event.h" 15 #include "base/trace_event/trace_event.h"
16 #include "ui/events/platform/platform_event_dispatcher.h"
17 #include "ui/events/platform/platform_event_source.h"
15 #include "ui/gfx/native_widget_types.h" 18 #include "ui/gfx/native_widget_types.h"
16 #include "ui/gfx/x/x11_types.h" 19 #include "ui/gfx/x/x11_types.h"
17 #include "ui/gl/gl_bindings.h" 20 #include "ui/gl/gl_bindings.h"
18 #include "ui/gl/gl_implementation.h" 21 #include "ui/gl/gl_implementation.h"
19 #include "ui/gl/gl_surface_egl.h" 22 #include "ui/gl/gl_surface_egl.h"
20 #include "ui/gl/gl_surface_egl_x11.h" 23 #include "ui/gl/gl_surface_egl_x11.h"
21 #include "ui/gl/gl_surface_glx.h" 24 #include "ui/gl/gl_surface_glx.h"
22 #include "ui/gl/gl_surface_osmesa.h" 25 #include "ui/gl/gl_surface_osmesa.h"
23 #include "ui/gl/gl_surface_stub.h" 26 #include "ui/gl/gl_surface_stub.h"
24 27
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 x, 239 x,
237 y); 240 y);
238 241
239 return gfx::SwapResult::SWAP_ACK; 242 return gfx::SwapResult::SWAP_ACK;
240 } 243 }
241 244
242 NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() { 245 NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() {
243 Destroy(); 246 Destroy();
244 } 247 }
245 248
249 // Native X11 specific implementation of GLX surface. Registers as a
250 // PlatformEventDispatcher to handle XEvents.
251 class GL_EXPORT NativeViewGLSurfaceGLXX11 : public NativeViewGLSurfaceGLX,
252 public ui::PlatformEventDispatcher {
253 public:
254 explicit NativeViewGLSurfaceGLXX11(gfx::AcceleratedWidget window);
255
256 // PlatformEventDispatcher implementation:
257 bool CanDispatchEvent(const ui::PlatformEvent& event) override;
258 uint32_t DispatchEvent(const ui::PlatformEvent& event) override;
259
260 protected:
261 ~NativeViewGLSurfaceGLXX11() override;
262
263 // NativeViewGLSurfaceGLX implementation:
264 void RegisterEvents() override;
265 void UnregisterEvents() override;
266
267 private:
268 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceGLXX11);
269 };
270
271 NativeViewGLSurfaceGLXX11::NativeViewGLSurfaceGLXX11(
272 gfx::AcceleratedWidget window)
273 : NativeViewGLSurfaceGLX(window) {}
274
275 bool NativeViewGLSurfaceGLXX11::CanDispatchEvent(
276 const ui::PlatformEvent& event) {
277 return CanHandleEvent(event);
278 }
279
280 uint32_t NativeViewGLSurfaceGLXX11::DispatchEvent(
281 const ui::PlatformEvent& event) {
282 ForwardExposeEvent(event);
283 return ui::POST_DISPATCH_STOP_PROPAGATION;
284 }
285
286 NativeViewGLSurfaceGLXX11::~NativeViewGLSurfaceGLXX11() {
287 Destroy();
288 }
289
290 void NativeViewGLSurfaceGLXX11::RegisterEvents() {
291 ui::PlatformEventSource* event_source =
292 ui::PlatformEventSource::GetInstance();
293 // Can be nullptr in tests, when we don't care about Exposes.
294 if (event_source) {
295 XSelectInput(gfx::GetXDisplay(), window(), ExposureMask);
296 event_source->AddPlatformEventDispatcher(this);
297 }
298 }
299
300 void NativeViewGLSurfaceGLXX11::UnregisterEvents() {
301 ui::PlatformEventSource* event_source =
302 ui::PlatformEventSource::GetInstance();
303 if (event_source)
304 event_source->RemovePlatformEventDispatcher(this);
305 }
306
246 } // namespace 307 } // namespace
247 308
248 bool GLSurface::InitializeOneOffInternal() { 309 bool GLSurface::InitializeOneOffInternal() {
249 switch (GetGLImplementation()) { 310 switch (GetGLImplementation()) {
250 case kGLImplementationDesktopGL: 311 case kGLImplementationDesktopGL:
251 if (!GLSurfaceGLX::InitializeOneOff()) { 312 if (!GLSurfaceGLX::InitializeOneOff()) {
252 LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed."; 313 LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed.";
253 return false; 314 return false;
254 } 315 }
255 break; 316 break;
(...skipping 22 matching lines...) Expand all
278 switch (GetGLImplementation()) { 339 switch (GetGLImplementation()) {
279 case kGLImplementationOSMesaGL: { 340 case kGLImplementationOSMesaGL: {
280 scoped_refptr<GLSurface> surface( 341 scoped_refptr<GLSurface> surface(
281 new NativeViewGLSurfaceOSMesa(window)); 342 new NativeViewGLSurfaceOSMesa(window));
282 if (!surface->Initialize()) 343 if (!surface->Initialize())
283 return NULL; 344 return NULL;
284 345
285 return surface; 346 return surface;
286 } 347 }
287 case kGLImplementationDesktopGL: { 348 case kGLImplementationDesktopGL: {
288 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceGLX(window)); 349 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceGLXX11(window));
289 if (!surface->Initialize()) 350 if (!surface->Initialize())
290 return NULL; 351 return NULL;
291 352
292 return surface; 353 return surface;
293 } 354 }
294 case kGLImplementationEGLGLES2: { 355 case kGLImplementationEGLGLES2: {
295 DCHECK(window != gfx::kNullAcceleratedWidget); 356 DCHECK(window != gfx::kNullAcceleratedWidget);
296 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceEGLX11(window)); 357 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceEGLX11(window));
297 if (!surface->Initialize()) 358 if (!surface->Initialize())
298 return NULL; 359 return NULL;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 NOTREACHED(); 401 NOTREACHED();
341 return NULL; 402 return NULL;
342 } 403 }
343 } 404 }
344 405
345 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { 406 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() {
346 return gfx::GetXDisplay(); 407 return gfx::GetXDisplay();
347 } 408 }
348 409
349 } // namespace gfx 410 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698