aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrQuad.h
blob: 3a202c61cb47da623493dd4da242fc3d01a61c47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrQuad_DEFINED
#define GrQuad_DEFINED

#include "SkPoint.h"
#include "SkMatrix.h"
#include "SkMatrixPriv.h"

/**
 * GrQuad is a collection of 4 points which can be used to represent an arbitrary quadrilateral
 */
class GrQuad {
public:
    GrQuad() {}

    GrQuad(const GrQuad& that) {
        *this = that;
    }

    explicit GrQuad(const SkRect& rect) {
        this->set(rect);
    }

    void set(const SkRect& rect) {
        fPoints->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
    }

    void map(const SkMatrix& matrix) {
        matrix.mapPoints(fPoints, kNumPoints);
    }

    void setFromMappedRect(const SkRect& rect, const SkMatrix& matrix) {
        SkMatrixPriv::SetMappedRectFan(matrix, rect, fPoints);
    }

    const GrQuad& operator=(const GrQuad& that) {
        memcpy(fPoints, that.fPoints, sizeof(SkPoint) * kNumPoints);
        return *this;
    }

    SkPoint* points() {
        return fPoints;
    }

    const SkPoint* points() const {
        return fPoints;
    }

    const SkPoint& point(int i) const {
        SkASSERT(i < kNumPoints);
        return fPoints[i];
    }

private:
    static const int kNumPoints = 4;
    SkPoint fPoints[kNumPoints];
};

#endif