-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Timers are not coalesced during thermal throttling; should match low …
…power mode https://bugs.webkit.org/show_bug.cgi?id=260931 rdar://112725366 Reviewed by Aditya Keerthi. * Source/WebCore/platform/ThermalMitigationNotifier.cpp: Added. (WebCore::ThermalMitigationNotifier::ThermalMitigationNotifier): (WebCore::ThermalMitigationNotifier::thermalMitigationEnabled const): * Source/WebCore/platform/ThermalMitigationNotifier.h: Added. * Source/WebCore/platform/cocoa/ThermalMitigationNotifier.mm: Added. (-[WebThermalMitigationObserver initWithNotifier:]): (-[WebThermalMitigationObserver dealloc]): (-[WebThermalMitigationObserver thermalStateDidChange]): (-[WebThermalMitigationObserver thermalMitigationEnabled]): (WebCore::ThermalMitigationNotifier::ThermalMitigationNotifier): (WebCore::ThermalMitigationNotifier::~ThermalMitigationNotifier): (WebCore::ThermalMitigationNotifier::thermalMitigationEnabled const): (WebCore::ThermalMitigationNotifier::notifyThermalMitigationChanged): (WebCore::notifyThermalMitigationChanged): Add an observer for thermal state. Assume that we want to mitigate our contribution to high thermals when the state is Serious or above. This has the same shape as LowPowerModeNotifier. * Source/WTF/wtf/PlatformHave.h: * Source/WebCore/Sources.txt: * Source/WebCore/SourcesCocoa.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/page/DOMTimer.h: * Source/WebCore/page/Page.cpp: (WebCore::m_thermalMitigationNotifier): (WebCore::m_badgeClient): (WebCore::Page::didChangeThrottlingReasons): (WebCore::Page::setIsVisuallyIdleInternal): (WebCore::Page::handleLowModePowerChange): (WebCore::Page::handleThermalMitigationChange): (WebCore::Page::updateDOMTimerAlignmentInterval): * Source/WebCore/page/Page.h: (WebCore::Page::isThermalMitigationEnabled const): * Source/WebCore/platform/graphics/AnimationFrameRate.cpp: (WebCore::operator<<): * Source/WebCore/platform/graphics/AnimationFrameRate.h: When thermal mitigation is enabled, align DOM timers to 30ms like we do in low power mode. * Source/WebCore/platform/graphics/avfoundation/objc/AVAssetMIMETypeCache.mm: * Source/WebCore/platform/graphics/avfoundation/objc/LocalSampleBufferDisplayLayer.mm: (WebCore::transformationMatrixForVideoFrame): (WebCore::LocalSampleBufferDisplayLayer::enqueueVideoFrame): (WebCore::videoTransformationMatrix): Deleted. * Source/WebCore/platform/network/mac/UTIUtilities.mm: * Source/WebCore/platform/audio/cocoa/AudioUtilitiesCocoa.h: Unrelated unified sources fixes. Canonical link: https://commits.webkit.org/267480@main
- Loading branch information
1 parent
acfa97d
commit 3088454
Showing
17 changed files
with
260 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (C) 2023 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "config.h" | ||
#include "ThermalMitigationNotifier.h" | ||
|
||
namespace WebCore { | ||
|
||
#if !HAVE(APPLE_THERMAL_MITIGATION_SUPPORT) | ||
|
||
ThermalMitigationNotifier::ThermalMitigationNotifier(ThermalMitigationChangeCallback&&) | ||
{ | ||
} | ||
|
||
ThermalMitigationNotifier::~ThermalMitigationNotifier() = default; | ||
|
||
bool ThermalMitigationNotifier::thermalMitigationEnabled() const | ||
{ | ||
return false; | ||
} | ||
|
||
#endif | ||
|
||
} // namespace WebCore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (C) 2023 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <wtf/Function.h> | ||
#include <wtf/WeakPtr.h> | ||
|
||
#if HAVE(APPLE_THERMAL_MITIGATION_SUPPORT) | ||
#include <wtf/RetainPtr.h> | ||
OBJC_CLASS WebThermalMitigationObserver; | ||
#endif | ||
|
||
namespace WebCore { | ||
|
||
class ThermalMitigationNotifier : public CanMakeWeakPtr<ThermalMitigationNotifier> { | ||
WTF_MAKE_FAST_ALLOCATED; | ||
public: | ||
using ThermalMitigationChangeCallback = Function<void(bool thermalMitigationEnabled)>; | ||
WEBCORE_EXPORT explicit ThermalMitigationNotifier(ThermalMitigationChangeCallback&&); | ||
WEBCORE_EXPORT ~ThermalMitigationNotifier(); | ||
|
||
WEBCORE_EXPORT bool thermalMitigationEnabled() const; | ||
|
||
private: | ||
#if HAVE(APPLE_THERMAL_MITIGATION_SUPPORT) | ||
void notifyThermalMitigationChanged(bool); | ||
friend void notifyThermalMitigationChanged(ThermalMitigationNotifier&, bool); | ||
|
||
RetainPtr<WebThermalMitigationObserver> m_observer; | ||
ThermalMitigationChangeCallback m_callback; | ||
#endif | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ | |
|
||
#if ENABLE(WEB_AUDIO) | ||
|
||
#include "AudioStreamDescription.h" | ||
|
||
namespace WebCore { | ||
class AudioBus; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
Source/WebCore/platform/cocoa/ThermalMitigationNotifier.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (C) 2023 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#import "config.h" | ||
#import "ThermalMitigationNotifier.h" | ||
|
||
#if HAVE(APPLE_THERMAL_MITIGATION_SUPPORT) | ||
|
||
#import "Logging.h" | ||
#import <Foundation/NSProcessInfo.h> | ||
#import <wtf/MainThread.h> | ||
|
||
@interface WebThermalMitigationObserver : NSObject | ||
@property (nonatomic) WeakPtr<WebCore::ThermalMitigationNotifier> notifier; | ||
@property (nonatomic, readonly) BOOL thermalMitigationEnabled; | ||
@end | ||
|
||
@implementation WebThermalMitigationObserver | ||
|
||
- (WebThermalMitigationObserver *)initWithNotifier:(WebCore::ThermalMitigationNotifier&)notifier | ||
{ | ||
self = [super init]; | ||
if (!self) | ||
return nil; | ||
|
||
_notifier = ¬ifier; | ||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(thermalStateDidChange) name:NSProcessInfoThermalStateDidChangeNotification object:nil]; | ||
return self; | ||
} | ||
|
||
- (void)dealloc | ||
{ | ||
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSProcessInfoThermalStateDidChangeNotification object:nil]; | ||
[super dealloc]; | ||
} | ||
|
||
- (void)thermalStateDidChange | ||
{ | ||
callOnMainThread([self, protectedSelf = RetainPtr<WebThermalMitigationObserver>(self)] { | ||
if (_notifier) | ||
notifyThermalMitigationChanged(*_notifier, self.thermalMitigationEnabled); | ||
}); | ||
} | ||
|
||
- (BOOL)thermalMitigationEnabled | ||
{ | ||
return NSProcessInfo.processInfo.thermalState >= NSProcessInfoThermalStateSerious; | ||
} | ||
|
||
@end | ||
|
||
namespace WebCore { | ||
|
||
ThermalMitigationNotifier::ThermalMitigationNotifier(ThermalMitigationChangeCallback&& callback) | ||
: m_observer(adoptNS([[WebThermalMitigationObserver alloc] initWithNotifier:*this])) | ||
, m_callback(WTFMove(callback)) | ||
{ | ||
} | ||
|
||
ThermalMitigationNotifier::~ThermalMitigationNotifier() | ||
{ | ||
[m_observer setNotifier:nil]; | ||
} | ||
|
||
bool ThermalMitigationNotifier::thermalMitigationEnabled() const | ||
{ | ||
return [m_observer thermalMitigationEnabled]; | ||
} | ||
|
||
void ThermalMitigationNotifier::notifyThermalMitigationChanged(bool enabled) | ||
{ | ||
m_callback(enabled); | ||
} | ||
|
||
void notifyThermalMitigationChanged(ThermalMitigationNotifier& notifier, bool enabled) | ||
{ | ||
RELEASE_LOG(PerformanceLogging, "Thermal mitigation is enabled: %d", enabled); | ||
notifier.notifyThermalMitigationChanged(enabled); | ||
} | ||
|
||
} // namespace WebCore | ||
|
||
#endif // HAVE(APPLE_THERMAL_MITIGATION_SUPPORT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.