• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GrGLOpsRenderPass_DEFINED
9 #define GrGLOpsRenderPass_DEFINED
10 
11 #include "src/gpu/GrOpsRenderPass.h"
12 
13 #include "src/gpu/GrOpFlushState.h"
14 #include "src/gpu/gl/GrGLGpu.h"
15 #include "src/gpu/gl/GrGLRenderTarget.h"
16 
17 class GrGLGpu;
18 class GrGLRenderTarget;
19 
20 class GrGLOpsRenderPass : public GrOpsRenderPass {
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:
GrGLOpsRenderPass(GrGLGpu * gpu)27     GrGLOpsRenderPass(GrGLGpu* gpu) : fGpu(gpu) {}
28 
inlineUpload(GrOpFlushState * state,GrDeferredTextureUploadFn & upload)29     void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override {
30         state->doUpload(upload);
31     }
32 
33     void set(GrRenderTarget*, bool useMSAASurface, const SkIRect& contentBounds, GrSurfaceOrigin,
34              const LoadAndStoreInfo&, const StencilLoadAndStoreInfo&);
35 
reset()36     void reset() {
37         fRenderTarget = nullptr;
38     }
39 
40 private:
gpu()41     GrGpu* gpu() override { return fGpu; }
42 
43     void bindInstanceBuffer(const GrBuffer*, int baseInstance);
44     void bindVertexBuffer(const GrBuffer*, int baseVertex);
45 
offsetForBaseIndex(int baseIndex)46     const void* offsetForBaseIndex(int baseIndex) const {
47         if (!fIndexPointer) {
48             // nullptr != 0. Adding an offset to a nullptr is undefined.
49             return (void*)(baseIndex * sizeof(uint16_t));
50         }
51         return fIndexPointer + baseIndex;
52     }
53 
54     void onBegin() override;
55     void onEnd() override;
56     bool onBindPipeline(const GrProgramInfo& programInfo, const SkRect& drawBounds) override;
57     void onSetScissorRect(const SkIRect& scissor) override;
58     bool onBindTextures(const GrGeometryProcessor&,
59                         const GrSurfaceProxy* const geomProcTextures[],
60                         const GrPipeline&) override;
61     void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
62                        sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) override;
63     void onDraw(int vertexCount, int baseVertex) override;
64     void onDrawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue,
65                        uint16_t maxIndexValue, int baseVertex) override;
66     void onDrawInstanced(int instanceCount, int baseInstance, int vertexCount,
67                          int baseVertex) override;
68     void onDrawIndexedInstanced(int indexCount, int baseIndex, int instanceCount, int baseInstance,
69                                 int baseVertex) override;
70     void onDrawIndirect(const GrBuffer* drawIndirectBuffer, size_t offset, int drawCount) override;
71     void multiDrawArraysANGLEOrWebGL(const GrBuffer* drawIndirectBuffer, size_t offset,
72                                      int drawCount);
73     void onDrawIndexedIndirect(const GrBuffer* drawIndirectBuffer, size_t offset,
74                                int drawCount) override;
75     void multiDrawElementsANGLEOrWebGL(const GrBuffer* drawIndirectBuffer, size_t offset,
76                                        int drawCount);
77     void onClear(const GrScissorState& scissor, std::array<float, 4> color) override;
78     void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override;
79 
80     GrGLGpu* const fGpu;
81 
82     bool fUseMultisampleFBO;
83     SkIRect fContentBounds;
84     LoadAndStoreInfo fColorLoadAndStoreInfo;
85     StencilLoadAndStoreInfo fStencilLoadAndStoreInfo;
86 
87     // Per-pipeline state.
88     GrPrimitiveType fPrimitiveType;
89     GrGLAttribArrayState* fAttribArrayState = nullptr;
90 
91     // If using an index buffer, this gets set during onBindBuffers. It is either the CPU address of
92     // the indices, or nullptr if they reside physically in GPU memory.
93     const uint16_t* fIndexPointer;
94 
95     // This tracks whether or not we bound the respective buffers during the bindBuffers call.
96     SkDEBUGCODE(bool fDidBindVertexBuffer = false;)
97     SkDEBUGCODE(bool fDidBindInstanceBuffer = false;)
98 
99     using INHERITED = GrOpsRenderPass;
100 };
101 
102 #endif
103