blob: c061be689d0b7d3c98739f1a437da5033e32a83f [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 */
45 SkLayerRasterizer* detachRasterizer();
46
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 */
59 SkLayerRasterizer* snapshotRasterizer() 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:
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000068 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000069
70 // override from SkRasterizer
71 virtual bool onRasterize(const SkPath& path, const SkMatrix& matrix,
72 const SkIRect* clipBounds,
reed@google.comfdba4042012-12-18 16:57:03 +000073 SkMask* mask, SkMask::CreateMode mode) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +000074
75private:
commit-bot@chromium.orgf792a1b2014-02-26 13:27:37 +000076 const SkDeque* const fLayers;
reedc5d5cf92014-06-18 14:41:26 -070077
78 SkLayerRasterizer();
79 SkLayerRasterizer(SkDeque* layers);
80 SkLayerRasterizer(SkReadBuffer&);
commit-bot@chromium.orgf792a1b2014-02-26 13:27:37 +000081
82 static SkDeque* ReadLayers(SkReadBuffer& buffer);
reed@android.com8a1c16f2008-12-17 15:59:43 +000083
commit-bot@chromium.org6573ce72014-04-10 20:42:53 +000084 friend class LayerRasterizerTester;
85
reed@android.com8a1c16f2008-12-17 15:59:43 +000086 typedef SkRasterizer INHERITED;
87};
88
89#endif