aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/batches/GrDrawPathBatch.h
blob: cf67cd9bba1a822bf2fb330e0adc2bc893be188d (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
66
67
68
69
70
71
72
73
74
75
/*
 * 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 GrDrawPathBatch_DEFINED
#define GrDrawPathBatch_DEFINED

#include "GrDrawBatch.h"
#include "GrGpu.h"
#include "GrPath.h"
#include "GrPathRendering.h"
#include "GrPathProcessor.h"

class GrDrawPathBatch final : public GrDrawBatch {
public:
    // This must return the concrete type because we install the stencil settings late :(
    static GrDrawPathBatch* Create(const GrPathProcessor* primProc, const GrPath* path) {
        return new GrDrawPathBatch(primProc, path);
    }

    const char* name() const override { return "DrawPath"; }

    SkString dumpInfo() const override {
        SkString string;
        string.printf("PATH: 0x%p", fPath.get());
        return string;
    }

    void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
        fPrimitiveProcessor->getInvariantOutputColor(out);
    }

    void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override {
        fPrimitiveProcessor->getInvariantOutputCoverage(out);
    }

    void setStencilSettings(const GrStencilSettings& stencil) { fStencilSettings = stencil; }

private:
    GrBatchTracker* tracker() { return reinterpret_cast<GrBatchTracker*>(&fWhatchamacallit); }
    GrDrawPathBatch(const GrPathProcessor* primProc, const GrPath* path)
    : fPrimitiveProcessor(primProc)
    , fPath(path) {
        fBounds = path->getBounds();
        primProc->viewMatrix().mapRect(&fBounds);
        this->initClassID<GrDrawPathBatch>();
    }

    void initBatchTracker(const GrPipelineOptimizations& opts) override {
        fPrimitiveProcessor->initBatchTracker(this->tracker(), opts);
    }

    bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { return false; }

    void onPrepare(GrBatchFlushState*) override {}

    void onDraw(GrBatchFlushState* state) override {
        GrProgramDesc  desc;
        state->gpu()->buildProgramDesc(&desc, *fPrimitiveProcessor.get(),
                                       *this->pipeline(), *this->tracker());
        GrPathRendering::DrawPathArgs args(fPrimitiveProcessor.get(), this->pipeline(),
                                           &desc, this->tracker(), &fStencilSettings);
        state->gpu()->pathRendering()->drawPath(args, fPath.get());
    }

    GrPendingProgramElement<const GrPathProcessor>      fPrimitiveProcessor;
    PathBatchTracker                                    fWhatchamacallit; // TODO: delete this
    GrStencilSettings                                   fStencilSettings;
    GrPendingIOResource<const GrPath, kRead_GrIOType>   fPath;
};

#endif