| OLD | NEW |
| 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 |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 // A mechanism for forwarding XExpose events from one window to another. | 304 // A mechanism for forwarding XExpose events from one window to another. |
| 305 // Because in the workaround for http://crbug.com/145600 the child window | 305 // Because in the workaround for http://crbug.com/145600 the child window |
| 306 // is placed on top of the parent window, only the child window will receive | 306 // is placed on top of the parent window, only the child window will receive |
| 307 // all expose events. These need to be forwared to the parent window to inform | 307 // all expose events. These need to be forwared to the parent window to inform |
| 308 // it that it should paint. | 308 // it that it should paint. |
| 309 class XExposeEventForwarder : public base::MessagePumpObserver { | 309 class XExposeEventForwarder : public base::MessagePumpObserver { |
| 310 public: | 310 public: |
| 311 XExposeEventForwarder() {} | 311 XExposeEventForwarder() {} |
| 312 virtual ~XExposeEventForwarder() { | 312 virtual ~XExposeEventForwarder() { |
| 313 DCHECK(child_to_parent_map_.empty()); | 313 DCHECK(child_to_parent_map_.empty()); |
| 314 DCHECK(parent_to_child_map_.empty()); |
| 314 } | 315 } |
| 315 void AddParentChildPair(gfx::AcceleratedWidget parent_window, | 316 void AddParentChildPair(gfx::AcceleratedWidget parent_window, |
| 316 gfx::AcceleratedWidget child_window) { | 317 gfx::AcceleratedWidget child_window) { |
| 317 if (child_to_parent_map_.empty()) | 318 if (child_to_parent_map_.empty()) |
| 318 base::MessagePumpX11::Current()->AddObserver(this); | 319 base::MessagePumpX11::Current()->AddObserver(this); |
| 319 | 320 |
| 320 DCHECK(child_to_parent_map_.find(child_window) == | 321 DCHECK(child_to_parent_map_.find(child_window) == |
| 321 child_to_parent_map_.end()); | 322 child_to_parent_map_.end()); |
| 322 child_to_parent_map_.insert(std::make_pair( | 323 child_to_parent_map_.insert(std::make_pair( |
| 323 child_window, parent_window)); | 324 child_window, parent_window)); |
| 325 parent_to_child_map_.insert(std::make_pair( |
| 326 parent_window, child_window)); |
| 324 } | 327 } |
| 325 void RemoveParentChildPair(gfx::AcceleratedWidget parent_window, | 328 void RemoveParentChildPair(gfx::AcceleratedWidget parent_window, |
| 326 gfx::AcceleratedWidget child_window) { | 329 gfx::AcceleratedWidget child_window) { |
| 327 DCHECK(child_to_parent_map_.find(child_window) != | 330 DCHECK(child_to_parent_map_.find(child_window) != |
| 328 child_to_parent_map_.end()); | 331 child_to_parent_map_.end()); |
| 332 DCHECK(parent_to_child_map_.find(parent_window) != |
| 333 parent_to_child_map_.end()); |
| 329 child_to_parent_map_.erase(child_window); | 334 child_to_parent_map_.erase(child_window); |
| 335 parent_to_child_map_.erase(parent_window); |
| 330 | 336 |
| 331 if (child_to_parent_map_.empty()) | 337 if (child_to_parent_map_.empty()) |
| 332 base::MessagePumpX11::Current()->RemoveObserver(this); | 338 base::MessagePumpX11::Current()->RemoveObserver(this); |
| 333 } | 339 } |
| 340 void SetChildWindowVisible(gfx::AcceleratedWidget parent_window, |
| 341 bool visible) { |
| 342 WindowMap::const_iterator found = parent_to_child_map_.find(parent_window); |
| 343 if (found == parent_to_child_map_.end()) |
| 344 return; |
| 345 gfx::AcceleratedWidget child_window = found->second; |
| 346 if (visible) |
| 347 XMapWindow(g_display, child_window); |
| 348 else |
| 349 XUnmapWindow(g_display, child_window); |
| 350 // XFlush(g_display); |
| 351 } |
| 334 | 352 |
| 335 private: | 353 private: |
| 336 virtual base::EventStatus WillProcessEvent ( | 354 virtual base::EventStatus WillProcessEvent ( |
| 337 const base::NativeEvent& xevent) OVERRIDE { | 355 const base::NativeEvent& xevent) OVERRIDE { |
| 338 if (xevent->type != Expose) | 356 if (xevent->type != Expose) |
| 339 return base::EVENT_CONTINUE; | 357 return base::EVENT_CONTINUE; |
| 340 | 358 |
| 341 WindowMap::const_iterator found = child_to_parent_map_.find( | 359 WindowMap::const_iterator found = child_to_parent_map_.find( |
| 342 xevent->xexpose.window); | 360 xevent->xexpose.window); |
| 343 if (found == child_to_parent_map_.end()) | 361 if (found == child_to_parent_map_.end()) |
| 344 return base::EVENT_CONTINUE; | 362 return base::EVENT_CONTINUE; |
| 345 | 363 |
| 346 gfx::AcceleratedWidget target_window = found->second; | 364 gfx::AcceleratedWidget target_window = found->second; |
| 347 XEvent forwarded_event = *xevent; | 365 XEvent forwarded_event = *xevent; |
| 348 forwarded_event.xexpose.window = target_window; | 366 forwarded_event.xexpose.window = target_window; |
| 349 XSendEvent(g_display, target_window, False, ExposureMask, | 367 XSendEvent(g_display, target_window, False, ExposureMask, |
| 350 &forwarded_event); | 368 &forwarded_event); |
| 351 return base::EVENT_CONTINUE; | 369 return base::EVENT_CONTINUE; |
| 352 } | 370 } |
| 353 virtual void DidProcessEvent(const base::NativeEvent& xevent) OVERRIDE { | 371 virtual void DidProcessEvent(const base::NativeEvent& xevent) OVERRIDE { |
| 354 } | 372 } |
| 355 | 373 |
| 356 typedef std::map<gfx::AcceleratedWidget, gfx::AcceleratedWidget> WindowMap; | 374 typedef std::map<gfx::AcceleratedWidget, gfx::AcceleratedWidget> WindowMap; |
| 357 WindowMap child_to_parent_map_; | 375 WindowMap child_to_parent_map_; |
| 376 WindowMap parent_to_child_map_; |
| 358 | 377 |
| 359 DISALLOW_COPY_AND_ASSIGN(XExposeEventForwarder); | 378 DISALLOW_COPY_AND_ASSIGN(XExposeEventForwarder); |
| 360 }; | 379 }; |
| 361 | 380 |
| 362 static base::LazyInstance<XExposeEventForwarder> g_xexpose_event_forwarder = | 381 static base::LazyInstance<XExposeEventForwarder> g_xexpose_event_forwarder = |
| 363 LAZY_INSTANCE_INITIALIZER; | 382 LAZY_INSTANCE_INITIALIZER; |
| 364 | 383 |
| 365 // Do not use this workaround when running in test harnesses that do not have | 384 // Do not use this workaround when running in test harnesses that do not have |
| 366 // a message loop or do not have a TYPE_GPU message loop. | 385 // a message loop or do not have a TYPE_GPU message loop. |
| 367 bool g_create_child_windows = false; | 386 bool g_create_child_windows = false; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 383 // it's own thread. | 402 // it's own thread. |
| 384 XInitThreads(); | 403 XInitThreads(); |
| 385 | 404 |
| 386 #if defined(TOOLKIT_GTK) | 405 #if defined(TOOLKIT_GTK) |
| 387 // Be sure to use the X display handle and not the GTK display handle if this | 406 // Be sure to use the X display handle and not the GTK display handle if this |
| 388 // is the GPU process. | 407 // is the GPU process. |
| 389 g_create_child_windows = | 408 g_create_child_windows = |
| 390 base::MessageLoop::current() && | 409 base::MessageLoop::current() && |
| 391 base::MessageLoop::current()->type() == base::MessageLoop::TYPE_GPU; | 410 base::MessageLoop::current()->type() == base::MessageLoop::TYPE_GPU; |
| 392 | 411 |
| 393 // Disable this path because it is causing window contents to disappear. | |
| 394 // http://crbug.com/292655 | |
| 395 g_create_child_windows = false; | |
| 396 | |
| 397 if (g_create_child_windows) | 412 if (g_create_child_windows) |
| 398 g_display = base::MessagePumpX11::GetDefaultXDisplay(); | 413 g_display = base::MessagePumpX11::GetDefaultXDisplay(); |
| 399 else | 414 else |
| 400 g_display = base::MessagePumpForUI::GetDefaultXDisplay(); | 415 g_display = base::MessagePumpForUI::GetDefaultXDisplay(); |
| 401 #else | 416 #else |
| 402 g_display = base::MessagePumpForUI::GetDefaultXDisplay(); | 417 g_display = base::MessagePumpForUI::GetDefaultXDisplay(); |
| 403 #endif | 418 #endif |
| 404 | 419 |
| 405 if (!g_display) { | 420 if (!g_display) { |
| 406 LOG(ERROR) << "XOpenDisplay failed."; | 421 LOG(ERROR) << "XOpenDisplay failed."; |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 int x, int y, int width, int height) { | 705 int x, int y, int width, int height) { |
| 691 DCHECK(gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer); | 706 DCHECK(gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer); |
| 692 glXCopySubBufferMESA(g_display, GetDrawableHandle(), x, y, width, height); | 707 glXCopySubBufferMESA(g_display, GetDrawableHandle(), x, y, width, height); |
| 693 return true; | 708 return true; |
| 694 } | 709 } |
| 695 | 710 |
| 696 VSyncProvider* NativeViewGLSurfaceGLX::GetVSyncProvider() { | 711 VSyncProvider* NativeViewGLSurfaceGLX::GetVSyncProvider() { |
| 697 return vsync_provider_.get(); | 712 return vsync_provider_.get(); |
| 698 } | 713 } |
| 699 | 714 |
| 715 #if defined(TOOLKIT_GTK) |
| 716 void NativeViewGLSurfaceGLX::AcceleratedCompositingStateChange( |
| 717 int32 surface_id, bool compositing_active) { |
| 718 g_xexpose_event_forwarder.Pointer()->SetChildWindowVisible( |
| 719 surface_id, compositing_active); |
| 720 } |
| 721 #endif |
| 722 |
| 700 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX() | 723 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX() |
| 701 : parent_window_(0), | 724 : parent_window_(0), |
| 702 #if defined(TOOLKIT_GTK) | 725 #if defined(TOOLKIT_GTK) |
| 703 child_window_(0), | 726 child_window_(0), |
| 704 dummy_window_(0), | 727 dummy_window_(0), |
| 705 backbuffer_allocated_(true), | 728 backbuffer_allocated_(true), |
| 706 frontbuffer_allocated_(true), | 729 frontbuffer_allocated_(true), |
| 707 #endif | 730 #endif |
| 708 config_(NULL) { | 731 config_(NULL) { |
| 709 } | 732 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 | 818 |
| 796 void* PbufferGLSurfaceGLX::GetConfig() { | 819 void* PbufferGLSurfaceGLX::GetConfig() { |
| 797 return config_; | 820 return config_; |
| 798 } | 821 } |
| 799 | 822 |
| 800 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { | 823 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { |
| 801 Destroy(); | 824 Destroy(); |
| 802 } | 825 } |
| 803 | 826 |
| 804 } // namespace gfx | 827 } // namespace gfx |
| OLD | NEW |