Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: third_party/WebKit/Source/core/html/shadow/MediaControls.cpp

Issue 2280123002: Fix under-invalidation of media buffered ranges (Closed)
Patch Set: Synchronize buffered ranges when the current play time changes Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 14 matching lines...) Expand all
25 */ 25 */
26 26
27 #include "core/html/shadow/MediaControls.h" 27 #include "core/html/shadow/MediaControls.h"
28 28
29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
30 #include "core/dom/ClientRect.h" 30 #include "core/dom/ClientRect.h"
31 #include "core/dom/Fullscreen.h" 31 #include "core/dom/Fullscreen.h"
32 #include "core/events/MouseEvent.h" 32 #include "core/events/MouseEvent.h"
33 #include "core/frame/Settings.h" 33 #include "core/frame/Settings.h"
34 #include "core/html/HTMLMediaElement.h" 34 #include "core/html/HTMLMediaElement.h"
35 #include "core/html/TimeRanges.h"
35 #include "core/html/track/TextTrackContainer.h" 36 #include "core/html/track/TextTrackContainer.h"
36 #include "core/layout/LayoutTheme.h" 37 #include "core/layout/LayoutTheme.h"
37 #include "platform/EventDispatchForbiddenScope.h" 38 #include "platform/EventDispatchForbiddenScope.h"
38 39
39 namespace blink { 40 namespace blink {
40 41
41 // If you change this value, then also update the corresponding value in 42 // If you change this value, then also update the corresponding value in
42 // LayoutTests/media/media-controls.js. 43 // LayoutTests/media/media-controls.js.
43 static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3; 44 static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3;
44 45
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 , m_textTrackList(nullptr) 120 , m_textTrackList(nullptr)
120 , m_castButton(nullptr) 121 , m_castButton(nullptr)
121 , m_fullScreenButton(nullptr) 122 , m_fullScreenButton(nullptr)
122 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired ) 123 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired )
123 , m_hideTimerBehaviorFlags(IgnoreNone) 124 , m_hideTimerBehaviorFlags(IgnoreNone)
124 , m_isMouseOverControls(false) 125 , m_isMouseOverControls(false)
125 , m_isPausedForScrubbing(false) 126 , m_isPausedForScrubbing(false)
126 , m_panelWidthChangedTimer(this, &MediaControls::panelWidthChangedTimerFired ) 127 , m_panelWidthChangedTimer(this, &MediaControls::panelWidthChangedTimerFired )
127 , m_panelWidth(0) 128 , m_panelWidth(0)
128 , m_allowHiddenVolumeControls(RuntimeEnabledFeatures::newMediaPlaybackUiEnab led()) 129 , m_allowHiddenVolumeControls(RuntimeEnabledFeatures::newMediaPlaybackUiEnab led())
130 , m_bufferedRangesPaintInvalidationTimer(this, &MediaControls::bufferedRange sPaintInvalidationTimerFired)
129 { 131 {
130 } 132 }
131 133
132 MediaControls* MediaControls::create(HTMLMediaElement& mediaElement) 134 MediaControls* MediaControls::create(HTMLMediaElement& mediaElement)
133 { 135 {
134 MediaControls* controls = new MediaControls(mediaElement); 136 MediaControls* controls = new MediaControls(mediaElement);
135 controls->setShadowPseudoId(AtomicString("-webkit-media-controls")); 137 controls->setShadowPseudoId(AtomicString("-webkit-media-controls"));
136 controls->initializeControls(); 138 controls->initializeControls();
137 return controls; 139 return controls;
138 } 140 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 270
269 // If the player has entered an error state, force it into the paused state. 271 // If the player has entered an error state, force it into the paused state.
270 if (mediaElement().error()) 272 if (mediaElement().error())
271 mediaElement().pause(); 273 mediaElement().pause();
272 274
273 updatePlayState(); 275 updatePlayState();
274 276
275 updateCurrentTimeDisplay(); 277 updateCurrentTimeDisplay();
276 278
277 m_timeline->setDuration(duration); 279 m_timeline->setDuration(duration);
278 m_timeline->setPosition(mediaElement().currentTime()); 280 updateTimelinePosition();
279 281
280 updateVolume(); 282 updateVolume();
281 283
282 refreshClosedCaptionsButtonVisibility(); 284 refreshClosedCaptionsButtonVisibility();
283 285
284 m_fullScreenButton->setIsWanted(shouldShowFullscreenButton(mediaElement())); 286 m_fullScreenButton->setIsWanted(shouldShowFullscreenButton(mediaElement()));
285 287
286 refreshCastButtonVisibilityWithoutUpdate(); 288 refreshCastButtonVisibilityWithoutUpdate();
287 } 289 }
288 290
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 void MediaControls::playbackStarted() 356 void MediaControls::playbackStarted()
355 { 357 {
356 BatchedControlUpdate batch(this); 358 BatchedControlUpdate batch(this);
357 359
358 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { 360 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) {
359 m_currentTimeDisplay->setIsWanted(true); 361 m_currentTimeDisplay->setIsWanted(true);
360 m_durationDisplay->setIsWanted(false); 362 m_durationDisplay->setIsWanted(false);
361 } 363 }
362 364
363 updatePlayState(); 365 updatePlayState();
364 m_timeline->setPosition(mediaElement().currentTime()); 366 updateTimelinePosition();
365 updateCurrentTimeDisplay(); 367 updateCurrentTimeDisplay();
366 368
367 startHideMediaControlsTimer(); 369 startHideMediaControlsTimer();
368 } 370 }
369 371
370 void MediaControls::playbackProgressed() 372 void MediaControls::playbackProgressed()
371 { 373 {
372 m_timeline->setPosition(mediaElement().currentTime()); 374 updateTimelinePosition();
373 updateCurrentTimeDisplay(); 375 updateCurrentTimeDisplay();
374 376
375 if (shouldHideMediaControls()) 377 if (shouldHideMediaControls())
376 makeTransparent(); 378 makeTransparent();
377 } 379 }
378 380
379 void MediaControls::playbackStopped() 381 void MediaControls::playbackStopped()
380 { 382 {
381 updatePlayState(); 383 updatePlayState();
382 m_timeline->setPosition(mediaElement().currentTime()); 384 updateTimelinePosition();
383 updateCurrentTimeDisplay(); 385 updateCurrentTimeDisplay();
384 makeOpaque(); 386 makeOpaque();
385 387
386 stopHideMediaControlsTimer(); 388 stopHideMediaControlsTimer();
387 } 389 }
388 390
389 void MediaControls::updatePlayState() 391 void MediaControls::updatePlayState()
390 { 392 {
391 if (m_isPausedForScrubbing) 393 if (m_isPausedForScrubbing)
392 return; 394 return;
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 769
768 void MediaControls::invalidate(Element* element) 770 void MediaControls::invalidate(Element* element)
769 { 771 {
770 if (!element) 772 if (!element)
771 return; 773 return;
772 774
773 if (LayoutObject* layoutObject = element->layoutObject()) 775 if (LayoutObject* layoutObject = element->layoutObject())
774 layoutObject->setShouldDoFullPaintInvalidation(); 776 layoutObject->setShouldDoFullPaintInvalidation();
775 } 777 }
776 778
779 static const double kBufferedRangesPaintInvalidationInterval = 0.5;
780
777 void MediaControls::networkStateChanged() 781 void MediaControls::networkStateChanged()
778 { 782 {
779 invalidate(m_playButton); 783 invalidate(m_playButton);
780 invalidate(m_overlayPlayButton); 784 invalidate(m_overlayPlayButton);
781 invalidate(m_muteButton); 785 invalidate(m_muteButton);
782 invalidate(m_fullScreenButton); 786 invalidate(m_fullScreenButton);
783 invalidate(m_timeline); 787 invalidate(m_timeline);
784 invalidate(m_volumeSlider); 788 invalidate(m_volumeSlider);
789
790 updateBufferedRanges();
791 if (m_mediaElement->getNetworkState() == HTMLMediaElement::kNetworkLoading) {
792 if (!m_bufferedRangesPaintInvalidationTimer.isActive())
793 m_bufferedRangesPaintInvalidationTimer.startRepeating(kBufferedRange sPaintInvalidationInterval, BLINK_FROM_HERE);
794 } else {
795 m_bufferedRangesPaintInvalidationTimer.stop();
796 }
797 }
798
799 void MediaControls::updateTimelinePosition()
800 {
801 m_timeline->setPosition(mediaElement().currentTime());
802 // Synchronize buffered ranges when the current time change.
803 updateBufferedRanges();
804 }
805
806 void MediaControls::updateBufferedRanges()
807 {
808 TimeRanges* newBuffered = m_mediaElement->buffered();
809 if (!m_bufferedRangesForPainting) {
810 if (!newBuffered->length())
811 return;
812 } else if (*m_bufferedRangesForPainting == *newBuffered) {
liberato (no reviews please) 2016/08/29 15:25:34 might one just unconditionally invalidate the time
Xianzhu 2016/08/29 18:04:14 Good question. It's unlikely to save invalidations
813 return;
814 }
815
816 m_bufferedRangesForPainting = newBuffered;
817 invalidate(m_timeline);
818 }
819
820 void MediaControls::bufferedRangesPaintInvalidationTimerFired(TimerBase*)
821 {
822 updateBufferedRanges();
785 } 823 }
786 824
787 DEFINE_TRACE(MediaControls) 825 DEFINE_TRACE(MediaControls)
788 { 826 {
789 visitor->trace(m_mediaElement); 827 visitor->trace(m_mediaElement);
790 visitor->trace(m_panel); 828 visitor->trace(m_panel);
791 visitor->trace(m_overlayPlayButton); 829 visitor->trace(m_overlayPlayButton);
792 visitor->trace(m_overlayEnclosure); 830 visitor->trace(m_overlayEnclosure);
793 visitor->trace(m_playButton); 831 visitor->trace(m_playButton);
794 visitor->trace(m_currentTimeDisplay); 832 visitor->trace(m_currentTimeDisplay);
795 visitor->trace(m_timeline); 833 visitor->trace(m_timeline);
796 visitor->trace(m_muteButton); 834 visitor->trace(m_muteButton);
797 visitor->trace(m_volumeSlider); 835 visitor->trace(m_volumeSlider);
798 visitor->trace(m_toggleClosedCaptionsButton); 836 visitor->trace(m_toggleClosedCaptionsButton);
799 visitor->trace(m_fullScreenButton); 837 visitor->trace(m_fullScreenButton);
800 visitor->trace(m_durationDisplay); 838 visitor->trace(m_durationDisplay);
801 visitor->trace(m_enclosure); 839 visitor->trace(m_enclosure);
802 visitor->trace(m_textTrackList); 840 visitor->trace(m_textTrackList);
803 visitor->trace(m_castButton); 841 visitor->trace(m_castButton);
804 visitor->trace(m_overlayCastButton); 842 visitor->trace(m_overlayCastButton);
843 visitor->trace(m_bufferedRangesForPainting);
805 HTMLDivElement::trace(visitor); 844 HTMLDivElement::trace(visitor);
806 } 845 }
807 846
808 } // namespace blink 847 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698