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