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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 212 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
213 transform.matrix().setColMajorf(new_layer->common.transform.matrix); | 213 transform.matrix().setColMajorf(new_layer->common.transform.matrix); |
214 layer->SetTransform(transform); | 214 layer->SetTransform(transform); |
215 | 215 |
216 // Consider a (0,0,0,0) rect as no clip rect. | 216 // Consider a (0,0,0,0) rect as no clip rect. |
217 if (new_layer->common.clip_rect.point.x != 0 || | 217 if (new_layer->common.clip_rect.point.x != 0 || |
218 new_layer->common.clip_rect.point.y != 0 || | 218 new_layer->common.clip_rect.point.y != 0 || |
219 new_layer->common.clip_rect.size.width != 0 || | 219 new_layer->common.clip_rect.size.width != 0 || |
220 new_layer->common.clip_rect.size.height != 0) { | 220 new_layer->common.clip_rect.size.height != 0) { |
221 scoped_refptr<cc::Layer> clip_parent = layer->parent(); | 221 scoped_refptr<cc::Layer> clip_parent = layer->parent(); |
222 if (clip_parent == layer_) { | 222 if (clip_parent.get() == layer_.get()) { |
223 // Create a clip parent layer, if it does not exist. | 223 // Create a clip parent layer, if it does not exist. |
224 clip_parent = cc::Layer::Create(); | 224 clip_parent = cc::Layer::Create(); |
225 clip_parent->SetMasksToBounds(true); | 225 clip_parent->SetMasksToBounds(true); |
226 clip_parent->SetIsDrawable(true); | 226 clip_parent->SetIsDrawable(true); |
227 layer_->ReplaceChild(layer, clip_parent); | 227 layer_->ReplaceChild(layer.get(), clip_parent); |
228 clip_parent->AddChild(layer); | 228 clip_parent->AddChild(layer); |
229 } | 229 } |
230 gfx::Point position = PP_ToGfxPoint(new_layer->common.clip_rect.point); | 230 gfx::Point position = PP_ToGfxPoint(new_layer->common.clip_rect.point); |
231 clip_parent->SetPosition(position); | 231 clip_parent->SetPosition(position); |
232 clip_parent->SetBounds(PP_ToGfxSize(new_layer->common.clip_rect.size)); | 232 clip_parent->SetBounds(PP_ToGfxSize(new_layer->common.clip_rect.size)); |
233 layer->SetPosition(gfx::Point(-position.x(), -position.y())); | 233 layer->SetPosition(gfx::Point(-position.x(), -position.y())); |
234 } else if (layer->parent() != layer_) { | 234 } else if (layer->parent() != layer_.get()) { |
235 // Remove the clip parent layer. | 235 // Remove the clip parent layer. |
236 layer_->ReplaceChild(layer->parent(), layer); | 236 layer_->ReplaceChild(layer->parent(), layer); |
237 layer->SetPosition(gfx::Point()); | 237 layer->SetPosition(gfx::Point()); |
238 } | 238 } |
239 | 239 |
240 if (new_layer->color) { | 240 if (new_layer->color) { |
241 layer->SetBackgroundColor(SkColorSetARGBMacro( | 241 layer->SetBackgroundColor(SkColorSetARGBMacro( |
242 new_layer->color->alpha * 255, | 242 new_layer->color->alpha * 255, |
243 new_layer->color->red * 255, | 243 new_layer->color->red * 255, |
244 new_layer->color->green * 255, | 244 new_layer->color->green * 255, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 341 |
342 // ResetLayers() has been called, we need rebuild layer stack. | 342 // ResetLayers() has been called, we need rebuild layer stack. |
343 if (reset) { | 343 if (reset) { |
344 layer_->RemoveAllChildren(); | 344 layer_->RemoveAllChildren(); |
345 layers_.clear(); | 345 layers_.clear(); |
346 } | 346 } |
347 | 347 |
348 for (size_t i = 0; i < layers.size(); ++i) { | 348 for (size_t i = 0; i < layers.size(); ++i) { |
349 const ppapi::CompositorLayerData* pp_layer = &layers[i]; | 349 const ppapi::CompositorLayerData* pp_layer = &layers[i]; |
350 LayerData* data = i >= layers_.size() ? NULL : &layers_[i]; | 350 LayerData* data = i >= layers_.size() ? NULL : &layers_[i]; |
351 DCHECK(!data || data->cc_layer); | 351 DCHECK(!data || data->cc_layer.get()); |
352 scoped_refptr<cc::Layer> cc_layer = data ? data->cc_layer : NULL; | 352 scoped_refptr<cc::Layer> cc_layer = data ? data->cc_layer : NULL; |
353 ppapi::CompositorLayerData* old_layer = data ? &data->pp_layer : NULL; | 353 ppapi::CompositorLayerData* old_layer = data ? &data->pp_layer : NULL; |
354 | 354 |
355 if (!cc_layer) { | 355 if (!cc_layer.get()) { |
356 if (pp_layer->color) | 356 if (pp_layer->color) |
357 cc_layer = cc::SolidColorLayer::Create(); | 357 cc_layer = cc::SolidColorLayer::Create(); |
358 else if (pp_layer->texture || pp_layer->image) | 358 else if (pp_layer->texture || pp_layer->image) |
359 cc_layer = cc::TextureLayer::CreateForMailbox(NULL); | 359 cc_layer = cc::TextureLayer::CreateForMailbox(NULL); |
360 layer_->AddChild(cc_layer); | 360 layer_->AddChild(cc_layer); |
361 } | 361 } |
362 | 362 |
363 UpdateLayer(cc_layer, old_layer, pp_layer, image_shms[i].Pass()); | 363 UpdateLayer(cc_layer, old_layer, pp_layer, image_shms[i].Pass()); |
364 | 364 |
365 if (old_layer) | 365 if (old_layer) |
(...skipping 10 matching lines...) Expand all Loading... |
376 | 376 |
377 // If the host is not bound to the instance, return PP_OK immediately. | 377 // If the host is not bound to the instance, return PP_OK immediately. |
378 if (!bound_instance_) | 378 if (!bound_instance_) |
379 return PP_OK; | 379 return PP_OK; |
380 | 380 |
381 commit_layers_reply_context_ = context->MakeReplyMessageContext(); | 381 commit_layers_reply_context_ = context->MakeReplyMessageContext(); |
382 return PP_OK_COMPLETIONPENDING; | 382 return PP_OK_COMPLETIONPENDING; |
383 } | 383 } |
384 | 384 |
385 } // namespace content | 385 } // namespace content |
OLD | NEW |