Skip to content

Commit

Permalink
Call WKDestroyRenderingResources() on iOS when tabs are backgrounded
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=168261
rdar://problem/30481079

Reviewed by Tim Horton.

Source/WebCore:

Add CABackingStoreCollectBlocking() to QuartzCoreSPI.h, and fix files in WebCore
that do a framework include.

* platform/graphics/cocoa/TextTrackRepresentationCocoa.mm:
* platform/graphics/cocoa/WebActionDisablingCALayerDelegate.h:
* platform/spi/cocoa/QuartzCoreSPI.h:
* platform/spi/mac/NSViewSPI.h:

Source/WebKit2:

There's code to call CABackingStoreCollectBlocking() on a 10s timer that exists for Mac, but on iOS
the web processes are suspended before this timer fires. So call CABackingStoreCollectBlocking()
from WebProcess::actualPrepareToSuspend(), which is where we also trigger the markAllLayersVolatile()
code.

Also add CABackingStoreCollectBlocking() to QuartzCoreSPI.h so we can use it without using WKSI.

Release-log how long this takes, in case we get reports of bad performance. In my testing it could be up to 10ms.

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::actualPrepareToSuspend):
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::destroyRenderingResources):


Canonical link: https://commits.webkit.org/185295@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212260 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
smfr committed Feb 14, 2017
1 parent 7a05bb7 commit 6cf896c
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 5 deletions.
16 changes: 16 additions & 0 deletions Source/WebCore/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
2017-02-13 Simon Fraser <[email protected]>

Call WKDestroyRenderingResources() on iOS when tabs are backgrounded
https://bugs.webkit.org/show_bug.cgi?id=168261
rdar://problem/30481079

Reviewed by Tim Horton.

Add CABackingStoreCollectBlocking() to QuartzCoreSPI.h, and fix files in WebCore
that do a framework include.

* platform/graphics/cocoa/TextTrackRepresentationCocoa.mm:
* platform/graphics/cocoa/WebActionDisablingCALayerDelegate.h:
* platform/spi/cocoa/QuartzCoreSPI.h:
* platform/spi/mac/NSViewSPI.h:

2017-02-13 Youenn Fablet <[email protected]>

ASSERTION FAILED: !m_bodyLoader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "GraphicsContextCG.h"
#include "IntRect.h"

#import <WebCore/QuartzCoreSPI.h>
#import "QuartzCoreSPI.h"

#if PLATFORM(IOS)
#include "WebCoreThread.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#ifndef WebActionDisablingCALayerDelegate_h
#define WebActionDisablingCALayerDelegate_h

#import <WebCore/QuartzCoreSPI.h>
#import "QuartzCoreSPI.h"

WEBCORE_EXPORT @interface WebActionDisablingCALayerDelegate : NSObject <CALayerDelegate>

Expand Down
6 changes: 5 additions & 1 deletion Source/WebCore/platform/spi/cocoa/QuartzCoreSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#if USE(APPLE_INTERNAL_SDK)

#include <QuartzCore/CABackingStore.h>
#include <QuartzCore/CAColorMatrix.h>
#include <QuartzCore/CARenderServer.h>

Expand Down Expand Up @@ -192,6 +193,8 @@ CAMachPortRef CAMachPortCreate(mach_port_t);
mach_port_t CAMachPortGetPort(CAMachPortRef);
CFTypeID CAMachPortGetTypeID(void);

void CABackingStoreCollectBlocking(void);

WTF_EXTERN_C_END

extern NSString * const kCATiledLayerRemoveImmediately;
Expand Down Expand Up @@ -235,4 +238,5 @@ extern NSString * const kCAContentsFormatRGBA10XR;

@protocol CAAnimationDelegate <NSObject>
@end
#endif

#endif // USE(APPLE_INTERNAL_SDK)
2 changes: 1 addition & 1 deletion Source/WebCore/platform/spi/mac/NSViewSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#if USE(APPKIT)

#import <WebCore/QuartzCoreSPI.h>
#import "QuartzCoreSPI.h"

@interface NSView () <CALayerDelegate>
@end
Expand Down
22 changes: 22 additions & 0 deletions Source/WebKit2/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
2017-02-13 Simon Fraser <[email protected]>

Call WKDestroyRenderingResources() on iOS when tabs are backgrounded
https://bugs.webkit.org/show_bug.cgi?id=168261
rdar://problem/30481079

Reviewed by Tim Horton.

There's code to call CABackingStoreCollectBlocking() on a 10s timer that exists for Mac, but on iOS
the web processes are suspended before this timer fires. So call CABackingStoreCollectBlocking()
from WebProcess::actualPrepareToSuspend(), which is where we also trigger the markAllLayersVolatile()
code.

Also add CABackingStoreCollectBlocking() to QuartzCoreSPI.h so we can use it without using WKSI.

Release-log how long this takes, in case we get reports of bad performance. In my testing it could be up to 10ms.

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::actualPrepareToSuspend):
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::destroyRenderingResources):

2017-02-13 Brady Eidson <[email protected]>

Followup to: Replace all WebKit Library Version checks in WK2 with SDK version checks.
Expand Down
4 changes: 4 additions & 0 deletions Source/WebKit2/WebProcess/WebProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,10 @@ void WebProcess::actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend shou
MemoryPressureHandler::singleton().releaseMemory(Critical::Yes, Synchronous::Yes);

setAllLayerTreeStatesFrozen(true);

#if PLATFORM(COCOA)
destroyRenderingResources();
#endif

markAllLayersVolatile([this, shouldAcknowledgeWhenReadyToSuspend] {
RELEASE_LOG(ProcessSuspension, "%p - WebProcess::markAllLayersVolatile() Successfuly marked all layers as volatile", this);
Expand Down
11 changes: 10 additions & 1 deletion Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#import "WebProcess.h"

#import "CustomProtocolManager.h"
#import "Logging.h"
#import "ObjCObjectGraph.h"
#import "SandboxExtension.h"
#import "SandboxInitializationParameters.h"
Expand All @@ -52,6 +53,7 @@
#import <WebCore/MemoryRelease.h>
#import <WebCore/NSAccessibilitySPI.h>
#import <WebCore/PerformanceLogging.h>
#import <WebCore/QuartzCoreSPI.h>
#import <WebCore/RuntimeApplicationChecks.h>
#import <WebCore/WebCoreNSURLExtras.h>
#import <WebCore/pthreadSPI.h>
Expand Down Expand Up @@ -435,7 +437,14 @@ bool shouldTransformObject(id object) const override

void WebProcess::destroyRenderingResources()
{
WKDestroyRenderingResources();
#if !RELEASE_LOG_DISABLED
double startTime = monotonicallyIncreasingTime();
#endif
CABackingStoreCollectBlocking();
#if !RELEASE_LOG_DISABLED
double endTime = monotonicallyIncreasingTime();
#endif
RELEASE_LOG(ProcessSuspension, "%p - WebProcess::destroyRenderingResources() took %.2fms", this, (endTime - startTime) * 1000.0);
}

} // namespace WebKit

0 comments on commit 6cf896c

Please sign in to comment.