OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/browser_plugin/browser_plugin_compositing_helper.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_compositing_helper.h" |
6 | 6 |
7 #include "cc/layers/delegated_renderer_layer.h" | 7 #include "cc/layers/delegated_renderer_layer.h" |
8 #include "cc/layers/solid_color_layer.h" | 8 #include "cc/layers/solid_color_layer.h" |
9 #include "cc/layers/texture_layer.h" | 9 #include "cc/layers/texture_layer.h" |
10 #include "cc/output/context_provider.h" | 10 #include "cc/output/context_provider.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 BrowserPluginManager* manager, | 34 BrowserPluginManager* manager, |
35 int instance_id, | 35 int instance_id, |
36 int host_routing_id) | 36 int host_routing_id) |
37 : instance_id_(instance_id), | 37 : instance_id_(instance_id), |
38 host_routing_id_(host_routing_id), | 38 host_routing_id_(host_routing_id), |
39 last_route_id_(0), | 39 last_route_id_(0), |
40 last_output_surface_id_(0), | 40 last_output_surface_id_(0), |
41 last_host_id_(0), | 41 last_host_id_(0), |
42 last_mailbox_valid_(false), | 42 last_mailbox_valid_(false), |
43 ack_pending_(true), | 43 ack_pending_(true), |
| 44 software_ack_pending_(false), |
44 container_(container), | 45 container_(container), |
45 browser_plugin_manager_(manager) { | 46 browser_plugin_manager_(manager) { |
46 } | 47 } |
47 | 48 |
48 BrowserPluginCompositingHelper::~BrowserPluginCompositingHelper() { | 49 BrowserPluginCompositingHelper::~BrowserPluginCompositingHelper() { |
49 } | 50 } |
50 | 51 |
51 void BrowserPluginCompositingHelper::DidCommitCompositorFrame() { | 52 void BrowserPluginCompositingHelper::DidCommitCompositorFrame() { |
| 53 if (software_ack_pending_) { |
| 54 cc::CompositorFrameAck ack; |
| 55 if (!unacked_software_frames_.empty()) { |
| 56 ack.last_software_frame_id = unacked_software_frames_.back(); |
| 57 unacked_software_frames_.pop_back(); |
| 58 } |
| 59 |
| 60 browser_plugin_manager_->Send( |
| 61 new BrowserPluginHostMsg_CompositorFrameACK( |
| 62 host_routing_id_, |
| 63 instance_id_, |
| 64 last_route_id_, |
| 65 last_output_surface_id_, |
| 66 last_host_id_, |
| 67 ack)); |
| 68 |
| 69 software_ack_pending_ = false; |
| 70 } |
52 if (!delegated_layer_.get() || !ack_pending_) | 71 if (!delegated_layer_.get() || !ack_pending_) |
53 return; | 72 return; |
54 | 73 |
55 cc::CompositorFrameAck ack; | 74 cc::CompositorFrameAck ack; |
56 delegated_layer_->TakeUnusedResourcesForChildCompositor(&ack.resources); | 75 delegated_layer_->TakeUnusedResourcesForChildCompositor(&ack.resources); |
57 | 76 |
58 browser_plugin_manager_->Send( | 77 browser_plugin_manager_->Send( |
59 new BrowserPluginHostMsg_CompositorFrameACK( | 78 new BrowserPluginHostMsg_CompositorFrameACK( |
60 host_routing_id_, | 79 host_routing_id_, |
61 instance_id_, | 80 instance_id_, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // Reset mailbox's name if the resource was lost. | 124 // Reset mailbox's name if the resource was lost. |
106 mailbox.name.SetZero(); | 125 mailbox.name.SetZero(); |
107 } | 126 } |
108 | 127 |
109 // This means the GPU process crashed or guest crashed. | 128 // This means the GPU process crashed or guest crashed. |
110 if (last_host_id_ != mailbox.host_id || | 129 if (last_host_id_ != mailbox.host_id || |
111 last_output_surface_id_ != mailbox.output_surface_id || | 130 last_output_surface_id_ != mailbox.output_surface_id || |
112 last_route_id_ != mailbox.route_id) | 131 last_route_id_ != mailbox.route_id) |
113 return; | 132 return; |
114 | 133 |
| 134 if (mailbox.type == SOFTWARE_COMPOSITOR_FRAME) |
| 135 unacked_software_frames_.push_back(mailbox.software_frame_id); |
| 136 |
115 // We need to send an ACK to for every buffer sent to us. | 137 // We need to send an ACK to for every buffer sent to us. |
116 // However, if a buffer is freed up from | 138 // However, if a buffer is freed up from |
117 // the compositor in cases like switching back to SW mode without a new | 139 // the compositor in cases like switching back to SW mode without a new |
118 // buffer arriving, no ACK is needed. | 140 // buffer arriving, no ACK is needed. |
119 if (!ack_pending_) { | 141 if (!ack_pending_) { |
120 last_mailbox_valid_ = false; | 142 last_mailbox_valid_ = false; |
121 return; | 143 return; |
122 } | 144 } |
123 ack_pending_ = false; | 145 ack_pending_ = false; |
124 switch (mailbox.type) { | 146 switch (mailbox.type) { |
(...skipping 20 matching lines...) Expand all Loading... |
145 browser_plugin_manager_->Send( | 167 browser_plugin_manager_->Send( |
146 new BrowserPluginHostMsg_CompositorFrameACK( | 168 new BrowserPluginHostMsg_CompositorFrameACK( |
147 host_routing_id_, | 169 host_routing_id_, |
148 instance_id_, | 170 instance_id_, |
149 mailbox.route_id, | 171 mailbox.route_id, |
150 mailbox.output_surface_id, | 172 mailbox.output_surface_id, |
151 mailbox.host_id, | 173 mailbox.host_id, |
152 ack)); | 174 ack)); |
153 break; | 175 break; |
154 } | 176 } |
155 case SOFTWARE_COMPOSITOR_FRAME: { | 177 case SOFTWARE_COMPOSITOR_FRAME: |
156 cc::CompositorFrameAck ack; | |
157 ack.last_software_frame_id = mailbox.software_frame_id; | |
158 | |
159 browser_plugin_manager_->Send( | |
160 new BrowserPluginHostMsg_CompositorFrameACK( | |
161 host_routing_id_, | |
162 instance_id_, | |
163 mailbox.route_id, | |
164 mailbox.output_surface_id, | |
165 mailbox.host_id, | |
166 ack)); | |
167 break; | 178 break; |
168 } | |
169 } | 179 } |
170 } | 180 } |
171 | 181 |
172 void BrowserPluginCompositingHelper::OnContainerDestroy() { | 182 void BrowserPluginCompositingHelper::OnContainerDestroy() { |
173 if (container_) | 183 if (container_) |
174 container_->setWebLayer(NULL); | 184 container_->setWebLayer(NULL); |
175 container_ = NULL; | 185 container_ = NULL; |
176 | 186 |
177 texture_layer_ = NULL; | 187 texture_layer_ = NULL; |
178 delegated_layer_ = NULL; | 188 delegated_layer_ = NULL; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 swap_info.host_id = host_id; | 313 swap_info.host_id = host_id; |
304 swap_info.software_frame_id = frame_data->id; | 314 swap_info.software_frame_id = frame_data->id; |
305 | 315 |
306 scoped_ptr<base::SharedMemory> shared_memory( | 316 scoped_ptr<base::SharedMemory> shared_memory( |
307 new base::SharedMemory(frame_data->handle, true)); | 317 new base::SharedMemory(frame_data->handle, true)); |
308 const size_t size_in_bytes = 4 * frame_data->size.GetArea(); | 318 const size_t size_in_bytes = 4 * frame_data->size.GetArea(); |
309 if (!shared_memory->Map(size_in_bytes)) { | 319 if (!shared_memory->Map(size_in_bytes)) { |
310 LOG(ERROR) << "Failed to map shared memory of size " | 320 LOG(ERROR) << "Failed to map shared memory of size " |
311 << size_in_bytes; | 321 << size_in_bytes; |
312 // Send ACK right away. | 322 // Send ACK right away. |
313 ack_pending_ = true; | 323 software_ack_pending_ = true; |
314 MailboxReleased(swap_info, 0, false); | 324 MailboxReleased(swap_info, 0, false); |
| 325 DidCommitCompositorFrame(); |
315 return; | 326 return; |
316 } | 327 } |
317 | 328 |
318 swap_info.shared_memory = shared_memory.release(); | 329 swap_info.shared_memory = shared_memory.release(); |
319 OnBuffersSwappedPrivate(swap_info, 0, | 330 OnBuffersSwappedPrivate(swap_info, 0, |
320 frame->metadata.device_scale_factor); | 331 frame->metadata.device_scale_factor); |
| 332 software_ack_pending_ = true; |
| 333 last_route_id_ = route_id; |
| 334 last_output_surface_id_ = output_surface_id; |
| 335 last_host_id_ = host_id; |
321 return; | 336 return; |
322 } | 337 } |
323 | 338 |
324 DCHECK(!texture_layer_.get()); | 339 DCHECK(!texture_layer_.get()); |
325 if (!delegated_layer_.get()) { | 340 if (!delegated_layer_.get()) { |
326 delegated_layer_ = cc::DelegatedRendererLayer::Create(NULL); | 341 delegated_layer_ = cc::DelegatedRendererLayer::Create(NULL); |
327 delegated_layer_->SetIsDrawable(true); | 342 delegated_layer_->SetIsDrawable(true); |
328 delegated_layer_->SetContentsOpaque(true); | 343 delegated_layer_->SetContentsOpaque(true); |
329 | 344 |
330 background_layer_->AddChild(delegated_layer_); | 345 background_layer_->AddChild(delegated_layer_); |
(...skipping 16 matching lines...) Expand all Loading... |
347 } | 362 } |
348 | 363 |
349 void BrowserPluginCompositingHelper::UpdateVisibility(bool visible) { | 364 void BrowserPluginCompositingHelper::UpdateVisibility(bool visible) { |
350 if (texture_layer_.get()) | 365 if (texture_layer_.get()) |
351 texture_layer_->SetIsDrawable(visible); | 366 texture_layer_->SetIsDrawable(visible); |
352 if (delegated_layer_.get()) | 367 if (delegated_layer_.get()) |
353 delegated_layer_->SetIsDrawable(visible); | 368 delegated_layer_->SetIsDrawable(visible); |
354 } | 369 } |
355 | 370 |
356 } // namespace content | 371 } // namespace content |
OLD | NEW |