Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(706)

Unified Diff: ui/compositor/dip_util.cc

Issue 375693006: Snap layers in views to physical pixel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « ui/compositor/dip_util.h ('k') | ui/compositor/layer.h » ('j') | ui/compositor/layer_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698