| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 if (compositor_) | 104 if (compositor_) |
| 105 compositor_->SetRootLayer(NULL); | 105 compositor_->SetRootLayer(NULL); |
| 106 if (parent_) | 106 if (parent_) |
| 107 parent_->Remove(this); | 107 parent_->Remove(this); |
| 108 if (layer_mask_) | 108 if (layer_mask_) |
| 109 SetMaskLayer(NULL); | 109 SetMaskLayer(NULL); |
| 110 if (layer_mask_back_link_) | 110 if (layer_mask_back_link_) |
| 111 layer_mask_back_link_->SetMaskLayer(NULL); | 111 layer_mask_back_link_->SetMaskLayer(NULL); |
| 112 for (size_t i = 0; i < children_.size(); ++i) | 112 for (size_t i = 0; i < children_.size(); ++i) |
| 113 children_[i]->parent_ = NULL; | 113 children_[i]->parent_ = NULL; |
| 114 cc_layer_->removeLayerAnimationEventObserver(this); | 114 cc_layer_->RemoveLayerAnimationEventObserver(this); |
| 115 cc_layer_->removeFromParent(); | 115 cc_layer_->RemoveFromParent(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 Compositor* Layer::GetCompositor() { | 118 Compositor* Layer::GetCompositor() { |
| 119 return GetRoot(this)->compositor_; | 119 return GetRoot(this)->compositor_; |
| 120 } | 120 } |
| 121 | 121 |
| 122 float Layer::opacity() const { | 122 float Layer::opacity() const { |
| 123 return cc_layer_->opacity(); | 123 return cc_layer_->opacity(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void Layer::SetCompositor(Compositor* compositor) { | 126 void Layer::SetCompositor(Compositor* compositor) { |
| 127 // This function must only be called to set the compositor on the root layer, | 127 // This function must only be called to set the compositor on the root layer, |
| 128 // or to reset it. | 128 // or to reset it. |
| 129 DCHECK(!compositor || !compositor_); | 129 DCHECK(!compositor || !compositor_); |
| 130 DCHECK(!compositor || compositor->root_layer() == this); | 130 DCHECK(!compositor || compositor->root_layer() == this); |
| 131 DCHECK(!parent_); | 131 DCHECK(!parent_); |
| 132 compositor_ = compositor; | 132 compositor_ = compositor; |
| 133 if (compositor) | 133 if (compositor) |
| 134 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); | 134 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void Layer::Add(Layer* child) { | 137 void Layer::Add(Layer* child) { |
| 138 DCHECK(!child->compositor_); | 138 DCHECK(!child->compositor_); |
| 139 if (child->parent_) | 139 if (child->parent_) |
| 140 child->parent_->Remove(child); | 140 child->parent_->Remove(child); |
| 141 child->parent_ = this; | 141 child->parent_ = this; |
| 142 children_.push_back(child); | 142 children_.push_back(child); |
| 143 cc_layer_->addChild(child->cc_layer_); | 143 cc_layer_->AddChild(child->cc_layer_); |
| 144 child->OnDeviceScaleFactorChanged(device_scale_factor_); | 144 child->OnDeviceScaleFactorChanged(device_scale_factor_); |
| 145 child->UpdateIsDrawn(); | 145 child->UpdateIsDrawn(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void Layer::Remove(Layer* child) { | 148 void Layer::Remove(Layer* child) { |
| 149 std::vector<Layer*>::iterator i = | 149 std::vector<Layer*>::iterator i = |
| 150 std::find(children_.begin(), children_.end(), child); | 150 std::find(children_.begin(), children_.end(), child); |
| 151 DCHECK(i != children_.end()); | 151 DCHECK(i != children_.end()); |
| 152 children_.erase(i); | 152 children_.erase(i); |
| 153 child->parent_ = NULL; | 153 child->parent_ = NULL; |
| 154 child->cc_layer_->removeFromParent(); | 154 child->cc_layer_->RemoveFromParent(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void Layer::StackAtTop(Layer* child) { | 157 void Layer::StackAtTop(Layer* child) { |
| 158 if (children_.size() <= 1 || child == children_.back()) | 158 if (children_.size() <= 1 || child == children_.back()) |
| 159 return; // Already in front. | 159 return; // Already in front. |
| 160 StackAbove(child, children_.back()); | 160 StackAbove(child, children_.back()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void Layer::StackAbove(Layer* child, Layer* other) { | 163 void Layer::StackAbove(Layer* child, Layer* other) { |
| 164 StackRelativeTo(child, other, true); | 164 StackRelativeTo(child, other, true); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 212 |
| 213 gfx::Rect Layer::GetTargetBounds() const { | 213 gfx::Rect Layer::GetTargetBounds() const { |
| 214 if (animator_.get() && animator_->IsAnimatingProperty( | 214 if (animator_.get() && animator_->IsAnimatingProperty( |
| 215 LayerAnimationElement::BOUNDS)) { | 215 LayerAnimationElement::BOUNDS)) { |
| 216 return animator_->GetTargetBounds(); | 216 return animator_->GetTargetBounds(); |
| 217 } | 217 } |
| 218 return bounds_; | 218 return bounds_; |
| 219 } | 219 } |
| 220 | 220 |
| 221 void Layer::SetMasksToBounds(bool masks_to_bounds) { | 221 void Layer::SetMasksToBounds(bool masks_to_bounds) { |
| 222 cc_layer_->setMasksToBounds(masks_to_bounds); | 222 cc_layer_->SetMasksToBounds(masks_to_bounds); |
| 223 } | 223 } |
| 224 | 224 |
| 225 bool Layer::GetMasksToBounds() const { | 225 bool Layer::GetMasksToBounds() const { |
| 226 return cc_layer_->masksToBounds(); | 226 return cc_layer_->masks_to_bounds(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 void Layer::SetOpacity(float opacity) { | 229 void Layer::SetOpacity(float opacity) { |
| 230 GetAnimator()->SetOpacity(opacity); | 230 GetAnimator()->SetOpacity(opacity); |
| 231 } | 231 } |
| 232 | 232 |
| 233 float Layer::GetCombinedOpacity() const { | 233 float Layer::GetCombinedOpacity() const { |
| 234 float opacity = this->opacity(); | 234 float opacity = this->opacity(); |
| 235 Layer* current = this->parent_; | 235 Layer* current = this->parent_; |
| 236 while (current) { | 236 while (current) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 layer_mask->children().empty() && | 287 layer_mask->children().empty() && |
| 288 !layer_mask->layer_mask_back_link_)); | 288 !layer_mask->layer_mask_back_link_)); |
| 289 DCHECK(!layer_mask_back_link_); | 289 DCHECK(!layer_mask_back_link_); |
| 290 if (layer_mask_ == layer_mask) | 290 if (layer_mask_ == layer_mask) |
| 291 return; | 291 return; |
| 292 // We need to de-reference the currently linked object so that no problem | 292 // We need to de-reference the currently linked object so that no problem |
| 293 // arises if the mask layer gets deleted before this object. | 293 // arises if the mask layer gets deleted before this object. |
| 294 if (layer_mask_) | 294 if (layer_mask_) |
| 295 layer_mask_->layer_mask_back_link_ = NULL; | 295 layer_mask_->layer_mask_back_link_ = NULL; |
| 296 layer_mask_ = layer_mask; | 296 layer_mask_ = layer_mask; |
| 297 cc_layer_->setMaskLayer( | 297 cc_layer_->SetMaskLayer( |
| 298 layer_mask ? layer_mask->cc_layer() : NULL); | 298 layer_mask ? layer_mask->cc_layer() : NULL); |
| 299 // We need to reference the linked object so that it can properly break the | 299 // We need to reference the linked object so that it can properly break the |
| 300 // link to us when it gets deleted. | 300 // link to us when it gets deleted. |
| 301 if (layer_mask) { | 301 if (layer_mask) { |
| 302 layer_mask->layer_mask_back_link_ = this; | 302 layer_mask->layer_mask_back_link_ = this; |
| 303 layer_mask->OnDeviceScaleFactorChanged(device_scale_factor_); | 303 layer_mask->OnDeviceScaleFactorChanged(device_scale_factor_); |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 | 306 |
| 307 void Layer::SetBackgroundZoom(float x_offset, | 307 void Layer::SetBackgroundZoom(float x_offset, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 329 if (layer_inverted_) | 329 if (layer_inverted_) |
| 330 filters.append(WebKit::WebFilterOperation::createInvertFilter(1.0)); | 330 filters.append(WebKit::WebFilterOperation::createInvertFilter(1.0)); |
| 331 // Brightness goes last, because the resulting colors neeed clamping, which | 331 // Brightness goes last, because the resulting colors neeed clamping, which |
| 332 // cause further color matrix filters to be applied separately. In this order, | 332 // cause further color matrix filters to be applied separately. In this order, |
| 333 // they all can be combined in a single pass. | 333 // they all can be combined in a single pass. |
| 334 if (layer_brightness_) { | 334 if (layer_brightness_) { |
| 335 filters.append(WebKit::WebFilterOperation::createSaturatingBrightnessFilter( | 335 filters.append(WebKit::WebFilterOperation::createSaturatingBrightnessFilter( |
| 336 layer_brightness_)); | 336 layer_brightness_)); |
| 337 } | 337 } |
| 338 | 338 |
| 339 cc_layer_->setFilters(filters); | 339 cc_layer_->SetFilters(filters); |
| 340 } | 340 } |
| 341 | 341 |
| 342 void Layer::SetLayerBackgroundFilters() { | 342 void Layer::SetLayerBackgroundFilters() { |
| 343 WebKit::WebFilterOperations filters; | 343 WebKit::WebFilterOperations filters; |
| 344 if (zoom_ != 1) { | 344 if (zoom_ != 1) { |
| 345 filters.append(WebKit::WebFilterOperation::createZoomFilter( | 345 filters.append(WebKit::WebFilterOperation::createZoomFilter( |
| 346 WebKit::WebRect(zoom_x_offset_, zoom_y_offset_, | 346 WebKit::WebRect(zoom_x_offset_, zoom_y_offset_, |
| 347 (GetTargetBounds().width() / zoom_), | 347 (GetTargetBounds().width() / zoom_), |
| 348 (GetTargetBounds().height() / zoom_)), | 348 (GetTargetBounds().height() / zoom_)), |
| 349 zoom_inset_)); | 349 zoom_inset_)); |
| 350 } | 350 } |
| 351 | 351 |
| 352 if (background_blur_radius_) { | 352 if (background_blur_radius_) { |
| 353 filters.append(WebKit::WebFilterOperation::createBlurFilter( | 353 filters.append(WebKit::WebFilterOperation::createBlurFilter( |
| 354 background_blur_radius_)); | 354 background_blur_radius_)); |
| 355 } | 355 } |
| 356 | 356 |
| 357 cc_layer_->setBackgroundFilters(filters); | 357 cc_layer_->SetBackgroundFilters(filters); |
| 358 } | 358 } |
| 359 | 359 |
| 360 float Layer::GetTargetOpacity() const { | 360 float Layer::GetTargetOpacity() const { |
| 361 if (animator_.get() && animator_->IsAnimatingProperty( | 361 if (animator_.get() && animator_->IsAnimatingProperty( |
| 362 LayerAnimationElement::OPACITY)) | 362 LayerAnimationElement::OPACITY)) |
| 363 return animator_->GetTargetOpacity(); | 363 return animator_->GetTargetOpacity(); |
| 364 return opacity(); | 364 return opacity(); |
| 365 } | 365 } |
| 366 | 366 |
| 367 void Layer::SetVisible(bool visible) { | 367 void Layer::SetVisible(bool visible) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 379 return is_drawn_; | 379 return is_drawn_; |
| 380 } | 380 } |
| 381 | 381 |
| 382 void Layer::UpdateIsDrawn() { | 382 void Layer::UpdateIsDrawn() { |
| 383 bool updated_is_drawn = visible_ && (!parent_ || parent_->IsDrawn()); | 383 bool updated_is_drawn = visible_ && (!parent_ || parent_->IsDrawn()); |
| 384 | 384 |
| 385 if (updated_is_drawn == is_drawn_) | 385 if (updated_is_drawn == is_drawn_) |
| 386 return; | 386 return; |
| 387 | 387 |
| 388 is_drawn_ = updated_is_drawn; | 388 is_drawn_ = updated_is_drawn; |
| 389 cc_layer_->setIsDrawable(is_drawn_ && type_ != LAYER_NOT_DRAWN); | 389 cc_layer_->SetIsDrawable(is_drawn_ && type_ != LAYER_NOT_DRAWN); |
| 390 | 390 |
| 391 for (size_t i = 0; i < children_.size(); ++i) { | 391 for (size_t i = 0; i < children_.size(); ++i) { |
| 392 children_[i]->UpdateIsDrawn(); | 392 children_[i]->UpdateIsDrawn(); |
| 393 } | 393 } |
| 394 } | 394 } |
| 395 | 395 |
| 396 bool Layer::ShouldDraw() const { | 396 bool Layer::ShouldDraw() const { |
| 397 return type_ != LAYER_NOT_DRAWN && GetCombinedOpacity() > 0.0f; | 397 return type_ != LAYER_NOT_DRAWN && GetCombinedOpacity() > 0.0f; |
| 398 } | 398 } |
| 399 | 399 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 412 if (target != root_layer) | 412 if (target != root_layer) |
| 413 target->ConvertPointFromAncestor(root_layer, point); | 413 target->ConvertPointFromAncestor(root_layer, point); |
| 414 } | 414 } |
| 415 | 415 |
| 416 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { | 416 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { |
| 417 if (fills_bounds_opaquely_ == fills_bounds_opaquely) | 417 if (fills_bounds_opaquely_ == fills_bounds_opaquely) |
| 418 return; | 418 return; |
| 419 | 419 |
| 420 fills_bounds_opaquely_ = fills_bounds_opaquely; | 420 fills_bounds_opaquely_ = fills_bounds_opaquely; |
| 421 | 421 |
| 422 cc_layer_->setContentsOpaque(fills_bounds_opaquely); | 422 cc_layer_->SetContentsOpaque(fills_bounds_opaquely); |
| 423 } | 423 } |
| 424 | 424 |
| 425 void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { | 425 void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { |
| 426 if (texture_layer_.get()) | 426 if (texture_layer_.get()) |
| 427 texture_layer_->willModifyTexture(); | 427 texture_layer_->willModifyTexture(); |
| 428 // TODO(piman): delegated_renderer_layer_ cleanup. | 428 // TODO(piman): delegated_renderer_layer_ cleanup. |
| 429 | 429 |
| 430 cc_layer_->removeAllChildren(); | 430 cc_layer_->RemoveAllChildren(); |
| 431 if (parent_) { | 431 if (parent_) { |
| 432 DCHECK(parent_->cc_layer_); | 432 DCHECK(parent_->cc_layer_); |
| 433 parent_->cc_layer_->replaceChild(cc_layer_, new_layer); | 433 parent_->cc_layer_->ReplaceChild(cc_layer_, new_layer); |
| 434 } | 434 } |
| 435 cc_layer_->removeLayerAnimationEventObserver(this); | 435 cc_layer_->RemoveLayerAnimationEventObserver(this); |
| 436 new_layer->setOpacity(cc_layer_->opacity()); | 436 new_layer->SetOpacity(cc_layer_->opacity()); |
| 437 | 437 |
| 438 cc_layer_= new_layer; | 438 cc_layer_= new_layer; |
| 439 content_layer_ = NULL; | 439 content_layer_ = NULL; |
| 440 solid_color_layer_ = NULL; | 440 solid_color_layer_ = NULL; |
| 441 texture_layer_ = NULL; | 441 texture_layer_ = NULL; |
| 442 delegated_renderer_layer_ = NULL; | 442 delegated_renderer_layer_ = NULL; |
| 443 | 443 |
| 444 cc_layer_->addLayerAnimationEventObserver(this); | 444 cc_layer_->AddLayerAnimationEventObserver(this); |
| 445 for (size_t i = 0; i < children_.size(); ++i) { | 445 for (size_t i = 0; i < children_.size(); ++i) { |
| 446 DCHECK(children_[i]->cc_layer_); | 446 DCHECK(children_[i]->cc_layer_); |
| 447 cc_layer_->addChild(children_[i]->cc_layer_); | 447 cc_layer_->AddChild(children_[i]->cc_layer_); |
| 448 } | 448 } |
| 449 cc_layer_->setAnchorPoint(gfx::PointF()); | 449 cc_layer_->SetAnchorPoint(gfx::PointF()); |
| 450 cc_layer_->setContentsOpaque(fills_bounds_opaquely_); | 450 cc_layer_->SetContentsOpaque(fills_bounds_opaquely_); |
| 451 cc_layer_->setForceRenderSurface(force_render_surface_); | 451 cc_layer_->SetForceRenderSurface(force_render_surface_); |
| 452 cc_layer_->setIsDrawable(IsDrawn()); | 452 cc_layer_->SetIsDrawable(IsDrawn()); |
| 453 } | 453 } |
| 454 | 454 |
| 455 void Layer::SetExternalTexture(Texture* texture) { | 455 void Layer::SetExternalTexture(Texture* texture) { |
| 456 DCHECK_EQ(type_, LAYER_TEXTURED); | 456 DCHECK_EQ(type_, LAYER_TEXTURED); |
| 457 DCHECK(!solid_color_layer_); | 457 DCHECK(!solid_color_layer_); |
| 458 bool has_texture = !!texture; | 458 bool has_texture = !!texture; |
| 459 layer_updated_externally_ = has_texture; | 459 layer_updated_externally_ = has_texture; |
| 460 texture_ = texture; | 460 texture_ = texture; |
| 461 if (!!texture_layer_ != has_texture) { | 461 if (!!texture_layer_ != has_texture) { |
| 462 // Switch to a different type of layer. | 462 // Switch to a different type of layer. |
| 463 if (has_texture) { | 463 if (has_texture) { |
| 464 scoped_refptr<cc::TextureLayer> new_layer = | 464 scoped_refptr<cc::TextureLayer> new_layer = |
| 465 cc::TextureLayer::create(this); | 465 cc::TextureLayer::Create(this); |
| 466 new_layer->setFlipped(texture_->flipped()); | 466 new_layer->setFlipped(texture_->flipped()); |
| 467 SwitchToLayer(new_layer); | 467 SwitchToLayer(new_layer); |
| 468 texture_layer_ = new_layer; | 468 texture_layer_ = new_layer; |
| 469 } else { | 469 } else { |
| 470 scoped_refptr<cc::ContentLayer> new_layer = | 470 scoped_refptr<cc::ContentLayer> new_layer = |
| 471 cc::ContentLayer::create(this); | 471 cc::ContentLayer::Create(this); |
| 472 SwitchToLayer(new_layer); | 472 SwitchToLayer(new_layer); |
| 473 content_layer_ = new_layer; | 473 content_layer_ = new_layer; |
| 474 } | 474 } |
| 475 RecomputeTransform(); | 475 RecomputeTransform(); |
| 476 } | 476 } |
| 477 RecomputeDrawsContentAndUVRect(); | 477 RecomputeDrawsContentAndUVRect(); |
| 478 } | 478 } |
| 479 | 479 |
| 480 void Layer::SetDelegatedFrame(scoped_ptr<cc::DelegatedFrameData> frame, | 480 void Layer::SetDelegatedFrame(scoped_ptr<cc::DelegatedFrameData> frame, |
| 481 gfx::Size frame_size_in_dip) { | 481 gfx::Size frame_size_in_dip) { |
| 482 DCHECK_EQ(type_, LAYER_TEXTURED); | 482 DCHECK_EQ(type_, LAYER_TEXTURED); |
| 483 bool has_frame = frame.get() && !frame->render_pass_list.empty(); | 483 bool has_frame = frame.get() && !frame->render_pass_list.empty(); |
| 484 layer_updated_externally_ = has_frame; | 484 layer_updated_externally_ = has_frame; |
| 485 delegated_frame_size_in_dip_ = frame_size_in_dip; | 485 delegated_frame_size_in_dip_ = frame_size_in_dip; |
| 486 if (!!delegated_renderer_layer_ != has_frame) { | 486 if (!!delegated_renderer_layer_ != has_frame) { |
| 487 if (has_frame) { | 487 if (has_frame) { |
| 488 scoped_refptr<cc::DelegatedRendererLayer> new_layer = | 488 scoped_refptr<cc::DelegatedRendererLayer> new_layer = |
| 489 cc::DelegatedRendererLayer::Create(); | 489 cc::DelegatedRendererLayer::Create(); |
| 490 SwitchToLayer(new_layer); | 490 SwitchToLayer(new_layer); |
| 491 delegated_renderer_layer_ = new_layer; | 491 delegated_renderer_layer_ = new_layer; |
| 492 } else { | 492 } else { |
| 493 scoped_refptr<cc::ContentLayer> new_layer = | 493 scoped_refptr<cc::ContentLayer> new_layer = |
| 494 cc::ContentLayer::create(this); | 494 cc::ContentLayer::Create(this); |
| 495 SwitchToLayer(new_layer); | 495 SwitchToLayer(new_layer); |
| 496 content_layer_ = new_layer; | 496 content_layer_ = new_layer; |
| 497 } | 497 } |
| 498 RecomputeTransform(); | 498 RecomputeTransform(); |
| 499 } | 499 } |
| 500 if (has_frame) | 500 if (has_frame) |
| 501 delegated_renderer_layer_->SetFrameData(frame.Pass()); | 501 delegated_renderer_layer_->SetFrameData(frame.Pass()); |
| 502 RecomputeDrawsContentAndUVRect(); | 502 RecomputeDrawsContentAndUVRect(); |
| 503 } | 503 } |
| 504 | 504 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 for (SkRegion::Iterator iter(damaged_region_); | 536 for (SkRegion::Iterator iter(damaged_region_); |
| 537 !iter.done(); iter.next()) { | 537 !iter.done(); iter.next()) { |
| 538 const SkIRect& sk_damaged = iter.rect(); | 538 const SkIRect& sk_damaged = iter.rect(); |
| 539 gfx::Rect damaged( | 539 gfx::Rect damaged( |
| 540 sk_damaged.x(), | 540 sk_damaged.x(), |
| 541 sk_damaged.y(), | 541 sk_damaged.y(), |
| 542 sk_damaged.width(), | 542 sk_damaged.width(), |
| 543 sk_damaged.height()); | 543 sk_damaged.height()); |
| 544 | 544 |
| 545 gfx::Rect damaged_in_pixel = ConvertRectToPixel(this, damaged); | 545 gfx::Rect damaged_in_pixel = ConvertRectToPixel(this, damaged); |
| 546 cc_layer_->setNeedsDisplayRect(damaged_in_pixel); | 546 cc_layer_->SetNeedsDisplayRect(damaged_in_pixel); |
| 547 } | 547 } |
| 548 damaged_region_.setEmpty(); | 548 damaged_region_.setEmpty(); |
| 549 } | 549 } |
| 550 for (size_t i = 0; i < children_.size(); ++i) | 550 for (size_t i = 0; i < children_.size(); ++i) |
| 551 children_[i]->SendDamagedRects(); | 551 children_[i]->SendDamagedRects(); |
| 552 } | 552 } |
| 553 | 553 |
| 554 void Layer::SuppressPaint() { | 554 void Layer::SuppressPaint() { |
| 555 if (!delegate_) | 555 if (!delegate_) |
| 556 return; | 556 return; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 WebKit::WebGraphicsContext3D* Layer::context() { | 602 WebKit::WebGraphicsContext3D* Layer::context() { |
| 603 DCHECK(texture_layer_); | 603 DCHECK(texture_layer_); |
| 604 return texture_->HostContext3D(); | 604 return texture_->HostContext3D(); |
| 605 } | 605 } |
| 606 | 606 |
| 607 void Layer::SetForceRenderSurface(bool force) { | 607 void Layer::SetForceRenderSurface(bool force) { |
| 608 if (force_render_surface_ == force) | 608 if (force_render_surface_ == force) |
| 609 return; | 609 return; |
| 610 | 610 |
| 611 force_render_surface_ = force; | 611 force_render_surface_ = force; |
| 612 cc_layer_->setForceRenderSurface(force_render_surface_); | 612 cc_layer_->SetForceRenderSurface(force_render_surface_); |
| 613 } | 613 } |
| 614 | 614 |
| 615 void Layer::OnAnimationStarted(const cc::AnimationEvent& event) { | 615 void Layer::OnAnimationStarted(const cc::AnimationEvent& event) { |
| 616 if (animator_) | 616 if (animator_) |
| 617 animator_->OnThreadedAnimationStarted(event); | 617 animator_->OnThreadedAnimationStarted(event); |
| 618 } | 618 } |
| 619 | 619 |
| 620 void Layer::StackRelativeTo(Layer* child, Layer* other, bool above) { | 620 void Layer::StackRelativeTo(Layer* child, Layer* other, bool above) { |
| 621 DCHECK_NE(child, other); | 621 DCHECK_NE(child, other); |
| 622 DCHECK_EQ(this, child->parent()); | 622 DCHECK_EQ(this, child->parent()); |
| 623 DCHECK_EQ(this, other->parent()); | 623 DCHECK_EQ(this, other->parent()); |
| 624 | 624 |
| 625 const size_t child_i = | 625 const size_t child_i = |
| 626 std::find(children_.begin(), children_.end(), child) - children_.begin(); | 626 std::find(children_.begin(), children_.end(), child) - children_.begin(); |
| 627 const size_t other_i = | 627 const size_t other_i = |
| 628 std::find(children_.begin(), children_.end(), other) - children_.begin(); | 628 std::find(children_.begin(), children_.end(), other) - children_.begin(); |
| 629 if ((above && child_i == other_i + 1) || (!above && child_i + 1 == other_i)) | 629 if ((above && child_i == other_i + 1) || (!above && child_i + 1 == other_i)) |
| 630 return; | 630 return; |
| 631 | 631 |
| 632 const size_t dest_i = | 632 const size_t dest_i = |
| 633 above ? | 633 above ? |
| 634 (child_i < other_i ? other_i : other_i + 1) : | 634 (child_i < other_i ? other_i : other_i + 1) : |
| 635 (child_i < other_i ? other_i - 1 : other_i); | 635 (child_i < other_i ? other_i - 1 : other_i); |
| 636 children_.erase(children_.begin() + child_i); | 636 children_.erase(children_.begin() + child_i); |
| 637 children_.insert(children_.begin() + dest_i, child); | 637 children_.insert(children_.begin() + dest_i, child); |
| 638 | 638 |
| 639 child->cc_layer_->removeFromParent(); | 639 child->cc_layer_->RemoveFromParent(); |
| 640 cc_layer_->insertChild(child->cc_layer_, dest_i); | 640 cc_layer_->InsertChild(child->cc_layer_, dest_i); |
| 641 } | 641 } |
| 642 | 642 |
| 643 bool Layer::ConvertPointForAncestor(const Layer* ancestor, | 643 bool Layer::ConvertPointForAncestor(const Layer* ancestor, |
| 644 gfx::Point* point) const { | 644 gfx::Point* point) const { |
| 645 gfx::Transform transform; | 645 gfx::Transform transform; |
| 646 bool result = GetTargetTransformRelativeTo(ancestor, &transform); | 646 bool result = GetTargetTransformRelativeTo(ancestor, &transform); |
| 647 gfx::Point3F p(*point); | 647 gfx::Point3F p(*point); |
| 648 transform.TransformPoint(p); | 648 transform.TransformPoint(p); |
| 649 *point = gfx::ToFlooredPoint(p.AsPointF()); | 649 *point = gfx::ToFlooredPoint(p.AsPointF()); |
| 650 return result; | 650 return result; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 } | 702 } |
| 703 } | 703 } |
| 704 | 704 |
| 705 void Layer::SetTransformImmediately(const gfx::Transform& transform) { | 705 void Layer::SetTransformImmediately(const gfx::Transform& transform) { |
| 706 transform_ = transform; | 706 transform_ = transform; |
| 707 | 707 |
| 708 RecomputeTransform(); | 708 RecomputeTransform(); |
| 709 } | 709 } |
| 710 | 710 |
| 711 void Layer::SetOpacityImmediately(float opacity) { | 711 void Layer::SetOpacityImmediately(float opacity) { |
| 712 cc_layer_->setOpacity(opacity); | 712 cc_layer_->SetOpacity(opacity); |
| 713 ScheduleDraw(); | 713 ScheduleDraw(); |
| 714 } | 714 } |
| 715 | 715 |
| 716 void Layer::SetVisibilityImmediately(bool visible) { | 716 void Layer::SetVisibilityImmediately(bool visible) { |
| 717 if (visible_ == visible) | 717 if (visible_ == visible) |
| 718 return; | 718 return; |
| 719 | 719 |
| 720 visible_ = visible; | 720 visible_ = visible; |
| 721 UpdateIsDrawn(); | 721 UpdateIsDrawn(); |
| 722 } | 722 } |
| 723 | 723 |
| 724 void Layer::SetBrightnessImmediately(float brightness) { | 724 void Layer::SetBrightnessImmediately(float brightness) { |
| 725 layer_brightness_ = brightness; | 725 layer_brightness_ = brightness; |
| 726 SetLayerFilters(); | 726 SetLayerFilters(); |
| 727 } | 727 } |
| 728 | 728 |
| 729 void Layer::SetGrayscaleImmediately(float grayscale) { | 729 void Layer::SetGrayscaleImmediately(float grayscale) { |
| 730 layer_grayscale_ = grayscale; | 730 layer_grayscale_ = grayscale; |
| 731 SetLayerFilters(); | 731 SetLayerFilters(); |
| 732 } | 732 } |
| 733 | 733 |
| 734 void Layer::SetColorImmediately(SkColor color) { | 734 void Layer::SetColorImmediately(SkColor color) { |
| 735 DCHECK_EQ(type_, LAYER_SOLID_COLOR); | 735 DCHECK_EQ(type_, LAYER_SOLID_COLOR); |
| 736 // WebColor is equivalent to SkColor, per WebColor.h. | 736 // WebColor is equivalent to SkColor, per WebColor.h. |
| 737 solid_color_layer_->setBackgroundColor(static_cast<WebKit::WebColor>(color)); | 737 solid_color_layer_->SetBackgroundColor(static_cast<WebKit::WebColor>(color)); |
| 738 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); | 738 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); |
| 739 } | 739 } |
| 740 | 740 |
| 741 void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) { | 741 void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) { |
| 742 SetBoundsImmediately(bounds); | 742 SetBoundsImmediately(bounds); |
| 743 } | 743 } |
| 744 | 744 |
| 745 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { | 745 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { |
| 746 SetTransformImmediately(transform); | 746 SetTransformImmediately(transform); |
| 747 } | 747 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 | 792 |
| 793 float Layer::GetGrayscaleForAnimation() const { | 793 float Layer::GetGrayscaleForAnimation() const { |
| 794 return layer_grayscale(); | 794 return layer_grayscale(); |
| 795 } | 795 } |
| 796 | 796 |
| 797 SkColor Layer::GetColorForAnimation() const { | 797 SkColor Layer::GetColorForAnimation() const { |
| 798 // WebColor is equivalent to SkColor, per WebColor.h. | 798 // WebColor is equivalent to SkColor, per WebColor.h. |
| 799 // The NULL check is here since this is invoked regardless of whether we have | 799 // The NULL check is here since this is invoked regardless of whether we have |
| 800 // been configured as LAYER_SOLID_COLOR. | 800 // been configured as LAYER_SOLID_COLOR. |
| 801 return solid_color_layer_.get() ? | 801 return solid_color_layer_.get() ? |
| 802 solid_color_layer_->backgroundColor() : SK_ColorBLACK; | 802 solid_color_layer_->background_color() : SK_ColorBLACK; |
| 803 } | 803 } |
| 804 | 804 |
| 805 void Layer::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) { | 805 void Layer::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) { |
| 806 DCHECK(cc_layer_); | 806 DCHECK(cc_layer_); |
| 807 cc_layer_->AddAnimation(animation.Pass()); | 807 cc_layer_->AddAnimation(animation.Pass()); |
| 808 } | 808 } |
| 809 | 809 |
| 810 void Layer::RemoveThreadedAnimation(int animation_id) { | 810 void Layer::RemoveThreadedAnimation(int animation_id) { |
| 811 DCHECK(cc_layer_); | 811 DCHECK(cc_layer_); |
| 812 cc_layer_->RemoveAnimation(animation_id); | 812 cc_layer_->RemoveAnimation(animation_id); |
| 813 } | 813 } |
| 814 | 814 |
| 815 void Layer::CreateWebLayer() { | 815 void Layer::CreateWebLayer() { |
| 816 if (type_ == LAYER_SOLID_COLOR) { | 816 if (type_ == LAYER_SOLID_COLOR) { |
| 817 solid_color_layer_ = cc::SolidColorLayer::Create(); | 817 solid_color_layer_ = cc::SolidColorLayer::Create(); |
| 818 cc_layer_ = solid_color_layer_.get(); | 818 cc_layer_ = solid_color_layer_.get(); |
| 819 } else { | 819 } else { |
| 820 content_layer_ = cc::ContentLayer::create(this); | 820 content_layer_ = cc::ContentLayer::Create(this); |
| 821 cc_layer_ = content_layer_.get(); | 821 cc_layer_ = content_layer_.get(); |
| 822 } | 822 } |
| 823 cc_layer_->setAnchorPoint(gfx::PointF()); | 823 cc_layer_->SetAnchorPoint(gfx::PointF()); |
| 824 cc_layer_->setContentsOpaque(true); | 824 cc_layer_->SetContentsOpaque(true); |
| 825 cc_layer_->setIsDrawable(type_ != LAYER_NOT_DRAWN); | 825 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); |
| 826 cc_layer_->addLayerAnimationEventObserver(this); | 826 cc_layer_->AddLayerAnimationEventObserver(this); |
| 827 } | 827 } |
| 828 | 828 |
| 829 void Layer::RecomputeTransform() { | 829 void Layer::RecomputeTransform() { |
| 830 gfx::Transform scale_translate; | 830 gfx::Transform scale_translate; |
| 831 scale_translate.matrix().set3x3(device_scale_factor_, 0, 0, | 831 scale_translate.matrix().set3x3(device_scale_factor_, 0, 0, |
| 832 0, device_scale_factor_, 0, | 832 0, device_scale_factor_, 0, |
| 833 0, 0, 1); | 833 0, 0, 1); |
| 834 // Start with the inverse matrix of above. | 834 // Start with the inverse matrix of above. |
| 835 gfx::Transform transform; | 835 gfx::Transform transform; |
| 836 transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0, | 836 transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0, |
| 837 0, 1.0f / device_scale_factor_, 0, | 837 0, 1.0f / device_scale_factor_, 0, |
| 838 0, 0, 1); | 838 0, 0, 1); |
| 839 transform.ConcatTransform(transform_); | 839 transform.ConcatTransform(transform_); |
| 840 gfx::Transform translate; | 840 gfx::Transform translate; |
| 841 translate.Translate(bounds_.x(), bounds_.y()); | 841 translate.Translate(bounds_.x(), bounds_.y()); |
| 842 transform.ConcatTransform(translate); | 842 transform.ConcatTransform(translate); |
| 843 transform.ConcatTransform(scale_translate); | 843 transform.ConcatTransform(scale_translate); |
| 844 cc_layer_->setTransform(transform); | 844 cc_layer_->SetTransform(transform); |
| 845 } | 845 } |
| 846 | 846 |
| 847 void Layer::RecomputeDrawsContentAndUVRect() { | 847 void Layer::RecomputeDrawsContentAndUVRect() { |
| 848 DCHECK(cc_layer_); | 848 DCHECK(cc_layer_); |
| 849 gfx::Size size(bounds_.size()); | 849 gfx::Size size(bounds_.size()); |
| 850 if (texture_layer_.get()) { | 850 if (texture_layer_.get()) { |
| 851 DCHECK(texture_); | 851 DCHECK(texture_); |
| 852 | 852 |
| 853 float texture_scale_factor = 1.0f / texture_->device_scale_factor(); | 853 float texture_scale_factor = 1.0f / texture_->device_scale_factor(); |
| 854 gfx::Size texture_size = gfx::ToFlooredSize( | 854 gfx::Size texture_size = gfx::ToFlooredSize( |
| 855 gfx::ScaleSize(texture_->size(), texture_scale_factor)); | 855 gfx::ScaleSize(texture_->size(), texture_scale_factor)); |
| 856 size.ClampToMax(texture_size); | 856 size.ClampToMax(texture_size); |
| 857 | 857 |
| 858 gfx::PointF uv_top_left(0.f, 0.f); | 858 gfx::PointF uv_top_left(0.f, 0.f); |
| 859 gfx::PointF uv_bottom_right( | 859 gfx::PointF uv_bottom_right( |
| 860 static_cast<float>(size.width())/texture_size.width(), | 860 static_cast<float>(size.width())/texture_size.width(), |
| 861 static_cast<float>(size.height())/texture_size.height()); | 861 static_cast<float>(size.height())/texture_size.height()); |
| 862 texture_layer_->setUV(uv_top_left, uv_bottom_right); | 862 texture_layer_->setUV(uv_top_left, uv_bottom_right); |
| 863 } else if (delegated_renderer_layer_.get()) { | 863 } else if (delegated_renderer_layer_.get()) { |
| 864 delegated_renderer_layer_->SetDisplaySize( | 864 delegated_renderer_layer_->SetDisplaySize( |
| 865 ConvertSizeToPixel(this, delegated_frame_size_in_dip_)); | 865 ConvertSizeToPixel(this, delegated_frame_size_in_dip_)); |
| 866 size.ClampToMax(delegated_frame_size_in_dip_); | 866 size.ClampToMax(delegated_frame_size_in_dip_); |
| 867 } | 867 } |
| 868 cc_layer_->setBounds(ConvertSizeToPixel(this, size)); | 868 cc_layer_->SetBounds(ConvertSizeToPixel(this, size)); |
| 869 } | 869 } |
| 870 | 870 |
| 871 } // namespace ui | 871 } // namespace ui |
| OLD | NEW |