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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
|
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
* Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2012 Company 100, Inc.
* Copyright (C) 2014-2019 Igalia S.L.
*
* 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 INC. 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 INC. 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 "LayerTreeHost.h"
#if USE(COORDINATED_GRAPHICS)
#include "CoordinatedSceneState.h"
#include "DrawingArea.h"
#include "WebPageInlines.h"
#include "WebPageProxyMessages.h"
#include "WebProcess.h"
#include <WebCore/AsyncScrollingCoordinator.h>
#include <WebCore/Chrome.h>
#include <WebCore/Damage.h>
#include <WebCore/GraphicsLayerCoordinated.h>
#include <WebCore/LocalFrame.h>
#include <WebCore/LocalFrameView.h>
#include <WebCore/NativeImage.h>
#include <WebCore/PageOverlayController.h>
#include <WebCore/RenderLayerBacking.h>
#include <WebCore/RenderView.h>
#include <WebCore/ScrollingThread.h>
#include <WebCore/Settings.h>
#include <WebCore/ThreadedScrollingTree.h>
#include <wtf/SetForScope.h>
#include <wtf/SystemTracing.h>
#include <wtf/TZoneMallocInlines.h>
#if USE(CAIRO)
#include <WebCore/CairoPaintingEngine.h>
#elif USE(SKIA)
#include <WebCore/SkiaPaintingEngine.h>
#endif
#if USE(GLIB_EVENT_LOOP)
#include <wtf/glib/RunLoopSourcePriority.h>
#endif
namespace WebKit {
using namespace WebCore;
WTF_MAKE_TZONE_ALLOCATED_IMPL(LayerTreeHost);
#if HAVE(DISPLAY_LINK)
LayerTreeHost::LayerTreeHost(WebPage& webPage)
#else
LayerTreeHost::LayerTreeHost(WebPage& webPage, WebCore::PlatformDisplayID displayID)
#endif
: m_webPage(webPage)
, m_sceneState(CoordinatedSceneState::create())
, m_layerFlushTimer(RunLoop::main(), this, &LayerTreeHost::layerFlushTimerFired)
#if !HAVE(DISPLAY_LINK)
, m_displayID(displayID)
#endif
#if USE(CAIRO)
, m_paintingEngine(Cairo::PaintingEngine::create())
#elif USE(SKIA)
, m_skiaPaintingEngine(SkiaPaintingEngine::create())
#endif
{
{
auto& rootLayer = m_sceneState->rootLayer();
#if ENABLE(DAMAGE_TRACKING)
rootLayer.setDamagePropagation(webPage.corePage()->settings().propagateDamagingInformation());
#endif
Locker locker { rootLayer.lock() };
rootLayer.setAnchorPoint(FloatPoint3D(0, 0, 0));
rootLayer.setSize(m_webPage.size());
}
#if USE(GLIB_EVENT_LOOP)
m_layerFlushTimer.setPriority(RunLoopSourcePriority::LayerFlushTimer);
m_layerFlushTimer.setName("[WebKit] LayerTreeHost"_s);
#endif
scheduleLayerFlush();
#if HAVE(DISPLAY_LINK)
m_compositor = ThreadedCompositor::create(*this);
#else
m_compositor = ThreadedCompositor::create(*this, *this, displayID);
#endif
#if ENABLE(DAMAGE_TRACKING)
auto damagePropagation = ([](const Settings& settings) {
if (!settings.propagateDamagingInformation())
return Damage::Propagation::None;
if (settings.unifyDamagedRegions())
return Damage::Propagation::Unified;
return Damage::Propagation::Region;
})(webPage.corePage()->settings());
m_compositor->setDamagePropagation(damagePropagation);
#endif
m_layerTreeContext.contextID = m_compositor->surfaceID();
}
LayerTreeHost::~LayerTreeHost()
{
if (m_forceRepaintAsync.callback)
m_forceRepaintAsync.callback();
cancelPendingLayerFlush();
m_sceneState->invalidate();
#if USE(SKIA)
m_skiaPaintingEngine = nullptr;
#endif
m_compositor->invalidate();
}
void LayerTreeHost::setLayerTreeStateIsFrozen(bool isFrozen)
{
if (m_layerTreeStateIsFrozen == isFrozen)
return;
m_layerTreeStateIsFrozen = isFrozen;
if (m_layerTreeStateIsFrozen)
cancelPendingLayerFlush();
else
scheduleLayerFlush();
}
void LayerTreeHost::scheduleLayerFlush()
{
WTFEmitSignpost(this, ScheduleLayerFlush, "isWaitingForRenderer %i", m_isWaitingForRenderer);
if (m_layerTreeStateIsFrozen)
return;
if (m_webPage.size().isEmpty())
return;
if (m_isWaitingForRenderer) {
m_scheduledWhileWaitingForRenderer = true;
return;
}
if (!m_layerFlushTimer.isActive())
m_layerFlushTimer.startOneShot(0_s);
}
void LayerTreeHost::cancelPendingLayerFlush()
{
m_layerFlushTimer.stop();
}
void LayerTreeHost::flushLayers()
{
if (m_layerTreeStateIsFrozen)
return;
#if PLATFORM(GTK) || PLATFORM(WPE)
TraceScope traceScope(FlushPendingLayerChangesStart, FlushPendingLayerChangesEnd);
#endif
Ref page { m_webPage };
page->updateRendering();
page->flushPendingEditorStateUpdate();
if (m_overlayCompositingLayer)
m_overlayCompositingLayer->flushCompositingState(visibleContentsRect());
OptionSet<FinalizeRenderingUpdateFlags> flags;
#if PLATFORM(GTK)
if (!m_transientZoom)
flags.add(FinalizeRenderingUpdateFlags::ApplyScrollingTreeLayerPositions);
#else
flags.add(FinalizeRenderingUpdateFlags::ApplyScrollingTreeLayerPositions);
#endif
page->finalizeRenderingUpdate(flags);
if (m_pendingResize) {
m_compositor->setSize(page->size(), page->deviceScaleFactor());
auto& rootLayer = m_sceneState->rootLayer();
Locker locker { rootLayer.lock() };
rootLayer.setSize(page->size());
}
#if PLATFORM(GTK)
// If we have an active transient zoom, we want the zoom to win over any changes
// that WebCore makes to the relevant layers, so re-apply our changes after flushing.
if (m_transientZoom)
applyTransientZoomToLayers(m_transientZoomScale, m_transientZoomOrigin);
#endif
#if PLATFORM(GTK) || PLATFORM(WPE)
if (auto* drawingArea = m_webPage.drawingArea())
drawingArea->dispatchPendingCallbacksAfterEnsuringDrawing();
#endif
bool didChangeSceneState = m_sceneState->flush();
if (m_compositionRequired || m_pendingResize || m_forceFrameSync || didChangeSceneState)
commitSceneState();
m_compositionRequired = false;
m_pendingResize = false;
m_forceFrameSync = false;
page->didUpdateRendering();
// Eject any backing stores whose only reference is held in the HashMap cache.
m_imageBackingStores.removeIf([](auto& it) {
return it.value->hasOneRef();
});
}
void LayerTreeHost::layerFlushTimerFired()
{
WTFBeginSignpost(this, LayerFlushTimerFired, "isWaitingForRenderer %i", m_isWaitingForRenderer);
if (m_isSuspended) {
WTFEndSignpost(this, LayerFlushTimerFired);
return;
}
if (m_isWaitingForRenderer) {
WTFEndSignpost(this, LayerFlushTimerFired);
return;
}
#if !HAVE(DISPLAY_LINK)
// If a force-repaint callback was registered, we should force a 'frame sync' that
// will guarantee us a call to renderNextFrame() once the update is complete.
if (m_forceRepaintAsync.callback)
m_forceFrameSync = true;
#endif
flushLayers();
WTFEndSignpost(this, LayerFlushTimerFired);
}
void LayerTreeHost::updateRootLayer()
{
Vector<Ref<CoordinatedPlatformLayer>> children;
if (m_rootCompositingLayer) {
children.append(downcast<GraphicsLayerCoordinated>(m_rootCompositingLayer)->coordinatedPlatformLayer());
if (m_overlayCompositingLayer)
children.append(downcast<GraphicsLayerCoordinated>(m_overlayCompositingLayer)->coordinatedPlatformLayer());
}
m_sceneState->setRootLayerChildren(WTFMove(children));
}
void LayerTreeHost::setRootCompositingLayer(GraphicsLayer* graphicsLayer)
{
if (m_rootCompositingLayer == graphicsLayer)
return;
m_rootCompositingLayer = graphicsLayer;
updateRootLayer();
}
void LayerTreeHost::setViewOverlayRootLayer(GraphicsLayer* graphicsLayer)
{
if (m_overlayCompositingLayer == graphicsLayer)
return;
m_overlayCompositingLayer = graphicsLayer;
updateRootLayer();
}
void LayerTreeHost::forceRepaint()
{
#if !HAVE(DISPLAY_LINK)
// This is necessary for running layout tests. Since in this case we are not waiting for a UIProcess to reply nicely.
// Instead we are just triggering forceRepaint. But we still want to have the scripted animation callbacks being executed.
if (auto* frameView = m_webPage.localMainFrameView())
frameView->updateLayoutAndStyleIfNeededRecursive();
// We need to schedule another flush, otherwise the forced paint might cancel a later expected flush.
m_forceFrameSync = true;
scheduleLayerFlush();
if (!m_isWaitingForRenderer)
flushLayers();
#else
if (m_isWaitingForRenderer) {
if (m_forceRepaintAsync.callback)
m_pendingForceRepaint = true;
return;
}
m_pendingForceRepaint = false;
m_webPage.corePage()->forceRepaintAllFrames();
m_forceFrameSync = true;
cancelPendingLayerFlush();
flushLayers();
m_sceneState->waitUntilPaintingComplete();
#endif
}
void LayerTreeHost::forceRepaintAsync(CompletionHandler<void()>&& callback)
{
#if !HAVE(DISPLAY_LINK)
scheduleLayerFlush();
// We want a clean repaint, meaning that if we're currently waiting for the renderer
// to finish an update, we'll have to schedule another flush when it's done.
ASSERT(!m_forceRepaintAsync.callback);
m_forceRepaintAsync.callback = WTFMove(callback);
m_forceRepaintAsync.needsFreshFlush = m_scheduledWhileWaitingForRenderer;
#else
ASSERT(!m_forceRepaintAsync.callback);
m_forceRepaintAsync.callback = WTFMove(callback);
forceRepaint();
if (m_pendingForceRepaint)
m_forceRepaintAsync.compositionRequestID = std::nullopt;
else
m_forceRepaintAsync.compositionRequestID = m_compositionRequestID;
#endif
}
#if PLATFORM(GTK) || PLATFORM(WPE)
void LayerTreeHost::ensureDrawing()
{
m_forceFrameSync = true;
scheduleLayerFlush();
}
#endif
void LayerTreeHost::sizeDidChange()
{
m_pendingResize = true;
if (m_isWaitingForRenderer)
scheduleLayerFlush();
else {
cancelPendingLayerFlush();
flushLayers();
}
}
void LayerTreeHost::pauseRendering()
{
m_isSuspended = true;
m_compositor->suspend();
}
void LayerTreeHost::resumeRendering()
{
m_isSuspended = false;
m_compositor->resume();
scheduleLayerFlush();
}
GraphicsLayerFactory* LayerTreeHost::graphicsLayerFactory()
{
return this;
}
FloatRect LayerTreeHost::visibleContentsRect() const
{
if (auto* localMainFrameView = m_webPage.localMainFrameView())
return FloatRect({ }, localMainFrameView->sizeForVisibleContent(ScrollableArea::VisibleContentRectIncludesScrollbars::Yes));
return m_webPage.bounds();
}
void LayerTreeHost::backgroundColorDidChange()
{
m_compositor->backgroundColorDidChange();
}
void LayerTreeHost::attachLayer(CoordinatedPlatformLayer& layer)
{
#if ENABLE(DAMAGE_TRACKING)
layer.setDamagePropagation(webPage().corePage()->settings().propagateDamagingInformation());
#endif
m_sceneState->addLayer(layer);
}
void LayerTreeHost::detachLayer(CoordinatedPlatformLayer& layer)
{
m_sceneState->removeLayer(layer);
}
void LayerTreeHost::notifyCompositionRequired()
{
#if ENABLE(SCROLLING_THREAD)
if (ScrollingThread::isCurrentThread()) {
m_compositionRequiredInScrollingThread = true;
return;
}
#endif
m_compositionRequired = true;
}
bool LayerTreeHost::isCompositionRequiredOrOngoing() const
{
return m_compositionRequired || m_forceFrameSync || m_compositor->isActive();
}
void LayerTreeHost::requestComposition()
{
#if ENABLE(SCROLLING_THREAD)
if (ScrollingThread::isCurrentThread()) {
if (!m_compositionRequiredInScrollingThread)
return;
m_compositionRequiredInScrollingThread = false;
}
#endif
m_compositor->scheduleUpdate();
}
RunLoop* LayerTreeHost::compositingRunLoop() const
{
return m_compositor->runLoop();
}
#if USE(CAIRO)
Cairo::PaintingEngine& LayerTreeHost::paintingEngine()
{
return *m_paintingEngine;
}
#endif
Ref<CoordinatedImageBackingStore> LayerTreeHost::imageBackingStore(Ref<NativeImage>&& nativeImage)
{
auto nativeImageID = nativeImage->uniqueID();
auto addResult = m_imageBackingStores.ensure(nativeImageID, [&] {
return CoordinatedImageBackingStore::create(WTFMove(nativeImage));
});
return addResult.iterator->value;
}
Ref<GraphicsLayer> LayerTreeHost::createGraphicsLayer(GraphicsLayer::Type layerType, GraphicsLayerClient& client)
{
return adoptRef(*new GraphicsLayerCoordinated(layerType, client, CoordinatedPlatformLayer::create(*this)));
}
#if !HAVE(DISPLAY_LINK)
RefPtr<DisplayRefreshMonitor> LayerTreeHost::createDisplayRefreshMonitor(PlatformDisplayID displayID)
{
ASSERT(m_displayID == displayID);
return Ref { m_compositor->displayRefreshMonitor() };
}
void LayerTreeHost::requestDisplayRefreshMonitorUpdate()
{
// Flush layers to cause a repaint. If m_isWaitingForRenderer was true at this point, the layer
// flush won't do anything, but that means there's a painting ongoing that will send the
// display refresh notification when it's done.
m_forceFrameSync = true;
scheduleLayerFlush();
}
void LayerTreeHost::handleDisplayRefreshMonitorUpdate(bool hasBeenRescheduled)
{
// Call renderNextFrame. If hasBeenRescheduled is true, the layer flush will force a repaint
// that will cause the display refresh notification to come.
renderNextFrame(hasBeenRescheduled);
}
#endif
void LayerTreeHost::willRenderFrame()
{
if (auto* drawingArea = m_webPage.drawingArea())
drawingArea->willStartRenderingUpdateDisplay();
}
void LayerTreeHost::didRenderFrame()
{
if (auto* drawingArea = m_webPage.drawingArea())
drawingArea->didCompleteRenderingUpdateDisplay();
}
#if HAVE(DISPLAY_LINK)
void LayerTreeHost::didComposite(uint32_t compositionResponseID)
{
WTFBeginSignpost(this, DidComposite, "compositionRequestID %i, compositionResponseID %i", m_compositionRequestID, compositionResponseID);
if (m_forceRepaintAsync.callback && m_forceRepaintAsync.compositionRequestID && compositionResponseID >= *m_forceRepaintAsync.compositionRequestID) {
m_forceRepaintAsync.callback();
m_forceRepaintAsync.compositionRequestID = std::nullopt;
}
if (!m_isWaitingForRenderer || m_compositionRequestID == compositionResponseID) {
m_isWaitingForRenderer = false;
bool scheduledWhileWaitingForRenderer = std::exchange(m_scheduledWhileWaitingForRenderer, false);
if (m_pendingForceRepaint) {
if (m_layerTreeStateIsFrozen) {
if (m_forceRepaintAsync.callback) {
m_forceRepaintAsync.callback();
m_forceRepaintAsync.compositionRequestID = std::nullopt;
}
} else {
forceRepaint();
if (m_forceRepaintAsync.callback)
m_forceRepaintAsync.compositionRequestID = m_compositionRequestID;
}
} else if (!m_isSuspended && !m_layerTreeStateIsFrozen && (scheduledWhileWaitingForRenderer || m_layerFlushTimer.isActive())) {
cancelPendingLayerFlush();
flushLayers();
}
}
WTFEndSignpost(this, DidComposite);
}
#endif
void LayerTreeHost::commitSceneState()
{
m_isWaitingForRenderer = true;
m_compositionRequestID = m_compositor->requestComposition();
WTFEmitSignpost(this, CommitSceneState, "compositionRequestID %i", m_compositionRequestID);
}
#if !HAVE(DISPLAY_LINK)
void LayerTreeHost::renderNextFrame(bool forceRepaint)
{
WTFBeginSignpost(this, RenderNextFrame);
m_isWaitingForRenderer = false;
bool scheduledWhileWaitingForRenderer = std::exchange(m_scheduledWhileWaitingForRenderer, false);
if (m_forceRepaintAsync.callback) {
// If the asynchronous force-repaint needs a separate fresh flush, it was due to
// the force-repaint request being registered while CoordinatedLayerTreeHost was
// waiting for the renderer to finish an update.
ASSERT(!m_forceRepaintAsync.needsFreshFlush || scheduledWhileWaitingForRenderer);
// Execute the callback if another layer flush and the subsequent state update
// aren't needed. If they are, the callback will be executed when this function
// is called after the next update.
if (!m_forceRepaintAsync.needsFreshFlush)
m_forceRepaintAsync.callback();
m_forceRepaintAsync.needsFreshFlush = false;
}
if (scheduledWhileWaitingForRenderer || m_layerFlushTimer.isActive() || forceRepaint) {
m_layerFlushTimer.stop();
if (forceRepaint)
m_forceFrameSync = true;
layerFlushTimerFired();
}
WTFEndSignpost(this, RenderNextFrame);
}
#endif
#if PLATFORM(GTK)
FloatPoint LayerTreeHost::constrainTransientZoomOrigin(double scale, FloatPoint origin) const
{
auto* frameView = m_webPage.localMainFrameView();
if (!frameView)
return origin;
FloatRect visibleContentRect = frameView->visibleContentRectIncludingScrollbars();
FloatPoint constrainedOrigin = visibleContentRect.location();
constrainedOrigin.moveBy(-origin);
IntSize scaledTotalContentsSize = frameView->totalContentsSize();
scaledTotalContentsSize.scale(scale * m_webPage.viewScaleFactor() / m_webPage.totalScaleFactor());
// Scaling may have exposed the overhang area, so we need to constrain the final
// layer position exactly like scrolling will once it's committed, to ensure that
// scrolling doesn't make the view jump.
constrainedOrigin = ScrollableArea::constrainScrollPositionForOverhang(roundedIntRect(visibleContentRect),
scaledTotalContentsSize, roundedIntPoint(constrainedOrigin), frameView->scrollOrigin(),
frameView->headerHeight(), frameView->footerHeight());
constrainedOrigin.moveBy(-visibleContentRect.location());
constrainedOrigin = -constrainedOrigin;
return constrainedOrigin;
}
CoordinatedPlatformLayer* LayerTreeHost::layerForTransientZoom() const
{
auto* frameView = m_webPage.localMainFrameView();
if (!frameView)
return nullptr;
RenderLayerBacking* renderViewBacking = frameView->renderView()->layer()->backing();
if (!renderViewBacking)
return nullptr;
auto* scaledLayer = renderViewBacking->contentsContainmentLayer();
if (!scaledLayer)
scaledLayer = renderViewBacking->graphicsLayer();
ASSERT(scaledLayer);
return &downcast<GraphicsLayerCoordinated>(*scaledLayer).coordinatedPlatformLayer();
}
void LayerTreeHost::applyTransientZoomToLayers(double scale, FloatPoint origin)
{
// FIXME: Scrollbars should stay in-place and change height while zooming.
FloatPoint constrainedOrigin = constrainTransientZoomOrigin(scale, origin);
auto* zoomLayer = layerForTransientZoom();
TransformationMatrix transform;
transform.translate(constrainedOrigin.x(), constrainedOrigin.y());
transform.scale(scale);
zoomLayer->setTransform(transform);
zoomLayer->setAnchorPoint(FloatPoint3D());
zoomLayer->setPosition(FloatPoint());
}
void LayerTreeHost::adjustTransientZoom(double scale, FloatPoint origin)
{
m_transientZoom = true;
m_transientZoomScale = scale;
m_transientZoomOrigin = origin;
applyTransientZoomToLayers(m_transientZoomScale, m_transientZoomOrigin);
}
void LayerTreeHost::commitTransientZoom(double scale, FloatPoint origin)
{
if (m_transientZoomScale == scale) {
// If the page scale is already the target scale, setPageScaleFactor() will short-circuit
// and not apply the transform, so we can't depend on it to do so.
TransformationMatrix finalTransform;
finalTransform.scale(scale);
layerForTransientZoom()->setTransform(finalTransform);
}
m_transientZoom = false;
m_transientZoomScale = 1;
m_transientZoomOrigin = FloatPoint();
}
#endif
#if PLATFORM(WPE) && USE(GBM) && ENABLE(WPE_PLATFORM)
void LayerTreeHost::preferredBufferFormatsDidChange()
{
m_compositor->preferredBufferFormatsDidChange();
}
#endif
} // namespace WebKit
#endif // USE(COORDINATED_GRAPHICS)
|