Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
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 */
8 #ifndef SkRasterClip_DEFINED
9 #define SkRasterClip_DEFINED
11 #include "SkRegion.h"
12 #include "SkAAClip.h"
14 class SkRasterClip {
15 public:
16 SkRasterClip();
17 SkRasterClip(const SkIRect&);
18 SkRasterClip(const SkRasterClip&);
19 ~SkRasterClip();
21 bool isBW() const { return fIsBW; }
22 bool isAA() const { return !fIsBW; }
23 const SkRegion& bwRgn() const { SkASSERT(fIsBW); return fBW; }
24 const SkAAClip& aaRgn() const { SkASSERT(!fIsBW); return fAA; }
26 bool isEmpty() const {
27 SkASSERT(this->computeIsEmpty() == fIsEmpty);
28 return fIsEmpty;
29 }
31 bool isRect() const {
32 SkASSERT(this->computeIsRect() == fIsRect);
33 return fIsRect;
34 }
36 bool isComplex() const;
37 const SkIRect& getBounds() const;
39 bool setEmpty();
40 bool setRect(const SkIRect&);
42 bool setPath(const SkPath& path, const SkRegion& clip, bool doAA);
43 bool setPath(const SkPath& path, const SkIRect& clip, bool doAA);
45 bool op(const SkIRect&, SkRegion::Op);
46 bool op(const SkRegion&, SkRegion::Op);
47 bool op(const SkRasterClip&, SkRegion::Op);
48 bool op(const SkRect&, SkRegion::Op, bool doAA);
50 void translate(int dx, int dy, SkRasterClip* dst) const;
51 void translate(int dx, int dy) {
52 this->translate(dx, dy, this);
53 }
55 bool quickContains(const SkIRect& rect) const;
56 bool quickContains(int left, int top, int right, int bottom) const {
57 return quickContains(SkIRect::MakeLTRB(left, top, right, bottom));
58 }
60 /**
61 * Return true if this region is empty, or if the specified rectangle does
62 * not intersect the region. Returning false is not a guarantee that they
63 * intersect, but returning true is a guarantee that they do not.
64 */
65 bool quickReject(const SkIRect& rect) const {
66 return this->isEmpty() || rect.isEmpty() ||
67 !SkIRect::Intersects(this->getBounds(), rect);
68 }
70 // hack for SkCanvas::getTotalClip
71 const SkRegion& forceGetBW();
73 #ifdef SK_DEBUG
74 void validate() const;
75 #else
76 void validate() const {}
77 #endif
79 private:
80 SkRegion fBW;
81 SkAAClip fAA;
82 bool fIsBW;
83 // these 2 are caches based on querying the right obj based on fIsBW
84 bool fIsEmpty;
85 bool fIsRect;
87 bool computeIsEmpty() const {
88 return fIsBW ? fBW.isEmpty() : fAA.isEmpty();
89 }
91 bool computeIsRect() const {
92 return fIsBW ? fBW.isRect() : false;
93 }
95 bool updateCacheAndReturnNonEmpty() {
96 fIsEmpty = this->computeIsEmpty();
97 fIsRect = this->computeIsRect();
98 return !fIsEmpty;
99 }
101 void convertToAA();
102 };
104 class SkAutoRasterClipValidate : SkNoncopyable {
105 public:
106 SkAutoRasterClipValidate(const SkRasterClip& rc) : fRC(rc) {
107 fRC.validate();
108 }
109 ~SkAutoRasterClipValidate() {
110 fRC.validate();
111 }
112 private:
113 const SkRasterClip& fRC;
114 };
115 #define SkAutoRasterClipValidate(...) SK_REQUIRE_LOCAL_VAR(SkAutoRasterClipValidate)
117 #ifdef SK_DEBUG
118 #define AUTO_RASTERCLIP_VALIDATE(rc) SkAutoRasterClipValidate arcv(rc)
119 #else
120 #define AUTO_RASTERCLIP_VALIDATE(rc)
121 #endif
123 ///////////////////////////////////////////////////////////////////////////////
125 /**
126 * Encapsulates the logic of deciding if we need to change/wrap the blitter
127 * for aaclipping. If so, getRgn and getBlitter return modified values. If
128 * not, they return the raw blitter and (bw) clip region.
129 *
130 * We need to keep the constructor/destructor cost as small as possible, so we
131 * can freely put this guy on the stack, and not pay too much for the case when
132 * we're really BW anyways.
133 */
134 class SkAAClipBlitterWrapper {
135 public:
136 SkAAClipBlitterWrapper();
137 SkAAClipBlitterWrapper(const SkRasterClip&, SkBlitter*);
138 SkAAClipBlitterWrapper(const SkAAClip*, SkBlitter*);
140 void init(const SkRasterClip&, SkBlitter*);
142 const SkIRect& getBounds() const {
143 SkASSERT(fClipRgn);
144 return fClipRgn->getBounds();
145 }
146 const SkRegion& getRgn() const {
147 SkASSERT(fClipRgn);
148 return *fClipRgn;
149 }
150 SkBlitter* getBlitter() {
151 SkASSERT(fBlitter);
152 return fBlitter;
153 }
155 private:
156 SkRegion fBWRgn;
157 SkAAClipBlitter fAABlitter;
158 // what we return
159 const SkRegion* fClipRgn;
160 SkBlitter* fBlitter;
161 };
163 #endif