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 23 struct SkIRect; 24 struct SkPoint; 25 struct SkRect; 26 class SkPaint; 27 class SkPath; 28 class SkRegion; 29 30 /** \class SkBounder 31 32 Base class for intercepting the device bounds of shapes before they are drawn. 33 Install a subclass of this in your canvas. 34 */ 35 class SkBounder : public SkRefCnt { 36 public: 37 /* Call to perform a clip test before calling onIRect. 38 Returns the result from onIRect. 39 */ 40 bool doIRect(const SkIRect&); 41 42 protected: 43 /** Override in your subclass. This is called with the device bounds of an 44 object (text, geometry, image) just before it is drawn. If your method 45 returns false, the drawing for that shape is aborted. If your method 46 returns true, drawing continues. The bounds your method receives have already 47 been transformed in to device coordinates, and clipped to the current clip. 48 */ 49 virtual bool onIRect(const SkIRect&) = 0; 50 51 /** Called after each shape has been drawn. The default implementation does 52 nothing, but your override could use this notification to signal itself 53 that the offscreen being rendered into needs to be updated to the screen. 54 */ 55 virtual void commit(); 56 57 private: 58 bool doHairline(const SkPoint&, const SkPoint&, const SkPaint&); 59 bool doRect(const SkRect&, const SkPaint&); 60 bool doPath(const SkPath&, const SkPaint&, bool doFill); setClip(const SkRegion * clip)61 void setClip(const SkRegion* clip) { fClip = clip; } 62 63 const SkRegion* fClip; 64 friend class SkAutoBounderCommit; 65 friend class SkDraw; 66 friend class SkDrawIter; 67 friend struct Draw1Glyph; 68 friend class SkMaskFilter; 69 }; 70 71 #endif 72 73