⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 259599 in webkit


Ignore:
Timestamp:
Apr 6, 2020, 4:05:06 PM (6 years ago)
Author:
Alan Coon
Message:

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

Location:
branches/safari-609-branch/Source/WebCore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-609-branch/Source/WebCore/ChangeLog

    r259511 r259599  
     12020-04-06  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r258434. rdar://problem/61352465
     4
     5    Safari sometimes crashes when switch video into PiP mode
     6    https://bugs.webkit.org/show_bug.cgi?id=208904
     7   
     8    Reviewed by Simon Fraser.
     9   
     10    With this patch, MediaControlTextTrackContainerElement won't paint its subtree
     11    to an image buffer (for the captions in video fullscreen or picture-in-picture mode)
     12    when the cues are updated. Instead, it only sets the flag m_needsGenerateTextTrackRepresentation
     13    to true after running layout based on the new cues. After that, it paints its subtree
     14    to an image buffer if needed at the end of Page::updateRendering() when the layout is clean.
     15    TextTrackRepresentationCocoa will use the image buffer to set the content of the layer
     16    for captions in video fullscreen or picture-in-picture mode.
     17   
     18    MediaControlTextTrackContainerElement class is responsible for rendering the captions in both:
     19    1) a video player in the inline mode.
     20    2) a video player in "video fullscreen" or picture-in-picture mode.
     21    This patch refactors some functions to make their responsibilities clear.
     22   
     23    * Modules/mediacontrols/MediaControlsHost.cpp:
     24    (WebCore::MediaControlsHost::updateTextTrackRepresentationImageIfNeeded):
     25    * Modules/mediacontrols/MediaControlsHost.h:
     26    * dom/Document.cpp:
     27    (WebCore::Document::setMediaElementShowingTextTrack):
     28    (WebCore::Document::clearMediaElementShowingTextTrack):
     29    (WebCore::Document::updateTextTrackRepresentationImageIfNeeded):
     30    * dom/Document.h:
     31   
     32    Functions textTracksAreReady(), textTrackReadyStateChanged() and configureTextTrackDisplay()
     33    should be wrapped with "#if ENABLE(VIDEO_TRACK)".
     34    * html/HTMLMediaElement.cpp:
     35    (WebCore::HTMLMediaElement::setTextTrackRepresentation):
     36    (WebCore::HTMLMediaElement::textTracksAreReady const):
     37    (WebCore::HTMLMediaElement::textTrackReadyStateChanged):
     38    (WebCore::HTMLMediaElement::configureTextTrackDisplay):
     39    (WebCore::HTMLMediaElement::updateTextTrackRepresentationImageIfNeeded):
     40    * html/HTMLMediaElement.h:
     41   
     42    * html/shadow/MediaControlElements.cpp:
     43    (WebCore::MediaControlTextTrackContainerElement::createElementRenderer):
     44    (WebCore::MediaControlTextTrackContainerElement::updateDisplay):
     45    (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationImageIfNeeded):
     46    (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationIfNeeded):
     47    (WebCore::MediaControlTextTrackContainerElement::clearTextTrackRepresentation):
     48    (WebCore::MediaControlTextTrackContainerElement::updateTextTrackStyle):
     49    (WebCore::MediaControlTextTrackContainerElement::enteredFullscreen):
     50    (WebCore::MediaControlTextTrackContainerElement::updateVideoDisplaySize):
     51    (WebCore::MediaControlTextTrackContainerElement::updateSizes):
     52    (WebCore::MediaControlTextTrackContainerElement::createTextTrackRepresentationImage):
     53    (WebCore::MediaControlTextTrackContainerElement::textTrackRepresentationBoundsChanged):
     54    (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentation): Deleted.
     55    (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationStyle): Deleted.
     56    (WebCore::MediaControlTextTrackContainerElement::layoutIfNecessary): Deleted.
     57    (WebCore::MediaControlTextTrackContainerElement::updateCueStyles): Deleted.
     58    * html/shadow/MediaControlElements.h:
     59    * html/shadow/MediaControls.cpp:
     60    (WebCore::MediaControls::updateTextTrackRepresentationImageIfNeeded):
     61    * html/shadow/MediaControls.h:
     62    * page/Page.cpp:
     63    (WebCore::Page::updateRendering):
     64    * rendering/RenderMediaControlElements.cpp:
     65    (WebCore::RenderMediaControlTextTrackContainer::RenderMediaControlTextTrackContainer):
     66    (WebCore::RenderMediaControlTextTrackContainer::layout):
     67    (WebCore::RenderTextTrackContainerElement::RenderTextTrackContainerElement): Deleted.
     68    (WebCore::RenderTextTrackContainerElement::layout): Deleted.
     69    * rendering/RenderMediaControlElements.h:
     70   
     71    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@258434 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     72
     73    2020-03-13  Peng Liu  <peng.liu6@apple.com>
     74
     75            Safari sometimes crashes when switch video into PiP mode
     76            https://bugs.webkit.org/show_bug.cgi?id=208904
     77
     78            Reviewed by Simon Fraser.
     79
     80            With this patch, MediaControlTextTrackContainerElement won't paint its subtree
     81            to an image buffer (for the captions in video fullscreen or picture-in-picture mode)
     82            when the cues are updated. Instead, it only sets the flag m_needsGenerateTextTrackRepresentation
     83            to true after running layout based on the new cues. After that, it paints its subtree
     84            to an image buffer if needed at the end of Page::updateRendering() when the layout is clean.
     85            TextTrackRepresentationCocoa will use the image buffer to set the content of the layer
     86            for captions in video fullscreen or picture-in-picture mode.
     87
     88            MediaControlTextTrackContainerElement class is responsible for rendering the captions in both:
     89            1) a video player in the inline mode.
     90            2) a video player in "video fullscreen" or picture-in-picture mode.
     91            This patch refactors some functions to make their responsibilities clear.
     92
     93            * Modules/mediacontrols/MediaControlsHost.cpp:
     94            (WebCore::MediaControlsHost::updateTextTrackRepresentationImageIfNeeded):
     95            * Modules/mediacontrols/MediaControlsHost.h:
     96            * dom/Document.cpp:
     97            (WebCore::Document::setMediaElementShowingTextTrack):
     98            (WebCore::Document::clearMediaElementShowingTextTrack):
     99            (WebCore::Document::updateTextTrackRepresentationImageIfNeeded):
     100            * dom/Document.h:
     101
     102            Functions textTracksAreReady(), textTrackReadyStateChanged() and configureTextTrackDisplay()
     103            should be wrapped with "#if ENABLE(VIDEO_TRACK)".
     104            * html/HTMLMediaElement.cpp:
     105            (WebCore::HTMLMediaElement::setTextTrackRepresentation):
     106            (WebCore::HTMLMediaElement::textTracksAreReady const):
     107            (WebCore::HTMLMediaElement::textTrackReadyStateChanged):
     108            (WebCore::HTMLMediaElement::configureTextTrackDisplay):
     109            (WebCore::HTMLMediaElement::updateTextTrackRepresentationImageIfNeeded):
     110            * html/HTMLMediaElement.h:
     111
     112            * html/shadow/MediaControlElements.cpp:
     113            (WebCore::MediaControlTextTrackContainerElement::createElementRenderer):
     114            (WebCore::MediaControlTextTrackContainerElement::updateDisplay):
     115            (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationImageIfNeeded):
     116            (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationIfNeeded):
     117            (WebCore::MediaControlTextTrackContainerElement::clearTextTrackRepresentation):
     118            (WebCore::MediaControlTextTrackContainerElement::updateTextTrackStyle):
     119            (WebCore::MediaControlTextTrackContainerElement::enteredFullscreen):
     120            (WebCore::MediaControlTextTrackContainerElement::updateVideoDisplaySize):
     121            (WebCore::MediaControlTextTrackContainerElement::updateSizes):
     122            (WebCore::MediaControlTextTrackContainerElement::createTextTrackRepresentationImage):
     123            (WebCore::MediaControlTextTrackContainerElement::textTrackRepresentationBoundsChanged):
     124            (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentation): Deleted.
     125            (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationStyle): Deleted.
     126            (WebCore::MediaControlTextTrackContainerElement::layoutIfNecessary): Deleted.
     127            (WebCore::MediaControlTextTrackContainerElement::updateCueStyles): Deleted.
     128            * html/shadow/MediaControlElements.h:
     129            * html/shadow/MediaControls.cpp:
     130            (WebCore::MediaControls::updateTextTrackRepresentationImageIfNeeded):
     131            * html/shadow/MediaControls.h:
     132            * page/Page.cpp:
     133            (WebCore::Page::updateRendering):
     134            * rendering/RenderMediaControlElements.cpp:
     135            (WebCore::RenderMediaControlTextTrackContainer::RenderMediaControlTextTrackContainer):
     136            (WebCore::RenderMediaControlTextTrackContainer::layout):
     137            (WebCore::RenderTextTrackContainerElement::RenderTextTrackContainerElement): Deleted.
     138            (WebCore::RenderTextTrackContainerElement::layout): Deleted.
     139            * rendering/RenderMediaControlElements.h:
     140
    11412020-04-03  Alan Coon  <alancoon@apple.com>
    2142
  • branches/safari-609-branch/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp

    r251950 r259599  
    166166}
    167167
     168void MediaControlsHost::updateTextTrackRepresentationImageIfNeeded()
     169{
     170    if (m_textTrackContainer)
     171        m_textTrackContainer->updateTextTrackRepresentationImageIfNeeded();
     172}
     173
    168174void MediaControlsHost::enteredFullscreen()
    169175{
  • branches/safari-609-branch/Source/WebCore/Modules/mediacontrols/MediaControlsHost.h

    r251950 r259599  
    7575    enum class ForceUpdate { Yes, No };
    7676    void updateCaptionDisplaySizes(ForceUpdate force = ForceUpdate::No);
     77    void updateTextTrackRepresentationImageIfNeeded();
    7778    void enteredFullscreen();
    7879    void exitedFullscreen();
  • branches/safari-609-branch/Source/WebCore/dom/Document.cpp

    r258581 r259599  
    54585458}
    54595459
     5460void Document::setMediaElementShowingTextTrack(const HTMLMediaElement& element)
     5461{
     5462    m_mediaElementShowingTextTrack = makeWeakPtr(element);
     5463}
     5464
     5465void Document::clearMediaElementShowingTextTrack()
     5466{
     5467    m_mediaElementShowingTextTrack = nullptr;
     5468}
     5469
     5470void Document::updateTextTrackRepresentationImageIfNeeded()
     5471{
     5472    if (m_mediaElementShowingTextTrack)
     5473        m_mediaElementShowingTextTrack->updateTextTrackRepresentationImageIfNeeded();
     5474}
     5475
    54605476#endif
    54615477
  • branches/safari-609-branch/Source/WebCore/dom/Document.h

    r255871 r259599  
    11111111    void unregisterForCaptionPreferencesChangedCallbacks(HTMLMediaElement&);
    11121112    void captionPreferencesChanged();
     1113    void setMediaElementShowingTextTrack(const HTMLMediaElement&);
     1114    void clearMediaElementShowingTextTrack();
     1115    void updateTextTrackRepresentationImageIfNeeded();
    11131116#endif
    11141117
     
    17921795#if ENABLE(VIDEO_TRACK)
    17931796    HashSet<HTMLMediaElement*> m_captionPreferencesChangedElements;
     1797    WeakPtr<HTMLMediaElement> m_mediaElementShowingTextTrack;
    17941798#endif
    17951799
  • branches/safari-609-branch/Source/WebCore/html/HTMLMediaElement.cpp

    r257037 r259599  
    18761876}
    18771877
    1878 bool HTMLMediaElement::textTracksAreReady() const
    1879 {
    1880     // 4.8.10.12.1 Text track model
    1881     // ...
    1882     // The text tracks of a media element are ready if all the text tracks whose mode was not
    1883     // in the disabled state when the element's resource selection algorithm last started now
    1884     // have a text track readiness state of loaded or failed to load.
    1885     for (unsigned i = 0; i < m_textTracksWhenResourceSelectionBegan.size(); ++i) {
    1886         if (m_textTracksWhenResourceSelectionBegan[i]->readinessState() == TextTrack::Loading
    1887             || m_textTracksWhenResourceSelectionBegan[i]->readinessState() == TextTrack::NotLoaded)
    1888             return false;
    1889     }
    1890 
    1891     return true;
    1892 }
    1893 
    1894 void HTMLMediaElement::textTrackReadyStateChanged(TextTrack* track)
    1895 {
    1896     if (track->readinessState() != TextTrack::Loading
    1897         && track->mode() != TextTrack::Mode::Disabled) {
    1898         // The display trees exist as long as the track is active, in this case,
    1899         // and if the same track is loaded again (for example if the src attribute was changed),
    1900         // cues can be accumulated with the old ones, that's why they needs to be flushed
    1901         if (hasMediaControls())
    1902             mediaControls()->clearTextDisplayContainer();
    1903         updateTextTrackDisplay();
    1904     }
    1905     if (m_player && m_textTracksWhenResourceSelectionBegan.contains(track)) {
    1906         if (track->readinessState() != TextTrack::Loading)
    1907             setReadyState(m_player->readyState());
    1908     } else {
    1909         // The track readiness state might have changed as a result of the user
    1910         // clicking the captions button. In this case, a check whether all the
    1911         // resources have failed loading should be done in order to hide the CC button.
    1912         if (hasMediaControls() && track->readinessState() == TextTrack::FailedToLoad)
    1913             mediaControls()->refreshClosedCaptionsButtonVisibility();
    1914     }
    1915 }
    1916 
    19171878void HTMLMediaElement::audioTrackEnabledChanged(AudioTrack& track)
    19181879{
     
    58125773    if (m_player)
    58135774        m_player->setTextTrackRepresentation(representation);
     5775
     5776    if (representation)
     5777        document().setMediaElementShowingTextTrack(*this);
     5778    else
     5779        document().clearMediaElementShowingTextTrack();
    58145780}
    58155781
     
    62916257#if ENABLE(VIDEO_TRACK)
    62926258
     6259bool HTMLMediaElement::textTracksAreReady() const
     6260{
     6261    // 4.8.10.12.1 Text track model
     6262    // ...
     6263    // The text tracks of a media element are ready if all the text tracks whose mode was not
     6264    // in the disabled state when the element's resource selection algorithm last started now
     6265    // have a text track readiness state of loaded or failed to load.
     6266    for (unsigned i = 0; i < m_textTracksWhenResourceSelectionBegan.size(); ++i) {
     6267        if (m_textTracksWhenResourceSelectionBegan[i]->readinessState() == TextTrack::Loading
     6268            || m_textTracksWhenResourceSelectionBegan[i]->readinessState() == TextTrack::NotLoaded)
     6269            return false;
     6270    }
     6271
     6272    return true;
     6273}
     6274
     6275void HTMLMediaElement::textTrackReadyStateChanged(TextTrack* track)
     6276{
     6277    if (track->readinessState() != TextTrack::Loading
     6278        && track->mode() != TextTrack::Mode::Disabled) {
     6279        // The display trees exist as long as the track is active, in this case,
     6280        // and if the same track is loaded again (for example if the src attribute was changed),
     6281        // cues can be accumulated with the old ones, that's why they needs to be flushed
     6282        if (hasMediaControls())
     6283            mediaControls()->clearTextDisplayContainer();
     6284        updateTextTrackDisplay();
     6285    }
     6286    if (m_player && m_textTracksWhenResourceSelectionBegan.contains(track)) {
     6287        if (track->readinessState() != TextTrack::Loading)
     6288            setReadyState(m_player->readyState());
     6289    } else {
     6290        // The track readiness state might have changed as a result of the user
     6291        // clicking the captions button. In this case, a check whether all the
     6292        // resources have failed loading should be done in order to hide the CC button.
     6293        if (hasMediaControls() && track->readinessState() == TextTrack::FailedToLoad)
     6294            mediaControls()->refreshClosedCaptionsButtonVisibility();
     6295    }
     6296}
     6297
     6298void HTMLMediaElement::configureTextTrackDisplay(TextTrackVisibilityCheckType checkType)
     6299{
     6300    ALWAYS_LOG(LOGIDENTIFIER, checkType);
     6301    ASSERT(m_textTracks);
     6302
     6303    if (m_processingPreferenceChange)
     6304        return;
     6305
     6306    if (document().activeDOMObjectsAreStopped())
     6307        return;
     6308
     6309    bool haveVisibleTextTrack = false;
     6310    for (unsigned i = 0; i < m_textTracks->length(); ++i) {
     6311        if (m_textTracks->item(i)->mode() == TextTrack::Mode::Showing) {
     6312            haveVisibleTextTrack = true;
     6313            break;
     6314        }
     6315    }
     6316
     6317    if (checkType == CheckTextTrackVisibility && m_haveVisibleTextTrack == haveVisibleTextTrack) {
     6318        updateActiveTextTrackCues(currentMediaTime());
     6319        return;
     6320    }
     6321
     6322    m_haveVisibleTextTrack = haveVisibleTextTrack;
     6323    m_closedCaptionsVisible = m_haveVisibleTextTrack;
     6324
     6325#if ENABLE(MEDIA_CONTROLS_SCRIPT)
     6326    if (!m_haveVisibleTextTrack)
     6327        return;
     6328
     6329    ensureMediaControlsShadowRoot();
     6330    updateTextTrackDisplay();
     6331#else
     6332    if (!m_haveVisibleTextTrack && !hasMediaControls() && !createMediaControls())
     6333        return;
     6334
     6335    mediaControls()->changedClosedCaptionsVisibility();
     6336
     6337    updateTextTrackDisplay();
     6338    updateActiveTextTrackCues(currentMediaTime());
     6339#endif
     6340}
     6341
    62936342void HTMLMediaElement::updateTextTrackDisplay()
    62946343{
     
    63066355}
    63076356
     6357void HTMLMediaElement::updateTextTrackRepresentationImageIfNeeded()
     6358{
     6359#if ENABLE(MEDIA_CONTROLS_SCRIPT)
     6360    ensureMediaControlsShadowRoot();
     6361    if (!m_mediaControlsHost)
     6362        m_mediaControlsHost = MediaControlsHost::create(*this);
     6363    m_mediaControlsHost->updateTextTrackRepresentationImageIfNeeded();
     6364#else
     6365    if (!hasMediaControls() && !createMediaControls())
     6366        return;
     6367
     6368    mediaControls()->updateTextTrackRepresentationImageIfNeeded();
     6369#endif
     6370}
     6371
    63086372#endif
    63096373
     
    65466610
    65476611#if ENABLE(VIDEO_TRACK)
    6548 void HTMLMediaElement::configureTextTrackDisplay(TextTrackVisibilityCheckType checkType)
    6549 {
    6550     ALWAYS_LOG(LOGIDENTIFIER, checkType);
    6551     ASSERT(m_textTracks);
    6552 
    6553     if (m_processingPreferenceChange)
    6554         return;
    6555 
    6556     if (document().activeDOMObjectsAreStopped())
    6557         return;
    6558 
    6559     bool haveVisibleTextTrack = false;
    6560     for (unsigned i = 0; i < m_textTracks->length(); ++i) {
    6561         if (m_textTracks->item(i)->mode() == TextTrack::Mode::Showing) {
    6562             haveVisibleTextTrack = true;
    6563             break;
    6564         }
    6565     }
    6566 
    6567     if (checkType == CheckTextTrackVisibility && m_haveVisibleTextTrack == haveVisibleTextTrack) {
    6568         updateActiveTextTrackCues(currentMediaTime());
    6569         return;
    6570     }
    6571 
    6572     m_haveVisibleTextTrack = haveVisibleTextTrack;
    6573     m_closedCaptionsVisible = m_haveVisibleTextTrack;
    6574 
    6575 #if ENABLE(MEDIA_CONTROLS_SCRIPT)
    6576     if (!m_haveVisibleTextTrack)
    6577         return;
    6578 
    6579     ensureMediaControlsShadowRoot();
    6580     updateTextTrackDisplay();
    6581 #else
    6582     if (!m_haveVisibleTextTrack && !hasMediaControls())
    6583         return;
    6584     if (!hasMediaControls() && !createMediaControls())
    6585         return;
    6586 
    6587     mediaControls()->changedClosedCaptionsVisibility();
    6588 
    6589     updateTextTrackDisplay();
    6590     updateActiveTextTrackCues(currentMediaTime());
    6591 #endif
    6592 }
    65936612
    65946613void HTMLMediaElement::captionPreferencesChanged()
  • branches/safari-609-branch/Source/WebCore/html/HTMLMediaElement.h

    r255029 r259599  
    380380    void setSelectedTextTrack(TextTrack*);
    381381
    382     bool textTracksAreReady() const;
    383     using HTMLMediaElementEnums::TextTrackVisibilityCheckType;
    384     void configureTextTrackDisplay(TextTrackVisibilityCheckType checkType = CheckTextTrackVisibility);
    385     void updateTextTrackDisplay();
    386 
    387382    // AudioTrackClient
    388383    void audioTrackEnabledChanged(AudioTrack&) final;
    389 
    390     void textTrackReadyStateChanged(TextTrack*);
    391384
    392385    // TextTrackClient
     
    406399
    407400    void captionPreferencesChanged();
     401    using HTMLMediaElementEnums::TextTrackVisibilityCheckType;
     402    void textTrackReadyStateChanged(TextTrack*);
     403    void updateTextTrackRepresentationImageIfNeeded();
    408404#endif
    409405
     
    804800    void markCaptionAndSubtitleTracksAsUnconfigured(ReconfigureMode);
    805801    CaptionUserPreferences::CaptionDisplayMode captionDisplayMode();
     802
     803    bool textTracksAreReady() const;
     804    void configureTextTrackDisplay(TextTrackVisibilityCheckType = CheckTextTrackVisibility);
     805    void updateTextTrackDisplay();
    806806#endif
    807807
  • branches/safari-609-branch/Source/WebCore/html/shadow/MediaControlElements.cpp

    r257037 r259599  
    11061106RenderPtr<RenderElement> MediaControlTextTrackContainerElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
    11071107{
    1108     return createRenderer<RenderTextTrackContainerElement>(*this, WTFMove(style));
     1108    return createRenderer<RenderMediaControlTextTrackContainer>(*this, WTFMove(style));
    11091109}
    11101110
     
    11841184
    11851185    if (mediaController()->closedCaptionsVisible()) {
    1186         // 10. For each text track cue cue in cues that has not yet had
     1186        // 10. For each text track cue in cues that has not yet had
    11871187        // corresponding CSS boxes added to output, in text track cue order, run the
    11881188        // following substeps:
     
    12061206        hide();
    12071207
    1208     if (m_textTrackRepresentation || video.requiresTextTrackRepresentation())
    1209         updateTextTrackRepresentation();
     1208    updateTextTrackRepresentationIfNeeded();
     1209    updateTextTrackStyle();
     1210    m_needsGenerateTextTrackRepresentation = true;
     1211}
     1212
     1213void MediaControlTextTrackContainerElement::updateTextTrackRepresentationImageIfNeeded()
     1214{
     1215    if (!m_needsGenerateTextTrackRepresentation)
     1216        return;
     1217
     1218    m_needsGenerateTextTrackRepresentation = false;
     1219
     1220    // We should call m_textTrackRepresentation->update() to paint the subtree of
     1221    // the RenderTextTrackContainerElement after the layout is clean.
     1222    if (m_textTrackRepresentation)
     1223        m_textTrackRepresentation->update();
    12101224}
    12111225
     
    12891303}
    12901304
    1291 void MediaControlTextTrackContainerElement::updateTextTrackRepresentation()
     1305void MediaControlTextTrackContainerElement::updateTextTrackRepresentationIfNeeded()
    12921306{
    12931307    auto mediaElement = parentMediaElement(this);
     
    12981312    if (!hasChildNodes() || !requiresTextTrackRepresentation) {
    12991313        if (m_textTrackRepresentation) {
    1300             if (!requiresTextTrackRepresentation) {
     1314            if (!requiresTextTrackRepresentation)
    13011315                clearTextTrackRepresentation();
    1302                 updateSizes(ForceUpdate::Yes);
    1303             } else
     1316            else
    13041317                m_textTrackRepresentation->setHidden(true);
    13051318        }
     
    13101323        ALWAYS_LOG(LOGIDENTIFIER);
    13111324
    1312         m_waitingForFirstLayout = true;
    13131325        m_textTrackRepresentation = TextTrackRepresentation::create(*this);
    13141326        if (document().page())
    13151327            m_textTrackRepresentation->setContentScale(document().page()->deviceScaleFactor());
    13161328        mediaElement->setTextTrackRepresentation(m_textTrackRepresentation.get());
    1317         updateSizes();
    1318         updateTextTrackRepresentationStyle();
    13191329    }
    13201330
    13211331    m_textTrackRepresentation->setHidden(false);
    1322     if (!m_waitingForFirstLayout)
    1323         m_textTrackRepresentation->update();
    13241332}
    13251333
     
    13311339    ALWAYS_LOG(LOGIDENTIFIER);
    13321340
    1333     m_waitingForFirstLayout = true;
    13341341    m_textTrackRepresentation = nullptr;
    13351342    if (auto mediaElement = parentMediaElement(this))
    13361343        mediaElement->setTextTrackRepresentation(nullptr);
    1337     updateTextTrackRepresentationStyle();
    1338     updateActiveCuesFontSize();
    1339 }
    1340 
    1341 void MediaControlTextTrackContainerElement::updateTextTrackRepresentationStyle()
     1344}
     1345
     1346void MediaControlTextTrackContainerElement::updateTextTrackStyle()
    13421347{
    13431348    if (m_textTrackRepresentation) {
     1349        setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute);
    13441350        setInlineStyleProperty(CSSPropertyWidth, m_videoDisplaySize.size().width(), CSSUnitType::CSS_PX);
    13451351        setInlineStyleProperty(CSSPropertyHeight, m_videoDisplaySize.size().height(), CSSUnitType::CSS_PX);
    1346         setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute);
    13471352        setInlineStyleProperty(CSSPropertyLeft, 0, CSSUnitType::CSS_PX);
    13481353        setInlineStyleProperty(CSSPropertyTop, 0, CSSUnitType::CSS_PX);
     
    13591364void MediaControlTextTrackContainerElement::enteredFullscreen()
    13601365{
    1361     if (hasChildNodes())
    1362         updateTextTrackRepresentation();
     1366    updateTextTrackRepresentationIfNeeded();
    13631367    updateSizes(ForceUpdate::Yes);
    13641368}
     
    13681372    clearTextTrackRepresentation();
    13691373    updateSizes(ForceUpdate::Yes);
    1370 }
    1371 
    1372 void MediaControlTextTrackContainerElement::layoutIfNecessary()
    1373 {
    1374     m_waitingForFirstLayout = false;
    1375 
    1376     auto sizeChanged = updateVideoDisplaySize();
    1377     if (m_textTrackRepresentation)
    1378         m_textTrackRepresentation->update();
    1379 
    1380     if (!sizeChanged)
    1381         return;
    1382 
    1383     // FIXME (121170): This function is called during layout, and should lay out the text tracks immediately.
    1384     m_taskQueue.enqueueTask([this] () {
    1385         updateCueStyles();
    1386     });
    13871374}
    13881375
     
    14121399
    14131400    m_videoDisplaySize = videoBox;
    1414     updateTextTrackRepresentationStyle();
    1415 
    14161401    return true;
    14171402}
     
    14191404void MediaControlTextTrackContainerElement::updateSizes(ForceUpdate force)
    14201405{
    1421     if (updateVideoDisplaySize() || force == ForceUpdate::Yes)
    1422         updateCueStyles();
    1423 }
    1424 
    1425 void MediaControlTextTrackContainerElement::updateCueStyles()
    1426 {
     1406    if (!updateVideoDisplaySize() && force != ForceUpdate::Yes)
     1407        return;
     1408
    14271409    if (!document().page())
    14281410        return;
     
    14341416    mediaElement->syncTextTrackBounds();
    14351417
     1418    updateActiveCuesFontSize();
     1419    updateTextStrokeStyle();
    14361420    for (auto& activeCue : mediaElement->currentlyActiveCues())
    14371421        activeCue.data()->recalculateStyles();
    14381422
    1439     updateActiveCuesFontSize();
    1440     updateDisplay();
    1441     updateTextStrokeStyle();
     1423    m_taskQueue.enqueueTask([this] () {
     1424        updateDisplay();
     1425    });
    14421426}
    14431427
     
    14731457        return nullptr;
    14741458
    1475     layer->paint(buffer->context(), paintingRect, LayoutSize(), { PaintBehavior::FlattenCompositingLayers, PaintBehavior::Snapshotting }, nullptr, RenderLayer::paintLayerPaintingCompositingAllPhasesFlags());
     1459    auto paintFlags = RenderLayer::paintLayerPaintingCompositingAllPhasesFlags();
     1460    paintFlags.add(RenderLayer::PaintLayerTemporaryClipRects);
     1461    layer->paint(buffer->context(), paintingRect, LayoutSize(), { PaintBehavior::FlattenCompositingLayers, PaintBehavior::Snapshotting }, nullptr, paintFlags);
    14761462
    14771463    return ImageBuffer::sinkIntoImage(WTFMove(buffer));
     
    14801466void MediaControlTextTrackContainerElement::textTrackRepresentationBoundsChanged(const IntRect&)
    14811467{
    1482     if (hasChildNodes())
    1483         updateTextTrackRepresentation();
     1468    updateTextTrackRepresentationIfNeeded();
    14841469    updateSizes();
    14851470}
  • branches/safari-609-branch/Source/WebCore/html/shadow/MediaControlElements.h

    r257037 r259599  
    484484    enum class ForceUpdate { Yes, No };
    485485    void updateSizes(ForceUpdate force = ForceUpdate::No);
    486     void layoutIfNecessary();
    487 
    488486    void updateDisplay();
     487
     488    void updateTextTrackRepresentationImageIfNeeded();
     489
    489490    void enteredFullscreen();
    490491    void exitedFullscreen();
     
    493494    explicit MediaControlTextTrackContainerElement(Document&);
    494495
     496    // Element
     497    RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
     498
     499    // TextTrackRepresentationClient
     500    RefPtr<Image> createTextTrackRepresentationImage() override;
     501    void textTrackRepresentationBoundsChanged(const IntRect&) override;
     502
     503    void updateTextTrackRepresentationIfNeeded();
     504    void clearTextTrackRepresentation();
     505
    495506    bool updateVideoDisplaySize();
    496     void updateCueStyles();
    497507    void updateActiveCuesFontSize();
    498508    void updateTextStrokeStyle();
    499509    void processActiveVTTCue(VTTCue&);
    500     RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
    501 
    502     RefPtr<Image> createTextTrackRepresentationImage() override;
    503     void textTrackRepresentationBoundsChanged(const IntRect&) override;
    504     void updateTextTrackRepresentation();
    505     void clearTextTrackRepresentation();
    506     void updateTextTrackRepresentationStyle();
     510    void updateTextTrackStyle();
    507511
    508512#if !RELEASE_LOG_DISABLED
     
    521525    int m_fontSize { 0 };
    522526    bool m_fontSizeIsImportant { false };
    523     bool m_waitingForFirstLayout { true };
     527    bool m_needsGenerateTextTrackRepresentation { false };
    524528};
    525529
  • branches/safari-609-branch/Source/WebCore/html/shadow/MediaControls.cpp

    r251950 r259599  
    406406    m_textDisplayContainer->updateDisplay();
    407407}
    408    
     408
    409409void MediaControls::textTrackPreferencesChanged()
    410410{
     
    420420}
    421421
     422void MediaControls::updateTextTrackRepresentationImageIfNeeded()
     423{
     424    if (m_textDisplayContainer)
     425        m_textDisplayContainer->updateTextTrackRepresentationImageIfNeeded();
     426}
     427
    422428#endif
    423429
  • branches/safari-609-branch/Source/WebCore/html/shadow/MediaControls.h

    r237266 r259599  
    104104    virtual void textTrackPreferencesChanged();
    105105    virtual void clearTextDisplayContainer();
     106    virtual void updateTextTrackRepresentationImageIfNeeded();
    106107#endif
    107108
  • branches/safari-609-branch/Source/WebCore/page/Page.cpp

    r256385 r259599  
    13471347
    13481348    layoutIfNeeded();
     1349
     1350#if ENABLE(VIDEO_TRACK)
     1351    forEachDocument([] (Document& document) {
     1352        document.updateTextTrackRepresentationImageIfNeeded();
     1353    });
     1354#endif
    13491355}
    13501356
  • branches/safari-609-branch/Source/WebCore/rendering/RenderMediaControlElements.cpp

    r257037 r259599  
    4242WTF_MAKE_ISO_ALLOCATED_IMPL(RenderMediaControlTimelineContainer);
    4343#if ENABLE(VIDEO_TRACK)
    44 WTF_MAKE_ISO_ALLOCATED_IMPL(RenderTextTrackContainerElement);
     44WTF_MAKE_ISO_ALLOCATED_IMPL(RenderMediaControlTextTrackContainer);
    4545#endif
    4646
     
    9191#if ENABLE(VIDEO_TRACK)
    9292
    93 RenderTextTrackContainerElement::RenderTextTrackContainerElement(Element& element, RenderStyle&& style)
     93RenderMediaControlTextTrackContainer::RenderMediaControlTextTrackContainer(Element& element, RenderStyle&& style)
    9494    : RenderBlockFlow(element, WTFMove(style))
    9595{
    9696}
    9797
    98 void RenderTextTrackContainerElement::layout()
     98void RenderMediaControlTextTrackContainer::layout()
    9999{
    100100    RenderBlockFlow::layout();
     
    105105
    106106    LayoutStateDisabler layoutStateDisabler(view().frameView().layoutContext());
    107     static_cast<MediaControlTextTrackContainerElement*>(element())->layoutIfNecessary();
    108107}
    109108
  • branches/safari-609-branch/Source/WebCore/rendering/RenderMediaControlElements.h

    r224537 r259599  
    6060#if ENABLE(VIDEO_TRACK)
    6161
    62 class RenderTextTrackContainerElement final : public RenderBlockFlow {
    63     WTF_MAKE_ISO_ALLOCATED(RenderTextTrackContainerElement);
     62class RenderMediaControlTextTrackContainer final : public RenderBlockFlow {
     63    WTF_MAKE_ISO_ALLOCATED(RenderMediaControlTextTrackContainer);
    6464public:
    65     RenderTextTrackContainerElement(Element&, RenderStyle&&);
     65    RenderMediaControlTextTrackContainer(Element&, RenderStyle&&);
    6666
    6767private:
Note: See TracChangeset for help on using the changeset viewer.