| 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 "GrGpu.h" | 14 #include "GrGpu.h" |
| 14 #include "GrGpuCommandBuffer.h" | 15 #include "GrGpuCommandBuffer.h" |
| 15 #include "GrRenderTarget.h" | 16 #include "GrRenderTarget.h" |
| 16 | 17 |
| 17 class GrClearBatch final : public GrBatch { | 18 class GrClearBatch final : public GrBatch { |
| 18 public: | 19 public: |
| 19 DEFINE_BATCH_CLASS_ID | 20 DEFINE_BATCH_CLASS_ID |
| 20 | 21 |
| 21 static sk_sp<GrClearBatch> Make(const SkIRect& rect, GrColor color, GrRende
rTarget* rt) { | 22 static sk_sp<GrClearBatch> Make(const GrFixedClip& clip, GrColor color, GrRe
nderTarget* rt) { |
| 22 return sk_sp<GrClearBatch>(new GrClearBatch(rect, color, rt)); | 23 sk_sp<GrClearBatch> batch(new GrClearBatch(clip, color, rt)); |
| 24 if (!batch->renderTarget()) { |
| 25 return nullptr; // The clip did not contain any pixels within the re
nder target. |
| 26 } |
| 27 return batch; |
| 23 } | 28 } |
| 24 | 29 |
| 25 const char* name() const override { return "Clear"; } | 30 const char* name() const override { return "Clear"; } |
| 26 | 31 |
| 27 uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()-
>getUniqueID(); } | 32 uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()-
>getUniqueID(); } |
| 28 GrRenderTarget* renderTarget() const override { return fRenderTarget.get();
} | 33 GrRenderTarget* renderTarget() const override { return fRenderTarget.get();
} |
| 29 | 34 |
| 30 SkString dumpInfo() const override { | 35 SkString dumpInfo() const override { |
| 31 SkString string; | 36 SkString string("Scissor ["); |
| 32 string.printf("Color: 0x%08x, Rect [L: %d, T: %d, R: %d, B: %d], RT: %d"
, | 37 if (fClip.scissorEnabled()) { |
| 33 fColor, fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBott
om, | 38 const SkIRect& r = fClip.scissorRect(); |
| 34 fRenderTarget.get()->getUniqueID()); | 39 string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRig
ht, r.fBottom); |
| 40 } |
| 41 string.appendf("], Color: 0x%08x, RT: %d", fColor, fRenderTarget.get()->
getUniqueID()); |
| 35 string.append(INHERITED::dumpInfo()); | 42 string.append(INHERITED::dumpInfo()); |
| 36 return string; | 43 return string; |
| 37 } | 44 } |
| 38 | 45 |
| 39 void setColor(GrColor color) { fColor = color; } | 46 void setColor(GrColor color) { fColor = color; } |
| 40 | 47 |
| 41 private: | 48 private: |
| 42 GrClearBatch(const SkIRect& rect, GrColor color, GrRenderTarget* rt) | 49 GrClearBatch(const GrFixedClip& clip, GrColor color, GrRenderTarget* rt) |
| 43 : INHERITED(ClassID()) | 50 : INHERITED(ClassID()) |
| 44 , fRect(rect) | 51 , fClip(clip) |
| 45 , fColor(color) | 52 , fColor(color) { |
| 46 , fRenderTarget(rt) { | 53 SkIRect rtRect = SkIRect::MakeWH(rt->width(), rt->height()); |
| 47 this->setBounds(SkRect::Make(rect), HasAABloat::kNo, IsZeroArea::kNo); | 54 if (fClip.scissorEnabled()) { |
| 55 // Don't let scissors extend outside the RT. This may improve batchi
ng. |
| 56 if (!fClip.intersect(rtRect)) { |
| 57 return; |
| 58 } |
| 59 if (fClip.scissorRect() == rtRect) { |
| 60 fClip.disableScissor(); |
| 61 } |
| 62 } |
| 63 this->setBounds(SkRect::Make(fClip.scissorEnabled() ? fClip.scissorRect(
) : rtRect), |
| 64 HasAABloat::kNo, IsZeroArea::kNo); |
| 65 fRenderTarget.reset(rt); |
| 48 } | 66 } |
| 49 | 67 |
| 50 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 68 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
| 51 // 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 |
| 52 // 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 |
| 53 // same color. | 71 // same color. |
| 54 GrClearBatch* cb = t->cast<GrClearBatch>(); | 72 GrClearBatch* cb = t->cast<GrClearBatch>(); |
| 55 SkASSERT(cb->fRenderTarget == fRenderTarget); | 73 SkASSERT(cb->fRenderTarget == fRenderTarget); |
| 56 if (cb->fRect.contains(fRect)) { | 74 if (cb->contains(this)) { |
| 57 fRect = cb->fRect; | 75 fClip = cb->fClip; |
| 58 this->replaceBounds(*t); | 76 this->replaceBounds(*t); |
| 59 fColor = cb->fColor; | 77 fColor = cb->fColor; |
| 60 return true; | 78 return true; |
| 61 } else if (cb->fColor == fColor && fRect.contains(cb->fRect)) { | 79 } else if (cb->fColor == fColor && this->contains(cb)) { |
| 62 return true; | 80 return true; |
| 63 } | 81 } |
| 64 return false; | 82 return false; |
| 65 } | 83 } |
| 66 | 84 |
| 85 bool contains(const GrClearBatch* that) const { |
| 86 // The constructor ensures that scissor gets disabled on any clip that f
ills the entire RT. |
| 87 return !fClip.scissorEnabled() || |
| 88 (that->fClip.scissorEnabled() && |
| 89 fClip.scissorRect().contains(that->fClip.scissorRect())); |
| 90 } |
| 91 |
| 67 void onPrepare(GrBatchFlushState*) override {} | 92 void onPrepare(GrBatchFlushState*) override {} |
| 68 | 93 |
| 69 void onDraw(GrBatchFlushState* state) override { | 94 void onDraw(GrBatchFlushState* state) override { |
| 70 state->commandBuffer()->clear(fRect, fColor, fRenderTarget.get()); | 95 state->commandBuffer()->clear(fClip, fColor, fRenderTarget.get()); |
| 71 } | 96 } |
| 72 | 97 |
| 73 SkIRect fRect; | 98 GrFixedClip fClip; |
| 74 GrColor fColor; | 99 GrColor fColor; |
| 75 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | 100 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
| 76 | 101 |
| 77 typedef GrBatch INHERITED; | 102 typedef GrBatch INHERITED; |
| 78 }; | 103 }; |
| 79 | 104 |
| 80 #endif | 105 #endif |
| OLD | NEW |