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 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
|
/*
* Copyright (C) 2010-2021 Apple Inc. All rights reserved.
* Copyright (C) 2021 Sony Interactive Entertainment Inc.
*
* 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. ``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
* 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 "GraphicsLayerWC.h"
#if USE(GRAPHICS_LAYER_WC)
#include "WCPlatformLayerGCGL.h"
#include "WCTileGrid.h"
#include <WebCore/GraphicsContext.h>
#include <WebCore/TransformState.h>
#include <wtf/TZoneMallocInlines.h>
namespace WebKit {
using namespace WebCore;
class WCTiledBacking final : public TiledBacking {
WTF_MAKE_TZONE_ALLOCATED_INLINE(WCTiledBacking);
WTF_OVERRIDE_DELETE_FOR_CHECKED_PTR(WCTiledBacking);
public:
WCTiledBacking(GraphicsLayerWC& owner)
: m_owner(owner) { }
bool paintAndFlush(WCLayerUpdateInfo& update)
{
bool repainted = false;
for (auto& entry : m_tileGrid.tiles()) {
auto& tile = *entry.value;
WCTileUpdate tileUpdate;
tileUpdate.index = entry.key;
tileUpdate.willRemove = tile.willRemove();
if (tileUpdate.willRemove) {
update.background.tileUpdates.append(WTFMove(tileUpdate));
continue;
}
if (!tile.hasDirtyRect())
continue;
repainted = true;
float deviceScaleFactor = m_owner.deviceScaleFactor();
auto& dirtyRect = tile.dirtyRect();
IntRect scaledDirtyRect = dirtyRect;
scaledDirtyRect.scale(deviceScaleFactor);
tileUpdate.dirtyRect = scaledDirtyRect;
auto image = m_owner.createImageBuffer(dirtyRect.size(), deviceScaleFactor);
auto& context = image->context();
context.translate(-dirtyRect.x(), -dirtyRect.y());
m_owner.paintGraphicsLayerContents(context, dirtyRect);
image->flushDrawingContextAsync();
tileUpdate.backingStore.setImageBuffer(WTFMove(image));
update.background.tileUpdates.append(WTFMove(tileUpdate));
}
m_tileGrid.clearDirtyRects();
return repainted;
}
void setSize(const FloatSize& size)
{
m_tileGrid.setSize(expandedIntSize(size));
}
void setDirtyRect(const WebCore::FloatRect& rect)
{
m_tileGrid.addDirtyRect(enclosingIntRect(rect));
}
bool updateCoverageRect(const FloatRect& rect)
{
return m_tileGrid.setCoverageRect(enclosingIntRect(rect));
}
TiledBacking* tiledBacking() const { return const_cast<WCTiledBacking*>(this); };
// TiledBacking override
void setClient(TiledBackingClient*) final { }
PlatformLayerIdentifier layerIdentifier() const final { return *m_owner.primaryLayerID(); }
TileGridIdentifier primaryGridIdentifier() const final { return TileGridIdentifier { 0 }; }
std::optional<TileGridIdentifier> secondaryGridIdentifier() const final { return { }; }
void setVisibleRect(const FloatRect&) final { }
FloatRect visibleRect() const final { return { }; };
void setLayoutViewportRect(std::optional<FloatRect>) final { }
void setCoverageRect(const FloatRect& rect) final { }
FloatRect coverageRect() const final { return { }; };
bool tilesWouldChangeForCoverageRect(const FloatRect&) const final { return false; }
void setTiledScrollingIndicatorPosition(const FloatPoint&) final { }
void setObscuredContentInsets(const FloatBoxExtent&) final { }
void setVelocity(const VelocityData&) final { }
void setTileSizeUpdateDelayDisabledForTesting(bool) final { };
void setScrollability(OptionSet<Scrollability>) final { }
void prepopulateRect(const FloatRect&) final { }
void setIsInWindow(bool) final { }
bool isInWindow() const final { return m_isInWindow; }
void setTileCoverage(TileCoverage) final { }
TileCoverage tileCoverage() const final { return { }; };
FloatRect adjustTileCoverageRect(const FloatRect& coverageRect, const FloatRect& previousVisibleRect, const FloatRect& currentVisibleRect, bool sizeChanged) final { return { }; };
FloatRect adjustTileCoverageRectForScrolling(const FloatRect& coverageRect, const FloatSize& newSize, const FloatRect& previousVisibleRect, const FloatRect& currentVisibleRect, float contentsScale) final { return { }; };
void willStartLiveResize() final { };
void didEndLiveResize() final { };
IntSize tileSize() const final { return m_tileGrid.tilePixelSize(); }
FloatRect rectForTile(TileIndex) const { return { }; }
void revalidateTiles() final { }
IntRect tileGridExtent() const final { return { }; }
void setScrollingPerformanceTestingEnabled(bool flag) final { }
bool scrollingPerformanceTestingEnabled() const final { return false; };
double retainedTileBackingStoreMemory() const final { return 0; }
IntRect tileCoverageRect() const final { return { }; }
void setScrollingModeIndication(ScrollingModeIndication) final { }
void setHasMargins(bool marginTop, bool marginBottom, bool marginLeft, bool marginRight) final { }
bool hasMargins() const final { return false; };
bool hasHorizontalMargins() const final { return false; };
bool hasVerticalMargins() const final { return false; };
void setMarginSize(int) final { }
int topMarginHeight() const final { return 0; };
int bottomMarginHeight() const final { return 0; };
int leftMarginWidth() const final { return 0; };
int rightMarginWidth() const final { return 0; };
void setZoomedOutContentsScale(float) final { }
float zoomedOutContentsScale() const final { return 1; }
float tilingScaleFactor() const final { return 1; }
IntRect bounds() const final { return { { }, IntSize(m_owner.size()) }; };
IntRect boundsWithoutMargin() const final { return bounds(); };
private:
bool m_isInWindow { false };
GraphicsLayerWC& m_owner;
WCTileGrid m_tileGrid;
};
GraphicsLayerWC::GraphicsLayerWC(Type layerType, GraphicsLayerClient& client, Observer& observer)
: GraphicsLayer(layerType, client)
, m_observer(&observer)
{
m_tiledBacking = makeUnique<WCTiledBacking>(*this);
if (layerType == Type::Normal)
client.tiledBackingUsageChanged(this, true);
m_observer->graphicsLayerAdded(*this);
}
GraphicsLayerWC::~GraphicsLayerWC()
{
willBeDestroyed();
if (m_observer)
m_observer->graphicsLayerRemoved(*this);
}
std::optional<PlatformLayerIdentifier> GraphicsLayerWC::primaryLayerID() const
{
return m_layerID;
}
void GraphicsLayerWC::setNeedsDisplay()
{
setNeedsDisplayInRect({ { }, m_size }, ClipToLayer);
}
void GraphicsLayerWC::setNeedsDisplayInRect(const WebCore::FloatRect& rect, ShouldClipToLayer shouldClip)
{
if (!drawsContent())
return;
m_tiledBacking->setDirtyRect(rect);
noteLayerPropertyChanged(WCLayerChange::Background);
addRepaintRect(rect);
}
void GraphicsLayerWC::setContentsNeedsDisplay()
{
// For example, if WebGL canvas changed, it needs flush to display.
noteLayerPropertyChanged(WCLayerChange::PlatformLayer);
}
bool GraphicsLayerWC::setChildren(Vector<Ref<GraphicsLayer>>&& children)
{
bool childrenChanged = GraphicsLayer::setChildren(WTFMove(children));
if (childrenChanged)
noteLayerPropertyChanged(WCLayerChange::Children);
return childrenChanged;
}
void GraphicsLayerWC::addChild(Ref<GraphicsLayer>&& childLayer)
{
GraphicsLayer::addChild(WTFMove(childLayer));
noteLayerPropertyChanged(WCLayerChange::Children);
}
void GraphicsLayerWC::addChildAtIndex(Ref<GraphicsLayer>&& childLayer, int index)
{
GraphicsLayer::addChildAtIndex(WTFMove(childLayer), index);
noteLayerPropertyChanged(WCLayerChange::Children);
}
void GraphicsLayerWC::addChildBelow(Ref<GraphicsLayer>&& childLayer, GraphicsLayer* sibling)
{
GraphicsLayer::addChildBelow(WTFMove(childLayer), sibling);
noteLayerPropertyChanged(WCLayerChange::Children);
}
void GraphicsLayerWC::addChildAbove(Ref<GraphicsLayer>&& childLayer, GraphicsLayer* sibling)
{
GraphicsLayer::addChildAbove(WTFMove(childLayer), sibling);
noteLayerPropertyChanged(WCLayerChange::Children);
}
bool GraphicsLayerWC::replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild)
{
if (GraphicsLayer::replaceChild(oldChild, WTFMove(newChild))) {
noteLayerPropertyChanged(WCLayerChange::Children);
return true;
}
return false;
}
void GraphicsLayerWC::willModifyChildren()
{
noteLayerPropertyChanged(WCLayerChange::Children);
}
void GraphicsLayerWC::setMaskLayer(RefPtr<GraphicsLayer>&& layer)
{
if (layer == m_maskLayer)
return;
GraphicsLayer::setMaskLayer(WTFMove(layer));
noteLayerPropertyChanged(WCLayerChange::MaskLayer);
}
void GraphicsLayerWC::setReplicatedLayer(GraphicsLayer* layer)
{
if (layer == m_replicatedLayer)
return;
GraphicsLayer::setReplicatedLayer(layer);
noteLayerPropertyChanged(WCLayerChange::ReplicaLayer);
}
void GraphicsLayerWC::setReplicatedByLayer(RefPtr<GraphicsLayer>&& layer)
{
if (layer == m_replicaLayer)
return;
GraphicsLayer::setReplicatedByLayer(WTFMove(layer));
noteLayerPropertyChanged(WCLayerChange::ReplicaLayer);
}
void GraphicsLayerWC::setPosition(const FloatPoint& point)
{
if (point == m_position)
return;
GraphicsLayer::setPosition(point);
noteLayerPropertyChanged(WCLayerChange::Position);
}
void GraphicsLayerWC::syncPosition(const FloatPoint& point)
{
if (point == m_position)
return;
GraphicsLayer::syncPosition(point);
noteLayerPropertyChanged(WCLayerChange::Position, DontScheduleFlush);
}
void GraphicsLayerWC::setAnchorPoint(const FloatPoint3D& point)
{
if (point == m_anchorPoint)
return;
GraphicsLayer::setAnchorPoint(point);
noteLayerPropertyChanged(WCLayerChange::AnchorPoint);
}
void GraphicsLayerWC::setSize(const FloatSize& size)
{
if (size == m_size)
return;
GraphicsLayer::setSize(size);
m_tiledBacking->setSize(size);
noteLayerPropertyChanged(WCLayerChange::Size);
}
void GraphicsLayerWC::setBoundsOrigin(const FloatPoint& origin)
{
if (origin == m_boundsOrigin)
return;
GraphicsLayer::setBoundsOrigin(origin);
noteLayerPropertyChanged(WCLayerChange::BoundsOrigin);
}
void GraphicsLayerWC::syncBoundsOrigin(const FloatPoint& origin)
{
if (origin == m_boundsOrigin)
return;
GraphicsLayer::syncBoundsOrigin(origin);
noteLayerPropertyChanged(WCLayerChange::BoundsOrigin, DontScheduleFlush);
}
void GraphicsLayerWC::setTransform(const TransformationMatrix& t)
{
if (t == transform())
return;
GraphicsLayer::setTransform(t);
noteLayerPropertyChanged(WCLayerChange::Transform);
}
void GraphicsLayerWC::setChildrenTransform(const TransformationMatrix& t)
{
if (t == childrenTransform())
return;
GraphicsLayer::setChildrenTransform(t);
noteLayerPropertyChanged(WCLayerChange::ChildrenTransform);
}
void GraphicsLayerWC::setPreserves3D(bool value)
{
if (value == preserves3D())
return;
GraphicsLayer::setPreserves3D(value);
noteLayerPropertyChanged(WCLayerChange::Preserves3D);
}
void GraphicsLayerWC::setMasksToBounds(bool value)
{
if (value == masksToBounds())
return;
GraphicsLayer::setMasksToBounds(value);
noteLayerPropertyChanged(WCLayerChange::MasksToBounds);
updateDebugIndicators();
}
void GraphicsLayerWC::setBackgroundColor(const WebCore::Color& value)
{
if (value == backgroundColor())
return;
GraphicsLayer::setBackgroundColor(value);
noteLayerPropertyChanged(WCLayerChange::Background);
}
void GraphicsLayerWC::setOpacity(float value)
{
if (value == opacity())
return;
GraphicsLayer::setOpacity(value);
noteLayerPropertyChanged(WCLayerChange::Opacity);
}
void GraphicsLayerWC::setContentsRect(const FloatRect& value)
{
if (value == contentsRect())
return;
GraphicsLayer::setContentsRect(value);
noteLayerPropertyChanged(WCLayerChange::ContentsRect);
}
void GraphicsLayerWC::setContentsClippingRect(const FloatRoundedRect& value)
{
if (value == contentsClippingRect())
return;
GraphicsLayer::setContentsClippingRect(value);
noteLayerPropertyChanged(WCLayerChange::ContentsClippingRect);
}
void GraphicsLayerWC::setContentsRectClipsDescendants(bool contentsRectClipsDescendants)
{
if (contentsRectClipsDescendants == m_contentsRectClipsDescendants)
return;
GraphicsLayer::setContentsRectClipsDescendants(contentsRectClipsDescendants);
noteLayerPropertyChanged(WCLayerChange::ContentsRectClipsDescendants);
}
void GraphicsLayerWC::setDrawsContent(bool value)
{
if (value == drawsContent())
return;
GraphicsLayer::setDrawsContent(value);
noteLayerPropertyChanged(WCLayerChange::Background);
updateDebugIndicators();
}
void GraphicsLayerWC::setContentsVisible(bool value)
{
if (value == contentsAreVisible())
return;
GraphicsLayer::setContentsVisible(value);
noteLayerPropertyChanged(WCLayerChange::ContentsVisible);
}
void GraphicsLayerWC::setBackfaceVisibility(bool value)
{
if (value == backfaceVisibility())
return;
GraphicsLayer::setBackfaceVisibility(value);
noteLayerPropertyChanged(WCLayerChange::BackfaceVisibility);
}
void GraphicsLayerWC::setContentsToSolidColor(const Color& color)
{
if (color == m_solidColor)
return;
m_solidColor = color;
noteLayerPropertyChanged(WCLayerChange::SolidColor);
}
void GraphicsLayerWC::setContentsToPlatformLayer(PlatformLayer* platformLayer, ContentsLayerPurpose)
{
if (m_platformLayer == platformLayer)
return;
m_platformLayer = platformLayer;
noteLayerPropertyChanged(WCLayerChange::PlatformLayer);
updateDebugIndicators();
}
void GraphicsLayerWC::setContentsToPlatformLayerHost(WebCore::LayerHostingContextIdentifier identifier)
{
if (m_hostIdentifier && *m_hostIdentifier == identifier)
return;
m_hostIdentifier = identifier;
noteLayerPropertyChanged(WCLayerChange::RemoteFrame);
}
void GraphicsLayerWC::setContentsDisplayDelegate(RefPtr<WebCore::GraphicsLayerContentsDisplayDelegate>&& displayDelegate, ContentsLayerPurpose purpose)
{
auto platformLayer = displayDelegate ? displayDelegate->platformLayer() : nullptr;
setContentsToPlatformLayer(platformLayer, purpose);
}
bool GraphicsLayerWC::usesContentsLayer() const
{
return m_platformLayer;
}
void GraphicsLayerWC::setShowDebugBorder(bool show)
{
if (isShowingDebugBorder() == show)
return;
GraphicsLayer::setShowDebugBorder(show);
updateDebugIndicators();
noteLayerPropertyChanged(WCLayerChange::ShowDebugBorder);
}
void GraphicsLayerWC::setDebugBorder(const Color& color, float width)
{
m_debugBorderColor = color;
m_debugBorderWidth = width;
noteLayerPropertyChanged(WCLayerChange::DebugBorderColor);
noteLayerPropertyChanged(WCLayerChange::DebugBorderWidth);
}
void GraphicsLayerWC::setShowRepaintCounter(bool show)
{
if (isShowingRepaintCounter() == show)
return;
GraphicsLayer::setShowRepaintCounter(show);
noteLayerPropertyChanged(WCLayerChange::ShowRepaintCounter);
}
static bool filtersCanBeComposited(const FilterOperations& filters)
{
if (!filters.size())
return false;
for (const auto& filterOperation : filters) {
if (filterOperation->type() == FilterOperation::Type::Reference)
return false;
}
return true;
}
bool GraphicsLayerWC::setFilters(const FilterOperations& filters)
{
bool canCompositeFilters = filtersCanBeComposited(filters);
if (GraphicsLayer::filters() == filters)
return canCompositeFilters;
if (canCompositeFilters) {
if (!GraphicsLayer::setFilters(filters))
return false;
} else if (GraphicsLayer::filters().size())
clearFilters();
noteLayerPropertyChanged(WCLayerChange::Filters);
return canCompositeFilters;
}
bool GraphicsLayerWC::setBackdropFilters(const FilterOperations& filters)
{
bool canCompositeFilters = filtersCanBeComposited(filters);
if (m_backdropFilters == filters)
return canCompositeFilters;
if (canCompositeFilters)
GraphicsLayer::setBackdropFilters(filters);
else
clearBackdropFilters();
noteLayerPropertyChanged(WCLayerChange::BackdropFilters);
updateDebugIndicators();
return canCompositeFilters;
}
void GraphicsLayerWC::setBackdropFiltersRect(const FloatRoundedRect& backdropFiltersRect)
{
if (m_backdropFiltersRect == backdropFiltersRect)
return;
GraphicsLayer::setBackdropFiltersRect(backdropFiltersRect);
noteLayerPropertyChanged(WCLayerChange::BackdropFiltersRect);
}
void GraphicsLayerWC::noteLayerPropertyChanged(OptionSet<WCLayerChange> flags, ScheduleFlushOrNot scheduleFlush)
{
if (beingDestroyed())
return;
bool needsFlush = !m_uncommittedChanges;
m_uncommittedChanges.add(flags);
if (client().isFlushingLayers())
return;
if (needsFlush && scheduleFlush == ScheduleFlush)
client().notifyFlushRequired(this);
}
void GraphicsLayerWC::flushCompositingState(const FloatRect& passedVisibleRect)
{
// passedVisibleRect doesn't contain the scrollbar area. Inflate it.
FloatRect visibleRect = passedVisibleRect;
visibleRect.inflate(20.f);
TransformState state(TransformState::UnapplyInverseTransformDirection, FloatQuad(visibleRect));
state.setSecondaryQuad(FloatQuad { visibleRect });
recursiveCommitChanges(state);
}
void GraphicsLayerWC::flushCompositingStateForThisLayerOnly()
{
if (!m_uncommittedChanges)
return;
WCLayerUpdateInfo update {
.id = *primaryLayerID(),
.changes = std::exchange(m_uncommittedChanges, { })
};
if (update.changes & WCLayerChange::Children) {
update.children = WTF::map(children(), [](auto& layer) {
return *layer->primaryLayerID();
});
}
if (update.changes & WCLayerChange::MaskLayer) {
if (maskLayer())
update.maskLayer = maskLayer()->primaryLayerID();
else
update.maskLayer = std::nullopt;
}
if (update.changes & WCLayerChange::ReplicaLayer) {
if (replicaLayer())
update.replicaLayer = replicaLayer()->primaryLayerID();
else
update.replicaLayer = std::nullopt;
}
if (update.changes & WCLayerChange::Position)
update.position = position();
if (update.changes & WCLayerChange::AnchorPoint)
update.anchorPoint = anchorPoint();
if (update.changes & WCLayerChange::Size)
update.size = size();
if (update.changes & WCLayerChange::BoundsOrigin)
update.boundsOrigin = boundsOrigin();
if (update.changes & WCLayerChange::Preserves3D)
update.preserves3D = preserves3D();
if (update.changes & WCLayerChange::ContentsRect)
update.contentsRect = contentsRect();
if (update.changes & WCLayerChange::ContentsClippingRect)
update.contentsClippingRect = contentsClippingRect();
if (update.changes & WCLayerChange::ContentsRectClipsDescendants)
update.contentsRectClipsDescendants = contentsRectClipsDescendants();
if (update.changes & WCLayerChange::ContentsVisible)
update.contentsVisible = contentsAreVisible();
if (update.changes & WCLayerChange::BackfaceVisibility)
update.backfaceVisibility = backfaceVisibility();
if (update.changes & WCLayerChange::MasksToBounds)
update.masksToBounds = masksToBounds();
if (update.changes & WCLayerChange::Background) {
update.background.color = backgroundColor();
if (drawsContent() && contentsAreVisible()) {
update.background.hasBackingStore = true;
update.background.backingStoreSize = WebCore::expandedIntSize(size() * deviceScaleFactor());
if (m_tiledBacking->paintAndFlush(update)) {
incrementRepaintCount();
update.changes.add(WCLayerChange::RepaintCount);
}
} else
update.background.hasBackingStore = false;
}
if (update.changes & WCLayerChange::SolidColor)
update.solidColor = m_solidColor;
if (update.changes & WCLayerChange::ShowDebugBorder)
update.showDebugBorder = isShowingDebugBorder();
if (update.changes & WCLayerChange::DebugBorderColor)
update.debugBorderColor = m_debugBorderColor;
if (update.changes & WCLayerChange::DebugBorderWidth)
update.debugBorderWidth = m_debugBorderWidth;
if (update.changes & WCLayerChange::ShowRepaintCounter)
update.showRepaintCounter = isShowingRepaintCounter();
if (update.changes & WCLayerChange::RepaintCount)
update.repaintCount = repaintCount();
if (update.changes & WCLayerChange::Opacity)
update.opacity = opacity();
if (update.changes & WCLayerChange::Transform)
update.transform = transform();
if (update.changes & WCLayerChange::ChildrenTransform)
update.childrenTransform = childrenTransform();
if (update.changes & WCLayerChange::Filters)
update.filters = filters();
if (update.changes & WCLayerChange::BackdropFilters)
update.backdropFilters = backdropFilters();
if (update.changes & WCLayerChange::BackdropFiltersRect)
update.backdropFiltersRect = backdropFiltersRect();
if (update.changes & WCLayerChange::PlatformLayer) {
update.platformLayer.hasLayer = m_platformLayer;
#if ENABLE(WEBGL)
if (m_platformLayer)
update.platformLayer.identifiers = static_cast<WCPlatformLayerGCGL*>(m_platformLayer)->takeContentBufferIdentifiers();
#endif
}
if (update.changes & WCLayerChange::RemoteFrame)
update.hostIdentifier = m_hostIdentifier;
m_observer->commitLayerUpdateInfo(WTFMove(update));
}
TiledBacking* GraphicsLayerWC::tiledBacking() const
{
return m_tiledBacking->tiledBacking();
}
RefPtr<WebCore::ImageBuffer> GraphicsLayerWC::createImageBuffer(WebCore::FloatSize size, float deviceScaleFactor)
{
return m_observer->createImageBuffer(size, deviceScaleFactor);
}
static inline bool accumulatesTransform(const GraphicsLayerWC& layer)
{
return !layer.masksToBounds() && (layer.preserves3D() || (layer.parent() && layer.parent()->preserves3D()));
}
TransformationMatrix GraphicsLayerWC::transformByApplyingAnchorPoint(const TransformationMatrix& matrix) const
{
if (matrix.isIdentity())
return matrix;
TransformationMatrix result;
FloatPoint3D absoluteAnchorPoint(anchorPoint());
absoluteAnchorPoint.scale(size().width(), size().height(), 1);
result.translate3d(absoluteAnchorPoint.x(), absoluteAnchorPoint.y(), absoluteAnchorPoint.z());
result.multiply(matrix);
result.translate3d(-absoluteAnchorPoint.x(), -absoluteAnchorPoint.y(), -absoluteAnchorPoint.z());
return result;
}
TransformationMatrix GraphicsLayerWC::layerTransform(const FloatPoint& position, const TransformationMatrix* customTransform) const
{
TransformationMatrix transform;
transform.translate(position.x(), position.y());
const auto& currentTransform = customTransform ? *customTransform
: (m_transform ? *m_transform : TransformationMatrix::identity);
transform.multiply(transformByApplyingAnchorPoint(currentTransform));
if (GraphicsLayer* parentLayer = parent()) {
if (parentLayer->hasNonIdentityChildrenTransform()) {
FloatPoint boundsOrigin = parentLayer->boundsOrigin();
FloatPoint3D parentAnchorPoint(parentLayer->anchorPoint());
parentAnchorPoint.scale(parentLayer->size().width(), parentLayer->size().height(), 1);
parentAnchorPoint += boundsOrigin;
transform.translateRight3d(-parentAnchorPoint.x(), -parentAnchorPoint.y(), -parentAnchorPoint.z());
transform = parentLayer->childrenTransform() * transform;
transform.translateRight3d(parentAnchorPoint.x(), parentAnchorPoint.y(), parentAnchorPoint.z());
}
}
return transform;
}
GraphicsLayerWC::VisibleAndCoverageRects GraphicsLayerWC::computeVisibleAndCoverageRect(TransformState& state, bool preserves3D) const
{
FloatPoint position = approximatePosition();
client().customPositionForVisibleRectComputation(this, position);
TransformationMatrix layerTransform;
TransformationMatrix currentTransform;
if (client().getCurrentTransform(this, currentTransform))
layerTransform = this->layerTransform(position, ¤tTransform);
else
layerTransform = this->layerTransform(position);
bool applyWasClamped;
TransformState::TransformAccumulation accumulation = preserves3D ? TransformState::AccumulateTransform : TransformState::FlattenTransform;
state.applyTransform(layerTransform, accumulation, &applyWasClamped);
bool mapWasClamped;
FloatRect clipRectForChildren = state.mappedQuad(&mapWasClamped).boundingBox();
FloatPoint boundsOrigin = m_boundsOrigin;
clipRectForChildren.move(boundsOrigin.x(), boundsOrigin.y());
FloatRect clipRectForSelf(boundsOrigin, m_size);
if (!applyWasClamped && !mapWasClamped)
clipRectForSelf.intersect(clipRectForChildren);
if (masksToBounds()) {
ASSERT(accumulation == TransformState::FlattenTransform);
// Flatten, and replace the quad in the TransformState with one that is clipped to this layer's bounds.
state.flatten();
state.setQuad(clipRectForSelf);
if (state.isMappingSecondaryQuad())
state.setSecondaryQuad(FloatQuad { clipRectForSelf });
}
FloatRect coverageRect = clipRectForSelf;
auto quad = state.mappedSecondaryQuad(&mapWasClamped);
if (quad && !mapWasClamped && !applyWasClamped)
coverageRect = (*quad).boundingBox();
return { clipRectForSelf, coverageRect, currentTransform };
}
void GraphicsLayerWC::recursiveCommitChanges(const TransformState& state)
{
TransformState localState = state;
bool accumulateTransform = accumulatesTransform(*this);
VisibleAndCoverageRects rects = computeVisibleAndCoverageRect(localState, accumulateTransform);
bool needsToPaint = m_tiledBacking->updateCoverageRect(rects.coverageRect);
if (needsToPaint)
noteLayerPropertyChanged(WCLayerChange::Background, DontScheduleFlush);
flushCompositingStateForThisLayerOnly();
if (auto* mask = maskLayer())
static_cast<GraphicsLayerWC*>(mask)->recursiveCommitChanges(localState);
if (auto* replica = replicaLayer())
static_cast<GraphicsLayerWC*>(replica)->recursiveCommitChanges(localState);
for (auto& child : children())
static_cast<GraphicsLayerWC*>(child.ptr())->recursiveCommitChanges(localState);
}
} // namespace WebKit
#endif // USE(GRAPHICS_LAYER_WC)
|