blob: e76253669ce34c583de81bdb2ffea431c382607a [file] [log] [blame]
egdaniel066df7c2016-06-08 14:02:27 -07001/*
Robert Phillips7294b852017-08-01 13:51:44 +00002* 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*/
egdaniel066df7c2016-06-08 14:02:27 -07007
8#ifndef GrGLGpuCommandBuffer_DEFINED
9#define GrGLGpuCommandBuffer_DEFINED
10
11#include "GrGpuCommandBuffer.h"
12
Hal Canary466c7d62017-07-03 15:11:49 -040013#include "GrGLGpu.h"
14#include "GrGLRenderTarget.h"
Brian Salomon742e31d2016-12-07 17:06:19 -050015#include "GrOpFlushState.h"
egdaniel066df7c2016-06-08 14:02:27 -070016
Robert Phillips009e9af2017-06-15 14:01:04 -040017class GrGLGpu;
Greg Daniel65a09272016-10-12 09:47:22 -040018class GrGLRenderTarget;
19
Greg Daniel500d58b2017-08-24 15:59:33 -040020class GrGLGpuTextureCommandBuffer : public GrGpuTextureCommandBuffer {
21public:
22 GrGLGpuTextureCommandBuffer(GrGLGpu* gpu, GrTexture* texture, GrSurfaceOrigin origin)
23 : INHERITED(texture, origin)
24 , fGpu(gpu) {
25 }
26
27 ~GrGLGpuTextureCommandBuffer() override {}
28
29 void submit() override {}
30
31 void copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override {
32 fGpu->copySurface(fTexture, src, srcRect, dstPoint);
33 }
34
35 void insertEventMarker(const char* msg) override {
36 fGpu->insertEventMarker(msg);
37 }
38
39private:
40 GrGLGpu* fGpu;
41
42 typedef GrGpuTextureCommandBuffer INHERITED;
43};
44
45class GrGLGpuRTCommandBuffer : public GrGpuRTCommandBuffer {
egdaniel9cb63402016-06-23 08:37:05 -070046/**
47 * We do not actually buffer up draws or do any work in the this class for GL. Instead commands
48 * are immediately sent to the gpu to execute. Thus all the commands in this class are simply
49 * pass through functions to corresponding calls in the GrGLGpu class.
50 */
egdaniel066df7c2016-06-08 14:02:27 -070051public:
Greg Daniel500d58b2017-08-24 15:59:33 -040052 GrGLGpuRTCommandBuffer(GrGLGpu* gpu, GrRenderTarget* rt, GrSurfaceOrigin origin,
53 const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo& stencilInfo)
Robert Phillips19e51dc2017-08-09 09:30:51 -040054 : INHERITED(rt, origin)
Robert Phillips54190c42017-08-09 20:09:38 +000055 , fGpu(gpu) {
56 fClearSB = LoadOp::kClear == stencilInfo.fLoadOp;
Robert Phillips95214472017-08-08 18:00:03 -040057 }
egdaniel066df7c2016-06-08 14:02:27 -070058
Greg Daniel500d58b2017-08-24 15:59:33 -040059 ~GrGLGpuRTCommandBuffer() override {}
egdaniel066df7c2016-06-08 14:02:27 -070060
Robert Phillips95214472017-08-08 18:00:03 -040061 void begin() override {
Robert Phillips54190c42017-08-09 20:09:38 +000062 if (fClearSB) {
Robert Phillips95214472017-08-08 18:00:03 -040063 fGpu->clearStencil(fRenderTarget, 0x0);
64 }
65 }
egdaniel066df7c2016-06-08 14:02:27 -070066 void end() override {}
67
Robert Phillips19e51dc2017-08-09 09:30:51 -040068 void discard() override { }
egdaniel066df7c2016-06-08 14:02:27 -070069
Robert Phillips19e51dc2017-08-09 09:30:51 -040070 void insertEventMarker(const char* msg) override {
Robert Phillips65a88fa2017-08-08 08:36:22 -040071 fGpu->insertEventMarker(msg);
72 }
73
Robert Phillips19e51dc2017-08-09 09:30:51 -040074 void inlineUpload(GrOpFlushState* state, GrDrawOp::DeferredUploadFn& upload) override {
Greg Daniel77b53f62016-10-18 11:48:51 -040075 state->doUpload(upload);
76 }
77
Greg Daniel500d58b2017-08-24 15:59:33 -040078 void copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override {
79 fGpu->copySurface(fRenderTarget, src, srcRect, dstPoint);
80 }
81
82 void submit() override {}
83
egdaniel066df7c2016-06-08 14:02:27 -070084private:
egdaniel9cb63402016-06-23 08:37:05 -070085 GrGpu* gpu() override { return fGpu; }
86
egdaniel9cb63402016-06-23 08:37:05 -070087 void onDraw(const GrPipeline& pipeline,
88 const GrPrimitiveProcessor& primProc,
Chris Dalton46983b72017-06-06 12:27:16 -060089 const GrMesh mesh[],
90 const GrPipeline::DynamicState dynamicStates[],
Greg Daniel36a77ee2016-10-18 10:33:25 -040091 int meshCount,
92 const SkRect& bounds) override {
Robert Phillips19e51dc2017-08-09 09:30:51 -040093 SkASSERT(pipeline.renderTarget() == fRenderTarget);
Chris Dalton46983b72017-06-06 12:27:16 -060094 fGpu->draw(pipeline, primProc, mesh, dynamicStates, meshCount);
egdaniel9cb63402016-06-23 08:37:05 -070095 }
96
Robert Phillips19e51dc2017-08-09 09:30:51 -040097 void onClear(const GrFixedClip& clip, GrColor color) override {
98 fGpu->clear(clip, color, fRenderTarget, fOrigin);
egdaniel9cb63402016-06-23 08:37:05 -070099 }
100
Robert Phillips19e51dc2017-08-09 09:30:51 -0400101 void onClearStencilClip(const GrFixedClip& clip, bool insideStencilMask) override {
102 fGpu->clearStencilClip(clip, insideStencilMask, fRenderTarget, fOrigin);
egdaniel9cb63402016-06-23 08:37:05 -0700103 }
104
Robert Phillips54190c42017-08-09 20:09:38 +0000105 GrGLGpu* fGpu;
106 bool fClearSB;
egdaniel066df7c2016-06-08 14:02:27 -0700107
Greg Daniel500d58b2017-08-24 15:59:33 -0400108 typedef GrGpuRTCommandBuffer INHERITED;
egdaniel066df7c2016-06-08 14:02:27 -0700109};
110
111#endif
112