blob: 6b56dea421dec2c8cbb5a68348016d28182e7a72 [file] [log] [blame]
joshualitte46760e2015-05-05 08:41:50 -07001/*
2 * Copyright 2015 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 "GrCommandBuilder.h"
9
joshualitt3b58d752015-05-07 11:14:30 -070010#include "GrInOrderCommandBuilder.h"
11#include "GrReorderCommandBuilder.h"
12
13GrCommandBuilder* GrCommandBuilder::Create(GrGpu* gpu, bool reorder) {
14 if (reorder) {
15 return SkNEW_ARGS(GrReorderCommandBuilder, (gpu));
16 } else {
17 return SkNEW_ARGS(GrInOrderCommandBuilder, (gpu));
18 }
19}
20
joshualitte46760e2015-05-05 08:41:50 -070021GrTargetCommands::Cmd* GrCommandBuilder::recordClear(const SkIRect* rect,
22 GrColor color,
23 bool canIgnoreRect,
24 GrRenderTarget* renderTarget) {
25 SkASSERT(renderTarget);
26
27 SkIRect r;
28 if (NULL == rect) {
29 // We could do something smart and remove previous draws and clears to
30 // the current render target. If we get that smart we have to make sure
31 // those draws aren't read before this clear (render-to-texture).
32 r.setLTRB(0, 0, renderTarget->width(), renderTarget->height());
33 rect = &r;
34 }
joshualitt36ec3832015-05-26 09:33:48 -070035
36 SkASSERT(color == GrColor_ILLEGAL ||
37 canIgnoreRect ||
38 (rect->fLeft <= rect->fRight && rect->fTop <= rect->fBottom));
39
joshualitte46760e2015-05-05 08:41:50 -070040 Clear* clr = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), Clear, (renderTarget));
41 GrColorIsPMAssert(color);
42 clr->fColor = color;
43 clr->fRect = *rect;
44 clr->fCanIgnoreRect = canIgnoreRect;
45 return clr;
46}
47
48GrTargetCommands::Cmd* GrCommandBuilder::recordClearStencilClip(const SkIRect& rect,
49 bool insideClip,
50 GrRenderTarget* renderTarget) {
51 SkASSERT(renderTarget);
52
53 ClearStencilClip* clr = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(),
54 ClearStencilClip,
55 (renderTarget));
56 clr->fRect = rect;
57 clr->fInsideClip = insideClip;
58 return clr;
59}
60
61GrTargetCommands::Cmd* GrCommandBuilder::recordDiscard(GrRenderTarget* renderTarget) {
62 SkASSERT(renderTarget);
63
64 Clear* clr = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), Clear, (renderTarget));
65 clr->fColor = GrColor_ILLEGAL;
66 return clr;
67}
68
69GrTargetCommands::Cmd* GrCommandBuilder::recordCopySurface(GrSurface* dst,
70 GrSurface* src,
71 const SkIRect& srcRect,
72 const SkIPoint& dstPoint) {
73 CopySurface* cs = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), CopySurface, (dst, src));
74 cs->fSrcRect = srcRect;
75 cs->fDstPoint = dstPoint;
76 return cs;
77}
78
79GrTargetCommands::Cmd*
80GrCommandBuilder::recordXferBarrierIfNecessary(const GrPipeline& pipeline,
bsalomon4b91f762015-05-19 09:29:46 -070081 const GrCaps& caps) {
joshualitte46760e2015-05-05 08:41:50 -070082 const GrXferProcessor& xp = *pipeline.getXferProcessor();
83 GrRenderTarget* rt = pipeline.getRenderTarget();
84
85 GrXferBarrierType barrierType;
86 if (!xp.willNeedXferBarrier(rt, caps, &barrierType)) {
87 return NULL;
88 }
89
cdalton231c5fd2015-05-13 12:35:36 -070090 XferBarrier* xb = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), XferBarrier, (rt));
joshualitte46760e2015-05-05 08:41:50 -070091 xb->fBarrierType = barrierType;
92 return xb;
93}