aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrPathRange.h
blob: b52fef170c62798894ee042bbb86c27e396209d0 (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
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrPathRange_DEFINED
#define GrPathRange_DEFINED

#include "GrGpuResource.h"
#include "GrResourceCache.h"
#include "SkStrokeRec.h"

class SkPath;

/**
 * Represents a contiguous range of GPU path objects with a common stroke. The
 * path range is immutable with the exception that individual paths can be
 * initialized lazily. Unititialized paths are silently ignored by drawing
 * functions.
 */
class GrPathRange : public GrGpuResource {
public:
    SK_DECLARE_INST_COUNT(GrPathRange);

    static const bool kIsWrapped = false;

    static GrResourceKey::ResourceType resourceType() {
        static const GrResourceKey::ResourceType type = GrResourceKey::GenerateResourceType();
        return type;
    }

    /**
     * Initialize to a range with a fixed size and stroke. Stroke must not be hairline.
     */
    GrPathRange(GrGpu* gpu, size_t size, const SkStrokeRec& stroke)
        : INHERITED(gpu, kIsWrapped),
          fSize(size),
          fStroke(stroke) {
        this->registerWithCache();
    }

    size_t getSize() const { return fSize; }
    const SkStrokeRec& getStroke() const { return fStroke; }

    /**
     * Initialize a path in the range. It is invalid to call this method for a
     * path that has already been initialized.
     */
    virtual void initAt(size_t index, const SkPath&) = 0;

protected:
    size_t fSize;
    SkStrokeRec fStroke;

private:
    typedef GrGpuResource INHERITED;
};

#endif