1 /*
2 * Copyright 2010 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 #include "GrFixedClip.h"
9
10 #include "GrAppliedClip.h"
11 #include "GrRenderTargetContext.h"
12
quickContains(const SkRect & rect) const13 bool GrFixedClip::quickContains(const SkRect& rect) const {
14 if (fWindowRectsState.enabled()) {
15 return false;
16 }
17 return !fScissorState.enabled() || GrClip::IsInsideClip(fScissorState.rect(), rect);
18 }
19
getConservativeBounds(int w,int h,SkIRect * devResult,bool * iior) const20 void GrFixedClip::getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const {
21 devResult->setXYWH(0, 0, w, h);
22 if (fScissorState.enabled()) {
23 if (!devResult->intersect(fScissorState.rect())) {
24 devResult->setEmpty();
25 }
26 }
27 if (iior) {
28 *iior = true;
29 }
30 }
31
isRRect(const SkRect & rtBounds,SkRRect * rr,GrAA * aa) const32 bool GrFixedClip::isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA* aa) const {
33 if (fWindowRectsState.enabled()) {
34 return false;
35 }
36 if (fScissorState.enabled()) {
37 SkRect rect = SkRect::Make(fScissorState.rect());
38 if (!rect.intersects(rtBounds)) {
39 return false;
40 }
41 rr->setRect(rect);
42 *aa = GrAA::kNo;
43 return true;
44 }
45 return false;
46 };
47
apply(GrContext *,GrRenderTargetContext * rtc,bool,bool,GrAppliedClip * out,SkRect * bounds) const48 bool GrFixedClip::apply(GrContext*, GrRenderTargetContext* rtc, bool, bool, GrAppliedClip* out,
49 SkRect* bounds) const {
50 if (fScissorState.enabled()) {
51 SkIRect tightScissor = SkIRect::MakeWH(rtc->width(), rtc->height());
52 if (!tightScissor.intersect(fScissorState.rect())) {
53 return false;
54 }
55 if (IsOutsideClip(tightScissor, *bounds)) {
56 return false;
57 }
58 if (!IsInsideClip(fScissorState.rect(), *bounds)) {
59 out->addScissor(tightScissor, bounds);
60 }
61 }
62
63 if (fWindowRectsState.enabled()) {
64 out->addWindowRectangles(fWindowRectsState);
65 }
66
67 return true;
68 }
69
Disabled()70 const GrFixedClip& GrFixedClip::Disabled() {
71 static const GrFixedClip disabled = GrFixedClip();
72 return disabled;
73 }
74