<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[259599] branches/safari-609-branch/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/259599">259599</a></dd>
<dt>Author</dt> <dd>alancoon@apple.com</dd>
<dt>Date</dt> <dd>2020-04-06 16:05:06 -0700 (Mon, 06 Apr 2020)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cherry-pick <a href="http://trac.webkit.org/projects/webkit/changeset/258434">r258434</a>. rdar://problem/61352465

    Safari sometimes crashes when switch video into PiP mode
    https://bugs.webkit.org/show_bug.cgi?id=208904

    Reviewed by Simon Fraser.

    With this patch, MediaControlTextTrackContainerElement won't paint its subtree
    to an image buffer (for the captions in video fullscreen or picture-in-picture mode)
    when the cues are updated. Instead, it only sets the flag m_needsGenerateTextTrackRepresentation
    to true after running layout based on the new cues. After that, it paints its subtree
    to an image buffer if needed at the end of Page::updateRendering() when the layout is clean.
    TextTrackRepresentationCocoa will use the image buffer to set the content of the layer
    for captions in video fullscreen or picture-in-picture mode.

    MediaControlTextTrackContainerElement class is responsible for rendering the captions in both:
    1) a video player in the inline mode.
    2) a video player in "video fullscreen" or picture-in-picture mode.
    This patch refactors some functions to make their responsibilities clear.

    * Modules/mediacontrols/MediaControlsHost.cpp:
    (WebCore::MediaControlsHost::updateTextTrackRepresentationImageIfNeeded):
    * Modules/mediacontrols/MediaControlsHost.h:
    * dom/Document.cpp:
    (WebCore::Document::setMediaElementShowingTextTrack):
    (WebCore::Document::clearMediaElementShowingTextTrack):
    (WebCore::Document::updateTextTrackRepresentationImageIfNeeded):
    * dom/Document.h:

    Functions textTracksAreReady(), textTrackReadyStateChanged() and configureTextTrackDisplay()
    should be wrapped with "#if ENABLE(VIDEO_TRACK)".
    * html/HTMLMediaElement.cpp:
    (WebCore::HTMLMediaElement::setTextTrackRepresentation):
    (WebCore::HTMLMediaElement::textTracksAreReady const):
    (WebCore::HTMLMediaElement::textTrackReadyStateChanged):
    (WebCore::HTMLMediaElement::configureTextTrackDisplay):
    (WebCore::HTMLMediaElement::updateTextTrackRepresentationImageIfNeeded):
    * html/HTMLMediaElement.h:

    * html/shadow/MediaControlElements.cpp:
    (WebCore::MediaControlTextTrackContainerElement::createElementRenderer):
    (WebCore::MediaControlTextTrackContainerElement::updateDisplay):
    (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationImageIfNeeded):
    (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationIfNeeded):
    (WebCore::MediaControlTextTrackContainerElement::clearTextTrackRepresentation):
    (WebCore::MediaControlTextTrackContainerElement::updateTextTrackStyle):
    (WebCore::MediaControlTextTrackContainerElement::enteredFullscreen):
    (WebCore::MediaControlTextTrackContainerElement::updateVideoDisplaySize):
    (WebCore::MediaControlTextTrackContainerElement::updateSizes):
    (WebCore::MediaControlTextTrackContainerElement::createTextTrackRepresentationImage):
    (WebCore::MediaControlTextTrackContainerElement::textTrackRepresentationBoundsChanged):
    (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentation): Deleted.
    (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationStyle): Deleted.
    (WebCore::MediaControlTextTrackContainerElement::layoutIfNecessary): Deleted.
    (WebCore::MediaControlTextTrackContainerElement::updateCueStyles): Deleted.
    * html/shadow/MediaControlElements.h:
    * html/shadow/MediaControls.cpp:
    (WebCore::MediaControls::updateTextTrackRepresentationImageIfNeeded):
    * html/shadow/MediaControls.h:
    * page/Page.cpp:
    (WebCore::Page::updateRendering):
    * rendering/RenderMediaControlElements.cpp:
    (WebCore::RenderMediaControlTextTrackContainer::RenderMediaControlTextTrackContainer):
    (WebCore::RenderMediaControlTextTrackContainer::layout):
    (WebCore::RenderTextTrackContainerElement::RenderTextTrackContainerElement): Deleted.
    (WebCore::RenderTextTrackContainerElement::layout): Deleted.
    * rendering/RenderMediaControlElements.h:

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@258434 268f45cc-cd09-0410-ab3c-d52691b4dbfc</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari609branchSourceWebCoreChangeLog">branches/safari-609-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari609branchSourceWebCoreModulesmediacontrolsMediaControlsHostcpp">branches/safari-609-branch/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp</a></li>
<li><a href="#branchessafari609branchSourceWebCoreModulesmediacontrolsMediaControlsHosth">branches/safari-609-branch/Source/WebCore/Modules/mediacontrols/MediaControlsHost.h</a></li>
<li><a href="#branchessafari609branchSourceWebCoredomDocumentcpp">branches/safari-609-branch/Source/WebCore/dom/Document.cpp</a></li>
<li><a href="#branchessafari609branchSourceWebCoredomDocumenth">branches/safari-609-branch/Source/WebCore/dom/Document.h</a></li>
<li><a href="#branchessafari609branchSourceWebCorehtmlHTMLMediaElementcpp">branches/safari-609-branch/Source/WebCore/html/HTMLMediaElement.cpp</a></li>
<li><a href="#branchessafari609branchSourceWebCorehtmlHTMLMediaElementh">branches/safari-609-branch/Source/WebCore/html/HTMLMediaElement.h</a></li>
<li><a href="#branchessafari609branchSourceWebCorehtmlshadowMediaControlElementscpp">branches/safari-609-branch/Source/WebCore/html/shadow/MediaControlElements.cpp</a></li>
<li><a href="#branchessafari609branchSourceWebCorehtmlshadowMediaControlElementsh">branches/safari-609-branch/Source/WebCore/html/shadow/MediaControlElements.h</a></li>
<li><a href="#branchessafari609branchSourceWebCorehtmlshadowMediaControlscpp">branches/safari-609-branch/Source/WebCore/html/shadow/MediaControls.cpp</a></li>
<li><a href="#branchessafari609branchSourceWebCorehtmlshadowMediaControlsh">branches/safari-609-branch/Source/WebCore/html/shadow/MediaControls.h</a></li>
<li><a href="#branchessafari609branchSourceWebCorepagePagecpp">branches/safari-609-branch/Source/WebCore/page/Page.cpp</a></li>
<li><a href="#branchessafari609branchSourceWebCorerenderingRenderMediaControlElementscpp">branches/safari-609-branch/Source/WebCore/rendering/RenderMediaControlElements.cpp</a></li>
<li><a href="#branchessafari609branchSourceWebCorerenderingRenderMediaControlElementsh">branches/safari-609-branch/Source/WebCore/rendering/RenderMediaControlElements.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari609branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/ChangeLog (259598 => 259599)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/ChangeLog      2020-04-06 22:47:10 UTC (rev 259598)
+++ branches/safari-609-branch/Source/WebCore/ChangeLog 2020-04-06 23:05:06 UTC (rev 259599)
</span><span class="lines">@@ -1,3 +1,143 @@
</span><ins>+2020-04-06  Alan Coon  <alancoon@apple.com>
+
+        Cherry-pick r258434. rdar://problem/61352465
+
+    Safari sometimes crashes when switch video into PiP mode
+    https://bugs.webkit.org/show_bug.cgi?id=208904
+    
+    Reviewed by Simon Fraser.
+    
+    With this patch, MediaControlTextTrackContainerElement won't paint its subtree
+    to an image buffer (for the captions in video fullscreen or picture-in-picture mode)
+    when the cues are updated. Instead, it only sets the flag m_needsGenerateTextTrackRepresentation
+    to true after running layout based on the new cues. After that, it paints its subtree
+    to an image buffer if needed at the end of Page::updateRendering() when the layout is clean.
+    TextTrackRepresentationCocoa will use the image buffer to set the content of the layer
+    for captions in video fullscreen or picture-in-picture mode.
+    
+    MediaControlTextTrackContainerElement class is responsible for rendering the captions in both:
+    1) a video player in the inline mode.
+    2) a video player in "video fullscreen" or picture-in-picture mode.
+    This patch refactors some functions to make their responsibilities clear.
+    
+    * Modules/mediacontrols/MediaControlsHost.cpp:
+    (WebCore::MediaControlsHost::updateTextTrackRepresentationImageIfNeeded):
+    * Modules/mediacontrols/MediaControlsHost.h:
+    * dom/Document.cpp:
+    (WebCore::Document::setMediaElementShowingTextTrack):
+    (WebCore::Document::clearMediaElementShowingTextTrack):
+    (WebCore::Document::updateTextTrackRepresentationImageIfNeeded):
+    * dom/Document.h:
+    
+    Functions textTracksAreReady(), textTrackReadyStateChanged() and configureTextTrackDisplay()
+    should be wrapped with "#if ENABLE(VIDEO_TRACK)".
+    * html/HTMLMediaElement.cpp:
+    (WebCore::HTMLMediaElement::setTextTrackRepresentation):
+    (WebCore::HTMLMediaElement::textTracksAreReady const):
+    (WebCore::HTMLMediaElement::textTrackReadyStateChanged):
+    (WebCore::HTMLMediaElement::configureTextTrackDisplay):
+    (WebCore::HTMLMediaElement::updateTextTrackRepresentationImageIfNeeded):
+    * html/HTMLMediaElement.h:
+    
+    * html/shadow/MediaControlElements.cpp:
+    (WebCore::MediaControlTextTrackContainerElement::createElementRenderer):
+    (WebCore::MediaControlTextTrackContainerElement::updateDisplay):
+    (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationImageIfNeeded):
+    (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationIfNeeded):
+    (WebCore::MediaControlTextTrackContainerElement::clearTextTrackRepresentation):
+    (WebCore::MediaControlTextTrackContainerElement::updateTextTrackStyle):
+    (WebCore::MediaControlTextTrackContainerElement::enteredFullscreen):
+    (WebCore::MediaControlTextTrackContainerElement::updateVideoDisplaySize):
+    (WebCore::MediaControlTextTrackContainerElement::updateSizes):
+    (WebCore::MediaControlTextTrackContainerElement::createTextTrackRepresentationImage):
+    (WebCore::MediaControlTextTrackContainerElement::textTrackRepresentationBoundsChanged):
+    (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentation): Deleted.
+    (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationStyle): Deleted.
+    (WebCore::MediaControlTextTrackContainerElement::layoutIfNecessary): Deleted.
+    (WebCore::MediaControlTextTrackContainerElement::updateCueStyles): Deleted.
+    * html/shadow/MediaControlElements.h:
+    * html/shadow/MediaControls.cpp:
+    (WebCore::MediaControls::updateTextTrackRepresentationImageIfNeeded):
+    * html/shadow/MediaControls.h:
+    * page/Page.cpp:
+    (WebCore::Page::updateRendering):
+    * rendering/RenderMediaControlElements.cpp:
+    (WebCore::RenderMediaControlTextTrackContainer::RenderMediaControlTextTrackContainer):
+    (WebCore::RenderMediaControlTextTrackContainer::layout):
+    (WebCore::RenderTextTrackContainerElement::RenderTextTrackContainerElement): Deleted.
+    (WebCore::RenderTextTrackContainerElement::layout): Deleted.
+    * rendering/RenderMediaControlElements.h:
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@258434 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-03-13  Peng Liu  <peng.liu6@apple.com>
+
+            Safari sometimes crashes when switch video into PiP mode
+            https://bugs.webkit.org/show_bug.cgi?id=208904
+
+            Reviewed by Simon Fraser.
+
+            With this patch, MediaControlTextTrackContainerElement won't paint its subtree
+            to an image buffer (for the captions in video fullscreen or picture-in-picture mode)
+            when the cues are updated. Instead, it only sets the flag m_needsGenerateTextTrackRepresentation
+            to true after running layout based on the new cues. After that, it paints its subtree
+            to an image buffer if needed at the end of Page::updateRendering() when the layout is clean.
+            TextTrackRepresentationCocoa will use the image buffer to set the content of the layer
+            for captions in video fullscreen or picture-in-picture mode.
+
+            MediaControlTextTrackContainerElement class is responsible for rendering the captions in both:
+            1) a video player in the inline mode.
+            2) a video player in "video fullscreen" or picture-in-picture mode.
+            This patch refactors some functions to make their responsibilities clear.
+
+            * Modules/mediacontrols/MediaControlsHost.cpp:
+            (WebCore::MediaControlsHost::updateTextTrackRepresentationImageIfNeeded):
+            * Modules/mediacontrols/MediaControlsHost.h:
+            * dom/Document.cpp:
+            (WebCore::Document::setMediaElementShowingTextTrack):
+            (WebCore::Document::clearMediaElementShowingTextTrack):
+            (WebCore::Document::updateTextTrackRepresentationImageIfNeeded):
+            * dom/Document.h:
+
+            Functions textTracksAreReady(), textTrackReadyStateChanged() and configureTextTrackDisplay()
+            should be wrapped with "#if ENABLE(VIDEO_TRACK)".
+            * html/HTMLMediaElement.cpp:
+            (WebCore::HTMLMediaElement::setTextTrackRepresentation):
+            (WebCore::HTMLMediaElement::textTracksAreReady const):
+            (WebCore::HTMLMediaElement::textTrackReadyStateChanged):
+            (WebCore::HTMLMediaElement::configureTextTrackDisplay):
+            (WebCore::HTMLMediaElement::updateTextTrackRepresentationImageIfNeeded):
+            * html/HTMLMediaElement.h:
+
+            * html/shadow/MediaControlElements.cpp:
+            (WebCore::MediaControlTextTrackContainerElement::createElementRenderer):
+            (WebCore::MediaControlTextTrackContainerElement::updateDisplay):
+            (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationImageIfNeeded):
+            (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationIfNeeded):
+            (WebCore::MediaControlTextTrackContainerElement::clearTextTrackRepresentation):
+            (WebCore::MediaControlTextTrackContainerElement::updateTextTrackStyle):
+            (WebCore::MediaControlTextTrackContainerElement::enteredFullscreen):
+            (WebCore::MediaControlTextTrackContainerElement::updateVideoDisplaySize):
+            (WebCore::MediaControlTextTrackContainerElement::updateSizes):
+            (WebCore::MediaControlTextTrackContainerElement::createTextTrackRepresentationImage):
+            (WebCore::MediaControlTextTrackContainerElement::textTrackRepresentationBoundsChanged):
+            (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentation): Deleted.
+            (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationStyle): Deleted.
+            (WebCore::MediaControlTextTrackContainerElement::layoutIfNecessary): Deleted.
+            (WebCore::MediaControlTextTrackContainerElement::updateCueStyles): Deleted.
+            * html/shadow/MediaControlElements.h:
+            * html/shadow/MediaControls.cpp:
+            (WebCore::MediaControls::updateTextTrackRepresentationImageIfNeeded):
+            * html/shadow/MediaControls.h:
+            * page/Page.cpp:
+            (WebCore::Page::updateRendering):
+            * rendering/RenderMediaControlElements.cpp:
+            (WebCore::RenderMediaControlTextTrackContainer::RenderMediaControlTextTrackContainer):
+            (WebCore::RenderMediaControlTextTrackContainer::layout):
+            (WebCore::RenderTextTrackContainerElement::RenderTextTrackContainerElement): Deleted.
+            (WebCore::RenderTextTrackContainerElement::layout): Deleted.
+            * rendering/RenderMediaControlElements.h:
+
</ins><span class="cx"> 2020-04-03  Alan Coon  <alancoon@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Cherry-pick r259378. rdar://problem/61269720
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCoreModulesmediacontrolsMediaControlsHostcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp (259598 => 259599)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp    2020-04-06 22:47:10 UTC (rev 259598)
+++ branches/safari-609-branch/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp       2020-04-06 23:05:06 UTC (rev 259599)
</span><span class="lines">@@ -165,6 +165,12 @@
</span><span class="cx">         m_textTrackContainer->updateDisplay();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void MediaControlsHost::updateTextTrackRepresentationImageIfNeeded()
+{
+    if (m_textTrackContainer)
+        m_textTrackContainer->updateTextTrackRepresentationImageIfNeeded();
+}
+
</ins><span class="cx"> void MediaControlsHost::enteredFullscreen()
</span><span class="cx"> {
</span><span class="cx">     if (m_textTrackContainer)
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCoreModulesmediacontrolsMediaControlsHosth"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/Modules/mediacontrols/MediaControlsHost.h (259598 => 259599)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/Modules/mediacontrols/MediaControlsHost.h      2020-04-06 22:47:10 UTC (rev 259598)
+++ branches/safari-609-branch/Source/WebCore/Modules/mediacontrols/MediaControlsHost.h 2020-04-06 23:05:06 UTC (rev 259599)
</span><span class="lines">@@ -74,6 +74,7 @@
</span><span class="cx"> 
</span><span class="cx">     enum class ForceUpdate { Yes, No };
</span><span class="cx">     void updateCaptionDisplaySizes(ForceUpdate force = ForceUpdate::No);
</span><ins>+    void updateTextTrackRepresentationImageIfNeeded();
</ins><span class="cx">     void enteredFullscreen();
</span><span class="cx">     void exitedFullscreen();
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/dom/Document.cpp (259598 => 259599)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/dom/Document.cpp       2020-04-06 22:47:10 UTC (rev 259598)
+++ branches/safari-609-branch/Source/WebCore/dom/Document.cpp  2020-04-06 23:05:06 UTC (rev 259599)
</span><span class="lines">@@ -5457,6 +5457,22 @@
</span><span class="cx">         element->captionPreferencesChanged();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Document::setMediaElementShowingTextTrack(const HTMLMediaElement& element)
+{
+    m_mediaElementShowingTextTrack = makeWeakPtr(element);
+}
+
+void Document::clearMediaElementShowingTextTrack()
+{
+    m_mediaElementShowingTextTrack = nullptr;
+}
+
+void Document::updateTextTrackRepresentationImageIfNeeded()
+{
+    if (m_mediaElementShowingTextTrack)
+        m_mediaElementShowingTextTrack->updateTextTrackRepresentationImageIfNeeded();
+}
+
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> void Document::setShouldCreateRenderers(bool f)
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/dom/Document.h (259598 => 259599)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/dom/Document.h 2020-04-06 22:47:10 UTC (rev 259598)
+++ branches/safari-609-branch/Source/WebCore/dom/Document.h    2020-04-06 23:05:06 UTC (rev 259599)
</span><span class="lines">@@ -1110,6 +1110,9 @@
</span><span class="cx">     void registerForCaptionPreferencesChangedCallbacks(HTMLMediaElement&);
</span><span class="cx">     void unregisterForCaptionPreferencesChangedCallbacks(HTMLMediaElement&);
</span><span class="cx">     void captionPreferencesChanged();
</span><ins>+    void setMediaElementShowingTextTrack(const HTMLMediaElement&);
+    void clearMediaElementShowingTextTrack();
+    void updateTextTrackRepresentationImageIfNeeded();
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     void registerForVisibilityStateChangedCallbacks(VisibilityChangeClient&);
</span><span class="lines">@@ -1791,6 +1794,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx">     HashSet<HTMLMediaElement*> m_captionPreferencesChangedElements;
</span><ins>+    WeakPtr<HTMLMediaElement> m_mediaElementShowingTextTrack;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     Element* m_mainArticleElement { nullptr };
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/html/HTMLMediaElement.cpp (259598 => 259599)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/html/HTMLMediaElement.cpp      2020-04-06 22:47:10 UTC (rev 259598)
+++ branches/safari-609-branch/Source/WebCore/html/HTMLMediaElement.cpp 2020-04-06 23:05:06 UTC (rev 259599)
</span><span class="lines">@@ -1875,45 +1875,6 @@
</span><span class="cx">         updateTextTrackDisplay();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool HTMLMediaElement::textTracksAreReady() const
-{
-    // 4.8.10.12.1 Text track model
-    // ...
-    // The text tracks of a media element are ready if all the text tracks whose mode was not
-    // in the disabled state when the element's resource selection algorithm last started now
-    // have a text track readiness state of loaded or failed to load.
-    for (unsigned i = 0; i < m_textTracksWhenResourceSelectionBegan.size(); ++i) {
-        if (m_textTracksWhenResourceSelectionBegan[i]->readinessState() == TextTrack::Loading
-            || m_textTracksWhenResourceSelectionBegan[i]->readinessState() == TextTrack::NotLoaded)
-            return false;
-    }
-
-    return true;
-}
-
-void HTMLMediaElement::textTrackReadyStateChanged(TextTrack* track)
-{
-    if (track->readinessState() != TextTrack::Loading
-        && track->mode() != TextTrack::Mode::Disabled) {
-        // The display trees exist as long as the track is active, in this case,
-        // and if the same track is loaded again (for example if the src attribute was changed),
-        // cues can be accumulated with the old ones, that's why they needs to be flushed
-        if (hasMediaControls())
-            mediaControls()->clearTextDisplayContainer();
-        updateTextTrackDisplay();
-    }
-    if (m_player && m_textTracksWhenResourceSelectionBegan.contains(track)) {
-        if (track->readinessState() != TextTrack::Loading)
-            setReadyState(m_player->readyState());
-    } else {
-        // The track readiness state might have changed as a result of the user
-        // clicking the captions button. In this case, a check whether all the
-        // resources have failed loading should be done in order to hide the CC button.
-        if (hasMediaControls() && track->readinessState() == TextTrack::FailedToLoad)
-            mediaControls()->refreshClosedCaptionsButtonVisibility();
-    }
-}
-
</del><span class="cx"> void HTMLMediaElement::audioTrackEnabledChanged(AudioTrack& track)
</span><span class="cx"> {
</span><span class="cx">     if (m_audioTracks && m_audioTracks->contains(track))
</span><span class="lines">@@ -5811,6 +5772,11 @@
</span><span class="cx"> {
</span><span class="cx">     if (m_player)
</span><span class="cx">         m_player->setTextTrackRepresentation(representation);
</span><ins>+
+    if (representation)
+        document().setMediaElementShowingTextTrack(*this);
+    else
+        document().clearMediaElementShowingTextTrack();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void HTMLMediaElement::syncTextTrackBounds()
</span><span class="lines">@@ -6290,6 +6256,89 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx"> 
</span><ins>+bool HTMLMediaElement::textTracksAreReady() const
+{
+    // 4.8.10.12.1 Text track model
+    // ...
+    // The text tracks of a media element are ready if all the text tracks whose mode was not
+    // in the disabled state when the element's resource selection algorithm last started now
+    // have a text track readiness state of loaded or failed to load.
+    for (unsigned i = 0; i < m_textTracksWhenResourceSelectionBegan.size(); ++i) {
+        if (m_textTracksWhenResourceSelectionBegan[i]->readinessState() == TextTrack::Loading
+            || m_textTracksWhenResourceSelectionBegan[i]->readinessState() == TextTrack::NotLoaded)
+            return false;
+    }
+
+    return true;
+}
+
+void HTMLMediaElement::textTrackReadyStateChanged(TextTrack* track)
+{
+    if (track->readinessState() != TextTrack::Loading
+        && track->mode() != TextTrack::Mode::Disabled) {
+        // The display trees exist as long as the track is active, in this case,
+        // and if the same track is loaded again (for example if the src attribute was changed),
+        // cues can be accumulated with the old ones, that's why they needs to be flushed
+        if (hasMediaControls())
+            mediaControls()->clearTextDisplayContainer();
+        updateTextTrackDisplay();
+    }
+    if (m_player && m_textTracksWhenResourceSelectionBegan.contains(track)) {
+        if (track->readinessState() != TextTrack::Loading)
+            setReadyState(m_player->readyState());
+    } else {
+        // The track readiness state might have changed as a result of the user
+        // clicking the captions button. In this case, a check whether all the
+        // resources have failed loading should be done in order to hide the CC button.
+        if (hasMediaControls() && track->readinessState() == TextTrack::FailedToLoad)
+            mediaControls()->refreshClosedCaptionsButtonVisibility();
+    }
+}
+
+void HTMLMediaElement::configureTextTrackDisplay(TextTrackVisibilityCheckType checkType)
+{
+    ALWAYS_LOG(LOGIDENTIFIER, checkType);
+    ASSERT(m_textTracks);
+
+    if (m_processingPreferenceChange)
+        return;
+
+    if (document().activeDOMObjectsAreStopped())
+        return;
+
+    bool haveVisibleTextTrack = false;
+    for (unsigned i = 0; i < m_textTracks->length(); ++i) {
+        if (m_textTracks->item(i)->mode() == TextTrack::Mode::Showing) {
+            haveVisibleTextTrack = true;
+            break;
+        }
+    }
+
+    if (checkType == CheckTextTrackVisibility && m_haveVisibleTextTrack == haveVisibleTextTrack) {
+        updateActiveTextTrackCues(currentMediaTime());
+        return;
+    }
+
+    m_haveVisibleTextTrack = haveVisibleTextTrack;
+    m_closedCaptionsVisible = m_haveVisibleTextTrack;
+
+#if ENABLE(MEDIA_CONTROLS_SCRIPT)
+    if (!m_haveVisibleTextTrack)
+        return;
+
+    ensureMediaControlsShadowRoot();
+    updateTextTrackDisplay();
+#else
+    if (!m_haveVisibleTextTrack && !hasMediaControls() && !createMediaControls())
+        return;
+
+    mediaControls()->changedClosedCaptionsVisibility();
+
+    updateTextTrackDisplay();
+    updateActiveTextTrackCues(currentMediaTime());
+#endif
+}
+
</ins><span class="cx"> void HTMLMediaElement::updateTextTrackDisplay()
</span><span class="cx"> {
</span><span class="cx"> #if ENABLE(MEDIA_CONTROLS_SCRIPT)
</span><span class="lines">@@ -6305,8 +6354,23 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void HTMLMediaElement::updateTextTrackRepresentationImageIfNeeded()
+{
+#if ENABLE(MEDIA_CONTROLS_SCRIPT)
+    ensureMediaControlsShadowRoot();
+    if (!m_mediaControlsHost)
+        m_mediaControlsHost = MediaControlsHost::create(*this);
+    m_mediaControlsHost->updateTextTrackRepresentationImageIfNeeded();
+#else
+    if (!hasMediaControls() && !createMediaControls())
+        return;
+
+    mediaControls()->updateTextTrackRepresentationImageIfNeeded();
</ins><span class="cx"> #endif
</span><ins>+}
</ins><span class="cx"> 
</span><ins>+#endif
+
</ins><span class="cx"> void HTMLMediaElement::setClosedCaptionsVisible(bool closedCaptionVisible)
</span><span class="cx"> {
</span><span class="cx">     INFO_LOG(LOGIDENTIFIER, closedCaptionVisible);
</span><span class="lines">@@ -6545,52 +6609,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><del>-void HTMLMediaElement::configureTextTrackDisplay(TextTrackVisibilityCheckType checkType)
-{
-    ALWAYS_LOG(LOGIDENTIFIER, checkType);
-    ASSERT(m_textTracks);
</del><span class="cx"> 
</span><del>-    if (m_processingPreferenceChange)
-        return;
-
-    if (document().activeDOMObjectsAreStopped())
-        return;
-
-    bool haveVisibleTextTrack = false;
-    for (unsigned i = 0; i < m_textTracks->length(); ++i) {
-        if (m_textTracks->item(i)->mode() == TextTrack::Mode::Showing) {
-            haveVisibleTextTrack = true;
-            break;
-        }
-    }
-
-    if (checkType == CheckTextTrackVisibility && m_haveVisibleTextTrack == haveVisibleTextTrack) {
-        updateActiveTextTrackCues(currentMediaTime());
-        return;
-    }
-
-    m_haveVisibleTextTrack = haveVisibleTextTrack;
-    m_closedCaptionsVisible = m_haveVisibleTextTrack;
-
-#if ENABLE(MEDIA_CONTROLS_SCRIPT)
-    if (!m_haveVisibleTextTrack)
-        return;
-
-    ensureMediaControlsShadowRoot();
-    updateTextTrackDisplay();
-#else
-    if (!m_haveVisibleTextTrack && !hasMediaControls())
-        return;
-    if (!hasMediaControls() && !createMediaControls())
-        return;
-
-    mediaControls()->changedClosedCaptionsVisibility();
-
-    updateTextTrackDisplay();
-    updateActiveTextTrackCues(currentMediaTime());
-#endif
-}
-
</del><span class="cx"> void HTMLMediaElement::captionPreferencesChanged()
</span><span class="cx"> {
</span><span class="cx">     if (!isVideo())
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCorehtmlHTMLMediaElementh"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/html/HTMLMediaElement.h (259598 => 259599)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/html/HTMLMediaElement.h        2020-04-06 22:47:10 UTC (rev 259598)
+++ branches/safari-609-branch/Source/WebCore/html/HTMLMediaElement.h   2020-04-06 23:05:06 UTC (rev 259599)
</span><span class="lines">@@ -379,16 +379,9 @@
</span><span class="cx"> 
</span><span class="cx">     void setSelectedTextTrack(TextTrack*);
</span><span class="cx"> 
</span><del>-    bool textTracksAreReady() const;
-    using HTMLMediaElementEnums::TextTrackVisibilityCheckType;
-    void configureTextTrackDisplay(TextTrackVisibilityCheckType checkType = CheckTextTrackVisibility);
-    void updateTextTrackDisplay();
-
</del><span class="cx">     // AudioTrackClient
</span><span class="cx">     void audioTrackEnabledChanged(AudioTrack&) final;
</span><span class="cx"> 
</span><del>-    void textTrackReadyStateChanged(TextTrack*);
-
</del><span class="cx">     // TextTrackClient
</span><span class="cx">     void textTrackKindChanged(TextTrack&) override;
</span><span class="cx">     void textTrackModeChanged(TextTrack&) override;
</span><span class="lines">@@ -405,6 +398,9 @@
</span><span class="cx">     void syncTextTrackBounds();
</span><span class="cx"> 
</span><span class="cx">     void captionPreferencesChanged();
</span><ins>+    using HTMLMediaElementEnums::TextTrackVisibilityCheckType;
+    void textTrackReadyStateChanged(TextTrack*);
+    void updateTextTrackRepresentationImageIfNeeded();
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(WIRELESS_PLAYBACK_TARGET)
</span><span class="lines">@@ -803,6 +799,10 @@
</span><span class="cx">     enum ReconfigureMode { Immediately, AfterDelay };
</span><span class="cx">     void markCaptionAndSubtitleTracksAsUnconfigured(ReconfigureMode);
</span><span class="cx">     CaptionUserPreferences::CaptionDisplayMode captionDisplayMode();
</span><ins>+
+    bool textTracksAreReady() const;
+    void configureTextTrackDisplay(TextTrackVisibilityCheckType = CheckTextTrackVisibility);
+    void updateTextTrackDisplay();
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     // These "internal" functions do not check user gesture restrictions.
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCorehtmlshadowMediaControlElementscpp"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/html/shadow/MediaControlElements.cpp (259598 => 259599)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/html/shadow/MediaControlElements.cpp   2020-04-06 22:47:10 UTC (rev 259598)
+++ branches/safari-609-branch/Source/WebCore/html/shadow/MediaControlElements.cpp      2020-04-06 23:05:06 UTC (rev 259599)
</span><span class="lines">@@ -1105,7 +1105,7 @@
</span><span class="cx"> 
</span><span class="cx"> RenderPtr<RenderElement> MediaControlTextTrackContainerElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
</span><span class="cx"> {
</span><del>-    return createRenderer<RenderTextTrackContainerElement>(*this, WTFMove(style));
</del><ins>+    return createRenderer<RenderMediaControlTextTrackContainer>(*this, WTFMove(style));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static bool compareCueIntervalForDisplay(const CueInterval& one, const CueInterval& two)
</span><span class="lines">@@ -1183,7 +1183,7 @@
</span><span class="cx">     std::sort(activeCues.begin(), activeCues.end(), &compareCueIntervalForDisplay);
</span><span class="cx"> 
</span><span class="cx">     if (mediaController()->closedCaptionsVisible()) {
</span><del>-        // 10. For each text track cue cue in cues that has not yet had
</del><ins>+        // 10. For each text track cue in cues that has not yet had
</ins><span class="cx">         // corresponding CSS boxes added to output, in text track cue order, run the
</span><span class="cx">         // following substeps:
</span><span class="cx">         for (auto& interval : activeCues) {
</span><span class="lines">@@ -1205,10 +1205,24 @@
</span><span class="cx">     else
</span><span class="cx">         hide();
</span><span class="cx"> 
</span><del>-    if (m_textTrackRepresentation || video.requiresTextTrackRepresentation())
-        updateTextTrackRepresentation();
</del><ins>+    updateTextTrackRepresentationIfNeeded();
+    updateTextTrackStyle();
+    m_needsGenerateTextTrackRepresentation = true;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void MediaControlTextTrackContainerElement::updateTextTrackRepresentationImageIfNeeded()
+{
+    if (!m_needsGenerateTextTrackRepresentation)
+        return;
+
+    m_needsGenerateTextTrackRepresentation = false;
+
+    // We should call m_textTrackRepresentation->update() to paint the subtree of
+    // the RenderTextTrackContainerElement after the layout is clean.
+    if (m_textTrackRepresentation)
+        m_textTrackRepresentation->update();
+}
+
</ins><span class="cx"> void MediaControlTextTrackContainerElement::processActiveVTTCue(VTTCue& cue)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(is<VTTCue>(cue) || is<TextTrackCueGeneric>(cue));
</span><span class="lines">@@ -1288,7 +1302,7 @@
</span><span class="cx">         setInlineStyleProperty(CSSPropertyStrokeWidth, strokeWidth, CSSUnitType::CSS_PX, important);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void MediaControlTextTrackContainerElement::updateTextTrackRepresentation()
</del><ins>+void MediaControlTextTrackContainerElement::updateTextTrackRepresentationIfNeeded()
</ins><span class="cx"> {
</span><span class="cx">     auto mediaElement = parentMediaElement(this);
</span><span class="cx">     if (!mediaElement)
</span><span class="lines">@@ -1297,10 +1311,9 @@
</span><span class="cx">     auto requiresTextTrackRepresentation = mediaElement->requiresTextTrackRepresentation();
</span><span class="cx">     if (!hasChildNodes() || !requiresTextTrackRepresentation) {
</span><span class="cx">         if (m_textTrackRepresentation) {
</span><del>-            if (!requiresTextTrackRepresentation) {
</del><ins>+            if (!requiresTextTrackRepresentation)
</ins><span class="cx">                 clearTextTrackRepresentation();
</span><del>-                updateSizes(ForceUpdate::Yes);
-            } else
</del><ins>+            else
</ins><span class="cx">                 m_textTrackRepresentation->setHidden(true);
</span><span class="cx">         }
</span><span class="cx">         return;
</span><span class="lines">@@ -1309,18 +1322,13 @@
</span><span class="cx">     if (!m_textTrackRepresentation) {
</span><span class="cx">         ALWAYS_LOG(LOGIDENTIFIER);
</span><span class="cx"> 
</span><del>-        m_waitingForFirstLayout = true;
</del><span class="cx">         m_textTrackRepresentation = TextTrackRepresentation::create(*this);
</span><span class="cx">         if (document().page())
</span><span class="cx">             m_textTrackRepresentation->setContentScale(document().page()->deviceScaleFactor());
</span><span class="cx">         mediaElement->setTextTrackRepresentation(m_textTrackRepresentation.get());
</span><del>-        updateSizes();
-        updateTextTrackRepresentationStyle();
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     m_textTrackRepresentation->setHidden(false);
</span><del>-    if (!m_waitingForFirstLayout)
-        m_textTrackRepresentation->update();
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaControlTextTrackContainerElement::clearTextTrackRepresentation()
</span><span class="lines">@@ -1330,20 +1338,17 @@
</span><span class="cx"> 
</span><span class="cx">     ALWAYS_LOG(LOGIDENTIFIER);
</span><span class="cx"> 
</span><del>-    m_waitingForFirstLayout = true;
</del><span class="cx">     m_textTrackRepresentation = nullptr;
</span><span class="cx">     if (auto mediaElement = parentMediaElement(this))
</span><span class="cx">         mediaElement->setTextTrackRepresentation(nullptr);
</span><del>-    updateTextTrackRepresentationStyle();
-    updateActiveCuesFontSize();
</del><span class="cx"> }
</span><span class="cx"> 
</span><del>-void MediaControlTextTrackContainerElement::updateTextTrackRepresentationStyle()
</del><ins>+void MediaControlTextTrackContainerElement::updateTextTrackStyle()
</ins><span class="cx"> {
</span><span class="cx">     if (m_textTrackRepresentation) {
</span><ins>+        setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute);
</ins><span class="cx">         setInlineStyleProperty(CSSPropertyWidth, m_videoDisplaySize.size().width(), CSSUnitType::CSS_PX);
</span><span class="cx">         setInlineStyleProperty(CSSPropertyHeight, m_videoDisplaySize.size().height(), CSSUnitType::CSS_PX);
</span><del>-        setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute);
</del><span class="cx">         setInlineStyleProperty(CSSPropertyLeft, 0, CSSUnitType::CSS_PX);
</span><span class="cx">         setInlineStyleProperty(CSSPropertyTop, 0, CSSUnitType::CSS_PX);
</span><span class="cx">         return;
</span><span class="lines">@@ -1358,8 +1363,7 @@
</span><span class="cx"> 
</span><span class="cx"> void MediaControlTextTrackContainerElement::enteredFullscreen()
</span><span class="cx"> {
</span><del>-    if (hasChildNodes())
-        updateTextTrackRepresentation();
</del><ins>+    updateTextTrackRepresentationIfNeeded();
</ins><span class="cx">     updateSizes(ForceUpdate::Yes);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1369,23 +1373,6 @@
</span><span class="cx">     updateSizes(ForceUpdate::Yes);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void MediaControlTextTrackContainerElement::layoutIfNecessary()
-{
-    m_waitingForFirstLayout = false;
-
-    auto sizeChanged = updateVideoDisplaySize();
-    if (m_textTrackRepresentation)
-        m_textTrackRepresentation->update();
-
-    if (!sizeChanged)
-        return;
-
-    // FIXME (121170): This function is called during layout, and should lay out the text tracks immediately.
-    m_taskQueue.enqueueTask([this] () {
-        updateCueStyles();
-    });
-}
-
</del><span class="cx"> bool MediaControlTextTrackContainerElement::updateVideoDisplaySize()
</span><span class="cx"> {
</span><span class="cx">     if (!document().page())
</span><span class="lines">@@ -1411,19 +1398,14 @@
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     m_videoDisplaySize = videoBox;
</span><del>-    updateTextTrackRepresentationStyle();
-
</del><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaControlTextTrackContainerElement::updateSizes(ForceUpdate force)
</span><span class="cx"> {
</span><del>-    if (updateVideoDisplaySize() || force == ForceUpdate::Yes)
-        updateCueStyles();
-}
</del><ins>+    if (!updateVideoDisplaySize() && force != ForceUpdate::Yes)
+        return;
</ins><span class="cx"> 
</span><del>-void MediaControlTextTrackContainerElement::updateCueStyles()
-{
</del><span class="cx">     if (!document().page())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="lines">@@ -1433,12 +1415,14 @@
</span><span class="cx"> 
</span><span class="cx">     mediaElement->syncTextTrackBounds();
</span><span class="cx"> 
</span><ins>+    updateActiveCuesFontSize();
+    updateTextStrokeStyle();
</ins><span class="cx">     for (auto& activeCue : mediaElement->currentlyActiveCues())
</span><span class="cx">         activeCue.data()->recalculateStyles();
</span><span class="cx"> 
</span><del>-    updateActiveCuesFontSize();
-    updateDisplay();
-    updateTextStrokeStyle();
</del><ins>+    m_taskQueue.enqueueTask([this] () {
+        updateDisplay();
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> RefPtr<Image> MediaControlTextTrackContainerElement::createTextTrackRepresentationImage()
</span><span class="lines">@@ -1472,7 +1456,9 @@
</span><span class="cx">     if (!buffer)
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><del>-    layer->paint(buffer->context(), paintingRect, LayoutSize(), { PaintBehavior::FlattenCompositingLayers, PaintBehavior::Snapshotting }, nullptr, RenderLayer::paintLayerPaintingCompositingAllPhasesFlags());
</del><ins>+    auto paintFlags = RenderLayer::paintLayerPaintingCompositingAllPhasesFlags();
+    paintFlags.add(RenderLayer::PaintLayerTemporaryClipRects);
+    layer->paint(buffer->context(), paintingRect, LayoutSize(), { PaintBehavior::FlattenCompositingLayers, PaintBehavior::Snapshotting }, nullptr, paintFlags);
</ins><span class="cx"> 
</span><span class="cx">     return ImageBuffer::sinkIntoImage(WTFMove(buffer));
</span><span class="cx"> }
</span><span class="lines">@@ -1479,8 +1465,7 @@
</span><span class="cx"> 
</span><span class="cx"> void MediaControlTextTrackContainerElement::textTrackRepresentationBoundsChanged(const IntRect&)
</span><span class="cx"> {
</span><del>-    if (hasChildNodes())
-        updateTextTrackRepresentation();
</del><ins>+    updateTextTrackRepresentationIfNeeded();
</ins><span class="cx">     updateSizes();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCorehtmlshadowMediaControlElementsh"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/html/shadow/MediaControlElements.h (259598 => 259599)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/html/shadow/MediaControlElements.h     2020-04-06 22:47:10 UTC (rev 259598)
+++ branches/safari-609-branch/Source/WebCore/html/shadow/MediaControlElements.h        2020-04-06 23:05:06 UTC (rev 259599)
</span><span class="lines">@@ -483,9 +483,10 @@
</span><span class="cx"> 
</span><span class="cx">     enum class ForceUpdate { Yes, No };
</span><span class="cx">     void updateSizes(ForceUpdate force = ForceUpdate::No);
</span><del>-    void layoutIfNecessary();
</del><ins>+    void updateDisplay();
</ins><span class="cx"> 
</span><del>-    void updateDisplay();
</del><ins>+    void updateTextTrackRepresentationImageIfNeeded();
+
</ins><span class="cx">     void enteredFullscreen();
</span><span class="cx">     void exitedFullscreen();
</span><span class="cx"> 
</span><span class="lines">@@ -492,19 +493,22 @@
</span><span class="cx"> private:
</span><span class="cx">     explicit MediaControlTextTrackContainerElement(Document&);
</span><span class="cx"> 
</span><del>-    bool updateVideoDisplaySize();
-    void updateCueStyles();
-    void updateActiveCuesFontSize();
-    void updateTextStrokeStyle();
-    void processActiveVTTCue(VTTCue&);
</del><ins>+    // Element
</ins><span class="cx">     RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
</span><span class="cx"> 
</span><ins>+    // TextTrackRepresentationClient
</ins><span class="cx">     RefPtr<Image> createTextTrackRepresentationImage() override;
</span><span class="cx">     void textTrackRepresentationBoundsChanged(const IntRect&) override;
</span><del>-    void updateTextTrackRepresentation();
</del><ins>+
+    void updateTextTrackRepresentationIfNeeded();
</ins><span class="cx">     void clearTextTrackRepresentation();
</span><del>-    void updateTextTrackRepresentationStyle();
</del><span class="cx"> 
</span><ins>+    bool updateVideoDisplaySize();
+    void updateActiveCuesFontSize();
+    void updateTextStrokeStyle();
+    void processActiveVTTCue(VTTCue&);
+    void updateTextTrackStyle();
+
</ins><span class="cx"> #if !RELEASE_LOG_DISABLED
</span><span class="cx">     const Logger& logger() const final;
</span><span class="cx">     const void* logIdentifier() const final;
</span><span class="lines">@@ -520,7 +524,7 @@
</span><span class="cx">     IntRect m_videoDisplaySize;
</span><span class="cx">     int m_fontSize { 0 };
</span><span class="cx">     bool m_fontSizeIsImportant { false };
</span><del>-    bool m_waitingForFirstLayout { true };
</del><ins>+    bool m_needsGenerateTextTrackRepresentation { false };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCorehtmlshadowMediaControlscpp"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/html/shadow/MediaControls.cpp (259598 => 259599)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/html/shadow/MediaControls.cpp  2020-04-06 22:47:10 UTC (rev 259598)
+++ branches/safari-609-branch/Source/WebCore/html/shadow/MediaControls.cpp     2020-04-06 23:05:06 UTC (rev 259599)
</span><span class="lines">@@ -405,7 +405,7 @@
</span><span class="cx"> 
</span><span class="cx">     m_textDisplayContainer->updateDisplay();
</span><span class="cx"> }
</span><del>-    
</del><ins>+
</ins><span class="cx"> void MediaControls::textTrackPreferencesChanged()
</span><span class="cx"> {
</span><span class="cx">     closedCaptionTracksChanged();
</span><span class="lines">@@ -419,6 +419,12 @@
</span><span class="cx">         m_textDisplayContainer->removeChildren();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void MediaControls::updateTextTrackRepresentationImageIfNeeded()
+{
+    if (m_textDisplayContainer)
+        m_textDisplayContainer->updateTextTrackRepresentationImageIfNeeded();
+}
+
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> void MediaControls::setSliderVolume()
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCorehtmlshadowMediaControlsh"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/html/shadow/MediaControls.h (259598 => 259599)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/html/shadow/MediaControls.h    2020-04-06 22:47:10 UTC (rev 259598)
+++ branches/safari-609-branch/Source/WebCore/html/shadow/MediaControls.h       2020-04-06 23:05:06 UTC (rev 259599)
</span><span class="lines">@@ -103,6 +103,7 @@
</span><span class="cx">     virtual void updateTextTrackDisplay();
</span><span class="cx">     virtual void textTrackPreferencesChanged();
</span><span class="cx">     virtual void clearTextDisplayContainer();
</span><ins>+    virtual void updateTextTrackRepresentationImageIfNeeded();
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> protected:
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCorepagePagecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/page/Page.cpp (259598 => 259599)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/page/Page.cpp  2020-04-06 22:47:10 UTC (rev 259598)
+++ branches/safari-609-branch/Source/WebCore/page/Page.cpp     2020-04-06 23:05:06 UTC (rev 259599)
</span><span class="lines">@@ -1346,6 +1346,12 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     layoutIfNeeded();
</span><ins>+
+#if ENABLE(VIDEO_TRACK)
+    forEachDocument([] (Document& document) {
+        document.updateTextTrackRepresentationImageIfNeeded();
+    });
+#endif
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Page::suspendScriptedAnimations()
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCorerenderingRenderMediaControlElementscpp"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/rendering/RenderMediaControlElements.cpp (259598 => 259599)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/rendering/RenderMediaControlElements.cpp       2020-04-06 22:47:10 UTC (rev 259598)
+++ branches/safari-609-branch/Source/WebCore/rendering/RenderMediaControlElements.cpp  2020-04-06 23:05:06 UTC (rev 259599)
</span><span class="lines">@@ -41,7 +41,7 @@
</span><span class="cx"> WTF_MAKE_ISO_ALLOCATED_IMPL(RenderMediaVolumeSliderContainer);
</span><span class="cx"> WTF_MAKE_ISO_ALLOCATED_IMPL(RenderMediaControlTimelineContainer);
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><del>-WTF_MAKE_ISO_ALLOCATED_IMPL(RenderTextTrackContainerElement);
</del><ins>+WTF_MAKE_ISO_ALLOCATED_IMPL(RenderMediaControlTextTrackContainer);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> RenderMediaVolumeSliderContainer::RenderMediaVolumeSliderContainer(Element& element, RenderStyle&& style)
</span><span class="lines">@@ -90,12 +90,12 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx"> 
</span><del>-RenderTextTrackContainerElement::RenderTextTrackContainerElement(Element& element, RenderStyle&& style)
</del><ins>+RenderMediaControlTextTrackContainer::RenderMediaControlTextTrackContainer(Element& element, RenderStyle&& style)
</ins><span class="cx">     : RenderBlockFlow(element, WTFMove(style))
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RenderTextTrackContainerElement::layout()
</del><ins>+void RenderMediaControlTextTrackContainer::layout()
</ins><span class="cx"> {
</span><span class="cx">     RenderBlockFlow::layout();
</span><span class="cx">     if (style().display() == DisplayType::None)
</span><span class="lines">@@ -104,7 +104,6 @@
</span><span class="cx">     ASSERT(mediaControlElementType(element()) == MediaTextTrackDisplayContainer);
</span><span class="cx"> 
</span><span class="cx">     LayoutStateDisabler layoutStateDisabler(view().frameView().layoutContext());
</span><del>-    static_cast<MediaControlTextTrackContainerElement*>(element())->layoutIfNecessary();
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(VIDEO_TRACK)
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCorerenderingRenderMediaControlElementsh"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/rendering/RenderMediaControlElements.h (259598 => 259599)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/rendering/RenderMediaControlElements.h 2020-04-06 22:47:10 UTC (rev 259598)
+++ branches/safari-609-branch/Source/WebCore/rendering/RenderMediaControlElements.h    2020-04-06 23:05:06 UTC (rev 259599)
</span><span class="lines">@@ -59,10 +59,10 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx"> 
</span><del>-class RenderTextTrackContainerElement final : public RenderBlockFlow {
-    WTF_MAKE_ISO_ALLOCATED(RenderTextTrackContainerElement);
</del><ins>+class RenderMediaControlTextTrackContainer final : public RenderBlockFlow {
+    WTF_MAKE_ISO_ALLOCATED(RenderMediaControlTextTrackContainer);
</ins><span class="cx"> public:
</span><del>-    RenderTextTrackContainerElement(Element&, RenderStyle&&);
</del><ins>+    RenderMediaControlTextTrackContainer(Element&, RenderStyle&&);
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     void layout() override;
</span></span></pre>
</div>
</div>

</body>
</html>