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 22 matching lines...) Expand all Loading... |
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 virtual void SetVisible(bool visible) OVERRIDE; | 115 virtual void SetVisible(bool visible) OVERRIDE; |
117 | 116 |
118 protected: | 117 protected: |
119 // ImageTransportSurface implementation: | 118 // ImageTransportSurface implementation: |
120 virtual void OnNewSurfaceACK( | 119 virtual void OnNewSurfaceACK( |
121 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | 120 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; |
122 virtual void OnBuffersSwappedACK() OVERRIDE; | 121 virtual void OnBuffersSwappedACK() OVERRIDE; |
123 virtual void OnResizeViewACK() OVERRIDE; | |
124 virtual void OnResize(gfx::Size size) OVERRIDE; | 122 virtual void OnResize(gfx::Size size) OVERRIDE; |
125 | 123 |
126 private: | 124 private: |
127 virtual ~GLXImageTransportSurface(); | 125 virtual ~GLXImageTransportSurface(); |
128 | 126 |
129 // Tell the browser to release the surface. | 127 // Tell the browser to release the surface. |
130 void ReleaseSurface(); | 128 void ReleaseSurface(); |
131 | 129 |
132 XID dummy_parent_; | 130 XID dummy_parent_; |
133 gfx::Size size_; | 131 gfx::Size size_; |
(...skipping 28 matching lines...) Expand all Loading... |
162 virtual void Destroy() OVERRIDE; | 160 virtual void Destroy() OVERRIDE; |
163 virtual bool IsOffscreen() OVERRIDE; | 161 virtual bool IsOffscreen() OVERRIDE; |
164 virtual bool SwapBuffers() OVERRIDE; | 162 virtual bool SwapBuffers() OVERRIDE; |
165 virtual gfx::Size GetSize() OVERRIDE; | 163 virtual gfx::Size GetSize() OVERRIDE; |
166 | 164 |
167 protected: | 165 protected: |
168 // ImageTransportSurface implementation: | 166 // ImageTransportSurface implementation: |
169 virtual void OnNewSurfaceACK( | 167 virtual void OnNewSurfaceACK( |
170 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | 168 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; |
171 virtual void OnBuffersSwappedACK() OVERRIDE; | 169 virtual void OnBuffersSwappedACK() OVERRIDE; |
172 virtual void OnResizeViewACK() OVERRIDE; | |
173 virtual void OnResize(gfx::Size size) OVERRIDE; | 170 virtual void OnResize(gfx::Size size) OVERRIDE; |
174 | 171 |
175 private: | 172 private: |
176 virtual ~OSMesaImageTransportSurface(); | 173 virtual ~OSMesaImageTransportSurface(); |
177 | 174 |
178 // Tell the browser to release the surface. | 175 // Tell the browser to release the surface. |
179 void ReleaseSurface(); | 176 void ReleaseSurface(); |
180 | 177 |
181 scoped_ptr<TransportDIB> shared_mem_; | 178 scoped_ptr<TransportDIB> shared_mem_; |
182 uint32 shared_id_; | 179 uint32 shared_id_; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 void EGLImageTransportSurface::OnNewSurfaceACK( | 367 void EGLImageTransportSurface::OnNewSurfaceACK( |
371 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { | 368 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { |
372 DCHECK_EQ(back_surface_->pixmap(), surface_id); | 369 DCHECK_EQ(back_surface_->pixmap(), surface_id); |
373 helper_->SetScheduled(true); | 370 helper_->SetScheduled(true); |
374 } | 371 } |
375 | 372 |
376 void EGLImageTransportSurface::OnBuffersSwappedACK() { | 373 void EGLImageTransportSurface::OnBuffersSwappedACK() { |
377 helper_->SetScheduled(true); | 374 helper_->SetScheduled(true); |
378 } | 375 } |
379 | 376 |
380 | |
381 void EGLImageTransportSurface::OnResizeViewACK() { | |
382 NOTREACHED(); | |
383 } | |
384 | |
385 GLXImageTransportSurface::GLXImageTransportSurface( | 377 GLXImageTransportSurface::GLXImageTransportSurface( |
386 GpuChannelManager* manager, | 378 GpuChannelManager* manager, |
387 int32 render_view_id, | 379 int32 render_view_id, |
388 int32 renderer_id, | 380 int32 renderer_id, |
389 int32 command_buffer_id) | 381 int32 command_buffer_id) |
390 : gfx::NativeViewGLSurfaceGLX(), | 382 : gfx::NativeViewGLSurfaceGLX(), |
391 dummy_parent_(0), | 383 dummy_parent_(0), |
392 size_(1, 1), | 384 size_(1, 1), |
393 bound_(false), | 385 bound_(false), |
394 needs_resize_(false), | 386 needs_resize_(false), |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 } | 532 } |
541 | 533 |
542 void GLXImageTransportSurface::OnNewSurfaceACK( | 534 void GLXImageTransportSurface::OnNewSurfaceACK( |
543 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { | 535 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { |
544 } | 536 } |
545 | 537 |
546 void GLXImageTransportSurface::OnBuffersSwappedACK() { | 538 void GLXImageTransportSurface::OnBuffersSwappedACK() { |
547 helper_->SetScheduled(true); | 539 helper_->SetScheduled(true); |
548 } | 540 } |
549 | 541 |
550 void GLXImageTransportSurface::OnResizeViewACK() { | |
551 NOTREACHED(); | |
552 } | |
553 | |
554 OSMesaImageTransportSurface::OSMesaImageTransportSurface( | 542 OSMesaImageTransportSurface::OSMesaImageTransportSurface( |
555 GpuChannelManager* manager, | 543 GpuChannelManager* manager, |
556 int32 render_view_id, | 544 int32 render_view_id, |
557 int32 renderer_id, | 545 int32 renderer_id, |
558 int32 command_buffer_id) | 546 int32 command_buffer_id) |
559 : gfx::GLSurfaceOSMesa(OSMESA_RGBA, gfx::Size(1, 1)), | 547 : gfx::GLSurfaceOSMesa(OSMESA_RGBA, gfx::Size(1, 1)), |
560 size_(gfx::Size(1, 1)) { | 548 size_(gfx::Size(1, 1)) { |
561 helper_.reset(new ImageTransportHelper(this, | 549 helper_.reset(new ImageTransportHelper(this, |
562 manager, | 550 manager, |
563 render_view_id, | 551 render_view_id, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 | 610 |
623 void OSMesaImageTransportSurface::OnNewSurfaceACK( | 611 void OSMesaImageTransportSurface::OnNewSurfaceACK( |
624 uint64 surface_id, TransportDIB::Handle surface_handle) { | 612 uint64 surface_id, TransportDIB::Handle surface_handle) { |
625 shared_id_ = surface_id; | 613 shared_id_ = surface_id; |
626 shared_mem_.reset(TransportDIB::Map(surface_handle)); | 614 shared_mem_.reset(TransportDIB::Map(surface_handle)); |
627 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | 615 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); |
628 | 616 |
629 helper_->SetScheduled(true); | 617 helper_->SetScheduled(true); |
630 } | 618 } |
631 | 619 |
632 void OSMesaImageTransportSurface::OnResizeViewACK() { | |
633 NOTREACHED(); | |
634 } | |
635 | |
636 bool OSMesaImageTransportSurface::SwapBuffers() { | 620 bool OSMesaImageTransportSurface::SwapBuffers() { |
637 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | 621 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); |
638 | 622 |
639 // Copy the OSMesa buffer to the shared memory | 623 // Copy the OSMesa buffer to the shared memory |
640 glFinish(); | 624 glFinish(); |
641 memcpy(shared_mem_->memory(), GetHandle(), size_.GetArea() * 4); | 625 memcpy(shared_mem_->memory(), GetHandle(), size_.GetArea() * 4); |
642 | 626 |
643 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 627 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
644 params.surface_id = shared_id_; | 628 params.surface_id = shared_id_; |
645 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 629 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
(...skipping 11 matching lines...) Expand all Loading... |
657 } | 641 } |
658 | 642 |
659 } // namespace | 643 } // namespace |
660 | 644 |
661 // static | 645 // static |
662 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( | 646 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( |
663 GpuChannelManager* manager, | 647 GpuChannelManager* manager, |
664 int32 render_view_id, | 648 int32 render_view_id, |
665 int32 renderer_id, | 649 int32 renderer_id, |
666 int32 command_buffer_id, | 650 int32 command_buffer_id, |
667 gfx::PluginWindowHandle handle) { | 651 gfx::PluginWindowHandle /* handle */) { |
668 scoped_refptr<gfx::GLSurface> surface; | 652 scoped_refptr<gfx::GLSurface> surface; |
669 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) | |
670 switch (gfx::GetGLImplementation()) { | 653 switch (gfx::GetGLImplementation()) { |
671 case gfx::kGLImplementationDesktopGL: | 654 case gfx::kGLImplementationDesktopGL: |
672 surface = new GLXImageTransportSurface(manager, | 655 surface = new GLXImageTransportSurface(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 case gfx::kGLImplementationEGLGLES2: | 660 case gfx::kGLImplementationEGLGLES2: |
678 surface = new EGLImageTransportSurface(manager, | 661 surface = new EGLImageTransportSurface(manager, |
679 render_view_id, | 662 render_view_id, |
680 renderer_id, | 663 renderer_id, |
681 command_buffer_id); | 664 command_buffer_id); |
682 break; | 665 break; |
683 case gfx::kGLImplementationOSMesaGL: | 666 case gfx::kGLImplementationOSMesaGL: |
684 surface = new OSMesaImageTransportSurface(manager, | 667 surface = new OSMesaImageTransportSurface(manager, |
685 render_view_id, | 668 render_view_id, |
686 renderer_id, | 669 renderer_id, |
687 command_buffer_id); | 670 command_buffer_id); |
688 break; | 671 break; |
689 default: | 672 default: |
690 NOTREACHED(); | 673 NOTREACHED(); |
691 return NULL; | 674 return NULL; |
692 } | 675 } |
693 #else | |
694 surface = gfx::GLSurface::CreateViewGLSurface(false, handle); | |
695 if (!surface.get()) | |
696 return NULL; | |
697 | |
698 surface = new PassThroughImageTransportSurface(manager, | |
699 render_view_id, | |
700 renderer_id, | |
701 command_buffer_id, | |
702 surface.get()); | |
703 #endif | |
704 if (surface->Initialize()) | 676 if (surface->Initialize()) |
705 return surface; | 677 return surface; |
706 else | 678 else |
707 return NULL; | 679 return NULL; |
708 } | 680 } |
709 | 681 |
710 #endif // defined(USE_GPU) | 682 #endif // defined(USE_GPU) |
OLD | NEW |