summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/android/LayerAndroid.h
blob: 8050356343583b43cafccfb6b6003c5ca3c0525d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef LayerAndroid_h
#define LayerAndroid_h

#if USE(ACCELERATED_COMPOSITING)

#include "Color.h"
#include "FloatPoint.h"
#include "FloatPoint3D.h"
#include "FloatSize.h"
#include "Length.h"
#include "RefPtr.h"
#include "SkLayer.h"
#include "StringHash.h"
#include "Vector.h"
#include <wtf/HashMap.h>

class SkCanvas;
class SkPicture;
class SkRect;

namespace WebCore {

class AndroidAnimation;
class AndroidAnimationValue;

class LayerAndroid : public SkLayer {

public:
    LayerAndroid(bool isRootLayer);
    LayerAndroid(const LayerAndroid& layer);
    virtual ~LayerAndroid();

    static int instancesCount();

    void setHaveContents(bool haveContents) { m_haveContents = haveContents; }
    void setHaveImage(bool haveImage) { m_haveImage = haveImage; }
    void setDrawsContent(bool drawsContent);
    void setMaskLayer(LayerAndroid*);
    void setMasksToBounds(bool);
    virtual void setBackgroundColor(SkColor color);
    void setIsRootLayer(bool isRootLayer) { m_isRootLayer = isRootLayer; }

    void paintOn(int scrollX, int scrollY, int width, int height, float scale, SkCanvas*);
    void paintOn(SkPoint offset, SkSize size, SkScalar scale, SkCanvas*);
    bool prepareContext(bool force = false);
    void startRecording();
    void stopRecording();
    SkPicture* recordContext();
    void setClip(SkCanvas* clip);

    void addAnimation(PassRefPtr<AndroidAnimation> anim);
    void removeAnimation(const String& name);
    bool evaluateAnimations() const;
    bool evaluateAnimations(double time) const;
    bool hasAnimations() const;

    void calcPosition(int scrollX, int scrollY, int viewWidth, int viewHeight,
                      float scale, float* xPtr, float* yPtr);

    SkPicture* picture() const { return m_recordingPicture; }

    void dumpLayers(FILE*, int indentLevel);

private:

    void paintChildren(int scrollX, int scrollY,
                       int width, int height,
                       float scale, SkCanvas* canvas,
                       float opacity);

    void paintMe(int scrollX, int scrollY,
                 int width, int height,
                 float scale, SkCanvas* canvas,
                 float opacity);

    bool m_isRootLayer;
    bool m_haveContents;
    bool m_drawsContent;
    bool m_haveImage;
    bool m_haveClip;

    SkPicture* m_recordingPicture;

    typedef HashMap<String, RefPtr<AndroidAnimation> > KeyframesMap;
    KeyframesMap m_animations;
};

}

#endif // USE(ACCELERATED_COMPOSITING)

#endif  // LayerAndroid_h