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