| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/pepper/pepper_compositor_host.h" | 5 #include "content/renderer/pepper/pepper_compositor_host.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
| 9 #include "cc/layers/layer.h" | 9 #include "cc/layers/layer.h" |
| 10 #include "cc/layers/solid_color_layer.h" | 10 #include "cc/layers/solid_color_layer.h" |
| 11 #include "cc/layers/texture_layer.h" | 11 #include "cc/layers/texture_layer.h" |
| 12 #include "cc/resources/texture_mailbox.h" | 12 #include "cc/resources/texture_mailbox.h" |
| 13 #include "cc/trees/layer_tree_host.h" |
| 13 #include "content/public/renderer/renderer_ppapi_host.h" | 14 #include "content/public/renderer/renderer_ppapi_host.h" |
| 14 #include "content/renderer/pepper/gfx_conversion.h" | 15 #include "content/renderer/pepper/gfx_conversion.h" |
| 15 #include "content/renderer/pepper/host_globals.h" | 16 #include "content/renderer/pepper/host_globals.h" |
| 16 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 17 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 17 #include "content/renderer/pepper/ppb_image_data_impl.h" | 18 #include "content/renderer/pepper/ppb_image_data_impl.h" |
| 18 #include "ppapi/c/pp_errors.h" | 19 #include "ppapi/c/pp_errors.h" |
| 19 #include "ppapi/host/dispatch_host_message.h" | 20 #include "ppapi/host/dispatch_host_message.h" |
| 20 #include "ppapi/host/ppapi_host.h" | 21 #include "ppapi/host/ppapi_host.h" |
| 21 #include "ppapi/proxy/ppapi_messages.h" | 22 #include "ppapi/proxy/ppapi_messages.h" |
| 22 #include "ppapi/thunk/enter.h" | 23 #include "ppapi/thunk/enter.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 128 |
| 128 PepperCompositorHost::LayerData::~LayerData() {} | 129 PepperCompositorHost::LayerData::~LayerData() {} |
| 129 | 130 |
| 130 PepperCompositorHost::PepperCompositorHost( | 131 PepperCompositorHost::PepperCompositorHost( |
| 131 RendererPpapiHost* host, | 132 RendererPpapiHost* host, |
| 132 PP_Instance instance, | 133 PP_Instance instance, |
| 133 PP_Resource resource) | 134 PP_Resource resource) |
| 134 : ResourceHost(host->GetPpapiHost(), instance, resource), | 135 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 135 bound_instance_(NULL), | 136 bound_instance_(NULL), |
| 136 weak_factory_(this) { | 137 weak_factory_(this) { |
| 137 layer_ = cc::Layer::Create(); | |
| 138 // TODO(penghuang): SetMasksToBounds() can be expensive if the layer is | |
| 139 // transformed. Possibly better could be to explicitly clip the child layers | |
| 140 // (by modifying their bounds). | |
| 141 layer_->SetMasksToBounds(true); | |
| 142 layer_->SetIsDrawable(true); | |
| 143 } | 138 } |
| 144 | 139 |
| 145 PepperCompositorHost::~PepperCompositorHost() { | 140 PepperCompositorHost::~PepperCompositorHost() { |
| 146 // Unbind from the instance when destroyed if we're still bound. | 141 // Unbind from the instance when destroyed if we're still bound. |
| 147 if (bound_instance_) | 142 if (bound_instance_) |
| 148 bound_instance_->BindGraphics(bound_instance_->pp_instance(), 0); | 143 bound_instance_->BindGraphics(bound_instance_->pp_instance(), 0); |
| 149 } | 144 } |
| 150 | 145 |
| 151 bool PepperCompositorHost::BindToInstance( | 146 bool PepperCompositorHost::BindToInstance( |
| 152 PepperPluginInstanceImpl* new_instance) { | 147 PepperPluginInstanceImpl* new_instance) { |
| 153 if (new_instance && new_instance->pp_instance() != pp_instance()) | 148 if (new_instance && new_instance->pp_instance() != pp_instance()) |
| 154 return false; // Can't bind other instance's contexts. | 149 return false; // Can't bind other instance's contexts. |
| 155 if (bound_instance_ == new_instance) | 150 if (bound_instance_ == new_instance) |
| 156 return true; // Rebinding the same device, nothing to do. | 151 return true; // Rebinding the same device, nothing to do. |
| 157 if (bound_instance_ && new_instance) | 152 if (bound_instance_ && new_instance) |
| 158 return false; // Can't change a bound device. | 153 return false; // Can't change a bound device. |
| 159 bound_instance_ = new_instance; | 154 bound_instance_ = new_instance; |
| 155 layer_ = NULL; |
| 156 layers_.clear(); |
| 157 if (bound_instance_) { |
| 158 layer_ = cc::Layer::Create(); |
| 159 // TODO(penghuang): SetMasksToBounds() can be expensive if the layer is |
| 160 // transformed. Possibly better could be to explicitly clip the child layers |
| 161 // (by modifying their bounds). |
| 162 layer_->SetMasksToBounds(true); |
| 163 layer_->SetIsDrawable(true); |
| 164 } |
| 160 return true; | 165 return true; |
| 166 |
| 161 } | 167 } |
| 162 | 168 |
| 163 void PepperCompositorHost::ViewInitiatedPaint() { | 169 void PepperCompositorHost::ViewInitiatedPaint() { |
| 164 if (!commit_layers_reply_context_.is_valid()) | 170 if (!commit_layers_reply_context_.is_valid()) |
| 165 return; | 171 return; |
| 166 host()->SendReply(commit_layers_reply_context_, | 172 host()->SendReply(commit_layers_reply_context_, |
| 167 PpapiPluginMsg_Compositor_CommitLayersReply()); | 173 PpapiPluginMsg_Compositor_CommitLayersReply()); |
| 168 commit_layers_reply_context_ = ppapi::host::ReplyMessageContext(); | 174 commit_layers_reply_context_ = ppapi::host::ReplyMessageContext(); |
| 169 } | 175 } |
| 170 | 176 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 } | 365 } |
| 360 | 366 |
| 361 UpdateLayer(cc_layer, old_layer, pp_layer, image_shms[i].Pass()); | 367 UpdateLayer(cc_layer, old_layer, pp_layer, image_shms[i].Pass()); |
| 362 | 368 |
| 363 if (old_layer) | 369 if (old_layer) |
| 364 *old_layer = *pp_layer; | 370 *old_layer = *pp_layer; |
| 365 else | 371 else |
| 366 layers_.push_back(LayerData(cc_layer, *pp_layer)); | 372 layers_.push_back(LayerData(cc_layer, *pp_layer)); |
| 367 } | 373 } |
| 368 | 374 |
| 375 // We need force to commit on the parent layer, so the ViewInitiatedPaint() |
| 376 // will be always called, even if all layers are not changed from previous |
| 377 // CommitLayers() call. |
| 378 if (layer_->layer_tree_host()) |
| 379 layer_->layer_tree_host()->SetNeedsCommit(); |
| 369 return PP_OK_COMPLETIONPENDING; | 380 return PP_OK_COMPLETIONPENDING; |
| 370 } | 381 } |
| 371 | 382 |
| 372 } // namespace content | 383 } // namespace content |
| OLD | NEW |