Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017 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 GrStencilClip_DEFINED |
| 9 | #define GrStencilClip_DEFINED |
| 10 | |
| 11 | #include "GrAppliedClip.h" |
| 12 | #include "GrFixedClip.h" |
| 13 | |
| 14 | /** |
| 15 | * Implements GrHardClip with the currently-existing stencil buffer contents and GrFixedClip. |
| 16 | */ |
| 17 | class GrStencilClip final : public GrHardClip { |
| 18 | public: |
| 19 | GrStencilClip(uint32_t stencilStackID = SK_InvalidGenID) : fStencilStackID(stencilStackID) {} |
| 20 | |
| 21 | explicit GrStencilClip(const SkIRect& scissorRect, uint32_t stencilStackID = SK_InvalidGenID) |
| 22 | : fFixedClip(scissorRect) |
| 23 | , fStencilStackID(stencilStackID) { |
| 24 | } |
| 25 | |
| 26 | const GrFixedClip& fixedClip() const { return fFixedClip; } |
| 27 | GrFixedClip& fixedClip() { return fFixedClip; } |
| 28 | |
| 29 | bool stencilStackID() const { return fStencilStackID; } |
| 30 | bool hasStencilClip() const { return SK_InvalidGenID != fStencilStackID; } |
| 31 | void setStencilClip(uint32_t stencilStackID) { fStencilStackID = stencilStackID; } |
| 32 | |
| 33 | bool quickContains(const SkRect& rect) const override { |
| 34 | return !this->hasStencilClip() && fFixedClip.quickContains(rect); |
| 35 | } |
| 36 | void getConservativeBounds(int width, int height, SkIRect* bounds, bool* iior) const override { |
| 37 | fFixedClip.getConservativeBounds(width, height, bounds, iior); |
| 38 | } |
| 39 | bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA* aa) const override { |
| 40 | return !this->hasStencilClip() && fFixedClip.isRRect(rtBounds, rr, aa); |
| 41 | } |
| 42 | bool apply(int rtWidth, int rtHeight, GrAppliedHardClip* out, SkRect* bounds) const override { |
| 43 | if (!fFixedClip.apply(rtWidth, rtHeight, out, bounds)) { |
| 44 | return false; |
| 45 | } |
| 46 | if (this->hasStencilClip()) { |
| 47 | out->addStencilClip(fStencilStackID); |
| 48 | } |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | private: |
| 53 | GrFixedClip fFixedClip; |
| 54 | uint32_t fStencilStackID; |
| 55 | |
| 56 | typedef GrClip INHERITED; |
| 57 | }; |
| 58 | |
| 59 | #endif |