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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/*
* 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 "RefPtr.h"
#include "SkColor.h"
#include "SkLayer.h"
#include "StringHash.h"
#include <wtf/HashMap.h>
class SkCanvas;
class SkMatrix;
class SkPicture;
namespace android {
class DrawExtra;
}
using namespace android;
struct SkLength {
enum SkLengthType { Undefined, Auto, Relative, Percent, Fixed, Static, Intrinsic, MinIntrinsic };
SkLengthType type;
SkScalar value;
SkLength() {
type = Undefined;
value = 0;
}
bool defined() const {
if (type == Undefined)
return false;
return true;
}
float calcFloatValue(float max) const {
switch (type) {
case Percent:
return (max * value) / 100.0f;
case Fixed:
return value;
default:
return value;
}
}
};
namespace WebCore {
class AndroidAnimation;
class LayerAndroid : public SkLayer {
public:
LayerAndroid(bool isRootLayer);
LayerAndroid(const LayerAndroid& layer);
LayerAndroid(SkPicture* );
virtual ~LayerAndroid();
static int instancesCount();
void setTranslation(SkScalar x, SkScalar y) { m_translation.set(x, y); }
void setRotation(SkScalar a) { m_angleTransform = a; m_doRotation = true; }
void setScale(SkScalar x, SkScalar y) { m_scale.set(x, y); }
SkPoint translation() const { return m_translation; }
SkRect bounds() const {
const SkPoint& pos = this->getPosition();
const SkSize& size = this->getSize();
SkRect rect;
rect.set(pos.fX, pos.fY,
pos.fX + size.width(),
pos.fY + size.height());
rect.offset(m_translation.fX, m_translation.fY);
return rect;
}
void setFixedPosition(SkLength left, // CSS left property
SkLength top, // CSS top property
SkLength right, // CSS right property
SkLength bottom, // CSS bottom property
int width, // visible overflow width
int height) { // visible overflow height
m_fixedLeft = left;
m_fixedTop = top;
m_fixedRight = right;
m_fixedBottom = bottom;
m_fixedWidth = width;
m_fixedHeight = height;
m_isFixed = true;
}
/** Call that method to position the layer relative to another one.
We can only be set relative to a fixed layer.
The parameter is not refcounted -- we only save its ID as we
need to reconnect with the correct layer once we copy the tree
to the UI.
*/
void setRelativeTo(LayerAndroid* container);
void setBackgroundColor(SkColor color);
void setMaskLayer(LayerAndroid*);
void setMasksToBounds(bool);
void setIsRootLayer(bool isRootLayer) { m_isRootLayer = isRootLayer; }
SkPicture* recordContext();
void addAnimation(PassRefPtr<AndroidAnimation> anim);
void removeAnimation(const String& name);
bool evaluateAnimations() const;
bool evaluateAnimations(double time) const;
bool hasAnimations() const;
SkPicture* picture() const { return m_recordingPicture; }
// remove layers bounds from visible rectangle to show what can be
// scrolled into view; returns original minus layer bounds in global space.
SkRect subtractLayers(const SkRect& visibleRect) const;
void dumpLayers(FILE*, int indentLevel) const;
void dumpToLog() const;
/** Call this to be sure all fixed descendants correctly have
a pointer to their container layer before we try
to update the positions. The fixed layer we point to is
not refcounted (no need, it's already in the layers' tree).
This call is recursive, so it should be called on the root of the
hierarchy.
*/
void ensureFixedLayersForDescendants(const LayerAndroid* rootLayer);
/** Call this with the current viewport (scrolling, zoom) to update
the position of the fixed layers.
This call is recursive, so it should be called on the root of the
hierarchy.
*/
void updateFixedLayersPositions(const SkRect& viewPort);
/** Call this to update the position attribute, so that later calls
like bounds() will report the corrected position.
This call is recursive, so it should be called on the root of the
hierarchy.
*/
void updatePositions();
void clipArea(SkTDArray<SkRect>* region) const;
const LayerAndroid* find(int x, int y) const;
const LayerAndroid* findById(int uniqueID) const;
LayerAndroid* getChild(int index) const {
return static_cast<LayerAndroid*>(this->INHERITED::getChild(index));
}
void setExtra(DrawExtra* extra); // does not assign ownership
int uniqueId() const { return m_uniqueId; }
protected:
virtual void onDraw(SkCanvas*, SkScalar opacity);
private:
#if DUMP_NAV_CACHE
friend class CachedLayer::Debug; // debugging access only
#endif
void bounds(SkRect* ) const;
bool prepareContext(bool force = false);
void clipInner(SkTDArray<SkRect>* region, const SkRect& local) const;
bool m_isRootLayer;
bool m_drawsContent;
bool m_haveClip;
bool m_doRotation;
bool m_isFixed;
bool m_isRelativeTo;
bool m_backgroundColorSet;
SkLength m_fixedLeft;
SkLength m_fixedTop;
SkLength m_fixedRight;
SkLength m_fixedBottom;
int m_fixedWidth;
int m_fixedHeight;
int m_relativeFixedLayerID;
SkPoint m_deltaPosition;
SkPoint m_translation;
SkPoint m_scale;
SkScalar m_angleTransform;
SkColor m_backgroundColor;
SkPicture* m_recordingPicture;
typedef HashMap<String, RefPtr<AndroidAnimation> > KeyframesMap;
KeyframesMap m_animations;
DrawExtra* m_extra;
int m_uniqueId;
LayerAndroid* m_relativeFixedLayer;
typedef SkLayer INHERITED;
};
}
#else
class SkPicture;
namespace WebCore {
class LayerAndroid {
public:
LayerAndroid(SkPicture* picture) :
m_recordingPicture(picture), // does not assign ownership
m_uniqueId(-1)
{}
SkPicture* picture() const { return m_recordingPicture; }
int uniqueId() const { return m_uniqueId; }
private:
SkPicture* m_recordingPicture;
int m_uniqueId;
};
}
#endif // USE(ACCELERATED_COMPOSITING)
#endif // LayerAndroid_h
|