Synchronize Web process remote layer tree commits with CoreAnimation commits in the UI process
https://bugs.webkit.org/show_bug.cgi?id=130984

Reviewed by Simon Fraser.

There's no reason for the Web process to paint faster than the UI process
can apply to and commit the CoreAnimation layer tree.

Also, once we get proper double-buffering and purgeable back buffers, we
will need the ability to make some assumptions about in-use surfaces.

Unfortunately, we can't actually tell when the render server commits, 
as this is an asynchronous operation in a process we don't control, so
for now, this is only an approximation.

This also means that the assumptions we would like to make won't be
strong guarantees yet.

* UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.h:
* UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.mm:
(WebKit::RemoteLayerTreeDrawingAreaProxy::commitLayerTree):
When we commit, install a run loop observer to fire immediately after CoreAnimation commits.

(WebKit::RemoteLayerTreeDrawingAreaProxy::showDebugIndicator):
Fix a typo ('cmponents').

(WebKit::coreAnimationDidCommitLayersCallback):
(WebKit::RemoteLayerTreeDrawingAreaProxy::scheduleCoreAnimationLayerCommitObserver):
(WebKit::RemoteLayerTreeDrawingAreaProxy::coreAnimationDidCommitLayers):
When CA commits, send a message to the Web process letting it know that we
swapped to the new backing store.

* WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.h:
* WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm:
(WebKit::RemoteLayerTreeDrawingArea::RemoteLayerTreeDrawingArea):
(WebKit::RemoteLayerTreeDrawingArea::flushLayers):
(WebKit::RemoteLayerTreeDrawingArea::didUpdate):
Defer remote layer tree commits until we get didUpdate() from the UI process.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166540 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Double-buffer RemoteLayerBackingStore
https://bugs.webkit.org/show_bug.cgi?id=130990

Reviewed by Simon Fraser.

We'll keep a front and back buffer for each surface; the front is generally currently
being displayed in the UI process, and the back is the one we'll paint into.

Swap the two surfaces each time we paint; since we synchronize with the UI process,
the old front surface will generally be out-of-use by the render server by the time
we paint again. However, since render server commits are asynchronous and we have 
no way to syncronize with them yet, we have to check if the (swapped to front) back buffer is in use,
and create a new front buffer if it is.

Triple-buffering would solve this problem, as would synchronization with the render server,
as would a pool of surfaces - we will revisit these solutions in future patches.

* Shared/mac/RemoteLayerBackingStore.h:
* Shared/mac/RemoteLayerBackingStore.mm:
(RemoteLayerBackingStore::ensureBackingStore):
(RemoteLayerBackingStore::clearBackingStore):
Factor clearBackingStore() out of ensureBackingStore() and display().

(RemoteLayerBackingStore::display):
Swap buffers. Since m_backSurface will hold on to the back surface's CGContext,
we don't need to worry about tearing down the image first anymore.
Don't worry about creating a back image (nor copying it into the front image)
if we're going to paint the whole layer.

(RemoteLayerBackingStore::drawInContext):
Fix some names.

(RemoteLayerBackingStore::applyBackingStoreToLayer):
Reduce duplication.

(RemoteLayerBackingStore::createImageForFrontBuffer): Deleted.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166541 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[UI-side compositing] Proxy animations to the UI process
https://bugs.webkit.org/show_bug.cgi?id=130946

Source/WebCore:

Reviewed by Tim Horton.

To proxy CA animations, make PlatformCAAnimation a pure virtual base class
and subclass for Mac, Windows, and Remote (just like PlatformCALayer).

Add coding support for TimingFunctions.

Do some minor #include tidyup.

Minor refactor in GraphicsLayerCA to share some animations code.

* WebCore.exp.in:
* WebCore.xcodeproj/project.pbxproj:
* platform/animation/TimingFunction.h: Add setters need for encode/decode.
(WebCore::CubicBezierTimingFunction::setValues):
(WebCore::CubicBezierTimingFunction::setTimingFunctionPreset):
(WebCore::StepsTimingFunction::create):
(WebCore::StepsTimingFunction::setNumberOfSteps):
(WebCore::StepsTimingFunction::setStepAtStart):
* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::GraphicsLayerCA::createPlatformCAAnimation):
(WebCore::GraphicsLayerCA::animationCanBeAccelerated): Minor refactor so we can share
code with GraphicsLayerCARemote.
(WebCore::GraphicsLayerCA::addAnimation):
(WebCore::GraphicsLayerCA::createBasicAnimation):
(WebCore::PassRefPtr<PlatformCAAnimation>GraphicsLayerCA::createKeyframeAnimation):
* platform/graphics/ca/GraphicsLayerCA.h:
* platform/graphics/ca/PlatformCAAnimation.h:
(WebCore::PlatformCAAnimation::~PlatformCAAnimation):
(WebCore::PlatformCAAnimation::isPlatformCAAnimationMac):
(WebCore::PlatformCAAnimation::isPlatformCAAnimationWin):
(WebCore::PlatformCAAnimation::isPlatformCAAnimationRemote):
(WebCore::PlatformCAAnimation::PlatformCAAnimation):
(WebCore::PlatformCAAnimation::setType):
* platform/graphics/ca/PlatformCALayer.h:
* platform/graphics/ca/mac/PlatformCAAnimationMac.h: Added.
* platform/graphics/ca/mac/PlatformCAAnimationMac.mm:
* platform/graphics/ca/mac/PlatformCALayerMac.mm:
(PlatformCALayerMac::addAnimationForKey):
(PlatformCALayerMac::animationForKey):
* platform/graphics/ca/mac/TileController.mm:
* platform/graphics/ca/win/PlatformCAAnimationWin.cpp:
* platform/graphics/ca/win/PlatformCAAnimationWin.h: Added.

Source/WebKit2:

Reviewed by Tim Horton.

Add encoding/decoding of TimingFunctions. Add encoding support
for HashSet.

Add PlatformCAAnimationRemote and have PlatformCALayerRemote allow
animations now. PlatformCALayerRemote's properties are defined in the class,
as is the encoding/decoding (much cleaner than having them in the transaction
class I think).

Add support for the "animationDidStart" callback and sending this back to the
web process. This involves a HashMap of layerID->WKAnimationDelegate stored
on the RemoteLayerTreeHost, and a message send via the DrawingArea. On the
other side, RemoteLayerTreeContext stores a HashMap of layerID->PlatformCALayerRemote*
for layers which have just started animations, which is used to get the
PlatformCALayer* to call animationDidStart() on.

This requires that the RemoteLayerTreeHost* be passed down into property application,
and that the RemoteLayerTreeHost have a reference to the drawing area.

To every CALayer in the UI process we -setValue:forKey: to track the PlatformLayerID,
so we can get back to it in order to dispatch "animationDidStart".

Replace some "using namespace WebKit" with "namespace WebKit { }".

* Platform/IPC/ArgumentCoders.h:
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<LinearTimingFunction>::encode):
(IPC::ArgumentCoder<LinearTimingFunction>::decode):
(IPC::ArgumentCoder<CubicBezierTimingFunction>::encode):
(IPC::ArgumentCoder<CubicBezierTimingFunction>::decode):
(IPC::ArgumentCoder<StepsTimingFunction>::encode):
(IPC::ArgumentCoder<StepsTimingFunction>::decode):
* Shared/WebCoreArgumentCoders.h:
* Shared/mac/RemoteLayerBackingStore.mm:
* Shared/mac/RemoteLayerTreePropertyApplier.h:
* Shared/mac/RemoteLayerTreePropertyApplier.mm:
(WebKit::applyPropertiesToLayer):
(WebKit::RemoteLayerTreePropertyApplier::applyProperties):
* Shared/mac/RemoteLayerTreeTransaction.h:
* Shared/mac/RemoteLayerTreeTransaction.mm:
(WebKit::RemoteLayerTreeTransaction::LayerProperties::LayerProperties):
(WebKit::RemoteLayerTreeTransaction::LayerProperties::encode):
(WebKit::RemoteLayerTreeTransaction::LayerProperties::decode):
(WebKit::dumpChangedLayers):
* UIProcess/ios/RemoteLayerTreeHostIOS.mm:
(WebKit::RemoteLayerTreeHost::layerID):
(WebKit::RemoteLayerTreeHost::createLayer):
* UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.h:
* UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.mm:
(WebKit::RemoteLayerTreeDrawingAreaProxy::RemoteLayerTreeDrawingAreaProxy):
(WebKit::RemoteLayerTreeDrawingAreaProxy::acceleratedAnimationDidStart):
(WebKit::RemoteLayerTreeDrawingAreaProxy::showDebugIndicator):
* UIProcess/mac/RemoteLayerTreeHost.h:
(WebKit::RemoteLayerTreeHost::animationDelegates):
* UIProcess/mac/RemoteLayerTreeHost.mm:
(WebKit::RemoteLayerTreeHost::RemoteLayerTreeHost):
(WebKit::RemoteLayerTreeHost::updateLayerTree):
(WebKit::RemoteLayerTreeHost::layerWillBeRemoved):
(WebKit::RemoteLayerTreeHost::animationDidStart):
(WebKit::RemoteLayerTreeHost::layerID):
(WebKit::RemoteLayerTreeHost::createLayer):
* WebKit2.xcodeproj/project.pbxproj:
* WebProcess/WebPage/DrawingArea.h:
(WebKit::DrawingArea::acceleratedAnimationDidStart):
* WebProcess/WebPage/DrawingArea.messages.in:
* WebProcess/WebPage/mac/GraphicsLayerCARemote.cpp:
(WebKit::GraphicsLayerCARemote::createPlatformCAAnimation):
* WebProcess/WebPage/mac/GraphicsLayerCARemote.h:
* WebProcess/WebPage/mac/PlatformCAAnimationRemote.h: Added.
* WebProcess/WebPage/mac/PlatformCAAnimationRemote.mm: Added.
* WebProcess/WebPage/mac/PlatformCALayerRemote.cpp:
(WebKit::PlatformCALayerRemote::recursiveBuildTransaction):
(WebKit::PlatformCALayerRemote::animationStarted):
(WebKit::PlatformCALayerRemote::addAnimationForKey):
(WebKit::PlatformCALayerRemote::removeAnimationForKey):
(WebKit::PlatformCALayerRemote::animationForKey):
(PlatformCALayerRemote::recursiveBuildTransaction): Deleted.
(PlatformCALayerRemote::addAnimationForKey): Deleted.
(PlatformCALayerRemote::removeAnimationForKey): Deleted.
(PlatformCALayerRemote::animationForKey): Deleted.
* WebProcess/WebPage/mac/PlatformCALayerRemoteCustom.mm:
* WebProcess/WebPage/mac/PlatformCALayerRemoteTiledBacking.cpp:
* WebProcess/WebPage/mac/RemoteLayerTreeContext.h:
* WebProcess/WebPage/mac/RemoteLayerTreeContext.mm:
(WebKit::RemoteLayerTreeContext::layerWillBeDestroyed):
(WebKit::RemoteLayerTreeContext::willStartAnimationOnLayer):
(WebKit::RemoteLayerTreeContext::animationDidStart):
* WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.h:
* WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm:
(WebKit::RemoteLayerTreeDrawingArea::acceleratedAnimationDidStart):
* WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
(WebKit::TiledCoreAnimationDrawingArea::commitTransientZoom):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166542 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Unreviewed, rolling out r166536.
https://bugs.webkit.org/show_bug.cgi?id=130993

This is not the correct fix. (Requested by bfulgham on
#webkit).

Reverted changeset:

"Unreviewed test fix after r166530."
http://trac.webkit.org/changeset/166536

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166543 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Improve GC_LOGGING
https://bugs.webkit.org/show_bug.cgi?id=130988

Reviewed by Geoffrey Garen.

GC_LOGGING can be useful for diagnosing where we're spending our time during collection, 
but it doesn't distinguish between Eden and Full collections in the data it gathers. This
patch updates it so that it can. It also adds the process ID to the beginning of each line 
of input to be able to distinguish between the output of multiple processes exiting at the 
same time.

* heap/Heap.cpp:
(JSC::Heap::collect):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166544 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[iOS WebKit2] Flush all surfaces after painting into all of them, instead of after painting into each one
https://bugs.webkit.org/show_bug.cgi?id=130768
<rdar://problem/16421471>

Reviewed by Benjamin Poulain.

* Shared/mac/RemoteLayerBackingStore.h:
Make RemoteLayerBackingStore noncopyable.
Add flush(), which synchronously flushes painting operations on the underlying backing store.
Add storage for the CGContext that needs to be flushed, and ensure that it is flushed before we paint again.

* Shared/mac/RemoteLayerBackingStore.mm:
(RemoteLayerBackingStore::display):

(RemoteLayerBackingStore::drawInContext):
Don't flush the context immediately after painting.

(RemoteLayerBackingStore::flush):
Flush the current front surface/buffer's context.
Clear the new pending-flush members.

* WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm:
(WebKit::flushBackingStoreChangesInTransaction):
(WebKit::RemoteLayerTreeDrawingArea::flushLayers):
Crawl through all of the valid changed backing stores in the transaction and flush them.
Reset changed properties after encoding the commit.

* Shared/mac/RemoteLayerTreeTransaction.h:
(WebKit::RemoteLayerTreeTransaction::LayerProperties::resetChangedProperties):
(WebKit::RemoteLayerTreeTransaction::changedLayers):
(WebKit::RemoteLayerTreeTransaction::changedLayerProperties):
* Shared/mac/RemoteLayerTreeTransaction.mm:
(WebKit::RemoteLayerTreeTransaction::LayerProperties::LayerProperties):
(WebKit::RemoteLayerTreeTransaction::LayerProperties::decode):
(WebKit::RemoteLayerTreeTransaction::encode):
(WebKit::RemoteLayerTreeTransaction::decode):
(WebKit::RemoteLayerTreeTransaction::layerPropertiesChanged):
(WebKit::dumpChangedLayers):
Instead of storing a copy of the LayerProperties struct for each changed layer
while building the transaction in the Web process, store a list of changed layers,
and directly encode the commit from those layers' LayerProperties. This provides a few benefits:
        - We avoid copying LayerProperties for every changed layer, every commit
        - We can make RemoteLayerBackingStore noncopyable
        - We can walk the changed layers after building the transaction
        in order to flush backing store, and actually affect the layers'
        own RemoteLayerBackingStore instead of a copy.
The UI process will still generate a LayerPropertiesMap at decode time.

* UIProcess/mac/RemoteLayerTreeHost.mm:
(WebKit::RemoteLayerTreeHost::updateLayerTree):
Don't copy the LayerProperties struct for the debug overlay. Instead,
adjust the properties which the debug overlay whacks directly on the layer,
after applying the normal LayerProperties.

* WebProcess/WebPage/mac/PlatformCALayerRemote.cpp:
(PlatformCALayerRemote::recursiveBuildTransaction):
Don't reset changed layer properties in the middle of building a transaction. Instead,
RemoteLayerTreeDrawingArea::flushLayers() will reset all the flags on all changed layers
after the commit is encoded.

* WebProcess/WebPage/mac/PlatformCALayerRemote.h:
(WebKit::PlatformCALayerRemote::properties):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166545 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Rename -[WKNavigationAction destinationFrame] to -[WKNavigationAction targetFrame]
https://bugs.webkit.org/show_bug.cgi?id=130994

Reviewed by Dan Bernstein.

* UIProcess/API/Cocoa/WKNavigationAction.h:
* UIProcess/API/Cocoa/WKNavigationAction.mm:
(-[WKNavigationAction description]):
(-[WKNavigationAction targetFrame]):
(-[WKNavigationAction setTargetFrame:]):
(-[WKNavigationAction destinationFrame]): Deleted.
(-[WKNavigationAction setDestinationFrame:]): Deleted.
* UIProcess/API/Cocoa/WKNavigationActionInternal.h:
* UIProcess/Cocoa/NavigationState.mm:
(WebKit::NavigationState::PolicyClient::decidePolicyForNavigationAction):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166546 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Unreviewed test correction after r166530.

* DumpRenderTree/mac/DumpRenderTree.mm:
(setDefaultsToConsistentValuesForTesting): No need to change preference for all tests. We set the proper
fine-grained setting for swipe tests. This prevents existing tests from breaking.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166547 268f45cc-cd09-0410-ab3c-d52691b4dbfc
REGRESSION (r166144?): fast/preloader/document-write.html is very flaky
https://bugs.webkit.org/show_bug.cgi?id=130942

* platform/mac/TestExpectations: Marking as such.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166548 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Fix the build.

* UIProcess/mac/RemoteLayerTreeHost.mm:
(WebKit::RemoteLayerTreeHost::updateLayerTree):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166549 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Fix the build.

* UIProcess/mac/RemoteLayerTreeHost.mm:
(WebKit::RemoteLayerTreeHost::updateLayerTree):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166550 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Crashes in PageConsole::addMessage
https://bugs.webkit.org/show_bug.cgi?id=130991
<rdar://problem/14795232>

Reviewed by Geoffrey Garen.

Source/WebCore:

Test: http/tests/misc/detached-frame-console.html

* page/DOMWindow.cpp: (WebCore::DOMWindow::printErrorMessage): Added a null check.
It's legitimate for this to be called for a window that is not currently displayed
in a frame.

LayoutTests:

* http/tests/misc/detached-frame-console-expected.txt: Added.
* http/tests/misc/detached-frame-console.html: Added.
* http/tests/misc/resources/detached-frame-console-subframe.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166551 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Remove duplicate entries in Derived Sources.

Rubber-stamped by Anders Carlsson.

* WebKit2.xcodeproj/project.pbxproj:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166552 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Add a new -[WKPreferences initWithUserDefaultsPrefixKey:] initializer
https://bugs.webkit.org/show_bug.cgi?id=130996

Reviewed by Simon Fraser.

Add a "key prefix" to the WebKit::WebPreferences create function, so we can use a different
key prefix ("WebKit") for the modern API and not pollute the user defaults namespace with
the old key prefix ("WebKit2.").

* UIProcess/API/C/WKPreferences.cpp:
(WKPreferencesCreate):
(WKPreferencesCreateWithIdentifier):
* UIProcess/API/Cocoa/WKPreferences.h:
* UIProcess/API/Cocoa/WKPreferences.mm:
(-[WKPreferences init]):
(-[WKPreferences initWithUserDefaultsPrefixKey:]):
(-[WKPreferences userDefaultsPrefixKey]):
* UIProcess/WebPageGroup.cpp:
(WebKit::WebPageGroup::WebPageGroup):
* UIProcess/WebPreferences.cpp:
(WebKit::WebPreferences::WebPreferences):
* UIProcess/WebPreferences.h:
(WebKit::WebPreferences::create):
* UIProcess/mac/WebPreferencesMac.mm:
(WebKit::makeKey):
(WebKit::setStringValueIfInUserDefaults):
(WebKit::setBoolValueIfInUserDefaults):
(WebKit::setUInt32ValueIfInUserDefaults):
(WebKit::setDoubleValueIfInUserDefaults):
(WebKit::WebPreferences::platformInitializeStore):
(WebKit::WebPreferences::platformUpdateStringValueForKey):
(WebKit::WebPreferences::platformUpdateBoolValueForKey):
(WebKit::WebPreferences::platformUpdateUInt32ValueForKey):
(WebKit::WebPreferences::platformUpdateDoubleValueForKey):
(WebKit::WebPreferences::platformUpdateFloatValueForKey):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166553 268f45cc-cd09-0410-ab3c-d52691b4dbfc