blob: ad370f077e9b3e52264b87ffb2d66aab056e0688 [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 Daniel36a77ee2016-10-18 10:33:25 -040019void GrGpuCommandBuffer::submit() {
egdaniel9cb63402016-06-23 08:37:05 -070020 this->gpu()->handleDirtyContext();
Greg Daniel36a77ee2016-10-18 10:33:25 -040021 this->onSubmit();
egdaniel9cb63402016-06-23 08:37:05 -070022}
23
Robert Phillips19e51dc2017-08-09 09:30:51 -040024void GrGpuCommandBuffer::clear(const GrFixedClip& clip, GrColor color) {
Greg Daniel65a09272016-10-12 09:47:22 -040025#ifdef SK_DEBUG
Robert Phillips19e51dc2017-08-09 09:30:51 -040026 GrRenderTarget* rt = fRenderTarget;
csmartdalton29df7602016-08-31 11:55:52 -070027 SkASSERT(rt);
28 SkASSERT(!clip.scissorEnabled() ||
29 (SkIRect::MakeWH(rt->width(), rt->height()).contains(clip.scissorRect()) &&
30 SkIRect::MakeWH(rt->width(), rt->height()) != clip.scissorRect()));
Greg Daniel65a09272016-10-12 09:47:22 -040031#endif
Robert Phillips19e51dc2017-08-09 09:30:51 -040032 this->onClear(clip, color);
egdaniel9cb63402016-06-23 08:37:05 -070033}
34
Robert Phillips19e51dc2017-08-09 09:30:51 -040035void GrGpuCommandBuffer::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
36 this->onClearStencilClip(clip, insideStencilMask);
egdaniel9cb63402016-06-23 08:37:05 -070037}
38
egdaniel9cb63402016-06-23 08:37:05 -070039bool GrGpuCommandBuffer::draw(const GrPipeline& pipeline,
40 const GrPrimitiveProcessor& primProc,
Chris Daltonbca46e22017-05-15 11:03:26 -060041 const GrMesh meshes[],
Chris Dalton46983b72017-06-06 12:27:16 -060042 const GrPipeline::DynamicState dynamicStates[],
Greg Daniel36a77ee2016-10-18 10:33:25 -040043 int meshCount,
44 const SkRect& bounds) {
Chris Daltonbca46e22017-05-15 11:03:26 -060045#ifdef SK_DEBUG
Chris Dalton1d616352017-05-31 12:51:23 -060046 SkASSERT(!primProc.hasInstanceAttribs() || this->gpu()->caps()->instanceAttribSupport());
Chris Daltonbca46e22017-05-15 11:03:26 -060047 for (int i = 0; i < meshCount; ++i) {
Chris Daltonb894c2b2017-06-14 12:39:19 -060048 SkASSERT(!GrPrimTypeRequiresGeometryShaderSupport(meshes[i].primitiveType()) ||
Chris Dalton3809bab2017-06-13 10:55:06 -060049 this->gpu()->caps()->shaderCaps()->geometryShaderSupport());
Chris Dalton1d616352017-05-31 12:51:23 -060050 SkASSERT(primProc.hasVertexAttribs() == meshes[i].hasVertexData());
51 SkASSERT(primProc.hasInstanceAttribs() == meshes[i].isInstanced());
Chris Daltonbca46e22017-05-15 11:03:26 -060052 }
53#endif
54
Robert Phillips9bee2e52017-05-29 12:37:20 -040055 if (pipeline.isBad() || !primProc.instantiate(this->gpu()->getContext()->resourceProvider())) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040056 return false;
57 }
58
egdaniel9cb63402016-06-23 08:37:05 -070059 if (primProc.numAttribs() > this->gpu()->caps()->maxVertexAttributes()) {
60 this->gpu()->stats()->incNumFailedDraws();
61 return false;
62 }
Chris Dalton46983b72017-06-06 12:27:16 -060063 this->onDraw(pipeline, primProc, meshes, dynamicStates, meshCount, bounds);
egdaniel9cb63402016-06-23 08:37:05 -070064 return true;
65}
66