gfx/skia/trunk/include/utils/SkLayer.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/utils/SkLayer.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,130 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2010 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 SkLayer_DEFINED
    1.14 +#define SkLayer_DEFINED
    1.15 +
    1.16 +#include "SkRefCnt.h"
    1.17 +#include "SkTDArray.h"
    1.18 +#include "SkColor.h"
    1.19 +#include "SkMatrix.h"
    1.20 +#include "SkPoint.h"
    1.21 +#include "SkRect.h"
    1.22 +#include "SkSize.h"
    1.23 +
    1.24 +class SkCanvas;
    1.25 +
    1.26 +class SkLayer : public SkRefCnt {
    1.27 +
    1.28 +public:
    1.29 +    SK_DECLARE_INST_COUNT(SkLayer)
    1.30 +
    1.31 +    SkLayer();
    1.32 +    SkLayer(const SkLayer&);
    1.33 +    virtual ~SkLayer();
    1.34 +
    1.35 +    bool isInheritFromRootTransform() const;
    1.36 +    SkScalar getOpacity() const { return m_opacity; }
    1.37 +    const SkSize& getSize() const { return m_size; }
    1.38 +    const SkPoint& getPosition() const { return m_position; }
    1.39 +    const SkPoint& getAnchorPoint() const { return m_anchorPoint; }
    1.40 +    const SkMatrix& getMatrix() const { return fMatrix; }
    1.41 +    const SkMatrix& getChildrenMatrix() const { return fChildrenMatrix; }
    1.42 +
    1.43 +    SkScalar getWidth() const { return m_size.width(); }
    1.44 +    SkScalar getHeight() const { return m_size.height(); }
    1.45 +
    1.46 +    void setInheritFromRootTransform(bool);
    1.47 +    void setOpacity(SkScalar opacity) { m_opacity = opacity; }
    1.48 +    void setSize(SkScalar w, SkScalar h) { m_size.set(w, h); }
    1.49 +    void setPosition(SkScalar x, SkScalar y) { m_position.set(x, y); }
    1.50 +    void setAnchorPoint(SkScalar x, SkScalar y) { m_anchorPoint.set(x, y); }
    1.51 +    void setMatrix(const SkMatrix&);
    1.52 +    void setChildrenMatrix(const SkMatrix&);
    1.53 +
    1.54 +    // children
    1.55 +
    1.56 +    /** Return the number of layers in our child list.
    1.57 +     */
    1.58 +    int countChildren() const;
    1.59 +
    1.60 +    /** Return the child at the specified index (starting at 0). This does not
    1.61 +        affect the reference count of the child.
    1.62 +     */
    1.63 +    SkLayer* getChild(int index) const;
    1.64 +
    1.65 +    /** Add this layer to our child list at the end (top-most), and ref() it.
    1.66 +        If it was already in another hierarchy, remove it from that list.
    1.67 +        Return the new child.
    1.68 +     */
    1.69 +    SkLayer* addChild(SkLayer* child);
    1.70 +
    1.71 +    /** Remove this layer from its parent's list (or do nothing if it has no
    1.72 +        parent.) If it had a parent, then unref() is called.
    1.73 +     */
    1.74 +    void detachFromParent();
    1.75 +
    1.76 +    /** Remove, and unref(), all of the layers in our child list.
    1.77 +     */
    1.78 +    void removeChildren();
    1.79 +
    1.80 +    /** Return our parent layer, or NULL if we have none.
    1.81 +     */
    1.82 +    SkLayer* getParent() const { return fParent; }
    1.83 +
    1.84 +    /** Return the root layer in this hiearchy. If this layer is the root
    1.85 +        (i.e. has no parent), then this returns itself.
    1.86 +     */
    1.87 +    SkLayer* getRootLayer() const;
    1.88 +
    1.89 +    // coordinate system transformations
    1.90 +
    1.91 +    /** Return, in matrix, the matix transfomations that are applied locally
    1.92 +        when this layer draws (i.e. its position and matrix/anchorPoint).
    1.93 +        This does not include the childrenMatrix, since that is only applied
    1.94 +        after this layer draws (but before its children draw).
    1.95 +     */
    1.96 +    void getLocalTransform(SkMatrix* matrix) const;
    1.97 +
    1.98 +    /** Return, in matrix, the concatenation of transforms that are applied
    1.99 +        from this layer's root parent to the layer itself.
   1.100 +        This is the matrix that is applied to the layer during drawing.
   1.101 +     */
   1.102 +    void localToGlobal(SkMatrix* matrix) const;
   1.103 +
   1.104 +    // paint method
   1.105 +
   1.106 +    void draw(SkCanvas*, SkScalar opacity);
   1.107 +    void draw(SkCanvas* canvas) {
   1.108 +        this->draw(canvas, SK_Scalar1);
   1.109 +    }
   1.110 +
   1.111 +protected:
   1.112 +    virtual void onDraw(SkCanvas*, SkScalar opacity);
   1.113 +
   1.114 +private:
   1.115 +    enum Flags {
   1.116 +        kInheritFromRootTransform_Flag = 0x01
   1.117 +    };
   1.118 +
   1.119 +    SkLayer*    fParent;
   1.120 +    SkScalar    m_opacity;
   1.121 +    SkSize      m_size;
   1.122 +    SkPoint     m_position;
   1.123 +    SkPoint     m_anchorPoint;
   1.124 +    SkMatrix    fMatrix;
   1.125 +    SkMatrix    fChildrenMatrix;
   1.126 +    uint32_t    fFlags;
   1.127 +
   1.128 +    SkTDArray<SkLayer*> m_children;
   1.129 +
   1.130 +    typedef SkRefCnt INHERITED;
   1.131 +};
   1.132 +
   1.133 +#endif

mercurial