Line data Source code
1 : /*
2 : * Copyright 2015 Google Inc.
3 : *
4 : * Use of this source code is governed by a BSD-style license that can be
5 : * found in the LICENSE file.
6 : */
7 :
8 : #ifndef GrQuad_DEFINED
9 : #define GrQuad_DEFINED
10 :
11 : #include "SkPoint.h"
12 : #include "SkMatrix.h"
13 : #include "SkMatrixPriv.h"
14 :
15 : /**
16 : * GrQuad is a collection of 4 points which can be used to represent an arbitrary quadrilateral
17 : */
18 : class GrQuad {
19 : public:
20 0 : GrQuad() {}
21 :
22 0 : GrQuad(const GrQuad& that) {
23 0 : *this = that;
24 0 : }
25 :
26 0 : explicit GrQuad(const SkRect& rect) {
27 0 : this->set(rect);
28 0 : }
29 :
30 0 : void set(const SkRect& rect) {
31 0 : fPoints->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
32 0 : }
33 :
34 : void map(const SkMatrix& matrix) {
35 : matrix.mapPoints(fPoints, kNumPoints);
36 : }
37 :
38 0 : void setFromMappedRect(const SkRect& rect, const SkMatrix& matrix) {
39 0 : SkMatrixPriv::SetMappedRectFan(matrix, rect, fPoints);
40 0 : }
41 :
42 0 : const GrQuad& operator=(const GrQuad& that) {
43 0 : memcpy(fPoints, that.fPoints, sizeof(SkPoint) * kNumPoints);
44 0 : return *this;
45 : }
46 :
47 : SkPoint* points() {
48 : return fPoints;
49 : }
50 :
51 : const SkPoint* points() const {
52 : return fPoints;
53 : }
54 :
55 0 : const SkPoint& point(int i) const {
56 0 : SkASSERT(i < kNumPoints);
57 0 : return fPoints[i];
58 : }
59 :
60 : private:
61 : static const int kNumPoints = 4;
62 : SkPoint fPoints[kNumPoints];
63 : };
64 :
65 : #endif
|