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

#include "GrTargetCommands.h"

#include "GrBatchFlushState.h"
#include "GrGpu.h"
#include "GrPathRendering.h"
#include "batches/GrDrawBatch.h"
#include "batches/GrVertexBatch.h"

GrBATCH_SPEW(int32_t GrTargetCommands::Cmd::gUniqueID = 0;)

void GrTargetCommands::reset() {
    fCmdBuffer.reset();
}

void GrTargetCommands::flush(GrGpu* gpu, GrResourceProvider* resourceProvider) {
    GrBATCH_INFO("Flushing\n");
    if (fCmdBuffer.empty()) {
        return;
    }
    GrBatchFlushState flushState(gpu, resourceProvider, fLastFlushToken);
    // Loop over all batches and generate geometry
    CmdBuffer::Iter genIter(fCmdBuffer);
    while (genIter.next()) {
        if (Cmd::kDrawBatch_CmdType == genIter->type()) {
            DrawBatch* db = reinterpret_cast<DrawBatch*>(genIter.get());
            db->batch()->prepare(&flushState);
        }
    }

    flushState.preIssueDraws();

    CmdBuffer::Iter iter(fCmdBuffer);
    while (iter.next()) {
        iter->execute(&flushState);
    }
    fLastFlushToken = flushState.lastFlushedToken();
}

void GrTargetCommands::DrawPath::execute(GrBatchFlushState* state) {
    if (!fState->fCompiled) {
        state->gpu()->buildProgramDesc(&fState->fDesc, *fState->fPrimitiveProcessor,
                                       *fState->getPipeline(), fState->fBatchTracker);
        fState->fCompiled = true;
    }
    GrPathRendering::DrawPathArgs args(fState->fPrimitiveProcessor.get(), fState->getPipeline(),
                                       &fState->fDesc, &fState->fBatchTracker, &fStencilSettings);
    state->gpu()->pathRendering()->drawPath(args, this->path());
}

void GrTargetCommands::DrawPaths::execute(GrBatchFlushState* state) {
    if (!fState->fCompiled) {
        state->gpu()->buildProgramDesc(&fState->fDesc, *fState->fPrimitiveProcessor,
                                       *fState->getPipeline(), fState->fBatchTracker);
        fState->fCompiled = true;
    }
    GrPathRendering::DrawPathArgs args(fState->fPrimitiveProcessor.get(), fState->getPipeline(),
                                       &fState->fDesc, &fState->fBatchTracker, &fStencilSettings);
    state->gpu()->pathRendering()->drawPaths(args, this->pathRange(), fIndices, fIndexType,
                                             fTransforms, fTransformType, fCount);
}

void GrTargetCommands::DrawBatch::execute(GrBatchFlushState* state) {
    fBatch->draw(state);
}