Changeset 95513 in webkit


Ignore:
Timestamp:
Sep 19, 2011 9:14:55 PM (13 years ago)
Author:
mrowe@apple.com
Message:

<http://webkit.org/b/68421> Stop calling UpdateSystemActivity in places where we hold power assertions that achieve the same effect

On SnowLeopard and newer it's not necessary to call UpdateSystemActivity to prevent the screensaver from kicking
in as the NoDisplaySleep assertion now has that effect. It's also not necessary to hold both a NoDisplaySleep and
a NoIdleSleep assertion as the latter is implied by the former.

Source/WebCore:

Since there were multiple copies of the same code to disable display sleep spread across WebCore, WebKit and WebKit2
this patch takes the approach of moving this functionality to a new DisplaySleepDisabler class that lives in WebCore.
A class is used as it makes it easier to reason about the lifetime of the assertions and to ensure that the assertions will
always be released when their owning objects go away.

Reviewed by Dan Bernstein.

  • WebCore.exp.in:
  • WebCore.xcodeproj/project.pbxproj:
  • platform/mac/DisplaySleepDisabler.cpp:

(WebCore::DisplaySleepDisabler::DisplaySleepDisabler): Register for the NoDisplaySleep assertion, and start our
system activity timer when on Leopard.
(WebCore::DisplaySleepDisabler::~DisplaySleepDisabler): Unregister for the assertion.
(WebCore::DisplaySleepDisabler::systemActivityTimerFired): Call UpdateSystemActivity to prevent the screensaver from
triggering on Leopard.

  • platform/mac/DisplaySleepDisabler.h:

(WebCore::DisplaySleepDisabler::create):

  • platform/mac/WebVideoFullscreenController.h:
  • platform/mac/WebVideoFullscreenController.mm:

(-[WebVideoFullscreenController dealloc]):
(-[WebVideoFullscreenController setupVideoOverlay:]): Remove the now-unnecessary explicit use of the WebCore namespace.
(-[WebVideoFullscreenController mediaElement]): Ditto.
(-[WebVideoFullscreenController setMediaElement:]): Ditto.
(-[WebVideoFullscreenController windowDidExitFullscreen]): Ditto.
(-[WebVideoFullscreenController updatePowerAssertions]): Create a DisplaySleepDisabler instance when transitioning from permitting
display sleep to disabling display sleep. Clear out our reference when sleep should be permitted, destroying any
disabler that we own.

Source/WebKit/mac:

Adopt the DisplaySleepDisabler class that was added to WebCore and remove all of duplicated logic from WebFullScreenController.

Reviewed by Dan Bernstein.

  • WebView/WebFullScreenController.h:
  • WebView/WebFullScreenController.mm:

(-[WebFullScreenController dealloc]):
(-[WebFullScreenController _updatePowerAssertions]): Create a DisplaySleepDisabler instance when transitioning from permitting
display sleep to disabling display sleep. Clear out our reference when sleep should be permitted, destroying any
disabler that we own.

Source/WebKit2:

Adopt the DisplaySleepDisabler class that was added to WebCore and remove all of duplicated logic from WKFullScreenWindowController.

Reviewed by Dan Bernstein.

  • UIProcess/mac/WKFullScreenWindowController.h:
  • UIProcess/mac/WKFullScreenWindowController.mm:

(-[WKFullScreenWindowController _updatePowerAssertions]): Create a DisplaySleepDisabler instance when transitioning from permitting
display sleep to disabling display sleep. Clear out our reference when sleep should be permitted, destroying any
disabler that we own. Also adds a FIXME about an error that was noticed while working in this code.

Location:
trunk/Source
Files:
11 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r95509 r95513  
     12011-09-19  Mark Rowe  <mrowe@apple.com>
     2
     3        <http://webkit.org/b/68421> Stop calling UpdateSystemActivity in places where we hold power assertions that achieve the same effect
     4
     5        On SnowLeopard and newer it's not necessary to call UpdateSystemActivity to prevent the screensaver from kicking
     6        in as the NoDisplaySleep assertion now has that effect. It's also not necessary to hold both a NoDisplaySleep and
     7        a NoIdleSleep assertion as the latter is implied by the former.
     8
     9        Since there were multiple copies of the same code to disable display sleep spread across WebCore, WebKit and WebKit2
     10        this patch takes the approach of moving this functionality to a new DisplaySleepDisabler class that lives in WebCore.
     11        A class is used as it makes it easier to reason about the lifetime of the assertions and to ensure that the assertions will
     12        always be released when their owning objects go away.
     13
     14        Reviewed by Dan Bernstein.
     15
     16        * WebCore.exp.in:
     17        * WebCore.xcodeproj/project.pbxproj:
     18        * platform/mac/DisplaySleepDisabler.cpp:
     19        (WebCore::DisplaySleepDisabler::DisplaySleepDisabler): Register for the NoDisplaySleep assertion, and start our
     20        system activity timer when on Leopard.
     21        (WebCore::DisplaySleepDisabler::~DisplaySleepDisabler): Unregister for the assertion.
     22        (WebCore::DisplaySleepDisabler::systemActivityTimerFired): Call UpdateSystemActivity to prevent the screensaver from
     23        triggering on Leopard.
     24        * platform/mac/DisplaySleepDisabler.h:
     25        (WebCore::DisplaySleepDisabler::create):
     26        * platform/mac/WebVideoFullscreenController.h:
     27        * platform/mac/WebVideoFullscreenController.mm:
     28        (-[WebVideoFullscreenController dealloc]):
     29        (-[WebVideoFullscreenController setupVideoOverlay:]): Remove the now-unnecessary explicit use of the WebCore namespace.
     30        (-[WebVideoFullscreenController mediaElement]): Ditto.
     31        (-[WebVideoFullscreenController setMediaElement:]): Ditto.
     32        (-[WebVideoFullscreenController windowDidExitFullscreen]): Ditto.
     33        (-[WebVideoFullscreenController updatePowerAssertions]): Create a DisplaySleepDisabler instance when transitioning from permitting
     34        display sleep to disabling display sleep. Clear out our reference when sleep should be permitted, destroying any
     35        disabler that we own.
     36
    1372011-09-19  Ryosuke Niwa  <rniwa@webkit.org>
    238
  • trunk/Source/WebCore/WebCore.exp.in

    r95372 r95513  
    550550__ZN7WebCore19TextResourceDecoderD1Ev
    551551__ZN7WebCore19applicationIsSafariEv
     552__ZN7WebCore20DisplaySleepDisablerC1EPKc
     553__ZN7WebCore20DisplaySleepDisablerD1Ev
    552554__ZN7WebCore20NodeRenderingContextC1EPNS_4NodeE
    553555__ZN7WebCore20NodeRenderingContextD1Ev
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r95486 r95513  
    15521552                5D88EE9111407FD300BC3ABC /* DOMSVGFEMorphologyElement.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 84224189107E786F00766A87 /* DOMSVGFEMorphologyElement.h */; };
    15531553                5D88EE9211407FF400BC3ABC /* DOMSVGFEMorphologyElementInternal.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 8422418B107E786F00766A87 /* DOMSVGFEMorphologyElementInternal.h */; };
     1554                5D8C4DBF1428222C0026CE72 /* DisplaySleepDisabler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5D8C4DBD1428222C0026CE72 /* DisplaySleepDisabler.cpp */; };
     1555                5D8C4DC01428222C0026CE72 /* DisplaySleepDisabler.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D8C4DBE1428222C0026CE72 /* DisplaySleepDisabler.h */; settings = {ATTRIBUTES = (Private, ); }; };
    15541556                5D925B670F64D4DD00B847F0 /* ScrollBehavior.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5D925B650F64D4DD00B847F0 /* ScrollBehavior.cpp */; };
    15551557                5D925B680F64D4DD00B847F0 /* ScrollBehavior.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D925B660F64D4DD00B847F0 /* ScrollBehavior.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    82108212                5D87BB4F11E3EAEB00702B6F /* WebCoreExportFileGenerator */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = WebCoreExportFileGenerator; sourceTree = BUILT_PRODUCTS_DIR; };
    82118213                5D87BB8211E3ED8600702B6F /* ExportFileGenerator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ExportFileGenerator.cpp; path = DerivedSources/WebCore/ExportFileGenerator.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
     8214                5D8C4DBD1428222C0026CE72 /* DisplaySleepDisabler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DisplaySleepDisabler.cpp; sourceTree = "<group>"; };
     8215                5D8C4DBE1428222C0026CE72 /* DisplaySleepDisabler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisplaySleepDisabler.h; sourceTree = "<group>"; };
    82128216                5D925B650F64D4DD00B847F0 /* ScrollBehavior.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollBehavior.cpp; sourceTree = "<group>"; };
    82138217                5D925B660F64D4DD00B847F0 /* ScrollBehavior.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollBehavior.h; sourceTree = "<group>"; };
     
    1452914533                        isa = PBXGroup;
    1453014534                        children = (
    14531                                 93500F3113FDE3BE0099EC24 /* NSScrollerImpDetails.h */,
    1453214535                                51E1ECAD0C91C54600DC255B /* AutodrainedPool.mm */,
    1453314536                                65A640F00533BB1F0085E777 /* BlockExceptions.h */,
     
    1453914542                                9352087609BD453400F2038D /* CookieJar.mm */,
    1454014543                                F58784F002DE375901EA4122 /* CursorMac.mm */,
     14544                                5D8C4DBE1428222C0026CE72 /* DisplaySleepDisabler.h */,
     14545                                5D8C4DBD1428222C0026CE72 /* DisplaySleepDisabler.cpp */,
    1454114546                                A795463D0B5C4C80007B438F /* DragDataMac.mm */,
    1454214547                                A7CFB3D40B7ED1180070C32D /* DragImageMac.mm */,
     
    1455714562                                657EDA0A1385CBD8004E0645 /* MemoryPressureHandlerMac.mm */,
    1455814563                                BC772C5D0C4EB3440083285F /* MIMETypeRegistryMac.mm */,
     14564                                93500F3113FDE3BE0099EC24 /* NSScrollerImpDetails.h */,
    1455914565                                A7D3C5230B576B4B002CA450 /* PasteboardHelper.h */,
    1456014566                                4B2709810AF2E5E00065127F /* PasteboardMac.mm */,
     
    2046320469                        buildActionMask = 2147483647;
    2046420470                        files = (
     20471                                5D8C4DC01428222C0026CE72 /* DisplaySleepDisabler.h in Headers */,
    2046520472                                B5B5DC6A119BB3D5002A8790 /* AbstractDatabase.h in Headers */,
    2046620473                                41E1B1D10FF5986900576B3B /* AbstractWorker.h in Headers */,
     
    2631126318                                9752D38D1413104B003305BD /* JSHTMLSpanElement.cpp in Sources */,
    2631226319                                0FE71405142170B800DB33BA /* ScrollbarThemeMock.cpp in Sources */,
     26320                                5D8C4DBF1428222C0026CE72 /* DisplaySleepDisabler.cpp in Sources */,
    2631326321                        );
    2631426322                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebCore/platform/mac/DisplaySleepDisabler.cpp

    r95512 r95513  
    2424 */
    2525
    26 #if ENABLE(FULLSCREEN_API)
     26#include "config.h"
     27#include "DisplaySleepDisabler.h"
    2728
    28 #import <Cocoa/Cocoa.h>
    29 #import <wtf/RetainPtr.h>
     29#include <IOKit/pwr_mgt/IOPMLib.h>
     30#include <wtf/RetainPtr.h>
    3031
    31 namespace WebKit {
    32 class LayerTreeContext;
     32#ifdef BUILDING_ON_LEOPARD
     33#include <wtf/UnusedParam.h>
     34#endif
     35
     36namespace WebCore {
     37
     38static const double systemActivityInterval = 1;
     39
     40DisplaySleepDisabler::DisplaySleepDisabler(const char* reason)
     41    : m_disableDisplaySleepAssertion(0)
     42#ifdef BUILDING_ON_LEOPARD
     43    , m_systemActivityTimer(this, &DisplaySleepDisabler::systemActivityTimerFired)
     44#endif
     45{
     46#ifndef BUILDING_ON_LEOPARD
     47    RetainPtr<CFStringRef> reasonCF(AdoptCF, CFStringCreateWithCString(kCFAllocatorDefault, reason, kCFStringEncodingUTF8));
     48    IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonCF.get(), &m_disableDisplaySleepAssertion);
     49#else
     50    UNUSED_PARAM(reason);
     51    IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &_idleDisplaySleepAssertion);
     52    m_systemActivityTimer.startRepeating(systemActivityInterval);
     53#endif
    3354}
    3455
    35 namespace WebCore {
    36 class IntRect;
     56DisplaySleepDisabler::~DisplaySleepDisabler()
     57{
     58    IOPMAssertionRelease(m_disableDisplaySleepAssertion);
    3759}
     60   
     61#ifdef BUILDING_ON_LEOPARD
     62void DisplaySleepDisabler::systemActivityTimerFired(Timer<DisplaySleepDisabler>*)
     63{
     64    UpdateSystemActivity(OverallAct);
     65}
     66#endif
    3867
    39 @class WKView;
    40 
    41 @interface WKFullScreenWindowController : NSWindowController {
    42 @private
    43     WKView *_webView;
    44     RetainPtr<NSView> _webViewPlaceholder;
    45     RetainPtr<NSView> _layerHostingView;
    46    
    47     BOOL _isEnteringFullScreen;
    48     BOOL _isExitingFullScreen;
    49     BOOL _isFullScreen;
    50     BOOL _forceDisableAnimation;
    51     BOOL _isPlaying;
    52     uint32_t _idleDisplaySleepAssertion;
    53     uint32_t _idleSystemSleepAssertion;
    54     NSTimer *_tickleTimer;
    5568}
    56 
    57 - (WKView*)webView;
    58 - (void)setWebView:(WKView*)webView;
    59 
    60 - (void)enterFullScreen:(NSScreen *)screen;
    61 - (void)exitFullScreen;
    62 - (void)beganEnterFullScreenAnimation;
    63 - (void)beganExitFullScreenAnimation;
    64 - (void)finishedEnterFullScreenAnimation:(bool)completed;
    65 - (void)finishedExitFullScreenAnimation:(bool)completed;
    66 - (void)enterAcceleratedCompositingMode:(const WebKit::LayerTreeContext&)context;
    67 - (void)exitAcceleratedCompositingMode;
    68 - (WebCore::IntRect)getFullScreenRect;
    69 - (void)close;
    70 
    71 @end
    72 
    73 #endif
  • trunk/Source/WebCore/platform/mac/DisplaySleepDisabler.h

    r95512 r95513  
    2424 */
    2525
    26 #if ENABLE(FULLSCREEN_API)
     26#ifndef DisplaySleepDisabler_h
     27#define DisplaySleepDisabler_h
    2728
    28 #import <Cocoa/Cocoa.h>
    29 #import <wtf/RetainPtr.h>
     29#include <wtf/Noncopyable.h>
     30#include <wtf/PassOwnPtr.h>
    3031
    31 namespace WebKit {
    32 class LayerTreeContext;
     32#ifdef BUILDNG_ON_LEOPARD
     33#include "Timer.h"
     34#endif
     35
     36namespace WebCore {
     37
     38class DisplaySleepDisabler {
     39    WTF_MAKE_NONCOPYABLE(DisplaySleepDisabler);
     40public:
     41    static PassOwnPtr<DisplaySleepDisabler> create(const char* reason) { return adoptPtr(new DisplaySleepDisabler(reason)); }
     42    ~DisplaySleepDisabler();
     43   
     44private:
     45    DisplaySleepDisabler(const char* reason);
     46
     47#ifdef BUILDNG_ON_LEOPARD
     48    void systemActivityTimerFired(Timer<DisplaySleepDisabler>*);
     49#endif
     50   
     51    uint32_t m_disableDisplaySleepAssertion;
     52#ifdef BUILDNG_ON_LEOPARD
     53    Timer<DisplaySleepDisabler> m_systemActivityTimer;
     54#endif
     55};
     56
    3357}
    3458
    35 namespace WebCore {
    36 class IntRect;
    37 }
    38 
    39 @class WKView;
    40 
    41 @interface WKFullScreenWindowController : NSWindowController {
    42 @private
    43     WKView *_webView;
    44     RetainPtr<NSView> _webViewPlaceholder;
    45     RetainPtr<NSView> _layerHostingView;
    46    
    47     BOOL _isEnteringFullScreen;
    48     BOOL _isExitingFullScreen;
    49     BOOL _isFullScreen;
    50     BOOL _forceDisableAnimation;
    51     BOOL _isPlaying;
    52     uint32_t _idleDisplaySleepAssertion;
    53     uint32_t _idleSystemSleepAssertion;
    54     NSTimer *_tickleTimer;
    55 }
    56 
    57 - (WKView*)webView;
    58 - (void)setWebView:(WKView*)webView;
    59 
    60 - (void)enterFullScreen:(NSScreen *)screen;
    61 - (void)exitFullScreen;
    62 - (void)beganEnterFullScreenAnimation;
    63 - (void)beganExitFullScreenAnimation;
    64 - (void)finishedEnterFullScreenAnimation:(bool)completed;
    65 - (void)finishedExitFullScreenAnimation:(bool)completed;
    66 - (void)enterAcceleratedCompositingMode:(const WebKit::LayerTreeContext&)context;
    67 - (void)exitAcceleratedCompositingMode;
    68 - (WebCore::IntRect)getFullScreenRect;
    69 - (void)close;
    70 
    71 @end
    72 
    73 #endif
     59#endif // DisplaySleepDisabler_h
  • trunk/Source/WebCore/platform/mac/WebVideoFullscreenController.h

    r93022 r95513  
    2828#import <AppKit/NSWindowController.h>
    2929#import <AppKit/NSScreen.h>
    30 #import <Foundation/NSTimer.h>
     30#import <wtf/OwnPtr.h>
    3131#import <wtf/RefPtr.h>
    3232
    3333namespace WebCore {
     34    class DisplaySleepDisabler;
    3435    class HTMLMediaElement;
    3536}
     
    5253    BOOL _isEndingFullscreen;
    5354    BOOL _forceDisableAnimation;
    54     uint32_t _idleDisplaySleepAssertion;
    55     uint32_t _idleSystemSleepAssertion;
    56     NSTimer *_tickleTimer;
     55
     56    OwnPtr<WebCore::DisplaySleepDisabler> _displaySleepDisabler;
    5757}
    5858
  • trunk/Source/WebCore/platform/mac/WebVideoFullscreenController.mm

    r94846 r95513  
    3333#import "WebWindowAnimation.h"
    3434#import <Carbon/Carbon.h>
    35 #import <IOKit/pwr_mgt/IOPMLib.h>
    3635#import <QTKit/QTKit.h>
     36#import <WebCore/DisplaySleepDisabler.h>
    3737#import <WebCore/HTMLMediaElement.h>
    3838#import <WebCore/SoftLinking.h>
     
    4444#endif
    4545
     46using namespace WebCore;
     47
    4648SOFT_LINK_FRAMEWORK(QTKit)
    4749SOFT_LINK_CLASS(QTKit, QTMovieLayer)
     
    5052
    5153#define QTMovieRateDidChangeNotification getQTMovieRateDidChangeNotification()
    52 static const NSTimeInterval tickleTimerInterval = 1.0;
    5354
    5455@interface WebVideoFullscreenWindow : NSWindow
     
    9091    ASSERT(!_backgroundFullscreenWindow);
    9192    ASSERT(!_fadeAnimation);
    92     [_tickleTimer invalidate];
    93     [_tickleTimer release];
    94     _tickleTimer = nil;
    9593    [[NSNotificationCenter defaultCenter] removeObserver:self];
    9694    [super dealloc];
     
    106104    WebVideoFullscreenWindow *window = [self fullscreenWindow];
    107105#if USE(GSTREAMER)
    108     if (_mediaElement && _mediaElement->platformMedia().type == WebCore::PlatformMedia::GStreamerGWorldType) {
    109         WebCore::GStreamerGWorld* gstGworld = _mediaElement->platformMedia().media.gstreamerGWorld;
     106    if (_mediaElement && _mediaElement->platformMedia().type == PlatformMedia::GStreamerGWorldType) {
     107        GStreamerGWorld* gstGworld = _mediaElement->platformMedia().media.gstreamerGWorld;
    110108        if (gstGworld->enterFullscreen())
    111109            [window setContentView:gstGworld->platformVideoWindow()->window()];
     
    114112    [[window contentView] setLayer:layer];
    115113    [[window contentView] setWantsLayer:YES];
    116     if (_mediaElement && _mediaElement->platformMedia().type == WebCore::PlatformMedia::QTMovieType)
     114    if (_mediaElement && _mediaElement->platformMedia().type == PlatformMedia::QTMovieType)
    117115        [layer setMovie:_mediaElement->platformMedia().media.qtMovie];
    118116#endif
     
    135133}
    136134
    137 - (WebCore::HTMLMediaElement*)mediaElement
     135- (HTMLMediaElement*)mediaElement
    138136{
    139137    return _mediaElement.get();
    140138}
    141139
    142 - (void)setMediaElement:(WebCore::HTMLMediaElement*)mediaElement
     140- (void)setMediaElement:(HTMLMediaElement*)mediaElement
    143141{
    144142    _mediaElement = mediaElement;
     
    181179{
    182180#if USE(GSTREAMER)
    183     if (_mediaElement && _mediaElement->platformMedia().type == WebCore::PlatformMedia::GStreamerGWorldType)
     181    if (_mediaElement && _mediaElement->platformMedia().type == PlatformMedia::GStreamerGWorldType)
    184182        _mediaElement->platformMedia().media.gstreamerGWorld->exitFullscreen();
    185183#endif
     
    366364}
    367365
    368 - (void)_disableIdleDisplaySleep
    369 {
    370     if (_idleDisplaySleepAssertion == kIOPMNullAssertionID)
    371 #if defined(BUILDING_ON_LEOPARD) // IOPMAssertionCreateWithName is not defined in the 10.5 SDK
    372         IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &_idleDisplaySleepAssertion);
    373 #else // IOPMAssertionCreate is depreciated in > 10.5
    374         IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, CFSTR("WebKit playing a video fullscreen."), &_idleDisplaySleepAssertion);
    375 #endif
    376 }
    377 
    378 - (void)_enableIdleDisplaySleep
    379 {
    380     if (_idleDisplaySleepAssertion != kIOPMNullAssertionID) {
    381         IOPMAssertionRelease(_idleDisplaySleepAssertion);
    382         _idleDisplaySleepAssertion = kIOPMNullAssertionID;
    383     }
    384 }
    385 
    386 - (void)_disableIdleSystemSleep
    387 {
    388     if (_idleSystemSleepAssertion == kIOPMNullAssertionID)
    389 #if defined(BUILDING_ON_LEOPARD) // IOPMAssertionCreateWithName is not defined in the 10.5 SDK
    390         IOPMAssertionCreate(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, &_idleSystemSleepAssertion);
    391 #else // IOPMAssertionCreate is depreciated in > 10.5
    392     IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, CFSTR("WebKit playing a video fullscreen."), &_idleSystemSleepAssertion);
    393 #endif
    394 }
    395 
    396 - (void)_enableIdleSystemSleep
    397 {
    398     if (_idleSystemSleepAssertion != kIOPMNullAssertionID) {
    399         IOPMAssertionRelease(_idleSystemSleepAssertion);
    400         _idleSystemSleepAssertion = kIOPMNullAssertionID;
    401     }
    402 }
    403 
    404 - (void)_enableTickleTimer
    405 {
    406     [_tickleTimer invalidate];
    407     [_tickleTimer release];
    408     _tickleTimer = [[NSTimer scheduledTimerWithTimeInterval:tickleTimerInterval target:self selector:@selector(_tickleTimerFired) userInfo:nil repeats:YES] retain];
    409 }
    410 
    411 - (void)_disableTickleTimer
    412 {
    413     [_tickleTimer invalidate];
    414     [_tickleTimer release];
    415     _tickleTimer = nil;
    416 }
    417 
    418 - (void)_tickleTimerFired
    419 {
    420     UpdateSystemActivity(OverallAct);
    421 }
    422 
    423366- (void)updatePowerAssertions
    424367{
    425368    float rate = 0;
    426     if (_mediaElement && _mediaElement->platformMedia().type == WebCore::PlatformMedia::QTMovieType)
     369    if (_mediaElement && _mediaElement->platformMedia().type == PlatformMedia::QTMovieType)
    427370        rate = [_mediaElement->platformMedia().media.qtMovie rate];
    428371   
    429372    if (rate && !_isEndingFullscreen) {
    430         [self _disableIdleSystemSleep];
    431         [self _disableIdleDisplaySleep];
    432         [self _enableTickleTimer];
    433     } else {
    434         [self _enableIdleSystemSleep];
    435         [self _enableIdleDisplaySleep];
    436         [self _disableTickleTimer];
    437     }
     373        if (!_displaySleepDisabler)
     374            _displaySleepDisabler = DisplaySleepDisabler::create("com.apple.WebCore - Fullscreen video");
     375    } else
     376        _displaySleepDisabler = nullptr;
    438377}
    439378
  • trunk/Source/WebKit/mac/ChangeLog

    r95501 r95513  
     12011-09-19  Mark Rowe  <mrowe@apple.com>
     2
     3        <http://webkit.org/b/68421> Stop calling UpdateSystemActivity in places where we hold power assertions that achieve the same effect
     4
     5        On SnowLeopard and newer it's not necessary to call UpdateSystemActivity to prevent the screensaver from kicking
     6        in as the NoDisplaySleep assertion now has that effect. It's also not necessary to hold both a NoDisplaySleep and
     7        a NoIdleSleep assertion as the latter is implied by the former.
     8
     9        Adopt the DisplaySleepDisabler class that was added to WebCore and remove all of duplicated logic from WebFullScreenController.
     10
     11        Reviewed by Dan Bernstein.
     12
     13        * WebView/WebFullScreenController.h:
     14        * WebView/WebFullScreenController.mm:
     15        (-[WebFullScreenController dealloc]):
     16        (-[WebFullScreenController _updatePowerAssertions]): Create a DisplaySleepDisabler instance when transitioning from permitting
     17        display sleep to disabling display sleep. Clear out our reference when sleep should be permitted, destroying any
     18        disabler that we own.
     19
    1202011-09-19  Adam Barth  <abarth@webkit.org>
    221
  • trunk/Source/WebKit/mac/WebView/WebFullScreenController.h

    r93024 r95513  
    2626#if ENABLE(FULLSCREEN_API)
    2727
     28#import <wtf/OwnPtr.h>
    2829#import <wtf/RefPtr.h>
    2930
     
    3132@class WebView;
    3233namespace WebCore {
     34    class DisplaySleepDisabler;
    3335    class Element;
    3436    class RenderBox;
     
    4749    BOOL _isFullscreen;
    4850    BOOL _forceDisableAnimation;
    49     uint32_t _idleDisplaySleepAssertion;
    50     uint32_t _idleSystemSleepAssertion;
    51     NSTimer *_tickleTimer;
     51    OwnPtr<WebCore::DisplaySleepDisabler> _displaySleepDisabler;
    5252    CGRect _initialFrame;
    5353}
  • trunk/Source/WebKit/mac/WebView/WebFullScreenController.mm

    r92651 r95513  
    3636#import <WebCore/CSSPropertyNames.h>
    3737#import <WebCore/Color.h>
    38 #import <WebCore/Document.h>
    3938#import <WebCore/DOMDocument.h>
    4039#import <WebCore/DOMDocumentInternal.h>
    4140#import <WebCore/DOMHTMLElement.h>
    4241#import <WebCore/DOMWindow.h>
     42#import <WebCore/DisplaySleepDisabler.h>
     43#import <WebCore/Document.h>
    4344#import <WebCore/EventListener.h>
    4445#import <WebCore/EventNames.h>
    4546#import <WebCore/HTMLElement.h>
     47#import <WebCore/HTMLMediaElement.h>
    4648#import <WebCore/HTMLNames.h>
    47 #import <WebCore/HTMLMediaElement.h>
    4849#import <WebCore/IntRect.h>
    4950#import <WebCore/NodeList.h>
    50 #import <WebCore/SoftLinking.h>
    5151#import <WebCore/RenderBlock.h>
    5252#import <WebCore/RenderLayer.h>
    5353#import <WebCore/RenderLayerBacking.h>
     54#import <WebCore/SoftLinking.h>
    5455#import <objc/objc-runtime.h>
    5556#import <wtf/RetainPtr.h>
    5657#import <wtf/UnusedParam.h>
    5758
    58 static const NSTimeInterval tickleTimerInterval = 1.0;
    5959static NSString* const isEnteringFullscreenKey = @"isEnteringFullscreen";
    6060
     
    122122- (void)dealloc
    123123{
    124     ASSERT(!_tickleTimer);
    125    
    126124    [self setWebView:nil];
    127125    [_placeholderView release];
     
    646644}
    647645
    648 - (void)_disableIdleDisplaySleep
    649 {
    650     if (_idleDisplaySleepAssertion == kIOPMNullAssertionID)
    651 #if defined(BUILDING_ON_LEOPARD) // IOPMAssertionCreateWithName is not defined in the 10.5 SDK
    652         IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &_idleDisplaySleepAssertion);
    653 #else // IOPMAssertionCreate is depreciated in > 10.5
    654         IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, CFSTR("WebKit playing a video fullscreen."), &_idleDisplaySleepAssertion);
    655 #endif
    656 }
    657 
    658 - (void)_enableIdleDisplaySleep
    659 {
    660     if (_idleDisplaySleepAssertion != kIOPMNullAssertionID) {
    661         IOPMAssertionRelease(_idleDisplaySleepAssertion);
    662         _idleDisplaySleepAssertion = kIOPMNullAssertionID;
    663     }
    664 }
    665 
    666 - (void)_disableIdleSystemSleep
    667 {
    668     if (_idleSystemSleepAssertion == kIOPMNullAssertionID)
    669 #if defined(BUILDING_ON_LEOPARD) // IOPMAssertionCreateWithName is not defined in the 10.5 SDK
    670         IOPMAssertionCreate(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, &_idleSystemSleepAssertion);
    671 #else // IOPMAssertionCreate is depreciated in > 10.5
    672     IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, CFSTR("WebKit playing a video fullscreen."), &_idleSystemSleepAssertion);
    673 #endif
    674 }
    675 
    676 - (void)_enableIdleSystemSleep
    677 {
    678     if (_idleSystemSleepAssertion != kIOPMNullAssertionID) {
    679         IOPMAssertionRelease(_idleSystemSleepAssertion);
    680         _idleSystemSleepAssertion = kIOPMNullAssertionID;
    681     }
    682 }
    683 
    684 - (void)_enableTickleTimer
    685 {
    686     [_tickleTimer invalidate];
    687     [_tickleTimer release];
    688     _tickleTimer = [[NSTimer scheduledTimerWithTimeInterval:tickleTimerInterval target:self selector:@selector(_tickleTimerFired) userInfo:nil repeats:YES] retain];
    689 }
    690 
    691 - (void)_disableTickleTimer
    692 {
    693     [_tickleTimer invalidate];
    694     [_tickleTimer release];
    695     _tickleTimer = nil;
    696 }
    697 
    698 - (void)_tickleTimerFired
    699 {
    700     UpdateSystemActivity(OverallAct);
    701 }
    702 
    703646- (void)_updatePowerAssertions
    704647{
     
    706649   
    707650    if (isPlaying && _isFullscreen) {
    708         [self _disableIdleSystemSleep];
    709         [self _disableIdleDisplaySleep];
    710         [self _enableTickleTimer];
    711     } else {
    712         [self _enableIdleSystemSleep];
    713         [self _enableIdleDisplaySleep];
    714         [self _disableTickleTimer];
    715     }
     651        if (!_displaySleepDisabler)
     652            _displaySleepDisabler = DisplaySleepDisabler::create("com.apple.WebKit - Fullscreen video");
     653    } else
     654        _displaySleepDisabler = nullptr;
    716655}
    717656
  • trunk/Source/WebKit2/ChangeLog

    r95501 r95513  
     12011-09-19  Mark Rowe  <mrowe@apple.com>
     2
     3        <http://webkit.org/b/68421> Stop calling UpdateSystemActivity in places where we hold power assertions that achieve the same effect
     4
     5        On SnowLeopard and newer it's not necessary to call UpdateSystemActivity to prevent the screensaver from kicking
     6        in as the NoDisplaySleep assertion now has that effect. It's also not necessary to hold both a NoDisplaySleep and
     7        a NoIdleSleep assertion as the latter is implied by the former.
     8
     9        Adopt the DisplaySleepDisabler class that was added to WebCore and remove all of duplicated logic from WKFullScreenWindowController.
     10
     11        Reviewed by Dan Bernstein.
     12
     13        * UIProcess/mac/WKFullScreenWindowController.h:
     14        * UIProcess/mac/WKFullScreenWindowController.mm:
     15        (-[WKFullScreenWindowController _updatePowerAssertions]): Create a DisplaySleepDisabler instance when transitioning from permitting
     16        display sleep to disabling display sleep. Clear out our reference when sleep should be permitted, destroying any
     17        disabler that we own. Also adds a FIXME about an error that was noticed while working in this code.
     18
    1192011-09-19  Adam Barth  <abarth@webkit.org>
    220
  • trunk/Source/WebKit2/UIProcess/mac/WKFullScreenWindowController.h

    r93023 r95513  
    2626#if ENABLE(FULLSCREEN_API)
    2727
    28 #import <Cocoa/Cocoa.h>
     28#import <wtf/OwnPtr.h>
    2929#import <wtf/RetainPtr.h>
    3030
     
    3434
    3535namespace WebCore {
     36class DisplaySleepDisabler;
    3637class IntRect;
    3738}
     
    5051    BOOL _forceDisableAnimation;
    5152    BOOL _isPlaying;
    52     uint32_t _idleDisplaySleepAssertion;
    53     uint32_t _idleSystemSleepAssertion;
    54     NSTimer *_tickleTimer;
     53    OwnPtr<WebCore::DisplaySleepDisabler> _displaySleepDisabler;
    5554}
    5655
  • trunk/Source/WebKit2/UIProcess/mac/WKFullScreenWindowController.mm

    r90851 r95513  
    3636#import "WebPageProxy.h"
    3737#import <Carbon/Carbon.h> // For SetSystemUIMode()
    38 #import <IOKit/pwr_mgt/IOPMLib.h> // For IOPMAssertionCreate()
    3938#import <QuartzCore/QuartzCore.h>
     39#import <WebCore/DisplaySleepDisabler.h>
    4040#import <WebCore/FloatRect.h>
    4141#import <WebCore/IntRect.h>
     
    4343#import <WebKitSystemInterface.h>
    4444#import <wtf/UnusedParam.h>
    45 
    46 static const NSTimeInterval tickleTimerInterval = 1.0;
    4745
    4846using namespace WebKit;
     
    472470}
    473471
    474 - (void)_disableIdleDisplaySleep
    475 {
    476     if (_idleDisplaySleepAssertion == kIOPMNullAssertionID)
    477 #if defined(BUILDING_ON_LEOPARD) // IOPMAssertionCreateWithName is not defined in the 10.5 SDK
    478         IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &_idleDisplaySleepAssertion);
    479 #else // IOPMAssertionCreate is depreciated in > 10.5
    480     IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, CFSTR("WebKit playing a video fullScreen."), &_idleDisplaySleepAssertion);
    481 #endif
    482 }
    483 
    484 - (void)_enableIdleDisplaySleep
    485 {
    486     if (_idleDisplaySleepAssertion != kIOPMNullAssertionID) {
    487         IOPMAssertionRelease(_idleDisplaySleepAssertion);
    488         _idleDisplaySleepAssertion = kIOPMNullAssertionID;
    489     }
    490 }
    491 
    492 - (void)_disableIdleSystemSleep
    493 {
    494     if (_idleSystemSleepAssertion == kIOPMNullAssertionID)
    495 #if defined(BUILDING_ON_LEOPARD) // IOPMAssertionCreateWithName is not defined in the 10.5 SDK
    496         IOPMAssertionCreate(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, &_idleSystemSleepAssertion);
    497 #else // IOPMAssertionCreate is depreciated in > 10.5
    498     IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, CFSTR("WebKit playing a video fullScreen."), &_idleSystemSleepAssertion);
    499 #endif
    500 }
    501 
    502 - (void)_enableIdleSystemSleep
    503 {
    504     if (_idleSystemSleepAssertion != kIOPMNullAssertionID) {
    505         IOPMAssertionRelease(_idleSystemSleepAssertion);
    506         _idleSystemSleepAssertion = kIOPMNullAssertionID;
    507     }
    508 }
    509 
    510 - (void)_enableTickleTimer
    511 {
    512     [_tickleTimer invalidate];
    513     [_tickleTimer release];
    514     _tickleTimer = [[NSTimer scheduledTimerWithTimeInterval:tickleTimerInterval target:self selector:@selector(_tickleTimerFired) userInfo:nil repeats:YES] retain];
    515 }
    516 
    517 - (void)_disableTickleTimer
    518 {
    519     [_tickleTimer invalidate];
    520     [_tickleTimer release];
    521     _tickleTimer = nil;
    522 }
    523 
    524 - (void)_tickleTimerFired
    525 {
    526     UpdateSystemActivity(OverallAct);
    527 }
    528 
    529472- (void)_updatePowerAssertions
    530473{
     474    // FIXME: _isPlaying is never modified so we never disable display sleep here! (<rdar://problem/10151029>)
    531475    if (_isPlaying && _isFullScreen) {
    532         [self _disableIdleSystemSleep];
    533         [self _disableIdleDisplaySleep];
    534         [self _enableTickleTimer];
    535     } else {
    536         [self _enableIdleSystemSleep];
    537         [self _enableIdleDisplaySleep];
    538         [self _disableTickleTimer];
    539     }
     476        if (!_displaySleepDisabler)
     477            _displaySleepDisabler = DisplaySleepDisabler::create("com.apple.WebKit2 - Fullscreen video");
     478    } else
     479        _displaySleepDisabler = nullptr;
    540480}
    541481
Note: See TracChangeset for help on using the changeset viewer.