Index: ui/gfx/compositor/layer.cc |
diff --git a/ui/gfx/compositor/layer.cc b/ui/gfx/compositor/layer.cc |
index 398ecc942f960609942a3bf989a7adf90f7ff331..0b675ad6067d0449c68d3fd9de2eb3846c448964 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" |
@@ -50,7 +51,8 @@ Layer::Layer() |
fills_bounds_opaquely_(true), |
layer_updated_externally_(false), |
opacity_(1.0f), |
- delegate_(NULL) { |
+ delegate_(NULL), |
+ scale_canvas_(true) { |
CreateWebLayer(); |
} |
@@ -62,7 +64,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 +103,7 @@ void Layer::Add(Layer* child) { |
child->parent_ = this; |
children_.push_back(child); |
web_layer_.addChild(child->web_layer_); |
+ child->UpdateLayerSize(); |
} |
void Layer::Remove(Layer* child) { |
@@ -166,6 +170,14 @@ void Layer::SetBounds(const gfx::Rect& bounds) { |
GetAnimator()->SetBounds(bounds); |
} |
+gfx::Rect Layer::GetBoundsInPixel() const { |
+ return ConvertRectToPixel(this, bounds()); |
+} |
+ |
+void Layer::SetBoundsInPixel(const gfx::Rect& bounds_in_pixel) { |
+ SetBounds(ConvertRectToDIP(this, bounds_in_pixel)); |
+} |
+ |
gfx::Rect Layer::GetTargetBounds() const { |
if (animator_.get() && animator_->IsAnimatingProperty( |
LayerAnimationElement::BOUNDS)) |
@@ -234,6 +246,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. |
piman
2012/05/04 18:46:06
FYI, I think the plan is to have a separate root f
|
if (source != root_layer) |
source->ConvertPointForAncestor(root_layer, point); |
if (target != root_layer) |
@@ -297,10 +311,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 +357,28 @@ void Layer::SuppressPaint() { |
children_[i]->SuppressPaint(); |
} |
+void Layer::UpdateLayerSize() { |
+ if (IsDrawn()) |
+ ScheduleDraw(); |
piman
2012/05/04 18:46:06
Let's not force this, except maybe if we explicitl
|
+ RecomputeTransform(); |
+ RecomputeDrawsContentAndUVRect(); |
+ for (size_t i = 0; i < children_.size(); ++i) |
+ children_[i]->UpdateLayerSize(); |
+} |
+ |
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 { |
@@ -510,9 +541,15 @@ void Layer::CreateWebLayer() { |
} |
void Layer::RecomputeTransform() { |
- ui::Transform transform = transform_; |
- transform.ConcatTranslate(bounds_.x(), bounds_.y()); |
- web_layer_.setTransform(transform.matrix()); |
+ Compositor* compositor = GetCompositor(); |
piman
2012/05/04 18:46:06
Is there a way we could avoid walking the layer tr
oshima
2012/05/04 21:08:06
Given that layer already have compositor_ and I ha
|
+ 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() { |
@@ -521,16 +558,17 @@ void Layer::RecomputeDrawsContentAndUVRect() { |
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(ConvertSizeToPixel(this, bounds_.size())); |
piman
2012/05/04 18:46:06
This, like above, will have to walk the layer tree
|
} 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 = GetBoundsInPixel(); |
piman
2012/05/04 18:46:06
Same here
|
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, |