| OLD | NEW |
| (Empty) |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "WebLayerTreeViewImpl.h" | |
| 7 | |
| 8 #include "WebLayerImpl.h" | |
| 9 #include "WebToCCInputHandlerAdapter.h" | |
| 10 #include "cc/font_atlas.h" | |
| 11 #include "cc/input_handler.h" | |
| 12 #include "cc/layer.h" | |
| 13 #include "cc/layer_tree_host.h" | |
| 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | |
| 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebInputHandler.h" | |
| 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" | |
| 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeView.h" | |
| 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewCli
ent.h" | |
| 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h
" | |
| 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | |
| 21 #include "webcore_convert.h" | |
| 22 | |
| 23 using namespace cc; | |
| 24 | |
| 25 namespace WebKit { | |
| 26 | |
| 27 WebLayerTreeView* WebLayerTreeView::create(WebLayerTreeViewClient* client, const
WebLayer& root, const WebLayerTreeView::Settings& settings) | |
| 28 { | |
| 29 scoped_ptr<WebLayerTreeViewImpl> layerTreeViewImpl(new WebLayerTreeViewImpl(
client)); | |
| 30 if (!layerTreeViewImpl->initialize(settings)) | |
| 31 return 0; | |
| 32 layerTreeViewImpl->setRootLayer(root); | |
| 33 return layerTreeViewImpl.release(); | |
| 34 } | |
| 35 | |
| 36 WebLayerTreeViewImpl::WebLayerTreeViewImpl(WebLayerTreeViewClient* client) | |
| 37 : m_client(client) | |
| 38 { | |
| 39 } | |
| 40 | |
| 41 WebLayerTreeViewImpl::~WebLayerTreeViewImpl() | |
| 42 { | |
| 43 } | |
| 44 | |
| 45 bool WebLayerTreeViewImpl::initialize(const WebLayerTreeView::Settings& webSetti
ngs) | |
| 46 { | |
| 47 CCLayerTreeSettings settings; | |
| 48 settings.acceleratePainting = webSettings.acceleratePainting; | |
| 49 settings.showFPSCounter = webSettings.showFPSCounter; | |
| 50 settings.showPlatformLayerTree = webSettings.showPlatformLayerTree; | |
| 51 settings.showPaintRects = webSettings.showPaintRects; | |
| 52 settings.renderVSyncEnabled = webSettings.renderVSyncEnabled; | |
| 53 settings.refreshRate = webSettings.refreshRate; | |
| 54 settings.defaultTileSize = convert(webSettings.defaultTileSize); | |
| 55 settings.maxUntiledLayerSize = convert(webSettings.maxUntiledLayerSize); | |
| 56 m_layerTreeHost = CCLayerTreeHost::create(this, settings); | |
| 57 if (!m_layerTreeHost.get()) | |
| 58 return false; | |
| 59 return true; | |
| 60 } | |
| 61 | |
| 62 void WebLayerTreeViewImpl::setSurfaceReady() | |
| 63 { | |
| 64 m_layerTreeHost->setSurfaceReady(); | |
| 65 } | |
| 66 | |
| 67 void WebLayerTreeViewImpl::setRootLayer(const WebLayer& root) | |
| 68 { | |
| 69 m_layerTreeHost->setRootLayer(static_cast<const WebLayerImpl*>(&root)->layer
()); | |
| 70 } | |
| 71 | |
| 72 void WebLayerTreeViewImpl::clearRootLayer() | |
| 73 { | |
| 74 m_layerTreeHost->setRootLayer(scoped_refptr<LayerChromium>()); | |
| 75 } | |
| 76 | |
| 77 void WebLayerTreeViewImpl::setViewportSize(const WebSize& layoutViewportSize, co
nst WebSize& deviceViewportSize) | |
| 78 { | |
| 79 if (!deviceViewportSize.isEmpty()) | |
| 80 m_layerTreeHost->setViewportSize(convert(layoutViewportSize), convert(de
viceViewportSize)); | |
| 81 else | |
| 82 m_layerTreeHost->setViewportSize(convert(layoutViewportSize), convert(la
youtViewportSize)); | |
| 83 } | |
| 84 | |
| 85 WebSize WebLayerTreeViewImpl::layoutViewportSize() const | |
| 86 { | |
| 87 return convert(m_layerTreeHost->layoutViewportSize()); | |
| 88 } | |
| 89 | |
| 90 WebSize WebLayerTreeViewImpl::deviceViewportSize() const | |
| 91 { | |
| 92 return convert(m_layerTreeHost->deviceViewportSize()); | |
| 93 } | |
| 94 | |
| 95 void WebLayerTreeViewImpl::setDeviceScaleFactor(const float deviceScaleFactor) | |
| 96 { | |
| 97 m_layerTreeHost->setDeviceScaleFactor(deviceScaleFactor); | |
| 98 } | |
| 99 | |
| 100 float WebLayerTreeViewImpl::deviceScaleFactor() const | |
| 101 { | |
| 102 return m_layerTreeHost->deviceScaleFactor(); | |
| 103 } | |
| 104 | |
| 105 void WebLayerTreeViewImpl::setBackgroundColor(WebColor color) | |
| 106 { | |
| 107 m_layerTreeHost->setBackgroundColor(color); | |
| 108 } | |
| 109 | |
| 110 void WebLayerTreeViewImpl::setHasTransparentBackground(bool transparent) | |
| 111 { | |
| 112 m_layerTreeHost->setHasTransparentBackground(transparent); | |
| 113 } | |
| 114 | |
| 115 void WebLayerTreeViewImpl::setVisible(bool visible) | |
| 116 { | |
| 117 m_layerTreeHost->setVisible(visible); | |
| 118 } | |
| 119 | |
| 120 void WebLayerTreeViewImpl::setPageScaleFactorAndLimits(float pageScaleFactor, fl
oat minimum, float maximum) | |
| 121 { | |
| 122 m_layerTreeHost->setPageScaleFactorAndLimits(pageScaleFactor, minimum, maxim
um); | |
| 123 } | |
| 124 | |
| 125 void WebLayerTreeViewImpl::startPageScaleAnimation(const WebPoint& scroll, bool
useAnchor, float newPageScale, double durationSec) | |
| 126 { | |
| 127 m_layerTreeHost->startPageScaleAnimation(IntSize(scroll.x, scroll.y), useAnc
hor, newPageScale, durationSec); | |
| 128 } | |
| 129 | |
| 130 void WebLayerTreeViewImpl::setNeedsAnimate() | |
| 131 { | |
| 132 m_layerTreeHost->setNeedsAnimate(); | |
| 133 } | |
| 134 | |
| 135 void WebLayerTreeViewImpl::setNeedsRedraw() | |
| 136 { | |
| 137 m_layerTreeHost->setNeedsRedraw(); | |
| 138 } | |
| 139 | |
| 140 bool WebLayerTreeViewImpl::commitRequested() const | |
| 141 { | |
| 142 return m_layerTreeHost->commitRequested(); | |
| 143 } | |
| 144 | |
| 145 void WebLayerTreeViewImpl::composite() | |
| 146 { | |
| 147 if (CCProxy::hasImplThread()) | |
| 148 m_layerTreeHost->setNeedsCommit(); | |
| 149 else | |
| 150 m_layerTreeHost->composite(); | |
| 151 } | |
| 152 | |
| 153 void WebLayerTreeViewImpl::updateAnimations(double frameBeginTime) | |
| 154 { | |
| 155 m_layerTreeHost->updateAnimations(frameBeginTime); | |
| 156 } | |
| 157 | |
| 158 bool WebLayerTreeViewImpl::compositeAndReadback(void *pixels, const WebRect& rec
t) | |
| 159 { | |
| 160 return m_layerTreeHost->compositeAndReadback(pixels, convert(rect)); | |
| 161 } | |
| 162 | |
| 163 void WebLayerTreeViewImpl::finishAllRendering() | |
| 164 { | |
| 165 m_layerTreeHost->finishAllRendering(); | |
| 166 } | |
| 167 | |
| 168 void WebLayerTreeViewImpl::renderingStats(WebRenderingStats& stats) const | |
| 169 { | |
| 170 CCRenderingStats ccStats; | |
| 171 m_layerTreeHost->renderingStats(&ccStats); | |
| 172 | |
| 173 stats.numAnimationFrames = ccStats.numAnimationFrames; | |
| 174 stats.numFramesSentToScreen = ccStats.numFramesSentToScreen; | |
| 175 stats.droppedFrameCount = ccStats.droppedFrameCount; | |
| 176 stats.totalPaintTimeInSeconds = ccStats.totalPaintTimeInSeconds; | |
| 177 stats.totalRasterizeTimeInSeconds = ccStats.totalRasterizeTimeInSeconds; | |
| 178 stats.totalCommitTimeInSeconds = ccStats.totalCommitTimeInSeconds; | |
| 179 stats.totalCommitCount = ccStats.totalCommitCount; | |
| 180 stats.numImplThreadScrolls = ccStats.numImplThreadScrolls; | |
| 181 stats.numMainThreadScrolls = ccStats.numMainThreadScrolls; | |
| 182 } | |
| 183 | |
| 184 void WebLayerTreeViewImpl::setFontAtlas(SkBitmap bitmap, WebRect asciiToWebRectT
able[128], int fontHeight) | |
| 185 { | |
| 186 IntRect asciiToRectTable[128]; | |
| 187 for (int i = 0; i < 128; ++i) | |
| 188 asciiToRectTable[i] = convert(asciiToWebRectTable[i]); | |
| 189 scoped_ptr<CCFontAtlas> fontAtlas = CCFontAtlas::create(bitmap, asciiToRectT
able, fontHeight); | |
| 190 m_layerTreeHost->setFontAtlas(fontAtlas.Pass()); | |
| 191 } | |
| 192 | |
| 193 void WebLayerTreeViewImpl::loseCompositorContext(int numTimes) | |
| 194 { | |
| 195 m_layerTreeHost->loseContext(numTimes); | |
| 196 } | |
| 197 | |
| 198 void WebLayerTreeViewImpl::willBeginFrame() | |
| 199 { | |
| 200 m_client->willBeginFrame(); | |
| 201 } | |
| 202 | |
| 203 void WebLayerTreeViewImpl::didBeginFrame() | |
| 204 { | |
| 205 m_client->didBeginFrame(); | |
| 206 } | |
| 207 | |
| 208 void WebLayerTreeViewImpl::animate(double monotonicFrameBeginTime) | |
| 209 { | |
| 210 m_client->updateAnimations(monotonicFrameBeginTime); | |
| 211 } | |
| 212 | |
| 213 void WebLayerTreeViewImpl::layout() | |
| 214 { | |
| 215 m_client->layout(); | |
| 216 } | |
| 217 | |
| 218 void WebLayerTreeViewImpl::applyScrollAndScale(const cc::IntSize& scrollDelta, f
loat pageScale) | |
| 219 { | |
| 220 m_client->applyScrollAndScale(convert(scrollDelta), pageScale); | |
| 221 } | |
| 222 | |
| 223 scoped_ptr<WebCompositorOutputSurface> WebLayerTreeViewImpl::createOutputSurface
() | |
| 224 { | |
| 225 return scoped_ptr<WebCompositorOutputSurface>(m_client->createOutputSurface(
)); | |
| 226 } | |
| 227 | |
| 228 void WebLayerTreeViewImpl::didRecreateOutputSurface(bool success) | |
| 229 { | |
| 230 m_client->didRecreateOutputSurface(success); | |
| 231 } | |
| 232 | |
| 233 scoped_ptr<CCInputHandler> WebLayerTreeViewImpl::createInputHandler() | |
| 234 { | |
| 235 scoped_ptr<CCInputHandler> ret; | |
| 236 scoped_ptr<WebInputHandler> handler(m_client->createInputHandler()); | |
| 237 if (handler) | |
| 238 ret = WebToCCInputHandlerAdapter::create(handler.Pass()); | |
| 239 return ret.Pass(); | |
| 240 } | |
| 241 | |
| 242 void WebLayerTreeViewImpl::willCommit() | |
| 243 { | |
| 244 m_client->willCommit(); | |
| 245 } | |
| 246 | |
| 247 void WebLayerTreeViewImpl::didCommit() | |
| 248 { | |
| 249 m_client->didCommit(); | |
| 250 } | |
| 251 | |
| 252 void WebLayerTreeViewImpl::didCommitAndDrawFrame() | |
| 253 { | |
| 254 m_client->didCommitAndDrawFrame(); | |
| 255 } | |
| 256 | |
| 257 void WebLayerTreeViewImpl::didCompleteSwapBuffers() | |
| 258 { | |
| 259 m_client->didCompleteSwapBuffers(); | |
| 260 } | |
| 261 | |
| 262 void WebLayerTreeViewImpl::scheduleComposite() | |
| 263 { | |
| 264 m_client->scheduleComposite(); | |
| 265 } | |
| 266 | |
| 267 } // namespace WebKit | |
| OLD | NEW |