| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrClearBatch_DEFINED | 8 #ifndef GrClearBatch_DEFINED |
| 9 #define GrClearBatch_DEFINED | 9 #define GrClearBatch_DEFINED |
| 10 | 10 |
| 11 #include "GrBatch.h" | 11 #include "GrBatch.h" |
| 12 #include "GrBatchFlushState.h" | 12 #include "GrBatchFlushState.h" |
| 13 #include "GrFixedClip.h" | 13 #include "GrFixedClip.h" |
| 14 #include "GrGpu.h" | 14 #include "GrGpu.h" |
| 15 #include "GrGpuCommandBuffer.h" | 15 #include "GrGpuCommandBuffer.h" |
| 16 #include "GrRenderTarget.h" | 16 #include "GrRenderTarget.h" |
| 17 | 17 |
| 18 class GrClearBatch final : public GrBatch { | 18 class GrClearBatch final : public GrBatch { |
| 19 public: | 19 public: |
| 20 DEFINE_BATCH_CLASS_ID | 20 DEFINE_BATCH_CLASS_ID |
| 21 | 21 |
| 22 static sk_sp<GrClearBatch> Make(const GrFixedClip& clip, GrColor color, GrRe
nderTarget* rt) { | 22 static sk_sp<GrClearBatch> Make(const GrFixedClip& clip, GrColor color, GrRe
nderTargetProxy* rtp) { |
| 23 sk_sp<GrClearBatch> batch(new GrClearBatch(clip, color, rt)); | 23 sk_sp<GrClearBatch> batch(new GrClearBatch(clip, color, rtp)); |
| 24 if (!batch->renderTarget()) { | 24 if (!batch->rtp()) { |
| 25 return nullptr; // The clip did not contain any pixels within the re
nder target. | 25 return nullptr; // The clip did not contain any pixels within the re
nder target. |
| 26 } | 26 } |
| 27 return batch; | 27 return batch; |
| 28 } | 28 } |
| 29 | 29 |
| 30 const char* name() const override { return "Clear"; } | 30 const char* name() const override { return "Clear"; } |
| 31 | 31 |
| 32 uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()-
>uniqueID(); } | 32 uint32_t renderTargetUniqueID() const override { return fRenderTargetProxy.g
et()->uniqueID(); } |
| 33 GrRenderTarget* renderTarget() const override { return fRenderTarget.get();
} | 33 GrRenderTargetProxy* rtp() const override { return fRenderTargetProxy.get();
} |
| 34 | 34 |
| 35 SkString dumpInfo() const override { | 35 SkString dumpInfo() const override { |
| 36 SkString string("Scissor ["); | 36 SkString string("Scissor ["); |
| 37 if (fClip.scissorEnabled()) { | 37 if (fClip.scissorEnabled()) { |
| 38 const SkIRect& r = fClip.scissorRect(); | 38 const SkIRect& r = fClip.scissorRect(); |
| 39 string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRig
ht, r.fBottom); | 39 string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRig
ht, r.fBottom); |
| 40 } | 40 } |
| 41 string.appendf("], Color: 0x%08x, RT: %d", fColor, fRenderTarget.get()->
uniqueID()); | 41 string.appendf("], Color: 0x%08x, RT: %d", fColor, fRenderTargetProxy.ge
t()->uniqueID()); |
| 42 string.append(INHERITED::dumpInfo()); | 42 string.append(INHERITED::dumpInfo()); |
| 43 return string; | 43 return string; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void setColor(GrColor color) { fColor = color; } | 46 void setColor(GrColor color) { fColor = color; } |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 GrClearBatch(const GrFixedClip& clip, GrColor color, GrRenderTarget* rt) | 49 GrClearBatch(const GrFixedClip& clip, GrColor color, GrRenderTargetProxy* rt
p) |
| 50 : INHERITED(ClassID()) | 50 : INHERITED(ClassID()) |
| 51 , fClip(clip) | 51 , fClip(clip) |
| 52 , fColor(color) { | 52 , fColor(color) { |
| 53 SkIRect rtRect = SkIRect::MakeWH(rt->width(), rt->height()); | 53 SkIRect rtRect = SkIRect::MakeWH(rtp->width(), rtp->height()); |
| 54 if (fClip.scissorEnabled()) { | 54 if (fClip.scissorEnabled()) { |
| 55 // Don't let scissors extend outside the RT. This may improve batchi
ng. | 55 // Don't let scissors extend outside the RT. This may improve batchi
ng. |
| 56 if (!fClip.intersect(rtRect)) { | 56 if (!fClip.intersect(rtRect)) { |
| 57 return; | 57 return; |
| 58 } | 58 } |
| 59 if (fClip.scissorRect() == rtRect) { | 59 if (fClip.scissorRect() == rtRect) { |
| 60 fClip.disableScissor(); | 60 fClip.disableScissor(); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 this->setBounds(SkRect::Make(fClip.scissorEnabled() ? fClip.scissorRect(
) : rtRect), | 63 this->setBounds(SkRect::Make(fClip.scissorEnabled() ? fClip.scissorRect(
) : rtRect), |
| 64 HasAABloat::kNo, IsZeroArea::kNo); | 64 HasAABloat::kNo, IsZeroArea::kNo); |
| 65 fRenderTarget.reset(rt); | 65 fRenderTargetProxy.reset(rtp); |
| 66 } | 66 } |
| 67 | 67 |
| 68 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 68 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
| 69 // This could be much more complicated. Currently we look at cases where
the new clear | 69 // This could be much more complicated. Currently we look at cases where
the new clear |
| 70 // contains the old clear, or when the new clear is a subset of the old
clear and is the | 70 // contains the old clear, or when the new clear is a subset of the old
clear and is the |
| 71 // same color. | 71 // same color. |
| 72 GrClearBatch* cb = t->cast<GrClearBatch>(); | 72 GrClearBatch* cb = t->cast<GrClearBatch>(); |
| 73 SkASSERT(cb->fRenderTarget == fRenderTarget); | 73 SkASSERT(cb->fRenderTargetProxy == fRenderTargetProxy); |
| 74 if (!fClip.windowRectsState().cheapEqualTo(cb->fClip.windowRectsState())
) { | 74 if (!fClip.windowRectsState().cheapEqualTo(cb->fClip.windowRectsState())
) { |
| 75 return false; | 75 return false; |
| 76 } | 76 } |
| 77 if (cb->contains(this)) { | 77 if (cb->contains(this)) { |
| 78 fClip = cb->fClip; | 78 fClip = cb->fClip; |
| 79 this->replaceBounds(*t); | 79 this->replaceBounds(*t); |
| 80 fColor = cb->fColor; | 80 fColor = cb->fColor; |
| 81 return true; | 81 return true; |
| 82 } else if (cb->fColor == fColor && this->contains(cb)) { | 82 } else if (cb->fColor == fColor && this->contains(cb)) { |
| 83 return true; | 83 return true; |
| 84 } | 84 } |
| 85 return false; | 85 return false; |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool contains(const GrClearBatch* that) const { | 88 bool contains(const GrClearBatch* that) const { |
| 89 // The constructor ensures that scissor gets disabled on any clip that f
ills the entire RT. | 89 // The constructor ensures that scissor gets disabled on any clip that f
ills the entire RT. |
| 90 return !fClip.scissorEnabled() || | 90 return !fClip.scissorEnabled() || |
| 91 (that->fClip.scissorEnabled() && | 91 (that->fClip.scissorEnabled() && |
| 92 fClip.scissorRect().contains(that->fClip.scissorRect())); | 92 fClip.scissorRect().contains(that->fClip.scissorRect())); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void onPrepare(GrBatchFlushState*) override {} | 95 void onPrepare(GrBatchFlushState*) override {} |
| 96 | 96 |
| 97 void onDraw(GrBatchFlushState* state, const SkRect& /*bounds*/) override { | 97 void onDraw(GrBatchFlushState* state, const SkRect& /*bounds*/) override { |
| 98 state->commandBuffer()->clear(fClip, fColor); | 98 state->commandBuffer()->clear(fClip, fColor); |
| 99 } | 99 } |
| 100 | 100 |
| 101 GrFixedClip fClip; | 101 GrFixedClip fClip; |
| 102 GrColor fColor; | 102 GrColor fColor; |
| 103 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | 103 GrPendingIOResource<GrRenderTargetProxy, kWrite_GrIOType> fRenderTargetPr
oxy; |
| 104 | 104 |
| 105 typedef GrBatch INHERITED; | 105 typedef GrBatch INHERITED; |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 #endif | 108 #endif |
| OLD | NEW |