GrDrawBatch.h revision ff2103200bad7abcf8929ae22ac78a9f4f725142
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 GrDrawBatch_DEFINED
9#define GrDrawBatch_DEFINED
10
11#include "GrBatch.h"
12#include "GrPipeline.h"
13
14struct GrInitInvariantOutput;
15
16/**
17 * GrDrawBatches are flushed in two phases (preDraw, and draw). In preDraw uploads to GrGpuResources
18 * and draws are determined and scheduled. They are issued in the draw phase. GrBatchToken is used
19 * to sequence the uploads relative to each other and to draws.
20 **/
21
22typedef uint64_t GrBatchToken;
23
24class GrBatchUploader : public SkRefCnt {
25public:
26    class TextureUploader;
27
28    GrBatchUploader(GrBatchToken lastUploadToken) : fLastUploadToken(lastUploadToken) {}
29    GrBatchToken lastUploadToken() const { return fLastUploadToken; }
30    virtual void upload(TextureUploader*)=0;
31
32private:
33    GrBatchToken fLastUploadToken;
34};
35
36/**
37 * Base class for GrBatches that draw. These batches have a GrPipeline installed by GrDrawTarget.
38 */
39class GrDrawBatch : public GrBatch {
40public:
41    class Target;
42
43    GrDrawBatch(uint32_t classID);
44    ~GrDrawBatch() override;
45
46    /**
47     * Fills in a structure informing the XP of overrides to its normal behavior.
48     */
49    void getPipelineOptimizations(GrPipelineOptimizations* override) const;
50
51    const GrPipeline* pipeline() const {
52        SkASSERT(fPipelineInstalled);
53        return reinterpret_cast<const GrPipeline*>(fPipelineStorage.get());
54    }
55
56    bool installPipeline(const GrPipeline::CreateArgs&);
57
58    // TODO no GrPrimitiveProcessors yet read fragment position
59    bool willReadFragmentPosition() const { return false; }
60
61    uint32_t renderTargetUniqueID() const final {
62        SkASSERT(fPipelineInstalled);
63        return this->pipeline()->getRenderTarget()->getUniqueID();
64    }
65
66    SkString dumpInfo() const override {
67        SkString string;
68        string.appendf("RT: %d\n", this->renderTargetUniqueID());
69        string.append("ColorStages:\n");
70        for (int i = 0; i < this->pipeline()->numColorFragmentProcessors(); i++) {
71            string.appendf("\t\t%s\n\t\t%s\n",
72                           this->pipeline()->getColorFragmentProcessor(i).name(),
73                           this->pipeline()->getColorFragmentProcessor(i).dumpInfo().c_str());
74        }
75        string.append("CoverageStages:\n");
76        for (int i = 0; i < this->pipeline()->numCoverageFragmentProcessors(); i++) {
77            string.appendf("\t\t%s\n\t\t%s\n",
78                           this->pipeline()->getCoverageFragmentProcessor(i).name(),
79                           this->pipeline()->getCoverageFragmentProcessor(i).dumpInfo().c_str());
80        }
81        string.appendf("XP: %s\n", this->pipeline()->getXferProcessor()->name());
82        return string;
83    }
84
85protected:
86    virtual void computePipelineOptimizations(GrInitInvariantOutput* color,
87                                              GrInitInvariantOutput* coverage,
88                                              GrBatchToXPOverrides* overrides) const = 0;
89
90private:
91    /**
92     * initBatchTracker is a hook for the some additional overrides / optimization possibilities
93     * from the GrXferProcessor.
94     */
95    virtual void initBatchTracker(const GrXPOverridesForBatch&) = 0;
96
97protected:
98    SkTArray<SkAutoTUnref<GrBatchUploader>, true>   fInlineUploads;
99
100private:
101    SkAlignedSTStorage<1, GrPipeline>               fPipelineStorage;
102    bool                                            fPipelineInstalled;
103    typedef GrBatch INHERITED;
104};
105
106#endif
107