| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 return GetRoot(this)->compositor_; | 90 return GetRoot(this)->compositor_; |
| 91 } | 91 } |
| 92 | 92 |
| 93 void Layer::SetCompositor(Compositor* compositor) { | 93 void Layer::SetCompositor(Compositor* compositor) { |
| 94 // This function must only be called to set the compositor on the root layer, | 94 // This function must only be called to set the compositor on the root layer, |
| 95 // or to reset it. | 95 // or to reset it. |
| 96 DCHECK(!compositor || !compositor_); | 96 DCHECK(!compositor || !compositor_); |
| 97 DCHECK(!compositor || compositor->root_layer() == this); | 97 DCHECK(!compositor || compositor->root_layer() == this); |
| 98 DCHECK(!parent_); | 98 DCHECK(!parent_); |
| 99 compositor_ = compositor; | 99 compositor_ = compositor; |
| 100 if (IsDIPEnabled() && compositor) | 100 if (compositor) |
| 101 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); | 101 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void Layer::Add(Layer* child) { | 104 void Layer::Add(Layer* child) { |
| 105 DCHECK(!child->compositor_); | 105 DCHECK(!child->compositor_); |
| 106 if (child->parent_) | 106 if (child->parent_) |
| 107 child->parent_->Remove(child); | 107 child->parent_->Remove(child); |
| 108 child->parent_ = this; | 108 child->parent_ = this; |
| 109 children_.push_back(child); | 109 children_.push_back(child); |
| 110 web_layer_.addChild(child->web_layer_); | 110 web_layer_.addChild(child->web_layer_); |
| 111 if (IsDIPEnabled()) | 111 child->OnDeviceScaleFactorChanged(device_scale_factor_); |
| 112 child->OnDeviceScaleFactorChanged(device_scale_factor_); | |
| 113 } | 112 } |
| 114 | 113 |
| 115 void Layer::Remove(Layer* child) { | 114 void Layer::Remove(Layer* child) { |
| 116 std::vector<Layer*>::iterator i = | 115 std::vector<Layer*>::iterator i = |
| 117 std::find(children_.begin(), children_.end(), child); | 116 std::find(children_.begin(), children_.end(), child); |
| 118 DCHECK(i != children_.end()); | 117 DCHECK(i != children_.end()); |
| 119 children_.erase(i); | 118 children_.erase(i); |
| 120 child->parent_ = NULL; | 119 child->parent_ = NULL; |
| 121 child->web_layer_.removeFromParent(); | 120 child->web_layer_.removeFromParent(); |
| 122 } | 121 } |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 !iter.done(); iter.next()) { | 330 !iter.done(); iter.next()) { |
| 332 const SkIRect& sk_damaged = iter.rect(); | 331 const SkIRect& sk_damaged = iter.rect(); |
| 333 gfx::Rect damaged( | 332 gfx::Rect damaged( |
| 334 sk_damaged.x(), | 333 sk_damaged.x(), |
| 335 sk_damaged.y(), | 334 sk_damaged.y(), |
| 336 sk_damaged.width(), | 335 sk_damaged.width(), |
| 337 sk_damaged.height()); | 336 sk_damaged.height()); |
| 338 | 337 |
| 339 // TODO(pkotwicz): Remove this once we are no longer linearly upscaling | 338 // TODO(pkotwicz): Remove this once we are no longer linearly upscaling |
| 340 // web contents when DIP is enabled (crbug.com/127455). | 339 // web contents when DIP is enabled (crbug.com/127455). |
| 341 if (IsDIPEnabled() && web_layer_is_accelerated_) { | 340 if (web_layer_is_accelerated_) { |
| 342 damaged.Inset(-1, -1); | 341 damaged.Inset(-1, -1); |
| 343 damaged = damaged.Intersect(bounds_); | 342 damaged = damaged.Intersect(bounds_); |
| 344 } | 343 } |
| 345 | 344 |
| 346 gfx::Rect damaged_in_pixel = ConvertRectToPixel(this, damaged); | 345 gfx::Rect damaged_in_pixel = ConvertRectToPixel(this, damaged); |
| 347 WebKit::WebFloatRect web_rect( | 346 WebKit::WebFloatRect web_rect( |
| 348 damaged_in_pixel.x(), | 347 damaged_in_pixel.x(), |
| 349 damaged_in_pixel.y(), | 348 damaged_in_pixel.y(), |
| 350 damaged_in_pixel.width(), | 349 damaged_in_pixel.width(), |
| 351 damaged_in_pixel.height()); | 350 damaged_in_pixel.height()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 363 | 362 |
| 364 void Layer::SuppressPaint() { | 363 void Layer::SuppressPaint() { |
| 365 if (!delegate_) | 364 if (!delegate_) |
| 366 return; | 365 return; |
| 367 delegate_ = NULL; | 366 delegate_ = NULL; |
| 368 for (size_t i = 0; i < children_.size(); ++i) | 367 for (size_t i = 0; i < children_.size(); ++i) |
| 369 children_[i]->SuppressPaint(); | 368 children_[i]->SuppressPaint(); |
| 370 } | 369 } |
| 371 | 370 |
| 372 void Layer::OnDeviceScaleFactorChanged(float device_scale_factor) { | 371 void Layer::OnDeviceScaleFactorChanged(float device_scale_factor) { |
| 373 CHECK(IsDIPEnabled()); | |
| 374 if (device_scale_factor_ == device_scale_factor) | 372 if (device_scale_factor_ == device_scale_factor) |
| 375 return; | 373 return; |
| 376 device_scale_factor_ = device_scale_factor; | 374 device_scale_factor_ = device_scale_factor; |
| 377 RecomputeTransform(); | 375 RecomputeTransform(); |
| 378 RecomputeDrawsContentAndUVRect(); | 376 RecomputeDrawsContentAndUVRect(); |
| 379 SchedulePaint(gfx::Rect(bounds_.size())); | 377 SchedulePaint(gfx::Rect(bounds_.size())); |
| 380 if (delegate_) | 378 if (delegate_) |
| 381 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); | 379 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); |
| 382 for (size_t i = 0; i < children_.size(); ++i) | 380 for (size_t i = 0; i < children_.size(); ++i) |
| 383 children_[i]->OnDeviceScaleFactorChanged(device_scale_factor); | 381 children_[i]->OnDeviceScaleFactorChanged(device_scale_factor); |
| 384 } | 382 } |
| 385 | 383 |
| 386 void Layer::paintContents(WebKit::WebCanvas* web_canvas, | 384 void Layer::paintContents(WebKit::WebCanvas* web_canvas, |
| 387 const WebKit::WebRect& clip) { | 385 const WebKit::WebRect& clip) { |
| 388 TRACE_EVENT0("ui", "Layer::paintContents"); | 386 TRACE_EVENT0("ui", "Layer::paintContents"); |
| 389 gfx::Canvas canvas(web_canvas); | 387 gfx::Canvas canvas(web_canvas); |
| 390 bool scale_canvas = IsDIPEnabled() && scale_canvas_; | 388 bool scale_canvas = scale_canvas_; |
| 391 if (scale_canvas) { | 389 if (scale_canvas) { |
| 392 canvas.sk_canvas()->scale(SkFloatToScalar(device_scale_factor_), | 390 canvas.sk_canvas()->scale(SkFloatToScalar(device_scale_factor_), |
| 393 SkFloatToScalar(device_scale_factor_)); | 391 SkFloatToScalar(device_scale_factor_)); |
| 394 } | 392 } |
| 395 if (delegate_) | 393 if (delegate_) |
| 396 delegate_->OnPaintLayer(&canvas); | 394 delegate_->OnPaintLayer(&canvas); |
| 397 if (scale_canvas) | 395 if (scale_canvas) |
| 398 canvas.Restore(); | 396 canvas.Restore(); |
| 399 } | 397 } |
| 400 | 398 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 web_layer_ = WebKit::WebContentLayer::create(this); | 551 web_layer_ = WebKit::WebContentLayer::create(this); |
| 554 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | 552 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
| 555 web_layer_.setOpaque(true); | 553 web_layer_.setOpaque(true); |
| 556 web_layer_is_accelerated_ = false; | 554 web_layer_is_accelerated_ = false; |
| 557 show_debug_borders_ = CommandLine::ForCurrentProcess()->HasSwitch( | 555 show_debug_borders_ = CommandLine::ForCurrentProcess()->HasSwitch( |
| 558 switches::kUIShowLayerBorders); | 556 switches::kUIShowLayerBorders); |
| 559 web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0); | 557 web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0); |
| 560 } | 558 } |
| 561 | 559 |
| 562 void Layer::RecomputeTransform() { | 560 void Layer::RecomputeTransform() { |
| 563 if (IsDIPEnabled()) { | 561 ui::Transform scale_translate; |
| 564 ui::Transform scale_translate; | 562 scale_translate.matrix().set3x3(device_scale_factor_, 0, 0, |
| 565 scale_translate.matrix().set3x3(device_scale_factor_, 0, 0, | 563 0, device_scale_factor_, 0, |
| 566 0, device_scale_factor_, 0, | 564 0, 0, 1); |
| 567 0, 0, 1); | 565 // Start with the inverse matrix of above. |
| 568 // Start with the inverse matrix of above. | 566 Transform transform; |
| 569 Transform transform; | 567 transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0, |
| 570 transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0, | 568 0, 1.0f / device_scale_factor_, 0, |
| 571 0, 1.0f / device_scale_factor_, 0, | 569 0, 0, 1); |
| 572 0, 0, 1); | 570 transform.ConcatTransform(transform_); |
| 573 transform.ConcatTransform(transform_); | 571 transform.ConcatTranslate(bounds_.x(), bounds_.y()); |
| 574 transform.ConcatTranslate(bounds_.x(), bounds_.y()); | 572 transform.ConcatTransform(scale_translate); |
| 575 transform.ConcatTransform(scale_translate); | 573 web_layer_.setTransform(transform.matrix()); |
| 576 web_layer_.setTransform(transform.matrix()); | |
| 577 } else { | |
| 578 Transform t = transform_; | |
| 579 t.ConcatTranslate(bounds_.x(), bounds_.y()); | |
| 580 web_layer_.setTransform(t.matrix()); | |
| 581 } | |
| 582 } | 574 } |
| 583 | 575 |
| 584 void Layer::RecomputeDrawsContentAndUVRect() { | 576 void Layer::RecomputeDrawsContentAndUVRect() { |
| 585 DCHECK(!web_layer_.isNull()); | 577 DCHECK(!web_layer_.isNull()); |
| 586 bool should_draw = type_ != LAYER_NOT_DRAWN; | 578 bool should_draw = type_ != LAYER_NOT_DRAWN; |
| 587 if (!web_layer_is_accelerated_) { | 579 if (!web_layer_is_accelerated_) { |
| 588 if (type_ != LAYER_SOLID_COLOR) | 580 if (type_ != LAYER_SOLID_COLOR) |
| 589 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); | 581 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); |
| 590 web_layer_.setBounds(ConvertSizeToPixel(this, bounds_.size())); | 582 web_layer_.setBounds(ConvertSizeToPixel(this, bounds_.size())); |
| 591 } else { | 583 } else { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 620 return; | 612 return; |
| 621 unsigned int color = 0xFF000000; | 613 unsigned int color = 0xFF000000; |
| 622 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; | 614 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; |
| 623 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); | 615 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); |
| 624 if (!opaque) | 616 if (!opaque) |
| 625 color |= 0xFF; | 617 color |= 0xFF; |
| 626 web_layer_.setDebugBorderColor(color); | 618 web_layer_.setDebugBorderColor(color); |
| 627 } | 619 } |
| 628 | 620 |
| 629 } // namespace ui | 621 } // namespace ui |
| OLD | NEW |