2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkLayerRasterizer_DEFINED
|
|
|
|
#define SkLayerRasterizer_DEFINED
|
|
|
|
|
|
|
|
#include "SkRasterizer.h"
|
|
|
|
#include "SkDeque.h"
|
|
|
|
#include "SkScalar.h"
|
|
|
|
|
|
|
|
class SkPaint;
|
|
|
|
|
2012-10-12 14:41:39 +00:00
|
|
|
class SK_API SkLayerRasterizer : public SkRasterizer {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
|
|
|
virtual ~SkLayerRasterizer();
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2014-02-26 13:27:37 +00:00
|
|
|
class SK_API Builder {
|
|
|
|
public:
|
|
|
|
Builder();
|
|
|
|
~Builder();
|
|
|
|
|
|
|
|
void addLayer(const SkPaint& paint) {
|
|
|
|
this->addLayer(paint, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new layer (above any previous layers) to the rasterizer.
|
|
|
|
* The layer will extract those fields that affect the mask from
|
|
|
|
* the specified paint, but will not retain a reference to the paint
|
|
|
|
* object itself, so it may be reused without danger of side-effects.
|
|
|
|
*/
|
|
|
|
void addLayer(const SkPaint& paint, SkScalar dx, SkScalar dy);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pass queue of layers on to newly created layer rasterizer and return it. The builder
|
2014-06-03 20:12:51 +00:00
|
|
|
* *cannot* be used any more after calling this function. If no layers have been added,
|
|
|
|
* returns NULL.
|
2014-04-10 20:42:53 +00:00
|
|
|
*
|
2014-06-03 20:12:51 +00:00
|
|
|
* The caller is responsible for calling unref() on the returned object, if non NULL.
|
2014-02-26 13:27:37 +00:00
|
|
|
*/
|
2016-03-21 20:25:16 +00:00
|
|
|
sk_sp<SkLayerRasterizer> detach();
|
2014-02-26 13:27:37 +00:00
|
|
|
|
2014-04-10 20:42:53 +00:00
|
|
|
/**
|
|
|
|
* Create and return a new immutable SkLayerRasterizer that contains a shapshot of the
|
|
|
|
* layers that were added to the Builder, without modifying the Builder. The Builder
|
|
|
|
* *may* be used after calling this function. It will continue to hold any layers
|
|
|
|
* previously added, so consecutive calls to this function will return identical objects,
|
|
|
|
* and objects returned by future calls to this function contain all the layers in
|
2014-06-03 20:12:51 +00:00
|
|
|
* previously returned objects. If no layers have been added, returns NULL.
|
2014-04-10 20:42:53 +00:00
|
|
|
*
|
|
|
|
* Future calls to addLayer will not affect rasterizers previously returned by this call.
|
|
|
|
*
|
2014-06-03 20:12:51 +00:00
|
|
|
* The caller is responsible for calling unref() on the returned object, if non NULL.
|
2014-04-10 20:42:53 +00:00
|
|
|
*/
|
2016-03-21 20:25:16 +00:00
|
|
|
sk_sp<SkLayerRasterizer> snapshot() const;
|
|
|
|
|
|
|
|
#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
|
|
|
|
SkLayerRasterizer* detachRasterizer() {
|
|
|
|
return this->detach().release();
|
|
|
|
}
|
|
|
|
SkLayerRasterizer* snapshotRasterizer() const {
|
|
|
|
return this->snapshot().release();
|
|
|
|
}
|
|
|
|
#endif
|
2014-04-10 20:42:53 +00:00
|
|
|
|
2014-02-26 13:27:37 +00:00
|
|
|
private:
|
|
|
|
SkDeque* fLayers;
|
|
|
|
};
|
|
|
|
|
2012-03-26 17:57:35 +00:00
|
|
|
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLayerRasterizer)
|
2011-08-09 19:01:50 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
protected:
|
2014-07-21 09:43:20 +00:00
|
|
|
SkLayerRasterizer();
|
2014-06-18 22:51:20 +00:00
|
|
|
SkLayerRasterizer(SkDeque* layers);
|
2015-03-26 01:17:31 +00:00
|
|
|
void flatten(SkWriteBuffer&) const override;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
// override from SkRasterizer
|
|
|
|
virtual bool onRasterize(const SkPath& path, const SkMatrix& matrix,
|
|
|
|
const SkIRect* clipBounds,
|
2015-03-26 01:17:31 +00:00
|
|
|
SkMask* mask, SkMask::CreateMode mode) const override;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
private:
|
2014-02-26 13:27:37 +00:00
|
|
|
const SkDeque* const fLayers;
|
|
|
|
|
|
|
|
static SkDeque* ReadLayers(SkReadBuffer& buffer);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2014-04-10 20:42:53 +00:00
|
|
|
friend class LayerRasterizerTester;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
typedef SkRasterizer INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|