@@ -79,19 +79,27 @@ std::optional<PlatformLayerIdentifier> GraphicsLayerCoordinated::primaryLayerID(
7979
8080void GraphicsLayerCoordinated::setNeedsDisplay ()
8181{
82- if (!m_drawsContent || !m_contentsVisible || m_size.isEmpty () || m_dirtyRegion. fullRepaint )
82+ if (!m_drawsContent || !m_contentsVisible || m_size.isEmpty ())
8383 return ;
8484
85- m_dirtyRegion.fullRepaint = true ;
86- m_dirtyRegion.rects .clear ();
87- noteLayerPropertyChanged (Change::DirtyRegion, ScheduleFlush::Yes);
85+ if (m_dirtyRegion) {
86+ if (m_dirtyRegion->mode () == Damage::Mode::Full)
87+ return ;
88+
89+ m_dirtyRegion->makeFull (m_size);
90+ } else
91+ m_dirtyRegion = Damage (m_size, Damage::Mode::Full);
8892
93+ noteLayerPropertyChanged (Change::DirtyRegion, ScheduleFlush::Yes);
8994 addRepaintRect ({ { }, m_size });
9095}
9196
9297void GraphicsLayerCoordinated::setNeedsDisplayInRect (const FloatRect& initialRect, ShouldClipToLayer shouldClip)
9398{
94- if (!m_drawsContent || !m_contentsVisible || m_size.isEmpty () || m_dirtyRegion.fullRepaint )
99+ if (!m_drawsContent || !m_contentsVisible || m_size.isEmpty ())
100+ return ;
101+
102+ if (m_dirtyRegion && m_dirtyRegion->mode () == Damage::Mode::Full)
95103 return ;
96104
97105 auto rect = initialRect;
@@ -101,17 +109,16 @@ void GraphicsLayerCoordinated::setNeedsDisplayInRect(const FloatRect& initialRec
101109 if (rect.isEmpty ())
102110 return ;
103111
104- auto & rects = m_dirtyRegion.rects ;
105- bool alreadyRecorded = std::any_of (rects.begin (), rects.end (), [&](auto & dirtyRect) {
106- return dirtyRect.contains (rect);
107- });
108- if (alreadyRecorded)
109- return ;
112+ addRepaintRect (rect);
110113
111- rects.append (rect);
112- noteLayerPropertyChanged (Change::DirtyRegion, ScheduleFlush::Yes);
114+ if (!m_dirtyRegion) {
115+ static constexpr FloatSize minDamageSize = { 512 , 512 };
116+ auto viewVisibleSize = client ().enclosingFrameViewVisibleSize ();
117+ m_dirtyRegion = Damage (m_size.constrainedBetween (minDamageSize, viewVisibleSize));
118+ }
113119
114- addRepaintRect (rect);
120+ if (m_dirtyRegion->add (rect))
121+ noteLayerPropertyChanged (Change::DirtyRegion, ScheduleFlush::Yes);
115122}
116123
117124void GraphicsLayerCoordinated::setPosition (const FloatPoint& position)
@@ -891,48 +898,6 @@ void GraphicsLayerCoordinated::updateVisibleRect(const FloatRect& rect)
891898 m_platformLayer->setTransformedVisibleRect (WTFMove (visibleRect), WTFMove (visibleRectFuture));
892899}
893900
894- #if ENABLE(DAMAGE_TRACKING)
895- void GraphicsLayerCoordinated::updateDamage (const FloatSize& visibleSize)
896- {
897- if (!m_platformLayer->damagePropagation ())
898- return ;
899-
900- if (m_dirtyRegion.fullRepaint ) {
901- m_platformLayer->setDamage (Damage (m_size, Damage::Mode::Full));
902- return ;
903- }
904-
905- static constexpr FloatSize minDamageSize = { 512 , 512 };
906- Damage damage (m_size.constrainedBetween (minDamageSize, visibleSize));
907- for (const auto & rect : m_dirtyRegion.rects )
908- damage.add (rect);
909- m_platformLayer->setDamage (WTFMove (damage));
910- }
911- #endif
912-
913- void GraphicsLayerCoordinated::updateDirtyRegion (const FloatSize& visibleSize)
914- {
915- #if ENABLE(DAMAGE_TRACKING)
916- updateDamage (visibleSize);
917- #else
918- UNUSED_PARAM (visibleSize);
919- #endif
920-
921- IntRect contentsRect (IntPoint::zero (), IntSize (m_size));
922- Vector<IntRect, 1 > dirtyRegion;
923- if (!m_dirtyRegion.fullRepaint ) {
924- dirtyRegion = m_dirtyRegion.rects .map <Vector<IntRect, 1 >>([](const FloatRect& rect) {
925- return enclosingIntRect (rect);
926- });
927- } else
928- dirtyRegion = { contentsRect };
929-
930- m_dirtyRegion.fullRepaint = false ;
931- m_dirtyRegion.rects .clear ();
932-
933- m_platformLayer->setDirtyRegion (WTFMove (dirtyRegion));
934- }
935-
936901void GraphicsLayerCoordinated::updateBackdropFilters ()
937902{
938903 bool canHaveBackdropFilters = needsBackdrop ();
@@ -1092,8 +1057,10 @@ void GraphicsLayerCoordinated::commitLayerChanges(CommitState& commitState, floa
10921057 if (m_pendingChanges.contains (Change::ContentsColor))
10931058 m_platformLayer->setContentsColor (m_contentsColor);
10941059
1095- if (m_pendingChanges.contains (Change::DirtyRegion))
1096- updateDirtyRegion (commitState.visibleRect .size ());
1060+ if (m_pendingChanges.contains (Change::DirtyRegion)) {
1061+ ASSERT (m_dirtyRegion.has_value ());
1062+ m_platformLayer->setDirtyRegion (*std::exchange (m_dirtyRegion, std::nullopt ));
1063+ }
10971064
10981065 if (m_pendingChanges.contains (Change::Filters))
10991066 m_platformLayer->setFilters (m_filters);
0 commit comments