Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h" | 5 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h" |
| 6 | 6 |
| 7 #include "cc/output/compositor_frame.h" | 7 #include "cc/output/compositor_frame.h" |
| 8 #include "cc/output/output_surface_client.h" | 8 #include "cc/output/output_surface_client.h" |
| 9 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida tor.h" | 9 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida tor.h" |
| 10 #include "content/browser/compositor/owned_mailbox.h" | |
| 10 #include "content/browser/compositor/reflector_impl.h" | 11 #include "content/browser/compositor/reflector_impl.h" |
| 11 #include "content/browser/renderer_host/render_widget_host_impl.h" | 12 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 12 #include "content/common/gpu/client/context_provider_command_buffer.h" | 13 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 14 #include "content/common/gpu/client/gl_helper.h" | |
| 13 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 14 #include "gpu/command_buffer/client/context_support.h" | 16 #include "gpu/command_buffer/client/context_support.h" |
| 15 #include "gpu/command_buffer/client/gles2_interface.h" | 17 #include "gpu/command_buffer/client/gles2_interface.h" |
| 16 | 18 |
| 17 namespace content { | 19 namespace content { |
| 18 | 20 |
| 19 GpuBrowserCompositorOutputSurface::GpuBrowserCompositorOutputSurface( | 21 GpuBrowserCompositorOutputSurface::GpuBrowserCompositorOutputSurface( |
| 20 const scoped_refptr<ContextProviderCommandBuffer>& context, | 22 const scoped_refptr<ContextProviderCommandBuffer>& context, |
| 21 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager, | 23 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager, |
| 22 scoped_ptr<BrowserCompositorOverlayCandidateValidator> | 24 scoped_ptr<BrowserCompositorOverlayCandidateValidator> |
| 23 overlay_candidate_validator) | 25 overlay_candidate_validator) |
| 24 : BrowserCompositorOutputSurface(context, | 26 : BrowserCompositorOutputSurface(context, |
| 25 vsync_manager, | 27 vsync_manager, |
| 26 overlay_candidate_validator.Pass()), | 28 overlay_candidate_validator.Pass()), |
| 27 #if defined(OS_MACOSX) | 29 #if defined(OS_MACOSX) |
| 28 should_show_frames_state_(SHOULD_SHOW_FRAMES), | 30 should_show_frames_state_(SHOULD_SHOW_FRAMES), |
| 29 #endif | 31 #endif |
| 30 swap_buffers_completion_callback_( | 32 swap_buffers_completion_callback_( |
| 31 base::Bind(&GpuBrowserCompositorOutputSurface::OnSwapBuffersCompleted, | 33 base::Bind(&GpuBrowserCompositorOutputSurface::OnSwapBuffersCompleted, |
| 32 base::Unretained(this))), | 34 base::Unretained(this))), |
| 33 update_vsync_parameters_callback_(base::Bind( | 35 update_vsync_parameters_callback_(base::Bind( |
| 34 &BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu, | 36 &BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu, |
| 35 base::Unretained(this))) { | 37 base::Unretained(this))), |
| 38 mirrored_compositor_gl_helper_texture_id_(0) { | |
| 36 } | 39 } |
| 37 | 40 |
| 38 GpuBrowserCompositorOutputSurface::~GpuBrowserCompositorOutputSurface() {} | 41 GpuBrowserCompositorOutputSurface::~GpuBrowserCompositorOutputSurface() { |
| 42 DCHECK(!reflector_); | |
| 43 DeleteTexture(); | |
| 44 } | |
| 39 | 45 |
| 40 CommandBufferProxyImpl* | 46 CommandBufferProxyImpl* |
| 41 GpuBrowserCompositorOutputSurface::GetCommandBufferProxy() { | 47 GpuBrowserCompositorOutputSurface::GetCommandBufferProxy() { |
| 42 ContextProviderCommandBuffer* provider_command_buffer = | 48 ContextProviderCommandBuffer* provider_command_buffer = |
| 43 static_cast<content::ContextProviderCommandBuffer*>( | 49 static_cast<content::ContextProviderCommandBuffer*>( |
| 44 context_provider_.get()); | 50 context_provider_.get()); |
| 45 CommandBufferProxyImpl* command_buffer_proxy = | 51 CommandBufferProxyImpl* command_buffer_proxy = |
| 46 provider_command_buffer->GetCommandBufferProxy(); | 52 provider_command_buffer->GetCommandBufferProxy(); |
| 47 DCHECK(command_buffer_proxy); | 53 DCHECK(command_buffer_proxy); |
| 48 return command_buffer_proxy; | 54 return command_buffer_proxy; |
| 49 } | 55 } |
| 50 | 56 |
| 51 bool GpuBrowserCompositorOutputSurface::BindToClient( | 57 bool GpuBrowserCompositorOutputSurface::BindToClient( |
| 52 cc::OutputSurfaceClient* client) { | 58 cc::OutputSurfaceClient* client) { |
| 53 if (!BrowserCompositorOutputSurface::BindToClient(client)) | 59 if (!BrowserCompositorOutputSurface::BindToClient(client)) |
| 54 return false; | 60 return false; |
| 55 | 61 |
| 56 GetCommandBufferProxy()->SetSwapBuffersCompletionCallback( | 62 GetCommandBufferProxy()->SetSwapBuffersCompletionCallback( |
| 57 swap_buffers_completion_callback_.callback()); | 63 swap_buffers_completion_callback_.callback()); |
| 58 GetCommandBufferProxy()->SetUpdateVSyncParametersCallback( | 64 GetCommandBufferProxy()->SetUpdateVSyncParametersCallback( |
| 59 update_vsync_parameters_callback_.callback()); | 65 update_vsync_parameters_callback_.callback()); |
| 60 return true; | 66 return true; |
| 61 } | 67 } |
| 62 | 68 |
| 69 void GpuBrowserCompositorOutputSurface::DeleteTexture() { | |
| 70 if (mirrored_compositor_gl_helper_.get()) { | |
| 71 mirrored_compositor_gl_helper_->DeleteTexture( | |
| 72 mirrored_compositor_gl_helper_texture_id_); | |
| 73 mailbox_ = nullptr; | |
| 74 mirrored_compositor_gl_helper_texture_id_ = 0; | |
| 75 mirrored_compositor_gl_helper_ = nullptr; | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 void GpuBrowserCompositorOutputSurface::OnReflectorChanged() { | |
| 80 if (!reflector_) { | |
| 81 DeleteTexture(); | |
| 82 } else { | |
| 83 GLHelper* shared_helper = | |
| 84 ImageTransportFactory::GetInstance()->GetGLHelper(); | |
| 85 mailbox_ = new OwnedMailbox(shared_helper); | |
| 86 | |
| 87 // Create a GLHelper attached to the mirrored compositor's output | |
| 88 // surface for copying the output of the mirrored compositor. | |
| 89 mirrored_compositor_gl_helper_.reset(new GLHelper( | |
| 90 context_provider()->ContextGL(), context_provider()->ContextSupport())); | |
| 91 // Create a texture id in the name space of the new GLHelper to update the | |
| 92 // mailbox being held by the |mirroring_layer_|. | |
|
piman
2015/05/13 19:46:23
can you add a DCHECK(!mirrored_compositor_gl_helpe
oshima
2015/05/14 14:44:58
Done.
| |
| 93 mirrored_compositor_gl_helper_texture_id_ = | |
| 94 mirrored_compositor_gl_helper_->ConsumeMailboxToTexture( | |
| 95 mailbox_->mailbox(), mailbox_->sync_point()); | |
| 96 reflector_->OnSourceTextureMailboxUpdated(mailbox_); | |
| 97 } | |
| 98 } | |
| 99 | |
| 63 void GpuBrowserCompositorOutputSurface::SwapBuffers( | 100 void GpuBrowserCompositorOutputSurface::SwapBuffers( |
| 64 cc::CompositorFrame* frame) { | 101 cc::CompositorFrame* frame) { |
| 65 DCHECK(frame->gl_frame_data); | 102 DCHECK(frame->gl_frame_data); |
| 66 | 103 |
| 67 GetCommandBufferProxy()->SetLatencyInfo(frame->metadata.latency_info); | 104 GetCommandBufferProxy()->SetLatencyInfo(frame->metadata.latency_info); |
| 68 | 105 |
| 69 if (reflector_) { | 106 if (reflector_) { |
| 70 if (frame->gl_frame_data->sub_buffer_rect == | 107 if (frame->gl_frame_data->sub_buffer_rect == |
| 71 gfx::Rect(frame->gl_frame_data->size)) | 108 gfx::Rect(frame->gl_frame_data->size)) { |
| 109 gfx::Size size = SurfaceSize(); | |
| 110 mirrored_compositor_gl_helper_->CopyTextureFullImage( | |
| 111 mirrored_compositor_gl_helper_texture_id_, size); | |
| 112 // Insert a barrier to make the copy show up in the mirroring compositor's | |
| 113 // mailbox. Since the the compositor contexts and the | |
| 114 // ImageTransportFactory's | |
| 115 // GLHelper are all on the same GPU channel, this is sufficient instead of | |
| 116 // plumbing through a sync point. | |
| 117 mirrored_compositor_gl_helper_->InsertOrderingBarrier(); | |
| 118 | |
| 72 reflector_->OnSourceSwapBuffers(); | 119 reflector_->OnSourceSwapBuffers(); |
| 73 else | 120 } else { |
| 74 reflector_->OnSourcePostSubBuffer(frame->gl_frame_data->sub_buffer_rect); | 121 const gfx::Rect& rect = frame->gl_frame_data->sub_buffer_rect; |
| 122 | |
| 123 mirrored_compositor_gl_helper_->CopyTextureSubImage( | |
| 124 mirrored_compositor_gl_helper_texture_id_, rect); | |
| 125 // Insert a barrier for the same reason above. | |
| 126 mirrored_compositor_gl_helper_->InsertOrderingBarrier(); | |
| 127 | |
| 128 reflector_->OnSourcePostSubBuffer(rect); | |
| 129 } | |
| 75 } | 130 } |
| 76 | 131 |
| 77 if (frame->gl_frame_data->sub_buffer_rect == | 132 if (frame->gl_frame_data->sub_buffer_rect == |
| 78 gfx::Rect(frame->gl_frame_data->size)) { | 133 gfx::Rect(frame->gl_frame_data->size)) { |
| 79 context_provider_->ContextSupport()->Swap(); | 134 context_provider_->ContextSupport()->Swap(); |
| 80 } else { | 135 } else { |
| 81 context_provider_->ContextSupport()->PartialSwapBuffers( | 136 context_provider_->ContextSupport()->PartialSwapBuffers( |
| 82 frame->gl_frame_data->sub_buffer_rect); | 137 frame->gl_frame_data->sub_buffer_rect); |
| 83 } | 138 } |
| 84 | 139 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 } | 189 } |
| 135 } | 190 } |
| 136 | 191 |
| 137 bool GpuBrowserCompositorOutputSurface:: | 192 bool GpuBrowserCompositorOutputSurface:: |
| 138 SurfaceShouldNotShowFramesAfterSuspendForRecycle() const { | 193 SurfaceShouldNotShowFramesAfterSuspendForRecycle() const { |
| 139 return should_show_frames_state_ != SHOULD_SHOW_FRAMES; | 194 return should_show_frames_state_ != SHOULD_SHOW_FRAMES; |
| 140 } | 195 } |
| 141 #endif | 196 #endif |
| 142 | 197 |
| 143 } // namespace content | 198 } // namespace content |
| OLD | NEW |