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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 virtual gfx::Size GetSize() OVERRIDE; | 70 virtual gfx::Size GetSize() OVERRIDE; |
71 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 71 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
72 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; | 72 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; |
73 virtual void SetVisible(bool visible) OVERRIDE; | 73 virtual void SetVisible(bool visible) OVERRIDE; |
74 | 74 |
75 protected: | 75 protected: |
76 // ImageTransportSurface implementation | 76 // ImageTransportSurface implementation |
77 virtual void OnNewSurfaceACK( | 77 virtual void OnNewSurfaceACK( |
78 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | 78 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; |
79 virtual void OnBuffersSwappedACK() OVERRIDE; | 79 virtual void OnBuffersSwappedACK() OVERRIDE; |
80 virtual void OnResizeViewACK() OVERRIDE; | |
81 virtual void OnResize(gfx::Size size) OVERRIDE; | 80 virtual void OnResize(gfx::Size size) OVERRIDE; |
82 | 81 |
83 private: | 82 private: |
84 virtual ~EGLImageTransportSurface() OVERRIDE; | 83 virtual ~EGLImageTransportSurface() OVERRIDE; |
85 void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); | 84 void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); |
86 | 85 |
87 uint32 fbo_id_; | 86 uint32 fbo_id_; |
88 | 87 |
89 scoped_refptr<EGLAcceleratedSurface> back_surface_; | 88 scoped_refptr<EGLAcceleratedSurface> back_surface_; |
90 scoped_refptr<EGLAcceleratedSurface> front_surface_; | 89 scoped_refptr<EGLAcceleratedSurface> front_surface_; |
(...skipping 21 matching lines...) Expand all Loading... |
112 virtual void Destroy() OVERRIDE; | 111 virtual void Destroy() OVERRIDE; |
113 virtual bool SwapBuffers() OVERRIDE; | 112 virtual bool SwapBuffers() OVERRIDE; |
114 virtual gfx::Size GetSize() OVERRIDE; | 113 virtual gfx::Size GetSize() OVERRIDE; |
115 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 114 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
116 | 115 |
117 protected: | 116 protected: |
118 // ImageTransportSurface implementation: | 117 // ImageTransportSurface implementation: |
119 virtual void OnNewSurfaceACK( | 118 virtual void OnNewSurfaceACK( |
120 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | 119 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; |
121 virtual void OnBuffersSwappedACK() OVERRIDE; | 120 virtual void OnBuffersSwappedACK() OVERRIDE; |
122 virtual void OnResizeViewACK() OVERRIDE; | |
123 virtual void OnResize(gfx::Size size) OVERRIDE; | 121 virtual void OnResize(gfx::Size size) OVERRIDE; |
124 | 122 |
125 private: | 123 private: |
126 virtual ~GLXImageTransportSurface(); | 124 virtual ~GLXImageTransportSurface(); |
127 | 125 |
128 // Tell the browser to release the surface. | 126 // Tell the browser to release the surface. |
129 void ReleaseSurface(); | 127 void ReleaseSurface(); |
130 | 128 |
131 XID dummy_parent_; | 129 XID dummy_parent_; |
132 gfx::Size size_; | 130 gfx::Size size_; |
(...skipping 28 matching lines...) Expand all Loading... |
161 virtual void Destroy() OVERRIDE; | 159 virtual void Destroy() OVERRIDE; |
162 virtual bool IsOffscreen() OVERRIDE; | 160 virtual bool IsOffscreen() OVERRIDE; |
163 virtual bool SwapBuffers() OVERRIDE; | 161 virtual bool SwapBuffers() OVERRIDE; |
164 virtual gfx::Size GetSize() OVERRIDE; | 162 virtual gfx::Size GetSize() OVERRIDE; |
165 | 163 |
166 protected: | 164 protected: |
167 // ImageTransportSurface implementation: | 165 // ImageTransportSurface implementation: |
168 virtual void OnNewSurfaceACK( | 166 virtual void OnNewSurfaceACK( |
169 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | 167 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; |
170 virtual void OnBuffersSwappedACK() OVERRIDE; | 168 virtual void OnBuffersSwappedACK() OVERRIDE; |
171 virtual void OnResizeViewACK() OVERRIDE; | |
172 virtual void OnResize(gfx::Size size) OVERRIDE; | 169 virtual void OnResize(gfx::Size size) OVERRIDE; |
173 | 170 |
174 private: | 171 private: |
175 virtual ~OSMesaImageTransportSurface(); | 172 virtual ~OSMesaImageTransportSurface(); |
176 | 173 |
177 // Tell the browser to release the surface. | 174 // Tell the browser to release the surface. |
178 void ReleaseSurface(); | 175 void ReleaseSurface(); |
179 | 176 |
180 scoped_ptr<TransportDIB> shared_mem_; | 177 scoped_ptr<TransportDIB> shared_mem_; |
181 uint32 shared_id_; | 178 uint32 shared_id_; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 void EGLImageTransportSurface::OnNewSurfaceACK( | 366 void EGLImageTransportSurface::OnNewSurfaceACK( |
370 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { | 367 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { |
371 DCHECK_EQ(back_surface_->pixmap(), surface_id); | 368 DCHECK_EQ(back_surface_->pixmap(), surface_id); |
372 helper_->SetScheduled(true); | 369 helper_->SetScheduled(true); |
373 } | 370 } |
374 | 371 |
375 void EGLImageTransportSurface::OnBuffersSwappedACK() { | 372 void EGLImageTransportSurface::OnBuffersSwappedACK() { |
376 helper_->SetScheduled(true); | 373 helper_->SetScheduled(true); |
377 } | 374 } |
378 | 375 |
379 | |
380 void EGLImageTransportSurface::OnResizeViewACK() { | |
381 NOTREACHED(); | |
382 } | |
383 | |
384 GLXImageTransportSurface::GLXImageTransportSurface( | 376 GLXImageTransportSurface::GLXImageTransportSurface( |
385 GpuChannelManager* manager, | 377 GpuChannelManager* manager, |
386 int32 render_view_id, | 378 int32 render_view_id, |
387 int32 renderer_id, | 379 int32 renderer_id, |
388 int32 command_buffer_id) | 380 int32 command_buffer_id) |
389 : gfx::NativeViewGLSurfaceGLX(), | 381 : gfx::NativeViewGLSurfaceGLX(), |
390 dummy_parent_(0), | 382 dummy_parent_(0), |
391 size_(1, 1), | 383 size_(1, 1), |
392 bound_(false), | 384 bound_(false), |
393 needs_resize_(false), | 385 needs_resize_(false), |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 } | 520 } |
529 | 521 |
530 void GLXImageTransportSurface::OnNewSurfaceACK( | 522 void GLXImageTransportSurface::OnNewSurfaceACK( |
531 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { | 523 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { |
532 } | 524 } |
533 | 525 |
534 void GLXImageTransportSurface::OnBuffersSwappedACK() { | 526 void GLXImageTransportSurface::OnBuffersSwappedACK() { |
535 helper_->SetScheduled(true); | 527 helper_->SetScheduled(true); |
536 } | 528 } |
537 | 529 |
538 void GLXImageTransportSurface::OnResizeViewACK() { | |
539 NOTREACHED(); | |
540 } | |
541 | |
542 OSMesaImageTransportSurface::OSMesaImageTransportSurface( | 530 OSMesaImageTransportSurface::OSMesaImageTransportSurface( |
543 GpuChannelManager* manager, | 531 GpuChannelManager* manager, |
544 int32 render_view_id, | 532 int32 render_view_id, |
545 int32 renderer_id, | 533 int32 renderer_id, |
546 int32 command_buffer_id) | 534 int32 command_buffer_id) |
547 : gfx::GLSurfaceOSMesa(OSMESA_RGBA, gfx::Size(1, 1)), | 535 : gfx::GLSurfaceOSMesa(OSMESA_RGBA, gfx::Size(1, 1)), |
548 size_(gfx::Size(1, 1)) { | 536 size_(gfx::Size(1, 1)) { |
549 helper_.reset(new ImageTransportHelper(this, | 537 helper_.reset(new ImageTransportHelper(this, |
550 manager, | 538 manager, |
551 render_view_id, | 539 render_view_id, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 | 598 |
611 void OSMesaImageTransportSurface::OnNewSurfaceACK( | 599 void OSMesaImageTransportSurface::OnNewSurfaceACK( |
612 uint64 surface_id, TransportDIB::Handle surface_handle) { | 600 uint64 surface_id, TransportDIB::Handle surface_handle) { |
613 shared_id_ = surface_id; | 601 shared_id_ = surface_id; |
614 shared_mem_.reset(TransportDIB::Map(surface_handle)); | 602 shared_mem_.reset(TransportDIB::Map(surface_handle)); |
615 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | 603 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); |
616 | 604 |
617 helper_->SetScheduled(true); | 605 helper_->SetScheduled(true); |
618 } | 606 } |
619 | 607 |
620 void OSMesaImageTransportSurface::OnResizeViewACK() { | |
621 NOTREACHED(); | |
622 } | |
623 | |
624 bool OSMesaImageTransportSurface::SwapBuffers() { | 608 bool OSMesaImageTransportSurface::SwapBuffers() { |
625 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | 609 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); |
626 | 610 |
627 // Copy the OSMesa buffer to the shared memory | 611 // Copy the OSMesa buffer to the shared memory |
628 glFinish(); | 612 glFinish(); |
629 memcpy(shared_mem_->memory(), GetHandle(), size_.GetArea() * 4); | 613 memcpy(shared_mem_->memory(), GetHandle(), size_.GetArea() * 4); |
630 | 614 |
631 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 615 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
632 params.surface_id = shared_id_; | 616 params.surface_id = shared_id_; |
633 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 617 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
(...skipping 11 matching lines...) Expand all Loading... |
645 } | 629 } |
646 | 630 |
647 } // namespace | 631 } // namespace |
648 | 632 |
649 // static | 633 // static |
650 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( | 634 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( |
651 GpuChannelManager* manager, | 635 GpuChannelManager* manager, |
652 int32 render_view_id, | 636 int32 render_view_id, |
653 int32 renderer_id, | 637 int32 renderer_id, |
654 int32 command_buffer_id, | 638 int32 command_buffer_id, |
655 gfx::PluginWindowHandle handle) { | 639 gfx::PluginWindowHandle /* handle */) { |
656 scoped_refptr<gfx::GLSurface> surface; | 640 scoped_refptr<gfx::GLSurface> surface; |
657 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) | |
658 switch (gfx::GetGLImplementation()) { | 641 switch (gfx::GetGLImplementation()) { |
659 case gfx::kGLImplementationDesktopGL: | 642 case gfx::kGLImplementationDesktopGL: |
660 surface = new GLXImageTransportSurface(manager, | 643 surface = new GLXImageTransportSurface(manager, |
661 render_view_id, | 644 render_view_id, |
662 renderer_id, | 645 renderer_id, |
663 command_buffer_id); | 646 command_buffer_id); |
664 break; | 647 break; |
665 case gfx::kGLImplementationEGLGLES2: | 648 case gfx::kGLImplementationEGLGLES2: |
666 surface = new EGLImageTransportSurface(manager, | 649 surface = new EGLImageTransportSurface(manager, |
667 render_view_id, | 650 render_view_id, |
668 renderer_id, | 651 renderer_id, |
669 command_buffer_id); | 652 command_buffer_id); |
670 break; | 653 break; |
671 case gfx::kGLImplementationOSMesaGL: | 654 case gfx::kGLImplementationOSMesaGL: |
672 surface = new OSMesaImageTransportSurface(manager, | 655 surface = new OSMesaImageTransportSurface(manager, |
673 render_view_id, | 656 render_view_id, |
674 renderer_id, | 657 renderer_id, |
675 command_buffer_id); | 658 command_buffer_id); |
676 break; | 659 break; |
677 default: | 660 default: |
678 NOTREACHED(); | 661 NOTREACHED(); |
679 return NULL; | 662 return NULL; |
680 } | 663 } |
681 #else | |
682 surface = gfx::GLSurface::CreateViewGLSurface(false, handle); | |
683 if (!surface.get()) | |
684 return NULL; | |
685 | |
686 surface = new PassThroughImageTransportSurface(manager, | |
687 render_view_id, | |
688 renderer_id, | |
689 command_buffer_id, | |
690 surface.get()); | |
691 #endif | |
692 if (surface->Initialize()) | 664 if (surface->Initialize()) |
693 return surface; | 665 return surface; |
694 else | 666 else |
695 return NULL; | 667 return NULL; |
696 } | 668 } |
697 | 669 |
698 #endif // defined(USE_GPU) | 670 #endif // defined(USE_GPU) |
OLD | NEW |