GrClearOp.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #ifndef GrClearOp_DEFINED
  8. #define GrClearOp_DEFINED
  9. #include "src/gpu/GrFixedClip.h"
  10. #include "src/gpu/ops/GrOp.h"
  11. class GrOpFlushState;
  12. class GrRecordingContext;
  13. class GrClearOp final : public GrOp {
  14. public:
  15. DEFINE_OP_CLASS_ID
  16. static std::unique_ptr<GrClearOp> Make(GrRecordingContext* context,
  17. const GrFixedClip& clip,
  18. const SkPMColor4f& color,
  19. GrSurfaceProxy* dstProxy);
  20. static std::unique_ptr<GrClearOp> Make(GrRecordingContext* context,
  21. const SkIRect& rect,
  22. const SkPMColor4f& color,
  23. bool fullScreen);
  24. const char* name() const override { return "Clear"; }
  25. #ifdef SK_DEBUG
  26. SkString dumpInfo() const override {
  27. SkString string;
  28. string.append(INHERITED::dumpInfo());
  29. string.appendf("Scissor [ ");
  30. if (fClip.scissorEnabled()) {
  31. const SkIRect& r = fClip.scissorRect();
  32. string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom);
  33. } else {
  34. string.append("disabled");
  35. }
  36. string.appendf("], Color: 0x%08x\n", fColor.toBytes_RGBA());
  37. return string;
  38. }
  39. #endif
  40. const SkPMColor4f& color() const { return fColor; }
  41. void setColor(const SkPMColor4f& color) { fColor = color; }
  42. private:
  43. friend class GrOpMemoryPool; // for ctors
  44. GrClearOp(const GrFixedClip& clip, const SkPMColor4f& color, GrSurfaceProxy* proxy);
  45. GrClearOp(const SkIRect& rect, const SkPMColor4f& color, bool fullScreen)
  46. : INHERITED(ClassID())
  47. , fClip(GrFixedClip(rect))
  48. , fColor(color) {
  49. if (fullScreen) {
  50. fClip.disableScissor();
  51. }
  52. this->setBounds(SkRect::Make(rect), HasAABloat::kNo, IsZeroArea::kNo);
  53. }
  54. CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
  55. // This could be much more complicated. Currently we look at cases where the new clear
  56. // contains the old clear, or when the new clear is a subset of the old clear and is the
  57. // same color.
  58. GrClearOp* cb = t->cast<GrClearOp>();
  59. if (fClip.windowRectsState() != cb->fClip.windowRectsState()) {
  60. return CombineResult::kCannotCombine;
  61. }
  62. if (cb->contains(this)) {
  63. fClip = cb->fClip;
  64. fColor = cb->fColor;
  65. return CombineResult::kMerged;
  66. } else if (cb->fColor == fColor && this->contains(cb)) {
  67. return CombineResult::kMerged;
  68. }
  69. return CombineResult::kCannotCombine;
  70. }
  71. bool contains(const GrClearOp* that) const {
  72. // The constructor ensures that scissor gets disabled on any clip that fills the entire RT.
  73. return !fClip.scissorEnabled() ||
  74. (that->fClip.scissorEnabled() &&
  75. fClip.scissorRect().contains(that->fClip.scissorRect()));
  76. }
  77. void onPrepare(GrOpFlushState*) override {}
  78. void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override;
  79. GrFixedClip fClip;
  80. SkPMColor4f fColor;
  81. typedef GrOp INHERITED;
  82. };
  83. #endif