180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SkBounder_DEFINED
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkBounder_DEFINED
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkTypes.h"
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkRefCnt.h"
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkPoint.h"
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustruct SkGlyph;
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustruct SkIRect;
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustruct SkPoint;
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustruct SkRect;
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkPaint;
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkPath;
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkRegion;
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/** \class SkBounder
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    Base class for intercepting the device bounds of shapes before they are drawn.
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    Install a subclass of this in your canvas.
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru*/
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkBounder : public SkRefCnt {
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic:
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_DECLARE_INST_COUNT(SkBounder)
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkBounder();
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /* Call to perform a clip test before calling onIRect.
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru       Returns the result from onIRect.
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool doIRect(const SkIRect&);
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool doIRectGlyph(const SkIRect& , int x, int y, const SkGlyph&);
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprotected:
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Override in your subclass. This is called with the device bounds of an
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        object (text, geometry, image) just before it is drawn. If your method
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        returns false, the drawing for that shape is aborted. If your method
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        returns true, drawing continues. The bounds your method receives have already
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        been transformed in to device coordinates, and clipped to the current clip.
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual bool onIRect(const SkIRect&) {
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return false;
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Passed to onIRectGlyph with the information about the current glyph.
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        LSB and RSB are fixed-point (16.16) coordinates of the start and end
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        of the glyph's advance
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    struct GlyphRec {
5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkIPoint    fLSB;   //!< fixed-point left-side-bearing of the glyph
5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkIPoint    fRSB;   //!< fixed-point right-side-bearing of the glyph
6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        uint16_t    fGlyphID;
6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        uint16_t    fFlags; //!< currently set to 0
6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    };
6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Optionally, override in your subclass to receive the glyph ID when
6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        text drawing supplies the device bounds of the object.
6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual bool onIRectGlyph(const SkIRect& r, const GlyphRec&) {
6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return onIRect(r);
6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Called after each shape has been drawn. The default implementation does
7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        nothing, but your override could use this notification to signal itself
7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        that the offscreen being rendered into needs to be updated to the screen.
7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual void commit();
7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate:
7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool doHairline(const SkPoint&, const SkPoint&, const SkPaint&);
7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool doRect(const SkRect&, const SkPaint&);
8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool doPath(const SkPath&, const SkPaint&, bool doFill);
8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setClip(const SkRegion* clip) { fClip = clip; }
8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const SkRegion* fClip;
8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    friend class SkAutoBounderCommit;
8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    friend class SkDraw;
8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    friend class SkDrawIter;
8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    friend struct Draw1Glyph;
8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    friend class SkMaskFilter;
8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    typedef SkRefCnt INHERITED;
9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
94