1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/core/SkBounder.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,93 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2006 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#ifndef SkBounder_DEFINED 1.14 +#define SkBounder_DEFINED 1.15 + 1.16 +#include "SkTypes.h" 1.17 +#include "SkRefCnt.h" 1.18 +#include "SkPoint.h" 1.19 + 1.20 +struct SkGlyph; 1.21 +struct SkIRect; 1.22 +struct SkPoint; 1.23 +struct SkRect; 1.24 +class SkPaint; 1.25 +class SkPath; 1.26 +class SkRegion; 1.27 + 1.28 +/** \class SkBounder 1.29 + 1.30 + Base class for intercepting the device bounds of shapes before they are drawn. 1.31 + Install a subclass of this in your canvas. 1.32 +*/ 1.33 +class SkBounder : public SkRefCnt { 1.34 +public: 1.35 + SK_DECLARE_INST_COUNT(SkBounder) 1.36 + 1.37 + SkBounder(); 1.38 + 1.39 + /* Call to perform a clip test before calling onIRect. 1.40 + Returns the result from onIRect. 1.41 + */ 1.42 + bool doIRect(const SkIRect&); 1.43 + bool doIRectGlyph(const SkIRect& , int x, int y, const SkGlyph&); 1.44 + 1.45 +protected: 1.46 + /** Override in your subclass. This is called with the device bounds of an 1.47 + object (text, geometry, image) just before it is drawn. If your method 1.48 + returns false, the drawing for that shape is aborted. If your method 1.49 + returns true, drawing continues. The bounds your method receives have already 1.50 + been transformed in to device coordinates, and clipped to the current clip. 1.51 + */ 1.52 + virtual bool onIRect(const SkIRect&) { 1.53 + return false; 1.54 + } 1.55 + 1.56 + /** Passed to onIRectGlyph with the information about the current glyph. 1.57 + LSB and RSB are fixed-point (16.16) coordinates of the start and end 1.58 + of the glyph's advance 1.59 + */ 1.60 + struct GlyphRec { 1.61 + SkIPoint fLSB; //!< fixed-point left-side-bearing of the glyph 1.62 + SkIPoint fRSB; //!< fixed-point right-side-bearing of the glyph 1.63 + uint16_t fGlyphID; 1.64 + uint16_t fFlags; //!< currently set to 0 1.65 + }; 1.66 + 1.67 + /** Optionally, override in your subclass to receive the glyph ID when 1.68 + text drawing supplies the device bounds of the object. 1.69 + */ 1.70 + virtual bool onIRectGlyph(const SkIRect& r, const GlyphRec&) { 1.71 + return onIRect(r); 1.72 + } 1.73 + 1.74 + /** Called after each shape has been drawn. The default implementation does 1.75 + nothing, but your override could use this notification to signal itself 1.76 + that the offscreen being rendered into needs to be updated to the screen. 1.77 + */ 1.78 + virtual void commit(); 1.79 + 1.80 +private: 1.81 + bool doHairline(const SkPoint&, const SkPoint&, const SkPaint&); 1.82 + bool doRect(const SkRect&, const SkPaint&); 1.83 + bool doPath(const SkPath&, const SkPaint&, bool doFill); 1.84 + void setClip(const SkRegion* clip) { fClip = clip; } 1.85 + 1.86 + const SkRegion* fClip; 1.87 + friend class SkAutoBounderCommit; 1.88 + friend class SkDraw; 1.89 + friend class SkDrawIter; 1.90 + friend struct Draw1Glyph; 1.91 + friend class SkMaskFilter; 1.92 + 1.93 + typedef SkRefCnt INHERITED; 1.94 +}; 1.95 + 1.96 +#endif