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 17struct SkGlyph; 18struct SkIRect; 19struct SkPoint; 20struct SkRect; 21class SkPaint; 22class SkPath; 23class 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*/ 30class SkBounder : public SkRefCnt { 31public: 32 SkBounder(); 33 34 /* Call to perform a clip test before calling onIRect. 35 Returns the result from onIRect. 36 */ 37 bool doIRect(const SkIRect&); 38 bool doIRectGlyph(const SkIRect& , int x, int y, const SkGlyph&); 39 40protected: 41 /** Override in your subclass. This is called with the device bounds of an 42 object (text, geometry, image) just before it is drawn. If your method 43 returns false, the drawing for that shape is aborted. If your method 44 returns true, drawing continues. The bounds your method receives have already 45 been transformed in to device coordinates, and clipped to the current clip. 46 */ 47 virtual bool onIRect(const SkIRect&) { 48 return false; 49 } 50 51 /** Passed to onIRectGlyph with the information about the current glyph. 52 LSB and RSB are fixed-point (16.16) coordinates of the start and end 53 of the glyph's advance 54 */ 55 struct GlyphRec { 56 SkIPoint fLSB; //!< fixed-point left-side-bearing of the glyph 57 SkIPoint fRSB; //!< fixed-point right-side-bearing of the glyph 58 uint16_t fGlyphID; 59 uint16_t fFlags; //!< currently set to 0 60 }; 61 62 /** Optionally, override in your subclass to receive the glyph ID when 63 text drawing supplies the device bounds of the object. 64 */ 65 virtual bool onIRectGlyph(const SkIRect& r, const GlyphRec&) { 66 return onIRect(r); 67 } 68 69 /** Called after each shape has been drawn. The default implementation does 70 nothing, but your override could use this notification to signal itself 71 that the offscreen being rendered into needs to be updated to the screen. 72 */ 73 virtual void commit(); 74 75private: 76 bool doHairline(const SkPoint&, const SkPoint&, const SkPaint&); 77 bool doRect(const SkRect&, const SkPaint&); 78 bool doPath(const SkPath&, const SkPaint&, bool doFill); 79 void setClip(const SkRegion* clip) { fClip = clip; } 80 81 const SkRegion* fClip; 82 friend class SkAutoBounderCommit; 83 friend class SkDraw; 84 friend class SkDrawIter; 85 friend struct Draw1Glyph; 86 friend class SkMaskFilter; 87}; 88 89#endif 90 91