blob: ee7414eafc97d8785343d35c623e78b02c9fb541 [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
robertphillips28a838e2016-06-23 14:07:00 -070010#include "GrCaps.h"
csmartdalton29df7602016-08-31 11:55:52 -070011#include "GrFixedClip.h"
egdaniel9cb63402016-06-23 08:37:05 -070012#include "GrGpu.h"
Brian Salomon2a55c8e2017-05-09 09:57:19 -040013#include "GrMesh.h"
egdaniel9cb63402016-06-23 08:37:05 -070014#include "GrPrimitiveProcessor.h"
15#include "GrRenderTarget.h"
16#include "SkRect.h"
17
Greg Daniel36a77ee2016-10-18 10:33:25 -040018void GrGpuCommandBuffer::submit() {
egdaniel9cb63402016-06-23 08:37:05 -070019 this->gpu()->handleDirtyContext();
Greg Daniel36a77ee2016-10-18 10:33:25 -040020 this->onSubmit();
egdaniel9cb63402016-06-23 08:37:05 -070021}
22
Brian Salomonc293a292016-11-30 13:38:32 -050023void GrGpuCommandBuffer::clear(GrRenderTarget* rt, const GrFixedClip& clip, GrColor color) {
Greg Daniel65a09272016-10-12 09:47:22 -040024#ifdef SK_DEBUG
csmartdalton29df7602016-08-31 11:55:52 -070025 SkASSERT(rt);
26 SkASSERT(!clip.scissorEnabled() ||
27 (SkIRect::MakeWH(rt->width(), rt->height()).contains(clip.scissorRect()) &&
28 SkIRect::MakeWH(rt->width(), rt->height()) != clip.scissorRect()));
Greg Daniel65a09272016-10-12 09:47:22 -040029#endif
Brian Salomonc293a292016-11-30 13:38:32 -050030 this->onClear(rt, clip, color);
egdaniel9cb63402016-06-23 08:37:05 -070031}
32
Brian Salomonc293a292016-11-30 13:38:32 -050033void GrGpuCommandBuffer::clearStencilClip(GrRenderTarget* rt, const GrFixedClip& clip,
Greg Daniel65a09272016-10-12 09:47:22 -040034 bool insideStencilMask) {
Brian Salomonc293a292016-11-30 13:38:32 -050035 this->onClearStencilClip(rt, clip, insideStencilMask);
egdaniel9cb63402016-06-23 08:37:05 -070036}
37
egdaniel9cb63402016-06-23 08:37:05 -070038bool GrGpuCommandBuffer::draw(const GrPipeline& pipeline,
39 const GrPrimitiveProcessor& primProc,
Chris Daltonbca46e22017-05-15 11:03:26 -060040 const GrMesh meshes[],
Greg Daniel36a77ee2016-10-18 10:33:25 -040041 int meshCount,
42 const SkRect& bounds) {
Chris Daltonbca46e22017-05-15 11:03:26 -060043#ifdef SK_DEBUG
44 for (int i = 0; i < meshCount; ++i) {
45 SkASSERT(SkToBool(primProc.numAttribs()) == SkToBool(meshes[i].vertexBuffer()));
46 }
47#endif
48
Robert Phillipsa91e0b72017-05-01 13:12:20 -040049 if (pipeline.isBad() || primProc.isBad()) {
50 return false;
51 }
52
Brian Salomonb5cb6832017-02-24 11:01:15 -050053 SkASSERT(pipeline.isInitialized());
egdaniel9cb63402016-06-23 08:37:05 -070054 if (primProc.numAttribs() > this->gpu()->caps()->maxVertexAttributes()) {
55 this->gpu()->stats()->incNumFailedDraws();
56 return false;
57 }
Chris Daltonbca46e22017-05-15 11:03:26 -060058 this->onDraw(pipeline, primProc, meshes, meshCount, bounds);
egdaniel9cb63402016-06-23 08:37:05 -070059 return true;
60}
61