blob: 1dc16c1caac5aa00319d2ea6cb4a4f55e9fc0497 [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 Daltonbca46e22017-05-15 11:03:26 -060042 for (int i = 0; i < meshCount; ++i) {
Chris Daltonb894c2b2017-06-14 12:39:19 -060043 SkASSERT(!GrPrimTypeRequiresGeometryShaderSupport(meshes[i].primitiveType()) ||
Chris Dalton3809bab2017-06-13 10:55:06 -060044 this->gpu()->caps()->shaderCaps()->geometryShaderSupport());
Chris Dalton1d616352017-05-31 12:51:23 -060045 SkASSERT(primProc.hasVertexAttribs() == meshes[i].hasVertexData());
46 SkASSERT(primProc.hasInstanceAttribs() == meshes[i].isInstanced());
Chris Daltonbca46e22017-05-15 11:03:26 -060047 }
48#endif
49
Robert Phillips9bee2e52017-05-29 12:37:20 -040050 if (pipeline.isBad() || !primProc.instantiate(this->gpu()->getContext()->resourceProvider())) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040051 return false;
52 }
53
egdaniel9cb63402016-06-23 08:37:05 -070054 if (primProc.numAttribs() > this->gpu()->caps()->maxVertexAttributes()) {
55 this->gpu()->stats()->incNumFailedDraws();
56 return false;
57 }
Chris Dalton46983b72017-06-06 12:27:16 -060058 this->onDraw(pipeline, primProc, meshes, dynamicStates, meshCount, bounds);
egdaniel9cb63402016-06-23 08:37:05 -070059 return true;
60}
61