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

Side by Side Diff: cc/resources/layer_quad.cc

Issue 1535833002: Delete CC. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-5
Patch Set: rebase Created 4 years, 10 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/resources/layer_quad.h ('k') | cc/resources/layer_quad_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
(Empty)
1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/resources/layer_quad.h"
6
7 #include "base/logging.h"
8 #include "ui/gfx/geometry/quad_f.h"
9
10 namespace cc {
11
12 LayerQuad::Edge::Edge(const gfx::PointF& p, const gfx::PointF& q) {
13 if (p == q) {
14 degenerate_ = true;
15 return;
16 }
17 degenerate_ = false;
18 gfx::Vector2dF tangent(p.y() - q.y(), q.x() - p.x());
19 float cross2 = p.x() * q.y() - q.x() * p.y();
20
21 set(tangent.x(), tangent.y(), cross2);
22 scale(1.0f / tangent.Length());
23 }
24
25 gfx::PointF LayerQuad::Edge::Intersect(const LayerQuad::Edge& e) const {
26 DCHECK(!degenerate());
27 DCHECK(!e.degenerate());
28
29 return gfx::PointF((y() * e.z() - e.y() * z()) / (x() * e.y() - e.x() * y()),
30 (x() * e.z() - e.x() * z()) / (e.x() * y() - x() * e.y()));
31 }
32
33 LayerQuad::LayerQuad(const gfx::QuadF& quad) {
34 // Create edges.
35 left_ = Edge(quad.p4(), quad.p1());
36 right_ = Edge(quad.p2(), quad.p3());
37 top_ = Edge(quad.p1(), quad.p2());
38 bottom_ = Edge(quad.p3(), quad.p4());
39
40 float sign = quad.IsCounterClockwise() ? -1 : 1;
41 left_.scale(sign);
42 right_.scale(sign);
43 top_.scale(sign);
44 bottom_.scale(sign);
45 }
46
47 LayerQuad::LayerQuad(const Edge& left,
48 const Edge& top,
49 const Edge& right,
50 const Edge& bottom)
51 : left_(left),
52 top_(top),
53 right_(right),
54 bottom_(bottom) {}
55
56 gfx::QuadF LayerQuad::ToQuadF() const {
57 size_t num_degenerate_edges = left_.degenerate() + right_.degenerate() +
58 top_.degenerate() + bottom_.degenerate();
59 if (num_degenerate_edges > 1) {
60 return gfx::QuadF();
61 }
62
63 if (left_.degenerate()) {
64 return gfx::QuadF(top_.Intersect(bottom_), top_.Intersect(right_),
65 right_.Intersect(bottom_), bottom_.Intersect(top_));
66 }
67 if (right_.degenerate()) {
68 return gfx::QuadF(left_.Intersect(top_), top_.Intersect(bottom_),
69 bottom_.Intersect(top_), bottom_.Intersect(left_));
70 }
71 if (top_.degenerate()) {
72 return gfx::QuadF(left_.Intersect(right_), right_.Intersect(left_),
73 right_.Intersect(bottom_), bottom_.Intersect(left_));
74 }
75 if (bottom_.degenerate()) {
76 return gfx::QuadF(left_.Intersect(top_), top_.Intersect(right_),
77 right_.Intersect(left_), left_.Intersect(right_));
78 }
79 return gfx::QuadF(left_.Intersect(top_),
80 top_.Intersect(right_),
81 right_.Intersect(bottom_),
82 bottom_.Intersect(left_));
83 }
84
85 void LayerQuad::ToFloatArray(float flattened[12]) const {
86 if (left_.degenerate()) {
87 flattened[0] = bottom_.x();
88 flattened[1] = bottom_.y();
89 flattened[2] = bottom_.z();
90 } else {
91 flattened[0] = left_.x();
92 flattened[1] = left_.y();
93 flattened[2] = left_.z();
94 }
95 if (top_.degenerate()) {
96 flattened[3] = left_.x();
97 flattened[4] = left_.y();
98 flattened[5] = left_.z();
99 } else {
100 flattened[3] = top_.x();
101 flattened[4] = top_.y();
102 flattened[5] = top_.z();
103 }
104 if (right_.degenerate()) {
105 flattened[6] = top_.x();
106 flattened[7] = top_.y();
107 flattened[8] = top_.z();
108 } else {
109 flattened[6] = right_.x();
110 flattened[7] = right_.y();
111 flattened[8] = right_.z();
112 }
113 if (bottom_.degenerate()) {
114 flattened[9] = right_.x();
115 flattened[10] = right_.y();
116 flattened[11] = right_.z();
117 } else {
118 flattened[9] = bottom_.x();
119 flattened[10] = bottom_.y();
120 flattened[11] = bottom_.z();
121 }
122 }
123
124 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/layer_quad.h ('k') | cc/resources/layer_quad_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698