blob: d66f24c74184bd2448d1045be8008879caedbe39 [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
Brian Salomon49348902018-06-26 09:12:38 -040029bool GrGpuRTCommandBuffer::draw(const GrPrimitiveProcessor& primProc, const GrPipeline& pipeline,
30 const GrPipeline::FixedDynamicState* fixedDynamicState,
31 const GrPipeline::DynamicStateArrays* dynamicStateArrays,
32 const GrMesh meshes[], int meshCount, const SkRect& bounds) {
Chris Daltonbca46e22017-05-15 11:03:26 -060033#ifdef SK_DEBUG
Brian Salomon92be2f72018-06-19 14:33:47 -040034 SkASSERT(!primProc.hasInstanceAttributes() || this->gpu()->caps()->instanceAttribSupport());
Chris Daltonbca46e22017-05-15 11:03:26 -060035 for (int i = 0; i < meshCount; ++i) {
Chris Daltonb894c2b2017-06-14 12:39:19 -060036 SkASSERT(!GrPrimTypeRequiresGeometryShaderSupport(meshes[i].primitiveType()) ||
Chris Dalton3809bab2017-06-13 10:55:06 -060037 this->gpu()->caps()->shaderCaps()->geometryShaderSupport());
Brian Salomon92be2f72018-06-19 14:33:47 -040038 SkASSERT(primProc.hasVertexAttributes() == meshes[i].hasVertexData());
39 SkASSERT(primProc.hasInstanceAttributes() == meshes[i].isInstanced());
Chris Daltonbca46e22017-05-15 11:03:26 -060040 }
41#endif
Brian Salomond818ebf2018-07-02 14:08:49 +000042 SkASSERT(!pipeline.isScissorEnabled() || fixedDynamicState ||
Brian Salomon49348902018-06-26 09:12:38 -040043 (dynamicStateArrays && dynamicStateArrays->fScissorRects));
44
Robert Phillips6be756b2018-01-16 15:07:54 -050045 auto resourceProvider = this->gpu()->getContext()->contextPriv().resourceProvider();
Chris Daltonbca46e22017-05-15 11:03:26 -060046
Brian Salomon7eae3e02018-08-07 14:02:38 +000047 if (pipeline.isBad()) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040048 return false;
49 }
Brian Salomoncd7907b2018-08-30 08:36:18 -040050 for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
51 if (!fixedDynamicState->fPrimitiveProcessorTextures[i]->instantiate(resourceProvider)) {
52 return false;
Brian Salomon7eae3e02018-08-07 14:02:38 +000053 }
54 }
Robert Phillipsa91e0b72017-05-01 13:12:20 -040055
Brian Salomon92be2f72018-06-19 14:33:47 -040056 if (primProc.numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) {
egdaniel9cb63402016-06-23 08:37:05 -070057 this->gpu()->stats()->incNumFailedDraws();
58 return false;
59 }
Brian Salomon49348902018-06-26 09:12:38 -040060 this->onDraw(primProc, pipeline, fixedDynamicState, dynamicStateArrays, meshes, meshCount,
61 bounds);
egdaniel9cb63402016-06-23 08:37:05 -070062 return true;
63}