blob: 4dfc334d7ab076a5c40560b8afad44db4a5717f2 [file] [log] [blame]
egdaniel9cb63402016-06-23 08:37:05 -07001/*
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 Phillips9bee2e52017-05-29 12:37:20 -040010#include "GrContext.h"
robertphillips28a838e2016-06-23 14:07:00 -070011#include "GrCaps.h"
csmartdalton29df7602016-08-31 11:55:52 -070012#include "GrFixedClip.h"
egdaniel9cb63402016-06-23 08:37:05 -070013#include "GrGpu.h"
Brian Salomon2a55c8e2017-05-09 09:57:19 -040014#include "GrMesh.h"
egdaniel9cb63402016-06-23 08:37:05 -070015#include "GrPrimitiveProcessor.h"
16#include "GrRenderTarget.h"
17#include "SkRect.h"
18
Greg Daniel500d58b2017-08-24 15:59:33 -040019void GrGpuRTCommandBuffer::clear(const GrFixedClip& clip, GrColor color) {
Robert Phillips4912d902018-04-27 12:09:35 -040020 SkASSERT(fRenderTarget);
21
Robert Phillips19e51dc2017-08-09 09:30:51 -040022 this->onClear(clip, color);
egdaniel9cb63402016-06-23 08:37:05 -070023}
24
Greg Daniel500d58b2017-08-24 15:59:33 -040025void GrGpuRTCommandBuffer::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
Robert Phillips19e51dc2017-08-09 09:30:51 -040026 this->onClearStencilClip(clip, insideStencilMask);
egdaniel9cb63402016-06-23 08:37:05 -070027}
28
Greg Daniel500d58b2017-08-24 15:59:33 -040029bool GrGpuRTCommandBuffer::draw(const GrPipeline& pipeline,
30 const GrPrimitiveProcessor& primProc,
31 const GrMesh meshes[],
32 const GrPipeline::DynamicState dynamicStates[],
33 int meshCount,
34 const SkRect& bounds) {
Chris Daltonbca46e22017-05-15 11:03:26 -060035#ifdef SK_DEBUG
Chris Dalton1d616352017-05-31 12:51:23 -060036 SkASSERT(!primProc.hasInstanceAttribs() || this->gpu()->caps()->instanceAttribSupport());
Chris Dalton27059d32018-01-23 14:06:50 -070037 SkASSERT(!primProc.willUsePrimitiveRestart() || this->gpu()->caps()->usePrimitiveRestart());
Chris Daltonbca46e22017-05-15 11:03:26 -060038 for (int i = 0; i < meshCount; ++i) {
Chris Daltonb894c2b2017-06-14 12:39:19 -060039 SkASSERT(!GrPrimTypeRequiresGeometryShaderSupport(meshes[i].primitiveType()) ||
Chris Dalton3809bab2017-06-13 10:55:06 -060040 this->gpu()->caps()->shaderCaps()->geometryShaderSupport());
Chris Dalton1d616352017-05-31 12:51:23 -060041 SkASSERT(primProc.hasVertexAttribs() == meshes[i].hasVertexData());
42 SkASSERT(primProc.hasInstanceAttribs() == meshes[i].isInstanced());
Chris Daltonbca46e22017-05-15 11:03:26 -060043 }
44#endif
Robert Phillips6be756b2018-01-16 15:07:54 -050045 auto resourceProvider = this->gpu()->getContext()->contextPriv().resourceProvider();
Chris Daltonbca46e22017-05-15 11:03:26 -060046
Robert Phillips6be756b2018-01-16 15:07:54 -050047 if (pipeline.isBad() || !primProc.instantiate(resourceProvider)) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040048 return false;
49 }
50
egdaniel9cb63402016-06-23 08:37:05 -070051 if (primProc.numAttribs() > this->gpu()->caps()->maxVertexAttributes()) {
52 this->gpu()->stats()->incNumFailedDraws();
53 return false;
54 }
Chris Dalton46983b72017-06-06 12:27:16 -060055 this->onDraw(pipeline, primProc, meshes, dynamicStates, meshCount, bounds);
egdaniel9cb63402016-06-23 08:37:05 -070056 return true;
57}
58