Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(868)

Side by Side Diff: content/browser/compositor/mus_browser_compositor_output_surface.cc

Issue 2056833002: WIP HW (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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))) {
46 capabilities_.delegated_rendering = true;
47 views::WindowTreeHostMus* window_tree_host =
48 static_cast<views::WindowTreeHostMus*>(
49 aura::WindowTreeHost::GetForAcceleratedWidget(surface_handle));
50 mus::Window* window = window_tree_host->native_widget()->window();
51 mus_window_surface_ =
52 window->RequestSurface(mus::mojom::SurfaceType::DEFAULT);
53 }
38 54
39 GpuBrowserCompositorOutputSurface::~GpuBrowserCompositorOutputSurface() {} 55 MusBrowserCompositorOutputSurface::~MusBrowserCompositorOutputSurface() {}
40 56
41 gpu::CommandBufferProxyImpl* 57 gpu::CommandBufferProxyImpl*
42 GpuBrowserCompositorOutputSurface::GetCommandBufferProxy() { 58 MusBrowserCompositorOutputSurface::GetCommandBufferProxy() {
43 ContextProviderCommandBuffer* provider_command_buffer = 59 ContextProviderCommandBuffer* provider_command_buffer =
44 static_cast<content::ContextProviderCommandBuffer*>( 60 static_cast<content::ContextProviderCommandBuffer*>(
45 context_provider_.get()); 61 context_provider_.get());
46 gpu::CommandBufferProxyImpl* command_buffer_proxy = 62 gpu::CommandBufferProxyImpl* command_buffer_proxy =
47 provider_command_buffer->GetCommandBufferProxy(); 63 provider_command_buffer->GetCommandBufferProxy();
48 DCHECK(command_buffer_proxy); 64 DCHECK(command_buffer_proxy);
49 return command_buffer_proxy; 65 return command_buffer_proxy;
50 } 66 }
51 67
52 bool GpuBrowserCompositorOutputSurface::BindToClient( 68 void MusBrowserCompositorOutputSurface::OnResourcesReturned(
69 mus::WindowSurface* surface,
70 mojo::Array<cc::ReturnedResource> resources) {
71 cc::CompositorFrameAck cfa;
72 cfa.resources = resources.To<cc::ReturnedResourceArray>();
73 ReclaimResources(&cfa);
74 }
75
76 bool MusBrowserCompositorOutputSurface::BindToClient(
53 cc::OutputSurfaceClient* client) { 77 cc::OutputSurfaceClient* client) {
78 mus_window_surface_->BindToThread();
79 mus_window_surface_->set_client(this);
80
54 if (!BrowserCompositorOutputSurface::BindToClient(client)) 81 if (!BrowserCompositorOutputSurface::BindToClient(client))
55 return false; 82 return false;
56 83
57 GetCommandBufferProxy()->SetSwapBuffersCompletionCallback( 84 GetCommandBufferProxy()->SetSwapBuffersCompletionCallback(
58 swap_buffers_completion_callback_.callback()); 85 swap_buffers_completion_callback_.callback());
59 GetCommandBufferProxy()->SetUpdateVSyncParametersCallback( 86 GetCommandBufferProxy()->SetUpdateVSyncParametersCallback(
60 update_vsync_parameters_callback_.callback()); 87 update_vsync_parameters_callback_.callback());
61 if (capabilities_.uses_default_gl_framebuffer) { 88 if (capabilities_.uses_default_gl_framebuffer) {
62 capabilities_.flipped_output_surface = 89 capabilities_.flipped_output_surface =
63 context_provider()->ContextCapabilities().flips_vertically; 90 context_provider()->ContextCapabilities().flips_vertically;
64 } 91 }
65 return true; 92 return true;
66 } 93 }
67 94
68 void GpuBrowserCompositorOutputSurface::OnReflectorChanged() { 95 void MusBrowserCompositorOutputSurface::OnReflectorChanged() {
69 if (!reflector_) { 96 if (!reflector_) {
70 reflector_texture_.reset(); 97 reflector_texture_.reset();
71 } else { 98 } else {
72 reflector_texture_.reset(new ReflectorTexture(context_provider())); 99 reflector_texture_.reset(new ReflectorTexture(context_provider()));
73 reflector_->OnSourceTextureMailboxUpdated(reflector_texture_->mailbox()); 100 reflector_->OnSourceTextureMailboxUpdated(reflector_texture_->mailbox());
74 } 101 }
75 } 102 }
76 103
77 void GpuBrowserCompositorOutputSurface::SwapBuffers( 104 void MusBrowserCompositorOutputSurface::SwapBuffers(
78 cc::CompositorFrame* frame) { 105 cc::CompositorFrame* frame) {
79 DCHECK(frame->gl_frame_data); 106 DCHECK(frame->delegated_frame_data);
80
81 GetCommandBufferProxy()->SetLatencyInfo(frame->metadata.latency_info); 107 GetCommandBufferProxy()->SetLatencyInfo(frame->metadata.latency_info);
82 108
83 if (reflector_) { 109 // TODO(fsamuel, rjkroege): We should probably throttle compositor frames.
84 if (frame->gl_frame_data->sub_buffer_rect == 110 client_->DidSwapBuffers();
85 gfx::Rect(frame->gl_frame_data->size)) {
86 reflector_texture_->CopyTextureFullImage(SurfaceSize());
87 reflector_->OnSourceSwapBuffers();
88 } else {
89 const gfx::Rect& rect = frame->gl_frame_data->sub_buffer_rect;
90 reflector_texture_->CopyTextureSubImage(rect);
91 reflector_->OnSourcePostSubBuffer(rect);
92 }
93 }
94 111
95 if (frame->gl_frame_data->sub_buffer_rect == 112 mus_window_surface_->SubmitCompositorFrame(
96 gfx::Rect(frame->gl_frame_data->size)) { 113 cc::mojom::CompositorFrame::From(*frame),
97 context_provider_->ContextSupport()->Swap(); 114 base::Bind(&MusBrowserCompositorOutputSurface::OnSwapBuffersComplete,
98 } else { 115 base::Unretained(this)));
99 context_provider_->ContextSupport()->PartialSwapBuffers(
100 frame->gl_frame_data->sub_buffer_rect);
101 }
102 116
103 client_->DidSwapBuffers(); 117 // TODO(penghuang): figure how to handle reflector.
118 return;
104 } 119 }
105 120
106 void GpuBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted( 121 void MusBrowserCompositorOutputSurface::OnGpuSwapBuffersCompleted(
107 const std::vector<ui::LatencyInfo>& latency_info, 122 const std::vector<ui::LatencyInfo>& latency_info,
108 gfx::SwapResult result, 123 gfx::SwapResult result,
109 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { 124 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) {
110 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); 125 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info);
111 OnSwapBuffersComplete(); 126 OnSwapBuffersComplete();
112 } 127 }
113 128
114 #if defined(OS_MACOSX) 129 #if defined(OS_MACOSX)
115 void GpuBrowserCompositorOutputSurface::SetSurfaceSuspendedForRecycle( 130 void MusBrowserCompositorOutputSurface::SetSurfaceSuspendedForRecycle(
116 bool suspended) {} 131 bool suspended) {}
117 #endif 132 #endif
118 133
119 } // namespace content 134 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698