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

Side by Side Diff: content/renderer/gpu/compositor_output_surface.cc

Issue 619843002: cc: Make separate interface for BeginFrame ipc from OutputSurface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer/gpu/compositor_output_surface.h" 5 #include "content/renderer/gpu/compositor_output_surface.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "cc/output/compositor_frame.h" 9 #include "cc/output/compositor_frame.h"
10 #include "cc/output/compositor_frame_ack.h" 10 #include "cc/output/compositor_frame_ack.h"
11 #include "cc/output/managed_memory_policy.h" 11 #include "cc/output/managed_memory_policy.h"
12 #include "cc/output/output_surface_client.h" 12 #include "cc/output/output_surface_client.h"
13 #include "content/common/gpu/client/command_buffer_proxy_impl.h" 13 #include "content/common/gpu/client/command_buffer_proxy_impl.h"
14 #include "content/common/gpu/client/context_provider_command_buffer.h" 14 #include "content/common/gpu/client/context_provider_command_buffer.h"
15 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 15 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
16 #include "content/common/view_messages.h" 16 #include "content/common/view_messages.h"
17 #include "content/public/common/content_switches.h" 17 #include "content/public/common/content_switches.h"
18 #include "content/renderer/gpu/frame_swap_message_queue.h" 18 #include "content/renderer/gpu/frame_swap_message_queue.h"
19 #include "content/renderer/render_thread_impl.h" 19 #include "content/renderer/render_thread_impl.h"
20 #include "gpu/command_buffer/client/context_support.h" 20 #include "gpu/command_buffer/client/context_support.h"
21 #include "gpu/command_buffer/client/gles2_interface.h" 21 #include "gpu/command_buffer/client/gles2_interface.h"
22 #include "ipc/ipc_forwarding_message_filter.h"
23 #include "ipc/ipc_sync_channel.h" 22 #include "ipc/ipc_sync_channel.h"
24 23
25 namespace { 24 namespace {
26 // There are several compositor surfaces in a process, but they share the same 25 // There are several compositor surfaces in a process, but they share the same
27 // compositor thread, so we use a simple int here to track prefer-smoothness. 26 // compositor thread, so we use a simple int here to track prefer-smoothness.
28 int g_prefer_smoothness_count = 0; 27 int g_prefer_smoothness_count = 0;
29 } // namespace 28 } // namespace
30 29
31 namespace content { 30 namespace content {
32 31
33 //------------------------------------------------------------------------------
34
35 // static
36 IPC::ForwardingMessageFilter* CompositorOutputSurface::CreateFilter(
37 base::TaskRunner* target_task_runner)
38 {
39 uint32 messages_to_filter[] = {
40 ViewMsg_UpdateVSyncParameters::ID,
41 ViewMsg_SwapCompositorFrameAck::ID,
42 ViewMsg_ReclaimCompositorResources::ID,
43 #if defined(OS_ANDROID)
44 ViewMsg_BeginFrame::ID
45 #endif
46 };
47
48 return new IPC::ForwardingMessageFilter(
49 messages_to_filter, arraysize(messages_to_filter),
50 target_task_runner);
51 }
52
53 CompositorOutputSurface::CompositorOutputSurface( 32 CompositorOutputSurface::CompositorOutputSurface(
54 int32 routing_id, 33 int32 routing_id,
55 uint32 output_surface_id, 34 uint32 output_surface_id,
56 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, 35 const scoped_refptr<ContextProviderCommandBuffer>& context_provider,
57 scoped_ptr<cc::SoftwareOutputDevice> software_device, 36 scoped_ptr<cc::SoftwareOutputDevice> software_device,
58 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue, 37 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue,
59 bool use_swap_compositor_frame_message) 38 bool use_swap_compositor_frame_message)
60 : OutputSurface(context_provider, software_device.Pass()), 39 : OutputSurface(context_provider, software_device.Pass()),
61 output_surface_id_(output_surface_id), 40 output_surface_id_(output_surface_id),
62 use_swap_compositor_frame_message_(use_swap_compositor_frame_message), 41 use_swap_compositor_frame_message_(use_swap_compositor_frame_message),
63 output_surface_filter_( 42 output_surface_filter_(
64 RenderThreadImpl::current()->compositor_output_surface_filter()), 43 RenderThreadImpl::current()->compositor_message_filter()),
65 frame_swap_message_queue_(swap_frame_message_queue), 44 frame_swap_message_queue_(swap_frame_message_queue),
66 routing_id_(routing_id), 45 routing_id_(routing_id),
67 prefers_smoothness_(false), 46 prefers_smoothness_(false),
68 #if defined(OS_WIN) 47 #if defined(OS_WIN)
69 // TODO(epenner): Implement PlatformThread::CurrentHandle() on windows. 48 // TODO(epenner): Implement PlatformThread::CurrentHandle() on windows.
70 main_thread_handle_(base::PlatformThreadHandle()), 49 main_thread_handle_(base::PlatformThreadHandle()),
71 #else 50 #else
72 main_thread_handle_(base::PlatformThread::CurrentHandle()), 51 main_thread_handle_(base::PlatformThread::CurrentHandle()),
73 #endif 52 #endif
74 layout_test_mode_(RenderThreadImpl::current()->layout_test_mode()), 53 layout_test_mode_(RenderThreadImpl::current()->layout_test_mode()),
75 weak_ptrs_(this) { 54 weak_ptrs_(this) {
76 DCHECK(output_surface_filter_.get()); 55 DCHECK(output_surface_filter_.get());
77 DCHECK(frame_swap_message_queue_.get()); 56 DCHECK(frame_swap_message_queue_.get());
78 DetachFromThread(); 57 DetachFromThread();
79 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); 58 message_sender_ = RenderThreadImpl::current()->sync_message_filter();
80 DCHECK(message_sender_.get()); 59 DCHECK(message_sender_.get());
81 if (OutputSurface::software_device()) 60 if (OutputSurface::software_device())
82 capabilities_.max_frames_pending = 1; 61 capabilities_.max_frames_pending = 1;
83 } 62 }
84 63
85 CompositorOutputSurface::~CompositorOutputSurface() { 64 CompositorOutputSurface::~CompositorOutputSurface() {
86 DCHECK(CalledOnValidThread()); 65 DCHECK(CalledOnValidThread());
87 SetNeedsBeginFrame(false);
88 if (!HasClient()) 66 if (!HasClient())
89 return; 67 return;
90 UpdateSmoothnessTakesPriority(false); 68 UpdateSmoothnessTakesPriority(false);
91 if (output_surface_proxy_.get()) 69 if (output_surface_proxy_.get())
92 output_surface_proxy_->ClearOutputSurface(); 70 output_surface_proxy_->ClearOutputSurface();
93 output_surface_filter_->RemoveRoute(routing_id_); 71 output_surface_filter_->RemoveHandlerOnCompositorThread(
72 routing_id_,
73 output_surface_filter_handler_);
94 } 74 }
95 75
96 bool CompositorOutputSurface::BindToClient( 76 bool CompositorOutputSurface::BindToClient(
97 cc::OutputSurfaceClient* client) { 77 cc::OutputSurfaceClient* client) {
98 DCHECK(CalledOnValidThread()); 78 DCHECK(CalledOnValidThread());
99 79
100 if (!cc::OutputSurface::BindToClient(client)) 80 if (!cc::OutputSurface::BindToClient(client))
101 return false; 81 return false;
102 82
103 output_surface_proxy_ = new CompositorOutputSurfaceProxy(this); 83 output_surface_proxy_ = new CompositorOutputSurfaceProxy(this);
104 output_surface_filter_->AddRoute( 84 output_surface_filter_handler_ =
105 routing_id_,
106 base::Bind(&CompositorOutputSurfaceProxy::OnMessageReceived, 85 base::Bind(&CompositorOutputSurfaceProxy::OnMessageReceived,
107 output_surface_proxy_)); 86 output_surface_proxy_);
87 output_surface_filter_->AddHandlerOnCompositorThread(
88 routing_id_,
89 output_surface_filter_handler_);
108 90
109 if (!context_provider()) { 91 if (!context_provider()) {
110 // Without a GPU context, the memory policy otherwise wouldn't be set. 92 // Without a GPU context, the memory policy otherwise wouldn't be set.
111 client->SetMemoryPolicy(cc::ManagedMemoryPolicy( 93 client->SetMemoryPolicy(cc::ManagedMemoryPolicy(
112 128 * 1024 * 1024, 94 128 * 1024 * 1024,
113 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, 95 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
114 base::SharedMemory::GetHandleLimit() / 3)); 96 base::SharedMemory::GetHandleLimit() / 3));
115 } 97 }
116 98
117 return true; 99 return true;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 168
187 void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { 169 void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) {
188 DCHECK(CalledOnValidThread()); 170 DCHECK(CalledOnValidThread());
189 if (!HasClient()) 171 if (!HasClient())
190 return; 172 return;
191 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message) 173 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message)
192 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters, 174 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters,
193 OnUpdateVSyncParametersFromBrowser); 175 OnUpdateVSyncParametersFromBrowser);
194 IPC_MESSAGE_HANDLER(ViewMsg_SwapCompositorFrameAck, OnSwapAck); 176 IPC_MESSAGE_HANDLER(ViewMsg_SwapCompositorFrameAck, OnSwapAck);
195 IPC_MESSAGE_HANDLER(ViewMsg_ReclaimCompositorResources, OnReclaimResources); 177 IPC_MESSAGE_HANDLER(ViewMsg_ReclaimCompositorResources, OnReclaimResources);
196 #if defined(OS_ANDROID)
197 IPC_MESSAGE_HANDLER(ViewMsg_BeginFrame, OnBeginFrame);
198 #endif
199 IPC_END_MESSAGE_MAP() 178 IPC_END_MESSAGE_MAP()
200 } 179 }
201 180
202 void CompositorOutputSurface::OnUpdateVSyncParametersFromBrowser( 181 void CompositorOutputSurface::OnUpdateVSyncParametersFromBrowser(
203 base::TimeTicks timebase, 182 base::TimeTicks timebase,
204 base::TimeDelta interval) { 183 base::TimeDelta interval) {
205 DCHECK(CalledOnValidThread()); 184 DCHECK(CalledOnValidThread());
206 CommitVSyncParameters(timebase, interval); 185 CommitVSyncParameters(timebase, interval);
207 } 186 }
208 187
209 #if defined(OS_ANDROID)
210 void CompositorOutputSurface::SetNeedsBeginFrame(bool enable) {
211 DCHECK(CalledOnValidThread());
212 Send(new ViewHostMsg_SetNeedsBeginFrame(routing_id_, enable));
213 }
214
215 void CompositorOutputSurface::OnBeginFrame(const cc::BeginFrameArgs& args) {
216 DCHECK(CalledOnValidThread());
217 client_->BeginFrame(args);
218 }
219 #endif // defined(OS_ANDROID)
220
221 void CompositorOutputSurface::OnSwapAck(uint32 output_surface_id, 188 void CompositorOutputSurface::OnSwapAck(uint32 output_surface_id,
222 const cc::CompositorFrameAck& ack) { 189 const cc::CompositorFrameAck& ack) {
223 // Ignore message if it's a stale one coming from a different output surface 190 // Ignore message if it's a stale one coming from a different output surface
224 // (e.g. after a lost context). 191 // (e.g. after a lost context).
225 if (output_surface_id != output_surface_id_) 192 if (output_surface_id != output_surface_id_)
226 return; 193 return;
227 ReclaimResources(&ack); 194 ReclaimResources(&ack);
228 client_->DidSwapBuffersComplete(); 195 client_->DidSwapBuffersComplete();
229 } 196 }
230 197
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // If this is the last surface to stop preferring smoothness, 244 // If this is the last surface to stop preferring smoothness,
278 // Reset the main thread's priority to the default. 245 // Reset the main thread's priority to the default.
279 if (prefers_smoothness_ == true && 246 if (prefers_smoothness_ == true &&
280 --g_prefer_smoothness_count == 0) { 247 --g_prefer_smoothness_count == 0) {
281 SetThreadPriorityToDefault(main_thread_handle_); 248 SetThreadPriorityToDefault(main_thread_handle_);
282 } 249 }
283 prefers_smoothness_ = prefers_smoothness; 250 prefers_smoothness_ = prefers_smoothness;
284 } 251 }
285 252
286 } // namespace content 253 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/gpu/compositor_output_surface.h ('k') | content/renderer/gpu/render_widget_compositor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698