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 "src/gpu/GrFixedClip.h"
9
10#include "src/gpu/GrAppliedClip.h"
11#include "src/gpu/GrRenderTargetContext.h"
12
13bool 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
20void 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
32bool 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
48bool GrFixedClip::apply(int rtWidth, int rtHeight, GrAppliedHardClip* out, SkRect* bounds) const {
49 if (fScissorState.enabled()) {
50 SkIRect tightScissor = SkIRect::MakeWH(rtWidth, rtHeight);
51 if (!tightScissor.intersect(fScissorState.rect())) {
52 return false;
53 }
54 if (IsOutsideClip(tightScissor, *bounds)) {
55 return false;
56 }
57 if (!IsInsideClip(fScissorState.rect(), *bounds)) {
58 out->addScissor(tightScissor, bounds);
59 }
60 }
61
62 if (fWindowRectsState.enabled()) {
63 out->addWindowRectangles(fWindowRectsState);
64 }
65
66 return true;
67}
68
69const GrFixedClip& GrFixedClip::Disabled() {
70 static const GrFixedClip disabled = GrFixedClip();
71 return disabled;
72}
73