| 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 |  | 
| Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 10 | #include "GrContext.h" | 
| robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 11 | #include "GrCaps.h" | 
| csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 12 | #include "GrFixedClip.h" | 
| egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 13 | #include "GrGpu.h" | 
| Brian Salomon | 2a55c8e | 2017-05-09 09:57:19 -0400 | [diff] [blame] | 14 | #include "GrMesh.h" | 
| egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 15 | #include "GrPrimitiveProcessor.h" | 
 | 16 | #include "GrRenderTarget.h" | 
 | 17 | #include "SkRect.h" | 
 | 18 |  | 
| Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 19 | void GrGpuRTCommandBuffer::clear(const GrFixedClip& clip, GrColor color) { | 
| Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 20 | #ifdef SK_DEBUG | 
| Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 21 |     GrRenderTarget* rt = fRenderTarget; | 
| csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 22 |     SkASSERT(rt); | 
 | 23 |     SkASSERT(!clip.scissorEnabled() || | 
 | 24 |              (SkIRect::MakeWH(rt->width(), rt->height()).contains(clip.scissorRect()) && | 
 | 25 |               SkIRect::MakeWH(rt->width(), rt->height()) != clip.scissorRect())); | 
| Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 26 | #endif | 
| Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 27 |     this->onClear(clip, color); | 
| egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 28 | } | 
 | 29 |  | 
| Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 30 | void GrGpuRTCommandBuffer::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) { | 
| Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 31 |     this->onClearStencilClip(clip, insideStencilMask); | 
| egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 32 | } | 
 | 33 |  | 
| Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 34 | bool GrGpuRTCommandBuffer::draw(const GrPipeline& pipeline, | 
 | 35 |                                 const GrPrimitiveProcessor& primProc, | 
 | 36 |                                 const GrMesh meshes[], | 
 | 37 |                                 const GrPipeline::DynamicState dynamicStates[], | 
 | 38 |                                 int meshCount, | 
 | 39 |                                 const SkRect& bounds) { | 
| Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 40 | #ifdef SK_DEBUG | 
| Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 41 |     SkASSERT(!primProc.hasInstanceAttribs() || this->gpu()->caps()->instanceAttribSupport()); | 
| Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 42 |     for (int i = 0; i < meshCount; ++i) { | 
| Chris Dalton | b894c2b | 2017-06-14 12:39:19 -0600 | [diff] [blame] | 43 |         SkASSERT(!GrPrimTypeRequiresGeometryShaderSupport(meshes[i].primitiveType()) || | 
| Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 44 |                  this->gpu()->caps()->shaderCaps()->geometryShaderSupport()); | 
| Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 45 |         SkASSERT(primProc.hasVertexAttribs() == meshes[i].hasVertexData()); | 
 | 46 |         SkASSERT(primProc.hasInstanceAttribs() == meshes[i].isInstanced()); | 
| Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 47 |     } | 
 | 48 | #endif | 
 | 49 |  | 
| Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 50 |     if (pipeline.isBad() || !primProc.instantiate(this->gpu()->getContext()->resourceProvider())) { | 
| Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 51 |         return false; | 
 | 52 |     } | 
 | 53 |  | 
| 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 | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 58 |     this->onDraw(pipeline, primProc, meshes, dynamicStates, meshCount, bounds); | 
| egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 59 |     return true; | 
 | 60 | } | 
 | 61 |  |