• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2006 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
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 
19 class SK_API SkLayerRasterizer : public SkRasterizer {
20 public:
21     virtual ~SkLayerRasterizer();
22 
23     class SK_API Builder {
24     public:
25         Builder();
26         ~Builder();
27 
addLayer(const SkPaint & paint)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. If no layers have been added,
43           *  returns NULL.
44           *
45           *  The caller is responsible for calling unref() on the returned object, if non NULL.
46           */
47         SkLayerRasterizer* detachRasterizer();
48 
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
55           *  previously returned objects. If no layers have been added, returns NULL.
56           *
57           *  Future calls to addLayer will not affect rasterizers previously returned by this call.
58           *
59           *  The caller is responsible for calling unref() on the returned object, if non NULL.
60           */
61         SkLayerRasterizer* snapshotRasterizer() const;
62 
63     private:
64         SkDeque* fLayers;
65     };
66 
67     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLayerRasterizer)
68 
69 protected:
70     SkLayerRasterizer();
71     SkLayerRasterizer(SkDeque* layers);
72     void flatten(SkWriteBuffer&) const override;
73 
74     // override from SkRasterizer
75     virtual bool onRasterize(const SkPath& path, const SkMatrix& matrix,
76                              const SkIRect* clipBounds,
77                              SkMask* mask, SkMask::CreateMode mode) const override;
78 
79 private:
80     const SkDeque* const fLayers;
81 
82     static SkDeque* ReadLayers(SkReadBuffer& buffer);
83 
84     friend class LayerRasterizerTester;
85 
86     typedef SkRasterizer INHERITED;
87 };
88 
89 #endif
90