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 GrGLGpuTextureCommandBuffer : public GrGpuTextureCommandBuffer {
21 public:
GrGLGpuTextureCommandBuffer(GrGLGpu * gpu)22     GrGLGpuTextureCommandBuffer(GrGLGpu* gpu) : fGpu(gpu) {}
23 
copy(GrSurface * src,GrSurfaceOrigin srcOrigin,const SkIRect & srcRect,const SkIPoint & dstPoint)24     void copy(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect,
25               const SkIPoint& dstPoint) override {
26         fGpu->copySurface(fTexture, fOrigin, src, srcOrigin, srcRect, dstPoint);
27     }
28 
insertEventMarker(const char * msg)29     void insertEventMarker(const char* msg) override {
30         fGpu->insertEventMarker(msg);
31     }
32 
reset()33     void reset() {
34         fTexture = nullptr;
35     }
36 
37 private:
38     GrGLGpu* fGpu;
39 
40     typedef GrGpuTextureCommandBuffer INHERITED;
41 };
42 
43 class GrGLGpuRTCommandBuffer : public GrGpuRTCommandBuffer {
44 /**
45  * We do not actually buffer up draws or do any work in the this class for GL. Instead commands
46  * are immediately sent to the gpu to execute. Thus all the commands in this class are simply
47  * pass through functions to corresponding calls in the GrGLGpu class.
48  */
49 public:
GrGLGpuRTCommandBuffer(GrGLGpu * gpu)50     GrGLGpuRTCommandBuffer(GrGLGpu* gpu) : fGpu(gpu) {}
51 
52     void begin() override;
end()53     void end() override {}
54 
discard()55     void discard() override { }
56 
insertEventMarker(const char * msg)57     void insertEventMarker(const char* msg) override {
58         fGpu->insertEventMarker(msg);
59     }
60 
inlineUpload(GrOpFlushState * state,GrDeferredTextureUploadFn & upload)61     void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override {
62         state->doUpload(upload);
63     }
64 
copy(GrSurface * src,GrSurfaceOrigin srcOrigin,const SkIRect & srcRect,const SkIPoint & dstPoint)65     void copy(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect,
66               const SkIPoint& dstPoint) override {
67         fGpu->copySurface(fRenderTarget, fOrigin, src, srcOrigin, srcRect, dstPoint);
68     }
69 
70     void set(GrRenderTarget*, GrSurfaceOrigin,
71              const GrGpuRTCommandBuffer::LoadAndStoreInfo&,
72              const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&);
73 
reset()74     void reset() {
75         fRenderTarget = nullptr;
76     }
77 
78 private:
gpu()79     GrGpu* gpu() override { return fGpu; }
80 
onDraw(const GrPrimitiveProcessor & primProc,const GrPipeline & pipeline,const GrPipeline::FixedDynamicState * fixedDynamicState,const GrPipeline::DynamicStateArrays * dynamicStateArrays,const GrMesh mesh[],int meshCount,const SkRect & bounds)81     void onDraw(const GrPrimitiveProcessor& primProc,
82                 const GrPipeline& pipeline,
83                 const GrPipeline::FixedDynamicState* fixedDynamicState,
84                 const GrPipeline::DynamicStateArrays* dynamicStateArrays,
85                 const GrMesh mesh[],
86                 int meshCount,
87                 const SkRect& bounds) override {
88         fGpu->draw(fRenderTarget, fOrigin, primProc, pipeline, fixedDynamicState,
89                    dynamicStateArrays, mesh, meshCount);
90     }
91 
onClear(const GrFixedClip & clip,const SkPMColor4f & color)92     void onClear(const GrFixedClip& clip, const SkPMColor4f& color) override {
93         fGpu->clear(clip, color, fRenderTarget, fOrigin);
94     }
95 
onClearStencilClip(const GrFixedClip & clip,bool insideStencilMask)96     void onClearStencilClip(const GrFixedClip& clip, bool insideStencilMask) override {
97         fGpu->clearStencilClip(clip, insideStencilMask, fRenderTarget, fOrigin);
98     }
99 
100     GrGLGpu*                                      fGpu;
101     GrGpuRTCommandBuffer::LoadAndStoreInfo        fColorLoadAndStoreInfo;
102     GrGpuRTCommandBuffer::StencilLoadAndStoreInfo fStencilLoadAndStoreInfo;
103 
104     typedef GrGpuRTCommandBuffer INHERITED;
105 };
106 
107 #endif
108 
109