1/*
2 * Copyright 2015 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 GrStencilPathBatch_DEFINED
9#define GrStencilPathBatch_DEFINED
10
11#include "GrBatch.h"
12#include "GrBatchFlushState.h"
13#include "GrGpu.h"
14#include "GrPath.h"
15#include "GrPathRendering.h"
16#include "GrRenderTarget.h"
17
18class GrStencilPathBatch final : public GrBatch {
19public:
20    DEFINE_BATCH_CLASS_ID
21
22    static GrBatch* Create(const SkMatrix& viewMatrix,
23                           bool useHWAA,
24                           const GrStencilSettings& stencil,
25                           const GrScissorState& scissor,
26                           GrRenderTarget* renderTarget,
27                           const GrPath* path) {
28        return new GrStencilPathBatch(viewMatrix, useHWAA, stencil, scissor, renderTarget, path);
29    }
30
31    const char* name() const override { return "StencilPath"; }
32
33    uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->getUniqueID(); }
34    GrRenderTarget* renderTarget() const override { return fRenderTarget.get(); }
35
36    SkString dumpInfo() const override {
37        SkString string;
38        string.printf("PATH: 0x%p, AA:%d", fPath.get(), fUseHWAA);
39        return string;
40    }
41
42private:
43    GrStencilPathBatch(const SkMatrix& viewMatrix,
44                       bool useHWAA,
45                       const GrStencilSettings& stencil,
46                       const GrScissorState& scissor,
47                       GrRenderTarget* renderTarget,
48                       const GrPath* path)
49    : INHERITED(ClassID())
50    , fViewMatrix(viewMatrix)
51    , fUseHWAA(useHWAA)
52    , fStencil(stencil)
53    , fScissor(scissor)
54    , fRenderTarget(renderTarget)
55    , fPath(path) {
56        fBounds = path->getBounds();
57    }
58
59    bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { return false; }
60
61    void onPrepare(GrBatchFlushState*) override {}
62
63    void onDraw(GrBatchFlushState* state) override {
64        GrPathRendering::StencilPathArgs args(fUseHWAA, fRenderTarget.get(), &fViewMatrix,
65                                              &fScissor, &fStencil);
66        state->gpu()->pathRendering()->stencilPath(args, fPath.get());
67    }
68
69    SkMatrix                                                fViewMatrix;
70    bool                                                    fUseHWAA;
71    GrStencilSettings                                       fStencil;
72    GrScissorState                                          fScissor;
73    GrPendingIOResource<GrRenderTarget, kWrite_GrIOType>    fRenderTarget;
74    GrPendingIOResource<const GrPath, kRead_GrIOType>       fPath;
75
76    typedef GrBatch INHERITED;
77};
78
79#endif
80