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