From 71531ca1f484da5837be8017a0c83e5bff701587 Mon Sep 17 00:00:00 2001 From: Derek Sollenberger Date: Thu, 24 Feb 2011 11:04:57 -0500 Subject: Skia Merge (revision 842) This merge picks up the fixed width font updates and improved blur code from the Skia repository. Change-Id: Iad2301a353c31da27ca214527cf4ed8f24641749 --- include/core/SkCanvas.h | 19 +++++++++++ include/core/SkClipStack.h | 65 ++++++++++++++++++++++++++++++++++++++ include/core/SkDeque.h | 8 ++--- include/core/SkDevice.h | 18 ++++++++--- include/core/SkScalerContext.h | 4 --- include/core/SkTypeface.h | 23 ++++++++------ include/effects/SkBlurDrawLooper.h | 8 +++-- include/effects/SkBlurMaskFilter.h | 6 ++-- 8 files changed, 126 insertions(+), 25 deletions(-) create mode 100644 include/core/SkClipStack.h (limited to 'include') diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index b2a9fa9..103507c 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -20,6 +20,7 @@ #include "SkTypes.h" #include "SkBitmap.h" #include "SkDeque.h" +#include "SkClipStack.h" #include "SkPaint.h" #include "SkRefCnt.h" #include "SkPath.h" @@ -789,6 +790,7 @@ protected: private: class MCRec; + SkClipStack fClipStack; SkDeque fMCStack; // points to top of stack MCRec* fMCRec; @@ -848,6 +850,23 @@ private: SkMatrix fExternalMatrix, fExternalInverse; bool fUseExternalMatrix; + + class AutoValidateClip : ::SkNoncopyable { + public: + explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) { + fCanvas->validateClip(); + } + ~AutoValidateClip() { fCanvas->validateClip(); } + + private: + const SkCanvas* fCanvas; + }; + +#ifdef SK_DEBUG + void validateClip() const; +#else + void validateClip() const {} +#endif }; /** Stack helper class to automatically call restoreToCount() on the canvas diff --git a/include/core/SkClipStack.h b/include/core/SkClipStack.h new file mode 100644 index 0000000..fb94155 --- /dev/null +++ b/include/core/SkClipStack.h @@ -0,0 +1,65 @@ +#ifndef SkClipStack_DEFINED +#define SkClipStack_DEFINED + +#include "SkDeque.h" +#include "SkRegion.h" + +struct SkRect; +class SkPath; + +class SkClipStack { +public: + SkClipStack(); + ~SkClipStack() {} + + void reset(); + + int getSaveCount() const { return fSaveCount; } + void save(); + void restore(); + + void clipDevRect(const SkIRect& ir, + SkRegion::Op op = SkRegion::kIntersect_Op) { + SkRect r; + r.set(ir); + this->clipDevRect(r, op); + } + void clipDevRect(const SkRect&, SkRegion::Op = SkRegion::kIntersect_Op); + void clipDevPath(const SkPath&, SkRegion::Op = SkRegion::kIntersect_Op); + + class B2FIter { + public: + B2FIter(const SkClipStack& stack); + + struct Clip { + const SkRect* fRect; // if non-null, this is a rect clip + const SkPath* fPath; // if non-null, this is a path clip + SkRegion::Op fOp; + }; + + /** + * Return the clip for this element in the iterator. If next() returns + * NULL, then the iterator is done. The type of clip is determined by + * the pointers fRect and fPath: + * + * fRect==NULL fPath!=NULL path clip + * fRect!=NULL fPath==NULL rect clip + * fRect==NULL fPath==NULL empty clip + */ + const Clip* next(); + + private: + Clip fClip; + SkDeque::F2BIter fIter; + }; + +private: + friend class B2FIter; + struct Rec; + + SkDeque fDeque; + int fSaveCount; +}; + +#endif + diff --git a/include/core/SkDeque.h b/include/core/SkDeque.h index cbed930..99c8dd4 100644 --- a/include/core/SkDeque.h +++ b/include/core/SkDeque.h @@ -42,7 +42,7 @@ public: void* push_front(); void* push_back(); - + void pop_front(); void pop_back(); @@ -50,9 +50,9 @@ private: struct Head; public: - class Iter { + class F2BIter { public: - Iter(const SkDeque& d); + F2BIter(const SkDeque& d); void* next(); private: @@ -67,7 +67,7 @@ private: size_t fElemSize; void* fInitialStorage; int fCount; - + friend class Iter; }; diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index 1b4630d..7791f34 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -23,6 +23,7 @@ #include "SkColor.h" #include "SkRefDict.h" +class SkClipStack; class SkDevice; class SkDraw; struct SkIRect; @@ -122,11 +123,20 @@ public: */ virtual SkGpuTexture* accessTexture() { return NULL; } - /** Called with the correct matrix and clip before this device is drawn - to using those settings. If your subclass overrides this, be sure to - call through to the base class as well. + /** + * Called with the correct matrix and clip before this device is drawn + * to using those settings. If your subclass overrides this, be sure to + * call through to the base class as well. + * + * The clipstack is another view of the clip. It records the actual + * geometry that went into building the region. It is present for devices + * that want to parse it, but is not required: the region is a complete + * picture of the current clip. (i.e. if you regionize all of the geometry + * in the clipstack, you will arrive at an equivalent region to the one + * passed in). */ - virtual void setMatrixClip(const SkMatrix&, const SkRegion&); + virtual void setMatrixClip(const SkMatrix&, const SkRegion&, + const SkClipStack&); /** Called when this device gains focus (i.e becomes the current device for drawing). diff --git a/include/core/SkScalerContext.h b/include/core/SkScalerContext.h index 0c93e2e..5937819 100644 --- a/include/core/SkScalerContext.h +++ b/include/core/SkScalerContext.h @@ -51,10 +51,6 @@ struct SkGlyph { fImage = NULL; fPath = NULL; fMaskFormat = MASK_FORMAT_UNKNOWN; -#ifdef SK_GPU_AWARE_GLYPHCACHE - fGLCacheOffset = SKGLYPH_GLCACHEOFFSET_INVALID; - fGLStrikePtr = NULL; -#endif } unsigned rowBytes() const { diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h index cea6ab1..728ba31 100644 --- a/include/core/SkTypeface.h +++ b/include/core/SkTypeface.h @@ -56,7 +56,11 @@ public: /** Returns true if getStyle() has the kItalic bit set. */ bool isItalic() const { return (fStyle & kItalic) != 0; } - + + /** Returns true if the typeface is fixed-width + */ + bool isFixedWidth() const { return fIsFixedWidth; } + /** Return a 32bit value for this typeface, unique for the underlying font data. Will never return 0. */ @@ -72,11 +76,11 @@ public: handling either being null (treating null as the default font) */ static bool Equal(const SkTypeface* facea, const SkTypeface* faceb); - + /** Return a new reference to the typeface that most closely matches the requested familyName and style. Pass null as the familyName to return the default font for the requested style. Will never return null - + @param familyName May be NULL. The name of the font family. @param style The style (normal, bold, italic) of the typeface. @return reference to the closest-matching typeface. Call must call @@ -100,7 +104,7 @@ public: requested typeface and specified Style. Use this call if you want to pick a new style from the same family of the existing typeface. If family is NULL, this selects from the default font's family. - + @param family May be NULL. The name of the existing type face. @param s The style (normal, bold, italic) of the type face. @return reference to the closest-matching typeface. Call must call @@ -112,7 +116,7 @@ public: not a valid font file, returns null. */ static SkTypeface* CreateFromFile(const char path[]); - + /** Return a new typeface given a stream. If the stream is not a valid font file, returns null. Ownership of the stream is transferred, so the caller must not reference it again. @@ -123,7 +127,7 @@ public: typeface referencing the same font when Deserialize is called. */ void serialize(SkWStream*) const; - + /** Given the data previously written by serialize(), return a new instance to a typeface referring to the same font. If that font is not available, return null. If an instance is returned, the caller is responsible for @@ -142,13 +146,14 @@ public: protected: /** uniqueID must be unique (please!) and non-zero */ - SkTypeface(Style style, uint32_t uniqueID) - : fUniqueID(uniqueID), fStyle(style) {} + SkTypeface(Style style, uint32_t uniqueID, bool isFixedWidth = false) + : fUniqueID(uniqueID), fStyle(style), fIsFixedWidth(isFixedWidth) {} private: uint32_t fUniqueID; Style fStyle; - + bool fIsFixedWidth; + typedef SkRefCnt INHERITED; }; diff --git a/include/effects/SkBlurDrawLooper.h b/include/effects/SkBlurDrawLooper.h index 6f96ff6..e7af5c2 100644 --- a/include/effects/SkBlurDrawLooper.h +++ b/include/effects/SkBlurDrawLooper.h @@ -21,6 +21,7 @@ #include "SkColor.h" class SkMaskFilter; +class SkColorFilter; /** \class SkBlurDrawLooper This class draws a shadow of the object (possibly offset), and then draws @@ -35,9 +36,11 @@ public: The blur layer's dx/dy/radius aren't affected by the canvas transform. */ - kIgnoreTransform_BlurFlag = 0x01, + kIgnoreTransform_BlurFlag = 0x01, + kOverrideColor_BlurFlag = 0x02, + kHighQuality_BlurFlag = 0x04, /** mask for all blur flags */ - kAll_BlurFlag = 0x01 + kAll_BlurFlag = 0x07 }; SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, SkColor color, @@ -64,6 +67,7 @@ private: SkCanvas* fCanvas; SkPaint* fPaint; SkMaskFilter* fBlur; + SkColorFilter* fColorFilter; SkScalar fDx, fDy; SkColor fBlurColor; SkColor fSavedColor; // remember the original diff --git a/include/effects/SkBlurMaskFilter.h b/include/effects/SkBlurMaskFilter.h index 0a68f54..0a0e8d2 100644 --- a/include/effects/SkBlurMaskFilter.h +++ b/include/effects/SkBlurMaskFilter.h @@ -35,9 +35,11 @@ public: enum BlurFlags { kNone_BlurFlag = 0x00, /** The blur layer's radius is not affected by transforms */ - kIgnoreTransform_BlurFlag = 0x01, + kIgnoreTransform_BlurFlag = 0x01, + /** Use a smother, higher qulity blur algorithm */ + kHighQuality_BlurFlag = 0x02, /** mask for all blur flags */ - kAll_BlurFlag = 0x01 + kAll_BlurFlag = 0x03 }; /** Create a blur maskfilter. -- cgit v1.1