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" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 }; | 43 }; |
44 | 44 |
45 return new IPC::ForwardingMessageFilter( | 45 return new IPC::ForwardingMessageFilter( |
46 messages_to_filter, arraysize(messages_to_filter), | 46 messages_to_filter, arraysize(messages_to_filter), |
47 target_task_runner); | 47 target_task_runner); |
48 } | 48 } |
49 | 49 |
50 CompositorOutputSurface::CompositorOutputSurface( | 50 CompositorOutputSurface::CompositorOutputSurface( |
51 int32 routing_id, | 51 int32 routing_id, |
52 WebGraphicsContext3DCommandBufferImpl* context3D, | 52 WebGraphicsContext3DCommandBufferImpl* context3D, |
53 cc::SoftwareOutputDevice* software_device) | 53 cc::SoftwareOutputDevice* software_device, |
| 54 bool use_swap_compositor_frame_message) |
54 : OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>(context3D), | 55 : OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>(context3D), |
55 make_scoped_ptr(software_device)), | 56 make_scoped_ptr(software_device)), |
| 57 use_swap_compositor_frame_message_(use_swap_compositor_frame_message), |
56 output_surface_filter_( | 58 output_surface_filter_( |
57 RenderThreadImpl::current()->compositor_output_surface_filter()), | 59 RenderThreadImpl::current()->compositor_output_surface_filter()), |
58 routing_id_(routing_id), | 60 routing_id_(routing_id), |
59 prefers_smoothness_(false), | 61 prefers_smoothness_(false), |
60 main_thread_handle_(base::PlatformThread::CurrentHandle()) { | 62 main_thread_handle_(base::PlatformThread::CurrentHandle()) { |
61 DCHECK(output_surface_filter_.get()); | 63 DCHECK(output_surface_filter_.get()); |
62 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
63 capabilities_.has_parent_compositor = command_line->HasSwitch( | |
64 switches::kEnableDelegatedRenderer); | |
65 DetachFromThread(); | 64 DetachFromThread(); |
66 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); | 65 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); |
67 DCHECK(message_sender_.get()); | 66 DCHECK(message_sender_.get()); |
68 } | 67 } |
69 | 68 |
70 CompositorOutputSurface::~CompositorOutputSurface() { | 69 CompositorOutputSurface::~CompositorOutputSurface() { |
71 DCHECK(CalledOnValidThread()); | 70 DCHECK(CalledOnValidThread()); |
72 if (!client_) | 71 if (!client_) |
73 return; | 72 return; |
74 UpdateSmoothnessTakesPriority(false); | 73 UpdateSmoothnessTakesPriority(false); |
(...skipping 11 matching lines...) Expand all Loading... |
86 | 85 |
87 output_surface_proxy_ = new CompositorOutputSurfaceProxy(this); | 86 output_surface_proxy_ = new CompositorOutputSurfaceProxy(this); |
88 output_surface_filter_->AddRoute( | 87 output_surface_filter_->AddRoute( |
89 routing_id_, | 88 routing_id_, |
90 base::Bind(&CompositorOutputSurfaceProxy::OnMessageReceived, | 89 base::Bind(&CompositorOutputSurfaceProxy::OnMessageReceived, |
91 output_surface_proxy_)); | 90 output_surface_proxy_)); |
92 | 91 |
93 return true; | 92 return true; |
94 } | 93 } |
95 | 94 |
96 void CompositorOutputSurface::SendFrameToParentCompositor( | 95 void CompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { |
97 cc::CompositorFrame* frame) { | 96 if (use_swap_compositor_frame_message_) { |
98 DCHECK(CalledOnValidThread()); | 97 Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, *frame)); |
99 Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, *frame)); | 98 return; |
100 } | 99 } |
101 | 100 |
102 void CompositorOutputSurface::SwapBuffers( | 101 if (frame->gl_frame_data) { |
103 const ui::LatencyInfo& latency_info) { | 102 WebGraphicsContext3DCommandBufferImpl* command_buffer = |
104 WebGraphicsContext3DCommandBufferImpl* command_buffer = | 103 static_cast<WebGraphicsContext3DCommandBufferImpl*>(context3d()); |
105 static_cast<WebGraphicsContext3DCommandBufferImpl*>(context3d()); | 104 CommandBufferProxyImpl* command_buffer_proxy = |
106 CommandBufferProxyImpl* command_buffer_proxy = | 105 command_buffer->GetCommandBufferProxy(); |
107 command_buffer->GetCommandBufferProxy(); | 106 DCHECK(command_buffer_proxy); |
108 DCHECK(command_buffer_proxy); | 107 context3d()->shallowFlushCHROMIUM(); |
109 context3d()->shallowFlushCHROMIUM(); | 108 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); |
110 command_buffer_proxy->SetLatencyInfo(latency_info); | 109 } |
111 OutputSurface::SwapBuffers(latency_info); | |
112 } | |
113 | 110 |
114 void CompositorOutputSurface::PostSubBuffer( | 111 OutputSurface::SwapBuffers(frame); |
115 gfx::Rect rect, const ui::LatencyInfo& latency_info) { | |
116 WebGraphicsContext3DCommandBufferImpl* command_buffer = | |
117 static_cast<WebGraphicsContext3DCommandBufferImpl*>(context3d()); | |
118 CommandBufferProxyImpl* command_buffer_proxy = | |
119 command_buffer->GetCommandBufferProxy(); | |
120 DCHECK(command_buffer_proxy); | |
121 context3d()->shallowFlushCHROMIUM(); | |
122 command_buffer_proxy->SetLatencyInfo(latency_info); | |
123 OutputSurface::PostSubBuffer(rect, latency_info); | |
124 } | 112 } |
125 | 113 |
126 void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { | 114 void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { |
127 DCHECK(CalledOnValidThread()); | 115 DCHECK(CalledOnValidThread()); |
128 if (!client_) | 116 if (!client_) |
129 return; | 117 return; |
130 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message) | 118 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message) |
131 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters, OnUpdateVSyncParameters); | 119 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters, OnUpdateVSyncParameters); |
132 IPC_MESSAGE_HANDLER(ViewMsg_SwapCompositorFrameAck, OnSwapAck); | 120 IPC_MESSAGE_HANDLER(ViewMsg_SwapCompositorFrameAck, OnSwapAck); |
133 #if defined(OS_ANDROID) | 121 #if defined(OS_ANDROID) |
(...skipping 14 matching lines...) Expand all Loading... |
148 Send(new ViewHostMsg_SetNeedsBeginFrame(routing_id_, enable)); | 136 Send(new ViewHostMsg_SetNeedsBeginFrame(routing_id_, enable)); |
149 } | 137 } |
150 | 138 |
151 void CompositorOutputSurface::OnBeginFrame(base::TimeTicks frame_time) { | 139 void CompositorOutputSurface::OnBeginFrame(base::TimeTicks frame_time) { |
152 DCHECK(CalledOnValidThread()); | 140 DCHECK(CalledOnValidThread()); |
153 client_->BeginFrame(frame_time); | 141 client_->BeginFrame(frame_time); |
154 } | 142 } |
155 #endif // defined(OS_ANDROID) | 143 #endif // defined(OS_ANDROID) |
156 | 144 |
157 void CompositorOutputSurface::OnSwapAck(const cc::CompositorFrameAck& ack) { | 145 void CompositorOutputSurface::OnSwapAck(const cc::CompositorFrameAck& ack) { |
158 client_->OnSendFrameToParentCompositorAck(ack); | 146 client_->OnSwapBuffersComplete(&ack); |
159 } | 147 } |
160 | 148 |
161 bool CompositorOutputSurface::Send(IPC::Message* message) { | 149 bool CompositorOutputSurface::Send(IPC::Message* message) { |
162 return message_sender_->Send(message); | 150 return message_sender_->Send(message); |
163 } | 151 } |
164 | 152 |
165 namespace { | 153 namespace { |
166 #if defined(OS_ANDROID) | 154 #if defined(OS_ANDROID) |
167 void SetThreadPriorityToIdle(base::PlatformThreadHandle handle) { | 155 void SetThreadPriorityToIdle(base::PlatformThreadHandle handle) { |
168 base::PlatformThread::SetThreadPriority( | 156 base::PlatformThread::SetThreadPriority( |
(...skipping 28 matching lines...) Expand all Loading... |
197 // If this is the last surface to stop preferring smoothness, | 185 // If this is the last surface to stop preferring smoothness, |
198 // Reset the main thread's priority to the default. | 186 // Reset the main thread's priority to the default. |
199 if (prefers_smoothness_ == true && | 187 if (prefers_smoothness_ == true && |
200 --g_prefer_smoothness_count == 0) { | 188 --g_prefer_smoothness_count == 0) { |
201 SetThreadPriorityToDefault(main_thread_handle_); | 189 SetThreadPriorityToDefault(main_thread_handle_); |
202 } | 190 } |
203 prefers_smoothness_ = prefers_smoothness; | 191 prefers_smoothness_ = prefers_smoothness; |
204 } | 192 } |
205 | 193 |
206 } // namespace content | 194 } // namespace content |
OLD | NEW |