• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
6 #ifndef CC_RESOURCES_LAYER_QUAD_H_
7 #define CC_RESOURCES_LAYER_QUAD_H_
8 
9 #include "base/basictypes.h"
10 #include "cc/base/cc_export.h"
11 #include "ui/gfx/point_f.h"
12 
13 namespace gfx {
14 class QuadF;
15 }
16 
17 static const float kAntiAliasingInflateDistance = 0.5f;
18 
19 namespace cc {
20 
21 class CC_EXPORT LayerQuad {
22  public:
23   class Edge {
24    public:
Edge()25     Edge() : x_(0), y_(0), z_(0) {}
26     Edge(const gfx::PointF& p, const gfx::PointF& q);
27 
x()28     float x() const { return x_; }
y()29     float y() const { return y_; }
z()30     float z() const { return z_; }
31 
set_x(float x)32     void set_x(float x) { x_ = x; }
set_y(float y)33     void set_y(float y) { y_ = y; }
set_z(float z)34     void set_z(float z) { z_ = z; }
set(float x,float y,float z)35     void set(float x, float y, float z) {
36       x_ = x;
37       y_ = y;
38       z_ = z;
39     }
40 
move_x(float dx)41     void move_x(float dx) { x_ += dx; }
move_y(float dy)42     void move_y(float dy) { y_ += dy; }
move_z(float dz)43     void move_z(float dz) { z_ += dz; }
move(float dx,float dy,float dz)44     void move(float dx, float dy, float dz) {
45       x_ += dx;
46       y_ += dy;
47       z_ += dz;
48     }
49 
scale_x(float sx)50     void scale_x(float sx) { x_ *= sx; }
scale_y(float sy)51     void scale_y(float sy) { y_ *= sy; }
scale_z(float sz)52     void scale_z(float sz) { z_ *= sz; }
scale(float sx,float sy,float sz)53     void scale(float sx, float sy, float sz) {
54       x_ *= sx;
55       y_ *= sy;
56       z_ *= sz;
57     }
scale(float s)58     void scale(float s) { scale(s, s, s); }
59 
Intersect(const Edge & e)60     gfx::PointF Intersect(const Edge& e) const {
61       return gfx::PointF(
62           (y() * e.z() - e.y() * z()) / (x() * e.y() - e.x() * y()),
63           (x() * e.z() - e.x() * z()) / (e.x() * y() - x() * e.y()));
64     }
65 
66    private:
67     float x_;
68     float y_;
69     float z_;
70   };
71 
72   LayerQuad(const Edge& left,
73             const Edge& top,
74             const Edge& right,
75             const Edge& bottom);
76   explicit LayerQuad(const gfx::QuadF& quad);
77 
left()78   Edge left() const { return left_; }
top()79   Edge top() const { return top_; }
right()80   Edge right() const { return right_; }
bottom()81   Edge bottom() const { return bottom_; }
82 
InflateX(float dx)83   void InflateX(float dx) {
84     left_.move_z(dx);
85     right_.move_z(dx);
86   }
InflateY(float dy)87   void InflateY(float dy) {
88     top_.move_z(dy);
89     bottom_.move_z(dy);
90   }
Inflate(float d)91   void Inflate(float d) {
92     InflateX(d);
93     InflateY(d);
94   }
InflateAntiAliasingDistance()95   void InflateAntiAliasingDistance() {
96     Inflate(kAntiAliasingInflateDistance);
97   }
98 
99   gfx::QuadF ToQuadF() const;
100 
101   void ToFloatArray(float flattened[12]) const;
102 
103  private:
104   Edge left_;
105   Edge top_;
106   Edge right_;
107   Edge bottom_;
108 
109   DISALLOW_COPY_AND_ASSIGN(LayerQuad);
110 };
111 
112 }  // namespace cc
113 
114 #endif  // CC_RESOURCES_LAYER_QUAD_H_
115