SkDrawLooper.h revision 0456e0b7b85060e9b9597ce414c4c2b19aff4f58
1 2/* 3 * Copyright 2011 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 SkDrawLooper_DEFINED 11#define SkDrawLooper_DEFINED 12 13#include "SkFlattenable.h" 14 15class SkCanvas; 16class SkPaint; 17 18/** \class SkDrawLooper 19 Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are, 20 and something is drawn to a canvas with that paint, the looper subclass will 21 be called, allowing it to modify the canvas and/or paint for that draw call. 22 More than that, via the next() method, the looper can modify the draw to be 23 invoked multiple times (hence the name loop-er), allow it to perform effects 24 like shadows or frame/fills, that require more than one pass. 25*/ 26class SK_API SkDrawLooper : public SkFlattenable { 27public: 28 SK_DECLARE_INST_COUNT(SkDrawLooper) 29 30 /** 31 * Called right before something is being drawn. This will be followed by 32 * calls to next() until next() returns false. 33 */ 34 virtual void init(SkCanvas*) = 0; 35 36 /** 37 * Called in a loop (after init()). Each time true is returned, the object 38 * is drawn (possibly with a modified canvas and/or paint). When false is 39 * finally returned, drawing for the object stops. 40 * 41 * On each call, the paint will be in its original state, but the canvas 42 * will be as it was following the previous call to next() or init(). 43 * 44 * The implementation must ensure that, when next() finally returns false, 45 * that the canvas has been restored to the state it was initially, before 46 * init() was first called. 47 */ 48 virtual bool next(SkCanvas*, SkPaint* paint) = 0; 49 50 /** 51 * The fast bounds functions are used to enable the paint to be culled early 52 * in the drawing pipeline. If a subclass can support this feature it must 53 * return true for the canComputeFastBounds() function. If that function 54 * returns false then computeFastBounds behavior is undefined otherwise it 55 * is expected to have the following behavior. Given the parent paint and 56 * the parent's bounding rect the subclass must fill in and return the 57 * storage rect, where the storage rect is with the union of the src rect 58 * and the looper's bounding rect. 59 */ 60 virtual bool canComputeFastBounds(const SkPaint& paint); 61 virtual void computeFastBounds(const SkPaint& paint, 62 const SkRect& src, SkRect* dst); 63 64protected: 65 SkDrawLooper() {} 66 SkDrawLooper(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {} 67 68private: 69 typedef SkFlattenable INHERITED; 70}; 71 72#endif 73