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 | |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 13 | #include "SkBlurTypes.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 14 | #include "SkFlattenable.h" |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 15 | #include "SkPoint.h" |
| 16 | #include "SkColor.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 17 | |
Herb Derby | 73fe7b0 | 2017-02-08 15:12:19 -0500 | [diff] [blame] | 18 | class SkArenaAlloc; |
| 19 | class SkCanvas; |
Matt Sarett | cdc651d | 2017-03-30 12:41:48 -0400 | [diff] [blame] | 20 | class SkColorSpaceXformer; |
Herb Derby | 73fe7b0 | 2017-02-08 15:12:19 -0500 | [diff] [blame] | 21 | class SkPaint; |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 22 | struct SkRect; |
Herb Derby | 73fe7b0 | 2017-02-08 15:12:19 -0500 | [diff] [blame] | 23 | class SkString; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 24 | |
| 25 | /** \class SkDrawLooper |
| 26 | Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are, |
| 27 | and something is drawn to a canvas with that paint, the looper subclass will |
| 28 | be called, allowing it to modify the canvas and/or paint for that draw call. |
| 29 | More than that, via the next() method, the looper can modify the draw to be |
| 30 | invoked multiple times (hence the name loop-er), allow it to perform effects |
| 31 | like shadows or frame/fills, that require more than one pass. |
| 32 | */ |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 33 | class SK_API SkDrawLooper : public SkFlattenable { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | public: |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 35 | /** |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 36 | * Holds state during a draw. Users call next() until it returns false. |
| 37 | * |
| 38 | * Subclasses of SkDrawLooper should create a subclass of this object to |
| 39 | * hold state specific to their subclass. |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 40 | */ |
commit-bot@chromium.org | e3beb6b | 2014-04-07 19:34:38 +0000 | [diff] [blame] | 41 | class SK_API Context : ::SkNoncopyable { |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 42 | public: |
| 43 | Context() {} |
| 44 | virtual ~Context() {} |
| 45 | |
| 46 | /** |
| 47 | * Called in a loop on objects returned by SkDrawLooper::createContext(). |
| 48 | * Each time true is returned, the object is drawn (possibly with a modified |
| 49 | * canvas and/or paint). When false is finally returned, drawing for the object |
| 50 | * stops. |
| 51 | * |
| 52 | * On each call, the paint will be in its original state, but the |
| 53 | * canvas will be as it was following the previous call to next() or |
| 54 | * createContext(). |
| 55 | * |
| 56 | * The implementation must ensure that, when next() finally returns |
| 57 | * false, the canvas has been restored to the state it was |
| 58 | * initially, before createContext() was first called. |
| 59 | */ |
| 60 | virtual bool next(SkCanvas* canvas, SkPaint* paint) = 0; |
| 61 | }; |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 62 | |
| 63 | /** |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 64 | * Called right before something is being drawn. Returns a Context |
| 65 | * whose next() method should be called until it returns false. |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 66 | */ |
Herb Derby | 73fe7b0 | 2017-02-08 15:12:19 -0500 | [diff] [blame] | 67 | virtual Context* makeContext(SkCanvas*, SkArenaAlloc*) const = 0; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 68 | |
reed@google.com | 9efd9a0 | 2012-01-30 15:41:43 +0000 | [diff] [blame] | 69 | /** |
| 70 | * The fast bounds functions are used to enable the paint to be culled early |
| 71 | * in the drawing pipeline. If a subclass can support this feature it must |
| 72 | * return true for the canComputeFastBounds() function. If that function |
| 73 | * returns false then computeFastBounds behavior is undefined otherwise it |
| 74 | * is expected to have the following behavior. Given the parent paint and |
| 75 | * the parent's bounding rect the subclass must fill in and return the |
| 76 | * storage rect, where the storage rect is with the union of the src rect |
| 77 | * and the looper's bounding rect. |
| 78 | */ |
mtklein | 05d6115 | 2014-12-01 13:03:22 -0800 | [diff] [blame] | 79 | bool canComputeFastBounds(const SkPaint& paint) const; |
| 80 | void computeFastBounds(const SkPaint& paint, const SkRect& src, SkRect* dst) const; |
reed@google.com | 9efd9a0 | 2012-01-30 15:41:43 +0000 | [diff] [blame] | 81 | |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 82 | struct BlurShadowRec { |
| 83 | SkScalar fSigma; |
| 84 | SkVector fOffset; |
| 85 | SkColor fColor; |
| 86 | SkBlurStyle fStyle; |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 87 | #ifdef SK_SUPPORT_LEGACY_BLURMASKFILTER |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 88 | SkBlurQuality fQuality; |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 89 | #endif |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 90 | }; |
| 91 | /** |
| 92 | * If this looper can be interpreted as having two layers, such that |
| 93 | * 1. The first layer (bottom most) just has a blur and translate |
| 94 | * 2. The second layer has no modifications to either paint or canvas |
| 95 | * 3. No other layers. |
| 96 | * then return true, and if not null, fill out the BlurShadowRec). |
| 97 | * |
| 98 | * If any of the above are not met, return false and ignore the BlurShadowRec parameter. |
| 99 | */ |
| 100 | virtual bool asABlurShadow(BlurShadowRec*) const; |
| 101 | |
Cary Clark | 9988541 | 2018-04-05 13:09:58 -0400 | [diff] [blame^] | 102 | virtual void toString(SkString* str) const = 0; |
mtklein | 3b37545 | 2016-04-04 14:57:19 -0700 | [diff] [blame] | 103 | SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper) |
robertphillips@google.com | 4991b8f | 2013-01-28 20:21:59 +0000 | [diff] [blame] | 104 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 105 | protected: |
Matt Sarett | cdc651d | 2017-03-30 12:41:48 -0400 | [diff] [blame] | 106 | sk_sp<SkDrawLooper> makeColorSpace(SkColorSpaceXformer* xformer) const { |
| 107 | return this->onMakeColorSpace(xformer); |
| 108 | } |
| 109 | virtual sk_sp<SkDrawLooper> onMakeColorSpace(SkColorSpaceXformer*) const = 0; |
| 110 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 111 | SkDrawLooper() {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 112 | |
| 113 | private: |
Matt Sarett | cdc651d | 2017-03-30 12:41:48 -0400 | [diff] [blame] | 114 | friend class SkColorSpaceXformer; |
| 115 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 116 | typedef SkFlattenable INHERITED; |
| 117 | }; |
| 118 | |
| 119 | #endif |