1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkRasterClip.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,163 @@ 1.4 +/* 1.5 + * Copyright 2010 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef SkRasterClip_DEFINED 1.12 +#define SkRasterClip_DEFINED 1.13 + 1.14 +#include "SkRegion.h" 1.15 +#include "SkAAClip.h" 1.16 + 1.17 +class SkRasterClip { 1.18 +public: 1.19 + SkRasterClip(); 1.20 + SkRasterClip(const SkIRect&); 1.21 + SkRasterClip(const SkRasterClip&); 1.22 + ~SkRasterClip(); 1.23 + 1.24 + bool isBW() const { return fIsBW; } 1.25 + bool isAA() const { return !fIsBW; } 1.26 + const SkRegion& bwRgn() const { SkASSERT(fIsBW); return fBW; } 1.27 + const SkAAClip& aaRgn() const { SkASSERT(!fIsBW); return fAA; } 1.28 + 1.29 + bool isEmpty() const { 1.30 + SkASSERT(this->computeIsEmpty() == fIsEmpty); 1.31 + return fIsEmpty; 1.32 + } 1.33 + 1.34 + bool isRect() const { 1.35 + SkASSERT(this->computeIsRect() == fIsRect); 1.36 + return fIsRect; 1.37 + } 1.38 + 1.39 + bool isComplex() const; 1.40 + const SkIRect& getBounds() const; 1.41 + 1.42 + bool setEmpty(); 1.43 + bool setRect(const SkIRect&); 1.44 + 1.45 + bool setPath(const SkPath& path, const SkRegion& clip, bool doAA); 1.46 + bool setPath(const SkPath& path, const SkIRect& clip, bool doAA); 1.47 + 1.48 + bool op(const SkIRect&, SkRegion::Op); 1.49 + bool op(const SkRegion&, SkRegion::Op); 1.50 + bool op(const SkRasterClip&, SkRegion::Op); 1.51 + bool op(const SkRect&, SkRegion::Op, bool doAA); 1.52 + 1.53 + void translate(int dx, int dy, SkRasterClip* dst) const; 1.54 + void translate(int dx, int dy) { 1.55 + this->translate(dx, dy, this); 1.56 + } 1.57 + 1.58 + bool quickContains(const SkIRect& rect) const; 1.59 + bool quickContains(int left, int top, int right, int bottom) const { 1.60 + return quickContains(SkIRect::MakeLTRB(left, top, right, bottom)); 1.61 + } 1.62 + 1.63 + /** 1.64 + * Return true if this region is empty, or if the specified rectangle does 1.65 + * not intersect the region. Returning false is not a guarantee that they 1.66 + * intersect, but returning true is a guarantee that they do not. 1.67 + */ 1.68 + bool quickReject(const SkIRect& rect) const { 1.69 + return this->isEmpty() || rect.isEmpty() || 1.70 + !SkIRect::Intersects(this->getBounds(), rect); 1.71 + } 1.72 + 1.73 + // hack for SkCanvas::getTotalClip 1.74 + const SkRegion& forceGetBW(); 1.75 + 1.76 +#ifdef SK_DEBUG 1.77 + void validate() const; 1.78 +#else 1.79 + void validate() const {} 1.80 +#endif 1.81 + 1.82 +private: 1.83 + SkRegion fBW; 1.84 + SkAAClip fAA; 1.85 + bool fIsBW; 1.86 + // these 2 are caches based on querying the right obj based on fIsBW 1.87 + bool fIsEmpty; 1.88 + bool fIsRect; 1.89 + 1.90 + bool computeIsEmpty() const { 1.91 + return fIsBW ? fBW.isEmpty() : fAA.isEmpty(); 1.92 + } 1.93 + 1.94 + bool computeIsRect() const { 1.95 + return fIsBW ? fBW.isRect() : false; 1.96 + } 1.97 + 1.98 + bool updateCacheAndReturnNonEmpty() { 1.99 + fIsEmpty = this->computeIsEmpty(); 1.100 + fIsRect = this->computeIsRect(); 1.101 + return !fIsEmpty; 1.102 + } 1.103 + 1.104 + void convertToAA(); 1.105 +}; 1.106 + 1.107 +class SkAutoRasterClipValidate : SkNoncopyable { 1.108 +public: 1.109 + SkAutoRasterClipValidate(const SkRasterClip& rc) : fRC(rc) { 1.110 + fRC.validate(); 1.111 + } 1.112 + ~SkAutoRasterClipValidate() { 1.113 + fRC.validate(); 1.114 + } 1.115 +private: 1.116 + const SkRasterClip& fRC; 1.117 +}; 1.118 +#define SkAutoRasterClipValidate(...) SK_REQUIRE_LOCAL_VAR(SkAutoRasterClipValidate) 1.119 + 1.120 +#ifdef SK_DEBUG 1.121 + #define AUTO_RASTERCLIP_VALIDATE(rc) SkAutoRasterClipValidate arcv(rc) 1.122 +#else 1.123 + #define AUTO_RASTERCLIP_VALIDATE(rc) 1.124 +#endif 1.125 + 1.126 +/////////////////////////////////////////////////////////////////////////////// 1.127 + 1.128 +/** 1.129 + * Encapsulates the logic of deciding if we need to change/wrap the blitter 1.130 + * for aaclipping. If so, getRgn and getBlitter return modified values. If 1.131 + * not, they return the raw blitter and (bw) clip region. 1.132 + * 1.133 + * We need to keep the constructor/destructor cost as small as possible, so we 1.134 + * can freely put this guy on the stack, and not pay too much for the case when 1.135 + * we're really BW anyways. 1.136 + */ 1.137 +class SkAAClipBlitterWrapper { 1.138 +public: 1.139 + SkAAClipBlitterWrapper(); 1.140 + SkAAClipBlitterWrapper(const SkRasterClip&, SkBlitter*); 1.141 + SkAAClipBlitterWrapper(const SkAAClip*, SkBlitter*); 1.142 + 1.143 + void init(const SkRasterClip&, SkBlitter*); 1.144 + 1.145 + const SkIRect& getBounds() const { 1.146 + SkASSERT(fClipRgn); 1.147 + return fClipRgn->getBounds(); 1.148 + } 1.149 + const SkRegion& getRgn() const { 1.150 + SkASSERT(fClipRgn); 1.151 + return *fClipRgn; 1.152 + } 1.153 + SkBlitter* getBlitter() { 1.154 + SkASSERT(fBlitter); 1.155 + return fBlitter; 1.156 + } 1.157 + 1.158 +private: 1.159 + SkRegion fBWRgn; 1.160 + SkAAClipBlitter fAABlitter; 1.161 + // what we return 1.162 + const SkRegion* fClipRgn; 1.163 + SkBlitter* fBlitter; 1.164 +}; 1.165 + 1.166 +#endif