egdaniel | 9cb6340 | 2016-06-23 08:37:05 -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 | #include "GrGpuCommandBuffer.h" |
| 9 | |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 10 | #include "GrCaps.h" |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 11 | #include "GrFixedClip.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 12 | #include "GrGpu.h" |
Brian Salomon | 2a55c8e | 2017-05-09 09:57:19 -0400 | [diff] [blame] | 13 | #include "GrMesh.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 14 | #include "GrPrimitiveProcessor.h" |
| 15 | #include "GrRenderTarget.h" |
| 16 | #include "SkRect.h" |
| 17 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 18 | void GrGpuCommandBuffer::submit() { |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 19 | this->gpu()->handleDirtyContext(); |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 20 | this->onSubmit(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 21 | } |
| 22 | |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 23 | void GrGpuCommandBuffer::clear(GrRenderTarget* rt, const GrFixedClip& clip, GrColor color) { |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 24 | #ifdef SK_DEBUG |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 25 | SkASSERT(rt); |
| 26 | SkASSERT(!clip.scissorEnabled() || |
| 27 | (SkIRect::MakeWH(rt->width(), rt->height()).contains(clip.scissorRect()) && |
| 28 | SkIRect::MakeWH(rt->width(), rt->height()) != clip.scissorRect())); |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 29 | #endif |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 30 | this->onClear(rt, clip, color); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 33 | void GrGpuCommandBuffer::clearStencilClip(GrRenderTarget* rt, const GrFixedClip& clip, |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 34 | bool insideStencilMask) { |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 35 | this->onClearStencilClip(rt, clip, insideStencilMask); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 36 | } |
| 37 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 38 | bool GrGpuCommandBuffer::draw(const GrPipeline& pipeline, |
| 39 | const GrPrimitiveProcessor& primProc, |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 40 | const GrMesh meshes[], |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 41 | int meshCount, |
| 42 | const SkRect& bounds) { |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 43 | #ifdef SK_DEBUG |
| 44 | for (int i = 0; i < meshCount; ++i) { |
| 45 | SkASSERT(SkToBool(primProc.numAttribs()) == SkToBool(meshes[i].vertexBuffer())); |
| 46 | } |
| 47 | #endif |
| 48 | |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 49 | if (pipeline.isBad() || primProc.isBad()) { |
| 50 | return false; |
| 51 | } |
| 52 | |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 53 | SkASSERT(pipeline.isInitialized()); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 54 | if (primProc.numAttribs() > this->gpu()->caps()->maxVertexAttributes()) { |
| 55 | this->gpu()->stats()->incNumFailedDraws(); |
| 56 | return false; |
| 57 | } |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 58 | this->onDraw(pipeline, primProc, meshes, meshCount, bounds); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 59 | return true; |
| 60 | } |
| 61 | |