1 /*
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 
10 #include "GrInOrderCommandBuilder.h"
11 #include "GrReorderCommandBuilder.h"
12 
Create(GrGpu * gpu,bool reorder)13 GrCommandBuilder* 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 
recordClear(const SkIRect * rect,GrColor color,bool canIgnoreRect,GrRenderTarget * renderTarget)21 GrTargetCommands::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     }
35     Clear* clr = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), Clear, (renderTarget));
36     GrColorIsPMAssert(color);
37     clr->fColor = color;
38     clr->fRect = *rect;
39     clr->fCanIgnoreRect = canIgnoreRect;
40     return clr;
41 }
42 
recordClearStencilClip(const SkIRect & rect,bool insideClip,GrRenderTarget * renderTarget)43 GrTargetCommands::Cmd* GrCommandBuilder::recordClearStencilClip(const SkIRect& rect,
44                                                                 bool insideClip,
45                                                                 GrRenderTarget* renderTarget) {
46     SkASSERT(renderTarget);
47 
48     ClearStencilClip* clr = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(),
49                                                      ClearStencilClip,
50                                                      (renderTarget));
51     clr->fRect = rect;
52     clr->fInsideClip = insideClip;
53     return clr;
54 }
55 
recordDiscard(GrRenderTarget * renderTarget)56 GrTargetCommands::Cmd* GrCommandBuilder::recordDiscard(GrRenderTarget* renderTarget) {
57     SkASSERT(renderTarget);
58 
59     Clear* clr = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), Clear, (renderTarget));
60     clr->fColor = GrColor_ILLEGAL;
61     return clr;
62 }
63 
recordCopySurface(GrSurface * dst,GrSurface * src,const SkIRect & srcRect,const SkIPoint & dstPoint)64 GrTargetCommands::Cmd* GrCommandBuilder::recordCopySurface(GrSurface* dst,
65                                                            GrSurface* src,
66                                                            const SkIRect& srcRect,
67                                                            const SkIPoint& dstPoint) {
68     CopySurface* cs = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), CopySurface, (dst, src));
69     cs->fSrcRect = srcRect;
70     cs->fDstPoint = dstPoint;
71     return cs;
72 }
73 
74 GrTargetCommands::Cmd*
recordXferBarrierIfNecessary(const GrPipeline & pipeline,const GrDrawTargetCaps & caps)75 GrCommandBuilder::recordXferBarrierIfNecessary(const GrPipeline& pipeline,
76                                                const GrDrawTargetCaps& caps) {
77     const GrXferProcessor& xp = *pipeline.getXferProcessor();
78     GrRenderTarget* rt = pipeline.getRenderTarget();
79 
80     GrXferBarrierType barrierType;
81     if (!xp.willNeedXferBarrier(rt, caps, &barrierType)) {
82         return NULL;
83     }
84 
85     XferBarrier* xb = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), XferBarrier, (rt));
86     xb->fBarrierType = barrierType;
87     return xb;
88 }
89