gfx/skia/trunk/include/core/SkDrawLooper.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/core/SkDrawLooper.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2011 The Android Open Source Project
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#ifndef SkDrawLooper_DEFINED
    1.14 +#define SkDrawLooper_DEFINED
    1.15 +
    1.16 +#include "SkFlattenable.h"
    1.17 +
    1.18 +class SkCanvas;
    1.19 +class SkPaint;
    1.20 +struct SkRect;
    1.21 +class SkString;
    1.22 +
    1.23 +/** \class SkDrawLooper
    1.24 +    Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are,
    1.25 +    and something is drawn to a canvas with that paint, the looper subclass will
    1.26 +    be called, allowing it to modify the canvas and/or paint for that draw call.
    1.27 +    More than that, via the next() method, the looper can modify the draw to be
    1.28 +    invoked multiple times (hence the name loop-er), allow it to perform effects
    1.29 +    like shadows or frame/fills, that require more than one pass.
    1.30 +*/
    1.31 +class SK_API SkDrawLooper : public SkFlattenable {
    1.32 +public:
    1.33 +    SK_DECLARE_INST_COUNT(SkDrawLooper)
    1.34 +
    1.35 +    /**
    1.36 +     *  Holds state during a draw. Users call next() until it returns false.
    1.37 +     *
    1.38 +     *  Subclasses of SkDrawLooper should create a subclass of this object to
    1.39 +     *  hold state specific to their subclass.
    1.40 +     */
    1.41 +    class SK_API Context : public SkNoncopyable {
    1.42 +    public:
    1.43 +        Context() {}
    1.44 +        virtual ~Context() {}
    1.45 +
    1.46 +        /**
    1.47 +         *  Called in a loop on objects returned by SkDrawLooper::createContext().
    1.48 +         *  Each time true is returned, the object is drawn (possibly with a modified
    1.49 +         *  canvas and/or paint). When false is finally returned, drawing for the object
    1.50 +         *  stops.
    1.51 +         *
    1.52 +         *  On each call, the paint will be in its original state, but the
    1.53 +         *  canvas will be as it was following the previous call to next() or
    1.54 +         *  createContext().
    1.55 +         *
    1.56 +         *  The implementation must ensure that, when next() finally returns
    1.57 +         *  false, the canvas has been restored to the state it was
    1.58 +         *  initially, before createContext() was first called.
    1.59 +         */
    1.60 +        virtual bool next(SkCanvas* canvas, SkPaint* paint) = 0;
    1.61 +    };
    1.62 +
    1.63 +    /**
    1.64 +     *  Called right before something is being drawn. Returns a Context
    1.65 +     *  whose next() method should be called until it returns false.
    1.66 +     *  The caller has to ensure that the storage pointer provides enough
    1.67 +     *  memory for the Context. The required size can be queried by calling
    1.68 +     *  contextSize(). It is also the caller's responsibility to destroy the
    1.69 +     *  object after use.
    1.70 +     */
    1.71 +    virtual Context* createContext(SkCanvas*, void* storage) const = 0;
    1.72 +
    1.73 +    /**
    1.74 +      *  Returns the number of bytes needed to store subclasses of Context (belonging to the
    1.75 +      *  corresponding SkDrawLooper subclass).
    1.76 +      */
    1.77 +    virtual size_t contextSize() const = 0;
    1.78 +
    1.79 +
    1.80 +    /**
    1.81 +     * The fast bounds functions are used to enable the paint to be culled early
    1.82 +     * in the drawing pipeline. If a subclass can support this feature it must
    1.83 +     * return true for the canComputeFastBounds() function.  If that function
    1.84 +     * returns false then computeFastBounds behavior is undefined otherwise it
    1.85 +     * is expected to have the following behavior. Given the parent paint and
    1.86 +     * the parent's bounding rect the subclass must fill in and return the
    1.87 +     * storage rect, where the storage rect is with the union of the src rect
    1.88 +     * and the looper's bounding rect.
    1.89 +     */
    1.90 +    virtual bool canComputeFastBounds(const SkPaint& paint) const;
    1.91 +    virtual void computeFastBounds(const SkPaint& paint,
    1.92 +                                   const SkRect& src, SkRect* dst) const;
    1.93 +
    1.94 +    SK_TO_STRING_PUREVIRT()
    1.95 +    SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper)
    1.96 +
    1.97 +protected:
    1.98 +    SkDrawLooper() {}
    1.99 +    SkDrawLooper(SkReadBuffer& buffer) : INHERITED(buffer) {}
   1.100 +
   1.101 +private:
   1.102 +    typedef SkFlattenable INHERITED;
   1.103 +};
   1.104 +
   1.105 +#endif

mercurial