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 "src/gpu/GrClip.h" 12 #include "src/gpu/GrScissorState.h" 13 #include "src/gpu/GrWindowRectsState.h" 14 15 /** 16 * Implements GrHardClip with scissor and window rectangles. 17 */ 18 class GrFixedClip final : public GrHardClip { 19 public: 20 GrFixedClip() = default; GrFixedClip(const SkIRect & scissorRect)21 explicit GrFixedClip(const SkIRect& scissorRect) : fScissorState(scissorRect) {} 22 scissorState()23 const GrScissorState& scissorState() const { return fScissorState; } scissorEnabled()24 bool scissorEnabled() const { return fScissorState.enabled(); } scissorRect()25 const SkIRect& scissorRect() const { SkASSERT(scissorEnabled()); return fScissorState.rect(); } 26 disableScissor()27 void disableScissor() { fScissorState.setDisabled(); } 28 setScissor(const SkIRect & irect)29 void setScissor(const SkIRect& irect) { 30 fScissorState.set(irect); 31 } intersect(const SkIRect & irect)32 bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& irect) { 33 return fScissorState.intersect(irect); 34 } 35 windowRectsState()36 const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; } hasWindowRectangles()37 bool hasWindowRectangles() const { return fWindowRectsState.enabled(); } 38 disableWindowRectangles()39 void disableWindowRectangles() { fWindowRectsState.setDisabled(); } 40 setWindowRectangles(const GrWindowRectangles & windows,GrWindowRectsState::Mode mode)41 void setWindowRectangles(const GrWindowRectangles& windows, GrWindowRectsState::Mode mode) { 42 fWindowRectsState.set(windows, mode); 43 } 44 45 bool quickContains(const SkRect&) const override; 46 void getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const override; 47 bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const override; 48 bool apply(int rtWidth, int rtHeight, GrAppliedHardClip*, SkRect*) const override; 49 50 static const GrFixedClip& Disabled(); 51 52 private: 53 GrScissorState fScissorState; 54 GrWindowRectsState fWindowRectsState; 55 }; 56 57 #endif 58