GrPath.h revision 3c33c389e9f8d14d86756ea1ddeba2097f31ad22
1/*
2 * Copyright 2012 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 GrPath_DEFINED
9#define GrPath_DEFINED
10
11#include "GrGpuResource.h"
12#include "GrStrokeInfo.h"
13#include "GrPathRendering.h"
14#include "SkPath.h"
15#include "SkRect.h"
16
17class GrPath : public GrGpuResource {
18public:
19    /**
20     * Initialize to a path with a fixed stroke. Stroke must not be hairline.
21     */
22    GrPath(GrGpu* gpu, const SkPath& skPath, const GrStrokeInfo& stroke)
23        : INHERITED(gpu)
24        , fBounds(SkRect::MakeEmpty())
25        , fFillType(GrPathRendering::kWinding_FillType)
26#ifdef SK_DEBUG
27        , fSkPath(skPath)
28        , fStroke(stroke)
29#endif
30    {
31    }
32
33    static void ComputeKey(const SkPath& path, const GrStrokeInfo& stroke, GrUniqueKey* key,
34                           bool* outIsVolatile);
35
36    const SkRect& getBounds() const { return fBounds; }
37
38    GrPathRendering::FillType getFillType() const { return fFillType; }
39
40    /**
41     * Returns true if a path can be drawn in the same draw paths operation as the other
42     * path. Should return true only when the condition holds transitively with all other paths in
43     * the same group.
44     * E.g.
45     * canCombineDrawPathBatchWith(a) AND canCombineDrawPathBatchWith(b)
46     * canCombineDrawPathBatchWith(a) AND canCombineDrawPathBatchWith(c)
47     *  implies
48     * canCombineDrawPathBatchWith(b) AND canCombineDrawPathBatchWith(c)
49     */
50    virtual bool canCombineDrawPathBatchWith(const GrPath& other) const = 0;
51#ifdef SK_DEBUG
52    bool isEqualTo(const SkPath& path, const GrStrokeInfo& stroke) const;
53#endif
54
55protected:
56    // Subclass should init these.
57    SkRect fBounds;
58    GrPathRendering::FillType fFillType;
59#ifdef SK_DEBUG
60    SkPath fSkPath;
61    GrStrokeInfo fStroke;
62#endif
63
64private:
65    typedef GrGpuResource INHERITED;
66};
67
68#endif
69