1 /* 2 * Copyright 2016 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 #ifndef GrFixedClip_DEFINED 9 #define GrFixedClip_DEFINED 10 11 #include "include/core/SkRect.h" 12 #include "include/private/base/SkAssert.h" 13 #include "src/gpu/ganesh/GrClip.h" 14 #include "src/gpu/ganesh/GrScissorState.h" 15 #include "src/gpu/ganesh/GrWindowRectsState.h" 16 17 class GrAppliedHardClip; 18 class GrWindowRectangles; 19 enum class GrAA : bool; 20 struct SkISize; 21 22 /** 23 * Implements GrHardClip with scissor and window rectangles. 24 */ 25 class GrFixedClip final : public GrHardClip { 26 public: GrFixedClip(const SkISize & rtDims)27 explicit GrFixedClip(const SkISize& rtDims) : fScissorState(rtDims) {} GrFixedClip(const SkISize & rtDims,const SkIRect & scissorRect)28 GrFixedClip(const SkISize& rtDims, const SkIRect& scissorRect) 29 : GrFixedClip(rtDims) { 30 SkAssertResult(fScissorState.set(scissorRect)); 31 } 32 scissorState()33 const GrScissorState& scissorState() const { return fScissorState; } scissorEnabled()34 bool scissorEnabled() const { return fScissorState.enabled(); } 35 // Returns the scissor rect or rt bounds if the scissor test is not enabled. scissorRect()36 const SkIRect& scissorRect() const { return fScissorState.rect(); } 37 disableScissor()38 void disableScissor() { fScissorState.setDisabled(); } 39 setScissor(const SkIRect & irect)40 [[nodiscard]] bool setScissor(const SkIRect& irect) { 41 return fScissorState.set(irect); 42 } intersect(const SkIRect & irect)43 [[nodiscard]] bool intersect(const SkIRect& irect) { 44 return fScissorState.intersect(irect); 45 } 46 windowRectsState()47 const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; } hasWindowRectangles()48 bool hasWindowRectangles() const { return fWindowRectsState.enabled(); } 49 disableWindowRectangles()50 void disableWindowRectangles() { fWindowRectsState.setDisabled(); } 51 setWindowRectangles(const GrWindowRectangles & windows,GrWindowRectsState::Mode mode)52 void setWindowRectangles(const GrWindowRectangles& windows, GrWindowRectsState::Mode mode) { 53 fWindowRectsState.set(windows, mode); 54 } 55 56 SkIRect getConservativeBounds() const final; 57 Effect apply(GrAppliedHardClip*, SkIRect*) const final; 58 PreClipResult preApply(const SkRect& drawBounds, GrAA aa) const final; 59 60 private: 61 GrScissorState fScissorState; 62 GrWindowRectsState fWindowRectsState; 63 }; 64 65 #endif 66