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

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

Issue 23191007: Make the GPU process use an X11 event loop (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « ui/gl/gl_surface_glx.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 extern "C" { 5 extern "C" {
6 #include <X11/Xlib.h> 6 #include <X11/Xlib.h>
7 } 7 }
8 8
9 #include "ui/gl/gl_surface_glx.h" 9 #include "ui/gl/gl_surface_glx.h"
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/debug/trace_event.h" 12 #include "base/debug/trace_event.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/message_loop/message_pump_x11.h"
17 #include "base/synchronization/cancellation_flag.h" 18 #include "base/synchronization/cancellation_flag.h"
18 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
19 #include "base/threading/non_thread_safe.h" 20 #include "base/threading/non_thread_safe.h"
20 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
21 #include "base/time/time.h" 22 #include "base/time/time.h"
22 #include "third_party/mesa/src/include/GL/osmesa.h" 23 #include "third_party/mesa/src/include/GL/osmesa.h"
23 #include "ui/base/x/x11_util.h" 24 #include "ui/base/x/x11_util.h"
24 #include "ui/gl/gl_bindings.h" 25 #include "ui/gl/gl_bindings.h"
25 #include "ui/gl/gl_implementation.h" 26 #include "ui/gl/gl_implementation.h"
26 #include "ui/gl/vsync_provider.h" 27 #include "ui/gl/vsync_provider.h"
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 if (initialized) 309 if (initialized)
309 return true; 310 return true;
310 311
311 // http://crbug.com/245466 312 // http://crbug.com/245466
312 setenv("force_s3tc_enable", "true", 1); 313 setenv("force_s3tc_enable", "true", 1);
313 314
314 // SGIVideoSyncProviderShim (if instantiated) will issue X commands on 315 // SGIVideoSyncProviderShim (if instantiated) will issue X commands on
315 // it's own thread. 316 // it's own thread.
316 XInitThreads(); 317 XInitThreads();
317 318
318 g_display = base::MessagePumpForUI::GetDefaultXDisplay(); 319 // XXX -- base::MessagePumpForUI is returning Gtk here -- we need to
320 // make this *not* be a compile-time decision.
321 g_display = //base::MessagePumpForUI::GetDefaultXDisplay();
322 base::MessagePumpX11::GetDefaultXDisplay();
319 if (!g_display) { 323 if (!g_display) {
320 LOG(ERROR) << "XOpenDisplay failed."; 324 LOG(ERROR) << "XOpenDisplay failed.";
321 return false; 325 return false;
322 } 326 }
323 327
324 int major, minor; 328 int major, minor;
325 if (!glXQueryVersion(g_display, &major, &minor)) { 329 if (!glXQueryVersion(g_display, &major, &minor)) {
326 LOG(ERROR) << "glxQueryVersion failed"; 330 LOG(ERROR) << "glxQueryVersion failed";
327 return false; 331 return false;
328 } 332 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 bool GLSurfaceGLX::IsOMLSyncControlSupported() { 385 bool GLSurfaceGLX::IsOMLSyncControlSupported() {
382 return g_glx_oml_sync_control_supported; 386 return g_glx_oml_sync_control_supported;
383 } 387 }
384 388
385 void* GLSurfaceGLX::GetDisplay() { 389 void* GLSurfaceGLX::GetDisplay() {
386 return g_display; 390 return g_display;
387 } 391 }
388 392
389 GLSurfaceGLX::~GLSurfaceGLX() {} 393 GLSurfaceGLX::~GLSurfaceGLX() {}
390 394
395 // XXX - we should just have 1 of these, not 1 per GLSurfaceGLX
396 class NativeViewXExposeEventForwarder : public base::MessageLoop::Observer {
397 public:
398 NativeViewXExposeEventForwarder(gfx::AcceleratedWidget parent_window,
399 gfx::AcceleratedWidget child_window)
400 : child_window_(child_window), parent_window_(parent_window) {
401 base::MessageLoopForUI::current()->AddObserver(this);
402 }
403 ~NativeViewXExposeEventForwarder() {
404 base::MessageLoopForUI::current()->RemoveObserver(this);
405 }
406
407 virtual base::EventStatus WillProcessEvent(
408 const base::NativeEvent& xevent) OVERRIDE {
409 if (xevent->type == Expose &&
410 xevent->xexpose.window == child_window_) {
411 XEvent forwarded_event = *xevent;
412 forwarded_event.xexpose.window = parent_window_;
413 XSendEvent(
414 g_display, parent_window_, False, ExposureMask, &forwarded_event);
415 }
416 return base::EVENT_CONTINUE;
417 }
418 virtual void DidProcessEvent(const base::NativeEvent&) OVERRIDE {
419 }
420
421 private:
422 gfx::AcceleratedWidget child_window_;
423 gfx::AcceleratedWidget parent_window_;
424 };
425
391 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX(gfx::AcceleratedWidget window) 426 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX(gfx::AcceleratedWidget window)
392 : window_(window), 427 : parent_window_(window),
428 window_(0),
393 config_(NULL) { 429 config_(NULL) {
394 } 430 }
395 431
396 bool NativeViewGLSurfaceGLX::Initialize() { 432 bool NativeViewGLSurfaceGLX::Initialize() {
397 XWindowAttributes attributes; 433 XWindowAttributes attributes;
398 if (!XGetWindowAttributes(g_display, window_, &attributes)) { 434 if (!XGetWindowAttributes(g_display, parent_window_, &attributes)) {
399 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; 435 LOG(ERROR) << "XGetWindowAttributes failed for window "
436 << parent_window_ << ".";
400 return false; 437 return false;
401 } 438 }
402 size_ = gfx::Size(attributes.width, attributes.height); 439 size_ = gfx::Size(attributes.width, attributes.height);
403 440
441 XSetWindowAttributes set_attributes = {0};
442 set_attributes.event_mask = ExposureMask;
443 window_= XCreateWindow(
444 g_display, parent_window_, 0, 0, attributes.width, attributes.height, 0,
445 attributes.depth, InputOutput, attributes.visual, CWEventMask,
446 &set_attributes);
447 XMapWindow(g_display, window_);
448 XFlush(g_display);
449
404 if (g_glx_oml_sync_control_supported) 450 if (g_glx_oml_sync_control_supported)
405 vsync_provider_.reset(new OMLSyncControlVSyncProvider(window_)); 451 vsync_provider_.reset(new OMLSyncControlVSyncProvider(window_));
406 else if (g_glx_sgi_video_sync_supported) 452 else if (g_glx_sgi_video_sync_supported)
407 vsync_provider_.reset(new SGIVideoSyncVSyncProvider(window_)); 453 vsync_provider_.reset(new SGIVideoSyncVSyncProvider(window_));
408 454
455 event_forwarder_.reset(
456 new NativeViewXExposeEventForwarder(parent_window_, window_));
457
409 return true; 458 return true;
410 } 459 }
411 460
412 void NativeViewGLSurfaceGLX::Destroy() { 461 void NativeViewGLSurfaceGLX::Destroy() {
462 event_forwarder_.reset();
463 if (window_) {
464 XDestroyWindow(g_display, window_);
465 XFlush(g_display);
466 window_ = 0;
467 }
413 } 468 }
414 469
415 bool NativeViewGLSurfaceGLX::Resize(const gfx::Size& size) { 470 bool NativeViewGLSurfaceGLX::Resize(const gfx::Size& size) {
471 XResizeWindow(g_display, window_, size.width(), size.height());
472 XFlush(g_display);
416 size_ = size; 473 size_ = size;
417 return true; 474 return true;
418 } 475 }
419 476
420 bool NativeViewGLSurfaceGLX::IsOffscreen() { 477 bool NativeViewGLSurfaceGLX::IsOffscreen() {
421 return false; 478 return false;
422 } 479 }
423 480
424 bool NativeViewGLSurfaceGLX::SwapBuffers() { 481 bool NativeViewGLSurfaceGLX::SwapBuffers() {
425 glXSwapBuffers(g_display, window_); 482 glXSwapBuffers(g_display, window_);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 DCHECK(gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer); 566 DCHECK(gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer);
510 glXCopySubBufferMESA(g_display, window_, x, y, width, height); 567 glXCopySubBufferMESA(g_display, window_, x, y, width, height);
511 return true; 568 return true;
512 } 569 }
513 570
514 VSyncProvider* NativeViewGLSurfaceGLX::GetVSyncProvider() { 571 VSyncProvider* NativeViewGLSurfaceGLX::GetVSyncProvider() {
515 return vsync_provider_.get(); 572 return vsync_provider_.get();
516 } 573 }
517 574
518 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX() 575 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX()
519 : window_(0), 576 : parent_window_(0),
577 window_(0),
520 config_(NULL) { 578 config_(NULL) {
521 } 579 }
522 580
523 NativeViewGLSurfaceGLX::~NativeViewGLSurfaceGLX() { 581 NativeViewGLSurfaceGLX::~NativeViewGLSurfaceGLX() {
524 Destroy(); 582 Destroy();
525 } 583 }
526 584
527 PbufferGLSurfaceGLX::PbufferGLSurfaceGLX(const gfx::Size& size) 585 PbufferGLSurfaceGLX::PbufferGLSurfaceGLX(const gfx::Size& size)
528 : size_(size), 586 : size_(size),
529 config_(NULL), 587 config_(NULL),
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 665
608 void* PbufferGLSurfaceGLX::GetConfig() { 666 void* PbufferGLSurfaceGLX::GetConfig() {
609 return config_; 667 return config_;
610 } 668 }
611 669
612 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { 670 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() {
613 Destroy(); 671 Destroy();
614 } 672 }
615 673
616 } // namespace gfx 674 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_surface_glx.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698