| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/compositor/layer.h" | 5 #include "ui/compositor/layer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 if (compositor_) | 105 if (compositor_) |
| 106 compositor_->SetRootLayer(NULL); | 106 compositor_->SetRootLayer(NULL); |
| 107 if (parent_) | 107 if (parent_) |
| 108 parent_->Remove(this); | 108 parent_->Remove(this); |
| 109 if (layer_mask_) | 109 if (layer_mask_) |
| 110 SetMaskLayer(NULL); | 110 SetMaskLayer(NULL); |
| 111 if (layer_mask_back_link_) | 111 if (layer_mask_back_link_) |
| 112 layer_mask_back_link_->SetMaskLayer(NULL); | 112 layer_mask_back_link_->SetMaskLayer(NULL); |
| 113 for (size_t i = 0; i < children_.size(); ++i) | 113 for (size_t i = 0; i < children_.size(); ++i) |
| 114 children_[i]->parent_ = NULL; | 114 children_[i]->parent_ = NULL; |
| 115 cc_layer_->removeLayerAnimationEventObserver(this); | 115 cc_layer_->RemoveLayerAnimationEventObserver(this); |
| 116 cc_layer_->removeFromParent(); | 116 cc_layer_->RemoveFromParent(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 Compositor* Layer::GetCompositor() { | 119 Compositor* Layer::GetCompositor() { |
| 120 return GetRoot(this)->compositor_; | 120 return GetRoot(this)->compositor_; |
| 121 } | 121 } |
| 122 | 122 |
| 123 float Layer::opacity() const { | 123 float Layer::opacity() const { |
| 124 return cc_layer_->opacity(); | 124 return cc_layer_->opacity(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void Layer::SetCompositor(Compositor* compositor) { | 127 void Layer::SetCompositor(Compositor* compositor) { |
| 128 // This function must only be called to set the compositor on the root layer, | 128 // This function must only be called to set the compositor on the root layer, |
| 129 // or to reset it. | 129 // or to reset it. |
| 130 DCHECK(!compositor || !compositor_); | 130 DCHECK(!compositor || !compositor_); |
| 131 DCHECK(!compositor || compositor->root_layer() == this); | 131 DCHECK(!compositor || compositor->root_layer() == this); |
| 132 DCHECK(!parent_); | 132 DCHECK(!parent_); |
| 133 compositor_ = compositor; | 133 compositor_ = compositor; |
| 134 if (compositor) { | 134 if (compositor) { |
| 135 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); | 135 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); |
| 136 SendPendingThreadedAnimations(); | 136 SendPendingThreadedAnimations(); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 void Layer::Add(Layer* child) { | 140 void Layer::Add(Layer* child) { |
| 141 DCHECK(!child->compositor_); | 141 DCHECK(!child->compositor_); |
| 142 if (child->parent_) | 142 if (child->parent_) |
| 143 child->parent_->Remove(child); | 143 child->parent_->Remove(child); |
| 144 child->parent_ = this; | 144 child->parent_ = this; |
| 145 children_.push_back(child); | 145 children_.push_back(child); |
| 146 cc_layer_->addChild(child->cc_layer_); | 146 cc_layer_->AddChild(child->cc_layer_); |
| 147 child->OnDeviceScaleFactorChanged(device_scale_factor_); | 147 child->OnDeviceScaleFactorChanged(device_scale_factor_); |
| 148 child->UpdateIsDrawn(); | 148 child->UpdateIsDrawn(); |
| 149 if (GetCompositor()) | 149 if (GetCompositor()) |
| 150 child->SendPendingThreadedAnimations(); | 150 child->SendPendingThreadedAnimations(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void Layer::Remove(Layer* child) { | 153 void Layer::Remove(Layer* child) { |
| 154 std::vector<Layer*>::iterator i = | 154 std::vector<Layer*>::iterator i = |
| 155 std::find(children_.begin(), children_.end(), child); | 155 std::find(children_.begin(), children_.end(), child); |
| 156 DCHECK(i != children_.end()); | 156 DCHECK(i != children_.end()); |
| 157 children_.erase(i); | 157 children_.erase(i); |
| 158 child->parent_ = NULL; | 158 child->parent_ = NULL; |
| 159 child->cc_layer_->removeFromParent(); | 159 child->cc_layer_->RemoveFromParent(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void Layer::StackAtTop(Layer* child) { | 162 void Layer::StackAtTop(Layer* child) { |
| 163 if (children_.size() <= 1 || child == children_.back()) | 163 if (children_.size() <= 1 || child == children_.back()) |
| 164 return; // Already in front. | 164 return; // Already in front. |
| 165 StackAbove(child, children_.back()); | 165 StackAbove(child, children_.back()); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void Layer::StackAbove(Layer* child, Layer* other) { | 168 void Layer::StackAbove(Layer* child, Layer* other) { |
| 169 StackRelativeTo(child, other, true); | 169 StackRelativeTo(child, other, true); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 217 |
| 218 gfx::Rect Layer::GetTargetBounds() const { | 218 gfx::Rect Layer::GetTargetBounds() const { |
| 219 if (animator_.get() && animator_->IsAnimatingProperty( | 219 if (animator_.get() && animator_->IsAnimatingProperty( |
| 220 LayerAnimationElement::BOUNDS)) { | 220 LayerAnimationElement::BOUNDS)) { |
| 221 return animator_->GetTargetBounds(); | 221 return animator_->GetTargetBounds(); |
| 222 } | 222 } |
| 223 return bounds_; | 223 return bounds_; |
| 224 } | 224 } |
| 225 | 225 |
| 226 void Layer::SetMasksToBounds(bool masks_to_bounds) { | 226 void Layer::SetMasksToBounds(bool masks_to_bounds) { |
| 227 cc_layer_->setMasksToBounds(masks_to_bounds); | 227 cc_layer_->SetMasksToBounds(masks_to_bounds); |
| 228 } | 228 } |
| 229 | 229 |
| 230 bool Layer::GetMasksToBounds() const { | 230 bool Layer::GetMasksToBounds() const { |
| 231 return cc_layer_->masksToBounds(); | 231 return cc_layer_->masks_to_bounds(); |
| 232 } | 232 } |
| 233 | 233 |
| 234 void Layer::SetOpacity(float opacity) { | 234 void Layer::SetOpacity(float opacity) { |
| 235 GetAnimator()->SetOpacity(opacity); | 235 GetAnimator()->SetOpacity(opacity); |
| 236 } | 236 } |
| 237 | 237 |
| 238 float Layer::GetCombinedOpacity() const { | 238 float Layer::GetCombinedOpacity() const { |
| 239 float opacity = this->opacity(); | 239 float opacity = this->opacity(); |
| 240 Layer* current = this->parent_; | 240 Layer* current = this->parent_; |
| 241 while (current) { | 241 while (current) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 layer_mask->children().empty() && | 292 layer_mask->children().empty() && |
| 293 !layer_mask->layer_mask_back_link_)); | 293 !layer_mask->layer_mask_back_link_)); |
| 294 DCHECK(!layer_mask_back_link_); | 294 DCHECK(!layer_mask_back_link_); |
| 295 if (layer_mask_ == layer_mask) | 295 if (layer_mask_ == layer_mask) |
| 296 return; | 296 return; |
| 297 // We need to de-reference the currently linked object so that no problem | 297 // We need to de-reference the currently linked object so that no problem |
| 298 // arises if the mask layer gets deleted before this object. | 298 // arises if the mask layer gets deleted before this object. |
| 299 if (layer_mask_) | 299 if (layer_mask_) |
| 300 layer_mask_->layer_mask_back_link_ = NULL; | 300 layer_mask_->layer_mask_back_link_ = NULL; |
| 301 layer_mask_ = layer_mask; | 301 layer_mask_ = layer_mask; |
| 302 cc_layer_->setMaskLayer( | 302 cc_layer_->SetMaskLayer( |
| 303 layer_mask ? layer_mask->cc_layer() : NULL); | 303 layer_mask ? layer_mask->cc_layer() : NULL); |
| 304 // We need to reference the linked object so that it can properly break the | 304 // We need to reference the linked object so that it can properly break the |
| 305 // link to us when it gets deleted. | 305 // link to us when it gets deleted. |
| 306 if (layer_mask) { | 306 if (layer_mask) { |
| 307 layer_mask->layer_mask_back_link_ = this; | 307 layer_mask->layer_mask_back_link_ = this; |
| 308 layer_mask->OnDeviceScaleFactorChanged(device_scale_factor_); | 308 layer_mask->OnDeviceScaleFactorChanged(device_scale_factor_); |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 | 311 |
| 312 void Layer::SetBackgroundZoom(float x_offset, | 312 void Layer::SetBackgroundZoom(float x_offset, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 334 if (layer_inverted_) | 334 if (layer_inverted_) |
| 335 filters.append(WebKit::WebFilterOperation::createInvertFilter(1.0)); | 335 filters.append(WebKit::WebFilterOperation::createInvertFilter(1.0)); |
| 336 // Brightness goes last, because the resulting colors neeed clamping, which | 336 // Brightness goes last, because the resulting colors neeed clamping, which |
| 337 // cause further color matrix filters to be applied separately. In this order, | 337 // cause further color matrix filters to be applied separately. In this order, |
| 338 // they all can be combined in a single pass. | 338 // they all can be combined in a single pass. |
| 339 if (layer_brightness_) { | 339 if (layer_brightness_) { |
| 340 filters.append(WebKit::WebFilterOperation::createSaturatingBrightnessFilter( | 340 filters.append(WebKit::WebFilterOperation::createSaturatingBrightnessFilter( |
| 341 layer_brightness_)); | 341 layer_brightness_)); |
| 342 } | 342 } |
| 343 | 343 |
| 344 cc_layer_->setFilters(filters); | 344 cc_layer_->SetFilters(filters); |
| 345 } | 345 } |
| 346 | 346 |
| 347 void Layer::SetLayerBackgroundFilters() { | 347 void Layer::SetLayerBackgroundFilters() { |
| 348 WebKit::WebFilterOperations filters; | 348 WebKit::WebFilterOperations filters; |
| 349 if (zoom_ != 1) { | 349 if (zoom_ != 1) { |
| 350 filters.append(WebKit::WebFilterOperation::createZoomFilter( | 350 filters.append(WebKit::WebFilterOperation::createZoomFilter( |
| 351 WebKit::WebRect(zoom_x_offset_, zoom_y_offset_, | 351 WebKit::WebRect(zoom_x_offset_, zoom_y_offset_, |
| 352 (GetTargetBounds().width() / zoom_), | 352 (GetTargetBounds().width() / zoom_), |
| 353 (GetTargetBounds().height() / zoom_)), | 353 (GetTargetBounds().height() / zoom_)), |
| 354 zoom_inset_)); | 354 zoom_inset_)); |
| 355 } | 355 } |
| 356 | 356 |
| 357 if (background_blur_radius_) { | 357 if (background_blur_radius_) { |
| 358 filters.append(WebKit::WebFilterOperation::createBlurFilter( | 358 filters.append(WebKit::WebFilterOperation::createBlurFilter( |
| 359 background_blur_radius_)); | 359 background_blur_radius_)); |
| 360 } | 360 } |
| 361 | 361 |
| 362 cc_layer_->setBackgroundFilters(filters); | 362 cc_layer_->SetBackgroundFilters(filters); |
| 363 } | 363 } |
| 364 | 364 |
| 365 float Layer::GetTargetOpacity() const { | 365 float Layer::GetTargetOpacity() const { |
| 366 if (animator_.get() && animator_->IsAnimatingProperty( | 366 if (animator_.get() && animator_->IsAnimatingProperty( |
| 367 LayerAnimationElement::OPACITY)) | 367 LayerAnimationElement::OPACITY)) |
| 368 return animator_->GetTargetOpacity(); | 368 return animator_->GetTargetOpacity(); |
| 369 return opacity(); | 369 return opacity(); |
| 370 } | 370 } |
| 371 | 371 |
| 372 void Layer::SetVisible(bool visible) { | 372 void Layer::SetVisible(bool visible) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 384 return is_drawn_; | 384 return is_drawn_; |
| 385 } | 385 } |
| 386 | 386 |
| 387 void Layer::UpdateIsDrawn() { | 387 void Layer::UpdateIsDrawn() { |
| 388 bool updated_is_drawn = visible_ && (!parent_ || parent_->IsDrawn()); | 388 bool updated_is_drawn = visible_ && (!parent_ || parent_->IsDrawn()); |
| 389 | 389 |
| 390 if (updated_is_drawn == is_drawn_) | 390 if (updated_is_drawn == is_drawn_) |
| 391 return; | 391 return; |
| 392 | 392 |
| 393 is_drawn_ = updated_is_drawn; | 393 is_drawn_ = updated_is_drawn; |
| 394 cc_layer_->setIsDrawable(is_drawn_ && type_ != LAYER_NOT_DRAWN); | 394 cc_layer_->SetIsDrawable(is_drawn_ && type_ != LAYER_NOT_DRAWN); |
| 395 | 395 |
| 396 for (size_t i = 0; i < children_.size(); ++i) { | 396 for (size_t i = 0; i < children_.size(); ++i) { |
| 397 children_[i]->UpdateIsDrawn(); | 397 children_[i]->UpdateIsDrawn(); |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 | 400 |
| 401 bool Layer::ShouldDraw() const { | 401 bool Layer::ShouldDraw() const { |
| 402 return type_ != LAYER_NOT_DRAWN && GetCombinedOpacity() > 0.0f; | 402 return type_ != LAYER_NOT_DRAWN && GetCombinedOpacity() > 0.0f; |
| 403 } | 403 } |
| 404 | 404 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 417 if (target != root_layer) | 417 if (target != root_layer) |
| 418 target->ConvertPointFromAncestor(root_layer, point); | 418 target->ConvertPointFromAncestor(root_layer, point); |
| 419 } | 419 } |
| 420 | 420 |
| 421 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { | 421 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { |
| 422 if (fills_bounds_opaquely_ == fills_bounds_opaquely) | 422 if (fills_bounds_opaquely_ == fills_bounds_opaquely) |
| 423 return; | 423 return; |
| 424 | 424 |
| 425 fills_bounds_opaquely_ = fills_bounds_opaquely; | 425 fills_bounds_opaquely_ = fills_bounds_opaquely; |
| 426 | 426 |
| 427 cc_layer_->setContentsOpaque(fills_bounds_opaquely); | 427 cc_layer_->SetContentsOpaque(fills_bounds_opaquely); |
| 428 } | 428 } |
| 429 | 429 |
| 430 void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { | 430 void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { |
| 431 if (texture_layer_.get()) | 431 if (texture_layer_.get()) |
| 432 texture_layer_->willModifyTexture(); | 432 texture_layer_->willModifyTexture(); |
| 433 // TODO(piman): delegated_renderer_layer_ cleanup. | 433 // TODO(piman): delegated_renderer_layer_ cleanup. |
| 434 | 434 |
| 435 cc_layer_->removeAllChildren(); | 435 cc_layer_->RemoveAllChildren(); |
| 436 if (parent_) { | 436 if (parent_) { |
| 437 DCHECK(parent_->cc_layer_); | 437 DCHECK(parent_->cc_layer_); |
| 438 parent_->cc_layer_->replaceChild(cc_layer_, new_layer); | 438 parent_->cc_layer_->ReplaceChild(cc_layer_, new_layer); |
| 439 } | 439 } |
| 440 cc_layer_->removeLayerAnimationEventObserver(this); | 440 cc_layer_->RemoveLayerAnimationEventObserver(this); |
| 441 new_layer->setOpacity(cc_layer_->opacity()); | 441 new_layer->SetOpacity(cc_layer_->opacity()); |
| 442 | 442 |
| 443 cc_layer_= new_layer; | 443 cc_layer_= new_layer; |
| 444 content_layer_ = NULL; | 444 content_layer_ = NULL; |
| 445 solid_color_layer_ = NULL; | 445 solid_color_layer_ = NULL; |
| 446 texture_layer_ = NULL; | 446 texture_layer_ = NULL; |
| 447 delegated_renderer_layer_ = NULL; | 447 delegated_renderer_layer_ = NULL; |
| 448 | 448 |
| 449 cc_layer_->addLayerAnimationEventObserver(this); | 449 cc_layer_->AddLayerAnimationEventObserver(this); |
| 450 for (size_t i = 0; i < children_.size(); ++i) { | 450 for (size_t i = 0; i < children_.size(); ++i) { |
| 451 DCHECK(children_[i]->cc_layer_); | 451 DCHECK(children_[i]->cc_layer_); |
| 452 cc_layer_->addChild(children_[i]->cc_layer_); | 452 cc_layer_->AddChild(children_[i]->cc_layer_); |
| 453 } | 453 } |
| 454 cc_layer_->setAnchorPoint(gfx::PointF()); | 454 cc_layer_->SetAnchorPoint(gfx::PointF()); |
| 455 cc_layer_->setContentsOpaque(fills_bounds_opaquely_); | 455 cc_layer_->SetContentsOpaque(fills_bounds_opaquely_); |
| 456 cc_layer_->setForceRenderSurface(force_render_surface_); | 456 cc_layer_->SetForceRenderSurface(force_render_surface_); |
| 457 cc_layer_->setIsDrawable(IsDrawn()); | 457 cc_layer_->SetIsDrawable(IsDrawn()); |
| 458 } | 458 } |
| 459 | 459 |
| 460 void Layer::SetExternalTexture(Texture* texture) { | 460 void Layer::SetExternalTexture(Texture* texture) { |
| 461 DCHECK_EQ(type_, LAYER_TEXTURED); | 461 DCHECK_EQ(type_, LAYER_TEXTURED); |
| 462 DCHECK(!solid_color_layer_); | 462 DCHECK(!solid_color_layer_); |
| 463 bool has_texture = !!texture; | 463 bool has_texture = !!texture; |
| 464 layer_updated_externally_ = has_texture; | 464 layer_updated_externally_ = has_texture; |
| 465 texture_ = texture; | 465 texture_ = texture; |
| 466 if (!!texture_layer_ != has_texture) { | 466 if (!!texture_layer_ != has_texture) { |
| 467 // Switch to a different type of layer. | 467 // Switch to a different type of layer. |
| 468 if (has_texture) { | 468 if (has_texture) { |
| 469 scoped_refptr<cc::TextureLayer> new_layer = | 469 scoped_refptr<cc::TextureLayer> new_layer = |
| 470 cc::TextureLayer::create(this); | 470 cc::TextureLayer::Create(this); |
| 471 new_layer->setFlipped(texture_->flipped()); | 471 new_layer->setFlipped(texture_->flipped()); |
| 472 SwitchToLayer(new_layer); | 472 SwitchToLayer(new_layer); |
| 473 texture_layer_ = new_layer; | 473 texture_layer_ = new_layer; |
| 474 } else { | 474 } else { |
| 475 scoped_refptr<cc::ContentLayer> new_layer = | 475 scoped_refptr<cc::ContentLayer> new_layer = |
| 476 cc::ContentLayer::create(this); | 476 cc::ContentLayer::Create(this); |
| 477 SwitchToLayer(new_layer); | 477 SwitchToLayer(new_layer); |
| 478 content_layer_ = new_layer; | 478 content_layer_ = new_layer; |
| 479 } | 479 } |
| 480 RecomputeTransform(); | 480 RecomputeTransform(); |
| 481 } | 481 } |
| 482 RecomputeDrawsContentAndUVRect(); | 482 RecomputeDrawsContentAndUVRect(); |
| 483 } | 483 } |
| 484 | 484 |
| 485 void Layer::SetDelegatedFrame(scoped_ptr<cc::DelegatedFrameData> frame, | 485 void Layer::SetDelegatedFrame(scoped_ptr<cc::DelegatedFrameData> frame, |
| 486 gfx::Size frame_size_in_dip) { | 486 gfx::Size frame_size_in_dip) { |
| 487 DCHECK_EQ(type_, LAYER_TEXTURED); | 487 DCHECK_EQ(type_, LAYER_TEXTURED); |
| 488 bool has_frame = frame.get() && !frame->render_pass_list.empty(); | 488 bool has_frame = frame.get() && !frame->render_pass_list.empty(); |
| 489 layer_updated_externally_ = has_frame; | 489 layer_updated_externally_ = has_frame; |
| 490 delegated_frame_size_in_dip_ = frame_size_in_dip; | 490 delegated_frame_size_in_dip_ = frame_size_in_dip; |
| 491 if (!!delegated_renderer_layer_ != has_frame) { | 491 if (!!delegated_renderer_layer_ != has_frame) { |
| 492 if (has_frame) { | 492 if (has_frame) { |
| 493 scoped_refptr<cc::DelegatedRendererLayer> new_layer = | 493 scoped_refptr<cc::DelegatedRendererLayer> new_layer = |
| 494 cc::DelegatedRendererLayer::Create(); | 494 cc::DelegatedRendererLayer::Create(); |
| 495 SwitchToLayer(new_layer); | 495 SwitchToLayer(new_layer); |
| 496 delegated_renderer_layer_ = new_layer; | 496 delegated_renderer_layer_ = new_layer; |
| 497 } else { | 497 } else { |
| 498 scoped_refptr<cc::ContentLayer> new_layer = | 498 scoped_refptr<cc::ContentLayer> new_layer = |
| 499 cc::ContentLayer::create(this); | 499 cc::ContentLayer::Create(this); |
| 500 SwitchToLayer(new_layer); | 500 SwitchToLayer(new_layer); |
| 501 content_layer_ = new_layer; | 501 content_layer_ = new_layer; |
| 502 } | 502 } |
| 503 RecomputeTransform(); | 503 RecomputeTransform(); |
| 504 } | 504 } |
| 505 if (has_frame) | 505 if (has_frame) |
| 506 delegated_renderer_layer_->SetFrameData(frame.Pass()); | 506 delegated_renderer_layer_->SetFrameData(frame.Pass()); |
| 507 RecomputeDrawsContentAndUVRect(); | 507 RecomputeDrawsContentAndUVRect(); |
| 508 } | 508 } |
| 509 | 509 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 for (SkRegion::Iterator iter(damaged_region_); | 541 for (SkRegion::Iterator iter(damaged_region_); |
| 542 !iter.done(); iter.next()) { | 542 !iter.done(); iter.next()) { |
| 543 const SkIRect& sk_damaged = iter.rect(); | 543 const SkIRect& sk_damaged = iter.rect(); |
| 544 gfx::Rect damaged( | 544 gfx::Rect damaged( |
| 545 sk_damaged.x(), | 545 sk_damaged.x(), |
| 546 sk_damaged.y(), | 546 sk_damaged.y(), |
| 547 sk_damaged.width(), | 547 sk_damaged.width(), |
| 548 sk_damaged.height()); | 548 sk_damaged.height()); |
| 549 | 549 |
| 550 gfx::Rect damaged_in_pixel = ConvertRectToPixel(this, damaged); | 550 gfx::Rect damaged_in_pixel = ConvertRectToPixel(this, damaged); |
| 551 cc_layer_->setNeedsDisplayRect(damaged_in_pixel); | 551 cc_layer_->SetNeedsDisplayRect(damaged_in_pixel); |
| 552 } | 552 } |
| 553 damaged_region_.setEmpty(); | 553 damaged_region_.setEmpty(); |
| 554 } | 554 } |
| 555 for (size_t i = 0; i < children_.size(); ++i) | 555 for (size_t i = 0; i < children_.size(); ++i) |
| 556 children_[i]->SendDamagedRects(); | 556 children_[i]->SendDamagedRects(); |
| 557 } | 557 } |
| 558 | 558 |
| 559 void Layer::SuppressPaint() { | 559 void Layer::SuppressPaint() { |
| 560 if (!delegate_) | 560 if (!delegate_) |
| 561 return; | 561 return; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 WebKit::WebGraphicsContext3D* Layer::context() { | 607 WebKit::WebGraphicsContext3D* Layer::context() { |
| 608 DCHECK(texture_layer_); | 608 DCHECK(texture_layer_); |
| 609 return texture_->HostContext3D(); | 609 return texture_->HostContext3D(); |
| 610 } | 610 } |
| 611 | 611 |
| 612 void Layer::SetForceRenderSurface(bool force) { | 612 void Layer::SetForceRenderSurface(bool force) { |
| 613 if (force_render_surface_ == force) | 613 if (force_render_surface_ == force) |
| 614 return; | 614 return; |
| 615 | 615 |
| 616 force_render_surface_ = force; | 616 force_render_surface_ = force; |
| 617 cc_layer_->setForceRenderSurface(force_render_surface_); | 617 cc_layer_->SetForceRenderSurface(force_render_surface_); |
| 618 } | 618 } |
| 619 | 619 |
| 620 void Layer::OnAnimationStarted(const cc::AnimationEvent& event) { | 620 void Layer::OnAnimationStarted(const cc::AnimationEvent& event) { |
| 621 if (animator_) | 621 if (animator_) |
| 622 animator_->OnThreadedAnimationStarted(event); | 622 animator_->OnThreadedAnimationStarted(event); |
| 623 } | 623 } |
| 624 | 624 |
| 625 void Layer::StackRelativeTo(Layer* child, Layer* other, bool above) { | 625 void Layer::StackRelativeTo(Layer* child, Layer* other, bool above) { |
| 626 DCHECK_NE(child, other); | 626 DCHECK_NE(child, other); |
| 627 DCHECK_EQ(this, child->parent()); | 627 DCHECK_EQ(this, child->parent()); |
| 628 DCHECK_EQ(this, other->parent()); | 628 DCHECK_EQ(this, other->parent()); |
| 629 | 629 |
| 630 const size_t child_i = | 630 const size_t child_i = |
| 631 std::find(children_.begin(), children_.end(), child) - children_.begin(); | 631 std::find(children_.begin(), children_.end(), child) - children_.begin(); |
| 632 const size_t other_i = | 632 const size_t other_i = |
| 633 std::find(children_.begin(), children_.end(), other) - children_.begin(); | 633 std::find(children_.begin(), children_.end(), other) - children_.begin(); |
| 634 if ((above && child_i == other_i + 1) || (!above && child_i + 1 == other_i)) | 634 if ((above && child_i == other_i + 1) || (!above && child_i + 1 == other_i)) |
| 635 return; | 635 return; |
| 636 | 636 |
| 637 const size_t dest_i = | 637 const size_t dest_i = |
| 638 above ? | 638 above ? |
| 639 (child_i < other_i ? other_i : other_i + 1) : | 639 (child_i < other_i ? other_i : other_i + 1) : |
| 640 (child_i < other_i ? other_i - 1 : other_i); | 640 (child_i < other_i ? other_i - 1 : other_i); |
| 641 children_.erase(children_.begin() + child_i); | 641 children_.erase(children_.begin() + child_i); |
| 642 children_.insert(children_.begin() + dest_i, child); | 642 children_.insert(children_.begin() + dest_i, child); |
| 643 | 643 |
| 644 child->cc_layer_->removeFromParent(); | 644 child->cc_layer_->RemoveFromParent(); |
| 645 cc_layer_->insertChild(child->cc_layer_, dest_i); | 645 cc_layer_->InsertChild(child->cc_layer_, dest_i); |
| 646 } | 646 } |
| 647 | 647 |
| 648 bool Layer::ConvertPointForAncestor(const Layer* ancestor, | 648 bool Layer::ConvertPointForAncestor(const Layer* ancestor, |
| 649 gfx::Point* point) const { | 649 gfx::Point* point) const { |
| 650 gfx::Transform transform; | 650 gfx::Transform transform; |
| 651 bool result = GetTargetTransformRelativeTo(ancestor, &transform); | 651 bool result = GetTargetTransformRelativeTo(ancestor, &transform); |
| 652 gfx::Point3F p(*point); | 652 gfx::Point3F p(*point); |
| 653 transform.TransformPoint(p); | 653 transform.TransformPoint(p); |
| 654 *point = gfx::ToFlooredPoint(p.AsPointF()); | 654 *point = gfx::ToFlooredPoint(p.AsPointF()); |
| 655 return result; | 655 return result; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 } | 707 } |
| 708 } | 708 } |
| 709 | 709 |
| 710 void Layer::SetTransformImmediately(const gfx::Transform& transform) { | 710 void Layer::SetTransformImmediately(const gfx::Transform& transform) { |
| 711 transform_ = transform; | 711 transform_ = transform; |
| 712 | 712 |
| 713 RecomputeTransform(); | 713 RecomputeTransform(); |
| 714 } | 714 } |
| 715 | 715 |
| 716 void Layer::SetOpacityImmediately(float opacity) { | 716 void Layer::SetOpacityImmediately(float opacity) { |
| 717 cc_layer_->setOpacity(opacity); | 717 cc_layer_->SetOpacity(opacity); |
| 718 ScheduleDraw(); | 718 ScheduleDraw(); |
| 719 } | 719 } |
| 720 | 720 |
| 721 void Layer::SetVisibilityImmediately(bool visible) { | 721 void Layer::SetVisibilityImmediately(bool visible) { |
| 722 if (visible_ == visible) | 722 if (visible_ == visible) |
| 723 return; | 723 return; |
| 724 | 724 |
| 725 visible_ = visible; | 725 visible_ = visible; |
| 726 UpdateIsDrawn(); | 726 UpdateIsDrawn(); |
| 727 } | 727 } |
| 728 | 728 |
| 729 void Layer::SetBrightnessImmediately(float brightness) { | 729 void Layer::SetBrightnessImmediately(float brightness) { |
| 730 layer_brightness_ = brightness; | 730 layer_brightness_ = brightness; |
| 731 SetLayerFilters(); | 731 SetLayerFilters(); |
| 732 } | 732 } |
| 733 | 733 |
| 734 void Layer::SetGrayscaleImmediately(float grayscale) { | 734 void Layer::SetGrayscaleImmediately(float grayscale) { |
| 735 layer_grayscale_ = grayscale; | 735 layer_grayscale_ = grayscale; |
| 736 SetLayerFilters(); | 736 SetLayerFilters(); |
| 737 } | 737 } |
| 738 | 738 |
| 739 void Layer::SetColorImmediately(SkColor color) { | 739 void Layer::SetColorImmediately(SkColor color) { |
| 740 DCHECK_EQ(type_, LAYER_SOLID_COLOR); | 740 DCHECK_EQ(type_, LAYER_SOLID_COLOR); |
| 741 // WebColor is equivalent to SkColor, per WebColor.h. | 741 // WebColor is equivalent to SkColor, per WebColor.h. |
| 742 solid_color_layer_->setBackgroundColor(static_cast<WebKit::WebColor>(color)); | 742 solid_color_layer_->SetBackgroundColor(static_cast<WebKit::WebColor>(color)); |
| 743 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); | 743 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); |
| 744 } | 744 } |
| 745 | 745 |
| 746 void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) { | 746 void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) { |
| 747 SetBoundsImmediately(bounds); | 747 SetBoundsImmediately(bounds); |
| 748 } | 748 } |
| 749 | 749 |
| 750 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { | 750 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { |
| 751 SetTransformImmediately(transform); | 751 SetTransformImmediately(transform); |
| 752 } | 752 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 | 797 |
| 798 float Layer::GetGrayscaleForAnimation() const { | 798 float Layer::GetGrayscaleForAnimation() const { |
| 799 return layer_grayscale(); | 799 return layer_grayscale(); |
| 800 } | 800 } |
| 801 | 801 |
| 802 SkColor Layer::GetColorForAnimation() const { | 802 SkColor Layer::GetColorForAnimation() const { |
| 803 // WebColor is equivalent to SkColor, per WebColor.h. | 803 // WebColor is equivalent to SkColor, per WebColor.h. |
| 804 // The NULL check is here since this is invoked regardless of whether we have | 804 // The NULL check is here since this is invoked regardless of whether we have |
| 805 // been configured as LAYER_SOLID_COLOR. | 805 // been configured as LAYER_SOLID_COLOR. |
| 806 return solid_color_layer_.get() ? | 806 return solid_color_layer_.get() ? |
| 807 solid_color_layer_->backgroundColor() : SK_ColorBLACK; | 807 solid_color_layer_->background_color() : SK_ColorBLACK; |
| 808 } | 808 } |
| 809 | 809 |
| 810 void Layer::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) { | 810 void Layer::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) { |
| 811 DCHECK(cc_layer_); | 811 DCHECK(cc_layer_); |
| 812 // Until this layer has a compositor (and hence cc_layer_ has a | 812 // Until this layer has a compositor (and hence cc_layer_ has a |
| 813 // LayerTreeHost), addAnimation will fail. | 813 // LayerTreeHost), addAnimation will fail. |
| 814 if (GetCompositor()) | 814 if (GetCompositor()) |
| 815 cc_layer_->AddAnimation(animation.Pass()); | 815 cc_layer_->AddAnimation(animation.Pass()); |
| 816 else | 816 else |
| 817 pending_threaded_animations_.push_back(animation.Pass()); | 817 pending_threaded_animations_.push_back(animation.Pass()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 | 859 |
| 860 for (size_t i = 0; i < children_.size(); ++i) | 860 for (size_t i = 0; i < children_.size(); ++i) |
| 861 children_[i]->SendPendingThreadedAnimations(); | 861 children_[i]->SendPendingThreadedAnimations(); |
| 862 } | 862 } |
| 863 | 863 |
| 864 void Layer::CreateWebLayer() { | 864 void Layer::CreateWebLayer() { |
| 865 if (type_ == LAYER_SOLID_COLOR) { | 865 if (type_ == LAYER_SOLID_COLOR) { |
| 866 solid_color_layer_ = cc::SolidColorLayer::Create(); | 866 solid_color_layer_ = cc::SolidColorLayer::Create(); |
| 867 cc_layer_ = solid_color_layer_.get(); | 867 cc_layer_ = solid_color_layer_.get(); |
| 868 } else { | 868 } else { |
| 869 content_layer_ = cc::ContentLayer::create(this); | 869 content_layer_ = cc::ContentLayer::Create(this); |
| 870 cc_layer_ = content_layer_.get(); | 870 cc_layer_ = content_layer_.get(); |
| 871 } | 871 } |
| 872 cc_layer_->setAnchorPoint(gfx::PointF()); | 872 cc_layer_->SetAnchorPoint(gfx::PointF()); |
| 873 cc_layer_->setContentsOpaque(true); | 873 cc_layer_->SetContentsOpaque(true); |
| 874 cc_layer_->setIsDrawable(type_ != LAYER_NOT_DRAWN); | 874 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); |
| 875 cc_layer_->addLayerAnimationEventObserver(this); | 875 cc_layer_->AddLayerAnimationEventObserver(this); |
| 876 } | 876 } |
| 877 | 877 |
| 878 void Layer::RecomputeTransform() { | 878 void Layer::RecomputeTransform() { |
| 879 gfx::Transform scale_translate; | 879 gfx::Transform scale_translate; |
| 880 scale_translate.matrix().set3x3(device_scale_factor_, 0, 0, | 880 scale_translate.matrix().set3x3(device_scale_factor_, 0, 0, |
| 881 0, device_scale_factor_, 0, | 881 0, device_scale_factor_, 0, |
| 882 0, 0, 1); | 882 0, 0, 1); |
| 883 // Start with the inverse matrix of above. | 883 // Start with the inverse matrix of above. |
| 884 gfx::Transform transform; | 884 gfx::Transform transform; |
| 885 transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0, | 885 transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0, |
| 886 0, 1.0f / device_scale_factor_, 0, | 886 0, 1.0f / device_scale_factor_, 0, |
| 887 0, 0, 1); | 887 0, 0, 1); |
| 888 transform.ConcatTransform(transform_); | 888 transform.ConcatTransform(transform_); |
| 889 gfx::Transform translate; | 889 gfx::Transform translate; |
| 890 translate.Translate(bounds_.x(), bounds_.y()); | 890 translate.Translate(bounds_.x(), bounds_.y()); |
| 891 transform.ConcatTransform(translate); | 891 transform.ConcatTransform(translate); |
| 892 transform.ConcatTransform(scale_translate); | 892 transform.ConcatTransform(scale_translate); |
| 893 cc_layer_->setTransform(transform); | 893 cc_layer_->SetTransform(transform); |
| 894 } | 894 } |
| 895 | 895 |
| 896 void Layer::RecomputeDrawsContentAndUVRect() { | 896 void Layer::RecomputeDrawsContentAndUVRect() { |
| 897 DCHECK(cc_layer_); | 897 DCHECK(cc_layer_); |
| 898 gfx::Size size(bounds_.size()); | 898 gfx::Size size(bounds_.size()); |
| 899 if (texture_layer_.get()) { | 899 if (texture_layer_.get()) { |
| 900 DCHECK(texture_); | 900 DCHECK(texture_); |
| 901 | 901 |
| 902 float texture_scale_factor = 1.0f / texture_->device_scale_factor(); | 902 float texture_scale_factor = 1.0f / texture_->device_scale_factor(); |
| 903 gfx::Size texture_size = gfx::ToFlooredSize( | 903 gfx::Size texture_size = gfx::ToFlooredSize( |
| 904 gfx::ScaleSize(texture_->size(), texture_scale_factor)); | 904 gfx::ScaleSize(texture_->size(), texture_scale_factor)); |
| 905 size.ClampToMax(texture_size); | 905 size.ClampToMax(texture_size); |
| 906 | 906 |
| 907 gfx::PointF uv_top_left(0.f, 0.f); | 907 gfx::PointF uv_top_left(0.f, 0.f); |
| 908 gfx::PointF uv_bottom_right( | 908 gfx::PointF uv_bottom_right( |
| 909 static_cast<float>(size.width())/texture_size.width(), | 909 static_cast<float>(size.width())/texture_size.width(), |
| 910 static_cast<float>(size.height())/texture_size.height()); | 910 static_cast<float>(size.height())/texture_size.height()); |
| 911 texture_layer_->setUV(uv_top_left, uv_bottom_right); | 911 texture_layer_->setUV(uv_top_left, uv_bottom_right); |
| 912 } else if (delegated_renderer_layer_.get()) { | 912 } else if (delegated_renderer_layer_.get()) { |
| 913 delegated_renderer_layer_->SetDisplaySize( | 913 delegated_renderer_layer_->SetDisplaySize( |
| 914 ConvertSizeToPixel(this, delegated_frame_size_in_dip_)); | 914 ConvertSizeToPixel(this, delegated_frame_size_in_dip_)); |
| 915 size.ClampToMax(delegated_frame_size_in_dip_); | 915 size.ClampToMax(delegated_frame_size_in_dip_); |
| 916 } | 916 } |
| 917 cc_layer_->setBounds(ConvertSizeToPixel(this, size)); | 917 cc_layer_->SetBounds(ConvertSizeToPixel(this, size)); |
| 918 } | 918 } |
| 919 | 919 |
| 920 } // namespace ui | 920 } // namespace ui |
| OLD | NEW |