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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | cc/output/overlay_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/output/overlay_candidate.h" 5 #include "cc/output/overlay_candidate.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "ui/gfx/geometry/point3_f.h"
9 #include "ui/gfx/geometry/rect_conversions.h" 10 #include "ui/gfx/geometry/rect_conversions.h"
10 11
11 namespace cc { 12 namespace cc {
12 13
14 namespace {
15 // 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:
16 const SkMScalar kEpsilon = 1e-8f;
17
18 enum Axis {
19 AXIS_POS_X,
20 AXIS_NEG_X,
21 AXIS_POS_Y,
22 AXIS_NEG_Y,
23 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.
24 };
25
26 Axis PointToAxis(const gfx::Point3F& point) {
27 if (std::abs(point.z()) > kEpsilon)
28 return NONE;
29 const bool x_zero = (std::abs(point.x()) <= kEpsilon);
30 const bool y_zero = (std::abs(point.y()) <= kEpsilon);
31 if (x_zero && !y_zero)
32 return (point.y() > 0) ? AXIS_POS_Y : AXIS_NEG_Y;
33 else if (y_zero && !x_zero)
34 return (point.x() > 0) ? AXIS_POS_X : AXIS_NEG_X;
35 else
36 return NONE;
37 }
38 } // namespace
39
13 OverlayCandidate::OverlayCandidate() 40 OverlayCandidate::OverlayCandidate()
14 : transform(gfx::OVERLAY_TRANSFORM_NONE), 41 : transform(gfx::OVERLAY_TRANSFORM_NONE),
15 format(RGBA_8888), 42 format(RGBA_8888),
16 uv_rect(0.f, 0.f, 1.f, 1.f), 43 uv_rect(0.f, 0.f, 1.f, 1.f),
17 resource_id(0), 44 resource_id(0),
18 plane_z_order(0), 45 plane_z_order(0),
19 overlay_handled(false) {} 46 overlay_handled(false) {}
20 47
21 OverlayCandidate::~OverlayCandidate() {} 48 OverlayCandidate::~OverlayCandidate() {}
22 49
23 // static 50 // static
24 gfx::OverlayTransform OverlayCandidate::GetOverlayTransform( 51 gfx::OverlayTransform OverlayCandidate::GetOverlayTransform(
25 const gfx::Transform& quad_transform, 52 const gfx::Transform& quad_transform,
26 bool flipped) { 53 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.
27 if (!quad_transform.IsPositiveScaleOrTranslation()) 54 if (!quad_transform.Preserves2dAxisAlignment()) {
28 return gfx::OVERLAY_TRANSFORM_INVALID; 55 return gfx::OVERLAY_TRANSFORM_INVALID;
56 }
29 57
30 return flipped ? gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL 58 gfx::Transform transform = quad_transform;
31 : gfx::OVERLAY_TRANSFORM_NONE; 59 transform.matrix().set(0, 3, 0);
60 transform.matrix().set(1, 3, 0);
61 transform.matrix().set(2, 3, 0);
62 if (flipped) {
63 transform.Scale(0, -1);
64 }
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.
65
66 gfx::Point3F x_axis(1, 0, 0);
67 gfx::Point3F y_axis(0, 1, 0);
68 transform.TransformPoint(&x_axis);
69 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
70
71 Axis x_to = PointToAxis(x_axis);
72 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
73
74 if (x_to == AXIS_POS_X && y_to == AXIS_POS_Y)
75 return gfx::OVERLAY_TRANSFORM_NONE;
76 else if (x_to == AXIS_NEG_X && y_to == AXIS_POS_Y)
77 return gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL;
78 else if (x_to == AXIS_POS_X && y_to == AXIS_NEG_Y)
79 return gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL;
80 else if (x_to == AXIS_NEG_Y && y_to == AXIS_POS_X)
81 return gfx::OVERLAY_TRANSFORM_ROTATE_270;
82 else if (x_to == AXIS_NEG_X && y_to == AXIS_NEG_Y)
83 return gfx::OVERLAY_TRANSFORM_ROTATE_180;
84 else if (x_to == AXIS_POS_Y && y_to == AXIS_NEG_X)
85 return gfx::OVERLAY_TRANSFORM_ROTATE_90;
86 else
87 return gfx::OVERLAY_TRANSFORM_INVALID;
32 } 88 }
33 89
34 // static 90 // static
35 gfx::OverlayTransform OverlayCandidate::ModifyTransform( 91 gfx::OverlayTransform OverlayCandidate::ModifyTransform(
36 gfx::OverlayTransform in, 92 gfx::OverlayTransform in,
37 gfx::OverlayTransform delta) { 93 gfx::OverlayTransform delta) {
38 // There are 8 different possible transforms. We can characterize these 94 // There are 8 different possible transforms. We can characterize these
39 // by looking at where the origin moves and the direction the horizontal goes. 95 // by looking at where the origin moves and the direction the horizontal goes.
40 // (TL=top-left, BR=bottom-right, H=horizontal, V=vertical). 96 // (TL=top-left, BR=bottom-right, H=horizontal, V=vertical).
41 // NONE: TL, H 97 // NONE: TL, H
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 break; 180 break;
125 default: 181 default:
126 return gfx::OVERLAY_TRANSFORM_INVALID; 182 return gfx::OVERLAY_TRANSFORM_INVALID;
127 } 183 }
128 } 184 }
129 185
130 // static 186 // static
131 gfx::RectF OverlayCandidate::GetOverlayRect( 187 gfx::RectF OverlayCandidate::GetOverlayRect(
132 const gfx::Transform& quad_transform, 188 const gfx::Transform& quad_transform,
133 const gfx::Rect& rect) { 189 const gfx::Rect& rect) {
134 DCHECK(quad_transform.IsPositiveScaleOrTranslation()); 190 DCHECK(quad_transform.Preserves2dAxisAlignment());
135 191
136 gfx::RectF float_rect(rect); 192 gfx::RectF float_rect(rect);
137 quad_transform.TransformRect(&float_rect); 193 quad_transform.TransformRect(&float_rect);
138 return float_rect; 194 return float_rect;
139 } 195 }
140 196
141 } // namespace cc 197 } // namespace cc
OLDNEW
« 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