blob: a1b7e2dc0ca64541176e2eb306448cc16f66d8a8 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
8#ifndef SkLayerRasterizer_DEFINED
9#define SkLayerRasterizer_DEFINED
10
11#include "SkRasterizer.h"
12#include "SkDeque.h"
13#include "SkScalar.h"
14
15class SkPaint;
16
tfarina@chromium.org6806fe82012-10-12 14:41:39 +000017class SK_API SkLayerRasterizer : public SkRasterizer {
reed@android.com8a1c16f2008-12-17 15:59:43 +000018public:
reed@android.com8a1c16f2008-12-17 15:59:43 +000019 virtual ~SkLayerRasterizer();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000020
commit-bot@chromium.orgf792a1b2014-02-26 13:27:37 +000021 class SK_API Builder {
22 public:
23 Builder();
24 ~Builder();
25
26 void addLayer(const SkPaint& paint) {
27 this->addLayer(paint, 0, 0);
28 }
29
30 /**
31 * Add a new layer (above any previous layers) to the rasterizer.
32 * The layer will extract those fields that affect the mask from
33 * the specified paint, but will not retain a reference to the paint
34 * object itself, so it may be reused without danger of side-effects.
35 */
36 void addLayer(const SkPaint& paint, SkScalar dx, SkScalar dy);
37
38 /**
39 * Pass queue of layers on to newly created layer rasterizer and return it. The builder
scroggo65044bf2014-06-03 13:12:51 -070040 * *cannot* be used any more after calling this function. If no layers have been added,
41 * returns NULL.
commit-bot@chromium.org6573ce72014-04-10 20:42:53 +000042 *
scroggo65044bf2014-06-03 13:12:51 -070043 * The caller is responsible for calling unref() on the returned object, if non NULL.
commit-bot@chromium.orgf792a1b2014-02-26 13:27:37 +000044 */
reed7b380d02016-03-21 13:25:16 -070045 sk_sp<SkLayerRasterizer> detach();
commit-bot@chromium.orgf792a1b2014-02-26 13:27:37 +000046
commit-bot@chromium.org6573ce72014-04-10 20:42:53 +000047 /**
48 * Create and return a new immutable SkLayerRasterizer that contains a shapshot of the
49 * layers that were added to the Builder, without modifying the Builder. The Builder
50 * *may* be used after calling this function. It will continue to hold any layers
51 * previously added, so consecutive calls to this function will return identical objects,
52 * and objects returned by future calls to this function contain all the layers in
scroggo65044bf2014-06-03 13:12:51 -070053 * previously returned objects. If no layers have been added, returns NULL.
commit-bot@chromium.org6573ce72014-04-10 20:42:53 +000054 *
55 * Future calls to addLayer will not affect rasterizers previously returned by this call.
56 *
scroggo65044bf2014-06-03 13:12:51 -070057 * The caller is responsible for calling unref() on the returned object, if non NULL.
commit-bot@chromium.org6573ce72014-04-10 20:42:53 +000058 */
reed7b380d02016-03-21 13:25:16 -070059 sk_sp<SkLayerRasterizer> snapshot() const;
60
commit-bot@chromium.orgf792a1b2014-02-26 13:27:37 +000061 private:
62 SkDeque* fLayers;
63 };
64
djsollen@google.comba28d032012-03-26 17:57:35 +000065 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLayerRasterizer)
reed@google.com43e9f202011-08-09 19:01:50 +000066
reed@android.com8a1c16f2008-12-17 15:59:43 +000067protected:
dominikg1bd6f7d2014-07-21 02:43:20 -070068 SkLayerRasterizer();
reed9f014712014-06-18 15:51:20 -070069 SkLayerRasterizer(SkDeque* layers);
mtklein36352bf2015-03-25 18:17:31 -070070 void flatten(SkWriteBuffer&) const override;
reed@android.com8a1c16f2008-12-17 15:59:43 +000071
72 // override from SkRasterizer
73 virtual bool onRasterize(const SkPath& path, const SkMatrix& matrix,
74 const SkIRect* clipBounds,
mtklein36352bf2015-03-25 18:17:31 -070075 SkMask* mask, SkMask::CreateMode mode) const override;
reed@android.com8a1c16f2008-12-17 15:59:43 +000076
reed9f014712014-06-18 15:51:20 -070077private:
reed9f014712014-06-18 15:51:20 -070078 const SkDeque* const fLayers;
commit-bot@chromium.orgf792a1b2014-02-26 13:27:37 +000079
80 static SkDeque* ReadLayers(SkReadBuffer& buffer);
reed@android.com8a1c16f2008-12-17 15:59:43 +000081
commit-bot@chromium.org6573ce72014-04-10 20:42:53 +000082 friend class LayerRasterizerTester;
83
reed@android.com8a1c16f2008-12-17 15:59:43 +000084 typedef SkRasterizer INHERITED;
85};
86
87#endif