Home | History | Annotate | Download | only in effects
      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 
     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 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
     73     SkLayerRasterizer(SkReadBuffer&);
     74 #endif
     75     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
     76 
     77     // override from SkRasterizer
     78     virtual bool onRasterize(const SkPath& path, const SkMatrix& matrix,
     79                              const SkIRect* clipBounds,
     80                              SkMask* mask, SkMask::CreateMode mode) const;
     81 
     82 private:
     83     const SkDeque* const fLayers;
     84 
     85     static SkDeque* ReadLayers(SkReadBuffer& buffer);
     86 
     87     friend class LayerRasterizerTester;
     88 
     89     typedef SkRasterizer INHERITED;
     90 };
     91 
     92 #endif
     93