Index: ui/compositor/dip_util.cc |
diff --git a/ui/compositor/dip_util.cc b/ui/compositor/dip_util.cc |
index fcecf249555ea0ae77a1893f6091d3e2050918fc..353cee31198d3688784d493e5aea941a01706163 100644 |
--- a/ui/compositor/dip_util.cc |
+++ b/ui/compositor/dip_util.cc |
@@ -5,6 +5,8 @@ |
#include "ui/compositor/dip_util.h" |
#include "base/command_line.h" |
+#include "cc/base/math_util.h" |
+#include "cc/layers/layer.h" |
#include "ui/compositor/compositor.h" |
#include "ui/compositor/compositor_switches.h" |
#include "ui/compositor/layer.h" |
@@ -70,4 +72,45 @@ gfx::Rect ConvertRectToPixel(const Layer* layer, |
gfx::ScaleSize(rect_in_dip.size(), scale))); |
} |
+#if !defined(NDEBUG) |
+namespace { |
+ |
+void CheckSnapped(float snapped_position) { |
+ const float kEplison = 0.0001f; |
+ float diff = std::abs(snapped_position - static_cast<int>(snapped_position)); |
+ DCHECK_LT(diff, kEplison); |
+} |
+ |
+} // namespace |
+#endif |
+ |
+void SnapLayerToPhysicalPixelBoundary(ui::Layer* snapped_layer, |
+ ui::Layer* layer_to_snap) { |
+ DCHECK_NE(snapped_layer, layer_to_snap); |
+ DCHECK(snapped_layer); |
+ DCHECK(snapped_layer->Contains(layer_to_snap)); |
+ |
+ 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(cc::MathUtil::Round(view_offset.x()), |
danakj
2014/07/17 15:12:14
MathUtil is not meant to be used outside of cc. I
|
+ cc::MathUtil::Round(view_offset.y())); |
+ |
+ gfx::Vector2dF fudge = view_offset_snapped - view_offset; |
+ fudge.Scale(1.0 / scale_factor); |
+ layer_to_snap->SetSubpixelPositionOffset(fudge); |
+#if !defined(NDEBUG) |
+ gfx::Point p; |
+ Layer::ConvertPointToLayer(layer_to_snap->parent(), snapped_layer, &p); |
+ cc::Layer* cc_layer = layer_to_snap->cc_layer(); |
+ gfx::PointF origin = cc_layer->position(); |
+ CheckSnapped((p.x() + origin.x()) * scale_factor); |
+ CheckSnapped((p.y() + origin.y()) * scale_factor); |
+#endif |
+} |
+ |
} // namespace ui |