blob: fdfb179cb6bab604188c2f20b12f74697e29b757 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkLayerRasterizer_DEFINED
11#define SkLayerRasterizer_DEFINED
12
13#include "SkRasterizer.h"
14#include "SkDeque.h"
15#include "SkScalar.h"
16
17class SkPaint;
18
tfarina@chromium.org6806fe82012-10-12 14:41:39 +000019class SK_API SkLayerRasterizer : public SkRasterizer {
reed@android.com8a1c16f2008-12-17 15:59:43 +000020public:
reed@android.com8a1c16f2008-12-17 15:59:43 +000021 virtual ~SkLayerRasterizer();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000022
commit-bot@chromium.orgf792a1b2014-02-26 13:27:37 +000023 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
42 * cannot be used any more after calling this function.
43 */
44 SkLayerRasterizer* detachRasterizer();
45
46 private:
47 SkDeque* fLayers;
48 };
49
50#ifdef SK_SUPPORT_LEGACY_LAYERRASTERIZER_API
mike@reedtribe.org6b919c32011-04-20 11:17:30 +000051 void addLayer(const SkPaint& paint) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000052 this->addLayer(paint, 0, 0);
53 }
54
rmistry@google.comfbfcd562012-08-23 18:09:54 +000055 /** Add a new layer (above any previous layers) to the rasterizer.
56 The layer will extract those fields that affect the mask from
57 the specified paint, but will not retain a reference to the paint
58 object itself, so it may be reused without danger of side-effects.
59 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000060 void addLayer(const SkPaint& paint, SkScalar dx, SkScalar dy);
commit-bot@chromium.orgf792a1b2014-02-26 13:27:37 +000061#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000062
djsollen@google.comba28d032012-03-26 17:57:35 +000063 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLayerRasterizer)
reed@google.com43e9f202011-08-09 19:01:50 +000064
reed@android.com8a1c16f2008-12-17 15:59:43 +000065protected:
commit-bot@chromium.orgf792a1b2014-02-26 13:27:37 +000066 SkLayerRasterizer(SkDeque* layers);
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000067 SkLayerRasterizer(SkReadBuffer&);
68 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
commit-bot@chromium.orgf792a1b2014-02-26 13:27:37 +000075#ifdef SK_SUPPORT_LEGACY_LAYERRASTERIZER_API
76public:
77#endif
78 SkLayerRasterizer();
79
reed@android.com8a1c16f2008-12-17 15:59:43 +000080private:
commit-bot@chromium.orgf792a1b2014-02-26 13:27:37 +000081#ifdef SK_SUPPORT_LEGACY_LAYERRASTERIZER_API
82 SkDeque* fLayers;
83#else
84 const SkDeque* const fLayers;
85#endif
86
87 static SkDeque* ReadLayers(SkReadBuffer& buffer);
reed@android.com8a1c16f2008-12-17 15:59:43 +000088
89 typedef SkRasterizer INHERITED;
90};
91
92#endif