Home | History | Annotate | Download | only in core
      1 
      2 /*
      3  * Copyright 2006 The Android Open Source Project
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 #ifndef SkBounder_DEFINED
     11 #define SkBounder_DEFINED
     12 
     13 #include "SkTypes.h"
     14 #include "SkRefCnt.h"
     15 #include "SkPoint.h"
     16 
     17 struct SkGlyph;
     18 struct SkIRect;
     19 struct SkPoint;
     20 struct SkRect;
     21 class SkPaint;
     22 class SkPath;
     23 class SkRegion;
     24 
     25 /** \class SkBounder
     26 
     27     Base class for intercepting the device bounds of shapes before they are drawn.
     28     Install a subclass of this in your canvas.
     29 */
     30 class SkBounder : public SkRefCnt {
     31 public:
     32     SK_DECLARE_INST_COUNT(SkBounder)
     33 
     34     SkBounder();
     35 
     36     /* Call to perform a clip test before calling onIRect.
     37        Returns the result from onIRect.
     38     */
     39     bool doIRect(const SkIRect&);
     40     bool doIRectGlyph(const SkIRect& , int x, int y, const SkGlyph&);
     41 
     42 protected:
     43     /** Override in your subclass. This is called with the device bounds of an
     44         object (text, geometry, image) just before it is drawn. If your method
     45         returns false, the drawing for that shape is aborted. If your method
     46         returns true, drawing continues. The bounds your method receives have already
     47         been transformed in to device coordinates, and clipped to the current clip.
     48     */
     49     virtual bool onIRect(const SkIRect&) {
     50         return false;
     51     }
     52 
     53     /** Passed to onIRectGlyph with the information about the current glyph.
     54         LSB and RSB are fixed-point (16.16) coordinates of the start and end
     55         of the glyph's advance
     56      */
     57     struct GlyphRec {
     58         SkIPoint    fLSB;   //!< fixed-point left-side-bearing of the glyph
     59         SkIPoint    fRSB;   //!< fixed-point right-side-bearing of the glyph
     60         uint16_t    fGlyphID;
     61         uint16_t    fFlags; //!< currently set to 0
     62     };
     63 
     64     /** Optionally, override in your subclass to receive the glyph ID when
     65         text drawing supplies the device bounds of the object.
     66     */
     67     virtual bool onIRectGlyph(const SkIRect& r, const GlyphRec&) {
     68         return onIRect(r);
     69     }
     70 
     71     /** Called after each shape has been drawn. The default implementation does
     72         nothing, but your override could use this notification to signal itself
     73         that the offscreen being rendered into needs to be updated to the screen.
     74     */
     75     virtual void commit();
     76 
     77 private:
     78     bool doHairline(const SkPoint&, const SkPoint&, const SkPaint&);
     79     bool doRect(const SkRect&, const SkPaint&);
     80     bool doPath(const SkPath&, const SkPaint&, bool doFill);
     81     void setClip(const SkRegion* clip) { fClip = clip; }
     82 
     83     const SkRegion* fClip;
     84     friend class SkAutoBounderCommit;
     85     friend class SkDraw;
     86     friend class SkDrawIter;
     87     friend struct Draw1Glyph;
     88     friend class SkMaskFilter;
     89 
     90     typedef SkRefCnt INHERITED;
     91 };
     92 
     93 #endif
     94