1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2017 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#ifndef StencilClip_DEFINED 9cb93a386Sopenharmony_ci#define StencilClip_DEFINED 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci#include "src/gpu/GrAppliedClip.h" 12cb93a386Sopenharmony_ci#include "src/gpu/GrFixedClip.h" 13cb93a386Sopenharmony_ci 14cb93a386Sopenharmony_cinamespace skgpu::v1 { 15cb93a386Sopenharmony_ci 16cb93a386Sopenharmony_ci/** 17cb93a386Sopenharmony_ci * Implements GrHardClip with the currently-existing stencil buffer contents and GrFixedClip. 18cb93a386Sopenharmony_ci */ 19cb93a386Sopenharmony_ciclass StencilClip final : public GrHardClip { 20cb93a386Sopenharmony_cipublic: 21cb93a386Sopenharmony_ci explicit StencilClip(const SkISize& rtDims, uint32_t stencilStackID = SK_InvalidGenID) 22cb93a386Sopenharmony_ci : fFixedClip(rtDims) 23cb93a386Sopenharmony_ci , fStencilStackID(stencilStackID) {} 24cb93a386Sopenharmony_ci 25cb93a386Sopenharmony_ci StencilClip(const SkISize& rtDims, 26cb93a386Sopenharmony_ci const SkIRect& scissorRect, 27cb93a386Sopenharmony_ci uint32_t stencilStackID = SK_InvalidGenID) 28cb93a386Sopenharmony_ci : fFixedClip(rtDims, scissorRect) 29cb93a386Sopenharmony_ci , fStencilStackID(stencilStackID) {} 30cb93a386Sopenharmony_ci 31cb93a386Sopenharmony_ci const GrFixedClip& fixedClip() const { return fFixedClip; } 32cb93a386Sopenharmony_ci GrFixedClip& fixedClip() { return fFixedClip; } 33cb93a386Sopenharmony_ci 34cb93a386Sopenharmony_ci uint32_t stencilStackID() const { return fStencilStackID; } 35cb93a386Sopenharmony_ci bool hasStencilClip() const { return SK_InvalidGenID != fStencilStackID; } 36cb93a386Sopenharmony_ci void setStencilClip(uint32_t stencilStackID) { fStencilStackID = stencilStackID; } 37cb93a386Sopenharmony_ci 38cb93a386Sopenharmony_ci SkIRect getConservativeBounds() const final { 39cb93a386Sopenharmony_ci return fFixedClip.getConservativeBounds(); 40cb93a386Sopenharmony_ci } 41cb93a386Sopenharmony_ci 42cb93a386Sopenharmony_ci Effect apply(GrAppliedHardClip* out, SkIRect* bounds) const final { 43cb93a386Sopenharmony_ci Effect effect = fFixedClip.apply(out, bounds); 44cb93a386Sopenharmony_ci if (effect == Effect::kClippedOut) { 45cb93a386Sopenharmony_ci // Stencil won't bring back coverage 46cb93a386Sopenharmony_ci return Effect::kClippedOut; 47cb93a386Sopenharmony_ci } 48cb93a386Sopenharmony_ci if (this->hasStencilClip()) { 49cb93a386Sopenharmony_ci out->addStencilClip(fStencilStackID); 50cb93a386Sopenharmony_ci effect = Effect::kClipped; 51cb93a386Sopenharmony_ci } 52cb93a386Sopenharmony_ci return effect; 53cb93a386Sopenharmony_ci } 54cb93a386Sopenharmony_ci 55cb93a386Sopenharmony_ci PreClipResult preApply(const SkRect& drawBounds, GrAA aa) const final { 56cb93a386Sopenharmony_ci if (this->hasStencilClip()) { 57cb93a386Sopenharmony_ci return this->INHERITED::preApply(drawBounds, aa); 58cb93a386Sopenharmony_ci } else { 59cb93a386Sopenharmony_ci return fFixedClip.preApply(drawBounds, aa); 60cb93a386Sopenharmony_ci } 61cb93a386Sopenharmony_ci } 62cb93a386Sopenharmony_ci 63cb93a386Sopenharmony_ciprivate: 64cb93a386Sopenharmony_ci GrFixedClip fFixedClip; 65cb93a386Sopenharmony_ci uint32_t fStencilStackID; 66cb93a386Sopenharmony_ci 67cb93a386Sopenharmony_ci using INHERITED = GrClip; 68cb93a386Sopenharmony_ci}; 69cb93a386Sopenharmony_ci 70cb93a386Sopenharmony_ci} // namespace skgpu::v1 71cb93a386Sopenharmony_ci 72cb93a386Sopenharmony_ci#endif // StencilClip_DEFINED 73