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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "WebLayerTreeViewImpl.h"
#include "CCFontAtlas.h"
#include "CCInputHandler.h"
#include "CCLayerTreeHost.h"
#include "LayerChromium.h"
#include "WebLayerImpl.h"
#include "WebToCCInputHandlerAdapter.h"
#include <public/WebGraphicsContext3D.h>
#include <public/WebInputHandler.h>
#include <public/WebLayer.h>
#include <public/WebLayerTreeView.h>
#include <public/WebLayerTreeViewClient.h>
#include <public/WebRenderingStats.h>
#include <public/WebSize.h>
using namespace WebCore;
namespace WebKit {
WebLayerTreeView* WebLayerTreeView::create(WebLayerTreeViewClient* client, const WebLayer& root, const WebLayerTreeView::Settings& settings)
{
OwnPtr<WebLayerTreeViewImpl> layerTreeViewImpl = adoptPtr(new WebLayerTreeViewImpl(client));
if (!layerTreeViewImpl->initialize(settings))
return 0;
layerTreeViewImpl->setRootLayer(root);
return layerTreeViewImpl.leakPtr();
}
WebLayerTreeViewImpl::WebLayerTreeViewImpl(WebLayerTreeViewClient* client)
: m_client(client)
{
}
WebLayerTreeViewImpl::~WebLayerTreeViewImpl()
{
}
bool WebLayerTreeViewImpl::initialize(const WebLayerTreeView::Settings& webSettings)
{
CCLayerTreeSettings settings;
settings.acceleratePainting = webSettings.acceleratePainting;
settings.showFPSCounter = webSettings.showFPSCounter;
settings.showPlatformLayerTree = webSettings.showPlatformLayerTree;
settings.showPaintRects = webSettings.showPaintRects;
settings.renderVSyncEnabled = webSettings.renderVSyncEnabled;
settings.refreshRate = webSettings.refreshRate;
settings.defaultTileSize = webSettings.defaultTileSize;
settings.maxUntiledLayerSize = webSettings.maxUntiledLayerSize;
m_layerTreeHost = CCLayerTreeHost::create(this, settings);
if (!m_layerTreeHost)
return false;
return true;
}
void WebLayerTreeViewImpl::setSurfaceReady()
{
m_layerTreeHost->setSurfaceReady();
}
void WebLayerTreeViewImpl::setRootLayer(const WebLayer& root)
{
m_layerTreeHost->setRootLayer(static_cast<const WebLayerImpl*>(&root)->layer());
}
void WebLayerTreeViewImpl::clearRootLayer()
{
m_layerTreeHost->setRootLayer(PassRefPtr<LayerChromium>());
}
void WebLayerTreeViewImpl::setViewportSize(const WebSize& layoutViewportSize, const WebSize& deviceViewportSize)
{
if (!deviceViewportSize.isEmpty())
m_layerTreeHost->setViewportSize(layoutViewportSize, deviceViewportSize);
else
m_layerTreeHost->setViewportSize(layoutViewportSize, layoutViewportSize);
}
WebSize WebLayerTreeViewImpl::layoutViewportSize() const
{
return WebSize(m_layerTreeHost->layoutViewportSize());
}
WebSize WebLayerTreeViewImpl::deviceViewportSize() const
{
return WebSize(m_layerTreeHost->deviceViewportSize());
}
void WebLayerTreeViewImpl::setDeviceScaleFactor(const float deviceScaleFactor)
{
m_layerTreeHost->setDeviceScaleFactor(deviceScaleFactor);
}
float WebLayerTreeViewImpl::deviceScaleFactor() const
{
return m_layerTreeHost->deviceScaleFactor();
}
void WebLayerTreeViewImpl::setBackgroundColor(WebColor color)
{
m_layerTreeHost->setBackgroundColor(color);
}
void WebLayerTreeViewImpl::setHasTransparentBackground(bool transparent)
{
m_layerTreeHost->setHasTransparentBackground(transparent);
}
void WebLayerTreeViewImpl::setVisible(bool visible)
{
m_layerTreeHost->setVisible(visible);
}
void WebLayerTreeViewImpl::setPageScaleFactorAndLimits(float pageScaleFactor, float minimum, float maximum)
{
m_layerTreeHost->setPageScaleFactorAndLimits(pageScaleFactor, minimum, maximum);
}
void WebLayerTreeViewImpl::startPageScaleAnimation(const WebPoint& scroll, bool useAnchor, float newPageScale, double durationSec)
{
m_layerTreeHost->startPageScaleAnimation(IntSize(scroll.x, scroll.y), useAnchor, newPageScale, durationSec);
}
void WebLayerTreeViewImpl::setNeedsAnimate()
{
m_layerTreeHost->setNeedsAnimate();
}
void WebLayerTreeViewImpl::setNeedsRedraw()
{
m_layerTreeHost->setNeedsRedraw();
}
bool WebLayerTreeViewImpl::commitRequested() const
{
return m_layerTreeHost->commitRequested();
}
void WebLayerTreeViewImpl::composite()
{
if (CCProxy::hasImplThread())
m_layerTreeHost->setNeedsCommit();
else
m_layerTreeHost->composite();
}
void WebLayerTreeViewImpl::updateAnimations(double frameBeginTime)
{
m_layerTreeHost->updateAnimations(frameBeginTime);
}
bool WebLayerTreeViewImpl::compositeAndReadback(void *pixels, const WebRect& rect)
{
return m_layerTreeHost->compositeAndReadback(pixels, rect);
}
void WebLayerTreeViewImpl::finishAllRendering()
{
m_layerTreeHost->finishAllRendering();
}
void WebLayerTreeViewImpl::renderingStats(WebRenderingStats& stats) const
{
CCRenderingStats ccStats;
m_layerTreeHost->renderingStats(ccStats);
stats.numAnimationFrames = ccStats.numAnimationFrames;
stats.numFramesSentToScreen = ccStats.numFramesSentToScreen;
stats.droppedFrameCount = ccStats.droppedFrameCount;
stats.totalPaintTimeInSeconds = ccStats.totalPaintTimeInSeconds;
stats.totalRasterizeTimeInSeconds = ccStats.totalRasterizeTimeInSeconds;
}
void WebLayerTreeViewImpl::setFontAtlas(SkBitmap bitmap, WebRect asciiToWebRectTable[128], int fontHeight)
{
IntRect asciiToRectTable[128];
for (int i = 0; i < 128; ++i)
asciiToRectTable[i] = asciiToWebRectTable[i];
OwnPtr<CCFontAtlas> fontAtlas = CCFontAtlas::create(bitmap, asciiToRectTable, fontHeight);
m_layerTreeHost->setFontAtlas(fontAtlas.release());
}
void WebLayerTreeViewImpl::loseCompositorContext(int numTimes)
{
m_layerTreeHost->loseContext(numTimes);
}
void WebLayerTreeViewImpl::willBeginFrame()
{
m_client->willBeginFrame();
}
void WebLayerTreeViewImpl::didBeginFrame()
{
m_client->didBeginFrame();
}
void WebLayerTreeViewImpl::animate(double monotonicFrameBeginTime)
{
m_client->updateAnimations(monotonicFrameBeginTime);
}
void WebLayerTreeViewImpl::layout()
{
m_client->layout();
}
void WebLayerTreeViewImpl::applyScrollAndScale(const WebCore::IntSize& scrollDelta, float pageScale)
{
m_client->applyScrollAndScale(scrollDelta, pageScale);
}
PassOwnPtr<WebCompositorOutputSurface> WebLayerTreeViewImpl::createOutputSurface()
{
return adoptPtr(m_client->createOutputSurface());
}
void WebLayerTreeViewImpl::didRecreateOutputSurface(bool success)
{
m_client->didRecreateOutputSurface(success);
}
PassOwnPtr<CCInputHandler> WebLayerTreeViewImpl::createInputHandler()
{
OwnPtr<WebInputHandler> handler = adoptPtr(m_client->createInputHandler());
if (handler)
return WebToCCInputHandlerAdapter::create(handler.release());
return nullptr;
}
void WebLayerTreeViewImpl::willCommit()
{
m_client->willCommit();
}
void WebLayerTreeViewImpl::didCommit()
{
m_client->didCommit();
}
void WebLayerTreeViewImpl::didCommitAndDrawFrame()
{
m_client->didCommitAndDrawFrame();
}
void WebLayerTreeViewImpl::didCompleteSwapBuffers()
{
m_client->didCompleteSwapBuffers();
}
void WebLayerTreeViewImpl::scheduleComposite()
{
m_client->scheduleComposite();
}
} // namespace WebKit
|