| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" | 13 #include "cc/content_layer.h" |
| 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorSuppor
t.h" | 14 #include "cc/solid_color_layer.h" |
| 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebContentLayer.h" | 15 #include "cc/texture_layer.h" |
| 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureL
ayer.h" | |
| 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperation.
h" | 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperation.
h" |
| 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations
.h" | 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations
.h" |
| 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h" | |
| 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatRect.h" | |
| 21 #include "third_party/WebKit/Source/Platform/chromium/public/WebSolidColorLayer.
h" | |
| 22 #include "ui/base/animation/animation.h" | 18 #include "ui/base/animation/animation.h" |
| 23 #include "ui/compositor/compositor_switches.h" | 19 #include "ui/compositor/compositor_switches.h" |
| 24 #include "ui/compositor/dip_util.h" | 20 #include "ui/compositor/dip_util.h" |
| 25 #include "ui/compositor/layer_animator.h" | 21 #include "ui/compositor/layer_animator.h" |
| 26 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
| 27 #include "ui/gfx/display.h" | 23 #include "ui/gfx/display.h" |
| 28 #include "ui/gfx/interpolated_transform.h" | 24 #include "ui/gfx/interpolated_transform.h" |
| 29 #include "ui/gfx/point_conversions.h" | 25 #include "ui/gfx/point_conversions.h" |
| 30 #include "ui/gfx/point3_f.h" | 26 #include "ui/gfx/point3_f.h" |
| 31 #include "ui/gfx/size_conversions.h" | 27 #include "ui/gfx/size_conversions.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 61 layer_brightness_(0.0f), | 57 layer_brightness_(0.0f), |
| 62 layer_grayscale_(0.0f), | 58 layer_grayscale_(0.0f), |
| 63 layer_inverted_(false), | 59 layer_inverted_(false), |
| 64 layer_mask_(NULL), | 60 layer_mask_(NULL), |
| 65 layer_mask_back_link_(NULL), | 61 layer_mask_back_link_(NULL), |
| 66 zoom_x_offset_(0), | 62 zoom_x_offset_(0), |
| 67 zoom_y_offset_(0), | 63 zoom_y_offset_(0), |
| 68 zoom_(1), | 64 zoom_(1), |
| 69 zoom_inset_(0), | 65 zoom_inset_(0), |
| 70 delegate_(NULL), | 66 delegate_(NULL), |
| 71 web_layer_(NULL), | 67 cc_layer_(NULL), |
| 72 scale_content_(true), | 68 scale_content_(true), |
| 73 device_scale_factor_(1.0f) { | 69 device_scale_factor_(1.0f) { |
| 74 CreateWebLayer(); | 70 CreateWebLayer(); |
| 75 } | 71 } |
| 76 | 72 |
| 77 Layer::Layer(LayerType type) | 73 Layer::Layer(LayerType type) |
| 78 : type_(type), | 74 : type_(type), |
| 79 compositor_(NULL), | 75 compositor_(NULL), |
| 80 parent_(NULL), | 76 parent_(NULL), |
| 81 visible_(true), | 77 visible_(true), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 110 if (compositor_) | 106 if (compositor_) |
| 111 compositor_->SetRootLayer(NULL); | 107 compositor_->SetRootLayer(NULL); |
| 112 if (parent_) | 108 if (parent_) |
| 113 parent_->Remove(this); | 109 parent_->Remove(this); |
| 114 if (layer_mask_) | 110 if (layer_mask_) |
| 115 SetMaskLayer(NULL); | 111 SetMaskLayer(NULL); |
| 116 if (layer_mask_back_link_) | 112 if (layer_mask_back_link_) |
| 117 layer_mask_back_link_->SetMaskLayer(NULL); | 113 layer_mask_back_link_->SetMaskLayer(NULL); |
| 118 for (size_t i = 0; i < children_.size(); ++i) | 114 for (size_t i = 0; i < children_.size(); ++i) |
| 119 children_[i]->parent_ = NULL; | 115 children_[i]->parent_ = NULL; |
| 120 web_layer_->removeFromParent(); | 116 cc_layer_->removeFromParent(); |
| 121 } | 117 } |
| 122 | 118 |
| 123 Compositor* Layer::GetCompositor() { | 119 Compositor* Layer::GetCompositor() { |
| 124 return GetRoot(this)->compositor_; | 120 return GetRoot(this)->compositor_; |
| 125 } | 121 } |
| 126 | 122 |
| 127 void Layer::SetCompositor(Compositor* compositor) { | 123 void Layer::SetCompositor(Compositor* compositor) { |
| 128 // This function must only be called to set the compositor on the root layer, | 124 // This function must only be called to set the compositor on the root layer, |
| 129 // or to reset it. | 125 // or to reset it. |
| 130 DCHECK(!compositor || !compositor_); | 126 DCHECK(!compositor || !compositor_); |
| 131 DCHECK(!compositor || compositor->root_layer() == this); | 127 DCHECK(!compositor || compositor->root_layer() == this); |
| 132 DCHECK(!parent_); | 128 DCHECK(!parent_); |
| 133 compositor_ = compositor; | 129 compositor_ = compositor; |
| 134 if (compositor) | 130 if (compositor) |
| 135 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); | 131 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); |
| 136 } | 132 } |
| 137 | 133 |
| 138 void Layer::Add(Layer* child) { | 134 void Layer::Add(Layer* child) { |
| 139 DCHECK(!child->compositor_); | 135 DCHECK(!child->compositor_); |
| 140 if (child->parent_) | 136 if (child->parent_) |
| 141 child->parent_->Remove(child); | 137 child->parent_->Remove(child); |
| 142 child->parent_ = this; | 138 child->parent_ = this; |
| 143 children_.push_back(child); | 139 children_.push_back(child); |
| 144 web_layer_->addChild(child->web_layer_); | 140 cc_layer_->addChild(child->cc_layer_); |
| 145 child->OnDeviceScaleFactorChanged(device_scale_factor_); | 141 child->OnDeviceScaleFactorChanged(device_scale_factor_); |
| 146 } | 142 } |
| 147 | 143 |
| 148 void Layer::Remove(Layer* child) { | 144 void Layer::Remove(Layer* child) { |
| 149 std::vector<Layer*>::iterator i = | 145 std::vector<Layer*>::iterator i = |
| 150 std::find(children_.begin(), children_.end(), child); | 146 std::find(children_.begin(), children_.end(), child); |
| 151 DCHECK(i != children_.end()); | 147 DCHECK(i != children_.end()); |
| 152 children_.erase(i); | 148 children_.erase(i); |
| 153 child->parent_ = NULL; | 149 child->parent_ = NULL; |
| 154 child->web_layer_->removeFromParent(); | 150 child->cc_layer_->removeFromParent(); |
| 155 } | 151 } |
| 156 | 152 |
| 157 void Layer::StackAtTop(Layer* child) { | 153 void Layer::StackAtTop(Layer* child) { |
| 158 if (children_.size() <= 1 || child == children_.back()) | 154 if (children_.size() <= 1 || child == children_.back()) |
| 159 return; // Already in front. | 155 return; // Already in front. |
| 160 StackAbove(child, children_.back()); | 156 StackAbove(child, children_.back()); |
| 161 } | 157 } |
| 162 | 158 |
| 163 void Layer::StackAbove(Layer* child, Layer* other) { | 159 void Layer::StackAbove(Layer* child, Layer* other) { |
| 164 StackRelativeTo(child, other, true); | 160 StackRelativeTo(child, other, true); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 208 |
| 213 gfx::Rect Layer::GetTargetBounds() const { | 209 gfx::Rect Layer::GetTargetBounds() const { |
| 214 if (animator_.get() && animator_->IsAnimatingProperty( | 210 if (animator_.get() && animator_->IsAnimatingProperty( |
| 215 LayerAnimationElement::BOUNDS)) { | 211 LayerAnimationElement::BOUNDS)) { |
| 216 return animator_->GetTargetBounds(); | 212 return animator_->GetTargetBounds(); |
| 217 } | 213 } |
| 218 return bounds_; | 214 return bounds_; |
| 219 } | 215 } |
| 220 | 216 |
| 221 void Layer::SetMasksToBounds(bool masks_to_bounds) { | 217 void Layer::SetMasksToBounds(bool masks_to_bounds) { |
| 222 web_layer_->setMasksToBounds(masks_to_bounds); | 218 cc_layer_->setMasksToBounds(masks_to_bounds); |
| 223 } | 219 } |
| 224 | 220 |
| 225 bool Layer::GetMasksToBounds() const { | 221 bool Layer::GetMasksToBounds() const { |
| 226 return web_layer_->masksToBounds(); | 222 return cc_layer_->masksToBounds(); |
| 227 } | 223 } |
| 228 | 224 |
| 229 void Layer::SetOpacity(float opacity) { | 225 void Layer::SetOpacity(float opacity) { |
| 230 GetAnimator()->SetOpacity(opacity); | 226 GetAnimator()->SetOpacity(opacity); |
| 231 } | 227 } |
| 232 | 228 |
| 233 float Layer::GetCombinedOpacity() const { | 229 float Layer::GetCombinedOpacity() const { |
| 234 float opacity = opacity_; | 230 float opacity = opacity_; |
| 235 Layer* current = this->parent_; | 231 Layer* current = this->parent_; |
| 236 while (current) { | 232 while (current) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 layer_mask->children().empty() && | 283 layer_mask->children().empty() && |
| 288 !layer_mask->layer_mask_back_link_)); | 284 !layer_mask->layer_mask_back_link_)); |
| 289 DCHECK(!layer_mask_back_link_); | 285 DCHECK(!layer_mask_back_link_); |
| 290 if (layer_mask_ == layer_mask) | 286 if (layer_mask_ == layer_mask) |
| 291 return; | 287 return; |
| 292 // We need to de-reference the currently linked object so that no problem | 288 // We need to de-reference the currently linked object so that no problem |
| 293 // arises if the mask layer gets deleted before this object. | 289 // arises if the mask layer gets deleted before this object. |
| 294 if (layer_mask_) | 290 if (layer_mask_) |
| 295 layer_mask_->layer_mask_back_link_ = NULL; | 291 layer_mask_->layer_mask_back_link_ = NULL; |
| 296 layer_mask_ = layer_mask; | 292 layer_mask_ = layer_mask; |
| 297 web_layer_->setMaskLayer( | 293 cc_layer_->setMaskLayer( |
| 298 layer_mask ? layer_mask->web_layer() : NULL); | 294 layer_mask ? layer_mask->cc_layer() : NULL); |
| 299 // We need to reference the linked object so that it can properly break the | 295 // We need to reference the linked object so that it can properly break the |
| 300 // link to us when it gets deleted. | 296 // link to us when it gets deleted. |
| 301 if (layer_mask) { | 297 if (layer_mask) { |
| 302 layer_mask->layer_mask_back_link_ = this; | 298 layer_mask->layer_mask_back_link_ = this; |
| 303 layer_mask->OnDeviceScaleFactorChanged(device_scale_factor_); | 299 layer_mask->OnDeviceScaleFactorChanged(device_scale_factor_); |
| 304 } | 300 } |
| 305 } | 301 } |
| 306 | 302 |
| 307 void Layer::SetBackgroundZoom(float x_offset, | 303 void Layer::SetBackgroundZoom(float x_offset, |
| 308 float y_offset, | 304 float y_offset, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 329 if (layer_inverted_) | 325 if (layer_inverted_) |
| 330 filters.append(WebKit::WebFilterOperation::createInvertFilter(1.0)); | 326 filters.append(WebKit::WebFilterOperation::createInvertFilter(1.0)); |
| 331 // Brightness goes last, because the resulting colors neeed clamping, which | 327 // Brightness goes last, because the resulting colors neeed clamping, which |
| 332 // cause further color matrix filters to be applied separately. In this order, | 328 // cause further color matrix filters to be applied separately. In this order, |
| 333 // they all can be combined in a single pass. | 329 // they all can be combined in a single pass. |
| 334 if (layer_brightness_) { | 330 if (layer_brightness_) { |
| 335 filters.append(WebKit::WebFilterOperation::createBrightnessFilter( | 331 filters.append(WebKit::WebFilterOperation::createBrightnessFilter( |
| 336 layer_brightness_)); | 332 layer_brightness_)); |
| 337 } | 333 } |
| 338 | 334 |
| 339 web_layer_->setFilters(filters); | 335 cc_layer_->setFilters(filters); |
| 340 } | 336 } |
| 341 | 337 |
| 342 void Layer::SetLayerBackgroundFilters() { | 338 void Layer::SetLayerBackgroundFilters() { |
| 343 WebKit::WebFilterOperations filters; | 339 WebKit::WebFilterOperations filters; |
| 344 if (zoom_ != 1) { | 340 if (zoom_ != 1) { |
| 345 filters.append(WebKit::WebFilterOperation::createZoomFilter( | 341 filters.append(WebKit::WebFilterOperation::createZoomFilter( |
| 346 WebKit::WebRect(zoom_x_offset_, zoom_y_offset_, | 342 WebKit::WebRect(zoom_x_offset_, zoom_y_offset_, |
| 347 (GetTargetBounds().width() / zoom_), | 343 (GetTargetBounds().width() / zoom_), |
| 348 (GetTargetBounds().height() / zoom_)), | 344 (GetTargetBounds().height() / zoom_)), |
| 349 zoom_inset_)); | 345 zoom_inset_)); |
| 350 } | 346 } |
| 351 | 347 |
| 352 if (background_blur_radius_) { | 348 if (background_blur_radius_) { |
| 353 filters.append(WebKit::WebFilterOperation::createBlurFilter( | 349 filters.append(WebKit::WebFilterOperation::createBlurFilter( |
| 354 background_blur_radius_)); | 350 background_blur_radius_)); |
| 355 } | 351 } |
| 356 | 352 |
| 357 web_layer_->setBackgroundFilters(filters); | 353 cc_layer_->setBackgroundFilters(filters); |
| 358 } | 354 } |
| 359 | 355 |
| 360 float Layer::GetTargetOpacity() const { | 356 float Layer::GetTargetOpacity() const { |
| 361 if (animator_.get() && animator_->IsAnimatingProperty( | 357 if (animator_.get() && animator_->IsAnimatingProperty( |
| 362 LayerAnimationElement::OPACITY)) | 358 LayerAnimationElement::OPACITY)) |
| 363 return animator_->GetTargetOpacity(); | 359 return animator_->GetTargetOpacity(); |
| 364 return opacity_; | 360 return opacity_; |
| 365 } | 361 } |
| 366 | 362 |
| 367 void Layer::SetVisible(bool visible) { | 363 void Layer::SetVisible(bool visible) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 if (target != root_layer) | 397 if (target != root_layer) |
| 402 target->ConvertPointFromAncestor(root_layer, point); | 398 target->ConvertPointFromAncestor(root_layer, point); |
| 403 } | 399 } |
| 404 | 400 |
| 405 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { | 401 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { |
| 406 if (fills_bounds_opaquely_ == fills_bounds_opaquely) | 402 if (fills_bounds_opaquely_ == fills_bounds_opaquely) |
| 407 return; | 403 return; |
| 408 | 404 |
| 409 fills_bounds_opaquely_ = fills_bounds_opaquely; | 405 fills_bounds_opaquely_ = fills_bounds_opaquely; |
| 410 | 406 |
| 411 web_layer_->setOpaque(fills_bounds_opaquely); | 407 cc_layer_->setContentsOpaque(fills_bounds_opaquely); |
| 412 } | 408 } |
| 413 | 409 |
| 414 void Layer::SetExternalTexture(Texture* texture) { | 410 void Layer::SetExternalTexture(Texture* texture) { |
| 415 DCHECK_EQ(type_, LAYER_TEXTURED); | 411 DCHECK_EQ(type_, LAYER_TEXTURED); |
| 416 layer_updated_externally_ = !!texture; | 412 layer_updated_externally_ = !!texture; |
| 417 texture_ = texture; | 413 texture_ = texture; |
| 418 if (web_layer_is_accelerated_ != layer_updated_externally_) { | 414 if (cc_layer_is_accelerated_ != layer_updated_externally_) { |
| 419 // Switch to a different type of layer. | 415 // Switch to a different type of layer. |
| 420 web_layer_->removeAllChildren(); | 416 cc_layer_->removeAllChildren(); |
| 421 scoped_ptr<WebKit::WebContentLayer> old_content_layer( | 417 scoped_refptr<cc::ContentLayer> old_content_layer( |
| 422 content_layer_.release()); | 418 content_layer_.release()); |
| 423 scoped_ptr<WebKit::WebSolidColorLayer> old_solid_layer( | 419 scoped_refptr<cc::SolidColorLayer> old_solid_layer( |
| 424 solid_color_layer_.release()); | 420 solid_color_layer_.release()); |
| 425 scoped_ptr<WebKit::WebExternalTextureLayer> old_texture_layer( | 421 scoped_refptr<cc::TextureLayer> old_texture_layer( |
| 426 texture_layer_.release()); | 422 texture_layer_.release()); |
| 427 WebKit::WebLayer* new_layer = NULL; | 423 cc::Layer* new_layer = NULL; |
| 428 WebKit::WebCompositorSupport* compositor_support = | |
| 429 WebKit::Platform::current()->compositorSupport(); | |
| 430 if (layer_updated_externally_) { | 424 if (layer_updated_externally_) { |
| 431 texture_layer_.reset( | 425 texture_layer_ = cc::TextureLayer::create(this); |
| 432 compositor_support->createExternalTextureLayer(this)); | |
| 433 texture_layer_->setFlipped(texture_->flipped()); | 426 texture_layer_->setFlipped(texture_->flipped()); |
| 434 new_layer = texture_layer_->layer(); | 427 new_layer = texture_layer_.get(); |
| 435 } else { | 428 } else { |
| 436 old_texture_layer->willModifyTexture(); | 429 old_texture_layer->willModifyTexture(); |
| 437 content_layer_.reset(compositor_support->createContentLayer(this)); | 430 content_layer_ = cc::ContentLayer::create(this); |
| 438 new_layer = content_layer_->layer(); | 431 new_layer = content_layer_.get(); |
| 439 } | 432 } |
| 440 if (parent_) { | 433 if (parent_) { |
| 441 DCHECK(parent_->web_layer_); | 434 DCHECK(parent_->cc_layer_); |
| 442 parent_->web_layer_->replaceChild(web_layer_, new_layer); | 435 parent_->cc_layer_->replaceChild(cc_layer_, new_layer); |
| 443 } | 436 } |
| 444 web_layer_= new_layer; | 437 cc_layer_= new_layer; |
| 445 web_layer_is_accelerated_ = layer_updated_externally_; | 438 cc_layer_is_accelerated_ = layer_updated_externally_; |
| 446 for (size_t i = 0; i < children_.size(); ++i) { | 439 for (size_t i = 0; i < children_.size(); ++i) { |
| 447 DCHECK(children_[i]->web_layer_); | 440 DCHECK(children_[i]->cc_layer_); |
| 448 web_layer_->addChild(children_[i]->web_layer_); | 441 cc_layer_->addChild(children_[i]->cc_layer_); |
| 449 } | 442 } |
| 450 web_layer_->setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | 443 cc_layer_->setAnchorPoint(gfx::PointF()); |
| 451 web_layer_->setOpaque(fills_bounds_opaquely_); | 444 cc_layer_->setContentsOpaque(fills_bounds_opaquely_); |
| 452 web_layer_->setOpacity(visible_ ? opacity_ : 0.f); | 445 cc_layer_->setOpacity(visible_ ? opacity_ : 0.f); |
| 453 web_layer_->setForceRenderSurface(force_render_surface_); | 446 cc_layer_->setForceRenderSurface(force_render_surface_); |
| 447 cc_layer_->setIsDrawable(true); |
| 454 RecomputeTransform(); | 448 RecomputeTransform(); |
| 455 } | 449 } |
| 456 RecomputeDrawsContentAndUVRect(); | 450 RecomputeDrawsContentAndUVRect(); |
| 457 } | 451 } |
| 458 | 452 |
| 459 void Layer::SetColor(SkColor color) { | 453 void Layer::SetColor(SkColor color) { |
| 460 GetAnimator()->SetColor(color); | 454 GetAnimator()->SetColor(color); |
| 461 } | 455 } |
| 462 | 456 |
| 463 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { | 457 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 484 for (SkRegion::Iterator iter(damaged_region_); | 478 for (SkRegion::Iterator iter(damaged_region_); |
| 485 !iter.done(); iter.next()) { | 479 !iter.done(); iter.next()) { |
| 486 const SkIRect& sk_damaged = iter.rect(); | 480 const SkIRect& sk_damaged = iter.rect(); |
| 487 gfx::Rect damaged( | 481 gfx::Rect damaged( |
| 488 sk_damaged.x(), | 482 sk_damaged.x(), |
| 489 sk_damaged.y(), | 483 sk_damaged.y(), |
| 490 sk_damaged.width(), | 484 sk_damaged.width(), |
| 491 sk_damaged.height()); | 485 sk_damaged.height()); |
| 492 | 486 |
| 493 gfx::Rect damaged_in_pixel = ConvertRectToPixel(this, damaged); | 487 gfx::Rect damaged_in_pixel = ConvertRectToPixel(this, damaged); |
| 494 WebKit::WebFloatRect web_rect( | 488 cc_layer_->setNeedsDisplayRect(damaged_in_pixel); |
| 495 damaged_in_pixel.x(), | |
| 496 damaged_in_pixel.y(), | |
| 497 damaged_in_pixel.width(), | |
| 498 damaged_in_pixel.height()); | |
| 499 web_layer_->invalidateRect(web_rect); | |
| 500 } | 489 } |
| 501 damaged_region_.setEmpty(); | 490 damaged_region_.setEmpty(); |
| 502 } | 491 } |
| 503 for (size_t i = 0; i < children_.size(); ++i) | 492 for (size_t i = 0; i < children_.size(); ++i) |
| 504 children_[i]->SendDamagedRects(); | 493 children_[i]->SendDamagedRects(); |
| 505 } | 494 } |
| 506 | 495 |
| 507 void Layer::SuppressPaint() { | 496 void Layer::SuppressPaint() { |
| 508 if (!delegate_) | 497 if (!delegate_) |
| 509 return; | 498 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 520 RecomputeDrawsContentAndUVRect(); | 509 RecomputeDrawsContentAndUVRect(); |
| 521 SchedulePaint(gfx::Rect(bounds_.size())); | 510 SchedulePaint(gfx::Rect(bounds_.size())); |
| 522 if (delegate_) | 511 if (delegate_) |
| 523 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); | 512 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); |
| 524 for (size_t i = 0; i < children_.size(); ++i) | 513 for (size_t i = 0; i < children_.size(); ++i) |
| 525 children_[i]->OnDeviceScaleFactorChanged(device_scale_factor); | 514 children_[i]->OnDeviceScaleFactorChanged(device_scale_factor); |
| 526 if (layer_mask_) | 515 if (layer_mask_) |
| 527 layer_mask_->OnDeviceScaleFactorChanged(device_scale_factor); | 516 layer_mask_->OnDeviceScaleFactorChanged(device_scale_factor); |
| 528 } | 517 } |
| 529 | 518 |
| 530 void Layer::paintContents(WebKit::WebCanvas* web_canvas, | 519 void Layer::paintContents(SkCanvas* sk_canvas, |
| 531 const WebKit::WebRect& clip, | 520 const gfx::Rect& clip, |
| 532 #if WEBCONTENTLAYERCLIENT_HAS_CANPAINTLCDTEXT | 521 gfx::RectF& opaque) { |
| 533 bool can_paint_lcd_text, | |
| 534 #endif // WEBCONTENTLAYERCLIENT_HAS_CANPAINTLCDTEXT | |
| 535 WebKit::WebFloatRect& opaque) { | |
| 536 TRACE_EVENT0("ui", "Layer::paintContents"); | 522 TRACE_EVENT0("ui", "Layer::paintContents"); |
| 537 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling( | 523 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling( |
| 538 web_canvas, ui::GetScaleFactorFromScale(device_scale_factor_))); | 524 sk_canvas, ui::GetScaleFactorFromScale(device_scale_factor_))); |
| 539 | 525 |
| 540 bool scale_content = scale_content_; | 526 bool scale_content = scale_content_; |
| 541 if (scale_content) { | 527 if (scale_content) { |
| 542 canvas->Save(); | 528 canvas->Save(); |
| 543 canvas->sk_canvas()->scale(SkFloatToScalar(device_scale_factor_), | 529 canvas->sk_canvas()->scale(SkFloatToScalar(device_scale_factor_), |
| 544 SkFloatToScalar(device_scale_factor_)); | 530 SkFloatToScalar(device_scale_factor_)); |
| 545 } | 531 } |
| 546 | 532 |
| 547 if (delegate_) | 533 if (delegate_) |
| 548 delegate_->OnPaintLayer(canvas.get()); | 534 delegate_->OnPaintLayer(canvas.get()); |
| 549 if (scale_content) | 535 if (scale_content) |
| 550 canvas->Restore(); | 536 canvas->Restore(); |
| 551 } | 537 } |
| 552 | 538 |
| 553 unsigned Layer::prepareTexture(WebKit::WebTextureUpdater& /* updater */) { | 539 unsigned Layer::prepareTexture(cc::ResourceUpdateQueue&) { |
| 554 DCHECK(layer_updated_externally_); | 540 DCHECK(layer_updated_externally_); |
| 555 return texture_->PrepareTexture(); | 541 return texture_->PrepareTexture(); |
| 556 } | 542 } |
| 557 | 543 |
| 558 WebKit::WebGraphicsContext3D* Layer::context() { | 544 WebKit::WebGraphicsContext3D* Layer::context() { |
| 559 DCHECK(layer_updated_externally_); | 545 DCHECK(layer_updated_externally_); |
| 560 return texture_->HostContext3D(); | 546 return texture_->HostContext3D(); |
| 561 } | 547 } |
| 562 | 548 |
| 563 void Layer::SetForceRenderSurface(bool force) { | 549 void Layer::SetForceRenderSurface(bool force) { |
| 564 if (force_render_surface_ == force) | 550 if (force_render_surface_ == force) |
| 565 return; | 551 return; |
| 566 | 552 |
| 567 force_render_surface_ = force; | 553 force_render_surface_ = force; |
| 568 web_layer_->setForceRenderSurface(force_render_surface_); | 554 cc_layer_->setForceRenderSurface(force_render_surface_); |
| 569 } | 555 } |
| 570 | 556 |
| 571 void Layer::StackRelativeTo(Layer* child, Layer* other, bool above) { | 557 void Layer::StackRelativeTo(Layer* child, Layer* other, bool above) { |
| 572 DCHECK_NE(child, other); | 558 DCHECK_NE(child, other); |
| 573 DCHECK_EQ(this, child->parent()); | 559 DCHECK_EQ(this, child->parent()); |
| 574 DCHECK_EQ(this, other->parent()); | 560 DCHECK_EQ(this, other->parent()); |
| 575 | 561 |
| 576 const size_t child_i = | 562 const size_t child_i = |
| 577 std::find(children_.begin(), children_.end(), child) - children_.begin(); | 563 std::find(children_.begin(), children_.end(), child) - children_.begin(); |
| 578 const size_t other_i = | 564 const size_t other_i = |
| 579 std::find(children_.begin(), children_.end(), other) - children_.begin(); | 565 std::find(children_.begin(), children_.end(), other) - children_.begin(); |
| 580 if ((above && child_i == other_i + 1) || (!above && child_i + 1 == other_i)) | 566 if ((above && child_i == other_i + 1) || (!above && child_i + 1 == other_i)) |
| 581 return; | 567 return; |
| 582 | 568 |
| 583 const size_t dest_i = | 569 const size_t dest_i = |
| 584 above ? | 570 above ? |
| 585 (child_i < other_i ? other_i : other_i + 1) : | 571 (child_i < other_i ? other_i : other_i + 1) : |
| 586 (child_i < other_i ? other_i - 1 : other_i); | 572 (child_i < other_i ? other_i - 1 : other_i); |
| 587 children_.erase(children_.begin() + child_i); | 573 children_.erase(children_.begin() + child_i); |
| 588 children_.insert(children_.begin() + dest_i, child); | 574 children_.insert(children_.begin() + dest_i, child); |
| 589 | 575 |
| 590 child->web_layer_->removeFromParent(); | 576 child->cc_layer_->removeFromParent(); |
| 591 web_layer_->insertChild(child->web_layer_, dest_i); | 577 cc_layer_->insertChild(child->cc_layer_, dest_i); |
| 592 } | 578 } |
| 593 | 579 |
| 594 bool Layer::ConvertPointForAncestor(const Layer* ancestor, | 580 bool Layer::ConvertPointForAncestor(const Layer* ancestor, |
| 595 gfx::Point* point) const { | 581 gfx::Point* point) const { |
| 596 gfx::Transform transform; | 582 gfx::Transform transform; |
| 597 bool result = GetTransformRelativeTo(ancestor, &transform); | 583 bool result = GetTransformRelativeTo(ancestor, &transform); |
| 598 gfx::Point3F p(*point); | 584 gfx::Point3F p(*point); |
| 599 transform.TransformPoint(p); | 585 transform.TransformPoint(p); |
| 600 *point = gfx::ToFlooredPoint(p.AsPointF()); | 586 *point = gfx::ToFlooredPoint(p.AsPointF()); |
| 601 return result; | 587 return result; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 transform_ = transform; | 639 transform_ = transform; |
| 654 | 640 |
| 655 RecomputeTransform(); | 641 RecomputeTransform(); |
| 656 } | 642 } |
| 657 | 643 |
| 658 void Layer::SetOpacityImmediately(float opacity) { | 644 void Layer::SetOpacityImmediately(float opacity) { |
| 659 bool schedule_draw = (opacity != opacity_ && IsDrawn()); | 645 bool schedule_draw = (opacity != opacity_ && IsDrawn()); |
| 660 opacity_ = opacity; | 646 opacity_ = opacity; |
| 661 | 647 |
| 662 if (visible_) | 648 if (visible_) |
| 663 web_layer_->setOpacity(opacity); | 649 cc_layer_->setOpacity(opacity); |
| 664 if (schedule_draw) | 650 if (schedule_draw) |
| 665 ScheduleDraw(); | 651 ScheduleDraw(); |
| 666 } | 652 } |
| 667 | 653 |
| 668 void Layer::SetVisibilityImmediately(bool visible) { | 654 void Layer::SetVisibilityImmediately(bool visible) { |
| 669 if (visible_ == visible) | 655 if (visible_ == visible) |
| 670 return; | 656 return; |
| 671 | 657 |
| 672 visible_ = visible; | 658 visible_ = visible; |
| 673 // TODO(piman): Expose a visibility flag on WebLayer. | 659 // TODO(piman): Expose a visibility flag on WebLayer. |
| 674 web_layer_->setOpacity(visible_ ? opacity_ : 0.f); | 660 cc_layer_->setOpacity(visible_ ? opacity_ : 0.f); |
| 675 } | 661 } |
| 676 | 662 |
| 677 void Layer::SetBrightnessImmediately(float brightness) { | 663 void Layer::SetBrightnessImmediately(float brightness) { |
| 678 layer_brightness_ = brightness; | 664 layer_brightness_ = brightness; |
| 679 SetLayerFilters(); | 665 SetLayerFilters(); |
| 680 } | 666 } |
| 681 | 667 |
| 682 void Layer::SetGrayscaleImmediately(float grayscale) { | 668 void Layer::SetGrayscaleImmediately(float grayscale) { |
| 683 layer_grayscale_ = grayscale; | 669 layer_grayscale_ = grayscale; |
| 684 SetLayerFilters(); | 670 SetLayerFilters(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 | 731 |
| 746 float Layer::GetGrayscaleForAnimation() const { | 732 float Layer::GetGrayscaleForAnimation() const { |
| 747 return layer_grayscale(); | 733 return layer_grayscale(); |
| 748 } | 734 } |
| 749 | 735 |
| 750 SkColor Layer::GetColorForAnimation() const { | 736 SkColor Layer::GetColorForAnimation() const { |
| 751 // WebColor is equivalent to SkColor, per WebColor.h. | 737 // WebColor is equivalent to SkColor, per WebColor.h. |
| 752 // The NULL check is here since this is invoked regardless of whether we have | 738 // The NULL check is here since this is invoked regardless of whether we have |
| 753 // been configured as LAYER_SOLID_COLOR. | 739 // been configured as LAYER_SOLID_COLOR. |
| 754 return solid_color_layer_.get() ? | 740 return solid_color_layer_.get() ? |
| 755 solid_color_layer_->layer()->backgroundColor() : SK_ColorBLACK; | 741 solid_color_layer_->backgroundColor() : SK_ColorBLACK; |
| 756 } | 742 } |
| 757 | 743 |
| 758 void Layer::CreateWebLayer() { | 744 void Layer::CreateWebLayer() { |
| 759 WebKit::WebCompositorSupport* compositor_support = | |
| 760 WebKit::Platform::current()->compositorSupport(); | |
| 761 if (type_ == LAYER_SOLID_COLOR) { | 745 if (type_ == LAYER_SOLID_COLOR) { |
| 762 solid_color_layer_.reset(compositor_support->createSolidColorLayer()); | 746 solid_color_layer_ = cc::SolidColorLayer::create(); |
| 763 web_layer_ = solid_color_layer_->layer(); | 747 cc_layer_ = solid_color_layer_.get(); |
| 764 } else { | 748 } else { |
| 765 content_layer_.reset(compositor_support->createContentLayer(this)); | 749 content_layer_ = cc::ContentLayer::create(this); |
| 766 web_layer_ = content_layer_->layer(); | 750 cc_layer_ = content_layer_.get(); |
| 767 } | 751 } |
| 768 web_layer_is_accelerated_ = false; | 752 cc_layer_is_accelerated_ = false; |
| 769 web_layer_->setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | 753 cc_layer_->setAnchorPoint(gfx::PointF()); |
| 770 web_layer_->setOpaque(true); | 754 cc_layer_->setContentsOpaque(true); |
| 755 cc_layer_->setIsDrawable(type_ != LAYER_NOT_DRAWN); |
| 771 } | 756 } |
| 772 | 757 |
| 773 void Layer::RecomputeTransform() { | 758 void Layer::RecomputeTransform() { |
| 774 gfx::Transform scale_translate; | 759 gfx::Transform scale_translate; |
| 775 scale_translate.matrix().set3x3(device_scale_factor_, 0, 0, | 760 scale_translate.matrix().set3x3(device_scale_factor_, 0, 0, |
| 776 0, device_scale_factor_, 0, | 761 0, device_scale_factor_, 0, |
| 777 0, 0, 1); | 762 0, 0, 1); |
| 778 // Start with the inverse matrix of above. | 763 // Start with the inverse matrix of above. |
| 779 gfx::Transform transform; | 764 gfx::Transform transform; |
| 780 transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0, | 765 transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0, |
| 781 0, 1.0f / device_scale_factor_, 0, | 766 0, 1.0f / device_scale_factor_, 0, |
| 782 0, 0, 1); | 767 0, 0, 1); |
| 783 transform.ConcatTransform(transform_); | 768 transform.ConcatTransform(transform_); |
| 784 transform.ConcatTranslate(bounds_.x(), bounds_.y()); | 769 transform.ConcatTranslate(bounds_.x(), bounds_.y()); |
| 785 transform.ConcatTransform(scale_translate); | 770 transform.ConcatTransform(scale_translate); |
| 786 web_layer_->setTransform(transform.matrix()); | 771 cc_layer_->setTransform(WebKit::WebTransformationMatrix(transform)); |
| 787 } | 772 } |
| 788 | 773 |
| 789 void Layer::RecomputeDrawsContentAndUVRect() { | 774 void Layer::RecomputeDrawsContentAndUVRect() { |
| 790 DCHECK(web_layer_); | 775 DCHECK(cc_layer_); |
| 791 bool should_draw = type_ != LAYER_NOT_DRAWN; | 776 if (!cc_layer_is_accelerated_) { |
| 792 if (!web_layer_is_accelerated_) { | 777 cc_layer_->setBounds(ConvertSizeToPixel(this, bounds_.size())); |
| 793 if (type_ != LAYER_SOLID_COLOR) { | |
| 794 web_layer_->setDrawsContent(should_draw); | |
| 795 } | |
| 796 web_layer_->setBounds(ConvertSizeToPixel(this, bounds_.size())); | |
| 797 } else { | 778 } else { |
| 798 DCHECK(texture_); | 779 DCHECK(texture_); |
| 799 | 780 |
| 800 float texture_scale_factor = 1.0f / texture_->device_scale_factor(); | 781 float texture_scale_factor = 1.0f / texture_->device_scale_factor(); |
| 801 gfx::Size texture_size = gfx::ToFlooredSize( | 782 gfx::Size texture_size = gfx::ToFlooredSize( |
| 802 gfx::ScaleSize(texture_->size(), texture_scale_factor)); | 783 gfx::ScaleSize(texture_->size(), texture_scale_factor)); |
| 803 | 784 |
| 804 gfx::Size size(std::min(bounds().width(), texture_size.width()), | 785 gfx::Size size(std::min(bounds().width(), texture_size.width()), |
| 805 std::min(bounds().height(), texture_size.height())); | 786 std::min(bounds().height(), texture_size.height())); |
| 806 WebKit::WebFloatRect rect( | 787 gfx::RectF rect( |
| 807 0, | 788 0, |
| 808 0, | 789 0, |
| 809 static_cast<float>(size.width())/texture_size.width(), | 790 static_cast<float>(size.width())/texture_size.width(), |
| 810 static_cast<float>(size.height())/texture_size.height()); | 791 static_cast<float>(size.height())/texture_size.height()); |
| 811 texture_layer_->setUVRect(rect); | 792 texture_layer_->setUVRect(rect); |
| 812 | 793 |
| 813 gfx::Size size_in_pixel = ConvertSizeToPixel(this, size); | 794 cc_layer_->setBounds(ConvertSizeToPixel(this, size)); |
| 814 web_layer_->setBounds(size_in_pixel); | |
| 815 } | 795 } |
| 816 } | 796 } |
| 817 | 797 |
| 818 } // namespace ui | 798 } // namespace ui |
| OLD | NEW |