OLD | NEW |
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/render_thread_impl.h" | 19 #include "content/renderer/render_thread_impl.h" |
19 #include "gpu/command_buffer/client/context_support.h" | 20 #include "gpu/command_buffer/client/context_support.h" |
20 #include "gpu/command_buffer/client/gles2_interface.h" | 21 #include "gpu/command_buffer/client/gles2_interface.h" |
21 #include "ipc/ipc_forwarding_message_filter.h" | 22 #include "ipc/ipc_forwarding_message_filter.h" |
22 #include "ipc/ipc_sync_channel.h" | 23 #include "ipc/ipc_sync_channel.h" |
23 | 24 |
24 namespace { | 25 namespace { |
25 // There are several compositor surfaces in a process, but they share the same | 26 // There are several compositor surfaces in a process, but they share the same |
26 // compositor thread, so we use a simple int here to track prefer-smoothness. | 27 // compositor thread, so we use a simple int here to track prefer-smoothness. |
27 int g_prefer_smoothness_count = 0; | 28 int g_prefer_smoothness_count = 0; |
(...skipping 19 matching lines...) Expand all Loading... |
47 return new IPC::ForwardingMessageFilter( | 48 return new IPC::ForwardingMessageFilter( |
48 messages_to_filter, arraysize(messages_to_filter), | 49 messages_to_filter, arraysize(messages_to_filter), |
49 target_task_runner); | 50 target_task_runner); |
50 } | 51 } |
51 | 52 |
52 CompositorOutputSurface::CompositorOutputSurface( | 53 CompositorOutputSurface::CompositorOutputSurface( |
53 int32 routing_id, | 54 int32 routing_id, |
54 uint32 output_surface_id, | 55 uint32 output_surface_id, |
55 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, | 56 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, |
56 scoped_ptr<cc::SoftwareOutputDevice> software_device, | 57 scoped_ptr<cc::SoftwareOutputDevice> software_device, |
| 58 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue, |
57 bool use_swap_compositor_frame_message) | 59 bool use_swap_compositor_frame_message) |
58 : OutputSurface(context_provider, software_device.Pass()), | 60 : OutputSurface(context_provider, software_device.Pass()), |
59 output_surface_id_(output_surface_id), | 61 output_surface_id_(output_surface_id), |
60 use_swap_compositor_frame_message_(use_swap_compositor_frame_message), | 62 use_swap_compositor_frame_message_(use_swap_compositor_frame_message), |
61 output_surface_filter_( | 63 output_surface_filter_( |
62 RenderThreadImpl::current()->compositor_output_surface_filter()), | 64 RenderThreadImpl::current()->compositor_output_surface_filter()), |
| 65 frame_swap_message_queue_(swap_frame_message_queue), |
63 routing_id_(routing_id), | 66 routing_id_(routing_id), |
64 prefers_smoothness_(false), | 67 prefers_smoothness_(false), |
65 #if defined(OS_WIN) | 68 #if defined(OS_WIN) |
66 // TODO(epenner): Implement PlatformThread::CurrentHandle() on windows. | 69 // TODO(epenner): Implement PlatformThread::CurrentHandle() on windows. |
67 main_thread_handle_(base::PlatformThreadHandle()), | 70 main_thread_handle_(base::PlatformThreadHandle()), |
68 #else | 71 #else |
69 main_thread_handle_(base::PlatformThread::CurrentHandle()), | 72 main_thread_handle_(base::PlatformThread::CurrentHandle()), |
70 #endif | 73 #endif |
71 layout_test_mode_(RenderThreadImpl::current()->layout_test_mode()), | 74 layout_test_mode_(RenderThreadImpl::current()->layout_test_mode()), |
72 weak_ptrs_(this) { | 75 weak_ptrs_(this) { |
73 DCHECK(output_surface_filter_.get()); | 76 DCHECK(output_surface_filter_.get()); |
| 77 DCHECK(frame_swap_message_queue_.get()); |
74 DetachFromThread(); | 78 DetachFromThread(); |
75 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); | 79 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); |
76 DCHECK(message_sender_.get()); | 80 DCHECK(message_sender_.get()); |
77 if (OutputSurface::software_device()) | 81 if (OutputSurface::software_device()) |
78 capabilities_.max_frames_pending = 1; | 82 capabilities_.max_frames_pending = 1; |
79 } | 83 } |
80 | 84 |
81 CompositorOutputSurface::~CompositorOutputSurface() { | 85 CompositorOutputSurface::~CompositorOutputSurface() { |
82 DCHECK(CalledOnValidThread()); | 86 DCHECK(CalledOnValidThread()); |
83 SetNeedsBeginFrame(false); | 87 SetNeedsBeginFrame(false); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 uint32 sync_point = context->InsertSyncPointCHROMIUM(); | 159 uint32 sync_point = context->InsertSyncPointCHROMIUM(); |
156 context_provider_->ContextSupport()->SignalSyncPoint(sync_point, closure); | 160 context_provider_->ContextSupport()->SignalSyncPoint(sync_point, closure); |
157 } else { | 161 } else { |
158 base::MessageLoopProxy::current()->PostTask(FROM_HERE, closure); | 162 base::MessageLoopProxy::current()->PostTask(FROM_HERE, closure); |
159 } | 163 } |
160 client_->DidSwapBuffers(); | 164 client_->DidSwapBuffers(); |
161 return; | 165 return; |
162 } | 166 } |
163 | 167 |
164 if (use_swap_compositor_frame_message_) { | 168 if (use_swap_compositor_frame_message_) { |
165 Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, | 169 { |
166 output_surface_id_, | 170 std::vector<IPC::Message> messages_to_deliver_with_frame; |
167 *frame)); | 171 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = |
| 172 frame_swap_message_queue_->AcquireSendMessageScope(); |
| 173 frame_swap_message_queue_->DrainMessages(&messages_to_deliver_with_frame); |
| 174 Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, |
| 175 output_surface_id_, |
| 176 *frame, |
| 177 messages_to_deliver_with_frame)); |
| 178 // ~send_message_scope. |
| 179 } |
168 client_->DidSwapBuffers(); | 180 client_->DidSwapBuffers(); |
169 return; | 181 return; |
170 } | 182 } |
171 | 183 |
172 if (frame->gl_frame_data) { | 184 if (frame->gl_frame_data) { |
173 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); | 185 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); |
174 ContextProviderCommandBuffer* provider_command_buffer = | 186 ContextProviderCommandBuffer* provider_command_buffer = |
175 static_cast<ContextProviderCommandBuffer*>(context_provider_.get()); | 187 static_cast<ContextProviderCommandBuffer*>(context_provider_.get()); |
176 CommandBufferProxyImpl* command_buffer_proxy = | 188 CommandBufferProxyImpl* command_buffer_proxy = |
177 provider_command_buffer->GetCommandBufferProxy(); | 189 provider_command_buffer->GetCommandBufferProxy(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 // If this is the last surface to stop preferring smoothness, | 287 // If this is the last surface to stop preferring smoothness, |
276 // Reset the main thread's priority to the default. | 288 // Reset the main thread's priority to the default. |
277 if (prefers_smoothness_ == true && | 289 if (prefers_smoothness_ == true && |
278 --g_prefer_smoothness_count == 0) { | 290 --g_prefer_smoothness_count == 0) { |
279 SetThreadPriorityToDefault(main_thread_handle_); | 291 SetThreadPriorityToDefault(main_thread_handle_); |
280 } | 292 } |
281 prefers_smoothness_ = prefers_smoothness; | 293 prefers_smoothness_ = prefers_smoothness; |
282 } | 294 } |
283 | 295 |
284 } // namespace content | 296 } // namespace content |
OLD | NEW |