OSDN Git Service

Add UI considerations to layers
[android-x86/external-webkit.git] / WebCore / platform / graphics / android / LayerAndroid.h
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef LayerAndroid_h
18 #define LayerAndroid_h
19
20 #if USE(ACCELERATED_COMPOSITING)
21
22 #include "FloatPoint.h"
23 #include "RefPtr.h"
24 #include "SkColor.h"
25 #include "SkLayer.h"
26 #include "StringHash.h"
27 #include <wtf/HashMap.h>
28
29 class FindOnPage;
30 class SkCanvas;
31 class SkMatrix;
32 class SkPicture;
33
34 namespace WebCore {
35
36 class AndroidAnimation;
37
38 class LayerAndroid : public SkLayer {
39
40 public:
41     LayerAndroid(bool isRootLayer);
42     LayerAndroid(const LayerAndroid& layer);
43     virtual ~LayerAndroid();
44
45     static int instancesCount();
46
47     void setHaveContents(bool haveContents) { m_haveContents = haveContents; }
48     void setHaveImage(bool haveImage) { m_haveImage = haveImage; }
49     void setDrawsContent(bool drawsContent);
50     void setFindOnPage(FindOnPage* findOnPage);
51     void setMaskLayer(LayerAndroid*);
52     void setMasksToBounds(bool);
53     virtual void setBackgroundColor(SkColor color);
54     void setIsRootLayer(bool isRootLayer) { m_isRootLayer = isRootLayer; }
55
56     virtual void draw(SkCanvas*, const SkRect* viewPort);
57 //    GraphicsContext* paintContext();
58     bool prepareContext(bool force = false);
59     void startRecording();
60     void stopRecording();
61     SkPicture* recordContext();
62     void setClip(SkCanvas* clip);
63
64     void addAnimation(PassRefPtr<AndroidAnimation> anim);
65     void removeAnimation(const String& name);
66     bool evaluateAnimations() const;
67     bool evaluateAnimations(double time) const;
68     bool hasAnimations() const;
69
70     SkPicture* picture() const { return m_recordingPicture; }
71
72     void dumpLayers(FILE*, int indentLevel) const;
73
74     void bounds(SkRect* ) const;
75     bool calcPosition(const SkRect* viewPort, SkMatrix*);
76     void clipArea(SkTDArray<SkRect>* region) const;
77     const LayerAndroid* find(FloatPoint position) const;
78     const LayerAndroid* findById(int uniqueID) const;
79     LayerAndroid* getChild(int index) const { return
80         static_cast<LayerAndroid*>(m_children[index]); }
81     bool haveClip() const { return m_haveClip; }
82     int uniqueId() const { return m_uniqueId; }
83 private:
84     bool boundsIsUnique(SkTDArray<SkRect>* region, const SkRect& local) const;
85     void clipInner(SkTDArray<SkRect>* region, const SkRect& local) const;
86     void paintChildren(const SkRect* viewPort, SkCanvas* canvas, float opacity);
87     void paintMe(const SkRect* viewPort, SkCanvas* canvas,
88                  float opacity);
89
90     bool m_isRootLayer;
91     bool m_haveContents;
92     bool m_drawsContent;
93     bool m_haveImage;
94     bool m_haveClip;
95
96     SkPicture* m_recordingPicture;
97
98     typedef HashMap<String, RefPtr<AndroidAnimation> > KeyframesMap;
99     KeyframesMap m_animations;
100     FindOnPage* m_findOnPage;
101     int m_uniqueId;
102 };
103
104 }
105
106 #endif // USE(ACCELERATED_COMPOSITING)
107
108 #endif  // LayerAndroid_h