1
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8#ifndef SkBoundaryPatch_DEFINED
9#define SkBoundaryPatch_DEFINED
10
11#include "SkPoint.h"
12#include "SkRefCnt.h"
13
14class SkBoundary : public SkRefCnt {
15public:
16    SK_DECLARE_INST_COUNT(SkBoundary)
17
18    // These must be 0, 1, 2, 3 for efficiency in the subclass implementations
19    enum Edge {
20        kTop    = 0,
21        kRight  = 1,
22        kBottom = 2,
23        kLeft   = 3
24    };
25    // Edge index goes clockwise around the boundary, beginning at the "top"
26    virtual SkPoint eval(Edge, SkScalar unitInterval) = 0;
27
28private:
29    typedef SkRefCnt INHERITED;
30};
31
32class SkBoundaryPatch {
33public:
34    SkBoundaryPatch();
35    ~SkBoundaryPatch();
36
37    SkBoundary* getBoundary() const { return fBoundary; }
38    SkBoundary* setBoundary(SkBoundary*);
39
40    SkPoint eval(SkScalar unitU, SkScalar unitV);
41    bool evalPatch(SkPoint verts[], int rows, int cols);
42
43private:
44    SkBoundary* fBoundary;
45};
46
47////////////////////////////////////////////////////////////////////////
48
49class SkLineBoundary : public SkBoundary {
50public:
51    SkPoint fPts[4];
52
53    // override
54    virtual SkPoint eval(Edge, SkScalar);
55};
56
57class SkCubicBoundary : public SkBoundary {
58public:
59    // the caller sets the first 12 entries. The 13th is used by the impl.
60    SkPoint fPts[13];
61
62    // override
63    virtual SkPoint eval(Edge, SkScalar);
64};
65
66#endif
67