blob: c7c76a4a9c7d08c0d5ef779c7ca51bd7de9e3019 [file] [log] [blame]
egdaniel066df7c2016-06-08 14:02:27 -07001/*
2* Copyright 2016 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 GrGLGpuCommandBuffer_DEFINED
9#define GrGLGpuCommandBuffer_DEFINED
10
11#include "GrGpuCommandBuffer.h"
12
egdaniel9cb63402016-06-23 08:37:05 -070013#include "GrGLGpu.h"
Brian Salomon742e31d2016-12-07 17:06:19 -050014#include "GrOpFlushState.h"
egdaniel066df7c2016-06-08 14:02:27 -070015
Greg Daniel65a09272016-10-12 09:47:22 -040016class GrGLRenderTarget;
17
egdaniel066df7c2016-06-08 14:02:27 -070018class GrGLGpuCommandBuffer : public GrGpuCommandBuffer {
egdaniel9cb63402016-06-23 08:37:05 -070019/**
20 * We do not actually buffer up draws or do any work in the this class for GL. Instead commands
21 * are immediately sent to the gpu to execute. Thus all the commands in this class are simply
22 * pass through functions to corresponding calls in the GrGLGpu class.
23 */
egdaniel066df7c2016-06-08 14:02:27 -070024public:
Brian Salomonc293a292016-11-30 13:38:32 -050025 GrGLGpuCommandBuffer(GrGLGpu* gpu) : fGpu(gpu), fRenderTarget(nullptr) {}
egdaniel066df7c2016-06-08 14:02:27 -070026
Brian Salomond3b65972017-03-22 12:05:03 -040027 ~GrGLGpuCommandBuffer() override {}
egdaniel066df7c2016-06-08 14:02:27 -070028
29 void end() override {}
30
Brian Salomonc293a292016-11-30 13:38:32 -050031 void discard(GrRenderTarget* rt) override {
32 GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(rt);
33 if (!fRenderTarget) {
34 fRenderTarget = target;
35 }
36 SkASSERT(target == fRenderTarget);
37 }
egdaniel066df7c2016-06-08 14:02:27 -070038
Greg Danieldbd11ec2017-03-21 16:56:31 -040039 void inlineUpload(GrOpFlushState* state, GrDrawOp::DeferredUploadFn& upload,
40 GrRenderTarget*) override {
Greg Daniel77b53f62016-10-18 11:48:51 -040041 state->doUpload(upload);
42 }
43
egdaniel066df7c2016-06-08 14:02:27 -070044private:
egdaniel9cb63402016-06-23 08:37:05 -070045 GrGpu* gpu() override { return fGpu; }
Greg Daniel65a09272016-10-12 09:47:22 -040046 GrRenderTarget* renderTarget() override { return fRenderTarget; }
egdaniel9cb63402016-06-23 08:37:05 -070047
Greg Daniel36a77ee2016-10-18 10:33:25 -040048 void onSubmit() override {}
egdaniel9cb63402016-06-23 08:37:05 -070049
50 void onDraw(const GrPipeline& pipeline,
51 const GrPrimitiveProcessor& primProc,
52 const GrMesh* mesh,
Greg Daniel36a77ee2016-10-18 10:33:25 -040053 int meshCount,
54 const SkRect& bounds) override {
Brian Salomonc293a292016-11-30 13:38:32 -050055 GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(pipeline.getRenderTarget());
56 if (!fRenderTarget) {
57 fRenderTarget = target;
58 }
59 SkASSERT(target == fRenderTarget);
egdaniel9cb63402016-06-23 08:37:05 -070060 fGpu->draw(pipeline, primProc, mesh, meshCount);
61 }
62
Brian Salomonc293a292016-11-30 13:38:32 -050063 void onClear(GrRenderTarget* rt, const GrFixedClip& clip, GrColor color) override {
64 GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(rt);
65 if (!fRenderTarget) {
66 fRenderTarget = target;
67 }
68 SkASSERT(target == fRenderTarget);
Greg Daniel65a09272016-10-12 09:47:22 -040069 fGpu->clear(clip, color, fRenderTarget);
egdaniel9cb63402016-06-23 08:37:05 -070070 }
71
Brian Salomonc293a292016-11-30 13:38:32 -050072 void onClearStencilClip(GrRenderTarget* rt, const GrFixedClip& clip,
csmartdalton29df7602016-08-31 11:55:52 -070073 bool insideStencilMask) override {
Brian Salomonc293a292016-11-30 13:38:32 -050074 GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(rt);
75 if (!fRenderTarget) {
76 fRenderTarget = target;
77 }
78 SkASSERT(target == fRenderTarget);
Greg Daniel65a09272016-10-12 09:47:22 -040079 fGpu->clearStencilClip(clip, insideStencilMask, fRenderTarget);
egdaniel9cb63402016-06-23 08:37:05 -070080 }
81
82 GrGLGpu* fGpu;
Greg Daniel65a09272016-10-12 09:47:22 -040083 GrGLRenderTarget* fRenderTarget;
egdaniel066df7c2016-06-08 14:02:27 -070084
85 typedef GrGpuCommandBuffer INHERITED;
86};
87
88#endif
89