michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkBounder_DEFINED michael@0: #define SkBounder_DEFINED michael@0: michael@0: #include "SkTypes.h" michael@0: #include "SkRefCnt.h" michael@0: #include "SkPoint.h" michael@0: michael@0: struct SkGlyph; michael@0: struct SkIRect; michael@0: struct SkPoint; michael@0: struct SkRect; michael@0: class SkPaint; michael@0: class SkPath; michael@0: class SkRegion; michael@0: michael@0: /** \class SkBounder michael@0: michael@0: Base class for intercepting the device bounds of shapes before they are drawn. michael@0: Install a subclass of this in your canvas. michael@0: */ michael@0: class SkBounder : public SkRefCnt { michael@0: public: michael@0: SK_DECLARE_INST_COUNT(SkBounder) michael@0: michael@0: SkBounder(); michael@0: michael@0: /* Call to perform a clip test before calling onIRect. michael@0: Returns the result from onIRect. michael@0: */ michael@0: bool doIRect(const SkIRect&); michael@0: bool doIRectGlyph(const SkIRect& , int x, int y, const SkGlyph&); michael@0: michael@0: protected: michael@0: /** Override in your subclass. This is called with the device bounds of an michael@0: object (text, geometry, image) just before it is drawn. If your method michael@0: returns false, the drawing for that shape is aborted. If your method michael@0: returns true, drawing continues. The bounds your method receives have already michael@0: been transformed in to device coordinates, and clipped to the current clip. michael@0: */ michael@0: virtual bool onIRect(const SkIRect&) { michael@0: return false; michael@0: } michael@0: michael@0: /** Passed to onIRectGlyph with the information about the current glyph. michael@0: LSB and RSB are fixed-point (16.16) coordinates of the start and end michael@0: of the glyph's advance michael@0: */ michael@0: struct GlyphRec { michael@0: SkIPoint fLSB; //!< fixed-point left-side-bearing of the glyph michael@0: SkIPoint fRSB; //!< fixed-point right-side-bearing of the glyph michael@0: uint16_t fGlyphID; michael@0: uint16_t fFlags; //!< currently set to 0 michael@0: }; michael@0: michael@0: /** Optionally, override in your subclass to receive the glyph ID when michael@0: text drawing supplies the device bounds of the object. michael@0: */ michael@0: virtual bool onIRectGlyph(const SkIRect& r, const GlyphRec&) { michael@0: return onIRect(r); michael@0: } michael@0: michael@0: /** Called after each shape has been drawn. The default implementation does michael@0: nothing, but your override could use this notification to signal itself michael@0: that the offscreen being rendered into needs to be updated to the screen. michael@0: */ michael@0: virtual void commit(); michael@0: michael@0: private: michael@0: bool doHairline(const SkPoint&, const SkPoint&, const SkPaint&); michael@0: bool doRect(const SkRect&, const SkPaint&); michael@0: bool doPath(const SkPath&, const SkPaint&, bool doFill); michael@0: void setClip(const SkRegion* clip) { fClip = clip; } michael@0: michael@0: const SkRegion* fClip; michael@0: friend class SkAutoBounderCommit; michael@0: friend class SkDraw; michael@0: friend class SkDrawIter; michael@0: friend struct Draw1Glyph; michael@0: friend class SkMaskFilter; michael@0: michael@0: typedef SkRefCnt INHERITED; michael@0: }; michael@0: michael@0: #endif