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

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: use cc::MathUtil::Round instead 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
« no previous file with comments | « ui/compositor/dip_util.h ('k') | ui/compositor/layer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « ui/compositor/dip_util.h ('k') | ui/compositor/layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698