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

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

Powered by Google App Engine
This is Rietveld 408576698