Index: ui/compositor/dip_util.cc |
diff --git a/ui/compositor/dip_util.cc b/ui/compositor/dip_util.cc |
index fcecf249555ea0ae77a1893f6091d3e2050918fc..27f71c665c78f99d3c5e0d67ad616692b76cca07 100644 |
--- a/ui/compositor/dip_util.cc |
+++ b/ui/compositor/dip_util.cc |
@@ -70,4 +70,25 @@ gfx::Rect ConvertRectToPixel(const Layer* layer, |
gfx::ScaleSize(rect_in_dip.size(), scale))); |
} |
+void SnapLayerToPhysicalPixelBoundary(ui::Layer* snapped_layer, |
+ ui::Layer* layer_to_snap) { |
+ DCHECK_NE(snapped_layer, layer_to_snap); |
+ if (!snapped_layer || !snapped_layer->Contains(layer_to_snap)) |
danakj
2014/07/15 21:11:02
Could these be DCHECKs instead?
Also can we DCHECK
oshima
2014/07/15 22:28:42
Done.
|
+ return; |
+ |
+ gfx::Point view_offset_dips = layer_to_snap->GetTargetBounds().origin(); |
+ ui::Layer::ConvertPointToLayer( |
+ layer_to_snap->parent(), snapped_layer, &view_offset_dips); |
+ gfx::PointF view_offset = view_offset_dips; |
+ |
+ float scale_factor = GetDeviceScaleFactor(layer_to_snap); |
+ view_offset.Scale(scale_factor); |
+ gfx::PointF view_offset_snapped(std::round(view_offset.x()), |
+ std::round(view_offset.y())); |
jamesr
2014/07/08 01:00:59
this moves the layer towards (0, 0). If this is u
|
+ |
+ gfx::Vector2dF fudge = view_offset_snapped - view_offset; |
+ fudge.Scale(1.0 / scale_factor); |
+ layer_to_snap->SetSubpixelPositionOffset(fudge); |
+} |
+ |
} // namespace ui |