Changeset 258434 in webkit


Ignore:
Timestamp:
Mar 13, 2020 2:49:31 PM (4 years ago)
Author:
Peng Liu
Message:

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:
Location:
trunk/Source/WebCore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r258424 r258434  
     12020-03-13  Peng Liu  <peng.liu6@apple.com>
     2
     3        Safari sometimes crashes when switch video into PiP mode
     4        https://bugs.webkit.org/show_bug.cgi?id=208904
     5
     6        Reviewed by Simon Fraser.
     7
     8        With this patch, MediaControlTextTrackContainerElement won't paint its subtree
     9        to an image buffer (for the captions in video fullscreen or picture-in-picture mode)
     10        when the cues are updated. Instead, it only sets the flag m_needsGenerateTextTrackRepresentation
     11        to true after running layout based on the new cues. After that, it paints its subtree
     12        to an image buffer if needed at the end of Page::updateRendering() when the layout is clean.
     13        TextTrackRepresentationCocoa will use the image buffer to set the content of the layer
     14        for captions in video fullscreen or picture-in-picture mode.
     15
     16        MediaControlTextTrackContainerElement class is responsible for rendering the captions in both:
     17        1) a video player in the inline mode.
     18        2) a video player in "video fullscreen" or picture-in-picture mode.
     19        This patch refactors some functions to make their responsibilities clear.
     20
     21        * Modules/mediacontrols/MediaControlsHost.cpp:
     22        (WebCore::MediaControlsHost::updateTextTrackRepresentationImageIfNeeded):
     23        * Modules/mediacontrols/MediaControlsHost.h:
     24        * dom/Document.cpp:
     25        (WebCore::Document::setMediaElementShowingTextTrack):
     26        (WebCore::Document::clearMediaElementShowingTextTrack):
     27        (WebCore::Document::updateTextTrackRepresentationImageIfNeeded):
     28        * dom/Document.h:
     29
     30        Functions textTracksAreReady(), textTrackReadyStateChanged() and configureTextTrackDisplay()
     31        should be wrapped with "#if ENABLE(VIDEO_TRACK)".
     32        * html/HTMLMediaElement.cpp:
     33        (WebCore::HTMLMediaElement::setTextTrackRepresentation):
     34        (WebCore::HTMLMediaElement::textTracksAreReady const):
     35        (WebCore::HTMLMediaElement::textTrackReadyStateChanged):
     36        (WebCore::HTMLMediaElement::configureTextTrackDisplay):
     37        (WebCore::HTMLMediaElement::updateTextTrackRepresentationImageIfNeeded):
     38        * html/HTMLMediaElement.h:
     39
     40        * html/shadow/MediaControlElements.cpp:
     41        (WebCore::MediaControlTextTrackContainerElement::createElementRenderer):
     42        (WebCore::MediaControlTextTrackContainerElement::updateDisplay):
     43        (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationImageIfNeeded):
     44        (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationIfNeeded):
     45        (WebCore::MediaControlTextTrackContainerElement::clearTextTrackRepresentation):
     46        (WebCore::MediaControlTextTrackContainerElement::updateTextTrackStyle):
     47        (WebCore::MediaControlTextTrackContainerElement::enteredFullscreen):
     48        (WebCore::MediaControlTextTrackContainerElement::updateVideoDisplaySize):
     49        (WebCore::MediaControlTextTrackContainerElement::updateSizes):
     50        (WebCore::MediaControlTextTrackContainerElement::createTextTrackRepresentationImage):
     51        (WebCore::MediaControlTextTrackContainerElement::textTrackRepresentationBoundsChanged):
     52        (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentation): Deleted.
     53        (WebCore::MediaControlTextTrackContainerElement::updateTextTrackRepresentationStyle): Deleted.
     54        (WebCore::MediaControlTextTrackContainerElement::layoutIfNecessary): Deleted.
     55        (WebCore::MediaControlTextTrackContainerElement::updateCueStyles): Deleted.
     56        * html/shadow/MediaControlElements.h:
     57        * html/shadow/MediaControls.cpp:
     58        (WebCore::MediaControls::updateTextTrackRepresentationImageIfNeeded):
     59        * html/shadow/MediaControls.h:
     60        * page/Page.cpp:
     61        (WebCore::Page::updateRendering):
     62        * rendering/RenderMediaControlElements.cpp:
     63        (WebCore::RenderMediaControlTextTrackContainer::RenderMediaControlTextTrackContainer):
     64        (WebCore::RenderMediaControlTextTrackContainer::layout):
     65        (WebCore::RenderTextTrackContainerElement::RenderTextTrackContainerElement): Deleted.
     66        (WebCore::RenderTextTrackContainerElement::layout): Deleted.
     67        * rendering/RenderMediaControlElements.h:
     68
    1692020-03-13  Ryan Haddad  <ryanhaddad@apple.com>
    270
  • trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp

    r257997 r258434  
    173173}
    174174
     175void MediaControlsHost::updateTextTrackRepresentationImageIfNeeded()
     176{
     177    if (m_textTrackContainer)
     178        m_textTrackContainer->updateTextTrackRepresentationImageIfNeeded();
     179}
     180
    175181void MediaControlsHost::enteredFullscreen()
    176182{
  • trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.h

    r258248 r258434  
    7474    enum class ForceUpdate { Yes, No };
    7575    void updateCaptionDisplaySizes(ForceUpdate = ForceUpdate::No);
     76    void updateTextTrackRepresentationImageIfNeeded();
    7677    void enteredFullscreen();
    7778    void exitedFullscreen();
  • trunk/Source/WebCore/dom/Document.cpp

    r258268 r258434  
    54525452}
    54535453
     5454void Document::setMediaElementShowingTextTrack(const HTMLMediaElement& element)
     5455{
     5456    m_mediaElementShowingTextTrack = makeWeakPtr(element);
     5457}
     5458
     5459void Document::clearMediaElementShowingTextTrack()
     5460{
     5461    m_mediaElementShowingTextTrack = nullptr;
     5462}
     5463
     5464void Document::updateTextTrackRepresentationImageIfNeeded()
     5465{
     5466    if (m_mediaElementShowingTextTrack)
     5467        m_mediaElementShowingTextTrack->updateTextTrackRepresentationImageIfNeeded();
     5468}
     5469
    54545470#endif
    54555471
  • trunk/Source/WebCore/dom/Document.h

    r258214 r258434  
    11161116    void unregisterForCaptionPreferencesChangedCallbacks(HTMLMediaElement&);
    11171117    void captionPreferencesChanged();
     1118    void setMediaElementShowingTextTrack(const HTMLMediaElement&);
     1119    void clearMediaElementShowingTextTrack();
     1120    void updateTextTrackRepresentationImageIfNeeded();
    11181121#endif
    11191122
     
    18021805#if ENABLE(VIDEO_TRACK)
    18031806    HashSet<HTMLMediaElement*> m_captionPreferencesChangedElements;
     1807    WeakPtr<HTMLMediaElement> m_mediaElementShowingTextTrack;
    18041808#endif
    18051809
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r258295 r258434  
    18771877}
    18781878
    1879 bool HTMLMediaElement::textTracksAreReady() const
    1880 {
    1881     // 4.8.10.12.1 Text track model
    1882     // ...
    1883     // The text tracks of a media element are ready if all the text tracks whose mode was not
    1884     // in the disabled state when the element's resource selection algorithm last started now
    1885     // have a text track readiness state of loaded or failed to load.
    1886     for (unsigned i = 0; i < m_textTracksWhenResourceSelectionBegan.size(); ++i) {
    1887         if (m_textTracksWhenResourceSelectionBegan[i]->readinessState() == TextTrack::Loading
    1888             || m_textTracksWhenResourceSelectionBegan[i]->readinessState() == TextTrack::NotLoaded)
    1889             return false;
    1890     }
    1891 
    1892     return true;
    1893 }
    1894 
    1895 void HTMLMediaElement::textTrackReadyStateChanged(TextTrack* track)
    1896 {
    1897     if (track->readinessState() != TextTrack::Loading
    1898         && track->mode() != TextTrack::Mode::Disabled) {
    1899         // The display trees exist as long as the track is active, in this case,
    1900         // and if the same track is loaded again (for example if the src attribute was changed),
    1901         // cues can be accumulated with the old ones, that's why they needs to be flushed
    1902         if (hasMediaControls())
    1903             mediaControls()->clearTextDisplayContainer();
    1904         updateTextTrackDisplay();
    1905     }
    1906     if (m_player && m_textTracksWhenResourceSelectionBegan.contains(track)) {
    1907         if (track->readinessState() != TextTrack::Loading)
    1908             setReadyState(m_player->readyState());
    1909     } else {
    1910         // The track readiness state might have changed as a result of the user
    1911         // clicking the captions button. In this case, a check whether all the
    1912         // resources have failed loading should be done in order to hide the CC button.
    1913         if (hasMediaControls() && track->readinessState() == TextTrack::FailedToLoad)
    1914             mediaControls()->refreshClosedCaptionsButtonVisibility();
    1915     }
    1916 }
    1917 
    19181879void HTMLMediaElement::audioTrackEnabledChanged(AudioTrack& track)
    19191880{
     
    58525813    if (m_player)
    58535814        m_player->setTextTrackRepresentation(representation);
     5815
     5816    if (representation)
     5817        document().setMediaElementShowingTextTrack(*this);
     5818    else
     5819        document().clearMediaElementShowingTextTrack();
    58545820}
    58555821
     
    63466312#if ENABLE(VIDEO_TRACK)
    63476313
     6314bool HTMLMediaElement::textTracksAreReady() const
     6315{
     6316    // 4.8.10.12.1 Text track model
     6317    // ...
     6318    // The text tracks of a media element are ready if all the text tracks whose mode was not
     6319    // in the disabled state when the element's resource selection algorithm last started now
     6320    // have a text track readiness state of loaded or failed to load.
     6321    for (unsigned i = 0; i < m_textTracksWhenResourceSelectionBegan.size(); ++i) {
     6322        if (m_textTracksWhenResourceSelectionBegan[i]->readinessState() == TextTrack::Loading
     6323            || m_textTracksWhenResourceSelectionBegan[i]->readinessState() == TextTrack::NotLoaded)
     6324            return false;
     6325    }
     6326
     6327    return true;
     6328}
     6329
     6330void HTMLMediaElement::textTrackReadyStateChanged(TextTrack* track)
     6331{
     6332    if (track->readinessState() != TextTrack::Loading
     6333        && track->mode() != TextTrack::Mode::Disabled) {
     6334        // The display trees exist as long as the track is active, in this case,
     6335        // and if the same track is loaded again (for example if the src attribute was changed),
     6336        // cues can be accumulated with the old ones, that's why they needs to be flushed
     6337        if (hasMediaControls())
     6338            mediaControls()->clearTextDisplayContainer();
     6339        updateTextTrackDisplay();
     6340    }
     6341    if (m_player && m_textTracksWhenResourceSelectionBegan.contains(track)) {
     6342        if (track->readinessState() != TextTrack::Loading)
     6343            setReadyState(m_player->readyState());
     6344    } else {
     6345        // The track readiness state might have changed as a result of the user
     6346        // clicking the captions button. In this case, a check whether all the
     6347        // resources have failed loading should be done in order to hide the CC button.
     6348        if (hasMediaControls() && track->readinessState() == TextTrack::FailedToLoad)
     6349            mediaControls()->refreshClosedCaptionsButtonVisibility();
     6350    }
     6351}
     6352
     6353void HTMLMediaElement::configureTextTrackDisplay(TextTrackVisibilityCheckType checkType)
     6354{
     6355    ALWAYS_LOG(LOGIDENTIFIER, checkType);
     6356    ASSERT(m_textTracks);
     6357
     6358    if (m_processingPreferenceChange)
     6359        return;
     6360
     6361    if (document().activeDOMObjectsAreStopped())
     6362        return;
     6363
     6364    bool haveVisibleTextTrack = false;
     6365    for (unsigned i = 0; i < m_textTracks->length(); ++i) {
     6366        if (m_textTracks->item(i)->mode() == TextTrack::Mode::Showing) {
     6367            haveVisibleTextTrack = true;
     6368            break;
     6369        }
     6370    }
     6371
     6372    if (checkType == CheckTextTrackVisibility && m_haveVisibleTextTrack == haveVisibleTextTrack) {
     6373        updateActiveTextTrackCues(currentMediaTime());
     6374        return;
     6375    }
     6376
     6377    m_haveVisibleTextTrack = haveVisibleTextTrack;
     6378    m_closedCaptionsVisible = m_haveVisibleTextTrack;
     6379
     6380#if ENABLE(MEDIA_CONTROLS_SCRIPT)
     6381    if (!m_haveVisibleTextTrack)
     6382        return;
     6383
     6384    ensureMediaControlsShadowRoot();
     6385    updateTextTrackDisplay();
     6386#else
     6387    if (!m_haveVisibleTextTrack && !hasMediaControls() && !createMediaControls())
     6388        return;
     6389
     6390    mediaControls()->changedClosedCaptionsVisibility();
     6391
     6392    updateTextTrackDisplay();
     6393    updateActiveTextTrackCues(currentMediaTime());
     6394#endif
     6395}
     6396
    63486397void HTMLMediaElement::updateTextTrackDisplay()
    63496398{
     
    63616410}
    63626411
     6412void HTMLMediaElement::updateTextTrackRepresentationImageIfNeeded()
     6413{
     6414#if ENABLE(MEDIA_CONTROLS_SCRIPT)
     6415    ensureMediaControlsShadowRoot();
     6416    if (!m_mediaControlsHost)
     6417        m_mediaControlsHost = MediaControlsHost::create(*this);
     6418    m_mediaControlsHost->updateTextTrackRepresentationImageIfNeeded();
     6419#else
     6420    if (!hasMediaControls() && !createMediaControls())
     6421        return;
     6422
     6423    mediaControls()->updateTextTrackRepresentationImageIfNeeded();
     6424#endif
     6425}
     6426
    63636427#endif
    63646428
     
    66016665
    66026666#if ENABLE(VIDEO_TRACK)
    6603 void HTMLMediaElement::configureTextTrackDisplay(TextTrackVisibilityCheckType checkType)
    6604 {
    6605     ALWAYS_LOG(LOGIDENTIFIER, checkType);
    6606     ASSERT(m_textTracks);
    6607 
    6608     if (m_processingPreferenceChange)
    6609         return;
    6610 
    6611     if (document().activeDOMObjectsAreStopped())
    6612         return;
    6613 
    6614     bool haveVisibleTextTrack = false;
    6615     for (unsigned i = 0; i < m_textTracks->length(); ++i) {
    6616         if (m_textTracks->item(i)->mode() == TextTrack::Mode::Showing) {
    6617             haveVisibleTextTrack = true;
    6618             break;
    6619         }
    6620     }
    6621 
    6622     if (checkType == CheckTextTrackVisibility && m_haveVisibleTextTrack == haveVisibleTextTrack) {
    6623         updateActiveTextTrackCues(currentMediaTime());
    6624         return;
    6625     }
    6626 
    6627     m_haveVisibleTextTrack = haveVisibleTextTrack;
    6628     m_closedCaptionsVisible = m_haveVisibleTextTrack;
    6629 
    6630 #if ENABLE(MEDIA_CONTROLS_SCRIPT)
    6631     if (!m_haveVisibleTextTrack)
    6632         return;
    6633 
    6634     ensureMediaControlsShadowRoot();
    6635     updateTextTrackDisplay();
    6636 #else
    6637     if (!m_haveVisibleTextTrack && !hasMediaControls())
    6638         return;
    6639     if (!hasMediaControls() && !createMediaControls())
    6640         return;
    6641 
    6642     mediaControls()->changedClosedCaptionsVisibility();
    6643 
    6644     updateTextTrackDisplay();
    6645     updateActiveTextTrackCues(currentMediaTime());
    6646 #endif
    6647 }
    66486667
    66496668void HTMLMediaElement::captionPreferencesChanged()
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r258295 r258434  
    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
     
    812808    void markCaptionAndSubtitleTracksAsUnconfigured(ReconfigureMode);
    813809    CaptionUserPreferences::CaptionDisplayMode captionDisplayMode();
     810
     811    bool textTracksAreReady() const;
     812    void configureTextTrackDisplay(TextTrackVisibilityCheckType = CheckTextTrackVisibility);
     813    void updateTextTrackDisplay();
    814814#endif
    815815
  • trunk/Source/WebCore/html/shadow/MediaControlElements.cpp

    r257997 r258434  
    11071107RenderPtr<RenderElement> MediaControlTextTrackContainerElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
    11081108{
    1109     return createRenderer<RenderTextTrackContainerElement>(*this, WTFMove(style));
     1109    return createRenderer<RenderMediaControlTextTrackContainer>(*this, WTFMove(style));
    11101110}
    11111111
     
    11851185
    11861186    if (mediaController()->closedCaptionsVisible()) {
    1187         // 10. For each text track cue cue in cues that has not yet had
     1187        // 10. For each text track cue in cues that has not yet had
    11881188        // corresponding CSS boxes added to output, in text track cue order, run the
    11891189        // following substeps:
     
    12071207        hide();
    12081208
    1209     if (m_textTrackRepresentation || video.requiresTextTrackRepresentation())
    1210         updateTextTrackRepresentation();
     1209    updateTextTrackRepresentationIfNeeded();
     1210    updateTextTrackStyle();
     1211    m_needsGenerateTextTrackRepresentation = true;
     1212}
     1213
     1214void MediaControlTextTrackContainerElement::updateTextTrackRepresentationImageIfNeeded()
     1215{
     1216    if (!m_needsGenerateTextTrackRepresentation)
     1217        return;
     1218
     1219    m_needsGenerateTextTrackRepresentation = false;
     1220
     1221    // We should call m_textTrackRepresentation->update() to paint the subtree of
     1222    // the RenderTextTrackContainerElement after the layout is clean.
     1223    if (m_textTrackRepresentation)
     1224        m_textTrackRepresentation->update();
    12111225}
    12121226
     
    12881302}
    12891303
    1290 void MediaControlTextTrackContainerElement::updateTextTrackRepresentation()
     1304void MediaControlTextTrackContainerElement::updateTextTrackRepresentationIfNeeded()
    12911305{
    12921306    auto mediaElement = parentMediaElement(this);
     
    12971311    if (!hasChildNodes() || !requiresTextTrackRepresentation) {
    12981312        if (m_textTrackRepresentation) {
    1299             if (!requiresTextTrackRepresentation) {
     1313            if (!requiresTextTrackRepresentation)
    13001314                clearTextTrackRepresentation();
    1301                 updateSizes(ForceUpdate::Yes);
    1302             } else
     1315            else
    13031316                m_textTrackRepresentation->setHidden(true);
    13041317        }
     
    13091322        ALWAYS_LOG(LOGIDENTIFIER);
    13101323
    1311         m_waitingForFirstLayout = true;
    13121324        m_textTrackRepresentation = TextTrackRepresentation::create(*this);
    13131325        if (document().page())
    13141326            m_textTrackRepresentation->setContentScale(document().page()->deviceScaleFactor());
    13151327        mediaElement->setTextTrackRepresentation(m_textTrackRepresentation.get());
    1316         updateSizes();
    1317         updateTextTrackRepresentationStyle();
    13181328    }
    13191329
    13201330    m_textTrackRepresentation->setHidden(false);
    1321     if (!m_waitingForFirstLayout)
    1322         m_textTrackRepresentation->update();
    13231331}
    13241332
     
    13301338    ALWAYS_LOG(LOGIDENTIFIER);
    13311339
    1332     m_waitingForFirstLayout = true;
    13331340    m_textTrackRepresentation = nullptr;
    13341341    if (auto mediaElement = parentMediaElement(this))
    13351342        mediaElement->setTextTrackRepresentation(nullptr);
    1336     updateTextTrackRepresentationStyle();
    1337     updateActiveCuesFontSize();
    1338 }
    1339 
    1340 void MediaControlTextTrackContainerElement::updateTextTrackRepresentationStyle()
     1343}
     1344
     1345void MediaControlTextTrackContainerElement::updateTextTrackStyle()
    13411346{
    13421347    if (m_textTrackRepresentation) {
     1348        setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute);
    13431349        setInlineStyleProperty(CSSPropertyWidth, m_videoDisplaySize.size().width(), CSSUnitType::CSS_PX);
    13441350        setInlineStyleProperty(CSSPropertyHeight, m_videoDisplaySize.size().height(), CSSUnitType::CSS_PX);
    1345         setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute);
    13461351        setInlineStyleProperty(CSSPropertyLeft, 0, CSSUnitType::CSS_PX);
    13471352        setInlineStyleProperty(CSSPropertyTop, 0, CSSUnitType::CSS_PX);
     
    13581363void MediaControlTextTrackContainerElement::enteredFullscreen()
    13591364{
    1360     if (hasChildNodes())
    1361         updateTextTrackRepresentation();
     1365    updateTextTrackRepresentationIfNeeded();
    13621366    updateSizes(ForceUpdate::Yes);
    13631367}
     
    13671371    clearTextTrackRepresentation();
    13681372    updateSizes(ForceUpdate::Yes);
    1369 }
    1370 
    1371 void MediaControlTextTrackContainerElement::layoutIfNecessary()
    1372 {
    1373     m_waitingForFirstLayout = false;
    1374 
    1375     auto sizeChanged = updateVideoDisplaySize();
    1376     if (m_textTrackRepresentation)
    1377         m_textTrackRepresentation->update();
    1378 
    1379     if (!sizeChanged)
    1380         return;
    1381 
    1382     // FIXME (121170): This function is called during layout, and should lay out the text tracks immediately.
    1383     m_taskQueue.enqueueTask([this] () {
    1384         updateCueStyles();
    1385     });
    13861373}
    13871374
     
    14111398
    14121399    m_videoDisplaySize = videoBox;
    1413     updateTextTrackRepresentationStyle();
    1414 
    14151400    return true;
    14161401}
     
    14181403void MediaControlTextTrackContainerElement::updateSizes(ForceUpdate force)
    14191404{
    1420     if (updateVideoDisplaySize() || force == ForceUpdate::Yes)
    1421         updateCueStyles();
    1422 }
    1423 
    1424 void MediaControlTextTrackContainerElement::updateCueStyles()
    1425 {
     1405    if (!updateVideoDisplaySize() && force != ForceUpdate::Yes)
     1406        return;
     1407
    14261408    if (!document().page())
    14271409        return;
     
    14331415    mediaElement->syncTextTrackBounds();
    14341416
     1417    updateActiveCuesFontSize();
     1418    updateTextStrokeStyle();
    14351419    for (auto& activeCue : mediaElement->currentlyActiveCues())
    14361420        activeCue.data()->recalculateStyles();
    14371421
    1438     updateActiveCuesFontSize();
    1439     updateDisplay();
    1440     updateTextStrokeStyle();
     1422    m_taskQueue.enqueueTask([this] () {
     1423        updateDisplay();
     1424    });
    14411425}
    14421426
     
    14721456        return nullptr;
    14731457
    1474     layer->paint(buffer->context(), paintingRect, LayoutSize(), { PaintBehavior::FlattenCompositingLayers, PaintBehavior::Snapshotting }, nullptr, RenderLayer::paintLayerPaintingCompositingAllPhasesFlags());
     1458    auto paintFlags = RenderLayer::paintLayerPaintingCompositingAllPhasesFlags();
     1459    paintFlags.add(RenderLayer::PaintLayerTemporaryClipRects);
     1460    layer->paint(buffer->context(), paintingRect, LayoutSize(), { PaintBehavior::FlattenCompositingLayers, PaintBehavior::Snapshotting }, nullptr, paintFlags);
    14751461
    14761462    return ImageBuffer::sinkIntoImage(WTFMove(buffer));
     
    14791465void MediaControlTextTrackContainerElement::textTrackRepresentationBoundsChanged(const IntRect&)
    14801466{
    1481     if (hasChildNodes())
    1482         updateTextTrackRepresentation();
     1467    updateTextTrackRepresentationIfNeeded();
    14831468    updateSizes();
    14841469}
  • trunk/Source/WebCore/html/shadow/MediaControlElements.h

    r256060 r258434  
    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
  • trunk/Source/WebCore/html/shadow/MediaControls.cpp

    r251950 r258434  
    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
  • trunk/Source/WebCore/html/shadow/MediaControls.h

    r257296 r258434  
    9999    virtual void textTrackPreferencesChanged();
    100100    virtual void clearTextDisplayContainer();
     101    virtual void updateTextTrackRepresentationImageIfNeeded();
    101102#endif
    102103
  • trunk/Source/WebCore/page/Page.cpp

    r258339 r258434  
    13561356
    13571357    layoutIfNeeded();
    1358    
     1358
    13591359    forEachDocument([] (Document& document) {
    13601360        document.updateHighlightPositions();
    13611361    });
     1362
     1363#if ENABLE(VIDEO_TRACK)
     1364    forEachDocument([] (Document& document) {
     1365        document.updateTextTrackRepresentationImageIfNeeded();
     1366    });
     1367#endif
    13621368}
    13631369
  • trunk/Source/WebCore/rendering/RenderMediaControlElements.cpp

    r256060 r258434  
    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
  • trunk/Source/WebCore/rendering/RenderMediaControlElements.h

    r224537 r258434  
    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.