reed | 9f01471 | 2014-06-18 15:51:20 -0700 | [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 2006 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 | |
reed | 9f01471 | 2014-06-18 15:51:20 -0700 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef SkLayerRasterizer_DEFINED |
| 11 | #define SkLayerRasterizer_DEFINED |
| 12 | |
| 13 | #include "SkRasterizer.h" |
| 14 | #include "SkDeque.h" |
| 15 | #include "SkScalar.h" |
| 16 | |
| 17 | class SkPaint; |
| 18 | |
tfarina@chromium.org | 6806fe8 | 2012-10-12 14:41:39 +0000 | [diff] [blame] | 19 | class SK_API SkLayerRasterizer : public SkRasterizer { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 20 | public: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | virtual ~SkLayerRasterizer(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 22 | |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 23 | class SK_API Builder { |
| 24 | public: |
| 25 | Builder(); |
| 26 | ~Builder(); |
| 27 | |
| 28 | void addLayer(const SkPaint& paint) { |
| 29 | this->addLayer(paint, 0, 0); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Add a new layer (above any previous layers) to the rasterizer. |
| 34 | * The layer will extract those fields that affect the mask from |
| 35 | * the specified paint, but will not retain a reference to the paint |
| 36 | * object itself, so it may be reused without danger of side-effects. |
| 37 | */ |
| 38 | void addLayer(const SkPaint& paint, SkScalar dx, SkScalar dy); |
| 39 | |
| 40 | /** |
| 41 | * Pass queue of layers on to newly created layer rasterizer and return it. The builder |
scroggo | 65044bf | 2014-06-03 13:12:51 -0700 | [diff] [blame] | 42 | * *cannot* be used any more after calling this function. If no layers have been added, |
| 43 | * returns NULL. |
commit-bot@chromium.org | 6573ce7 | 2014-04-10 20:42:53 +0000 | [diff] [blame] | 44 | * |
scroggo | 65044bf | 2014-06-03 13:12:51 -0700 | [diff] [blame] | 45 | * The caller is responsible for calling unref() on the returned object, if non NULL. |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 46 | */ |
| 47 | SkLayerRasterizer* detachRasterizer(); |
| 48 | |
commit-bot@chromium.org | 6573ce7 | 2014-04-10 20:42:53 +0000 | [diff] [blame] | 49 | /** |
| 50 | * Create and return a new immutable SkLayerRasterizer that contains a shapshot of the |
| 51 | * layers that were added to the Builder, without modifying the Builder. The Builder |
| 52 | * *may* be used after calling this function. It will continue to hold any layers |
| 53 | * previously added, so consecutive calls to this function will return identical objects, |
| 54 | * and objects returned by future calls to this function contain all the layers in |
scroggo | 65044bf | 2014-06-03 13:12:51 -0700 | [diff] [blame] | 55 | * previously returned objects. If no layers have been added, returns NULL. |
commit-bot@chromium.org | 6573ce7 | 2014-04-10 20:42:53 +0000 | [diff] [blame] | 56 | * |
| 57 | * Future calls to addLayer will not affect rasterizers previously returned by this call. |
| 58 | * |
scroggo | 65044bf | 2014-06-03 13:12:51 -0700 | [diff] [blame] | 59 | * The caller is responsible for calling unref() on the returned object, if non NULL. |
commit-bot@chromium.org | 6573ce7 | 2014-04-10 20:42:53 +0000 | [diff] [blame] | 60 | */ |
| 61 | SkLayerRasterizer* snapshotRasterizer() const; |
| 62 | |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 63 | private: |
| 64 | SkDeque* fLayers; |
| 65 | }; |
| 66 | |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 67 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLayerRasterizer) |
reed@google.com | 43e9f20 | 2011-08-09 19:01:50 +0000 | [diff] [blame] | 68 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 69 | protected: |
dominikg | 1bd6f7d | 2014-07-21 02:43:20 -0700 | [diff] [blame] | 70 | SkLayerRasterizer(); |
reed | 9f01471 | 2014-06-18 15:51:20 -0700 | [diff] [blame] | 71 | SkLayerRasterizer(SkDeque* layers); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 72 | void flatten(SkWriteBuffer&) const override; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | |
| 74 | // override from SkRasterizer |
| 75 | virtual bool onRasterize(const SkPath& path, const SkMatrix& matrix, |
| 76 | const SkIRect* clipBounds, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 77 | SkMask* mask, SkMask::CreateMode mode) const override; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 78 | |
reed | 9f01471 | 2014-06-18 15:51:20 -0700 | [diff] [blame] | 79 | private: |
reed | 9f01471 | 2014-06-18 15:51:20 -0700 | [diff] [blame] | 80 | const SkDeque* const fLayers; |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 81 | |
| 82 | static SkDeque* ReadLayers(SkReadBuffer& buffer); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 83 | |
commit-bot@chromium.org | 6573ce7 | 2014-04-10 20:42:53 +0000 | [diff] [blame] | 84 | friend class LayerRasterizerTester; |
| 85 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 86 | typedef SkRasterizer INHERITED; |
| 87 | }; |
| 88 | |
| 89 | #endif |