| Index: ui/gfx/compositor/layer.cc
|
| diff --git a/ui/gfx/compositor/layer.cc b/ui/gfx/compositor/layer.cc
|
| index 398ecc942f960609942a3bf989a7adf90f7ff331..b4a75e44d36d142087fd6776749dc907ce388dff 100644
|
| --- a/ui/gfx/compositor/layer.cc
|
| +++ b/ui/gfx/compositor/layer.cc
|
| @@ -21,6 +21,7 @@
|
| #include "ui/base/animation/animation.h"
|
| #include "ui/gfx/canvas.h"
|
| #include "ui/gfx/compositor/compositor_switches.h"
|
| +#include "ui/gfx/compositor/dip_util.h"
|
| #include "ui/gfx/compositor/layer_animator.h"
|
| #include "ui/gfx/interpolated_transform.h"
|
| #include "ui/gfx/point3.h"
|
| @@ -38,6 +39,12 @@ const ui::Layer* GetRoot(const ui::Layer* layer) {
|
| return layer->parent() ? GetRoot(layer->parent()) : layer;
|
| }
|
|
|
| +float GetScale(const ui::Compositor* compositor) {
|
| + if (!ui::IsDIPEnabled())
|
| + return 1.0f;
|
| + return compositor ? compositor->device_scale_factor() : 1.0f;
|
| +}
|
| +
|
| } // namespace
|
|
|
| namespace ui {
|
| @@ -50,7 +57,8 @@ Layer::Layer()
|
| fills_bounds_opaquely_(true),
|
| layer_updated_externally_(false),
|
| opacity_(1.0f),
|
| - delegate_(NULL) {
|
| + delegate_(NULL),
|
| + scale_canvas_(true) {
|
| CreateWebLayer();
|
| }
|
|
|
| @@ -62,7 +70,8 @@ Layer::Layer(LayerType type)
|
| fills_bounds_opaquely_(true),
|
| layer_updated_externally_(false),
|
| opacity_(1.0f),
|
| - delegate_(NULL) {
|
| + delegate_(NULL),
|
| + scale_canvas_(true) {
|
| CreateWebLayer();
|
| }
|
|
|
| @@ -100,6 +109,7 @@ void Layer::Add(Layer* child) {
|
| child->parent_ = this;
|
| children_.push_back(child);
|
| web_layer_.addChild(child->web_layer_);
|
| + child->UpdateLayerSize(GetCompositor());
|
| }
|
|
|
| void Layer::Remove(Layer* child) {
|
| @@ -234,6 +244,8 @@ void Layer::ConvertPointToLayer(const Layer* source,
|
| const Layer* root_layer = GetRoot(source);
|
| CHECK_EQ(root_layer, GetRoot(target));
|
|
|
| + // TODO(oshima): We probably need to handle source's root != target's root
|
| + // case under multi monitor environment.
|
| if (source != root_layer)
|
| source->ConvertPointForAncestor(root_layer, point);
|
| if (target != root_layer)
|
| @@ -254,6 +266,7 @@ void Layer::SetExternalTexture(Texture* texture) {
|
| DCHECK_EQ(type_, LAYER_TEXTURED);
|
| layer_updated_externally_ = !!texture;
|
| texture_ = texture;
|
| + const Compositor* compositor = GetCompositor();
|
| if (web_layer_is_accelerated_ != layer_updated_externally_) {
|
| // Switch to a different type of layer.
|
| web_layer_.removeAllChildren();
|
| @@ -280,10 +293,10 @@ void Layer::SetExternalTexture(Texture* texture) {
|
| web_layer_.setOpaque(fills_bounds_opaquely_);
|
| web_layer_.setOpacity(visible_ ? opacity_ : 0.f);
|
| web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0);
|
| - RecomputeTransform();
|
| + RecomputeTransform(compositor);
|
| RecomputeDebugBorderColor();
|
| }
|
| - RecomputeDrawsContentAndUVRect();
|
| + RecomputeDrawsContentAndUVRect(compositor);
|
| }
|
|
|
| void Layer::SetColor(SkColor color) {
|
| @@ -297,10 +310,11 @@ void Layer::SetColor(SkColor color) {
|
| bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) {
|
| if (type_ == LAYER_SOLID_COLOR || !delegate_)
|
| return false;
|
| - damaged_region_.op(invalid_rect.x(),
|
| - invalid_rect.y(),
|
| - invalid_rect.right(),
|
| - invalid_rect.bottom(),
|
| + gfx::Rect invalid_rect_in_pixel = ConvertRectToPixel(this, invalid_rect);
|
| + damaged_region_.op(invalid_rect_in_pixel.x(),
|
| + invalid_rect_in_pixel.y(),
|
| + invalid_rect_in_pixel.right(),
|
| + invalid_rect_in_pixel.bottom(),
|
| SkRegion::kUnion_Op);
|
| ScheduleDraw();
|
| return true;
|
| @@ -342,12 +356,26 @@ void Layer::SuppressPaint() {
|
| children_[i]->SuppressPaint();
|
| }
|
|
|
| +void Layer::UpdateLayerSize(const Compositor* compositor) {
|
| + RecomputeTransform(compositor);
|
| + RecomputeDrawsContentAndUVRect(compositor);
|
| + for (size_t i = 0; i < children_.size(); ++i)
|
| + children_[i]->UpdateLayerSize(compositor);
|
| +}
|
| +
|
| void Layer::paintContents(WebKit::WebCanvas* web_canvas,
|
| const WebKit::WebRect& clip) {
|
| TRACE_EVENT0("ui", "Layer::paintContents");
|
| gfx::Canvas canvas(web_canvas);
|
| + bool scale_canvas = IsDIPEnabled() && scale_canvas_;
|
| + if (scale_canvas) {
|
| + float scale = GetDeviceScaleFactor(this);
|
| + canvas.sk_canvas()->scale(SkFloatToScalar(scale), SkFloatToScalar(scale));
|
| + }
|
| if (delegate_)
|
| delegate_->OnPaintLayer(&canvas);
|
| + if (scale_canvas)
|
| + canvas.Restore();
|
| }
|
|
|
| float Layer::GetCombinedOpacity() const {
|
| @@ -418,24 +446,24 @@ bool Layer::GetTransformRelativeTo(const Layer* ancestor,
|
| void Layer::SetBoundsImmediately(const gfx::Rect& bounds) {
|
| if (bounds == bounds_)
|
| return;
|
| + Compositor* compositor = GetCompositor();
|
|
|
| bool was_move = bounds_.size() == bounds.size();
|
| bounds_ = bounds;
|
| if (IsDrawn()) {
|
| if (was_move)
|
| - ScheduleDraw();
|
| + ScheduleDraw(compositor);
|
| else
|
| - SchedulePaint(gfx::Rect(bounds.size()));
|
| + SchedulePaint(compositor, gfx::Rect(bounds.size()));
|
| }
|
| -
|
| - RecomputeTransform();
|
| - RecomputeDrawsContentAndUVRect();
|
| + RecomputeTransform(compositor);
|
| + RecomputeDrawsContentAndUVRect(compositor);
|
| }
|
|
|
| void Layer::SetTransformImmediately(const ui::Transform& transform) {
|
| transform_ = transform;
|
|
|
| - RecomputeTransform();
|
| + RecomputeTransform(GetCompositor());
|
| }
|
|
|
| void Layer::SetOpacityImmediately(float opacity) {
|
| @@ -505,32 +533,37 @@ void Layer::CreateWebLayer() {
|
| show_debug_borders_ = CommandLine::ForCurrentProcess()->HasSwitch(
|
| switches::kUIShowLayerBorders);
|
| web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0);
|
| - RecomputeDrawsContentAndUVRect();
|
| - RecomputeDebugBorderColor();
|
| }
|
|
|
| -void Layer::RecomputeTransform() {
|
| - ui::Transform transform = transform_;
|
| - transform.ConcatTranslate(bounds_.x(), bounds_.y());
|
| - web_layer_.setTransform(transform.matrix());
|
| +void Layer::RecomputeTransform(const Compositor* compositor) {
|
| + Transform t;
|
| + if (compositor && IsDIPEnabled()) {
|
| + t = compositor->GetTranslateTransform(transform_, bounds_.origin());
|
| + } else {
|
| + t = transform_;
|
| + t.ConcatTranslate(bounds_.x(), bounds_.y());
|
| + }
|
| + web_layer_.setTransform(t.matrix());
|
| }
|
|
|
| -void Layer::RecomputeDrawsContentAndUVRect() {
|
| +void Layer::RecomputeDrawsContentAndUVRect(const Compositor* compositor) {
|
| DCHECK(!web_layer_.isNull());
|
| + float device_scale_factor = GetScale(compositor);
|
| bool should_draw = type_ != LAYER_NOT_DRAWN;
|
| if (!web_layer_is_accelerated_) {
|
| if (type_ != LAYER_SOLID_COLOR)
|
| web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw);
|
| - web_layer_.setBounds(bounds_.size());
|
| + web_layer_.setBounds(bounds_.size().Scale(device_scale_factor));
|
| } else {
|
| DCHECK(texture_);
|
| unsigned int texture_id = texture_->texture_id();
|
| WebKit::WebExternalTextureLayer texture_layer =
|
| web_layer_.to<WebKit::WebExternalTextureLayer>();
|
| texture_layer.setTextureId(should_draw ? texture_id : 0);
|
| + gfx::Rect bounds_in_pixel = bounds().Scale(device_scale_factor);
|
| gfx::Size texture_size = texture_->size();
|
| - gfx::Size size(std::min(bounds_.width(), texture_size.width()),
|
| - std::min(bounds_.height(), texture_size.height()));
|
| + gfx::Size size(std::min(bounds_in_pixel.width(), texture_size.width()),
|
| + std::min(bounds_in_pixel.height(), texture_size.height()));
|
| WebKit::WebFloatRect rect(
|
| 0,
|
| 0,
|
| @@ -552,4 +585,25 @@ void Layer::RecomputeDebugBorderColor() {
|
| web_layer_.setDebugBorderColor(color);
|
| }
|
|
|
| +void Layer::ScheduleDraw(Compositor* compositor) {
|
| + if (compositor)
|
| + compositor->ScheduleDraw();
|
| +}
|
| +
|
| +bool Layer::SchedulePaint(Compositor* compositor,
|
| + const gfx::Rect& invalid_rect) {
|
| + if (type_ == LAYER_SOLID_COLOR || !delegate_)
|
| + return false;
|
| + gfx::Rect invalid_rect_in_pixel =
|
| + invalid_rect.Scale(GetScale(compositor));
|
| + damaged_region_.op(invalid_rect_in_pixel.x(),
|
| + invalid_rect_in_pixel.y(),
|
| + invalid_rect_in_pixel.right(),
|
| + invalid_rect_in_pixel.bottom(),
|
| + SkRegion::kUnion_Op);
|
| + ScheduleDraw(compositor);
|
| + return true;
|
| +}
|
| +
|
| +
|
| } // namespace ui
|
|
|