| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #if defined(ENABLE_GPU) | 5 #if defined(ENABLE_GPU) |
| 6 | 6 |
| 7 #include "content/common/gpu/image_transport_surface.h" | 7 #include "content/common/gpu/image_transport_surface.h" |
| 8 | 8 |
| 9 // This conflicts with the defines in Xlib.h and must come first. | 9 // This conflicts with the defines in Xlib.h and must come first. |
| 10 #include "content/common/gpu/gpu_messages.h" | 10 #include "content/common/gpu/gpu_messages.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 virtual gfx::Size GetSize() OVERRIDE; | 69 virtual gfx::Size GetSize() OVERRIDE; |
| 70 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 70 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
| 71 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; | 71 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; |
| 72 virtual void SetVisible(bool visible) OVERRIDE; | 72 virtual void SetVisible(bool visible) OVERRIDE; |
| 73 | 73 |
| 74 protected: | 74 protected: |
| 75 // ImageTransportSurface implementation | 75 // ImageTransportSurface implementation |
| 76 virtual void OnNewSurfaceACK( | 76 virtual void OnNewSurfaceACK( |
| 77 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | 77 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; |
| 78 virtual void OnBuffersSwappedACK() OVERRIDE; | 78 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 79 virtual void OnResizeViewACK() OVERRIDE; |
| 79 virtual void OnResize(gfx::Size size) OVERRIDE; | 80 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 80 | 81 |
| 81 private: | 82 private: |
| 82 virtual ~EGLImageTransportSurface() OVERRIDE; | 83 virtual ~EGLImageTransportSurface() OVERRIDE; |
| 83 void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); | 84 void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); |
| 84 | 85 |
| 85 uint32 fbo_id_; | 86 uint32 fbo_id_; |
| 86 | 87 |
| 87 scoped_refptr<EGLAcceleratedSurface> back_surface_; | 88 scoped_refptr<EGLAcceleratedSurface> back_surface_; |
| 88 scoped_refptr<EGLAcceleratedSurface> front_surface_; | 89 scoped_refptr<EGLAcceleratedSurface> front_surface_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 110 virtual void Destroy() OVERRIDE; | 111 virtual void Destroy() OVERRIDE; |
| 111 virtual bool SwapBuffers() OVERRIDE; | 112 virtual bool SwapBuffers() OVERRIDE; |
| 112 virtual gfx::Size GetSize() OVERRIDE; | 113 virtual gfx::Size GetSize() OVERRIDE; |
| 113 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 114 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
| 114 | 115 |
| 115 protected: | 116 protected: |
| 116 // ImageTransportSurface implementation: | 117 // ImageTransportSurface implementation: |
| 117 virtual void OnNewSurfaceACK( | 118 virtual void OnNewSurfaceACK( |
| 118 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | 119 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; |
| 119 virtual void OnBuffersSwappedACK() OVERRIDE; | 120 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 121 virtual void OnResizeViewACK() OVERRIDE; |
| 120 virtual void OnResize(gfx::Size size) OVERRIDE; | 122 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 121 | 123 |
| 122 private: | 124 private: |
| 123 virtual ~GLXImageTransportSurface(); | 125 virtual ~GLXImageTransportSurface(); |
| 124 | 126 |
| 125 // Tell the browser to release the surface. | 127 // Tell the browser to release the surface. |
| 126 void ReleaseSurface(); | 128 void ReleaseSurface(); |
| 127 | 129 |
| 128 XID dummy_parent_; | 130 XID dummy_parent_; |
| 129 gfx::Size size_; | 131 gfx::Size size_; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 155 virtual void Destroy() OVERRIDE; | 157 virtual void Destroy() OVERRIDE; |
| 156 virtual bool IsOffscreen() OVERRIDE; | 158 virtual bool IsOffscreen() OVERRIDE; |
| 157 virtual bool SwapBuffers() OVERRIDE; | 159 virtual bool SwapBuffers() OVERRIDE; |
| 158 virtual gfx::Size GetSize() OVERRIDE; | 160 virtual gfx::Size GetSize() OVERRIDE; |
| 159 | 161 |
| 160 protected: | 162 protected: |
| 161 // ImageTransportSurface implementation: | 163 // ImageTransportSurface implementation: |
| 162 virtual void OnNewSurfaceACK( | 164 virtual void OnNewSurfaceACK( |
| 163 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | 165 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; |
| 164 virtual void OnBuffersSwappedACK() OVERRIDE; | 166 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 167 virtual void OnResizeViewACK() OVERRIDE; |
| 165 virtual void OnResize(gfx::Size size) OVERRIDE; | 168 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 166 | 169 |
| 167 private: | 170 private: |
| 168 virtual ~OSMesaImageTransportSurface(); | 171 virtual ~OSMesaImageTransportSurface(); |
| 169 | 172 |
| 170 // Tell the browser to release the surface. | 173 // Tell the browser to release the surface. |
| 171 void ReleaseSurface(); | 174 void ReleaseSurface(); |
| 172 | 175 |
| 173 scoped_ptr<TransportDIB> shared_mem_; | 176 scoped_ptr<TransportDIB> shared_mem_; |
| 174 uint32 shared_id_; | 177 uint32 shared_id_; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 void EGLImageTransportSurface::OnNewSurfaceACK( | 365 void EGLImageTransportSurface::OnNewSurfaceACK( |
| 363 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { | 366 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { |
| 364 DCHECK_EQ(back_surface_->pixmap(), surface_id); | 367 DCHECK_EQ(back_surface_->pixmap(), surface_id); |
| 365 helper_->SetScheduled(true); | 368 helper_->SetScheduled(true); |
| 366 } | 369 } |
| 367 | 370 |
| 368 void EGLImageTransportSurface::OnBuffersSwappedACK() { | 371 void EGLImageTransportSurface::OnBuffersSwappedACK() { |
| 369 helper_->SetScheduled(true); | 372 helper_->SetScheduled(true); |
| 370 } | 373 } |
| 371 | 374 |
| 375 |
| 376 void EGLImageTransportSurface::OnResizeViewACK() { |
| 377 } |
| 378 |
| 372 GLXImageTransportSurface::GLXImageTransportSurface( | 379 GLXImageTransportSurface::GLXImageTransportSurface( |
| 373 GpuChannelManager* manager, | 380 GpuChannelManager* manager, |
| 374 int32 render_view_id, | 381 int32 render_view_id, |
| 375 int32 renderer_id, | 382 int32 renderer_id, |
| 376 int32 command_buffer_id) | 383 int32 command_buffer_id) |
| 377 : gfx::NativeViewGLSurfaceGLX(), | 384 : gfx::NativeViewGLSurfaceGLX(), |
| 378 dummy_parent_(0), | 385 dummy_parent_(0), |
| 379 size_(1, 1), | 386 size_(1, 1), |
| 380 bound_(false), | 387 bound_(false), |
| 381 made_current_(false) { | 388 made_current_(false) { |
| 382 helper_.reset(new ImageTransportHelper(this, | 389 helper_.reset(new ImageTransportHelper(this, |
| 383 manager, | 390 manager, |
| 384 render_view_id, | 391 render_view_id, |
| 385 renderer_id, | 392 renderer_id, |
| 386 command_buffer_id, | 393 command_buffer_id, |
| 387 gfx::kNullPluginWindow)); | 394 gfx::kNullPluginWindow)); |
| 388 } | 395 } |
| 389 | 396 |
| 390 GLXImageTransportSurface::~GLXImageTransportSurface() { | 397 GLXImageTransportSurface::~GLXImageTransportSurface() { |
| 391 Destroy(); | 398 Destroy(); |
| 392 } | 399 } |
| 393 | 400 |
| 394 bool GLXImageTransportSurface::Initialize() { | 401 bool GLXImageTransportSurface::Initialize() { |
| 395 // Create a dummy window to host the real window. | 402 // Create a dummy window to host the real window. |
| 396 Display* dpy = gfx::GLSurfaceGLX::GetDisplay(); | 403 Display* dpy = static_cast<Display*>(GetDisplay()); |
| 397 XSetWindowAttributes swa; | 404 XSetWindowAttributes swa; |
| 398 swa.event_mask = StructureNotifyMask; | 405 swa.event_mask = StructureNotifyMask; |
| 399 swa.override_redirect = True; | 406 swa.override_redirect = True; |
| 400 dummy_parent_ = XCreateWindow( | 407 dummy_parent_ = XCreateWindow( |
| 401 dpy, | 408 dpy, |
| 402 RootWindow(dpy, DefaultScreen(dpy)), // parent | 409 RootWindow(dpy, DefaultScreen(dpy)), // parent |
| 403 -100, -100, 1, 1, | 410 -100, -100, 1, 1, |
| 404 0, // border width | 411 0, // border width |
| 405 CopyFromParent, // depth | 412 CopyFromParent, // depth |
| 406 InputOutput, | 413 InputOutput, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 432 if (!helper_->Initialize()) | 439 if (!helper_->Initialize()) |
| 433 return false; | 440 return false; |
| 434 return gfx::NativeViewGLSurfaceGLX::Initialize(); | 441 return gfx::NativeViewGLSurfaceGLX::Initialize(); |
| 435 } | 442 } |
| 436 | 443 |
| 437 void GLXImageTransportSurface::Destroy() { | 444 void GLXImageTransportSurface::Destroy() { |
| 438 if (bound_) | 445 if (bound_) |
| 439 ReleaseSurface(); | 446 ReleaseSurface(); |
| 440 | 447 |
| 441 if (window_) { | 448 if (window_) { |
| 442 Display* dpy = gfx::GLSurfaceGLX::GetDisplay(); | 449 Display* dpy = static_cast<Display*>(GetDisplay()); |
| 443 XDestroyWindow(dpy, window_); | 450 XDestroyWindow(dpy, window_); |
| 444 XDestroyWindow(dpy, dummy_parent_); | 451 XDestroyWindow(dpy, dummy_parent_); |
| 445 } | 452 } |
| 446 | 453 |
| 447 helper_->Destroy(); | 454 helper_->Destroy(); |
| 448 gfx::NativeViewGLSurfaceGLX::Destroy(); | 455 gfx::NativeViewGLSurfaceGLX::Destroy(); |
| 449 } | 456 } |
| 450 | 457 |
| 451 void GLXImageTransportSurface::ReleaseSurface() { | 458 void GLXImageTransportSurface::ReleaseSurface() { |
| 452 DCHECK(bound_); | 459 DCHECK(bound_); |
| 453 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 460 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
| 454 params.identifier = window_; | 461 params.identifier = window_; |
| 455 helper_->SendAcceleratedSurfaceRelease(params); | 462 helper_->SendAcceleratedSurfaceRelease(params); |
| 456 } | 463 } |
| 457 | 464 |
| 458 void GLXImageTransportSurface::OnResize(gfx::Size size) { | 465 void GLXImageTransportSurface::OnResize(gfx::Size size) { |
| 459 size_ = size; | 466 size_ = size; |
| 460 if (bound_) { | 467 if (bound_) { |
| 461 ReleaseSurface(); | 468 ReleaseSurface(); |
| 462 bound_ = false; | 469 bound_ = false; |
| 463 } | 470 } |
| 464 | 471 |
| 465 Display* dpy = gfx::GLSurfaceGLX::GetDisplay(); | 472 Display* dpy = static_cast<Display*>(GetDisplay()); |
| 466 XResizeWindow(dpy, window_, size_.width(), size_.height()); | 473 XResizeWindow(dpy, window_, size_.width(), size_.height()); |
| 467 XFlush(dpy); | 474 XFlush(dpy); |
| 468 | 475 |
| 469 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 476 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
| 470 params.width = size_.width(); | 477 params.width = size_.width(); |
| 471 params.height = size_.height(); | 478 params.height = size_.height(); |
| 472 params.surface_id = window_; | 479 params.surface_id = window_; |
| 473 helper_->SendAcceleratedSurfaceNew(params); | 480 helper_->SendAcceleratedSurfaceNew(params); |
| 474 | 481 |
| 475 helper_->SetScheduled(false); | 482 helper_->SetScheduled(false); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 489 | 496 |
| 490 gfx::Size GLXImageTransportSurface::GetSize() { | 497 gfx::Size GLXImageTransportSurface::GetSize() { |
| 491 return size_; | 498 return size_; |
| 492 } | 499 } |
| 493 | 500 |
| 494 bool GLXImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { | 501 bool GLXImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { |
| 495 if (made_current_) | 502 if (made_current_) |
| 496 return true; | 503 return true; |
| 497 | 504 |
| 498 // Check for driver support. | 505 // Check for driver support. |
| 499 Display* dpy = gfx::GLSurfaceGLX::GetDisplay(); | 506 Display* dpy = static_cast<Display*>(GetDisplay()); |
| 500 int event_base, error_base; | 507 int event_base, error_base; |
| 501 if (XCompositeQueryExtension(dpy, &event_base, &error_base)) { | 508 if (XCompositeQueryExtension(dpy, &event_base, &error_base)) { |
| 502 int major = 0, minor = 2; | 509 int major = 0, minor = 2; |
| 503 XCompositeQueryVersion(dpy, &major, &minor); | 510 XCompositeQueryVersion(dpy, &major, &minor); |
| 504 if (major == 0 && minor < 2) { | 511 if (major == 0 && minor < 2) { |
| 505 LOG(ERROR) << "Pixmap from window not supported."; | 512 LOG(ERROR) << "Pixmap from window not supported."; |
| 506 return false; | 513 return false; |
| 507 } | 514 } |
| 508 } | 515 } |
| 509 | 516 |
| 510 context->SetSwapInterval(0); | 517 context->SetSwapInterval(0); |
| 511 | 518 |
| 512 made_current_ = true; | 519 made_current_ = true; |
| 513 return true; | 520 return true; |
| 514 } | 521 } |
| 515 | 522 |
| 516 void GLXImageTransportSurface::OnNewSurfaceACK( | 523 void GLXImageTransportSurface::OnNewSurfaceACK( |
| 517 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { | 524 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { |
| 518 DCHECK(!bound_); | 525 DCHECK(!bound_); |
| 519 bound_ = true; | 526 bound_ = true; |
| 520 helper_->SetScheduled(true); | 527 helper_->SetScheduled(true); |
| 521 } | 528 } |
| 522 | 529 |
| 523 void GLXImageTransportSurface::OnBuffersSwappedACK() { | 530 void GLXImageTransportSurface::OnBuffersSwappedACK() { |
| 524 helper_->SetScheduled(true); | 531 helper_->SetScheduled(true); |
| 525 } | 532 } |
| 526 | 533 |
| 534 void GLXImageTransportSurface::OnResizeViewACK() { |
| 535 } |
| 536 |
| 527 OSMesaImageTransportSurface::OSMesaImageTransportSurface( | 537 OSMesaImageTransportSurface::OSMesaImageTransportSurface( |
| 528 GpuChannelManager* manager, | 538 GpuChannelManager* manager, |
| 529 int32 render_view_id, | 539 int32 render_view_id, |
| 530 int32 renderer_id, | 540 int32 renderer_id, |
| 531 int32 command_buffer_id) | 541 int32 command_buffer_id) |
| 532 : gfx::GLSurfaceOSMesa(OSMESA_RGBA, gfx::Size(1, 1)), | 542 : gfx::GLSurfaceOSMesa(OSMESA_RGBA, gfx::Size(1, 1)), |
| 533 size_(gfx::Size(1, 1)) { | 543 size_(gfx::Size(1, 1)) { |
| 534 helper_.reset(new ImageTransportHelper(this, | 544 helper_.reset(new ImageTransportHelper(this, |
| 535 manager, | 545 manager, |
| 536 render_view_id, | 546 render_view_id, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 | 605 |
| 596 void OSMesaImageTransportSurface::OnNewSurfaceACK( | 606 void OSMesaImageTransportSurface::OnNewSurfaceACK( |
| 597 uint64 surface_id, TransportDIB::Handle surface_handle) { | 607 uint64 surface_id, TransportDIB::Handle surface_handle) { |
| 598 shared_id_ = surface_id; | 608 shared_id_ = surface_id; |
| 599 shared_mem_.reset(TransportDIB::Map(surface_handle)); | 609 shared_mem_.reset(TransportDIB::Map(surface_handle)); |
| 600 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | 610 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); |
| 601 | 611 |
| 602 helper_->SetScheduled(true); | 612 helper_->SetScheduled(true); |
| 603 } | 613 } |
| 604 | 614 |
| 615 void OSMesaImageTransportSurface::OnResizeViewACK() { |
| 616 } |
| 617 |
| 605 bool OSMesaImageTransportSurface::SwapBuffers() { | 618 bool OSMesaImageTransportSurface::SwapBuffers() { |
| 606 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | 619 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); |
| 607 | 620 |
| 608 // Copy the OSMesa buffer to the shared memory | 621 // Copy the OSMesa buffer to the shared memory |
| 609 glFinish(); | 622 glFinish(); |
| 610 memcpy(shared_mem_->memory(), GetHandle(), size_.GetArea() * 4); | 623 memcpy(shared_mem_->memory(), GetHandle(), size_.GetArea() * 4); |
| 611 | 624 |
| 612 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 625 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| 613 params.surface_id = shared_id_; | 626 params.surface_id = shared_id_; |
| 614 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 627 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 626 } | 639 } |
| 627 | 640 |
| 628 } // namespace | 641 } // namespace |
| 629 | 642 |
| 630 // static | 643 // static |
| 631 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( | 644 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( |
| 632 GpuChannelManager* manager, | 645 GpuChannelManager* manager, |
| 633 int32 render_view_id, | 646 int32 render_view_id, |
| 634 int32 renderer_id, | 647 int32 renderer_id, |
| 635 int32 command_buffer_id, | 648 int32 command_buffer_id, |
| 636 gfx::PluginWindowHandle /* handle */) { | 649 gfx::PluginWindowHandle handle) { |
| 637 scoped_refptr<gfx::GLSurface> surface; | 650 scoped_refptr<gfx::GLSurface> surface; |
| 651 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) |
| 638 switch (gfx::GetGLImplementation()) { | 652 switch (gfx::GetGLImplementation()) { |
| 639 case gfx::kGLImplementationDesktopGL: | 653 case gfx::kGLImplementationDesktopGL: |
| 640 surface = new GLXImageTransportSurface(manager, | 654 surface = new GLXImageTransportSurface(manager, |
| 641 render_view_id, | 655 render_view_id, |
| 642 renderer_id, | 656 renderer_id, |
| 643 command_buffer_id); | 657 command_buffer_id); |
| 644 break; | 658 break; |
| 645 case gfx::kGLImplementationEGLGLES2: | 659 case gfx::kGLImplementationEGLGLES2: |
| 646 surface = new EGLImageTransportSurface(manager, | 660 surface = new EGLImageTransportSurface(manager, |
| 647 render_view_id, | 661 render_view_id, |
| 648 renderer_id, | 662 renderer_id, |
| 649 command_buffer_id); | 663 command_buffer_id); |
| 650 break; | 664 break; |
| 651 case gfx::kGLImplementationOSMesaGL: | 665 case gfx::kGLImplementationOSMesaGL: |
| 652 surface = new OSMesaImageTransportSurface(manager, | 666 surface = new OSMesaImageTransportSurface(manager, |
| 653 render_view_id, | 667 render_view_id, |
| 654 renderer_id, | 668 renderer_id, |
| 655 command_buffer_id); | 669 command_buffer_id); |
| 656 break; | 670 break; |
| 657 default: | 671 default: |
| 658 NOTREACHED(); | 672 NOTREACHED(); |
| 659 return NULL; | 673 return NULL; |
| 660 } | 674 } |
| 675 #else |
| 676 surface = gfx::GLSurface::CreateViewGLSurface(false, handle); |
| 677 if (!surface.get()) |
| 678 return NULL; |
| 679 |
| 680 surface = new PassThroughImageTransportSurface(manager, |
| 681 render_view_id, |
| 682 renderer_id, |
| 683 command_buffer_id, |
| 684 surface.get()); |
| 685 #endif |
| 661 if (surface->Initialize()) | 686 if (surface->Initialize()) |
| 662 return surface; | 687 return surface; |
| 663 else | 688 else |
| 664 return NULL; | 689 return NULL; |
| 665 } | 690 } |
| 666 | 691 |
| 667 #endif // defined(USE_GPU) | 692 #endif // defined(USE_GPU) |
| OLD | NEW |