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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 } | 384 } |
385 | 385 |
386 void* GLSurfaceGLX::GetDisplay() { | 386 void* GLSurfaceGLX::GetDisplay() { |
387 return g_display; | 387 return g_display; |
388 } | 388 } |
389 | 389 |
390 GLSurfaceGLX::~GLSurfaceGLX() {} | 390 GLSurfaceGLX::~GLSurfaceGLX() {} |
391 | 391 |
392 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX(gfx::AcceleratedWidget window) | 392 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX(gfx::AcceleratedWidget window) |
393 : parent_window_(window), | 393 : parent_window_(window), |
394 window_(0), | |
394 config_(NULL) { | 395 config_(NULL) { |
395 } | 396 } |
396 | 397 |
397 gfx::AcceleratedWidget NativeViewGLSurfaceGLX::GetDrawableHandle() const { | 398 gfx::AcceleratedWidget NativeViewGLSurfaceGLX::GetDrawableHandle() const { |
398 return parent_window_; | 399 return window_; |
399 } | 400 } |
400 | 401 |
401 bool NativeViewGLSurfaceGLX::Initialize() { | 402 bool NativeViewGLSurfaceGLX::Initialize() { |
402 XWindowAttributes attributes; | 403 XWindowAttributes attributes; |
403 if (!XGetWindowAttributes(g_display, parent_window_, &attributes)) { | 404 if (!XGetWindowAttributes(g_display, parent_window_, &attributes)) { |
404 LOG(ERROR) << "XGetWindowAttributes failed for window " << parent_window_ | 405 LOG(ERROR) << "XGetWindowAttributes failed for window " << parent_window_ |
405 << "."; | 406 << "."; |
406 return false; | 407 return false; |
407 } | 408 } |
408 size_ = gfx::Size(attributes.width, attributes.height); | 409 size_ = gfx::Size(attributes.width, attributes.height); |
410 // Create a child window, with a CopyFromParent visual (to avoid inducing | |
411 // extra blits in the driver), that we can resize exactly in Resize(), | |
412 // correctly ordered with GL, so that we don't have invalid transient states. | |
413 // See https://crbug.com/326995. | |
414 window_ = XCreateWindow(g_display, | |
415 parent_window_, | |
416 0, | |
417 0, | |
418 size_.width(), | |
419 size_.height(), | |
420 0, | |
421 CopyFromParent, | |
422 InputOutput, | |
423 CopyFromParent, | |
424 0, | |
425 NULL); | |
426 XMapWindow(g_display, window_); | |
ccameron
2014/05/23 09:09:06
Looking back at https://chromiumcodereview.appspot
| |
409 | 427 |
410 gfx::AcceleratedWidget window_for_vsync = parent_window_; | 428 gfx::AcceleratedWidget window_for_vsync = window_; |
411 | 429 |
412 if (g_glx_oml_sync_control_supported) | 430 if (g_glx_oml_sync_control_supported) |
413 vsync_provider_.reset(new OMLSyncControlVSyncProvider(window_for_vsync)); | 431 vsync_provider_.reset(new OMLSyncControlVSyncProvider(window_for_vsync)); |
414 else if (g_glx_sgi_video_sync_supported) | 432 else if (g_glx_sgi_video_sync_supported) |
415 vsync_provider_.reset(new SGIVideoSyncVSyncProvider(window_for_vsync)); | 433 vsync_provider_.reset(new SGIVideoSyncVSyncProvider(window_for_vsync)); |
416 | 434 |
417 return true; | 435 return true; |
418 } | 436 } |
419 | 437 |
420 void NativeViewGLSurfaceGLX::Destroy() { | 438 void NativeViewGLSurfaceGLX::Destroy() { |
439 if (window_) { | |
440 XDestroyWindow(g_display, window_); | |
441 XFlush(g_display); | |
442 } | |
421 } | 443 } |
422 | 444 |
423 bool NativeViewGLSurfaceGLX::Resize(const gfx::Size& size) { | 445 bool NativeViewGLSurfaceGLX::Resize(const gfx::Size& size) { |
424 size_ = size; | 446 size_ = size; |
447 glXWaitGL(); | |
448 XResizeWindow(g_display, window_, size.width(), size.height()); | |
449 glXWaitX(); | |
425 return true; | 450 return true; |
426 } | 451 } |
427 | 452 |
428 bool NativeViewGLSurfaceGLX::IsOffscreen() { | 453 bool NativeViewGLSurfaceGLX::IsOffscreen() { |
429 return false; | 454 return false; |
430 } | 455 } |
431 | 456 |
432 bool NativeViewGLSurfaceGLX::SwapBuffers() { | 457 bool NativeViewGLSurfaceGLX::SwapBuffers() { |
433 TRACE_EVENT2("gpu", "NativeViewGLSurfaceGLX:RealSwapBuffers", | 458 TRACE_EVENT2("gpu", "NativeViewGLSurfaceGLX:RealSwapBuffers", |
434 "width", GetSize().width(), | 459 "width", GetSize().width(), |
(...skipping 25 matching lines...) Expand all Loading... | |
460 // TODO(kbr): this is not a reliable code path. On platforms which | 485 // TODO(kbr): this is not a reliable code path. On platforms which |
461 // support it, we should use glXChooseFBConfig in the browser | 486 // support it, we should use glXChooseFBConfig in the browser |
462 // process to choose the FBConfig and from there the X Visual to | 487 // process to choose the FBConfig and from there the X Visual to |
463 // use when creating the window in the first place. Then we can | 488 // use when creating the window in the first place. Then we can |
464 // pass that FBConfig down rather than attempting to reconstitute | 489 // pass that FBConfig down rather than attempting to reconstitute |
465 // it. | 490 // it. |
466 | 491 |
467 XWindowAttributes attributes; | 492 XWindowAttributes attributes; |
468 if (!XGetWindowAttributes( | 493 if (!XGetWindowAttributes( |
469 g_display, | 494 g_display, |
470 parent_window_, | 495 window_, |
471 &attributes)) { | 496 &attributes)) { |
472 LOG(ERROR) << "XGetWindowAttributes failed for window " << | 497 LOG(ERROR) << "XGetWindowAttributes failed for window " << |
473 parent_window_ << "."; | 498 window_ << "."; |
474 return NULL; | 499 return NULL; |
475 } | 500 } |
476 | 501 |
477 int visual_id = XVisualIDFromVisual(attributes.visual); | 502 int visual_id = XVisualIDFromVisual(attributes.visual); |
478 | 503 |
479 int num_elements = 0; | 504 int num_elements = 0; |
480 scoped_ptr<GLXFBConfig, ScopedPtrXFree> configs( | 505 scoped_ptr<GLXFBConfig, ScopedPtrXFree> configs( |
481 glXGetFBConfigs(g_display, | 506 glXGetFBConfigs(g_display, |
482 DefaultScreen(g_display), | 507 DefaultScreen(g_display), |
483 &num_elements)); | 508 &num_elements)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 glXCopySubBufferMESA(g_display, GetDrawableHandle(), x, y, width, height); | 542 glXCopySubBufferMESA(g_display, GetDrawableHandle(), x, y, width, height); |
518 return true; | 543 return true; |
519 } | 544 } |
520 | 545 |
521 VSyncProvider* NativeViewGLSurfaceGLX::GetVSyncProvider() { | 546 VSyncProvider* NativeViewGLSurfaceGLX::GetVSyncProvider() { |
522 return vsync_provider_.get(); | 547 return vsync_provider_.get(); |
523 } | 548 } |
524 | 549 |
525 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX() | 550 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX() |
526 : parent_window_(0), | 551 : parent_window_(0), |
552 window_(0), | |
527 config_(NULL) { | 553 config_(NULL) { |
528 } | 554 } |
529 | 555 |
530 NativeViewGLSurfaceGLX::~NativeViewGLSurfaceGLX() { | 556 NativeViewGLSurfaceGLX::~NativeViewGLSurfaceGLX() { |
531 Destroy(); | 557 Destroy(); |
532 } | 558 } |
533 | 559 |
534 PbufferGLSurfaceGLX::PbufferGLSurfaceGLX(const gfx::Size& size) | 560 PbufferGLSurfaceGLX::PbufferGLSurfaceGLX(const gfx::Size& size) |
535 : size_(size), | 561 : size_(size), |
536 config_(NULL), | 562 config_(NULL), |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
614 | 640 |
615 void* PbufferGLSurfaceGLX::GetConfig() { | 641 void* PbufferGLSurfaceGLX::GetConfig() { |
616 return config_; | 642 return config_; |
617 } | 643 } |
618 | 644 |
619 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { | 645 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { |
620 Destroy(); | 646 Destroy(); |
621 } | 647 } |
622 | 648 |
623 } // namespace gfx | 649 } // namespace gfx |
OLD | NEW |