2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2011 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
|
|
|
*/
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SkDrawLooper_DEFINED
|
|
|
|
#define SkDrawLooper_DEFINED
|
|
|
|
|
2018-07-16 21:44:06 +00:00
|
|
|
#include "../private/SkNoncopyable.h"
|
2014-04-29 15:20:16 +00:00
|
|
|
#include "SkBlurTypes.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkFlattenable.h"
|
2014-04-29 15:20:16 +00:00
|
|
|
#include "SkPoint.h"
|
|
|
|
#include "SkColor.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-02-08 20:12:19 +00:00
|
|
|
class SkArenaAlloc;
|
|
|
|
class SkCanvas;
|
2017-03-30 16:41:48 +00:00
|
|
|
class SkColorSpaceXformer;
|
2017-02-08 20:12:19 +00:00
|
|
|
class SkPaint;
|
2012-08-07 15:54:32 +00:00
|
|
|
struct SkRect;
|
2017-02-08 20:12:19 +00:00
|
|
|
class SkString;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** \class SkDrawLooper
|
|
|
|
Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are,
|
|
|
|
and something is drawn to a canvas with that paint, the looper subclass will
|
|
|
|
be called, allowing it to modify the canvas and/or paint for that draw call.
|
|
|
|
More than that, via the next() method, the looper can modify the draw to be
|
|
|
|
invoked multiple times (hence the name loop-er), allow it to perform effects
|
|
|
|
like shadows or frame/fills, that require more than one pass.
|
|
|
|
*/
|
2011-03-15 21:27:08 +00:00
|
|
|
class SK_API SkDrawLooper : public SkFlattenable {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2011-04-07 14:18:59 +00:00
|
|
|
/**
|
2014-03-12 09:42:01 +00:00
|
|
|
* Holds state during a draw. Users call next() until it returns false.
|
|
|
|
*
|
|
|
|
* Subclasses of SkDrawLooper should create a subclass of this object to
|
|
|
|
* hold state specific to their subclass.
|
2011-04-07 14:18:59 +00:00
|
|
|
*/
|
2014-04-07 19:34:38 +00:00
|
|
|
class SK_API Context : ::SkNoncopyable {
|
2014-03-12 09:42:01 +00:00
|
|
|
public:
|
|
|
|
Context() {}
|
|
|
|
virtual ~Context() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called in a loop on objects returned by SkDrawLooper::createContext().
|
|
|
|
* Each time true is returned, the object is drawn (possibly with a modified
|
|
|
|
* canvas and/or paint). When false is finally returned, drawing for the object
|
|
|
|
* stops.
|
|
|
|
*
|
|
|
|
* On each call, the paint will be in its original state, but the
|
|
|
|
* canvas will be as it was following the previous call to next() or
|
|
|
|
* createContext().
|
|
|
|
*
|
|
|
|
* The implementation must ensure that, when next() finally returns
|
|
|
|
* false, the canvas has been restored to the state it was
|
|
|
|
* initially, before createContext() was first called.
|
|
|
|
*/
|
|
|
|
virtual bool next(SkCanvas* canvas, SkPaint* paint) = 0;
|
|
|
|
};
|
2011-04-07 14:18:59 +00:00
|
|
|
|
|
|
|
/**
|
2014-03-12 09:42:01 +00:00
|
|
|
* Called right before something is being drawn. Returns a Context
|
|
|
|
* whose next() method should be called until it returns false.
|
2011-04-07 14:18:59 +00:00
|
|
|
*/
|
2017-02-08 20:12:19 +00:00
|
|
|
virtual Context* makeContext(SkCanvas*, SkArenaAlloc*) const = 0;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-01-30 15:41:43 +00:00
|
|
|
/**
|
|
|
|
* The fast bounds functions are used to enable the paint to be culled early
|
|
|
|
* in the drawing pipeline. If a subclass can support this feature it must
|
|
|
|
* return true for the canComputeFastBounds() function. If that function
|
|
|
|
* returns false then computeFastBounds behavior is undefined otherwise it
|
|
|
|
* is expected to have the following behavior. Given the parent paint and
|
|
|
|
* the parent's bounding rect the subclass must fill in and return the
|
|
|
|
* storage rect, where the storage rect is with the union of the src rect
|
|
|
|
* and the looper's bounding rect.
|
|
|
|
*/
|
2014-12-01 21:03:22 +00:00
|
|
|
bool canComputeFastBounds(const SkPaint& paint) const;
|
|
|
|
void computeFastBounds(const SkPaint& paint, const SkRect& src, SkRect* dst) const;
|
2012-01-30 15:41:43 +00:00
|
|
|
|
2014-04-29 15:20:16 +00:00
|
|
|
struct BlurShadowRec {
|
|
|
|
SkScalar fSigma;
|
|
|
|
SkVector fOffset;
|
|
|
|
SkColor fColor;
|
|
|
|
SkBlurStyle fStyle;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* If this looper can be interpreted as having two layers, such that
|
|
|
|
* 1. The first layer (bottom most) just has a blur and translate
|
|
|
|
* 2. The second layer has no modifications to either paint or canvas
|
|
|
|
* 3. No other layers.
|
|
|
|
* then return true, and if not null, fill out the BlurShadowRec).
|
|
|
|
*
|
|
|
|
* If any of the above are not met, return false and ignore the BlurShadowRec parameter.
|
|
|
|
*/
|
|
|
|
virtual bool asABlurShadow(BlurShadowRec*) const;
|
|
|
|
|
2018-05-21 15:56:57 +00:00
|
|
|
static SkFlattenable::Type GetFlattenableType() {
|
|
|
|
return kSkDrawLooper_Type;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkFlattenable::Type getFlattenableType() const override {
|
|
|
|
return kSkDrawLooper_Type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static sk_sp<SkDrawLooper> Deserialize(const void* data, size_t size,
|
|
|
|
const SkDeserialProcs* procs = nullptr) {
|
|
|
|
return sk_sp<SkDrawLooper>(static_cast<SkDrawLooper*>(
|
|
|
|
SkFlattenable::Deserialize(
|
|
|
|
kSkDrawLooper_Type, data, size, procs).release()));
|
|
|
|
}
|
2013-01-28 20:21:59 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
protected:
|
2017-03-30 16:41:48 +00:00
|
|
|
sk_sp<SkDrawLooper> makeColorSpace(SkColorSpaceXformer* xformer) const {
|
|
|
|
return this->onMakeColorSpace(xformer);
|
|
|
|
}
|
|
|
|
virtual sk_sp<SkDrawLooper> onMakeColorSpace(SkColorSpaceXformer*) const = 0;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkDrawLooper() {}
|
|
|
|
|
|
|
|
private:
|
2017-03-30 16:41:48 +00:00
|
|
|
friend class SkColorSpaceXformer;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
typedef SkFlattenable INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|