joshualitt | e46760e | 2015-05-05 08:41:50 -0700 | [diff] [blame] | 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 | |
joshualitt | 3b58d75 | 2015-05-07 11:14:30 -0700 | [diff] [blame] | 10 | #include "GrInOrderCommandBuilder.h" |
| 11 | #include "GrReorderCommandBuilder.h" |
| 12 | |
| 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 | |
joshualitt | e46760e | 2015-05-05 08:41:50 -0700 | [diff] [blame] | 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 | } |
joshualitt | 36ec383 | 2015-05-26 09:33:48 -0700 | [diff] [blame] | 35 | |
joshualitt | 7a9c45c | 2015-05-26 12:32:23 -0700 | [diff] [blame] | 36 | SkASSERT(canIgnoreRect || (rect->fLeft <= rect->fRight && rect->fTop <= rect->fBottom)); |
joshualitt | 36ec383 | 2015-05-26 09:33:48 -0700 | [diff] [blame] | 37 | |
joshualitt | e46760e | 2015-05-05 08:41:50 -0700 | [diff] [blame] | 38 | Clear* clr = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), Clear, (renderTarget)); |
| 39 | GrColorIsPMAssert(color); |
| 40 | clr->fColor = color; |
| 41 | clr->fRect = *rect; |
| 42 | clr->fCanIgnoreRect = canIgnoreRect; |
| 43 | return clr; |
| 44 | } |
| 45 | |
| 46 | GrTargetCommands::Cmd* GrCommandBuilder::recordClearStencilClip(const SkIRect& rect, |
| 47 | bool insideClip, |
| 48 | GrRenderTarget* renderTarget) { |
| 49 | SkASSERT(renderTarget); |
| 50 | |
| 51 | ClearStencilClip* clr = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), |
| 52 | ClearStencilClip, |
| 53 | (renderTarget)); |
| 54 | clr->fRect = rect; |
| 55 | clr->fInsideClip = insideClip; |
| 56 | return clr; |
| 57 | } |
| 58 | |
| 59 | GrTargetCommands::Cmd* GrCommandBuilder::recordDiscard(GrRenderTarget* renderTarget) { |
| 60 | SkASSERT(renderTarget); |
| 61 | |
| 62 | Clear* clr = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), Clear, (renderTarget)); |
| 63 | clr->fColor = GrColor_ILLEGAL; |
| 64 | return clr; |
| 65 | } |
| 66 | |
| 67 | GrTargetCommands::Cmd* GrCommandBuilder::recordCopySurface(GrSurface* dst, |
| 68 | GrSurface* src, |
| 69 | const SkIRect& srcRect, |
| 70 | const SkIPoint& dstPoint) { |
| 71 | CopySurface* cs = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), CopySurface, (dst, src)); |
| 72 | cs->fSrcRect = srcRect; |
| 73 | cs->fDstPoint = dstPoint; |
| 74 | return cs; |
| 75 | } |
| 76 | |
| 77 | GrTargetCommands::Cmd* |
| 78 | GrCommandBuilder::recordXferBarrierIfNecessary(const GrPipeline& pipeline, |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 79 | const GrCaps& caps) { |
joshualitt | e46760e | 2015-05-05 08:41:50 -0700 | [diff] [blame] | 80 | const GrXferProcessor& xp = *pipeline.getXferProcessor(); |
| 81 | GrRenderTarget* rt = pipeline.getRenderTarget(); |
| 82 | |
| 83 | GrXferBarrierType barrierType; |
| 84 | if (!xp.willNeedXferBarrier(rt, caps, &barrierType)) { |
| 85 | return NULL; |
| 86 | } |
| 87 | |
cdalton | 231c5fd | 2015-05-13 12:35:36 -0700 | [diff] [blame] | 88 | XferBarrier* xb = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), XferBarrier, (rt)); |
joshualitt | e46760e | 2015-05-05 08:41:50 -0700 | [diff] [blame] | 89 | xb->fBarrierType = barrierType; |
| 90 | return xb; |
| 91 | } |