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_linux.h" | 7 #include "content/common/gpu/image_transport_surface_linux.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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 virtual gfx::Size GetSize() OVERRIDE; | 49 virtual gfx::Size GetSize() OVERRIDE; |
50 virtual void OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 50 virtual void OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
51 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; | 51 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; |
52 | 52 |
53 protected: | 53 protected: |
54 // ImageTransportSurface implementation | 54 // ImageTransportSurface implementation |
55 virtual void OnNewSurfaceACK( | 55 virtual void OnNewSurfaceACK( |
56 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | 56 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; |
57 virtual void OnBuffersSwappedACK() OVERRIDE; | 57 virtual void OnBuffersSwappedACK() OVERRIDE; |
58 virtual void OnResize(gfx::Size size) OVERRIDE; | 58 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 59 virtual void OnSurfaceVisible(bool visible) OVERRIDE; |
59 | 60 |
60 private: | 61 private: |
61 virtual ~EGLImageTransportSurface() OVERRIDE; | 62 virtual ~EGLImageTransportSurface() OVERRIDE; |
62 void ReleaseSurface(scoped_refptr<AcceleratedSurface>* surface); | 63 void ReleaseSurface(scoped_refptr<AcceleratedSurface>* surface); |
63 | 64 |
64 uint32 fbo_id_; | 65 uint32 fbo_id_; |
65 | 66 |
66 scoped_refptr<AcceleratedSurface> back_surface_; | 67 scoped_refptr<AcceleratedSurface> back_surface_; |
67 scoped_refptr<AcceleratedSurface> front_surface_; | 68 scoped_refptr<AcceleratedSurface> front_surface_; |
68 | 69 |
(...skipping 18 matching lines...) Expand all Loading... |
87 virtual bool SwapBuffers() OVERRIDE; | 88 virtual bool SwapBuffers() OVERRIDE; |
88 virtual gfx::Size GetSize() OVERRIDE; | 89 virtual gfx::Size GetSize() OVERRIDE; |
89 virtual void OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 90 virtual void OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
90 | 91 |
91 protected: | 92 protected: |
92 // ImageTransportSurface implementation: | 93 // ImageTransportSurface implementation: |
93 virtual void OnNewSurfaceACK( | 94 virtual void OnNewSurfaceACK( |
94 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | 95 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; |
95 virtual void OnBuffersSwappedACK() OVERRIDE; | 96 virtual void OnBuffersSwappedACK() OVERRIDE; |
96 virtual void OnResize(gfx::Size size) OVERRIDE; | 97 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 98 virtual void OnSurfaceVisible(bool visible) OVERRIDE; |
97 | 99 |
98 private: | 100 private: |
99 virtual ~GLXImageTransportSurface(); | 101 virtual ~GLXImageTransportSurface(); |
100 | 102 |
101 // Tell the browser to release the surface. | 103 // Tell the browser to release the surface. |
102 void ReleaseSurface(); | 104 void ReleaseSurface(); |
103 | 105 |
104 XID dummy_parent_; | 106 XID dummy_parent_; |
105 gfx::Size size_; | 107 gfx::Size size_; |
106 | 108 |
(...skipping 26 matching lines...) Expand all Loading... |
133 virtual bool SwapBuffers() OVERRIDE; | 135 virtual bool SwapBuffers() OVERRIDE; |
134 virtual gfx::Size GetSize() OVERRIDE; | 136 virtual gfx::Size GetSize() OVERRIDE; |
135 virtual void* GetHandle() OVERRIDE; | 137 virtual void* GetHandle() OVERRIDE; |
136 | 138 |
137 protected: | 139 protected: |
138 // ImageTransportSurface implementation: | 140 // ImageTransportSurface implementation: |
139 virtual void OnNewSurfaceACK( | 141 virtual void OnNewSurfaceACK( |
140 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | 142 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; |
141 virtual void OnBuffersSwappedACK() OVERRIDE; | 143 virtual void OnBuffersSwappedACK() OVERRIDE; |
142 virtual void OnResize(gfx::Size size) OVERRIDE; | 144 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 145 virtual void OnSurfaceVisible(bool visible) OVERRIDE; |
143 | 146 |
144 private: | 147 private: |
145 virtual ~OSMesaImageTransportSurface(); | 148 virtual ~OSMesaImageTransportSurface(); |
146 | 149 |
147 // Tell the browser to release the surface. | 150 // Tell the browser to release the surface. |
148 void ReleaseSurface(); | 151 void ReleaseSurface(); |
149 | 152 |
150 scoped_ptr<TransportDIB> shared_mem_; | 153 scoped_ptr<TransportDIB> shared_mem_; |
151 uint32 shared_id_; | 154 uint32 shared_id_; |
152 gfx::Size size_; | 155 gfx::Size size_; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 241 |
239 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 242 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
240 params.width = size.width(); | 243 params.width = size.width(); |
241 params.height = size.height(); | 244 params.height = size.height(); |
242 params.identifier = back_surface_->pixmap(); | 245 params.identifier = back_surface_->pixmap(); |
243 helper_->SendAcceleratedSurfaceNew(params); | 246 helper_->SendAcceleratedSurfaceNew(params); |
244 | 247 |
245 helper_->SetScheduled(false); | 248 helper_->SetScheduled(false); |
246 } | 249 } |
247 | 250 |
| 251 void EGLImageTransportSurface::OnSurfaceVisible(bool visible) { |
| 252 if (!visible && back_surface_.get() && front_surface_.get()) { |
| 253 printf("[ - ] Releasing a Surface!\n\n"); |
| 254 ReleaseSurface(&back_surface_); |
| 255 } else if (visible && !back_surface_.get() && front_surface_.get()) { |
| 256 printf("[ + ] Recreating a Surface!\n\n"); |
| 257 OnResize(front_surface_->size()); |
| 258 } else { |
| 259 printf("[ . ] Not touching the surface. visible:%s!\n\n", |
| 260 visible ? "true" : "false"); |
| 261 } |
| 262 fflush(stdout); |
| 263 } |
| 264 |
248 bool EGLImageTransportSurface::SwapBuffers() { | 265 bool EGLImageTransportSurface::SwapBuffers() { |
249 front_surface_.swap(back_surface_); | 266 front_surface_.swap(back_surface_); |
250 DCHECK_NE(front_surface_.get(), static_cast<AcceleratedSurface*>(NULL)); | 267 DCHECK_NE(front_surface_.get(), static_cast<AcceleratedSurface*>(NULL)); |
251 glFlush(); | 268 glFlush(); |
252 | 269 |
253 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 270 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
254 params.surface_id = front_surface_->pixmap(); | 271 params.surface_id = front_surface_->pixmap(); |
255 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 272 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
256 | 273 |
257 gfx::Size expected_size = front_surface_->size(); | 274 gfx::Size expected_size = front_surface_->size(); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 397 |
381 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 398 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
382 params.width = size_.width(); | 399 params.width = size_.width(); |
383 params.height = size_.height(); | 400 params.height = size_.height(); |
384 params.identifier = window_; | 401 params.identifier = window_; |
385 helper_->SendAcceleratedSurfaceNew(params); | 402 helper_->SendAcceleratedSurfaceNew(params); |
386 | 403 |
387 helper_->SetScheduled(false); | 404 helper_->SetScheduled(false); |
388 } | 405 } |
389 | 406 |
| 407 void GLXImageTransportSurface::OnSurfaceVisible(bool visible) { |
| 408 NOTIMPLEMENTED(); |
| 409 } |
| 410 |
390 bool GLXImageTransportSurface::SwapBuffers() { | 411 bool GLXImageTransportSurface::SwapBuffers() { |
391 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); | 412 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); |
392 glFlush(); | 413 glFlush(); |
393 | 414 |
394 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 415 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
395 params.surface_id = window_; | 416 params.surface_id = window_; |
396 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 417 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
397 | 418 |
398 helper_->SetScheduled(false); | 419 helper_->SetScheduled(false); |
399 return true; | 420 return true; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 | 504 |
484 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 505 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
485 params.width = size_.width(); | 506 params.width = size_.width(); |
486 params.height = size_.height(); | 507 params.height = size_.height(); |
487 params.identifier = 0; // id comes from the browser with the shared mem | 508 params.identifier = 0; // id comes from the browser with the shared mem |
488 helper_->SendAcceleratedSurfaceNew(params); | 509 helper_->SendAcceleratedSurfaceNew(params); |
489 | 510 |
490 helper_->SetScheduled(false); | 511 helper_->SetScheduled(false); |
491 } | 512 } |
492 | 513 |
| 514 void OSMesaImageTransportSurface::OnSurfaceVisible(bool visible) { |
| 515 NOTIMPLEMENTED(); |
| 516 } |
| 517 |
493 void OSMesaImageTransportSurface::OnNewSurfaceACK( | 518 void OSMesaImageTransportSurface::OnNewSurfaceACK( |
494 uint64 surface_id, TransportDIB::Handle surface_handle) { | 519 uint64 surface_id, TransportDIB::Handle surface_handle) { |
495 shared_id_ = surface_id; | 520 shared_id_ = surface_id; |
496 shared_mem_.reset(TransportDIB::Map(surface_handle)); | 521 shared_mem_.reset(TransportDIB::Map(surface_handle)); |
497 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | 522 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); |
498 | 523 |
499 // When we get the shared memory buffer back we can use that for OSMesa to | 524 // When we get the shared memory buffer back we can use that for OSMesa to |
500 // write in, so we give it to OSMesa. | 525 // write in, so we give it to OSMesa. |
501 helper_->MakeCurrent(); | 526 helper_->MakeCurrent(); |
502 | 527 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 } | 614 } |
590 | 615 |
591 bool ImageTransportHelper::Initialize() { | 616 bool ImageTransportHelper::Initialize() { |
592 gpu::gles2::GLES2Decoder* decoder = Decoder(); | 617 gpu::gles2::GLES2Decoder* decoder = Decoder(); |
593 if (!decoder) | 618 if (!decoder) |
594 return false; | 619 return false; |
595 | 620 |
596 decoder->SetResizeCallback( | 621 decoder->SetResizeCallback( |
597 NewCallback(this, &ImageTransportHelper::Resize)); | 622 NewCallback(this, &ImageTransportHelper::Resize)); |
598 | 623 |
| 624 decoder->SetSurfaceVisibleCallback( |
| 625 NewCallback(this, &ImageTransportHelper::SurfaceVisible)); |
| 626 |
599 return true; | 627 return true; |
600 } | 628 } |
601 | 629 |
602 void ImageTransportHelper::Destroy() { | 630 void ImageTransportHelper::Destroy() { |
603 } | 631 } |
604 | 632 |
605 bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { | 633 bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { |
606 bool handled = true; | 634 bool handled = true; |
607 IPC_BEGIN_MESSAGE_MAP(ImageTransportHelper, message) | 635 IPC_BEGIN_MESSAGE_MAP(ImageTransportHelper, message) |
608 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_NewACK, | 636 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_NewACK, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 } | 680 } |
653 | 681 |
654 void ImageTransportHelper::OnBuffersSwappedACK() { | 682 void ImageTransportHelper::OnBuffersSwappedACK() { |
655 surface_->OnBuffersSwappedACK(); | 683 surface_->OnBuffersSwappedACK(); |
656 } | 684 } |
657 | 685 |
658 void ImageTransportHelper::Resize(gfx::Size size) { | 686 void ImageTransportHelper::Resize(gfx::Size size) { |
659 surface_->OnResize(size); | 687 surface_->OnResize(size); |
660 } | 688 } |
661 | 689 |
| 690 void ImageTransportHelper::SurfaceVisible(bool visible) { |
| 691 surface_->OnSurfaceVisible(visible); |
| 692 } |
| 693 |
662 bool ImageTransportHelper::MakeCurrent() { | 694 bool ImageTransportHelper::MakeCurrent() { |
663 gpu::gles2::GLES2Decoder* decoder = Decoder(); | 695 gpu::gles2::GLES2Decoder* decoder = Decoder(); |
664 if (!decoder) | 696 if (!decoder) |
665 return false; | 697 return false; |
666 return decoder->MakeCurrent(); | 698 return decoder->MakeCurrent(); |
667 } | 699 } |
668 | 700 |
669 gpu::GpuScheduler* ImageTransportHelper::Scheduler() { | 701 gpu::GpuScheduler* ImageTransportHelper::Scheduler() { |
670 GpuChannel* channel = manager_->LookupChannel(renderer_id_); | 702 GpuChannel* channel = manager_->LookupChannel(renderer_id_); |
671 if (!channel) | 703 if (!channel) |
(...skipping 14 matching lines...) Expand all Loading... |
686 | 718 |
687 GpuCommandBufferStub* stub = | 719 GpuCommandBufferStub* stub = |
688 channel->LookupCommandBuffer(command_buffer_id_); | 720 channel->LookupCommandBuffer(command_buffer_id_); |
689 if (!stub) | 721 if (!stub) |
690 return NULL; | 722 return NULL; |
691 | 723 |
692 return stub->decoder(); | 724 return stub->decoder(); |
693 } | 725 } |
694 | 726 |
695 #endif // defined(USE_GPU) | 727 #endif // defined(USE_GPU) |
OLD | NEW |