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/location.h" | 8 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 frame_swap_message_queue_(swap_frame_message_queue), | 43 frame_swap_message_queue_(swap_frame_message_queue), |
44 routing_id_(routing_id), | 44 routing_id_(routing_id), |
45 #if defined(OS_ANDROID) | 45 #if defined(OS_ANDROID) |
46 prefers_smoothness_(false), | 46 prefers_smoothness_(false), |
47 main_thread_runner_(base::MessageLoop::current()->task_runner()), | 47 main_thread_runner_(base::MessageLoop::current()->task_runner()), |
48 #endif | 48 #endif |
49 layout_test_mode_(RenderThreadImpl::current()->layout_test_mode()), | 49 layout_test_mode_(RenderThreadImpl::current()->layout_test_mode()), |
50 weak_ptrs_(this) { | 50 weak_ptrs_(this) { |
51 DCHECK(output_surface_filter_.get()); | 51 DCHECK(output_surface_filter_.get()); |
52 DCHECK(frame_swap_message_queue_.get()); | 52 DCHECK(frame_swap_message_queue_.get()); |
53 DetachFromThread(); | |
54 capabilities_.max_frames_pending = 1; | 53 capabilities_.max_frames_pending = 1; |
55 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); | 54 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); |
56 DCHECK(message_sender_.get()); | 55 DCHECK(message_sender_.get()); |
57 } | 56 } |
58 | 57 |
59 CompositorOutputSurface::~CompositorOutputSurface() { | 58 CompositorOutputSurface::~CompositorOutputSurface() {} |
60 DCHECK(CalledOnValidThread()); | |
61 if (!HasClient()) | |
62 return; | |
63 UpdateSmoothnessTakesPriority(false); | |
64 if (output_surface_proxy_.get()) | |
65 output_surface_proxy_->ClearOutputSurface(); | |
66 output_surface_filter_->RemoveHandlerOnCompositorThread( | |
67 routing_id_, | |
68 output_surface_filter_handler_); | |
69 } | |
70 | 59 |
71 bool CompositorOutputSurface::BindToClient( | 60 bool CompositorOutputSurface::BindToClient( |
72 cc::OutputSurfaceClient* client) { | 61 cc::OutputSurfaceClient* client) { |
73 DCHECK(CalledOnValidThread()); | |
74 | |
75 if (!cc::OutputSurface::BindToClient(client)) | 62 if (!cc::OutputSurface::BindToClient(client)) |
76 return false; | 63 return false; |
77 | 64 |
78 output_surface_proxy_ = new CompositorOutputSurfaceProxy(this); | 65 output_surface_proxy_ = new CompositorOutputSurfaceProxy(this); |
79 output_surface_filter_handler_ = | 66 output_surface_filter_handler_ = |
80 base::Bind(&CompositorOutputSurfaceProxy::OnMessageReceived, | 67 base::Bind(&CompositorOutputSurfaceProxy::OnMessageReceived, |
81 output_surface_proxy_); | 68 output_surface_proxy_); |
82 output_surface_filter_->AddHandlerOnCompositorThread( | 69 output_surface_filter_->AddHandlerOnCompositorThread( |
83 routing_id_, | 70 routing_id_, |
84 output_surface_filter_handler_); | 71 output_surface_filter_handler_); |
85 | 72 |
86 if (!context_provider()) { | 73 if (!context_provider()) { |
87 // Without a GPU context, the memory policy otherwise wouldn't be set. | 74 // Without a GPU context, the memory policy otherwise wouldn't be set. |
88 client->SetMemoryPolicy(cc::ManagedMemoryPolicy( | 75 client->SetMemoryPolicy(cc::ManagedMemoryPolicy( |
89 128 * 1024 * 1024, | 76 128 * 1024 * 1024, |
90 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, | 77 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, |
91 base::SharedMemory::GetHandleLimit() / 3)); | 78 base::SharedMemory::GetHandleLimit() / 3)); |
92 } | 79 } |
93 | 80 |
94 return true; | 81 return true; |
95 } | 82 } |
96 | 83 |
| 84 void CompositorOutputSurface::DetachFromClient() { |
| 85 if (!HasClient()) |
| 86 return; |
| 87 UpdateSmoothnessTakesPriority(false); |
| 88 if (output_surface_proxy_.get()) |
| 89 output_surface_proxy_->ClearOutputSurface(); |
| 90 output_surface_filter_->RemoveHandlerOnCompositorThread( |
| 91 routing_id_, output_surface_filter_handler_); |
| 92 cc::OutputSurface::DetachFromClient(); |
| 93 } |
| 94 |
97 void CompositorOutputSurface::ShortcutSwapAck( | 95 void CompositorOutputSurface::ShortcutSwapAck( |
98 uint32 output_surface_id, | 96 uint32 output_surface_id, |
99 scoped_ptr<cc::GLFrameData> gl_frame_data) { | 97 scoped_ptr<cc::GLFrameData> gl_frame_data) { |
100 if (!layout_test_previous_frame_ack_) { | 98 if (!layout_test_previous_frame_ack_) { |
101 layout_test_previous_frame_ack_.reset(new cc::CompositorFrameAck); | 99 layout_test_previous_frame_ack_.reset(new cc::CompositorFrameAck); |
102 layout_test_previous_frame_ack_->gl_frame_data.reset(new cc::GLFrameData); | 100 layout_test_previous_frame_ack_->gl_frame_data.reset(new cc::GLFrameData); |
103 } | 101 } |
104 | 102 |
105 OnSwapAck(output_surface_id, *layout_test_previous_frame_ack_); | 103 OnSwapAck(output_surface_id, *layout_test_previous_frame_ack_); |
106 | 104 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 output_surface_id_, | 147 output_surface_id_, |
150 *frame, | 148 *frame, |
151 messages_to_deliver_with_frame)); | 149 messages_to_deliver_with_frame)); |
152 // ~send_message_scope. | 150 // ~send_message_scope. |
153 } | 151 } |
154 client_->DidSwapBuffers(); | 152 client_->DidSwapBuffers(); |
155 } | 153 } |
156 } | 154 } |
157 | 155 |
158 void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { | 156 void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { |
159 DCHECK(CalledOnValidThread()); | 157 DCHECK(CalledOnValidClientThread()); |
160 if (!HasClient()) | 158 if (!HasClient()) |
161 return; | 159 return; |
162 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message) | 160 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message) |
163 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters, | 161 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters, |
164 OnUpdateVSyncParametersFromBrowser); | 162 OnUpdateVSyncParametersFromBrowser); |
165 IPC_MESSAGE_HANDLER(ViewMsg_SwapCompositorFrameAck, OnSwapAck); | 163 IPC_MESSAGE_HANDLER(ViewMsg_SwapCompositorFrameAck, OnSwapAck); |
166 IPC_MESSAGE_HANDLER(ViewMsg_ReclaimCompositorResources, OnReclaimResources); | 164 IPC_MESSAGE_HANDLER(ViewMsg_ReclaimCompositorResources, OnReclaimResources); |
167 IPC_END_MESSAGE_MAP() | 165 IPC_END_MESSAGE_MAP() |
168 } | 166 } |
169 | 167 |
170 void CompositorOutputSurface::OnUpdateVSyncParametersFromBrowser( | 168 void CompositorOutputSurface::OnUpdateVSyncParametersFromBrowser( |
171 base::TimeTicks timebase, | 169 base::TimeTicks timebase, |
172 base::TimeDelta interval) { | 170 base::TimeDelta interval) { |
173 DCHECK(CalledOnValidThread()); | 171 DCHECK(CalledOnValidClientThread()); |
174 CommitVSyncParameters(timebase, interval); | 172 CommitVSyncParameters(timebase, interval); |
175 } | 173 } |
176 | 174 |
177 void CompositorOutputSurface::OnSwapAck(uint32 output_surface_id, | 175 void CompositorOutputSurface::OnSwapAck(uint32 output_surface_id, |
178 const cc::CompositorFrameAck& ack) { | 176 const cc::CompositorFrameAck& ack) { |
179 // Ignore message if it's a stale one coming from a different output surface | 177 // Ignore message if it's a stale one coming from a different output surface |
180 // (e.g. after a lost context). | 178 // (e.g. after a lost context). |
181 if (output_surface_id != output_surface_id_) | 179 if (output_surface_id != output_surface_id_) |
182 return; | 180 return; |
183 ReclaimResources(&ack); | 181 ReclaimResources(&ack); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 main_thread_runner_->PostTask(FROM_HERE, | 218 main_thread_runner_->PostTask(FROM_HERE, |
221 base::Bind(&SetThreadPriorityToIdle)); | 219 base::Bind(&SetThreadPriorityToIdle)); |
222 } else { | 220 } else { |
223 main_thread_runner_->PostTask(FROM_HERE, | 221 main_thread_runner_->PostTask(FROM_HERE, |
224 base::Bind(&SetThreadPriorityToDefault)); | 222 base::Bind(&SetThreadPriorityToDefault)); |
225 } | 223 } |
226 #endif | 224 #endif |
227 } | 225 } |
228 | 226 |
229 } // namespace content | 227 } // namespace content |
OLD | NEW |