egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 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 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 13 | #include "GrGLGpu.h" |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 14 | #include "GrOpFlushState.h" |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 15 | |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 16 | class GrGLRenderTarget; |
| 17 | |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 18 | class GrGLGpuCommandBuffer : public GrGpuCommandBuffer { |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 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 | */ |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 24 | public: |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 25 | GrGLGpuCommandBuffer(GrGLGpu* gpu) : fGpu(gpu), fRenderTarget(nullptr) {} |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 26 | |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 27 | ~GrGLGpuCommandBuffer() override {} |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 28 | |
| 29 | void end() override {} |
| 30 | |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 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 | } |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 38 | |
Greg Daniel | dbd11ec | 2017-03-21 16:56:31 -0400 | [diff] [blame^] | 39 | void inlineUpload(GrOpFlushState* state, GrDrawOp::DeferredUploadFn& upload, |
| 40 | GrRenderTarget*) override { |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 41 | state->doUpload(upload); |
| 42 | } |
| 43 | |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 44 | private: |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 45 | GrGpu* gpu() override { return fGpu; } |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 46 | GrRenderTarget* renderTarget() override { return fRenderTarget; } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 47 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 48 | void onSubmit() override {} |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 49 | |
| 50 | void onDraw(const GrPipeline& pipeline, |
| 51 | const GrPrimitiveProcessor& primProc, |
| 52 | const GrMesh* mesh, |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 53 | int meshCount, |
| 54 | const SkRect& bounds) override { |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 55 | GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(pipeline.getRenderTarget()); |
| 56 | if (!fRenderTarget) { |
| 57 | fRenderTarget = target; |
| 58 | } |
| 59 | SkASSERT(target == fRenderTarget); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 60 | fGpu->draw(pipeline, primProc, mesh, meshCount); |
| 61 | } |
| 62 | |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 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); |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 69 | fGpu->clear(clip, color, fRenderTarget); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 72 | void onClearStencilClip(GrRenderTarget* rt, const GrFixedClip& clip, |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 73 | bool insideStencilMask) override { |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 74 | GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(rt); |
| 75 | if (!fRenderTarget) { |
| 76 | fRenderTarget = target; |
| 77 | } |
| 78 | SkASSERT(target == fRenderTarget); |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 79 | fGpu->clearStencilClip(clip, insideStencilMask, fRenderTarget); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | GrGLGpu* fGpu; |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 83 | GrGLRenderTarget* fRenderTarget; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 84 | |
| 85 | typedef GrGpuCommandBuffer INHERITED; |
| 86 | }; |
| 87 | |
| 88 | #endif |
| 89 | |