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

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: Move Get*Axis to MathUtil, rename flipped->y_flipped 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
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 "cc/base/math_util.h"
9 #include "ui/gfx/geometry/rect_conversions.h" 10 #include "ui/gfx/geometry/rect_conversions.h"
11 #include "ui/gfx/geometry/vector3d_f.h"
10 12
11 namespace cc { 13 namespace cc {
12 14
15 namespace {
16 // Tolerance for considering axis vector elements to be zero.
17 const SkMScalar kEpsilon = 1e-8f;
18
19 enum Axis { NONE, AXIS_POS_X, AXIS_NEG_X, AXIS_POS_Y, AXIS_NEG_Y };
20
21 Axis VectorToAxis(const gfx::Vector3dF& vec) {
22 if (std::abs(vec.z()) > kEpsilon)
23 return NONE;
24 const bool x_zero = (std::abs(vec.x()) <= kEpsilon);
25 const bool y_zero = (std::abs(vec.y()) <= kEpsilon);
26 if (x_zero && !y_zero)
27 return (vec.y() > 0) ? AXIS_POS_Y : AXIS_NEG_Y;
28 else if (y_zero && !x_zero)
29 return (vec.x() > 0) ? AXIS_POS_X : AXIS_NEG_X;
30 else
31 return NONE;
32 }
33
34 } // namespace
35
13 OverlayCandidate::OverlayCandidate() 36 OverlayCandidate::OverlayCandidate()
14 : transform(gfx::OVERLAY_TRANSFORM_NONE), 37 : transform(gfx::OVERLAY_TRANSFORM_NONE),
15 format(RGBA_8888), 38 format(RGBA_8888),
16 uv_rect(0.f, 0.f, 1.f, 1.f), 39 uv_rect(0.f, 0.f, 1.f, 1.f),
17 resource_id(0), 40 resource_id(0),
18 plane_z_order(0), 41 plane_z_order(0),
19 overlay_handled(false) {} 42 overlay_handled(false) {}
20 43
21 OverlayCandidate::~OverlayCandidate() {} 44 OverlayCandidate::~OverlayCandidate() {}
22 45
23 // static 46 // static
24 gfx::OverlayTransform OverlayCandidate::GetOverlayTransform( 47 gfx::OverlayTransform OverlayCandidate::GetOverlayTransform(
25 const gfx::Transform& quad_transform, 48 const gfx::Transform& quad_transform,
26 bool flipped) { 49 bool y_flipped) {
27 if (!quad_transform.IsPositiveScaleOrTranslation()) 50 if (!quad_transform.Preserves2dAxisAlignment()) {
28 return gfx::OVERLAY_TRANSFORM_INVALID; 51 return gfx::OVERLAY_TRANSFORM_INVALID;
52 }
29 53
30 return flipped ? gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL 54 gfx::Vector3dF x_axis = MathUtil::GetXAxis(quad_transform);
31 : gfx::OVERLAY_TRANSFORM_NONE; 55 gfx::Vector3dF y_axis = MathUtil::GetYAxis(quad_transform);
56 if (y_flipped) {
57 y_axis.Scale(-1);
58 }
59
60 Axis x_to = VectorToAxis(x_axis);
61 Axis y_to = VectorToAxis(y_axis);
62
63 if (x_to == AXIS_POS_X && y_to == AXIS_POS_Y)
64 return gfx::OVERLAY_TRANSFORM_NONE;
65 else if (x_to == AXIS_NEG_X && y_to == AXIS_POS_Y)
66 return gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL;
67 else if (x_to == AXIS_POS_X && y_to == AXIS_NEG_Y)
68 return gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL;
69 else if (x_to == AXIS_NEG_Y && y_to == AXIS_POS_X)
70 return gfx::OVERLAY_TRANSFORM_ROTATE_270;
71 else if (x_to == AXIS_NEG_X && y_to == AXIS_NEG_Y)
72 return gfx::OVERLAY_TRANSFORM_ROTATE_180;
73 else if (x_to == AXIS_POS_Y && y_to == AXIS_NEG_X)
74 return gfx::OVERLAY_TRANSFORM_ROTATE_90;
75 else
76 return gfx::OVERLAY_TRANSFORM_INVALID;
32 } 77 }
33 78
34 // static 79 // static
35 gfx::OverlayTransform OverlayCandidate::ModifyTransform( 80 gfx::OverlayTransform OverlayCandidate::ModifyTransform(
36 gfx::OverlayTransform in, 81 gfx::OverlayTransform in,
37 gfx::OverlayTransform delta) { 82 gfx::OverlayTransform delta) {
38 // There are 8 different possible transforms. We can characterize these 83 // There are 8 different possible transforms. We can characterize these
39 // by looking at where the origin moves and the direction the horizontal goes. 84 // by looking at where the origin moves and the direction the horizontal goes.
40 // (TL=top-left, BR=bottom-right, H=horizontal, V=vertical). 85 // (TL=top-left, BR=bottom-right, H=horizontal, V=vertical).
41 // NONE: TL, H 86 // NONE: TL, H
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 break; 169 break;
125 default: 170 default:
126 return gfx::OVERLAY_TRANSFORM_INVALID; 171 return gfx::OVERLAY_TRANSFORM_INVALID;
127 } 172 }
128 } 173 }
129 174
130 // static 175 // static
131 gfx::RectF OverlayCandidate::GetOverlayRect( 176 gfx::RectF OverlayCandidate::GetOverlayRect(
132 const gfx::Transform& quad_transform, 177 const gfx::Transform& quad_transform,
133 const gfx::Rect& rect) { 178 const gfx::Rect& rect) {
134 DCHECK(quad_transform.IsPositiveScaleOrTranslation()); 179 DCHECK(quad_transform.Preserves2dAxisAlignment());
135 180
136 gfx::RectF float_rect(rect); 181 gfx::RectF float_rect(rect);
137 quad_transform.TransformRect(&float_rect); 182 quad_transform.TransformRect(&float_rect);
138 return float_rect; 183 return float_rect;
139 } 184 }
140 185
141 } // namespace cc 186 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698