| 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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 if (!(*image_shm)->Map(desc.stride * desc.size.height)) { | 138 if (!(*image_shm)->Map(desc.stride * desc.size.height)) { |
| 139 image_shm->reset(); | 139 image_shm->reset(); |
| 140 return PP_ERROR_NOMEMORY; | 140 return PP_ERROR_NOMEMORY; |
| 141 } | 141 } |
| 142 return PP_OK; | 142 return PP_OK; |
| 143 } | 143 } |
| 144 | 144 |
| 145 return PP_ERROR_BADARGUMENT; | 145 return PP_ERROR_BADARGUMENT; |
| 146 } | 146 } |
| 147 | 147 |
| 148 cc::LayerSettings g_pepper_layer_settings; |
| 149 |
| 148 } // namespace | 150 } // namespace |
| 149 | 151 |
| 150 PepperCompositorHost::LayerData::LayerData( | 152 PepperCompositorHost::LayerData::LayerData( |
| 151 const scoped_refptr<cc::Layer>& cc, | 153 const scoped_refptr<cc::Layer>& cc, |
| 152 const ppapi::CompositorLayerData& pp) : cc_layer(cc), pp_layer(pp) {} | 154 const ppapi::CompositorLayerData& pp) : cc_layer(cc), pp_layer(pp) {} |
| 153 | 155 |
| 154 PepperCompositorHost::LayerData::~LayerData() {} | 156 PepperCompositorHost::LayerData::~LayerData() {} |
| 155 | 157 |
| 156 PepperCompositorHost::PepperCompositorHost( | 158 PepperCompositorHost::PepperCompositorHost( |
| 157 RendererPpapiHost* host, | 159 RendererPpapiHost* host, |
| 158 PP_Instance instance, | 160 PP_Instance instance, |
| 159 PP_Resource resource) | 161 PP_Resource resource) |
| 160 : ResourceHost(host->GetPpapiHost(), instance, resource), | 162 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 161 bound_instance_(NULL), | 163 bound_instance_(NULL), |
| 162 weak_factory_(this) { | 164 weak_factory_(this) { |
| 163 layer_ = cc::Layer::Create(); | 165 layer_ = cc::Layer::Create(PepperLayerSettings()); |
| 164 // TODO(penghuang): SetMasksToBounds() can be expensive if the layer is | 166 // TODO(penghuang): SetMasksToBounds() can be expensive if the layer is |
| 165 // transformed. Possibly better could be to explicitly clip the child layers | 167 // transformed. Possibly better could be to explicitly clip the child layers |
| 166 // (by modifying their bounds). | 168 // (by modifying their bounds). |
| 167 layer_->SetMasksToBounds(true); | 169 layer_->SetMasksToBounds(true); |
| 168 layer_->SetIsDrawable(true); | 170 layer_->SetIsDrawable(true); |
| 169 } | 171 } |
| 170 | 172 |
| 171 PepperCompositorHost::~PepperCompositorHost() { | 173 PepperCompositorHost::~PepperCompositorHost() { |
| 172 // Unbind from the instance when destroyed if we're still bound. | 174 // Unbind from the instance when destroyed if we're still bound. |
| 173 if (bound_instance_) | 175 if (bound_instance_) |
| 174 bound_instance_->BindGraphics(bound_instance_->pp_instance(), 0); | 176 bound_instance_->BindGraphics(bound_instance_->pp_instance(), 0); |
| 175 } | 177 } |
| 176 | 178 |
| 179 // static |
| 180 const cc::LayerSettings& PepperCompositorHost::PepperLayerSettings() { |
| 181 return g_pepper_layer_settings; |
| 182 } |
| 183 |
| 184 // static |
| 185 void PepperCompositorHost::SetPepperLayerSettings( |
| 186 const cc::LayerSettings& settings) { |
| 187 g_pepper_layer_settings = settings; |
| 188 } |
| 189 |
| 177 bool PepperCompositorHost::BindToInstance( | 190 bool PepperCompositorHost::BindToInstance( |
| 178 PepperPluginInstanceImpl* new_instance) { | 191 PepperPluginInstanceImpl* new_instance) { |
| 179 if (new_instance && new_instance->pp_instance() != pp_instance()) | 192 if (new_instance && new_instance->pp_instance() != pp_instance()) |
| 180 return false; // Can't bind other instance's contexts. | 193 return false; // Can't bind other instance's contexts. |
| 181 if (bound_instance_ == new_instance) | 194 if (bound_instance_ == new_instance) |
| 182 return true; // Rebinding the same device, nothing to do. | 195 return true; // Rebinding the same device, nothing to do. |
| 183 if (bound_instance_ && new_instance) | 196 if (bound_instance_ && new_instance) |
| 184 return false; // Can't change a bound device. | 197 return false; // Can't change a bound device. |
| 185 bound_instance_ = new_instance; | 198 bound_instance_ = new_instance; |
| 186 if (!bound_instance_) | 199 if (!bound_instance_) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 layer->SetTransform(transform); | 253 layer->SetTransform(transform); |
| 241 | 254 |
| 242 // Consider a (0,0,0,0) rect as no clip rect. | 255 // Consider a (0,0,0,0) rect as no clip rect. |
| 243 if (new_layer->common.clip_rect.point.x != 0 || | 256 if (new_layer->common.clip_rect.point.x != 0 || |
| 244 new_layer->common.clip_rect.point.y != 0 || | 257 new_layer->common.clip_rect.point.y != 0 || |
| 245 new_layer->common.clip_rect.size.width != 0 || | 258 new_layer->common.clip_rect.size.width != 0 || |
| 246 new_layer->common.clip_rect.size.height != 0) { | 259 new_layer->common.clip_rect.size.height != 0) { |
| 247 scoped_refptr<cc::Layer> clip_parent = layer->parent(); | 260 scoped_refptr<cc::Layer> clip_parent = layer->parent(); |
| 248 if (clip_parent.get() == layer_.get()) { | 261 if (clip_parent.get() == layer_.get()) { |
| 249 // Create a clip parent layer, if it does not exist. | 262 // Create a clip parent layer, if it does not exist. |
| 250 clip_parent = cc::Layer::Create(); | 263 clip_parent = cc::Layer::Create(PepperLayerSettings()); |
| 251 clip_parent->SetMasksToBounds(true); | 264 clip_parent->SetMasksToBounds(true); |
| 252 clip_parent->SetIsDrawable(true); | 265 clip_parent->SetIsDrawable(true); |
| 253 layer_->ReplaceChild(layer.get(), clip_parent); | 266 layer_->ReplaceChild(layer.get(), clip_parent); |
| 254 clip_parent->AddChild(layer); | 267 clip_parent->AddChild(layer); |
| 255 } | 268 } |
| 256 gfx::Point position = PP_ToGfxPoint(new_layer->common.clip_rect.point); | 269 gfx::Point position = PP_ToGfxPoint(new_layer->common.clip_rect.point); |
| 257 clip_parent->SetPosition(position); | 270 clip_parent->SetPosition(position); |
| 258 clip_parent->SetBounds(PP_ToGfxSize(new_layer->common.clip_rect.size)); | 271 clip_parent->SetBounds(PP_ToGfxSize(new_layer->common.clip_rect.size)); |
| 259 layer->SetPosition(gfx::Point(-position.x(), -position.y())); | 272 layer->SetPosition(gfx::Point(-position.x(), -position.y())); |
| 260 } else if (layer->parent() != layer_.get()) { | 273 } else if (layer->parent() != layer_.get()) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 395 |
| 383 for (size_t i = 0; i < layers.size(); ++i) { | 396 for (size_t i = 0; i < layers.size(); ++i) { |
| 384 const ppapi::CompositorLayerData* pp_layer = &layers[i]; | 397 const ppapi::CompositorLayerData* pp_layer = &layers[i]; |
| 385 LayerData* data = i >= layers_.size() ? NULL : &layers_[i]; | 398 LayerData* data = i >= layers_.size() ? NULL : &layers_[i]; |
| 386 DCHECK(!data || data->cc_layer.get()); | 399 DCHECK(!data || data->cc_layer.get()); |
| 387 scoped_refptr<cc::Layer> cc_layer = data ? data->cc_layer : NULL; | 400 scoped_refptr<cc::Layer> cc_layer = data ? data->cc_layer : NULL; |
| 388 ppapi::CompositorLayerData* old_layer = data ? &data->pp_layer : NULL; | 401 ppapi::CompositorLayerData* old_layer = data ? &data->pp_layer : NULL; |
| 389 | 402 |
| 390 if (!cc_layer.get()) { | 403 if (!cc_layer.get()) { |
| 391 if (pp_layer->color) | 404 if (pp_layer->color) |
| 392 cc_layer = cc::SolidColorLayer::Create(); | 405 cc_layer = cc::SolidColorLayer::Create(PepperLayerSettings()); |
| 393 else if (pp_layer->texture || pp_layer->image) | 406 else if (pp_layer->texture || pp_layer->image) |
| 394 cc_layer = cc::TextureLayer::CreateForMailbox(NULL); | 407 cc_layer = |
| 408 cc::TextureLayer::CreateForMailbox(PepperLayerSettings(), NULL); |
| 395 layer_->AddChild(cc_layer); | 409 layer_->AddChild(cc_layer); |
| 396 } | 410 } |
| 397 | 411 |
| 398 UpdateLayer(cc_layer, old_layer, pp_layer, image_shms[i].Pass()); | 412 UpdateLayer(cc_layer, old_layer, pp_layer, image_shms[i].Pass()); |
| 399 | 413 |
| 400 if (old_layer) | 414 if (old_layer) |
| 401 *old_layer = *pp_layer; | 415 *old_layer = *pp_layer; |
| 402 else | 416 else |
| 403 layers_.push_back(LayerData(cc_layer, *pp_layer)); | 417 layers_.push_back(LayerData(cc_layer, *pp_layer)); |
| 404 } | 418 } |
| 405 | 419 |
| 406 // We need to force a commit for each CommitLayers() call, even if no layers | 420 // We need to force a commit for each CommitLayers() call, even if no layers |
| 407 // changed since the last call to CommitLayers(). This is so | 421 // changed since the last call to CommitLayers(). This is so |
| 408 // WiewInitiatedPaint() will always be called. | 422 // WiewInitiatedPaint() will always be called. |
| 409 if (layer_->layer_tree_host()) | 423 if (layer_->layer_tree_host()) |
| 410 layer_->layer_tree_host()->SetNeedsCommit(); | 424 layer_->layer_tree_host()->SetNeedsCommit(); |
| 411 | 425 |
| 412 // If the host is not bound to the instance, return PP_OK immediately. | 426 // If the host is not bound to the instance, return PP_OK immediately. |
| 413 if (!bound_instance_) | 427 if (!bound_instance_) |
| 414 return PP_OK; | 428 return PP_OK; |
| 415 | 429 |
| 416 commit_layers_reply_context_ = context->MakeReplyMessageContext(); | 430 commit_layers_reply_context_ = context->MakeReplyMessageContext(); |
| 417 return PP_OK_COMPLETIONPENDING; | 431 return PP_OK_COMPLETIONPENDING; |
| 418 } | 432 } |
| 419 | 433 |
| 420 } // namespace content | 434 } // namespace content |
| OLD | NEW |