blob: e60a6602f0587d32dedd8655ce53d1c6061b6748 [file] [log] [blame]
bsalomonadd79ef2015-08-19 13:26:49 -07001/*
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 GrDrawPathBatch_DEFINED
9#define GrDrawPathBatch_DEFINED
10
11#include "GrDrawBatch.h"
12#include "GrGpu.h"
13#include "GrPath.h"
14#include "GrPathRendering.h"
15#include "GrPathProcessor.h"
16
17class GrDrawPathBatch final : public GrDrawBatch {
18public:
19 // This must return the concrete type because we install the stencil settings late :(
20 static GrDrawPathBatch* Create(const GrPathProcessor* primProc, const GrPath* path) {
21 return SkNEW_ARGS(GrDrawPathBatch, (primProc, path));
22 }
23
24 const char* name() const override { return "DrawPath"; }
25
26 SkString dumpInfo() const override {
27 SkString string;
28 string.printf("PATH: 0x%p", fPath.get());
29 return string;
30 }
31
32 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const {
33 fPrimitiveProcessor->getInvariantOutputColor(out);
34 }
35
36 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const {
37 fPrimitiveProcessor->getInvariantOutputCoverage(out);
38 }
39
40 void setStencilSettings(const GrStencilSettings& stencil) { fStencilSettings = stencil; }
41
42private:
43 GrBatchTracker* tracker() { return reinterpret_cast<GrBatchTracker*>(&fWhatchamacallit); }
44 GrDrawPathBatch(const GrPathProcessor* primProc, const GrPath* path)
45 : fPrimitiveProcessor(primProc)
46 , fPath(path) {
47 fBounds = path->getBounds();
48 primProc->viewMatrix().mapRect(&fBounds);
49 this->initClassID<GrDrawPathBatch>();
50 }
51
52 virtual void initBatchTracker(const GrPipelineOptimizations& opts) {
53 fPrimitiveProcessor->initBatchTracker(this->tracker(), opts);
54 }
55
56 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { return false; }
57
58 void onPrepare(GrBatchFlushState*) override {}
59
60 void onDraw(GrBatchFlushState* state) override {
61 GrProgramDesc desc;
62 state->gpu()->buildProgramDesc(&desc, *fPrimitiveProcessor.get(),
63 *this->pipeline(), *this->tracker());
64 GrPathRendering::DrawPathArgs args(fPrimitiveProcessor.get(), this->pipeline(),
65 &desc, this->tracker(), &fStencilSettings);
66 state->gpu()->pathRendering()->drawPath(args, fPath.get());
67 }
68
69 GrPendingProgramElement<const GrPathProcessor> fPrimitiveProcessor;
70 PathBatchTracker fWhatchamacallit; // TODO: delete this
71 GrStencilSettings fStencilSettings;
72 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath;
73};
74
75#endif