epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef SkBounder_DEFINED |
| 11 | #define SkBounder_DEFINED |
| 12 | |
| 13 | #include "SkTypes.h" |
| 14 | #include "SkRefCnt.h" |
reed@android.com | d055c1f | 2010-03-01 14:54:05 +0000 | [diff] [blame] | 15 | #include "SkPoint.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | |
reed@android.com | d055c1f | 2010-03-01 14:54:05 +0000 | [diff] [blame] | 17 | struct SkGlyph; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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: |
reed@google.com | 0a0a236 | 2011-03-23 13:51:55 +0000 | [diff] [blame] | 32 | SkBounder(); |
| 33 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | /* Call to perform a clip test before calling onIRect. |
| 35 | Returns the result from onIRect. |
| 36 | */ |
| 37 | bool doIRect(const SkIRect&); |
reed@android.com | d055c1f | 2010-03-01 14:54:05 +0000 | [diff] [blame] | 38 | bool doIRectGlyph(const SkIRect& , int x, int y, const SkGlyph&); |
| 39 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | protected: |
| 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 | */ |
reed@android.com | 474a12c | 2010-01-04 19:35:33 +0000 | [diff] [blame] | 47 | virtual bool onIRect(const SkIRect&) { |
| 48 | return false; |
| 49 | } |
| 50 | |
reed@android.com | d055c1f | 2010-03-01 14:54:05 +0000 | [diff] [blame] | 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 | |
reed@android.com | 474a12c | 2010-01-04 19:35:33 +0000 | [diff] [blame] | 62 | /** Optionally, override in your subclass to receive the glyph ID when |
| 63 | text drawing supplies the device bounds of the object. |
| 64 | */ |
reed@android.com | d055c1f | 2010-03-01 14:54:05 +0000 | [diff] [blame] | 65 | virtual bool onIRectGlyph(const SkIRect& r, const GlyphRec&) { |
reed@android.com | 474a12c | 2010-01-04 19:35:33 +0000 | [diff] [blame] | 66 | return onIRect(r); |
| 67 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | |
| 75 | private: |
| 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 | |