1 /* 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 13 #include "GrGLGpu.h" 14 #include "GrOpFlushState.h" 15 16 class GrGLRenderTarget; 17 18 class GrGLGpuCommandBuffer : public GrGpuCommandBuffer { 19 /** 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 */ 24 public: GrGLGpuCommandBuffer(GrGLGpu * gpu)25 GrGLGpuCommandBuffer(GrGLGpu* gpu) : fGpu(gpu), fRenderTarget(nullptr) {} 26 ~GrGLGpuCommandBuffer()27 ~GrGLGpuCommandBuffer() override {} 28 end()29 void end() override {} 30 discard(GrRenderTarget * rt)31 void discard(GrRenderTarget* rt) override { 32 GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(rt); 33 if (!fRenderTarget) { 34 fRenderTarget = target; 35 } 36 SkASSERT(target == fRenderTarget); 37 } 38 inlineUpload(GrOpFlushState * state,GrDrawOp::DeferredUploadFn & upload,GrRenderTarget *)39 void inlineUpload(GrOpFlushState* state, GrDrawOp::DeferredUploadFn& upload, 40 GrRenderTarget*) override { 41 state->doUpload(upload); 42 } 43 44 private: gpu()45 GrGpu* gpu() override { return fGpu; } renderTarget()46 GrRenderTarget* renderTarget() override { return fRenderTarget; } 47 onSubmit()48 void onSubmit() override {} 49 onDraw(const GrPipeline & pipeline,const GrPrimitiveProcessor & primProc,const GrMesh * mesh,int meshCount,const SkRect & bounds)50 void onDraw(const GrPipeline& pipeline, 51 const GrPrimitiveProcessor& primProc, 52 const GrMesh* mesh, 53 int meshCount, 54 const SkRect& bounds) override { 55 GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(pipeline.getRenderTarget()); 56 if (!fRenderTarget) { 57 fRenderTarget = target; 58 } 59 SkASSERT(target == fRenderTarget); 60 fGpu->draw(pipeline, primProc, mesh, meshCount); 61 } 62 onClear(GrRenderTarget * rt,const GrFixedClip & clip,GrColor color)63 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); 69 fGpu->clear(clip, color, fRenderTarget); 70 } 71 onClearStencilClip(GrRenderTarget * rt,const GrFixedClip & clip,bool insideStencilMask)72 void onClearStencilClip(GrRenderTarget* rt, const GrFixedClip& clip, 73 bool insideStencilMask) override { 74 GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(rt); 75 if (!fRenderTarget) { 76 fRenderTarget = target; 77 } 78 SkASSERT(target == fRenderTarget); 79 fGpu->clearStencilClip(clip, insideStencilMask, fRenderTarget); 80 } 81 82 GrGLGpu* fGpu; 83 GrGLRenderTarget* fRenderTarget; 84 85 typedef GrGpuCommandBuffer INHERITED; 86 }; 87 88 #endif 89 90