OLD | NEW |
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/rect_conversions.h" | 9 #include "ui/gfx/geometry/rect_conversions.h" |
10 | 10 |
11 namespace cc { | 11 namespace cc { |
12 | 12 |
13 OverlayCandidate::OverlayCandidate() | 13 OverlayCandidate::OverlayCandidate() |
14 : transform(gfx::OVERLAY_TRANSFORM_NONE), | 14 : transform(gfx::OVERLAY_TRANSFORM_NONE), |
15 format(RGBA_8888), | 15 format(RGBA_8888), |
16 uv_rect(0.f, 0.f, 1.f, 1.f), | 16 uv_rect(0.f, 0.f, 1.f, 1.f), |
17 resource_id(0), | 17 resource_id(0), |
18 plane_z_order(0), | 18 plane_z_order(0), |
19 overlay_handled(false) {} | 19 overlay_handled(false) {} |
20 | 20 |
21 OverlayCandidate::~OverlayCandidate() {} | 21 OverlayCandidate::~OverlayCandidate() {} |
22 | 22 |
23 // static | 23 // static |
24 gfx::OverlayTransform OverlayCandidate::GetOverlayTransform( | 24 gfx::OverlayTransform OverlayCandidate::GetOverlayTransform( |
25 const gfx::Transform& quad_transform, | 25 const gfx::Transform& quad_transform, |
26 bool flipped) { | 26 bool flipped) { |
27 if (!quad_transform.IsIdentityOrTranslation()) | 27 if (!quad_transform.IsPositiveScaleOrTranslation()) |
28 return gfx::OVERLAY_TRANSFORM_INVALID; | 28 return gfx::OVERLAY_TRANSFORM_INVALID; |
29 | 29 |
30 return flipped ? gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL | 30 return flipped ? gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL |
31 : gfx::OVERLAY_TRANSFORM_NONE; | 31 : gfx::OVERLAY_TRANSFORM_NONE; |
32 } | 32 } |
33 | 33 |
34 // static | 34 // static |
| 35 gfx::OverlayTransform OverlayCandidate::ModifyTransform( |
| 36 gfx::OverlayTransform in, |
| 37 gfx::OverlayTransform delta) { |
| 38 // There are 8 different possible transforms. We can characterize these |
| 39 // by looking at where the origin moves and the direction the horizontal goes. |
| 40 // (TL=top-left, BR=bottom-right, H=horizontal, V=vertical). |
| 41 // NONE: TL, H |
| 42 // FLIP_VERTICAL: BL, H |
| 43 // FLIP_HORIZONTAL: TR, H |
| 44 // ROTATE_90: TR, V |
| 45 // ROTATE_180: BR, H |
| 46 // ROTATE_270: BL, V |
| 47 // Missing transforms: TL, V & BR, V |
| 48 // Basic combinations: |
| 49 // Flip X & Y -> Rotate 180 (TL,H -> TR,H -> BR,H or TL,H -> BL,H -> BR,H) |
| 50 // Flip X or Y + Rotate 180 -> other flip (eg, TL,H -> TR,H -> BL,H) |
| 51 // Rotate + Rotate simply adds values. |
| 52 // Rotate 90/270 + flip is invalid because we can only have verticals with |
| 53 // the origin in TR or BL. |
| 54 if (delta == gfx::OVERLAY_TRANSFORM_NONE) |
| 55 return in; |
| 56 switch (in) { |
| 57 case gfx::OVERLAY_TRANSFORM_NONE: |
| 58 return delta; |
| 59 case gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL: |
| 60 switch (delta) { |
| 61 case gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL: |
| 62 return gfx::OVERLAY_TRANSFORM_NONE; |
| 63 case gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL: |
| 64 return gfx::OVERLAY_TRANSFORM_ROTATE_180; |
| 65 case gfx::OVERLAY_TRANSFORM_ROTATE_180: |
| 66 return gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL; |
| 67 default: |
| 68 return gfx::OVERLAY_TRANSFORM_INVALID; |
| 69 } |
| 70 break; |
| 71 case gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL: |
| 72 switch (delta) { |
| 73 case gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL: |
| 74 return gfx::OVERLAY_TRANSFORM_NONE; |
| 75 case gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL: |
| 76 return gfx::OVERLAY_TRANSFORM_ROTATE_180; |
| 77 case gfx::OVERLAY_TRANSFORM_ROTATE_90: |
| 78 case gfx::OVERLAY_TRANSFORM_ROTATE_180: |
| 79 return gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL; |
| 80 case gfx::OVERLAY_TRANSFORM_ROTATE_270: |
| 81 default: |
| 82 return gfx::OVERLAY_TRANSFORM_INVALID; |
| 83 } |
| 84 break; |
| 85 case gfx::OVERLAY_TRANSFORM_ROTATE_90: |
| 86 switch (delta) { |
| 87 case gfx::OVERLAY_TRANSFORM_ROTATE_90: |
| 88 return gfx::OVERLAY_TRANSFORM_ROTATE_180; |
| 89 case gfx::OVERLAY_TRANSFORM_ROTATE_180: |
| 90 return gfx::OVERLAY_TRANSFORM_ROTATE_270; |
| 91 case gfx::OVERLAY_TRANSFORM_ROTATE_270: |
| 92 return gfx::OVERLAY_TRANSFORM_NONE; |
| 93 default: |
| 94 return gfx::OVERLAY_TRANSFORM_INVALID; |
| 95 } |
| 96 break; |
| 97 case gfx::OVERLAY_TRANSFORM_ROTATE_180: |
| 98 switch (delta) { |
| 99 case gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL: |
| 100 return gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL; |
| 101 case gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL: |
| 102 return gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL; |
| 103 case gfx::OVERLAY_TRANSFORM_ROTATE_90: |
| 104 return gfx::OVERLAY_TRANSFORM_ROTATE_270; |
| 105 case gfx::OVERLAY_TRANSFORM_ROTATE_180: |
| 106 return gfx::OVERLAY_TRANSFORM_NONE; |
| 107 case gfx::OVERLAY_TRANSFORM_ROTATE_270: |
| 108 return gfx::OVERLAY_TRANSFORM_ROTATE_90; |
| 109 default: |
| 110 return gfx::OVERLAY_TRANSFORM_INVALID; |
| 111 } |
| 112 break; |
| 113 case gfx::OVERLAY_TRANSFORM_ROTATE_270: |
| 114 switch (delta) { |
| 115 case gfx::OVERLAY_TRANSFORM_ROTATE_90: |
| 116 return gfx::OVERLAY_TRANSFORM_NONE; |
| 117 case gfx::OVERLAY_TRANSFORM_ROTATE_180: |
| 118 return gfx::OVERLAY_TRANSFORM_ROTATE_90; |
| 119 case gfx::OVERLAY_TRANSFORM_ROTATE_270: |
| 120 return gfx::OVERLAY_TRANSFORM_ROTATE_180; |
| 121 default: |
| 122 return gfx::OVERLAY_TRANSFORM_INVALID; |
| 123 } |
| 124 break; |
| 125 default: |
| 126 return gfx::OVERLAY_TRANSFORM_INVALID; |
| 127 } |
| 128 } |
| 129 |
| 130 // static |
35 gfx::Rect OverlayCandidate::GetOverlayRect(const gfx::Transform& quad_transform, | 131 gfx::Rect OverlayCandidate::GetOverlayRect(const gfx::Transform& quad_transform, |
36 const gfx::Rect& rect) { | 132 const gfx::Rect& rect) { |
37 DCHECK(quad_transform.IsIdentityOrTranslation()); | 133 DCHECK(quad_transform.IsPositiveScaleOrTranslation()); |
38 | 134 |
39 gfx::RectF float_rect(rect); | 135 gfx::RectF float_rect(rect); |
40 quad_transform.TransformRect(&float_rect); | 136 quad_transform.TransformRect(&float_rect); |
41 return gfx::ToNearestRect(float_rect); | 137 return gfx::ToNearestRect(float_rect); |
42 } | 138 } |
43 | 139 |
44 } // namespace cc | 140 } // namespace cc |
OLD | NEW |