| 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 22 matching lines...) Expand all Loading... |
| 33 ack_pending_(true), | 33 ack_pending_(true), |
| 34 ack_pending_for_crashed_guest_(false), | 34 ack_pending_for_crashed_guest_(false), |
| 35 container_(container), | 35 container_(container), |
| 36 browser_plugin_manager_(manager) { | 36 browser_plugin_manager_(manager) { |
| 37 } | 37 } |
| 38 | 38 |
| 39 BrowserPluginCompositingHelper::~BrowserPluginCompositingHelper() { | 39 BrowserPluginCompositingHelper::~BrowserPluginCompositingHelper() { |
| 40 } | 40 } |
| 41 | 41 |
| 42 void BrowserPluginCompositingHelper::DidCommitCompositorFrame() { | 42 void BrowserPluginCompositingHelper::DidCommitCompositorFrame() { |
| 43 if (!delegated_layer_ || !ack_pending_) | 43 if (!delegated_layer_.get() || !ack_pending_) |
| 44 return; | 44 return; |
| 45 | 45 |
| 46 cc::CompositorFrameAck ack; | 46 cc::CompositorFrameAck ack; |
| 47 delegated_layer_->TakeUnusedResourcesForChildCompositor(&ack.resources); | 47 delegated_layer_->TakeUnusedResourcesForChildCompositor(&ack.resources); |
| 48 | 48 |
| 49 browser_plugin_manager_->Send( | 49 browser_plugin_manager_->Send( |
| 50 new BrowserPluginHostMsg_CompositorFrameACK( | 50 new BrowserPluginHostMsg_CompositorFrameACK( |
| 51 host_routing_id_, | 51 host_routing_id_, |
| 52 instance_id_, | 52 instance_id_, |
| 53 last_route_id_, | 53 last_route_id_, |
| 54 last_host_id_, | 54 last_host_id_, |
| 55 ack)); | 55 ack)); |
| 56 | 56 |
| 57 ack_pending_ = false; | 57 ack_pending_ = false; |
| 58 } | 58 } |
| 59 | 59 |
| 60 void BrowserPluginCompositingHelper::EnableCompositing(bool enable) { | 60 void BrowserPluginCompositingHelper::EnableCompositing(bool enable) { |
| 61 if (enable && !background_layer_) { | 61 if (enable && !background_layer_.get()) { |
| 62 background_layer_ = cc::SolidColorLayer::Create(); | 62 background_layer_ = cc::SolidColorLayer::Create(); |
| 63 background_layer_->SetMasksToBounds(true); | 63 background_layer_->SetMasksToBounds(true); |
| 64 background_layer_->SetBackgroundColor( | 64 background_layer_->SetBackgroundColor( |
| 65 SkColorSetARGBInline(255, 255, 255, 255)); | 65 SkColorSetARGBInline(255, 255, 255, 255)); |
| 66 web_layer_.reset(new webkit::WebLayerImpl(background_layer_)); | 66 web_layer_.reset(new webkit::WebLayerImpl(background_layer_)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 container_->setWebLayer(enable ? web_layer_.get() : NULL); | 69 container_->setWebLayer(enable ? web_layer_.get() : NULL); |
| 70 } | 70 } |
| 71 | 71 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 92 // We use a shared graphics context accessible from the main | 92 // We use a shared graphics context accessible from the main |
| 93 // thread to do it. | 93 // thread to do it. |
| 94 void BrowserPluginCompositingHelper::FreeMailboxMemory( | 94 void BrowserPluginCompositingHelper::FreeMailboxMemory( |
| 95 const std::string& mailbox_name, | 95 const std::string& mailbox_name, |
| 96 unsigned sync_point) { | 96 unsigned sync_point) { |
| 97 if (mailbox_name.empty()) | 97 if (mailbox_name.empty()) |
| 98 return; | 98 return; |
| 99 | 99 |
| 100 scoped_refptr<cc::ContextProvider> context_provider = | 100 scoped_refptr<cc::ContextProvider> context_provider = |
| 101 RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); | 101 RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); |
| 102 if (!context_provider) | 102 if (!context_provider.get()) |
| 103 return; | 103 return; |
| 104 | 104 |
| 105 WebKit::WebGraphicsContext3D *context = context_provider->Context3d(); | 105 WebKit::WebGraphicsContext3D *context = context_provider->Context3d(); |
| 106 // When a buffer is released from the compositor, we also get a | 106 // When a buffer is released from the compositor, we also get a |
| 107 // sync point that specifies when in the command buffer | 107 // sync point that specifies when in the command buffer |
| 108 // it's safe to use it again. | 108 // it's safe to use it again. |
| 109 // If the sync point is non-zero, we need to tell our context | 109 // If the sync point is non-zero, we need to tell our context |
| 110 // to wait until this sync point is reached before we can safely | 110 // to wait until this sync point is reached before we can safely |
| 111 // delete the buffer. | 111 // delete the buffer. |
| 112 if (sync_point) | 112 if (sync_point) |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 background_layer_ = NULL; | 188 background_layer_ = NULL; |
| 189 web_layer_.reset(); | 189 web_layer_.reset(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void BrowserPluginCompositingHelper::OnBuffersSwapped( | 192 void BrowserPluginCompositingHelper::OnBuffersSwapped( |
| 193 const gfx::Size& size, | 193 const gfx::Size& size, |
| 194 const std::string& mailbox_name, | 194 const std::string& mailbox_name, |
| 195 int gpu_route_id, | 195 int gpu_route_id, |
| 196 int gpu_host_id, | 196 int gpu_host_id, |
| 197 float device_scale_factor) { | 197 float device_scale_factor) { |
| 198 DCHECK(!delegated_layer_); | 198 DCHECK(!delegated_layer_.get()); |
| 199 // If the guest crashed but the GPU process didn't, we may still have | 199 // If the guest crashed but the GPU process didn't, we may still have |
| 200 // a transport surface waiting on an ACK, which we must send to | 200 // a transport surface waiting on an ACK, which we must send to |
| 201 // avoid leaking. | 201 // avoid leaking. |
| 202 if (last_route_id_ != gpu_route_id && last_host_id_ == gpu_host_id) | 202 if (last_route_id_ != gpu_route_id && last_host_id_ == gpu_host_id) |
| 203 ack_pending_for_crashed_guest_ = ack_pending_; | 203 ack_pending_for_crashed_guest_ = ack_pending_; |
| 204 | 204 |
| 205 // If these mismatch, we are either just starting up, GPU process crashed or | 205 // If these mismatch, we are either just starting up, GPU process crashed or |
| 206 // guest renderer crashed. | 206 // guest renderer crashed. |
| 207 // In this case, we are communicating with a new image transport | 207 // In this case, we are communicating with a new image transport |
| 208 // surface and must ACK with the new ID's and an empty mailbox. | 208 // surface and must ACK with the new ID's and an empty mailbox. |
| 209 if (last_route_id_ != gpu_route_id || last_host_id_ != gpu_host_id) | 209 if (last_route_id_ != gpu_route_id || last_host_id_ != gpu_host_id) |
| 210 last_mailbox_valid_ = false; | 210 last_mailbox_valid_ = false; |
| 211 | 211 |
| 212 last_route_id_ = gpu_route_id; | 212 last_route_id_ = gpu_route_id; |
| 213 last_host_id_ = gpu_host_id; | 213 last_host_id_ = gpu_host_id; |
| 214 | 214 |
| 215 ack_pending_ = true; | 215 ack_pending_ = true; |
| 216 // Browser plugin getting destroyed, do a fast ACK. | 216 // Browser plugin getting destroyed, do a fast ACK. |
| 217 if (!background_layer_) { | 217 if (!background_layer_.get()) { |
| 218 MailboxReleased(mailbox_name, gpu_route_id, gpu_host_id, 0, false); | 218 MailboxReleased(mailbox_name, gpu_route_id, gpu_host_id, 0, false); |
| 219 return; | 219 return; |
| 220 } | 220 } |
| 221 | 221 |
| 222 if (!texture_layer_) { | 222 if (!texture_layer_.get()) { |
| 223 texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL); | 223 texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL); |
| 224 texture_layer_->SetIsDrawable(true); | 224 texture_layer_->SetIsDrawable(true); |
| 225 texture_layer_->SetContentsOpaque(true); | 225 texture_layer_->SetContentsOpaque(true); |
| 226 | 226 |
| 227 background_layer_->AddChild(texture_layer_); | 227 background_layer_->AddChild(texture_layer_); |
| 228 } | 228 } |
| 229 | 229 |
| 230 // The size of browser plugin container is not always equal to the size | 230 // The size of browser plugin container is not always equal to the size |
| 231 // of the buffer that arrives here. This could be for a number of reasons, | 231 // of the buffer that arrives here. This could be for a number of reasons, |
| 232 // including autosize and a resize in progress. | 232 // including autosize and a resize in progress. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 259 texture_layer_->SetTextureMailbox(cc::TextureMailbox(mailbox_name, | 259 texture_layer_->SetTextureMailbox(cc::TextureMailbox(mailbox_name, |
| 260 callback)); | 260 callback)); |
| 261 texture_layer_->SetNeedsDisplay(); | 261 texture_layer_->SetNeedsDisplay(); |
| 262 last_mailbox_valid_ = current_mailbox_valid; | 262 last_mailbox_valid_ = current_mailbox_valid; |
| 263 } | 263 } |
| 264 | 264 |
| 265 void BrowserPluginCompositingHelper::OnCompositorFrameSwapped( | 265 void BrowserPluginCompositingHelper::OnCompositorFrameSwapped( |
| 266 scoped_ptr<cc::CompositorFrame> frame, | 266 scoped_ptr<cc::CompositorFrame> frame, |
| 267 int route_id, | 267 int route_id, |
| 268 int host_id) { | 268 int host_id) { |
| 269 DCHECK(!texture_layer_); | 269 DCHECK(!texture_layer_.get()); |
| 270 if (!delegated_layer_) { | 270 if (!delegated_layer_.get()) { |
| 271 delegated_layer_ = cc::DelegatedRendererLayer::Create(NULL); | 271 delegated_layer_ = cc::DelegatedRendererLayer::Create(NULL); |
| 272 delegated_layer_->SetIsDrawable(true); | 272 delegated_layer_->SetIsDrawable(true); |
| 273 delegated_layer_->SetContentsOpaque(true); | 273 delegated_layer_->SetContentsOpaque(true); |
| 274 | 274 |
| 275 background_layer_->AddChild(delegated_layer_); | 275 background_layer_->AddChild(delegated_layer_); |
| 276 } | 276 } |
| 277 | 277 |
| 278 cc::DelegatedFrameData *frame_data = frame->delegated_frame_data.get(); | 278 cc::DelegatedFrameData *frame_data = frame->delegated_frame_data.get(); |
| 279 if (!frame_data) | 279 if (!frame_data) |
| 280 return; | 280 return; |
| 281 | 281 |
| 282 CheckSizeAndAdjustLayerBounds( | 282 CheckSizeAndAdjustLayerBounds( |
| 283 frame_data->render_pass_list.back()->output_rect.size(), | 283 frame_data->render_pass_list.back()->output_rect.size(), |
| 284 frame->metadata.device_scale_factor, | 284 frame->metadata.device_scale_factor, |
| 285 delegated_layer_.get()); | 285 delegated_layer_.get()); |
| 286 | 286 |
| 287 delegated_layer_->SetFrameData(frame->delegated_frame_data.Pass()); | 287 delegated_layer_->SetFrameData(frame->delegated_frame_data.Pass()); |
| 288 last_route_id_ = route_id; | 288 last_route_id_ = route_id; |
| 289 last_host_id_ = host_id; | 289 last_host_id_ = host_id; |
| 290 ack_pending_ = true; | 290 ack_pending_ = true; |
| 291 } | 291 } |
| 292 | 292 |
| 293 void BrowserPluginCompositingHelper::UpdateVisibility(bool visible) { | 293 void BrowserPluginCompositingHelper::UpdateVisibility(bool visible) { |
| 294 if (texture_layer_) | 294 if (texture_layer_.get()) |
| 295 texture_layer_->SetIsDrawable(visible); | 295 texture_layer_->SetIsDrawable(visible); |
| 296 if (delegated_layer_) | 296 if (delegated_layer_.get()) |
| 297 delegated_layer_->SetIsDrawable(visible); | 297 delegated_layer_->SetIsDrawable(visible); |
| 298 } | 298 } |
| 299 | 299 |
| 300 } // namespace content | 300 } // namespace content |
| OLD | NEW |