| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/shared_memory.h" | 12 #include "base/memory/shared_memory.h" |
| 13 #include "cc/blink/web_layer_impl.h" | 13 #include "cc/blink/web_layer_impl.h" |
| 14 #include "cc/layers/layer.h" | 14 #include "cc/layers/layer.h" |
| 15 #include "cc/layers/layer_settings.h" |
| 15 #include "cc/layers/solid_color_layer.h" | 16 #include "cc/layers/solid_color_layer.h" |
| 16 #include "cc/layers/texture_layer.h" | 17 #include "cc/layers/texture_layer.h" |
| 17 #include "cc/resources/texture_mailbox.h" | 18 #include "cc/resources/texture_mailbox.h" |
| 18 #include "cc/trees/layer_tree_host.h" | 19 #include "cc/trees/layer_tree_host.h" |
| 19 #include "content/child/child_shared_bitmap_manager.h" | 20 #include "content/child/child_shared_bitmap_manager.h" |
| 20 #include "content/child/child_thread_impl.h" | 21 #include "content/child/child_thread_impl.h" |
| 21 #include "content/public/renderer/renderer_ppapi_host.h" | 22 #include "content/public/renderer/renderer_ppapi_host.h" |
| 22 #include "content/renderer/pepper/gfx_conversion.h" | 23 #include "content/renderer/pepper/gfx_conversion.h" |
| 23 #include "content/renderer/pepper/host_globals.h" | 24 #include "content/renderer/pepper/host_globals.h" |
| 24 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 25 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 150 |
| 150 PepperCompositorHost::LayerData::~LayerData() {} | 151 PepperCompositorHost::LayerData::~LayerData() {} |
| 151 | 152 |
| 152 PepperCompositorHost::PepperCompositorHost( | 153 PepperCompositorHost::PepperCompositorHost( |
| 153 RendererPpapiHost* host, | 154 RendererPpapiHost* host, |
| 154 PP_Instance instance, | 155 PP_Instance instance, |
| 155 PP_Resource resource) | 156 PP_Resource resource) |
| 156 : ResourceHost(host->GetPpapiHost(), instance, resource), | 157 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 157 bound_instance_(NULL), | 158 bound_instance_(NULL), |
| 158 weak_factory_(this) { | 159 weak_factory_(this) { |
| 159 layer_ = cc::Layer::Create(cc_blink::WebLayerImpl::LayerSettings()); | 160 layer_ = cc::Layer::Create(cc::LayerSettings()); |
| 160 // TODO(penghuang): SetMasksToBounds() can be expensive if the layer is | 161 // TODO(penghuang): SetMasksToBounds() can be expensive if the layer is |
| 161 // transformed. Possibly better could be to explicitly clip the child layers | 162 // transformed. Possibly better could be to explicitly clip the child layers |
| 162 // (by modifying their bounds). | 163 // (by modifying their bounds). |
| 163 layer_->SetMasksToBounds(true); | 164 layer_->SetMasksToBounds(true); |
| 164 layer_->SetIsDrawable(true); | 165 layer_->SetIsDrawable(true); |
| 165 } | 166 } |
| 166 | 167 |
| 167 PepperCompositorHost::~PepperCompositorHost() { | 168 PepperCompositorHost::~PepperCompositorHost() { |
| 168 // Unbind from the instance when destroyed if we're still bound. | 169 // Unbind from the instance when destroyed if we're still bound. |
| 169 if (bound_instance_) | 170 if (bound_instance_) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 layer->SetTransform(transform); | 237 layer->SetTransform(transform); |
| 237 | 238 |
| 238 // Consider a (0,0,0,0) rect as no clip rect. | 239 // Consider a (0,0,0,0) rect as no clip rect. |
| 239 if (new_layer->common.clip_rect.point.x != 0 || | 240 if (new_layer->common.clip_rect.point.x != 0 || |
| 240 new_layer->common.clip_rect.point.y != 0 || | 241 new_layer->common.clip_rect.point.y != 0 || |
| 241 new_layer->common.clip_rect.size.width != 0 || | 242 new_layer->common.clip_rect.size.width != 0 || |
| 242 new_layer->common.clip_rect.size.height != 0) { | 243 new_layer->common.clip_rect.size.height != 0) { |
| 243 scoped_refptr<cc::Layer> clip_parent = layer->parent(); | 244 scoped_refptr<cc::Layer> clip_parent = layer->parent(); |
| 244 if (clip_parent.get() == layer_.get()) { | 245 if (clip_parent.get() == layer_.get()) { |
| 245 // Create a clip parent layer, if it does not exist. | 246 // Create a clip parent layer, if it does not exist. |
| 246 clip_parent = cc::Layer::Create(cc_blink::WebLayerImpl::LayerSettings()); | 247 clip_parent = cc::Layer::Create(cc::LayerSettings()); |
| 247 clip_parent->SetMasksToBounds(true); | 248 clip_parent->SetMasksToBounds(true); |
| 248 clip_parent->SetIsDrawable(true); | 249 clip_parent->SetIsDrawable(true); |
| 249 layer_->ReplaceChild(layer.get(), clip_parent); | 250 layer_->ReplaceChild(layer.get(), clip_parent); |
| 250 clip_parent->AddChild(layer); | 251 clip_parent->AddChild(layer); |
| 251 } | 252 } |
| 252 auto position = | 253 auto position = |
| 253 gfx::PointF(PP_ToGfxPoint(new_layer->common.clip_rect.point)); | 254 gfx::PointF(PP_ToGfxPoint(new_layer->common.clip_rect.point)); |
| 254 clip_parent->SetPosition(position); | 255 clip_parent->SetPosition(position); |
| 255 clip_parent->SetBounds(PP_ToGfxSize(new_layer->common.clip_rect.size)); | 256 clip_parent->SetBounds(PP_ToGfxSize(new_layer->common.clip_rect.size)); |
| 256 layer->SetPosition(gfx::PointF(-position.x(), -position.y())); | 257 layer->SetPosition(gfx::PointF(-position.x(), -position.y())); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 for (size_t i = 0; i < layers.size(); ++i) { | 381 for (size_t i = 0; i < layers.size(); ++i) { |
| 381 const ppapi::CompositorLayerData* pp_layer = &layers[i]; | 382 const ppapi::CompositorLayerData* pp_layer = &layers[i]; |
| 382 LayerData* data = i >= layers_.size() ? NULL : &layers_[i]; | 383 LayerData* data = i >= layers_.size() ? NULL : &layers_[i]; |
| 383 DCHECK(!data || data->cc_layer.get()); | 384 DCHECK(!data || data->cc_layer.get()); |
| 384 scoped_refptr<cc::Layer> cc_layer = data ? data->cc_layer : NULL; | 385 scoped_refptr<cc::Layer> cc_layer = data ? data->cc_layer : NULL; |
| 385 ppapi::CompositorLayerData* old_layer = data ? &data->pp_layer : NULL; | 386 ppapi::CompositorLayerData* old_layer = data ? &data->pp_layer : NULL; |
| 386 | 387 |
| 387 if (!cc_layer.get()) { | 388 if (!cc_layer.get()) { |
| 388 if (pp_layer->color) | 389 if (pp_layer->color) |
| 389 cc_layer = cc::SolidColorLayer::Create( | 390 cc_layer = cc::SolidColorLayer::Create( |
| 390 cc_blink::WebLayerImpl::LayerSettings()); | 391 cc::LayerSettings()); |
| 391 else if (pp_layer->texture || pp_layer->image) | 392 else if (pp_layer->texture || pp_layer->image) |
| 392 cc_layer = cc::TextureLayer::CreateForMailbox( | 393 cc_layer = cc::TextureLayer::CreateForMailbox( |
| 393 cc_blink::WebLayerImpl::LayerSettings(), NULL); | 394 cc::LayerSettings(), NULL); |
| 394 layer_->AddChild(cc_layer); | 395 layer_->AddChild(cc_layer); |
| 395 } | 396 } |
| 396 | 397 |
| 397 UpdateLayer(cc_layer, old_layer, pp_layer, std::move(image_shms[i])); | 398 UpdateLayer(cc_layer, old_layer, pp_layer, std::move(image_shms[i])); |
| 398 | 399 |
| 399 if (old_layer) | 400 if (old_layer) |
| 400 *old_layer = *pp_layer; | 401 *old_layer = *pp_layer; |
| 401 else | 402 else |
| 402 layers_.push_back(LayerData(cc_layer, *pp_layer)); | 403 layers_.push_back(LayerData(cc_layer, *pp_layer)); |
| 403 } | 404 } |
| 404 | 405 |
| 405 // We need to force a commit for each CommitLayers() call, even if no layers | 406 // We need to force a commit for each CommitLayers() call, even if no layers |
| 406 // changed since the last call to CommitLayers(). This is so | 407 // changed since the last call to CommitLayers(). This is so |
| 407 // WiewInitiatedPaint() will always be called. | 408 // WiewInitiatedPaint() will always be called. |
| 408 if (layer_->layer_tree_host()) | 409 if (layer_->layer_tree_host()) |
| 409 layer_->layer_tree_host()->SetNeedsCommit(); | 410 layer_->layer_tree_host()->SetNeedsCommit(); |
| 410 | 411 |
| 411 // If the host is not bound to the instance, return PP_OK immediately. | 412 // If the host is not bound to the instance, return PP_OK immediately. |
| 412 if (!bound_instance_) | 413 if (!bound_instance_) |
| 413 return PP_OK; | 414 return PP_OK; |
| 414 | 415 |
| 415 commit_layers_reply_context_ = context->MakeReplyMessageContext(); | 416 commit_layers_reply_context_ = context->MakeReplyMessageContext(); |
| 416 return PP_OK_COMPLETIONPENDING; | 417 return PP_OK_COMPLETIONPENDING; |
| 417 } | 418 } |
| 418 | 419 |
| 419 } // namespace content | 420 } // namespace content |
| OLD | NEW |