3 * Copyright 2006 The Android Open Source Project
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #ifndef SkLayerRasterizer_DEFINED
11 #define SkLayerRasterizer_DEFINED
13 #include "SkRasterizer.h"
19 class SK_API SkLayerRasterizer : public SkRasterizer {
21 virtual ~SkLayerRasterizer();
23 class SK_API Builder {
28 void addLayer(const SkPaint& paint) {
29 this->addLayer(paint, 0, 0);
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.
38 void addLayer(const SkPaint& paint, SkScalar dx, SkScalar dy);
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. If no layers have been added,
45 * The caller is responsible for calling unref() on the returned object, if non NULL.
47 SkLayerRasterizer* detachRasterizer();
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
55 * previously returned objects. If no layers have been added, returns NULL.
57 * Future calls to addLayer will not affect rasterizers previously returned by this call.
59 * The caller is responsible for calling unref() on the returned object, if non NULL.
61 SkLayerRasterizer* snapshotRasterizer() const;
67 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLayerRasterizer)
71 SkLayerRasterizer(SkDeque* layers);
72 SkLayerRasterizer(SkReadBuffer&);
73 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
75 // override from SkRasterizer
76 virtual bool onRasterize(const SkPath& path, const SkMatrix& matrix,
77 const SkIRect* clipBounds,
78 SkMask* mask, SkMask::CreateMode mode) const;
81 const SkDeque* const fLayers;
83 static SkDeque* ReadLayers(SkReadBuffer& buffer);
85 friend class LayerRasterizerTester;
87 typedef SkRasterizer INHERITED;