Chromium Code Reviews| 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" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 if (!(*image_shm)->Map(desc.stride * desc.size.height)) { | 112 if (!(*image_shm)->Map(desc.stride * desc.size.height)) { |
| 113 image_shm->reset(); | 113 image_shm->reset(); |
| 114 return PP_ERROR_NOMEMORY; | 114 return PP_ERROR_NOMEMORY; |
| 115 } | 115 } |
| 116 return PP_OK; | 116 return PP_OK; |
| 117 } | 117 } |
| 118 | 118 |
| 119 return PP_ERROR_BADARGUMENT; | 119 return PP_ERROR_BADARGUMENT; |
| 120 } | 120 } |
| 121 | 121 |
| 122 // cc::Layer::SetNeedsCommit() is a protected method, we have to use a subclass | |
| 123 // to make it assessable. | |
| 124 class ContainerLayer : public cc::Layer { | |
|
piman
2014/06/18 00:55:24
Please don't subclass cc::Layer outside of cc.
Fo
Peng
2014/06/18 02:35:02
Done.
| |
| 125 public: | |
| 126 static scoped_refptr<cc::Layer> Create(); | |
| 127 void ForceToCommit(); | |
| 128 | |
| 129 private: | |
| 130 ContainerLayer() {}; | |
| 131 virtual ~ContainerLayer() {}; | |
| 132 | |
| 133 DISALLOW_COPY_AND_ASSIGN(ContainerLayer); | |
| 134 }; | |
| 135 | |
| 136 scoped_refptr<cc::Layer> ContainerLayer::Create() { | |
| 137 return make_scoped_refptr(new ContainerLayer()); | |
| 138 } | |
| 139 | |
| 140 void ContainerLayer::ForceToCommit() { | |
| 141 SetNeedsCommit(); | |
| 142 } | |
| 143 | |
| 122 } // namespace | 144 } // namespace |
| 123 | 145 |
| 124 PepperCompositorHost::LayerData::LayerData( | 146 PepperCompositorHost::LayerData::LayerData( |
| 125 const scoped_refptr<cc::Layer>& cc, | 147 const scoped_refptr<cc::Layer>& cc, |
| 126 const ppapi::CompositorLayerData& pp) : cc_layer(cc), pp_layer(pp) {} | 148 const ppapi::CompositorLayerData& pp) : cc_layer(cc), pp_layer(pp) {} |
| 127 | 149 |
| 128 PepperCompositorHost::LayerData::~LayerData() {} | 150 PepperCompositorHost::LayerData::~LayerData() {} |
| 129 | 151 |
| 130 PepperCompositorHost::PepperCompositorHost( | 152 PepperCompositorHost::PepperCompositorHost( |
| 131 RendererPpapiHost* host, | 153 RendererPpapiHost* host, |
| 132 PP_Instance instance, | 154 PP_Instance instance, |
| 133 PP_Resource resource) | 155 PP_Resource resource) |
| 134 : ResourceHost(host->GetPpapiHost(), instance, resource), | 156 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 135 bound_instance_(NULL), | 157 bound_instance_(NULL), |
| 136 weak_factory_(this) { | 158 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 } | 159 } |
| 144 | 160 |
| 145 PepperCompositorHost::~PepperCompositorHost() { | 161 PepperCompositorHost::~PepperCompositorHost() { |
| 146 // Unbind from the instance when destroyed if we're still bound. | 162 // Unbind from the instance when destroyed if we're still bound. |
| 147 if (bound_instance_) | 163 if (bound_instance_) |
| 148 bound_instance_->BindGraphics(bound_instance_->pp_instance(), 0); | 164 bound_instance_->BindGraphics(bound_instance_->pp_instance(), 0); |
| 149 } | 165 } |
| 150 | 166 |
| 151 bool PepperCompositorHost::BindToInstance( | 167 bool PepperCompositorHost::BindToInstance( |
| 152 PepperPluginInstanceImpl* new_instance) { | 168 PepperPluginInstanceImpl* new_instance) { |
| 153 if (new_instance && new_instance->pp_instance() != pp_instance()) | 169 if (new_instance && new_instance->pp_instance() != pp_instance()) |
| 154 return false; // Can't bind other instance's contexts. | 170 return false; // Can't bind other instance's contexts. |
| 155 if (bound_instance_ == new_instance) | 171 if (bound_instance_ == new_instance) |
| 156 return true; // Rebinding the same device, nothing to do. | 172 return true; // Rebinding the same device, nothing to do. |
| 157 if (bound_instance_ && new_instance) | 173 if (bound_instance_ && new_instance) |
| 158 return false; // Can't change a bound device. | 174 return false; // Can't change a bound device. |
| 159 bound_instance_ = new_instance; | 175 bound_instance_ = new_instance; |
| 176 layer_ = NULL; | |
| 177 layers_.clear(); | |
| 178 if (bound_instance_) { | |
| 179 layer_ = ContainerLayer::Create(); | |
| 180 // TODO(penghuang): SetMasksToBounds() can be expensive if the layer is | |
| 181 // transformed. Possibly better could be to explicitly clip the child layers | |
| 182 // (by modifying their bounds). | |
|
piman
2014/06/18 00:55:24
Note: what's expensive is not calling SetMasksToBo
Peng
2014/06/18 02:35:02
No. Without this change, the below code will crash
| |
| 183 layer_->SetMasksToBounds(true); | |
| 184 layer_->SetIsDrawable(true); | |
| 185 } | |
| 160 return true; | 186 return true; |
| 187 | |
| 161 } | 188 } |
| 162 | 189 |
| 163 void PepperCompositorHost::ViewInitiatedPaint() { | 190 void PepperCompositorHost::ViewInitiatedPaint() { |
| 164 if (!commit_layers_reply_context_.is_valid()) | 191 if (!commit_layers_reply_context_.is_valid()) |
| 165 return; | 192 return; |
| 166 host()->SendReply(commit_layers_reply_context_, | 193 host()->SendReply(commit_layers_reply_context_, |
| 167 PpapiPluginMsg_Compositor_CommitLayersReply()); | 194 PpapiPluginMsg_Compositor_CommitLayersReply()); |
| 168 commit_layers_reply_context_ = ppapi::host::ReplyMessageContext(); | 195 commit_layers_reply_context_ = ppapi::host::ReplyMessageContext(); |
| 169 } | 196 } |
| 170 | 197 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 } | 386 } |
| 360 | 387 |
| 361 UpdateLayer(cc_layer, old_layer, pp_layer, image_shms[i].Pass()); | 388 UpdateLayer(cc_layer, old_layer, pp_layer, image_shms[i].Pass()); |
| 362 | 389 |
| 363 if (old_layer) | 390 if (old_layer) |
| 364 *old_layer = *pp_layer; | 391 *old_layer = *pp_layer; |
| 365 else | 392 else |
| 366 layers_.push_back(LayerData(cc_layer, *pp_layer)); | 393 layers_.push_back(LayerData(cc_layer, *pp_layer)); |
| 367 } | 394 } |
| 368 | 395 |
| 396 // We need force to commit on the parent layer, so the ViewInitiatedPaint() | |
| 397 // will be always called, even if all layers are not changed from previous | |
| 398 // CommitLayers() call. | |
| 399 (static_cast<ContainerLayer*>(layer_.get()))->ForceToCommit(); | |
| 369 return PP_OK_COMPLETIONPENDING; | 400 return PP_OK_COMPLETIONPENDING; |
| 370 } | 401 } |
| 371 | 402 |
| 372 } // namespace content | 403 } // namespace content |
| OLD | NEW |