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

Unified Diff: cc/output/overlay_candidate.cc

Issue 1135813005: Add detection for rotation and flip overlay transforms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 | « no previous file | cc/output/overlay_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/output/overlay_candidate.cc
diff --git a/cc/output/overlay_candidate.cc b/cc/output/overlay_candidate.cc
index 0cbd3deefa8de361f4b9273c8d705a8743d9445e..db3bbc5a5528008abab6f066688885d218c6a4be 100644
--- a/cc/output/overlay_candidate.cc
+++ b/cc/output/overlay_candidate.cc
@@ -6,10 +6,37 @@
#include <algorithm>
#include "base/logging.h"
+#include "ui/gfx/geometry/point3_f.h"
#include "ui/gfx/geometry/rect_conversions.h"
namespace cc {
+namespace {
+// Taken from SkMatrix44.
danakj 2015/05/11 16:58:04 can you TODO pointing to a bug to make this consta
Ian Vollick 2015/05/12 01:24:15 I believe that this from transform.cc (which also
halliwell 2015/05/12 01:57:09 Correct, I just copied this comment from Transform
hendrikw 2015/05/12 02:12:29 Perhaps even replace it with std::numeric_limits<f
halliwell 2015/05/12 15:11:31 Definitely not that :) numeric_limits::epsilon is
hendrikw 2015/05/12 16:12:39 If accuracy isn't important for your use case, the
halliwell 2015/05/12 22:22:19 Well ... this number is actually smaller than std:
+const SkMScalar kEpsilon = 1e-8f;
+
+enum Axis {
+ AXIS_POS_X,
+ AXIS_NEG_X,
+ AXIS_POS_Y,
+ AXIS_NEG_Y,
+ NONE,
danakj 2015/05/11 16:58:04 usually NONE would go first so it's 0
halliwell 2015/05/12 15:11:31 Done.
+};
+
+Axis PointToAxis(const gfx::Point3F& point) {
+ if (std::abs(point.z()) > kEpsilon)
+ return NONE;
+ const bool x_zero = (std::abs(point.x()) <= kEpsilon);
+ const bool y_zero = (std::abs(point.y()) <= kEpsilon);
+ if (x_zero && !y_zero)
+ return (point.y() > 0) ? AXIS_POS_Y : AXIS_NEG_Y;
+ else if (y_zero && !x_zero)
+ return (point.x() > 0) ? AXIS_POS_X : AXIS_NEG_X;
+ else
+ return NONE;
+}
+} // namespace
+
OverlayCandidate::OverlayCandidate()
: transform(gfx::OVERLAY_TRANSFORM_NONE),
format(RGBA_8888),
@@ -24,11 +51,40 @@ OverlayCandidate::~OverlayCandidate() {}
gfx::OverlayTransform OverlayCandidate::GetOverlayTransform(
const gfx::Transform& quad_transform,
bool flipped) {
hendrikw 2015/05/12 02:12:29 rename to flipped_over_y_axis?
halliwell 2015/05/12 15:11:31 I agree this isn't super clear, especially when "F
hendrikw 2015/05/12 16:12:39 I don't know, I would probably start the rename he
danakj 2015/05/12 16:54:32 +1 Feel free to improve the name elsewhere
halliwell 2015/05/12 22:22:20 Ok, renamed here and in TextureDrawQuad.
- if (!quad_transform.IsPositiveScaleOrTranslation())
+ if (!quad_transform.Preserves2dAxisAlignment()) {
return gfx::OVERLAY_TRANSFORM_INVALID;
+ }
- return flipped ? gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL
- : gfx::OVERLAY_TRANSFORM_NONE;
+ gfx::Transform transform = quad_transform;
+ transform.matrix().set(0, 3, 0);
+ transform.matrix().set(1, 3, 0);
+ transform.matrix().set(2, 3, 0);
+ if (flipped) {
+ transform.Scale(0, -1);
+ }
hendrikw 2015/05/12 02:12:29 Should probably have GetXAxis() and GetYAxis() fun
halliwell 2015/05/12 15:11:31 Yep, GetXAxis/GetYAxis seem like a clear way to ex
danakj 2015/05/12 16:54:32 You could put it in cc/base/math_util if cc is the
halliwell 2015/05/12 22:22:19 Moved to cc::MathUtil.
+
+ gfx::Point3F x_axis(1, 0, 0);
+ gfx::Point3F y_axis(0, 1, 0);
+ transform.TransformPoint(&x_axis);
+ transform.TransformPoint(&y_axis);
Ian Vollick 2015/05/12 01:24:15 Regarding Dana's question about whether we could d
halliwell 2015/05/12 15:11:31 Indeed, not a huge perf hit, but seems silly to be
+
+ Axis x_to = PointToAxis(x_axis);
+ Axis y_to = PointToAxis(y_axis);
hendrikw 2015/05/12 02:12:29 your PointToAxis functions ignores scale, is that
halliwell 2015/05/12 15:11:31 Correct. TRANSFORM_NONE doesn't mean 'no transfor
+
+ if (x_to == AXIS_POS_X && y_to == AXIS_POS_Y)
+ return gfx::OVERLAY_TRANSFORM_NONE;
+ else if (x_to == AXIS_NEG_X && y_to == AXIS_POS_Y)
+ return gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL;
+ else if (x_to == AXIS_POS_X && y_to == AXIS_NEG_Y)
+ return gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL;
+ else if (x_to == AXIS_NEG_Y && y_to == AXIS_POS_X)
+ return gfx::OVERLAY_TRANSFORM_ROTATE_270;
+ else if (x_to == AXIS_NEG_X && y_to == AXIS_NEG_Y)
+ return gfx::OVERLAY_TRANSFORM_ROTATE_180;
+ else if (x_to == AXIS_POS_Y && y_to == AXIS_NEG_X)
+ return gfx::OVERLAY_TRANSFORM_ROTATE_90;
+ else
+ return gfx::OVERLAY_TRANSFORM_INVALID;
}
// static
@@ -131,7 +187,7 @@ gfx::OverlayTransform OverlayCandidate::ModifyTransform(
gfx::RectF OverlayCandidate::GetOverlayRect(
const gfx::Transform& quad_transform,
const gfx::Rect& rect) {
- DCHECK(quad_transform.IsPositiveScaleOrTranslation());
+ DCHECK(quad_transform.Preserves2dAxisAlignment());
gfx::RectF float_rect(rect);
quad_transform.TransformRect(&float_rect);
« no previous file with comments | « no previous file | cc/output/overlay_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698