OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/mus_browser_compositor_output_surface.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
| 11 #include "cc/output/compositor_frame_ack.h" |
11 #include "cc/output/output_surface_client.h" | 12 #include "cc/output/output_surface_client.h" |
12 #include "components/display_compositor/compositor_overlay_candidate_validator.h
" | 13 #include "components/display_compositor/compositor_overlay_candidate_validator.h
" |
| 14 #include "components/mus/common/gpu_service.h" |
| 15 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h" |
| 16 #include "components/mus/public/cpp/window.h" |
| 17 #include "components/mus/public/cpp/window_surface.h" |
13 #include "content/browser/compositor/reflector_impl.h" | 18 #include "content/browser/compositor/reflector_impl.h" |
14 #include "content/browser/compositor/reflector_texture.h" | 19 #include "content/browser/compositor/reflector_texture.h" |
15 #include "content/browser/renderer_host/render_widget_host_impl.h" | 20 #include "content/browser/renderer_host/render_widget_host_impl.h" |
16 #include "content/common/gpu/client/context_provider_command_buffer.h" | 21 #include "content/common/gpu/client/context_provider_command_buffer.h" |
17 #include "gpu/command_buffer/client/context_support.h" | 22 #include "gpu/command_buffer/client/context_support.h" |
18 #include "gpu/ipc/client/command_buffer_proxy_impl.h" | 23 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
| 24 #include "ui/views/mus/native_widget_mus.h" |
| 25 #include "ui/views/mus/window_tree_host_mus.h" |
19 | 26 |
20 namespace content { | 27 namespace content { |
21 | 28 |
22 GpuBrowserCompositorOutputSurface::GpuBrowserCompositorOutputSurface( | 29 MusBrowserCompositorOutputSurface::MusBrowserCompositorOutputSurface( |
| 30 gpu::SurfaceHandle surface_handle, |
23 scoped_refptr<ContextProviderCommandBuffer> context, | 31 scoped_refptr<ContextProviderCommandBuffer> context, |
24 scoped_refptr<ui::CompositorVSyncManager> vsync_manager, | 32 scoped_refptr<ui::CompositorVSyncManager> vsync_manager, |
25 cc::SyntheticBeginFrameSource* begin_frame_source, | 33 cc::SyntheticBeginFrameSource* begin_frame_source, |
26 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> | 34 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> |
27 overlay_candidate_validator) | 35 overlay_candidate_validator) |
28 : BrowserCompositorOutputSurface(std::move(context), | 36 : BrowserCompositorOutputSurface(std::move(context), |
29 std::move(vsync_manager), | 37 std::move(vsync_manager), |
30 begin_frame_source, | 38 begin_frame_source, |
31 std::move(overlay_candidate_validator)), | 39 std::move(overlay_candidate_validator)), |
32 swap_buffers_completion_callback_(base::Bind( | 40 swap_buffers_completion_callback_(base::Bind( |
33 &GpuBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted, | 41 &MusBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted, |
34 base::Unretained(this))), | 42 base::Unretained(this))), |
35 update_vsync_parameters_callback_(base::Bind( | 43 update_vsync_parameters_callback_(base::Bind( |
36 &BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu, | 44 &BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu, |
37 base::Unretained(this))) {} | 45 base::Unretained(this))) { |
38 | 46 capabilities_.delegated_rendering = true; |
39 GpuBrowserCompositorOutputSurface::~GpuBrowserCompositorOutputSurface() {} | 47 views::WindowTreeHostMus* window_tree_host = |
40 | 48 static_cast<views::WindowTreeHostMus*>( |
41 gpu::CommandBufferProxyImpl* | 49 aura::WindowTreeHost::GetForAcceleratedWidget(surface_handle)); |
42 GpuBrowserCompositorOutputSurface::GetCommandBufferProxy() { | 50 mus::Window* window = window_tree_host->native_widget()->window(); |
43 ContextProviderCommandBuffer* provider_command_buffer = | 51 mus_window_surface_ = |
44 static_cast<content::ContextProviderCommandBuffer*>( | 52 window->RequestSurface(mus::mojom::SurfaceType::DEFAULT); |
45 context_provider_.get()); | |
46 gpu::CommandBufferProxyImpl* command_buffer_proxy = | |
47 provider_command_buffer->GetCommandBufferProxy(); | |
48 DCHECK(command_buffer_proxy); | |
49 return command_buffer_proxy; | |
50 } | 53 } |
51 | 54 |
52 bool GpuBrowserCompositorOutputSurface::BindToClient( | 55 MusBrowserCompositorOutputSurface::~MusBrowserCompositorOutputSurface() {} |
| 56 |
| 57 void MusBrowserCompositorOutputSurface::OnReflectorChanged() { |
| 58 if (!reflector_) { |
| 59 reflector_texture_.reset(); |
| 60 } else { |
| 61 reflector_texture_.reset(new ReflectorTexture(context_provider())); |
| 62 reflector_->OnSourceTextureMailboxUpdated(reflector_texture_->mailbox()); |
| 63 } |
| 64 } |
| 65 |
| 66 void MusBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted( |
| 67 const std::vector<ui::LatencyInfo>& latency_info, |
| 68 gfx::SwapResult result, |
| 69 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { |
| 70 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); |
| 71 OnSwapBuffersComplete(); |
| 72 } |
| 73 |
| 74 #if defined(OS_MACOSX) |
| 75 void MusBrowserCompositorOutputSurface::SetSurfaceSuspendedForRecycle( |
| 76 bool suspended) {} |
| 77 #endif |
| 78 |
| 79 void MusBrowserCompositorOutputSurface::SwapBuffers(cc::CompositorFrame frame) { |
| 80 DCHECK(frame.delegated_frame_data); |
| 81 GetCommandBufferProxy()->SetLatencyInfo(frame.metadata.latency_info); |
| 82 |
| 83 // TODO(fsamuel, rjkroege): We should probably throttle compositor frames. |
| 84 client_->DidSwapBuffers(); |
| 85 |
| 86 mus_window_surface_->SubmitCompositorFrame( |
| 87 cc::mojom::CompositorFrame::From(frame), |
| 88 base::Bind(&MusBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted, |
| 89 base::Unretained(this), std::vector<ui::LatencyInfo>(), |
| 90 gfx::SwapResult::SWAP_ACK, nullptr)); |
| 91 // TODO(penghuang): figure how to handle reflector. |
| 92 return; |
| 93 } |
| 94 |
| 95 bool MusBrowserCompositorOutputSurface::BindToClient( |
53 cc::OutputSurfaceClient* client) { | 96 cc::OutputSurfaceClient* client) { |
| 97 mus_window_surface_->BindToThread(); |
| 98 mus_window_surface_->set_client(this); |
| 99 |
54 if (!BrowserCompositorOutputSurface::BindToClient(client)) | 100 if (!BrowserCompositorOutputSurface::BindToClient(client)) |
55 return false; | 101 return false; |
56 | 102 |
57 GetCommandBufferProxy()->SetSwapBuffersCompletionCallback( | 103 GetCommandBufferProxy()->SetSwapBuffersCompletionCallback( |
58 swap_buffers_completion_callback_.callback()); | 104 swap_buffers_completion_callback_.callback()); |
59 GetCommandBufferProxy()->SetUpdateVSyncParametersCallback( | 105 GetCommandBufferProxy()->SetUpdateVSyncParametersCallback( |
60 update_vsync_parameters_callback_.callback()); | 106 update_vsync_parameters_callback_.callback()); |
61 if (capabilities_.uses_default_gl_framebuffer) { | 107 if (capabilities_.uses_default_gl_framebuffer) { |
62 capabilities_.flipped_output_surface = | 108 capabilities_.flipped_output_surface = |
63 context_provider()->ContextCapabilities().flips_vertically; | 109 context_provider()->ContextCapabilities().flips_vertically; |
64 } | 110 } |
65 return true; | 111 return true; |
66 } | 112 } |
67 | 113 |
68 uint32_t GpuBrowserCompositorOutputSurface::GetFramebufferCopyTextureFormat() { | 114 uint32_t MusBrowserCompositorOutputSurface::GetFramebufferCopyTextureFormat() { |
69 auto* gl = static_cast<ContextProviderCommandBuffer*>(context_provider()); | 115 auto* gl = static_cast<ContextProviderCommandBuffer*>(context_provider()); |
70 return gl->GetCopyTextureInternalFormat(); | 116 return gl->GetCopyTextureInternalFormat(); |
71 } | 117 } |
72 | 118 |
73 void GpuBrowserCompositorOutputSurface::OnReflectorChanged() { | 119 void MusBrowserCompositorOutputSurface::OnResourcesReturned( |
74 if (!reflector_) { | 120 mus::WindowSurface* surface, |
75 reflector_texture_.reset(); | 121 mojo::Array<cc::ReturnedResource> resources) { |
76 } else { | 122 cc::CompositorFrameAck cfa; |
77 reflector_texture_.reset(new ReflectorTexture(context_provider())); | 123 cfa.resources = resources.To<cc::ReturnedResourceArray>(); |
78 reflector_->OnSourceTextureMailboxUpdated(reflector_texture_->mailbox()); | 124 ReclaimResources(&cfa); |
79 } | |
80 } | 125 } |
81 | 126 |
82 void GpuBrowserCompositorOutputSurface::SwapBuffers(cc::CompositorFrame frame) { | 127 gpu::CommandBufferProxyImpl* |
83 DCHECK(frame.gl_frame_data); | 128 MusBrowserCompositorOutputSurface::GetCommandBufferProxy() { |
84 | 129 ContextProviderCommandBuffer* provider_command_buffer = |
85 GetCommandBufferProxy()->SetLatencyInfo(frame.metadata.latency_info); | 130 static_cast<content::ContextProviderCommandBuffer*>( |
86 | 131 context_provider_.get()); |
87 if (reflector_) { | 132 gpu::CommandBufferProxyImpl* command_buffer_proxy = |
88 if (frame.gl_frame_data->sub_buffer_rect == | 133 provider_command_buffer->GetCommandBufferProxy(); |
89 gfx::Rect(frame.gl_frame_data->size)) { | 134 DCHECK(command_buffer_proxy); |
90 reflector_texture_->CopyTextureFullImage(SurfaceSize()); | 135 return command_buffer_proxy; |
91 reflector_->OnSourceSwapBuffers(); | |
92 } else { | |
93 const gfx::Rect& rect = frame.gl_frame_data->sub_buffer_rect; | |
94 reflector_texture_->CopyTextureSubImage(rect); | |
95 reflector_->OnSourcePostSubBuffer(rect); | |
96 } | |
97 } | |
98 | |
99 if (frame.gl_frame_data->sub_buffer_rect == | |
100 gfx::Rect(frame.gl_frame_data->size)) { | |
101 context_provider_->ContextSupport()->Swap(); | |
102 } else { | |
103 context_provider_->ContextSupport()->PartialSwapBuffers( | |
104 frame.gl_frame_data->sub_buffer_rect); | |
105 } | |
106 | |
107 client_->DidSwapBuffers(); | |
108 } | 136 } |
109 | 137 |
110 void GpuBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted( | |
111 const std::vector<ui::LatencyInfo>& latency_info, | |
112 gfx::SwapResult result, | |
113 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { | |
114 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); | |
115 OnSwapBuffersComplete(); | |
116 } | |
117 | |
118 #if defined(OS_MACOSX) | |
119 void GpuBrowserCompositorOutputSurface::SetSurfaceSuspendedForRecycle( | |
120 bool suspended) {} | |
121 #endif | |
122 | |
123 } // namespace content | 138 } // namespace content |
OLD | NEW |