Home | History | Annotate | Download | only in gl
      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 "GrGLRenderTarget.h"
     15 #include "GrOpFlushState.h"
     16 
     17 class GrGLGpu;
     18 class GrGLRenderTarget;
     19 
     20 class GrGLGpuCommandBuffer : public GrGpuCommandBuffer {
     21 /**
     22  * We do not actually buffer up draws or do any work in the this class for GL. Instead commands
     23  * are immediately sent to the gpu to execute. Thus all the commands in this class are simply
     24  * pass through functions to corresponding calls in the GrGLGpu class.
     25  */
     26 public:
     27     GrGLGpuCommandBuffer(GrGLGpu* gpu) : fGpu(gpu), fRenderTarget(nullptr) {}
     28 
     29     ~GrGLGpuCommandBuffer() override {}
     30 
     31     void end() override {}
     32 
     33     void discard(GrRenderTarget* rt) override {
     34         GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(rt);
     35         if (!fRenderTarget) {
     36             fRenderTarget = target;
     37         }
     38         SkASSERT(target == fRenderTarget);
     39     }
     40 
     41     void inlineUpload(GrOpFlushState* state, GrDrawOp::DeferredUploadFn& upload,
     42                       GrRenderTarget*) override {
     43         state->doUpload(upload);
     44     }
     45 
     46 private:
     47     GrGpu* gpu() override { return fGpu; }
     48     GrRenderTarget* renderTarget() override { return fRenderTarget; }
     49 
     50     void onSubmit() override {}
     51 
     52     void onDraw(const GrPipeline& pipeline,
     53                 const GrPrimitiveProcessor& primProc,
     54                 const GrMesh mesh[],
     55                 const GrPipeline::DynamicState dynamicStates[],
     56                 int meshCount,
     57                 const SkRect& bounds) override {
     58         GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(pipeline.getRenderTarget());
     59         if (!fRenderTarget) {
     60             fRenderTarget = target;
     61         }
     62         SkASSERT(target == fRenderTarget);
     63         fGpu->draw(pipeline, primProc, mesh, dynamicStates, meshCount);
     64     }
     65 
     66     void onClear(GrRenderTarget* rt, const GrFixedClip& clip, GrColor color) override {
     67         GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(rt);
     68         if (!fRenderTarget) {
     69             fRenderTarget = target;
     70         }
     71         SkASSERT(target == fRenderTarget);
     72         fGpu->clear(clip, color, fRenderTarget);
     73     }
     74 
     75     void onClearStencilClip(GrRenderTarget* rt, const GrFixedClip& clip,
     76                             bool insideStencilMask) override {
     77         GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(rt);
     78         if (!fRenderTarget) {
     79             fRenderTarget = target;
     80         }
     81         SkASSERT(target == fRenderTarget);
     82         fGpu->clearStencilClip(clip, insideStencilMask, fRenderTarget);
     83     }
     84 
     85     GrGLGpu*                    fGpu;
     86     GrGLRenderTarget*           fRenderTarget;
     87 
     88     typedef GrGpuCommandBuffer INHERITED;
     89 };
     90 
     91 #endif
     92 
     93