blob: 654f7009be4ced6f8339ff29fc45a1187773837b [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) {
Greg Daniel65a09272016-10-12 09:47:22 -040020#ifdef SK_DEBUG
Robert Phillips19e51dc2017-08-09 09:30:51 -040021 GrRenderTarget* rt = fRenderTarget;
csmartdalton29df7602016-08-31 11:55:52 -070022 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 Daniel65a09272016-10-12 09:47:22 -040026#endif
Robert Phillips19e51dc2017-08-09 09:30:51 -040027 this->onClear(clip, color);
egdaniel9cb63402016-06-23 08:37:05 -070028}
29
Greg Daniel500d58b2017-08-24 15:59:33 -040030void GrGpuRTCommandBuffer::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
Robert Phillips19e51dc2017-08-09 09:30:51 -040031 this->onClearStencilClip(clip, insideStencilMask);
egdaniel9cb63402016-06-23 08:37:05 -070032}
33
Greg Daniel500d58b2017-08-24 15:59:33 -040034bool 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 Daltonbca46e22017-05-15 11:03:26 -060040#ifdef SK_DEBUG
Chris Dalton1d616352017-05-31 12:51:23 -060041 SkASSERT(!primProc.hasInstanceAttribs() || this->gpu()->caps()->instanceAttribSupport());
Chris Dalton27059d32018-01-23 14:06:50 -070042 SkASSERT(!primProc.willUsePrimitiveRestart() || this->gpu()->caps()->usePrimitiveRestart());
Chris Daltonbca46e22017-05-15 11:03:26 -060043 for (int i = 0; i < meshCount; ++i) {
Chris Daltonb894c2b2017-06-14 12:39:19 -060044 SkASSERT(!GrPrimTypeRequiresGeometryShaderSupport(meshes[i].primitiveType()) ||
Chris Dalton3809bab2017-06-13 10:55:06 -060045 this->gpu()->caps()->shaderCaps()->geometryShaderSupport());
Chris Dalton1d616352017-05-31 12:51:23 -060046 SkASSERT(primProc.hasVertexAttribs() == meshes[i].hasVertexData());
47 SkASSERT(primProc.hasInstanceAttribs() == meshes[i].isInstanced());
Chris Daltonbca46e22017-05-15 11:03:26 -060048 }
49#endif
Robert Phillips6be756b2018-01-16 15:07:54 -050050 auto resourceProvider = this->gpu()->getContext()->contextPriv().resourceProvider();
Chris Daltonbca46e22017-05-15 11:03:26 -060051
Robert Phillips6be756b2018-01-16 15:07:54 -050052 if (pipeline.isBad() || !primProc.instantiate(resourceProvider)) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040053 return false;
54 }
55
egdaniel9cb63402016-06-23 08:37:05 -070056 if (primProc.numAttribs() > this->gpu()->caps()->maxVertexAttributes()) {
57 this->gpu()->stats()->incNumFailedDraws();
58 return false;
59 }
Chris Dalton46983b72017-06-06 12:27:16 -060060 this->onDraw(pipeline, primProc, meshes, dynamicStates, meshCount, bounds);
egdaniel9cb63402016-06-23 08:37:05 -070061 return true;
62}
63