diff options
Diffstat (limited to 'Source/WebKit2/WebProcess')
47 files changed, 1492 insertions, 953 deletions
diff --git a/Source/WebKit2/WebProcess/Geolocation/WebGeolocationManager.cpp b/Source/WebKit2/WebProcess/Geolocation/WebGeolocationManager.cpp index 2b976763f..1bdf11d65 100644 --- a/Source/WebKit2/WebProcess/Geolocation/WebGeolocationManager.cpp +++ b/Source/WebKit2/WebProcess/Geolocation/WebGeolocationManager.cpp @@ -76,10 +76,10 @@ void WebGeolocationManager::didChangePosition(const WebGeolocationPosition::Data #if ENABLE(GEOLOCATION) RefPtr<GeolocationPosition> position = GeolocationPosition::create(data.timestamp, data.latitude, data.longitude, data.accuracy); - HashSet<WebPage*>::const_iterator it = m_pageSet.begin(); - HashSet<WebPage*>::const_iterator end = m_pageSet.end(); - for (; it != end; ++it) { - WebPage* page = *it; + Vector<RefPtr<WebPage> > webPageCopy; + copyToVector(m_pageSet, webPageCopy); + for (size_t i = 0; i < webPageCopy.size(); ++i) { + WebPage* page = webPageCopy[i].get(); if (page->corePage()) GeolocationController::from(page->corePage())->positionChanged(position.get()); } @@ -92,10 +92,10 @@ void WebGeolocationManager::didFailToDeterminePosition() // FIXME: Add localized error string. RefPtr<GeolocationError> error = GeolocationError::create(GeolocationError::PositionUnavailable, /* Localized error string */ String("")); - HashSet<WebPage*>::const_iterator it = m_pageSet.begin(); - HashSet<WebPage*>::const_iterator end = m_pageSet.end(); - for (; it != end; ++it) { - WebPage* page = *it; + Vector<RefPtr<WebPage> > webPageCopy; + copyToVector(m_pageSet, webPageCopy); + for (size_t i = 0; i < webPageCopy.size(); ++i) { + WebPage* page = webPageCopy[i].get(); if (page->corePage()) GeolocationController::from(page->corePage())->errorOccurred(error.get()); } diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.cpp index 55d083b27..ee10e964f 100644 --- a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.cpp +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.cpp @@ -255,3 +255,8 @@ void WKBundleSetPageVisibilityState(WKBundleRef bundleRef, WKBundlePageRef pageR { toImpl(bundleRef)->setPageVisibilityState(toImpl(pageRef), state, isInitialState); } + +void WKBundleSetUserStyleSheetLocation(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, WKStringRef location) +{ + toImpl(bundleRef)->setUserStyleSheetLocation(toImpl(pageGroupRef), toImpl(location)->string()); +} diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp index 2ae22371d..1f43a1220 100644 --- a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp @@ -287,21 +287,27 @@ bool WKBundlePageFindString(WKBundlePageRef pageRef, WKStringRef target, WKFindO return toImpl(pageRef)->findStringFromInjectedBundle(toImpl(target)->string(), toFindOptions(findOptions)); } +WKImageRef WKBundlePageCreateSnapshotWithOptions(WKBundlePageRef pageRef, WKRect rect, WKSnapshotOptions options) +{ + RefPtr<WebImage> webImage = toImpl(pageRef)->scaledSnapshotWithOptions(toIntRect(rect), 1, toSnapshotOptions(options)); + return toAPI(webImage.release().leakRef()); +} + WKImageRef WKBundlePageCreateSnapshotInViewCoordinates(WKBundlePageRef pageRef, WKRect rect, WKImageOptions options) { - RefPtr<WebImage> webImage = toImpl(pageRef)->snapshotInViewCoordinates(toIntRect(rect), toImageOptions(options)); + RefPtr<WebImage> webImage = toImpl(pageRef)->scaledSnapshotWithOptions(toIntRect(rect), 1, snapshotOptionsFromImageOptions(options)); return toAPI(webImage.release().leakRef()); } WKImageRef WKBundlePageCreateSnapshotInDocumentCoordinates(WKBundlePageRef pageRef, WKRect rect, WKImageOptions options) { - RefPtr<WebImage> webImage = toImpl(pageRef)->snapshotInDocumentCoordinates(toIntRect(rect), toImageOptions(options)); + RefPtr<WebImage> webImage = toImpl(pageRef)->scaledSnapshotWithOptions(toIntRect(rect), 1, snapshotOptionsFromImageOptions(options)); return toAPI(webImage.release().leakRef()); } WKImageRef WKBundlePageCreateScaledSnapshotInDocumentCoordinates(WKBundlePageRef pageRef, WKRect rect, double scaleFactor, WKImageOptions options) { - RefPtr<WebImage> webImage = toImpl(pageRef)->scaledSnapshotInDocumentCoordinates(toIntRect(rect), scaleFactor, toImageOptions(options)); + RefPtr<WebImage> webImage = toImpl(pageRef)->scaledSnapshotWithOptions(toIntRect(rect), scaleFactor, snapshotOptionsFromImageOptions(options)); return toAPI(webImage.release().leakRef()); } diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.h index aa8609244..28eee5c73 100644 --- a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.h +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.h @@ -398,8 +398,14 @@ WK_EXPORT bool WKBundlePageCanHandleRequest(WKURLRequestRef request); WK_EXPORT bool WKBundlePageFindString(WKBundlePageRef page, WKStringRef target, WKFindOptions findOptions); +WK_EXPORT WKImageRef WKBundlePageCreateSnapshotWithOptions(WKBundlePageRef page, WKRect rect, WKSnapshotOptions options); + +// We should deprecate these functions in favor of just using WKBundlePageCreateSnapshotWithOptions. WK_EXPORT WKImageRef WKBundlePageCreateSnapshotInViewCoordinates(WKBundlePageRef page, WKRect rect, WKImageOptions options); WK_EXPORT WKImageRef WKBundlePageCreateSnapshotInDocumentCoordinates(WKBundlePageRef page, WKRect rect, WKImageOptions options); + +// We should keep this function since it allows passing a scale factor, but we should re-name it to +// WKBundlePageCreateScaledSnapshotWithOptions. WK_EXPORT WKImageRef WKBundlePageCreateScaledSnapshotInDocumentCoordinates(WKBundlePageRef page, WKRect rect, double scaleFactor, WKImageOptions options); WK_EXPORT double WKBundlePageGetBackingScaleFactor(WKBundlePageRef page); diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h index 12e933ea8..b5e10e57f 100644 --- a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h @@ -74,6 +74,7 @@ WK_EXPORT void WKBundleSetGeolocationPermission(WKBundleRef bundle, WKBundlePage WK_EXPORT void WKBundleSetJavaScriptCanAccessClipboard(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled); WK_EXPORT void WKBundleSetPrivateBrowsingEnabled(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled); WK_EXPORT void WKBundleSetPopupBlockingEnabled(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled); +WK_EXPORT void WKBundleSetUserStyleSheetLocation(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, WKStringRef location); WK_EXPORT void WKBundleSetAuthorAndUserStylesEnabled(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled); WK_EXPORT void WKBundleClearAllDatabases(WKBundleRef bundle); WK_EXPORT void WKBundleSetDatabaseQuota(WKBundleRef bundle, uint64_t); diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp index d809d611b..127715c7a 100644 --- a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp @@ -131,6 +131,30 @@ void InjectedBundle::overrideBoolPreferenceForTestRunner(WebPageGroupProxy* page // FIXME: Need an explicit way to set "WebKitTabToLinksPreferenceKey" directly in WebPage. + if (preference == "WebKit2AsynchronousPluginInitializationEnabled") { + WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::asynchronousPluginInitializationEnabledKey(), enabled); + for (HashSet<Page*>::iterator i = pages.begin(); i != pages.end(); ++i) { + WebPage* webPage = static_cast<WebFrameLoaderClient*>((*i)->mainFrame()->loader()->client())->webFrame()->page(); + webPage->setAsynchronousPluginInitializationEnabled(enabled); + } + } + + if (preference == "WebKit2AsynchronousPluginInitializationEnabledForAllPlugins") { + WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::asynchronousPluginInitializationEnabledForAllPluginsKey(), enabled); + for (HashSet<Page*>::iterator i = pages.begin(); i != pages.end(); ++i) { + WebPage* webPage = static_cast<WebFrameLoaderClient*>((*i)->mainFrame()->loader()->client())->webFrame()->page(); + webPage->setAsynchronousPluginInitializationEnabledForAllPlugins(enabled); + } + } + + if (preference == "WebKit2ArtificialPluginInitializationDelayEnabled") { + WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::artificialPluginInitializationDelayEnabledKey(), enabled); + for (HashSet<Page*>::iterator i = pages.begin(); i != pages.end(); ++i) { + WebPage* webPage = static_cast<WebFrameLoaderClient*>((*i)->mainFrame()->loader()->client())->webFrame()->page(); + webPage->setArtificialPluginInitializationDelayEnabled(enabled); + } + } + // Map the names used in LayoutTests with the names used in WebCore::Settings and WebPreferencesStore. #define FOR_EACH_OVERRIDE_BOOL_PREFERENCE(macro) \ macro(WebKitAcceleratedCompositingEnabled, AcceleratedCompositingEnabled, acceleratedCompositingEnabled) \ @@ -479,4 +503,11 @@ void InjectedBundle::setPageVisibilityState(WebPage* page, int state, bool isIni #endif } +void InjectedBundle::setUserStyleSheetLocation(WebPageGroupProxy* pageGroup, const String& location) +{ + const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages(); + for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter) + (*iter)->settings()->setUserStyleSheetLocation(KURL(KURL(), location)); +} + } // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h index f3e36a85d..1e240503b 100644 --- a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h @@ -123,6 +123,7 @@ public: int pageNumberForElementById(WebFrame*, const String&, double, double); String pageSizeAndMarginsInPixels(WebFrame*, int, int, int, int, int, int, int); bool isPageBoxVisible(WebFrame*, int); + void setUserStyleSheetLocation(WebPageGroupProxy*, const String&); // UserContent API void addUserScript(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& source, const String& url, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserScriptInjectionTime, WebCore::UserContentInjectedFrames); diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp b/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp index 4d82cff01..b20743213 100644 --- a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp +++ b/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp @@ -548,6 +548,38 @@ bool NetscapePlugin::allowPopups() const return false; } +#if PLUGIN_ARCHITECTURE(MAC) +static bool isTransparentSilverlightBackgroundValue(const String& lowercaseBackgroundValue) +{ + // This checks if the background color value is transparent, according to + // the forumat documented at http://msdn.microsoft.com/en-us/library/cc838148(VS.95).aspx + if (lowercaseBackgroundValue.startsWith('#')) { + if (lowercaseBackgroundValue.length() == 5 && lowercaseBackgroundValue[1] != 'f') { + // An 8-bit RGB value with alpha transparency, in the form #ARGB. + return true; + } + + if (lowercaseBackgroundValue.length() == 9 && !(lowercaseBackgroundValue[1] == 'f' && lowercaseBackgroundValue[2] == 'f')) { + // A 16-bit RGB value with alpha transparency, in the form #AARRGGBB. + return true; + } + } else if (lowercaseBackgroundValue.startsWith("sc#")) { + Vector<String> components; + lowercaseBackgroundValue.substring(3).split(",", components); + + // An ScRGB value with alpha transparency, in the form sc#A,R,G,B. + if (components.size() == 4) { + if (components[0].toDouble() < 1) + return true; + } + } else if (lowercaseBackgroundValue == "transparent") + return true; + + // This is an opaque color. + return false; +} +#endif + bool NetscapePlugin::initialize(const Parameters& parameters) { uint16_t mode = parameters.isFullFramePlugin ? NP_FULL : NP_EMBED; @@ -581,10 +613,10 @@ bool NetscapePlugin::initialize(const Parameters& parameters) } #if PLUGIN_ARCHITECTURE(MAC) - if (m_pluginModule->pluginQuirks().contains(PluginQuirks::MakeTransparentIfBackgroundAttributeExists)) { + if (m_pluginModule->pluginQuirks().contains(PluginQuirks::MakeOpaqueUnlessTransparentSilverlightBackgroundAttributeExists)) { for (size_t i = 0; i < parameters.names.size(); ++i) { if (equalIgnoringCase(parameters.names[i], "background")) { - setIsTransparent(true); + setIsTransparent(isTransparentSilverlightBackgroundValue(parameters.values[i].lower())); break; } } diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h b/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h index 1c49c6032..8591892b8 100644 --- a/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h +++ b/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h @@ -54,6 +54,10 @@ public: static PassRefPtr<NetscapePlugin> fromNPP(NPP); + // In-process NetscapePlugins don't support asynchronous initialization. + virtual void waitForAsynchronousInitialization() { } + virtual bool isBeingAsynchronouslyInitialized() const { return false; } + #if PLATFORM(MAC) NPError setDrawingModel(NPDrawingModel); NPError setEventModel(NPEventModel); diff --git a/Source/WebKit2/WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm b/Source/WebKit2/WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm index f1fa2f646..8a447df31 100644 --- a/Source/WebKit2/WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm +++ b/Source/WebKit2/WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm @@ -1057,6 +1057,27 @@ PlatformLayer* NetscapePlugin::pluginLayer() return static_cast<PlatformLayer*>(m_pluginLayer.get()); } +static void makeCGLPresentLayerOpaque(CALayer *pluginRootLayer) +{ + // We look for a layer that's the only sublayer of the root layer that is an instance + // of the CGLPresentLayer class which in turn is a subclass of CAOpenGLLayer and make + // it opaque if all these conditions hold. + + NSArray *sublayers = [pluginRootLayer sublayers]; + if ([sublayers count] != 1) + return; + + Class cglPresentLayerClass = NSClassFromString(@"CGLPresentLayer"); + if (![cglPresentLayerClass isSubclassOfClass:[CAOpenGLLayer class]]) + return; + + CALayer *layer = [sublayers objectAtIndex:0]; + if (![layer isKindOfClass:cglPresentLayerClass]) + return; + + [layer setOpaque:YES]; +} + void NetscapePlugin::updatePluginLayer() { if (m_drawingModel != NPDrawingModelCoreAnimation) @@ -1086,6 +1107,10 @@ void NetscapePlugin::updatePluginLayer() m_pluginLayer = reinterpret_cast<CALayer *>(value); else m_pluginLayer.adoptNS(reinterpret_cast<CALayer *>(value)); + + if (m_pluginModule->pluginQuirks().contains(PluginQuirks::MakeOpaqueUnlessTransparentSilverlightBackgroundAttributeExists) && + !m_isTransparent) + makeCGLPresentLayerOpaque(m_pluginLayer.get()); } #ifndef NP_NO_CARBON diff --git a/Source/WebKit2/WebProcess/Plugins/PDF/BuiltInPDFView.h b/Source/WebKit2/WebProcess/Plugins/PDF/BuiltInPDFView.h index 6d11c8552..8a7c28a5b 100644 --- a/Source/WebKit2/WebProcess/Plugins/PDF/BuiltInPDFView.h +++ b/Source/WebKit2/WebProcess/Plugins/PDF/BuiltInPDFView.h @@ -50,6 +50,10 @@ public: static WebCore::PluginInfo pluginInfo(); + // In-process PDFViews don't support asynchronous initialization. + virtual void waitForAsynchronousInitialization() { } + virtual bool isBeingAsynchronouslyInitialized() const { return false; } + private: explicit BuiltInPDFView(WebFrame*); diff --git a/Source/WebKit2/WebProcess/Plugins/Plugin.h b/Source/WebKit2/WebProcess/Plugins/Plugin.h index 5be84f476..b91174f9e 100644 --- a/Source/WebKit2/WebProcess/Plugins/Plugin.h +++ b/Source/WebKit2/WebProcess/Plugins/Plugin.h @@ -83,6 +83,10 @@ public: // Sets the active plug-in controller and initializes the plug-in. bool initialize(PluginController*, const Parameters&); + // Forces synchronous initialization of a plugin previously initialized asynchronously. + virtual void waitForAsynchronousInitialization() = 0; + virtual bool isBeingAsynchronouslyInitialized() const = 0; + // Destroys the plug-in. void destroyPlugin(); diff --git a/Source/WebKit2/WebProcess/Plugins/PluginController.h b/Source/WebKit2/WebProcess/Plugins/PluginController.h index 42c29595e..6682ba020 100644 --- a/Source/WebKit2/WebProcess/Plugins/PluginController.h +++ b/Source/WebKit2/WebProcess/Plugins/PluginController.h @@ -138,6 +138,15 @@ public: // Returns whether private browsing is enabled. virtual bool isPrivateBrowsingEnabled() = 0; + + // Returns whether or not asynchronous plugin initialization is enabled. + virtual bool asynchronousPluginInitializationEnabled() const { return false; } + + // Returns whether or not asynchronous plugin initialization should be attempted for all plugins. + virtual bool asynchronousPluginInitializationEnabledForAllPlugins() const { return false; } + + // Returns the articifical plugin delay to use for testing of asynchronous plugin initialization. + virtual bool artificialPluginInitializationDelayEnabled() const { return false; } // Increments a counter that prevents the plug-in from being destroyed. virtual void protectPluginFromDestruction() = 0; @@ -151,6 +160,12 @@ public: virtual void windowedPluginGeometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, uint64_t windowID) = 0; #endif + // Called when the a plug-in instance is successfully initialized, either synchronously or asynchronously. + virtual void didInitializePlugin() = 0; + + // Called when the a plug-in instance fails to initialized, either synchronously or asynchronously. + virtual void didFailToInitializePlugin() = 0; + // Helper class for delaying destruction of a plug-in. class PluginDestructionProtector { public: diff --git a/Source/WebKit2/WebProcess/Plugins/PluginProcessConnection.cpp b/Source/WebKit2/WebProcess/Plugins/PluginProcessConnection.cpp index 8339ad45c..cc313d2e4 100644 --- a/Source/WebKit2/WebProcess/Plugins/PluginProcessConnection.cpp +++ b/Source/WebKit2/WebProcess/Plugins/PluginProcessConnection.cpp @@ -73,9 +73,10 @@ static double defaultSyncMessageTimeout(const String& pluginPath) return syncMessageTimeout; } -PluginProcessConnection::PluginProcessConnection(PluginProcessConnectionManager* pluginProcessConnectionManager, const String& pluginPath, CoreIPC::Connection::Identifier connectionIdentifier) +PluginProcessConnection::PluginProcessConnection(PluginProcessConnectionManager* pluginProcessConnectionManager, const String& pluginPath, CoreIPC::Connection::Identifier connectionIdentifier, bool supportsAsynchronousPluginInitialization) : m_pluginProcessConnectionManager(pluginProcessConnectionManager) , m_pluginPath(pluginPath) + , m_supportsAsynchronousPluginInitialization(supportsAsynchronousPluginInitialization) { m_connection = CoreIPC::Connection::createClientConnection(connectionIdentifier, this, WebProcess::shared().runLoop()); diff --git a/Source/WebKit2/WebProcess/Plugins/PluginProcessConnection.h b/Source/WebKit2/WebProcess/Plugins/PluginProcessConnection.h index 61c4ac2a5..bc866d10c 100644 --- a/Source/WebKit2/WebProcess/Plugins/PluginProcessConnection.h +++ b/Source/WebKit2/WebProcess/Plugins/PluginProcessConnection.h @@ -43,9 +43,9 @@ class PluginProxy; class PluginProcessConnection : public RefCounted<PluginProcessConnection>, CoreIPC::Connection::Client { public: - static PassRefPtr<PluginProcessConnection> create(PluginProcessConnectionManager* pluginProcessConnectionManager, const String& pluginPath, CoreIPC::Connection::Identifier connectionIdentifier) + static PassRefPtr<PluginProcessConnection> create(PluginProcessConnectionManager* pluginProcessConnectionManager, const String& pluginPath, CoreIPC::Connection::Identifier connectionIdentifier, bool supportsAsynchronousPluginInitialization) { - return adoptRef(new PluginProcessConnection(pluginProcessConnectionManager, pluginPath, connectionIdentifier)); + return adoptRef(new PluginProcessConnection(pluginProcessConnectionManager, pluginPath, connectionIdentifier, supportsAsynchronousPluginInitialization)); } ~PluginProcessConnection(); @@ -58,8 +58,10 @@ public: NPRemoteObjectMap* npRemoteObjectMap() const { return m_npRemoteObjectMap.get(); } + bool supportsAsynchronousPluginInitialization() const { return m_supportsAsynchronousPluginInitialization; } + private: - PluginProcessConnection(PluginProcessConnectionManager* pluginProcessConnectionManager, const String& pluginPath, CoreIPC::Connection::Identifier connectionIdentifier); + PluginProcessConnection(PluginProcessConnectionManager*, const String& pluginPath, CoreIPC::Connection::Identifier connectionIdentifier, bool supportsAsynchronousInitialization); // CoreIPC::Connection::Client virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*); @@ -82,6 +84,8 @@ private: HashMap<uint64_t, PluginProxy*> m_plugins; RefPtr<NPRemoteObjectMap> m_npRemoteObjectMap; + + bool m_supportsAsynchronousPluginInitialization; }; } // namespace WebKit diff --git a/Source/WebKit2/WebProcess/Plugins/PluginProcessConnectionManager.cpp b/Source/WebKit2/WebProcess/Plugins/PluginProcessConnectionManager.cpp index fd1906d7a..b77050992 100644 --- a/Source/WebKit2/WebProcess/Plugins/PluginProcessConnectionManager.cpp +++ b/Source/WebKit2/WebProcess/Plugins/PluginProcessConnectionManager.cpp @@ -57,13 +57,14 @@ PluginProcessConnection* PluginProcessConnectionManager::getPluginProcessConnect } CoreIPC::Attachment encodedConnectionIdentifier; + bool supportsAsynchronousInitialization; if (!WebProcess::shared().connection()->sendSync(Messages::WebProcessProxy::GetPluginProcessConnection(pluginPath), - Messages::WebProcessProxy::GetPluginProcessConnection::Reply(encodedConnectionIdentifier), 0)) + Messages::WebProcessProxy::GetPluginProcessConnection::Reply(encodedConnectionIdentifier, supportsAsynchronousInitialization), 0)) return 0; #if PLATFORM(MAC) - CoreIPC::Connection::Identifier connectionIdentifier = encodedConnectionIdentifier.port(); - if (!connectionIdentifier) + CoreIPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.port()); + if (CoreIPC::Connection::identifierIsNull(connectionIdentifier)) return 0; #elif USE(UNIX_DOMAIN_SOCKETS) CoreIPC::Connection::Identifier connectionIdentifier = encodedConnectionIdentifier.fileDescriptor(); @@ -71,7 +72,7 @@ PluginProcessConnection* PluginProcessConnectionManager::getPluginProcessConnect return 0; #endif - RefPtr<PluginProcessConnection> pluginProcessConnection = PluginProcessConnection::create(this, pluginPath, connectionIdentifier); + RefPtr<PluginProcessConnection> pluginProcessConnection = PluginProcessConnection::create(this, pluginPath, connectionIdentifier, supportsAsynchronousInitialization); m_pluginProcessConnections.append(pluginProcessConnection); { diff --git a/Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp b/Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp index d4a3549f4..17db25708 100644 --- a/Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp +++ b/Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp @@ -68,6 +68,7 @@ PluginProxy::PluginProxy(const String& pluginPath) , m_waitingForPaintInResponseToUpdate(false) , m_wantsWheelEvents(false) , m_remoteLayerClientID(0) + , m_waitingOnAsynchronousInitialization(false) { } @@ -93,38 +94,112 @@ bool PluginProxy::initialize(const Parameters& parameters) m_connection->addPluginProxy(this); // Ask the plug-in process to create a plug-in. - PluginCreationParameters creationParameters; - creationParameters.pluginInstanceID = m_pluginInstanceID; - creationParameters.windowNPObjectID = windowNPObjectID(); - creationParameters.parameters = parameters; - creationParameters.userAgent = controller()->userAgent(); - creationParameters.contentsScaleFactor = contentsScaleFactor(); - creationParameters.isPrivateBrowsingEnabled = controller()->isPrivateBrowsingEnabled(); + m_pendingPluginCreationParameters = adoptPtr(new PluginCreationParameters); + + m_pendingPluginCreationParameters->pluginInstanceID = m_pluginInstanceID; + m_pendingPluginCreationParameters->windowNPObjectID = windowNPObjectID(); + m_pendingPluginCreationParameters->parameters = parameters; + m_pendingPluginCreationParameters->userAgent = controller()->userAgent(); + m_pendingPluginCreationParameters->contentsScaleFactor = contentsScaleFactor(); + m_pendingPluginCreationParameters->isPrivateBrowsingEnabled = controller()->isPrivateBrowsingEnabled(); + m_pendingPluginCreationParameters->artificialPluginInitializationDelayEnabled = controller()->artificialPluginInitializationDelayEnabled(); + #if USE(ACCELERATED_COMPOSITING) - creationParameters.isAcceleratedCompositingEnabled = controller()->isAcceleratedCompositingEnabled(); + m_pendingPluginCreationParameters->isAcceleratedCompositingEnabled = controller()->isAcceleratedCompositingEnabled(); #endif + if (!canInitializeAsynchronously()) + return initializeSynchronously(); + + // Remember that we tried to create this plug-in asynchronously in case we need to create it synchronously later. + m_waitingOnAsynchronousInitialization = true; + PluginCreationParameters creationParameters(*m_pendingPluginCreationParameters.get()); + m_connection->connection()->send(Messages::WebProcessConnection::CreatePluginAsynchronously(creationParameters), m_pluginInstanceID); + return true; +} + +bool PluginProxy::canInitializeAsynchronously() const +{ + return controller()->asynchronousPluginInitializationEnabled() && (m_connection->supportsAsynchronousPluginInitialization() || controller()->asynchronousPluginInitializationEnabledForAllPlugins()); +} + +void PluginProxy::waitForAsynchronousInitialization() +{ + ASSERT(!m_isStarted); + ASSERT(m_waitingOnAsynchronousInitialization); + + initializeSynchronously(); +} + +bool PluginProxy::initializeSynchronously() +{ + ASSERT(m_pendingPluginCreationParameters); + + m_pendingPluginCreationParameters->asynchronousCreationIncomplete = m_waitingOnAsynchronousInitialization; bool result = false; bool wantsWheelEvents = false; uint32_t remoteLayerClientID = 0; + + PluginCreationParameters parameters(*m_pendingPluginCreationParameters.get()); - if (!m_connection->connection()->sendSync(Messages::WebProcessConnection::CreatePlugin(creationParameters), Messages::WebProcessConnection::CreatePlugin::Reply(result, wantsWheelEvents, remoteLayerClientID), 0) || !result) { - m_connection->removePluginProxy(this); - return false; - } + if (!m_connection->connection()->sendSync(Messages::WebProcessConnection::CreatePlugin(parameters), Messages::WebProcessConnection::CreatePlugin::Reply(result, wantsWheelEvents, remoteLayerClientID), 0) || !result) + didFailToCreatePluginInternal(); + else + didCreatePluginInternal(wantsWheelEvents, remoteLayerClientID); + + return result; +} +void PluginProxy::didCreatePlugin(bool wantsWheelEvents, uint32_t remoteLayerClientID) +{ + // We might have tried to create the plug-in sychronously while waiting on the asynchronous reply, + // in which case we should ignore this message. + if (!m_waitingOnAsynchronousInitialization) + return; + + didCreatePluginInternal(wantsWheelEvents, remoteLayerClientID); +} + +void PluginProxy::didFailToCreatePlugin() +{ + // We might have tried to create the plug-in sychronously while waiting on the asynchronous reply, + // in which case we should ignore this message. + if (!m_waitingOnAsynchronousInitialization) + return; + + didFailToCreatePluginInternal(); +} + +void PluginProxy::didCreatePluginInternal(bool wantsWheelEvents, uint32_t remoteLayerClientID) +{ m_wantsWheelEvents = wantsWheelEvents; m_remoteLayerClientID = remoteLayerClientID; m_isStarted = true; + controller()->didInitializePlugin(); - return true; + // Whether synchronously or asynchronously, this plug-in was created and we shouldn't need to remember + // anything about how. + m_pendingPluginCreationParameters.clear(); + m_waitingOnAsynchronousInitialization = false; } -void PluginProxy::destroy() +void PluginProxy::didFailToCreatePluginInternal() { - ASSERT(m_isStarted); + // Calling out to the connection and the controller could potentially cause the plug-in proxy to go away, so protect it here. + RefPtr<PluginProxy> protect(this); + + m_connection->removePluginProxy(this); + controller()->didFailToInitializePlugin(); + + // Whether synchronously or asynchronously, this plug-in failed to create and we shouldn't need to remember + // anything about how. + m_pendingPluginCreationParameters.clear(); + m_waitingOnAsynchronousInitialization = false; +} - m_connection->connection()->sendSync(Messages::WebProcessConnection::DestroyPlugin(m_pluginInstanceID), Messages::WebProcessConnection::DestroyPlugin::Reply(), 0); +void PluginProxy::destroy() +{ + m_connection->connection()->sendSync(Messages::WebProcessConnection::DestroyPlugin(m_pluginInstanceID, m_waitingOnAsynchronousInitialization), Messages::WebProcessConnection::DestroyPlugin::Reply(), 0); m_isStarted = false; diff --git a/Source/WebKit2/WebProcess/Plugins/PluginProxy.h b/Source/WebKit2/WebProcess/Plugins/PluginProxy.h index be07caa85..c0ca116b0 100644 --- a/Source/WebKit2/WebProcess/Plugins/PluginProxy.h +++ b/Source/WebKit2/WebProcess/Plugins/PluginProxy.h @@ -49,6 +49,8 @@ class ShareableBitmap; class NPVariantData; class PluginProcessConnection; +struct PluginCreationParameters; + class PluginProxy : public Plugin { public: static PassRefPtr<PluginProxy> create(const String& pluginPath); @@ -60,11 +62,16 @@ public: void didReceivePluginProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments); void didReceiveSyncPluginProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, OwnPtr<CoreIPC::ArgumentEncoder>&); + bool isBeingAsynchronouslyInitialized() const { return m_waitingOnAsynchronousInitialization; } + private: explicit PluginProxy(const String& pluginPath); // Plugin virtual bool initialize(const Parameters&); + bool initializeSynchronously(); + + virtual void waitForAsynchronousInitialization(); virtual void destroy(); virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect); virtual PassRefPtr<ShareableBitmap> snapshot(); @@ -141,6 +148,14 @@ private: void windowedPluginGeometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, uint64_t windowID); #endif + bool canInitializeAsynchronously() const; + + void didCreatePlugin(bool wantsWheelEvents, uint32_t remoteLayerClientID); + void didFailToCreatePlugin(); + + void didCreatePluginInternal(bool wantsWheelEvents, uint32_t remoteLayerClientID); + void didFailToCreatePluginInternal(); + String m_pluginPath; RefPtr<PluginProcessConnection> m_connection; @@ -174,6 +189,9 @@ private: // The client ID for the CA layer in the plug-in process. Will be 0 if the plug-in is not a CA plug-in. uint32_t m_remoteLayerClientID; + + OwnPtr<PluginCreationParameters> m_pendingPluginCreationParameters; + bool m_waitingOnAsynchronousInitialization; #if PLATFORM(MAC) RetainPtr<CALayer> m_pluginLayer; diff --git a/Source/WebKit2/WebProcess/Plugins/PluginProxy.messages.in b/Source/WebKit2/WebProcess/Plugins/PluginProxy.messages.in index a2ef31965..453c0f1d2 100644 --- a/Source/WebKit2/WebProcess/Plugins/PluginProxy.messages.in +++ b/Source/WebKit2/WebProcess/Plugins/PluginProxy.messages.in @@ -74,6 +74,12 @@ messages -> PluginProxy { # Update geometry of windowed plugin widget WindowedPluginGeometryDidChange(WebCore::IntRect frameRect, WebCore::IntRect clipRect, uint64_t windowID) #endif + + # Tells the WebProcess that the plug-in was successfully initialized asynchronously + DidCreatePlugin(bool wantsWheelEvents, uint32_t remoteLayerClientID) -> () + + # Tells the WebProcess that the plug-in failed to initialize. + DidFailToCreatePlugin() -> () } #endif diff --git a/Source/WebKit2/WebProcess/Plugins/PluginView.cpp b/Source/WebKit2/WebProcess/Plugins/PluginView.cpp index 072a69c9c..d07f8b79d 100644 --- a/Source/WebKit2/WebProcess/Plugins/PluginView.cpp +++ b/Source/WebKit2/WebProcess/Plugins/PluginView.cpp @@ -260,6 +260,7 @@ PluginView::PluginView(PassRefPtr<HTMLPlugInElement> pluginElement, PassRefPtr<P , m_webPage(webPage(m_pluginElement.get())) , m_parameters(parameters) , m_isInitialized(false) + , m_isWaitingForSynchronousInitialization(false) , m_isWaitingUntilMediaCanStart(false) , m_isBeingDestroyed(false) , m_pendingURLRequestsTimer(RunLoop::main(), this, &PluginView::pendingURLRequestsTimerFired) @@ -285,7 +286,7 @@ PluginView::~PluginView() for (FrameLoadMap::iterator it = m_pendingFrameLoads.begin(), end = m_pendingFrameLoads.end(); it != end; ++it) it->first->setLoadListener(0); - if (m_plugin && m_isInitialized) { + if (m_plugin) { m_isBeingDestroyed = true; m_plugin->destroyPlugin(); m_isBeingDestroyed = false; @@ -487,15 +488,20 @@ void PluginView::initializePlugin() } } } - - if (!m_plugin->initialize(this, m_parameters)) { - // We failed to initialize the plug-in. - m_plugin = 0; - m_webPage->send(Messages::WebPageProxy::DidFailToInitializePlugin(m_parameters.mimeType)); - return; - } + m_plugin->initialize(this, m_parameters); + // Plug-in initialization continued in didFailToInitializePlugin() or didInitializePlugin(). +} + +void PluginView::didFailToInitializePlugin() +{ + m_plugin = 0; + m_webPage->send(Messages::WebPageProxy::DidFailToInitializePlugin(m_parameters.mimeType)); +} + +void PluginView::didInitializePlugin() +{ m_isInitialized = true; #if PLATFORM(MAC) @@ -539,6 +545,19 @@ PlatformLayer* PluginView::platformLayer() const JSObject* PluginView::scriptObject(JSGlobalObject* globalObject) { + // If we're already waiting for synchronous initialization of the plugin, + // calls to scriptObject() are from the plug-in itself and need to return 0; + if (m_isWaitingForSynchronousInitialization) + return 0; + + // If the plug-in exists but is not initialized then we're still initializing asynchronously. + // We need to wait here until initialization has either succeeded or failed. + if (m_plugin->isBeingAsynchronouslyInitialized()) { + m_isWaitingForSynchronousInitialization = true; + m_plugin->waitForAsynchronousInitialization(); + m_isWaitingForSynchronousInitialization = false; + } + // The plug-in can be null here if it failed to initialize. if (!m_isInitialized || !m_plugin) return 0; @@ -1250,6 +1269,21 @@ bool PluginView::isPrivateBrowsingEnabled() return settings->privateBrowsingEnabled(); } +bool PluginView::asynchronousPluginInitializationEnabled() const +{ + return m_webPage->asynchronousPluginInitializationEnabled(); +} + +bool PluginView::asynchronousPluginInitializationEnabledForAllPlugins() const +{ + return m_webPage->asynchronousPluginInitializationEnabledForAllPlugins(); +} + +bool PluginView::artificialPluginInitializationDelayEnabled() const +{ + return m_webPage->artificialPluginInitializationDelayEnabled(); +} + void PluginView::protectPluginFromDestruction() { if (!m_isBeingDestroyed) diff --git a/Source/WebKit2/WebProcess/Plugins/PluginView.h b/Source/WebKit2/WebProcess/Plugins/PluginView.h index f101b2f4f..a6a056ccd 100644 --- a/Source/WebKit2/WebProcess/Plugins/PluginView.h +++ b/Source/WebKit2/WebProcess/Plugins/PluginView.h @@ -80,7 +80,6 @@ private: virtual ~PluginView(); void initializePlugin(); - void destroyPlugin(); void viewGeometryDidChange(); void viewVisibilityDidChange(); @@ -164,6 +163,9 @@ private: virtual void setCookiesForURL(const String& urlString, const String& cookieString); virtual bool getAuthenticationInfo(const WebCore::ProtectionSpace&, String& username, String& password); virtual bool isPrivateBrowsingEnabled(); + virtual bool asynchronousPluginInitializationEnabled() const; + virtual bool asynchronousPluginInitializationEnabledForAllPlugins() const; + virtual bool artificialPluginInitializationDelayEnabled() const; virtual void protectPluginFromDestruction(); virtual void unprotectPluginFromDestruction(); #if PLUGIN_ARCHITECTURE(X11) @@ -171,6 +173,9 @@ private: virtual void windowedPluginGeometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, uint64_t windowID); #endif + virtual void didInitializePlugin(); + virtual void didFailToInitializePlugin(); + // WebFrame::LoadListener virtual void didFinishLoad(WebFrame*); virtual void didFailLoad(WebFrame*, bool wasCancelled); @@ -181,6 +186,7 @@ private: Plugin::Parameters m_parameters; bool m_isInitialized; + bool m_isWaitingForSynchronousInitialization; bool m_isWaitingUntilMediaCanStart; bool m_isBeingDestroyed; diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp index 3af596626..c7fc9a7b7 100644 --- a/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp +++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp @@ -638,7 +638,7 @@ void WebChromeClient::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves) #if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER) void WebChromeClient::scheduleAnimation() { -#if USE(UI_SIDE_COMPOSITING) +#if USE(COORDINATED_GRAPHICS) m_page->drawingArea()->layerTreeHost()->scheduleAnimation(); #endif } diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp index fbb824974..ceccd6af1 100644 --- a/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp +++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp @@ -943,7 +943,7 @@ void WebFrameLoaderClient::updateGlobalHistory() data.title = loader->title().string(); data.originalRequest = loader->originalRequestCopy(); - WebProcess::shared().connection()->send(Messages::WebContext::DidNavigateWithNavigationData(webPage->pageID(), data, m_frame->frameID()), 0); + WebProcess::shared().connection()->send(Messages::WebProcessProxy::DidNavigateWithNavigationData(webPage->pageID(), data, m_frame->frameID()), 0); } void WebFrameLoaderClient::updateGlobalHistoryRedirectLinks() @@ -957,13 +957,13 @@ void WebFrameLoaderClient::updateGlobalHistoryRedirectLinks() // Client redirect if (!loader->clientRedirectSourceForHistory().isNull()) { - WebProcess::shared().connection()->send(Messages::WebContext::DidPerformClientRedirect(webPage->pageID(), + WebProcess::shared().connection()->send(Messages::WebProcessProxy::DidPerformClientRedirect(webPage->pageID(), loader->clientRedirectSourceForHistory(), loader->clientRedirectDestinationForHistory(), m_frame->frameID()), 0); } // Server redirect if (!loader->serverRedirectSourceForHistory().isNull()) { - WebProcess::shared().connection()->send(Messages::WebContext::DidPerformServerRedirect(webPage->pageID(), + WebProcess::shared().connection()->send(Messages::WebProcessProxy::DidPerformServerRedirect(webPage->pageID(), loader->serverRedirectSourceForHistory(), loader->serverRedirectDestinationForHistory(), m_frame->frameID()), 0); } } @@ -1194,7 +1194,7 @@ void WebFrameLoaderClient::setTitle(const StringWithDirection& title, const KURL return; // FIXME: use direction of title. - WebProcess::shared().connection()->send(Messages::WebContext::DidUpdateHistoryTitle(webPage->pageID(), + WebProcess::shared().connection()->send(Messages::WebProcessProxy::DidUpdateHistoryTitle(webPage->pageID(), title.string(), url.string(), m_frame->frameID()), 0); } diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebRegisterProtocolHandlerClient.h b/Source/WebKit2/WebProcess/WebCoreSupport/WebRegisterProtocolHandlerClient.h index 7019747b9..63f199098 100644 --- a/Source/WebKit2/WebProcess/WebCoreSupport/WebRegisterProtocolHandlerClient.h +++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebRegisterProtocolHandlerClient.h @@ -26,6 +26,8 @@ #ifndef WebRegisterProtocolHandlerClient_h #define WebRegisterProtocolHandlerClient_h +#if ENABLE(REGISTER_PROTOCOL_HANDLER) + #include <WebCore/RegisterProtocolHandlerClient.h> #include <wtf/text/WTFString.h> @@ -36,9 +38,7 @@ public: virtual ~WebRegisterProtocolHandlerClient() { } private: -#if ENABLE(REGISTER_PROTOCOL_HANDLER) virtual void registerProtocolHandler(const String& scheme, const String& baseURL, const String& url, const String& title) OVERRIDE { } -#endif #if ENABLE(CUSTOM_SCHEME_HANDLER) virtual CustomHandlersState isProtocolHandlerRegistered(const String&, const String&, const String&) { return CustomHandlersDeclined; } @@ -48,4 +48,5 @@ private: } +#endif // ENABLE(REGISTER_PROTOCOL_HANDLER) #endif // WebRegisterProtocolHandlerClient_h diff --git a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp new file mode 100644 index 000000000..26a7ddb29 --- /dev/null +++ b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp @@ -0,0 +1,834 @@ +/* + Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if USE(COORDINATED_GRAPHICS) +#include "CoordinatedGraphicsLayer.h" + +#include "BackingStore.h" +#include "CoordinatedTile.h" +#include "FloatQuad.h" +#include "Frame.h" +#include "FrameView.h" +#include "GraphicsContext.h" +#include "GraphicsLayer.h" +#include "LayerTreeCoordinatorProxyMessages.h" +#include "Page.h" +#include "TextureMapperPlatformLayer.h" +#include "WebPage.h" +#include <wtf/CurrentTime.h> +#include <wtf/HashMap.h> +#include <wtf/text/CString.h> + +using namespace WebKit; + +namespace WebCore { + +static HashMap<WebLayerID, CoordinatedGraphicsLayer*>& layerByIDMap() +{ + static HashMap<WebLayerID, CoordinatedGraphicsLayer*> globalMap; + return globalMap; +} + +CoordinatedGraphicsLayer* CoordinatedGraphicsLayer::layerByID(WebKit::WebLayerID id) +{ + HashMap<WebLayerID, CoordinatedGraphicsLayer*>& table = layerByIDMap(); + HashMap<WebLayerID, CoordinatedGraphicsLayer*>::iterator it = table.find(id); + if (it == table.end()) + return 0; + return it->second; +} + +static WebLayerID toWebLayerID(GraphicsLayer* layer) +{ + return layer ? toCoordinatedGraphicsLayer(layer)->id() : 0; +} + +void CoordinatedGraphicsLayer::didChangeLayerState() +{ + m_shouldSyncLayerState = true; + if (client()) + client()->notifySyncRequired(this); +} + +void CoordinatedGraphicsLayer::didChangeAnimatedProperties() +{ + m_shouldSyncAnimatedProperties = true; + if (client()) + client()->notifySyncRequired(this); +} + +void CoordinatedGraphicsLayer::didChangeChildren() +{ + m_shouldSyncChildren = true; + if (client()) + client()->notifySyncRequired(this); +} + +#if ENABLE(CSS_FILTERS) +void CoordinatedGraphicsLayer::didChangeFilters() +{ + m_shouldSyncFilters = true; + if (client()) + client()->notifySyncRequired(this); +} +#endif + +void CoordinatedGraphicsLayer::setShouldUpdateVisibleRect() +{ + if (!transform().isAffine()) + return; + + m_shouldUpdateVisibleRect = true; + for (size_t i = 0; i < children().size(); ++i) + toCoordinatedGraphicsLayer(children()[i])->setShouldUpdateVisibleRect(); + if (replicaLayer()) + toCoordinatedGraphicsLayer(replicaLayer())->setShouldUpdateVisibleRect(); +} + +void CoordinatedGraphicsLayer::didChangeGeometry() +{ + didChangeLayerState(); + setShouldUpdateVisibleRect(); +} + +CoordinatedGraphicsLayer::CoordinatedGraphicsLayer(GraphicsLayerClient* client) + : GraphicsLayer(client) + , m_maskTarget(0) + , m_inUpdateMode(false) + , m_shouldUpdateVisibleRect(true) + , m_shouldSyncLayerState(true) + , m_shouldSyncChildren(true) + , m_shouldSyncFilters(true) + , m_shouldSyncAnimatedProperties(true) + , m_fixedToViewport(false) + , m_canvasNeedsDisplay(false) + , m_CoordinatedGraphicsLayerClient(0) + , m_contentsScale(1) + , m_canvasPlatformLayer(0) + , m_animationStartedTimer(this, &CoordinatedGraphicsLayer::animationStartedTimerFired) +{ + static WebLayerID nextLayerID = 1; + m_id = nextLayerID++; + layerByIDMap().add(id(), this); +} + +CoordinatedGraphicsLayer::~CoordinatedGraphicsLayer() +{ + layerByIDMap().remove(id()); + + if (m_CoordinatedGraphicsLayerClient) { + purgeBackingStores(); + m_CoordinatedGraphicsLayerClient->detachLayer(this); + } + willBeDestroyed(); +} + +void CoordinatedGraphicsLayer::willBeDestroyed() +{ + GraphicsLayer::willBeDestroyed(); +} + +bool CoordinatedGraphicsLayer::setChildren(const Vector<GraphicsLayer*>& children) +{ + bool ok = GraphicsLayer::setChildren(children); + if (!ok) + return false; + for (int i = 0; i < children.size(); ++i) { + CoordinatedGraphicsLayer* child = toCoordinatedGraphicsLayer(children[i]); + child->setCoordinatedGraphicsLayerClient(m_CoordinatedGraphicsLayerClient); + child->didChangeLayerState(); + } + didChangeChildren(); + return true; +} + +void CoordinatedGraphicsLayer::addChild(GraphicsLayer* layer) +{ + GraphicsLayer::addChild(layer); + toCoordinatedGraphicsLayer(layer)->setCoordinatedGraphicsLayerClient(m_CoordinatedGraphicsLayerClient); + toCoordinatedGraphicsLayer(layer)->didChangeLayerState(); + didChangeChildren(); +} + +void CoordinatedGraphicsLayer::addChildAtIndex(GraphicsLayer* layer, int index) +{ + GraphicsLayer::addChildAtIndex(layer, index); + toCoordinatedGraphicsLayer(layer)->setCoordinatedGraphicsLayerClient(m_CoordinatedGraphicsLayerClient); + toCoordinatedGraphicsLayer(layer)->didChangeLayerState(); + didChangeChildren(); +} + +void CoordinatedGraphicsLayer::addChildAbove(GraphicsLayer* layer, GraphicsLayer* sibling) +{ + GraphicsLayer::addChildAbove(layer, sibling); + toCoordinatedGraphicsLayer(layer)->setCoordinatedGraphicsLayerClient(m_CoordinatedGraphicsLayerClient); + toCoordinatedGraphicsLayer(layer)->didChangeLayerState(); + didChangeChildren(); +} + +void CoordinatedGraphicsLayer::addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling) +{ + GraphicsLayer::addChildBelow(layer, sibling); + toCoordinatedGraphicsLayer(layer)->setCoordinatedGraphicsLayerClient(m_CoordinatedGraphicsLayerClient); + toCoordinatedGraphicsLayer(layer)->didChangeLayerState(); + didChangeChildren(); +} + +bool CoordinatedGraphicsLayer::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild) +{ + bool ok = GraphicsLayer::replaceChild(oldChild, newChild); + if (!ok) + return false; + didChangeChildren(); + toCoordinatedGraphicsLayer(oldChild)->didChangeLayerState(); + toCoordinatedGraphicsLayer(newChild)->setCoordinatedGraphicsLayerClient(m_CoordinatedGraphicsLayerClient); + toCoordinatedGraphicsLayer(newChild)->didChangeLayerState(); + return true; +} + +void CoordinatedGraphicsLayer::removeFromParent() +{ + if (CoordinatedGraphicsLayer* parentLayer = toCoordinatedGraphicsLayer(parent())) + parentLayer->didChangeChildren(); + GraphicsLayer::removeFromParent(); + + didChangeLayerState(); +} + +void CoordinatedGraphicsLayer::setPosition(const FloatPoint& p) +{ + if (position() == p) + return; + + GraphicsLayer::setPosition(p); + didChangeGeometry(); +} + +void CoordinatedGraphicsLayer::setAnchorPoint(const FloatPoint3D& p) +{ + if (anchorPoint() == p) + return; + + GraphicsLayer::setAnchorPoint(p); + didChangeGeometry(); +} + +void CoordinatedGraphicsLayer::setSize(const FloatSize& size) +{ + if (this->size() == size) + return; + + GraphicsLayer::setSize(size); + setNeedsDisplay(); + if (maskLayer()) + maskLayer()->setSize(size); + didChangeGeometry(); +} + +void CoordinatedGraphicsLayer::setTransform(const TransformationMatrix& t) +{ + if (transform() == t) + return; + + GraphicsLayer::setTransform(t); + didChangeGeometry(); +} + +void CoordinatedGraphicsLayer::setChildrenTransform(const TransformationMatrix& t) +{ + if (childrenTransform() == t) + return; + + GraphicsLayer::setChildrenTransform(t); + didChangeGeometry(); +} + +void CoordinatedGraphicsLayer::setPreserves3D(bool b) +{ + if (preserves3D() == b) + return; + + GraphicsLayer::setPreserves3D(b); + didChangeGeometry(); +} + +void CoordinatedGraphicsLayer::setMasksToBounds(bool b) +{ + if (masksToBounds() == b) + return; + GraphicsLayer::setMasksToBounds(b); + didChangeGeometry(); +} + +void CoordinatedGraphicsLayer::setDrawsContent(bool b) +{ + if (drawsContent() == b) + return; + GraphicsLayer::setDrawsContent(b); + + didChangeLayerState(); +} + +void CoordinatedGraphicsLayer::setContentsVisible(bool b) +{ + if (contentsAreVisible() == b) + return; + GraphicsLayer::setContentsVisible(b); + + didChangeLayerState(); +} + +void CoordinatedGraphicsLayer::setContentsOpaque(bool b) +{ + if (contentsOpaque() == b) + return; + if (m_mainBackingStore) + m_mainBackingStore->setSupportsAlpha(!b); + GraphicsLayer::setContentsOpaque(b); + didChangeLayerState(); +} + +void CoordinatedGraphicsLayer::setBackfaceVisibility(bool b) +{ + if (backfaceVisibility() == b) + return; + + GraphicsLayer::setBackfaceVisibility(b); + didChangeLayerState(); +} + +void CoordinatedGraphicsLayer::setOpacity(float opacity) +{ + if (this->opacity() == opacity) + return; + + GraphicsLayer::setOpacity(opacity); + didChangeLayerState(); +} + +void CoordinatedGraphicsLayer::setContentsRect(const IntRect& r) +{ + if (contentsRect() == r) + return; + + GraphicsLayer::setContentsRect(r); + didChangeLayerState(); +} + +void CoordinatedGraphicsLayer::setContentsNeedsDisplay() +{ + RefPtr<Image> image = m_image; + setContentsToImage(0); + setContentsToImage(image.get()); + m_canvasNeedsDisplay = true; + if (client()) + client()->notifySyncRequired(this); +} + +void CoordinatedGraphicsLayer::setContentsToCanvas(PlatformLayer* platformLayer) +{ + m_canvasPlatformLayer = platformLayer; + m_canvasNeedsDisplay = true; + if (client()) + client()->notifySyncRequired(this); +} + +#if ENABLE(CSS_FILTERS) +bool CoordinatedGraphicsLayer::setFilters(const FilterOperations& newFilters) +{ + if (filters() == newFilters) + return true; + didChangeFilters(); + return GraphicsLayer::setFilters(newFilters); +} +#endif + + +void CoordinatedGraphicsLayer::setContentsToImage(Image* image) +{ + if (image == m_image) + return; + int64_t newID = 0; + if (m_CoordinatedGraphicsLayerClient) { + // We adopt first, in case this is the same frame - that way we avoid destroying and recreating the image. + newID = m_CoordinatedGraphicsLayerClient->adoptImageBackingStore(image); + m_CoordinatedGraphicsLayerClient->releaseImageBackingStore(m_layerInfo.imageBackingStoreID); + didChangeLayerState(); + if (m_layerInfo.imageBackingStoreID && newID == m_layerInfo.imageBackingStoreID) + return; + } else { + // If m_CoordinatedGraphicsLayerClient is not set yet there should be no backing store ID. + ASSERT(!m_layerInfo.imageBackingStoreID); + didChangeLayerState(); + } + + m_layerInfo.imageBackingStoreID = newID; + m_image = image; + GraphicsLayer::setContentsToImage(image); +} + +void CoordinatedGraphicsLayer::setMaskLayer(GraphicsLayer* layer) +{ + if (layer == maskLayer()) + return; + + GraphicsLayer::setMaskLayer(layer); + + if (!layer) + return; + + layer->setSize(size()); + CoordinatedGraphicsLayer* CoordinatedGraphicsLayer = toCoordinatedGraphicsLayer(layer); + CoordinatedGraphicsLayer->setCoordinatedGraphicsLayerClient(m_CoordinatedGraphicsLayerClient); + CoordinatedGraphicsLayer->setMaskTarget(this); + CoordinatedGraphicsLayer->didChangeLayerState(); + didChangeLayerState(); + +} + +void CoordinatedGraphicsLayer::setReplicatedByLayer(GraphicsLayer* layer) +{ + if (layer == replicaLayer()) + return; + + if (layer) + toCoordinatedGraphicsLayer(layer)->setCoordinatedGraphicsLayerClient(m_CoordinatedGraphicsLayerClient); + + GraphicsLayer::setReplicatedByLayer(layer); + didChangeLayerState(); +} + +void CoordinatedGraphicsLayer::setNeedsDisplay() +{ + setNeedsDisplayInRect(IntRect(IntPoint::zero(), IntSize(size().width(), size().height()))); +} + +void CoordinatedGraphicsLayer::setNeedsDisplayInRect(const FloatRect& rect) +{ + if (m_mainBackingStore) + m_mainBackingStore->invalidate(IntRect(rect)); + didChangeLayerState(); +} + +WebLayerID CoordinatedGraphicsLayer::id() const +{ + return m_id; +} + +void CoordinatedGraphicsLayer::syncCompositingState(const FloatRect& rect) +{ + if (CoordinatedGraphicsLayer* mask = toCoordinatedGraphicsLayer(maskLayer())) + mask->syncCompositingStateForThisLayerOnly(); + + if (CoordinatedGraphicsLayer* replica = toCoordinatedGraphicsLayer(replicaLayer())) + replica->syncCompositingStateForThisLayerOnly(); + + m_CoordinatedGraphicsLayerClient->syncFixedLayers(); + + syncCompositingStateForThisLayerOnly(); + + for (size_t i = 0; i < children().size(); ++i) + children()[i]->syncCompositingState(rect); +} + +CoordinatedGraphicsLayer* toCoordinatedGraphicsLayer(GraphicsLayer* layer) +{ + return static_cast<CoordinatedGraphicsLayer*>(layer); +} + +void CoordinatedGraphicsLayer::syncChildren() +{ + if (!m_shouldSyncChildren) + return; + m_shouldSyncChildren = false; + Vector<WebLayerID> childIDs; + for (size_t i = 0; i < children().size(); ++i) + childIDs.append(toWebLayerID(children()[i])); + + m_CoordinatedGraphicsLayerClient->syncLayerChildren(m_id, childIDs); +} + +#if ENABLE(CSS_FILTERS) +void CoordinatedGraphicsLayer::syncFilters() +{ + if (!m_shouldSyncFilters) + return; + m_shouldSyncFilters = false; + m_CoordinatedGraphicsLayerClient->syncLayerFilters(m_id, filters()); +} +#endif + +void CoordinatedGraphicsLayer::syncLayerState() +{ + if (!m_shouldSyncLayerState) + return; + m_shouldSyncLayerState = false; + m_layerInfo.fixedToViewport = fixedToViewport(); + + m_layerInfo.anchorPoint = anchorPoint(); + m_layerInfo.backfaceVisible = backfaceVisibility(); + m_layerInfo.childrenTransform = childrenTransform(); + m_layerInfo.contentsOpaque = contentsOpaque(); + m_layerInfo.contentsRect = contentsRect(); + m_layerInfo.drawsContent = drawsContent(); + m_layerInfo.contentsVisible = contentsAreVisible(); + m_layerInfo.mask = toWebLayerID(maskLayer()); + m_layerInfo.masksToBounds = masksToBounds(); + m_layerInfo.opacity = opacity(); + m_layerInfo.parent = toWebLayerID(parent()); + m_layerInfo.pos = position(); + m_layerInfo.preserves3D = preserves3D(); + m_layerInfo.replica = toWebLayerID(replicaLayer()); + m_layerInfo.size = size(); + m_layerInfo.transform = transform(); + if (!m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform)) + m_effectiveTransform = transform(); + if (!m_animations.hasActiveAnimationsOfType(AnimatedPropertyOpacity)) + m_effectiveOpacity = opacity(); + m_CoordinatedGraphicsLayerClient->syncLayerState(m_id, m_layerInfo); +} + +void CoordinatedGraphicsLayer::syncAnimatedProperties() +{ + m_animations.apply(this); + if (!m_shouldSyncAnimatedProperties) + return; + + m_shouldSyncAnimatedProperties = true; + if (m_effectiveOpacity != opacity()) + m_CoordinatedGraphicsLayerClient->setLayerAnimatedOpacity(id(), m_effectiveOpacity); + if (m_effectiveTransform != transform()) + m_CoordinatedGraphicsLayerClient->setLayerAnimatedTransform(id(), m_effectiveTransform); +} + + +void CoordinatedGraphicsLayer::syncCanvas() +{ + if (!m_canvasNeedsDisplay) + return; + + if (!m_canvasPlatformLayer) + return; + +#if USE(GRAPHICS_SURFACE) + uint32_t graphicsSurfaceToken = m_canvasPlatformLayer->copyToGraphicsSurface(); + m_CoordinatedGraphicsLayerClient->syncCanvas(m_id, IntSize(size().width(), size().height()), graphicsSurfaceToken); +#endif + m_canvasNeedsDisplay = false; +} + +void CoordinatedGraphicsLayer::ensureImageBackingStore() +{ + if (!m_image) + return; + if (!m_layerInfo.imageBackingStoreID) + m_layerInfo.imageBackingStoreID = m_CoordinatedGraphicsLayerClient->adoptImageBackingStore(m_image.get()); +} + +void CoordinatedGraphicsLayer::syncCompositingStateForThisLayerOnly() +{ + // The remote image might have been released by purgeBackingStores. + ensureImageBackingStore(); + syncLayerState(); + syncAnimatedProperties(); + computeTransformedVisibleRect(); + syncChildren(); +#if ENABLE(CSS_FILTERS) + syncFilters(); +#endif + updateContentBuffers(); + syncCanvas(); +} + +void CoordinatedGraphicsLayer::tiledBackingStorePaintBegin() +{ +} + +void CoordinatedGraphicsLayer::setRootLayer(bool isRoot) +{ + m_layerInfo.isRootLayer = isRoot; + didChangeLayerState(); +} + +void CoordinatedGraphicsLayer::setVisibleContentRectTrajectoryVector(const FloatPoint& trajectoryVector) +{ + if (m_mainBackingStore) + m_mainBackingStore->coverWithTilesIfNeeded(trajectoryVector); +} + +void CoordinatedGraphicsLayer::setContentsScale(float scale) +{ + m_contentsScale = scale; + adjustContentsScale(); +} + +float CoordinatedGraphicsLayer::effectiveContentsScale() +{ + return shouldUseTiledBackingStore() ? m_contentsScale : 1; +} + +void CoordinatedGraphicsLayer::adjustContentsScale() +{ + if (!drawsContent()) + return; + + if (!m_mainBackingStore || m_mainBackingStore->contentsScale() == effectiveContentsScale()) + return; + + // Between creating the new backing store and painting the content, + // we do not want to drop the previous one as that might result in + // briefly seeing flickering as the old tiles may be dropped before + // something replaces them. + m_previousBackingStore = m_mainBackingStore.release(); + + // No reason to save the previous backing store for non-visible areas. + m_previousBackingStore->removeAllNonVisibleTiles(); + + createBackingStore(); +} + +void CoordinatedGraphicsLayer::createBackingStore() +{ + m_mainBackingStore = adoptPtr(new TiledBackingStore(this, CoordinatedTileBackend::create(this))); + m_mainBackingStore->setSupportsAlpha(!contentsOpaque()); + m_mainBackingStore->setContentsScale(effectiveContentsScale()); +} + +void CoordinatedGraphicsLayer::tiledBackingStorePaint(GraphicsContext* context, const IntRect& rect) +{ + if (rect.isEmpty()) + return; + paintGraphicsLayerContents(*context, rect); +} + +void CoordinatedGraphicsLayer::tiledBackingStorePaintEnd(const Vector<IntRect>& updatedRects) +{ +} + +bool CoordinatedGraphicsLayer::tiledBackingStoreUpdatesAllowed() const +{ + if (!m_inUpdateMode) + return false; + return m_CoordinatedGraphicsLayerClient->layerTreeTileUpdatesAllowed(); +} + +IntRect CoordinatedGraphicsLayer::tiledBackingStoreContentsRect() +{ + return IntRect(0, 0, size().width(), size().height()); +} + +bool CoordinatedGraphicsLayer::shouldUseTiledBackingStore() +{ + return !selfOrAncestorHaveNonAffineTransforms(); +} + +IntRect CoordinatedGraphicsLayer::tiledBackingStoreVisibleRect() +{ + if (!shouldUseTiledBackingStore()) + return tiledBackingStoreContentsRect(); + + // Non-invertible layers are not visible. + if (!m_layerTransform.combined().isInvertible()) + return IntRect(); + + // Return a projection of the visible rect (surface coordinates) onto the layer's plane (layer coordinates). + // The resulting quad might be squewed and the visible rect is the bounding box of this quad, + // so it might spread further than the real visible area (and then even more amplified by the cover rect multiplier). + return enclosingIntRect(m_layerTransform.combined().inverse().clampedBoundsOfProjectedQuad(FloatQuad(FloatRect(m_CoordinatedGraphicsLayerClient->visibleContentsRect())))); +} + +Color CoordinatedGraphicsLayer::tiledBackingStoreBackgroundColor() const +{ + return contentsOpaque() ? Color::white : Color::transparent; +} + +PassOwnPtr<WebCore::GraphicsContext> CoordinatedGraphicsLayer::beginContentUpdate(const WebCore::IntSize& size, ShareableSurface::Handle& handle, WebCore::IntPoint& offset) +{ + return m_CoordinatedGraphicsLayerClient->beginContentUpdate(size, contentsOpaque() ? 0 : ShareableBitmap::SupportsAlpha, handle, offset); +} + +void CoordinatedGraphicsLayer::createTile(int tileID, const SurfaceUpdateInfo& updateInfo, const IntRect& targetRect) +{ + m_CoordinatedGraphicsLayerClient->createTile(id(), tileID, updateInfo, targetRect); +} + +void CoordinatedGraphicsLayer::updateTile(int tileID, const SurfaceUpdateInfo& updateInfo, const IntRect& targetRect) +{ + m_CoordinatedGraphicsLayerClient->updateTile(id(), tileID, updateInfo, targetRect); +} + +void CoordinatedGraphicsLayer::removeTile(int tileID) +{ + m_CoordinatedGraphicsLayerClient->removeTile(id(), tileID); +} + +void CoordinatedGraphicsLayer::updateContentBuffers() +{ + if (!drawsContent()) { + m_mainBackingStore.clear(); + m_previousBackingStore.clear(); + return; + } + + m_inUpdateMode = true; + // This is the only place we (re)create the main tiled backing store, once we + // have a remote client and we are ready to send our data to the UI process. + if (!m_mainBackingStore) + createBackingStore(); + m_mainBackingStore->updateTileBuffers(); + m_inUpdateMode = false; + + // The previous backing store is kept around to avoid flickering between + // removing the existing tiles and painting the new ones. The first time + // the visibleRect is full painted we remove the previous backing store. + if (m_mainBackingStore->visibleAreaIsCovered()) + m_previousBackingStore.clear(); +} + +void CoordinatedGraphicsLayer::purgeBackingStores() +{ + m_mainBackingStore.clear(); + m_previousBackingStore.clear(); + + if (m_layerInfo.imageBackingStoreID) { + m_CoordinatedGraphicsLayerClient->releaseImageBackingStore(m_layerInfo.imageBackingStoreID); + m_layerInfo.imageBackingStoreID = 0; + } + + didChangeLayerState(); + didChangeChildren(); +} + +void CoordinatedGraphicsLayer::setCoordinatedGraphicsLayerClient(WebKit::CoordinatedGraphicsLayerClient* client) +{ + if (m_CoordinatedGraphicsLayerClient == client) + return; + + if (CoordinatedGraphicsLayer* replica = toCoordinatedGraphicsLayer(replicaLayer())) + replica->setCoordinatedGraphicsLayerClient(client); + if (CoordinatedGraphicsLayer* mask = toCoordinatedGraphicsLayer(maskLayer())) + mask->setCoordinatedGraphicsLayerClient(client); + for (size_t i = 0; i < children().size(); ++i) { + CoordinatedGraphicsLayer* layer = toCoordinatedGraphicsLayer(this->children()[i]); + layer->setCoordinatedGraphicsLayerClient(client); + } + + // We have to release resources on the UI process here if the remote client has changed or is removed. + if (m_CoordinatedGraphicsLayerClient) { + purgeBackingStores(); + m_CoordinatedGraphicsLayerClient->detachLayer(this); + } + m_CoordinatedGraphicsLayerClient = client; + if (client) + client->attachLayer(this); +} + +void CoordinatedGraphicsLayer::adjustVisibleRect() +{ + if (m_mainBackingStore) + m_mainBackingStore->coverWithTilesIfNeeded(); +} + +void CoordinatedGraphicsLayer::computeTransformedVisibleRect() +{ + if (!m_shouldUpdateVisibleRect) + return; + m_shouldUpdateVisibleRect = false; + m_layerTransform.setLocalTransform(m_effectiveTransform); + m_layerTransform.setPosition(position()); + m_layerTransform.setAnchorPoint(anchorPoint()); + m_layerTransform.setSize(size()); + m_layerTransform.setFlattening(!preserves3D()); + m_layerTransform.setChildrenTransform(childrenTransform()); + m_layerTransform.combineTransforms(parent() ? toCoordinatedGraphicsLayer(parent())->m_layerTransform.combinedForChildren() : TransformationMatrix()); + + // The combined transform will be used in tiledBackingStoreVisibleRect. + adjustVisibleRect(); + adjustContentsScale(); +} + +static PassOwnPtr<GraphicsLayer> createCoordinatedGraphicsLayer(GraphicsLayerClient* client) +{ + return adoptPtr(new CoordinatedGraphicsLayer(client)); +} + +void CoordinatedGraphicsLayer::initFactory() +{ + GraphicsLayer::setGraphicsLayerFactory(createCoordinatedGraphicsLayer); +} + +bool CoordinatedGraphicsLayer::selfOrAncestorHaveNonAffineTransforms() +{ + if (!m_layerTransform.combined().isAffine()) + return true; + + return false; +} + +bool CoordinatedGraphicsLayer::addAnimation(const KeyframeValueList& valueList, const IntSize& boxSize, const Animation* anim, const String& keyframesName, double timeOffset) +{ + ASSERT(!keyframesName.isEmpty()); + + if (!anim || anim->isEmptyOrZeroDuration() || valueList.size() < 2 || (valueList.property() != AnimatedPropertyWebkitTransform && valueList.property() != AnimatedPropertyOpacity)) + return false; + + bool listsMatch = false; + bool ignoredHasBigRotation; + + if (valueList.property() == AnimatedPropertyWebkitTransform) + listsMatch = validateTransformOperations(valueList, ignoredHasBigRotation) >= 0; + + m_animations.add(GraphicsLayerAnimation(keyframesName, valueList, boxSize, anim, timeOffset, listsMatch)); + m_animationStartedTimer.startOneShot(0); + didChangeLayerState(); + return true; +} + +void CoordinatedGraphicsLayer::pauseAnimation(const String& animationName, double timeOffset) +{ + m_animations.pause(animationName, timeOffset); +} + +void CoordinatedGraphicsLayer::removeAnimation(const String& animationName) +{ + m_animations.remove(animationName); +} + +void CoordinatedGraphicsLayer::animationStartedTimerFired(Timer<CoordinatedGraphicsLayer>*) +{ + client()->notifyAnimationStarted(this, /* DOM time */ WTF::currentTime()); +} + +void CoordinatedGraphicsLayer::setAnimatedTransform(const TransformationMatrix& transform) +{ + m_effectiveTransform = transform; + didChangeAnimatedProperties(); + m_shouldUpdateVisibleRect = true; +} + +void CoordinatedGraphicsLayer::setAnimatedOpacity(float opacity) +{ + m_effectiveOpacity = opacity; + didChangeAnimatedProperties(); +} + +} +#endif diff --git a/Source/WebKit2/WebProcess/WebPage/LayerTreeCoordinator/WebGraphicsLayer.h b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.h index 9ce8ecdad..25ccd9454 100644 --- a/Source/WebKit2/WebProcess/WebPage/LayerTreeCoordinator/WebGraphicsLayer.h +++ b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.h @@ -18,18 +18,19 @@ */ -#ifndef WebGraphicsLayer_h -#define WebGraphicsLayer_h +#ifndef CoordinatedGraphicsLayer_h +#define CoordinatedGraphicsLayer_h +#include "CoordinatedTile.h" #include "FloatPoint3D.h" #include "GraphicsLayer.h" +#include "GraphicsLayerAnimation.h" #include "GraphicsLayerTransform.h" #include "Image.h" #include "IntSize.h" #include "ShareableBitmap.h" #include "TiledBackingStore.h" #include "TiledBackingStoreClient.h" -#include "TiledBackingStoreRemoteTile.h" #include "TransformationMatrix.h" #include "UpdateInfo.h" #include "WebLayerTreeInfo.h" @@ -37,16 +38,16 @@ #include <WebCore/RunLoop.h> #include <wtf/text/StringHash.h> -#if USE(UI_SIDE_COMPOSITING) +#if USE(COORDINATED_GRAPHICS) namespace WebCore { -class WebGraphicsLayer; +class CoordinatedGraphicsLayer; } namespace WebKit { -class WebGraphicsLayerClient { +class CoordinatedGraphicsLayerClient { public: - // TiledBackingStoreRemoteTileClient + // CoordinatedTileClient virtual void createTile(WebLayerID, int tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&) = 0; virtual void updateTile(WebLayerID, int tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&) = 0; virtual void removeTile(WebLayerID, int tileID) = 0; @@ -63,8 +64,12 @@ public: #if PLATFORM(QT) virtual void syncCanvas(WebLayerID, const WebCore::IntSize& canvasSize, uint32_t graphicsSurfaceToken) = 0; #endif - virtual void attachLayer(WebCore::WebGraphicsLayer*) = 0; - virtual void detachLayer(WebCore::WebGraphicsLayer*) = 0; + + virtual void setLayerAnimatedOpacity(WebLayerID, float) = 0; + virtual void setLayerAnimatedTransform(WebLayerID, const WebCore::TransformationMatrix&) = 0; + + virtual void attachLayer(WebCore::CoordinatedGraphicsLayer*) = 0; + virtual void detachLayer(WebCore::CoordinatedGraphicsLayer*) = 0; virtual void syncFixedLayers() = 0; virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, ShareableBitmap::Flags, ShareableSurface::Handle&, WebCore::IntPoint&) = 0; }; @@ -72,12 +77,13 @@ public: namespace WebCore { -class WebGraphicsLayer : public WebCore::GraphicsLayer +class CoordinatedGraphicsLayer : public WebCore::GraphicsLayer , public TiledBackingStoreClient - , public WebKit::TiledBackingStoreRemoteTileClient { + , public WebKit::CoordinatedTileClient + , public GraphicsLayerAnimation::Client { public: - WebGraphicsLayer(GraphicsLayerClient*); - virtual ~WebGraphicsLayer(); + CoordinatedGraphicsLayer(GraphicsLayerClient*); + virtual ~CoordinatedGraphicsLayer(); // Reimplementations from GraphicsLayer.h. bool setChildren(const Vector<GraphicsLayer*>&); @@ -95,6 +101,7 @@ public: void setPreserves3D(bool); void setMasksToBounds(bool); void setDrawsContent(bool); + void setContentsVisible(bool); void setContentsOpaque(bool); void setBackfaceVisibility(bool); void setOpacity(float); @@ -117,7 +124,7 @@ public: void setRootLayer(bool); WebKit::WebLayerID id() const; - static WebGraphicsLayer* layerByID(WebKit::WebLayerID); + static CoordinatedGraphicsLayer* layerByID(WebKit::WebLayerID); void didSynchronize(); Image* image() { return m_image.get(); } @@ -138,13 +145,13 @@ public: virtual IntRect tiledBackingStoreVisibleRect(); virtual Color tiledBackingStoreBackgroundColor() const; - // TiledBackingStoreRemoteTileClient + // CoordinatedTileClient virtual void createTile(int tileID, const WebKit::SurfaceUpdateInfo&, const WebCore::IntRect&); virtual void updateTile(int tileID, const WebKit::SurfaceUpdateInfo&, const WebCore::IntRect&); virtual void removeTile(int tileID); virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, WebKit::ShareableSurface::Handle&, WebCore::IntPoint&); - void setWebGraphicsLayerClient(WebKit::WebGraphicsLayerClient*); + void setCoordinatedGraphicsLayerClient(WebKit::CoordinatedGraphicsLayerClient*); void syncChildren(); void syncLayerState(); #if ENABLE(CSS_FILTERS) @@ -158,6 +165,14 @@ public: void updateContentBuffers(); void purgeBackingStores(); + // GraphicsLayerAnimation::Client + virtual void setAnimatedTransform(const TransformationMatrix&); + virtual void setAnimatedOpacity(float); + + virtual bool addAnimation(const KeyframeValueList&, const IntSize&, const Animation*, const String&, double); + virtual void pauseAnimation(const String&, double); + virtual void removeAnimation(const String&); + private: virtual void willBeDestroyed(); WebKit::WebLayerID m_id; @@ -171,10 +186,12 @@ private: bool m_shouldSyncLayerState: 1; bool m_shouldSyncChildren: 1; bool m_shouldSyncFilters: 1; + bool m_shouldSyncAnimatedProperties: 1; bool m_fixedToViewport : 1; bool m_canvasNeedsDisplay : 1; void notifyChange(); + void didChangeAnimatedProperties(); void didChangeGeometry(); void didChangeLayerState(); void didChangeChildren(); @@ -182,6 +199,9 @@ private: void didChangeFilters(); #endif + float m_effectiveOpacity; + TransformationMatrix m_effectiveTransform; + void createBackingStore(); bool selfOrAncestorHaveNonAffineTransforms(); @@ -189,19 +209,24 @@ private: void adjustContentsScale(); void computeTransformedVisibleRect(); void syncLayerParameters(); + void syncAnimatedProperties(); void setShouldUpdateVisibleRect(); float effectiveContentsScale(); - WebKit::WebGraphicsLayerClient* m_webGraphicsLayerClient; + void animationStartedTimerFired(WebCore::Timer<CoordinatedGraphicsLayer>*); + + WebKit::CoordinatedGraphicsLayerClient* m_CoordinatedGraphicsLayerClient; OwnPtr<WebCore::TiledBackingStore> m_mainBackingStore; OwnPtr<WebCore::TiledBackingStore> m_previousBackingStore; float m_contentsScale; PlatformLayer* m_canvasPlatformLayer; + Timer<CoordinatedGraphicsLayer> m_animationStartedTimer; + GraphicsLayerAnimations m_animations; }; -WebGraphicsLayer* toWebGraphicsLayer(GraphicsLayer*); +CoordinatedGraphicsLayer* toCoordinatedGraphicsLayer(GraphicsLayer*); } #endif -#endif // WebGraphicsLayer_H +#endif // CoordinatedGraphicsLayer_H diff --git a/Source/WebKit2/WebProcess/WebPage/TiledBackingStoreRemoteTile.cpp b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedTile.cpp index 2125600b1..4a6244e2d 100644 --- a/Source/WebKit2/WebProcess/WebPage/TiledBackingStoreRemoteTile.cpp +++ b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedTile.cpp @@ -24,7 +24,7 @@ */ #include "config.h" -#include "TiledBackingStoreRemoteTile.h" +#include "CoordinatedTile.h" #if USE(TILED_BACKING_STORE) @@ -37,7 +37,7 @@ using namespace WebCore; namespace WebKit { -TiledBackingStoreRemoteTile::TiledBackingStoreRemoteTile(TiledBackingStoreRemoteTileClient* client, TiledBackingStore* tiledBackingStore, const Coordinate& tileCoordinate) +CoordinatedTile::CoordinatedTile(CoordinatedTileClient* client, TiledBackingStore* tiledBackingStore, const Coordinate& tileCoordinate) : m_client(client) , m_tiledBackingStore(tiledBackingStore) , m_coordinate(tileCoordinate) @@ -47,18 +47,18 @@ TiledBackingStoreRemoteTile::TiledBackingStoreRemoteTile(TiledBackingStoreRemote { } -TiledBackingStoreRemoteTile::~TiledBackingStoreRemoteTile() +CoordinatedTile::~CoordinatedTile() { if (m_ID) m_client->removeTile(m_ID); } -bool TiledBackingStoreRemoteTile::isDirty() const +bool CoordinatedTile::isDirty() const { return !m_dirtyRect.isEmpty(); } -void TiledBackingStoreRemoteTile::invalidate(const IntRect& dirtyRect) +void CoordinatedTile::invalidate(const IntRect& dirtyRect) { IntRect tileDirtyRect = intersection(dirtyRect, m_rect); if (tileDirtyRect.isEmpty()) @@ -67,7 +67,7 @@ void TiledBackingStoreRemoteTile::invalidate(const IntRect& dirtyRect) m_dirtyRect.unite(tileDirtyRect); } -Vector<IntRect> TiledBackingStoreRemoteTile::updateBackBuffer() +Vector<IntRect> CoordinatedTile::updateBackBuffer() { if (!isDirty()) return Vector<IntRect>(); @@ -96,38 +96,38 @@ Vector<IntRect> TiledBackingStoreRemoteTile::updateBackBuffer() return Vector<IntRect>(); } -void TiledBackingStoreRemoteTile::swapBackBufferToFront() +void CoordinatedTile::swapBackBufferToFront() { // Handled by tiledBackingStorePaintEnd. } -bool TiledBackingStoreRemoteTile::isReadyToPaint() const +bool CoordinatedTile::isReadyToPaint() const { return !!m_ID; } -void TiledBackingStoreRemoteTile::paint(GraphicsContext* context, const IntRect& rect) +void CoordinatedTile::paint(GraphicsContext* context, const IntRect& rect) { ASSERT_NOT_REACHED(); } -void TiledBackingStoreRemoteTile::resize(const IntSize& newSize) +void CoordinatedTile::resize(const IntSize& newSize) { m_rect = IntRect(m_rect.location(), newSize); m_dirtyRect = m_rect; } -TiledBackingStoreRemoteTileBackend::TiledBackingStoreRemoteTileBackend(TiledBackingStoreRemoteTileClient* client) +CoordinatedTileBackend::CoordinatedTileBackend(CoordinatedTileClient* client) : m_client(client) { } -PassRefPtr<WebCore::Tile> TiledBackingStoreRemoteTileBackend::createTile(WebCore::TiledBackingStore* tiledBackingStore, const WebCore::Tile::Coordinate& tileCoordinate) +PassRefPtr<WebCore::Tile> CoordinatedTileBackend::createTile(WebCore::TiledBackingStore* tiledBackingStore, const WebCore::Tile::Coordinate& tileCoordinate) { - return TiledBackingStoreRemoteTile::create(m_client, tiledBackingStore, tileCoordinate); + return CoordinatedTile::create(m_client, tiledBackingStore, tileCoordinate); } -void TiledBackingStoreRemoteTileBackend::paintCheckerPattern(WebCore::GraphicsContext*, const WebCore::FloatRect&) +void CoordinatedTileBackend::paintCheckerPattern(WebCore::GraphicsContext*, const WebCore::FloatRect&) { } diff --git a/Source/WebKit2/WebProcess/WebPage/TiledBackingStoreRemoteTile.h b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedTile.h index cae11e9bb..84d1134f0 100644 --- a/Source/WebKit2/WebProcess/WebPage/TiledBackingStoreRemoteTile.h +++ b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedTile.h @@ -23,8 +23,8 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef TiledBackingStoreRemoteTile_h -#define TiledBackingStoreRemoteTile_h +#ifndef CoordinatedTile_h +#define CoordinatedTile_h #if USE(TILED_BACKING_STORE) @@ -40,13 +40,13 @@ class TiledBackingStore; namespace WebKit { -class TiledBackingStoreRemoteTileClient; +class CoordinatedTileClient; class SurfaceUpdateInfo; -class TiledBackingStoreRemoteTile : public WebCore::Tile { +class CoordinatedTile : public WebCore::Tile { public: - static PassRefPtr<Tile> create(TiledBackingStoreRemoteTileClient* client, WebCore::TiledBackingStore* tiledBackingStore, const Coordinate& tileCoordinate) { return adoptRef(new TiledBackingStoreRemoteTile(client, tiledBackingStore, tileCoordinate)); } - ~TiledBackingStoreRemoteTile(); + static PassRefPtr<Tile> create(CoordinatedTileClient* client, WebCore::TiledBackingStore* tiledBackingStore, const Coordinate& tileCoordinate) { return adoptRef(new CoordinatedTile(client, tiledBackingStore, tileCoordinate)); } + ~CoordinatedTile(); bool isDirty() const; void invalidate(const WebCore::IntRect&); @@ -60,9 +60,9 @@ public: void resize(const WebCore::IntSize&); private: - TiledBackingStoreRemoteTile(TiledBackingStoreRemoteTileClient*, WebCore::TiledBackingStore*, const Coordinate&); + CoordinatedTile(CoordinatedTileClient*, WebCore::TiledBackingStore*, const Coordinate&); - TiledBackingStoreRemoteTileClient* m_client; + CoordinatedTileClient* m_client; WebCore::TiledBackingStore* m_tiledBackingStore; Coordinate m_coordinate; WebCore::IntRect m_rect; @@ -73,24 +73,24 @@ private: OwnPtr<WebCore::ImageBuffer> m_localBuffer; }; -class TiledBackingStoreRemoteTileClient { +class CoordinatedTileClient { public: - virtual ~TiledBackingStoreRemoteTileClient() { } + virtual ~CoordinatedTileClient() { } virtual void createTile(int tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&) = 0; virtual void updateTile(int tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&) = 0; virtual void removeTile(int tileID) = 0; virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, ShareableSurface::Handle&, WebCore::IntPoint&) = 0; }; -class TiledBackingStoreRemoteTileBackend : public WebCore::TiledBackingStoreBackend { +class CoordinatedTileBackend : public WebCore::TiledBackingStoreBackend { public: - static PassOwnPtr<WebCore::TiledBackingStoreBackend> create(TiledBackingStoreRemoteTileClient* client) { return adoptPtr(new TiledBackingStoreRemoteTileBackend(client)); } + static PassOwnPtr<WebCore::TiledBackingStoreBackend> create(CoordinatedTileClient* client) { return adoptPtr(new CoordinatedTileBackend(client)); } PassRefPtr<WebCore::Tile> createTile(WebCore::TiledBackingStore*, const WebCore::Tile::Coordinate&); void paintCheckerPattern(WebCore::GraphicsContext*, const WebCore::FloatRect&); private: - TiledBackingStoreRemoteTileBackend(TiledBackingStoreRemoteTileClient*); - TiledBackingStoreRemoteTileClient* m_client; + CoordinatedTileBackend(CoordinatedTileClient*); + CoordinatedTileClient* m_client; }; @@ -98,4 +98,4 @@ private: #endif // USE(TILED_BACKING_STORE) -#endif // TiledBackingStoreRemoteTile +#endif // CoordinatedTile diff --git a/Source/WebKit2/WebProcess/WebPage/LayerTreeCoordinator/LayerTreeCoordinator.cpp b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp index ae3994422..7095c438b 100644 --- a/Source/WebKit2/WebProcess/WebPage/LayerTreeCoordinator/LayerTreeCoordinator.cpp +++ b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp @@ -1,4 +1,4 @@ -/* + /* * Copyright (C) 2011 Apple Inc. All rights reserved. * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). * @@ -26,16 +26,18 @@ #include "config.h" +#if USE(COORDINATED_GRAPHICS) #include "LayerTreeCoordinator.h" +#include "CoordinatedGraphicsLayer.h" #include "DrawingAreaImpl.h" #include "GraphicsContext.h" #include "LayerTreeCoordinatorProxyMessages.h" #include "MessageID.h" #include "SurfaceUpdateInfo.h" #include "WebCoreArgumentCoders.h" -#include "WebGraphicsLayer.h" #include "WebPage.h" +#include "WebPageProxyMessages.h" #include <WebCore/Frame.h> #include <WebCore/FrameView.h> #include <WebCore/Page.h> @@ -56,13 +58,13 @@ PassRefPtr<LayerTreeCoordinator> LayerTreeCoordinator::create(WebPage* webPage) LayerTreeCoordinator::~LayerTreeCoordinator() { - // Prevent setWebGraphicsLayerClient(0) -> detachLayer() from modifying the set while we iterate it. - HashSet<WebCore::WebGraphicsLayer*> registeredLayers; + // Prevent setCoordinatedGraphicsLayerClient(0) -> detachLayer() from modifying the set while we iterate it. + HashSet<WebCore::CoordinatedGraphicsLayer*> registeredLayers; registeredLayers.swap(m_registeredLayers); - HashSet<WebCore::WebGraphicsLayer*>::iterator end = registeredLayers.end(); - for (HashSet<WebCore::WebGraphicsLayer*>::iterator it = registeredLayers.begin(); it != end; ++it) - (*it)->setWebGraphicsLayerClient(0); + HashSet<WebCore::CoordinatedGraphicsLayer*>::iterator end = registeredLayers.end(); + for (HashSet<WebCore::CoordinatedGraphicsLayer*>::iterator it = registeredLayers.begin(); it != end; ++it) + (*it)->setCoordinatedGraphicsLayerClient(0); } LayerTreeCoordinator::LayerTreeCoordinator(WebPage* webPage) @@ -77,20 +79,21 @@ LayerTreeCoordinator::LayerTreeCoordinator(WebPage* webPage) , m_shouldSyncRootLayer(true) , m_layerFlushTimer(this, &LayerTreeCoordinator::layerFlushTimerFired) , m_layerFlushSchedulingEnabled(true) + , m_forceRepaintAsyncCallbackID(0) { // Create a root layer. m_rootLayer = GraphicsLayer::create(this); - WebGraphicsLayer* webRootLayer = toWebGraphicsLayer(m_rootLayer.get()); + CoordinatedGraphicsLayer* webRootLayer = toCoordinatedGraphicsLayer(m_rootLayer.get()); webRootLayer->setRootLayer(true); #ifndef NDEBUG m_rootLayer->setName("LayerTreeCoordinator root layer"); #endif m_rootLayer->setDrawsContent(false); m_rootLayer->setSize(m_webPage->size()); - m_layerTreeContext.webLayerID = toWebGraphicsLayer(webRootLayer)->id(); + m_layerTreeContext.webLayerID = toCoordinatedGraphicsLayer(webRootLayer)->id(); m_nonCompositedContentLayer = GraphicsLayer::create(this); - toWebGraphicsLayer(m_rootLayer.get())->setWebGraphicsLayerClient(this); + toCoordinatedGraphicsLayer(m_rootLayer.get())->setCoordinatedGraphicsLayerClient(this); #ifndef NDEBUG m_nonCompositedContentLayer->setName("LayerTreeCoordinator non-composited content"); #endif @@ -174,12 +177,25 @@ void LayerTreeCoordinator::scrollNonCompositedContents(const WebCore::IntRect& s void LayerTreeCoordinator::forceRepaint() { + // This is necessary for running layout tests. Since in this case we are not waiting for a UIProcess to reply nicely. + // Instead we are just triggering forceRepaint. But we still want to have the scripted animation callbacks being executed. + syncDisplayState(); + // We need to schedule another flush, otherwise the forced paint might cancel a later expected flush. // This is aligned with LayerTreeHostCA. scheduleLayerFlush(); flushPendingLayerChanges(); } +bool LayerTreeCoordinator::forceRepaintAsync(uint64_t callbackID) +{ + // We expect the UI process to not require a new repaint until the previous one has finished. + ASSERT(!m_forceRepaintAsyncCallbackID); + m_forceRepaintAsyncCallbackID = callbackID; + scheduleLayerFlush(); + return true; +} + void LayerTreeCoordinator::sizeDidChange(const WebCore::IntSize& newSize) { if (m_rootLayer->size() == newSize) @@ -234,6 +250,9 @@ void LayerTreeCoordinator::setPageOverlayOpacity(float value) bool LayerTreeCoordinator::flushPendingLayerChanges() { + if (m_waitingForUIProcess) + return false; + m_shouldSyncFrame = false; bool didSync = m_webPage->corePage()->mainFrame()->view()->syncCompositingStateIncludingSubframes(); m_nonCompositedContentLayer->syncCompositingStateForThisLayerOnly(); @@ -243,18 +262,23 @@ bool LayerTreeCoordinator::flushPendingLayerChanges() m_rootLayer->syncCompositingStateForThisLayerOnly(); if (m_shouldSyncRootLayer) { - m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetRootCompositingLayer(toWebGraphicsLayer(m_rootLayer.get())->id())); + m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetRootCompositingLayer(toCoordinatedGraphicsLayer(m_rootLayer.get())->id())); m_shouldSyncRootLayer = false; } - if (!m_shouldSyncFrame) - return didSync; + if (m_shouldSyncFrame) { + didSync = true; + m_webPage->send(Messages::LayerTreeCoordinatorProxy::DidRenderFrame()); + m_waitingForUIProcess = true; + m_shouldSyncFrame = false; + } - m_webPage->send(Messages::LayerTreeCoordinatorProxy::DidRenderFrame()); - m_waitingForUIProcess = true; - m_shouldSyncFrame = false; + if (m_forceRepaintAsyncCallbackID) { + m_webPage->send(Messages::WebPageProxy::VoidCallback(m_forceRepaintAsyncCallbackID)); + m_forceRepaintAsyncCallbackID = 0; + } - return true; + return didSync; } void LayerTreeCoordinator::syncLayerState(WebLayerID id, const WebLayerInfo& info) @@ -288,7 +312,7 @@ void LayerTreeCoordinator::syncLayerFilters(WebLayerID id, const FilterOperation } #endif -void LayerTreeCoordinator::attachLayer(WebGraphicsLayer* layer) +void LayerTreeCoordinator::attachLayer(CoordinatedGraphicsLayer* layer) { ASSERT(!m_registeredLayers.contains(layer)); m_registeredLayers.add(layer); @@ -297,7 +321,7 @@ void LayerTreeCoordinator::attachLayer(WebGraphicsLayer* layer) layer->adjustVisibleRect(); } -void LayerTreeCoordinator::detachLayer(WebGraphicsLayer* layer) +void LayerTreeCoordinator::detachLayer(CoordinatedGraphicsLayer* layer) { m_registeredLayers.remove(layer); m_shouldSyncFrame = true; @@ -324,7 +348,7 @@ static void updateOffsetFromViewportForSelf(RenderLayer* renderLayer) if (!renderLayer->isStackingContext()) return; - WebGraphicsLayer* graphicsLayer = toWebGraphicsLayer(backing->graphicsLayer()); + CoordinatedGraphicsLayer* graphicsLayer = toCoordinatedGraphicsLayer(backing->graphicsLayer()); graphicsLayer->setFixedToViewport(true); } @@ -356,12 +380,8 @@ void LayerTreeCoordinator::performScheduledLayerFlush() { if (m_isSuspended || m_waitingForUIProcess) return; -#if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER) && !USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) - // Make sure that any previously registered animation callbacks are being executed before we flush the layers. - m_webPage->corePage()->mainFrame()->view()->serviceScriptedAnimations(convertSecondsToDOMTimeStamp(currentTime())); -#endif - m_webPage->layoutIfNeeded(); + syncDisplayState(); if (!m_isValid) return; @@ -370,6 +390,16 @@ void LayerTreeCoordinator::performScheduledLayerFlush() didPerformScheduledLayerFlush(); } +void LayerTreeCoordinator::syncDisplayState() +{ +#if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER) && !USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) + // Make sure that any previously registered animation callbacks are being executed before we flush the layers. + m_webPage->corePage()->mainFrame()->view()->serviceScriptedAnimations(convertSecondsToDOMTimeStamp(currentTime())); +#endif + + m_webPage->layoutIfNeeded(); +} + void LayerTreeCoordinator::didPerformScheduledLayerFlush() { if (m_notifyAfterScheduledLayerFlush) { @@ -520,20 +550,33 @@ WebCore::IntRect LayerTreeCoordinator::visibleContentsRect() const return m_visibleContentsRect; } + +void LayerTreeCoordinator::setLayerAnimatedOpacity(WebLayerID id, float opacity) +{ + m_shouldSyncFrame = true; + m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetLayerAnimatedOpacity(id, opacity)); +} + +void LayerTreeCoordinator::setLayerAnimatedTransform(WebLayerID id, const TransformationMatrix& transform) +{ + m_shouldSyncFrame = true; + m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetLayerAnimatedTransform(id, transform)); +} + void LayerTreeCoordinator::setVisibleContentsRect(const IntRect& rect, float scale, const FloatPoint& trajectoryVector) { bool contentsRectDidChange = rect != m_visibleContentsRect; bool contentsScaleDidChange = scale != m_contentsScale; - if (trajectoryVector != FloatPoint::zero()) - toWebGraphicsLayer(m_nonCompositedContentLayer.get())->setVisibleContentRectTrajectoryVector(trajectoryVector); + // A zero trajectoryVector indicates that tiles all around the viewport are requested. + toCoordinatedGraphicsLayer(m_nonCompositedContentLayer.get())->setVisibleContentRectTrajectoryVector(trajectoryVector); if (contentsRectDidChange || contentsScaleDidChange) { m_visibleContentsRect = rect; m_contentsScale = scale; - HashSet<WebCore::WebGraphicsLayer*>::iterator end = m_registeredLayers.end(); - for (HashSet<WebCore::WebGraphicsLayer*>::iterator it = m_registeredLayers.begin(); it != end; ++it) { + HashSet<WebCore::CoordinatedGraphicsLayer*>::iterator end = m_registeredLayers.end(); + for (HashSet<WebCore::CoordinatedGraphicsLayer*>::iterator it = m_registeredLayers.begin(); it != end; ++it) { if (contentsScaleDidChange) (*it)->setContentsScale(scale); if (contentsRectDidChange) @@ -548,12 +591,10 @@ void LayerTreeCoordinator::setVisibleContentsRect(const IntRect& rect, float sca m_shouldSendScrollPositionUpdate = true; } -#if USE(UI_SIDE_COMPOSITING) void LayerTreeCoordinator::scheduleAnimation() { scheduleLayerFlush(); } -#endif void LayerTreeCoordinator::renderNextFrame() { @@ -570,8 +611,8 @@ bool LayerTreeCoordinator::layerTreeTileUpdatesAllowed() const void LayerTreeCoordinator::purgeBackingStores() { - HashSet<WebCore::WebGraphicsLayer*>::iterator end = m_registeredLayers.end(); - for (HashSet<WebCore::WebGraphicsLayer*>::iterator it = m_registeredLayers.begin(); it != end; ++it) + HashSet<WebCore::CoordinatedGraphicsLayer*>::iterator end = m_registeredLayers.end(); + for (HashSet<WebCore::CoordinatedGraphicsLayer*>::iterator it = m_registeredLayers.begin(); it != end; ++it) (*it)->purgeBackingStores(); ASSERT(!m_directlyCompositedImageRefCounts.size()); @@ -597,3 +638,4 @@ PassOwnPtr<WebCore::GraphicsContext> LayerTreeCoordinator::beginContentUpdate(co } } // namespace WebKit +#endif // USE(COORDINATED_GRAPHICS) diff --git a/Source/WebKit2/WebProcess/WebPage/LayerTreeCoordinator/LayerTreeCoordinator.h b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.h index 7f6038005..3fd59d218 100644 --- a/Source/WebKit2/WebProcess/WebPage/LayerTreeCoordinator/LayerTreeCoordinator.h +++ b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.h @@ -20,11 +20,13 @@ #ifndef LayerTreeCoordinator_h #define LayerTreeCoordinator_h +#if USE(COORDINATED_GRAPHICS) + +#include "CoordinatedGraphicsLayer.h" #include "LayerTreeContext.h" #include "LayerTreeHost.h" #include "Timer.h" #include "UpdateAtlas.h" -#include "WebGraphicsLayer.h" #include <WebCore/GraphicsLayerClient.h> #include <wtf/OwnPtr.h> @@ -34,7 +36,7 @@ class UpdateInfo; class WebPage; class LayerTreeCoordinator : public LayerTreeHost, WebCore::GraphicsLayerClient - , public WebGraphicsLayerClient { + , public CoordinatedGraphicsLayerClient { public: static PassRefPtr<LayerTreeCoordinator> create(WebPage*); virtual ~LayerTreeCoordinator(); @@ -51,6 +53,7 @@ public: virtual void setNonCompositedContentsNeedDisplay(const WebCore::IntRect&); virtual void scrollNonCompositedContents(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset); virtual void forceRepaint(); + virtual bool forceRepaintAsync(uint64_t callbackID); virtual void sizeDidChange(const WebCore::IntSize& newSize); virtual void didInstallPageOverlay(); @@ -77,18 +80,18 @@ public: virtual void syncLayerState(WebLayerID, const WebLayerInfo&); virtual void syncLayerChildren(WebLayerID, const Vector<WebLayerID>&); + virtual void setLayerAnimatedOpacity(WebLayerID, float); + virtual void setLayerAnimatedTransform(WebLayerID, const WebCore::TransformationMatrix&); #if ENABLE(CSS_FILTERS) virtual void syncLayerFilters(WebLayerID, const WebCore::FilterOperations&); #endif virtual void syncCanvas(WebLayerID, const WebCore::IntSize& canvasSize, uint32_t graphicsSurfaceToken) OVERRIDE; - virtual void attachLayer(WebCore::WebGraphicsLayer*); - virtual void detachLayer(WebCore::WebGraphicsLayer*); + virtual void attachLayer(WebCore::CoordinatedGraphicsLayer*); + virtual void detachLayer(WebCore::CoordinatedGraphicsLayer*); virtual void syncFixedLayers(); virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, ShareableBitmap::Flags, ShareableSurface::Handle&, WebCore::IntPoint&); -#if USE(UI_SIDE_COMPOSITING) virtual void scheduleAnimation() OVERRIDE; -#endif protected: explicit LayerTreeCoordinator(WebPage*); @@ -108,6 +111,7 @@ private: void cancelPendingLayerFlush(); void performScheduledLayerFlush(); void didPerformScheduledLayerFlush(); + void syncDisplayState(); OwnPtr<WebCore::GraphicsLayer> m_rootLayer; @@ -117,7 +121,7 @@ private: // The page overlay layer. Will be null if there's no page overlay. OwnPtr<WebCore::GraphicsLayer> m_pageOverlayLayer; - HashSet<WebCore::WebGraphicsLayer*> m_registeredLayers; + HashSet<WebCore::CoordinatedGraphicsLayer*> m_registeredLayers; HashMap<int64_t, int> m_directlyCompositedImageRefCounts; Vector<UpdateAtlas> m_updateAtlases; @@ -136,8 +140,11 @@ private: void layerFlushTimerFired(WebCore::Timer<LayerTreeCoordinator>*); WebCore::Timer<LayerTreeCoordinator> m_layerFlushTimer; bool m_layerFlushSchedulingEnabled; + uint64_t m_forceRepaintAsyncCallbackID; }; } +#endif + #endif // LayerTreeCoordinator_h diff --git a/Source/WebKit2/WebProcess/WebPage/LayerTreeCoordinator/LayerTreeCoordinator.messages.in b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.messages.in index aff6f96ad..7b9c2acdf 100644 --- a/Source/WebKit2/WebProcess/WebPage/LayerTreeCoordinator/LayerTreeCoordinator.messages.in +++ b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.messages.in @@ -18,7 +18,7 @@ # -#if USE(UI_SIDE_COMPOSITING) +#if USE(COORDINATED_GRAPHICS) messages -> LayerTreeCoordinator { SetVisibleContentsRect(WebCore::IntRect visibleContentsRect, float scale, WebCore::FloatPoint trajectoryVectory) RenderNextFrame() diff --git a/Source/WebKit2/WebProcess/WebPage/DrawingArea.h b/Source/WebKit2/WebProcess/WebPage/DrawingArea.h index 71aa607cb..759e675ad 100644 --- a/Source/WebKit2/WebProcess/WebPage/DrawingArea.h +++ b/Source/WebKit2/WebProcess/WebPage/DrawingArea.h @@ -90,7 +90,7 @@ public: virtual void scheduleCompositingLayerSync() = 0; #endif -#if USE(UI_SIDE_COMPOSITING) +#if USE(COORDINATED_GRAPHICS) virtual void didReceiveLayerTreeCoordinatorMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*) = 0; #endif diff --git a/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.cpp b/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.cpp index 5e6d5ec0a..eefd1bb88 100644 --- a/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.cpp +++ b/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.cpp @@ -199,6 +199,11 @@ void DrawingAreaImpl::forceRepaint() display(); } +bool DrawingAreaImpl::forceRepaintAsync(uint64_t callbackID) +{ + return m_layerTreeHost && m_layerTreeHost->forceRepaintAsync(callbackID); +} + void DrawingAreaImpl::didInstallPageOverlay() { if (m_layerTreeHost) @@ -688,7 +693,7 @@ void DrawingAreaImpl::display(UpdateInfo& updateInfo) m_displayTimer.stop(); } -#if USE(UI_SIDE_COMPOSITING) +#if USE(COORDINATED_GRAPHICS) void DrawingAreaImpl::didReceiveLayerTreeCoordinatorMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments) { if (m_layerTreeHost) diff --git a/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.h b/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.h index 2cebbd5c4..0174a5d6e 100644 --- a/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.h +++ b/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.h @@ -57,6 +57,7 @@ private: virtual bool layerTreeStateIsFrozen() const { return m_layerTreeStateIsFrozen; } virtual LayerTreeHost* layerTreeHost() const { return m_layerTreeHost.get(); } virtual void forceRepaint(); + virtual bool forceRepaintAsync(uint64_t callbackID); virtual void didInstallPageOverlay(); virtual void didUninstallPageOverlay(); @@ -77,7 +78,7 @@ private: virtual void setLayerHostingMode(uint32_t) OVERRIDE; #endif -#if USE(UI_SIDE_COMPOSITING) +#if USE(COORDINATED_GRAPHICS) virtual void didReceiveLayerTreeCoordinatorMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*); #endif diff --git a/Source/WebKit2/WebProcess/WebPage/LayerTreeCoordinator/WebGraphicsLayer.cpp b/Source/WebKit2/WebProcess/WebPage/LayerTreeCoordinator/WebGraphicsLayer.cpp deleted file mode 100644 index 19ce4d031..000000000 --- a/Source/WebKit2/WebProcess/WebPage/LayerTreeCoordinator/WebGraphicsLayer.cpp +++ /dev/null @@ -1,748 +0,0 @@ -/* - Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#if USE(UI_SIDE_COMPOSITING) -#include "WebGraphicsLayer.h" - -#include "BackingStore.h" -#include "FloatQuad.h" -#include "Frame.h" -#include "FrameView.h" -#include "GraphicsContext.h" -#include "GraphicsLayer.h" -#include "LayerTreeCoordinatorProxyMessages.h" -#include "Page.h" -#include "TextureMapperPlatformLayer.h" -#include "TiledBackingStoreRemoteTile.h" -#include "WebPage.h" -#include <wtf/CurrentTime.h> -#include <wtf/HashMap.h> -#include <wtf/text/CString.h> - -using namespace WebKit; - -namespace WebCore { - -static HashMap<WebLayerID, WebGraphicsLayer*>& layerByIDMap() -{ - static HashMap<WebLayerID, WebGraphicsLayer*> globalMap; - return globalMap; -} - -WebGraphicsLayer* WebGraphicsLayer::layerByID(WebKit::WebLayerID id) -{ - HashMap<WebLayerID, WebGraphicsLayer*>& table = layerByIDMap(); - HashMap<WebLayerID, WebGraphicsLayer*>::iterator it = table.find(id); - if (it == table.end()) - return 0; - return it->second; -} - -static WebLayerID toWebLayerID(GraphicsLayer* layer) -{ - return layer ? toWebGraphicsLayer(layer)->id() : 0; -} - -void WebGraphicsLayer::didChangeLayerState() -{ - m_shouldSyncLayerState = true; - if (client()) - client()->notifySyncRequired(this); -} - -void WebGraphicsLayer::didChangeChildren() -{ - m_shouldSyncChildren = true; - if (client()) - client()->notifySyncRequired(this); -} - -#if ENABLE(CSS_FILTERS) -void WebGraphicsLayer::didChangeFilters() -{ - m_shouldSyncFilters = true; - if (client()) - client()->notifySyncRequired(this); -} -#endif - -void WebGraphicsLayer::setShouldUpdateVisibleRect() -{ - if (!transform().isAffine()) - return; - - m_shouldUpdateVisibleRect = true; - for (size_t i = 0; i < children().size(); ++i) - toWebGraphicsLayer(children()[i])->setShouldUpdateVisibleRect(); - if (replicaLayer()) - toWebGraphicsLayer(replicaLayer())->setShouldUpdateVisibleRect(); -} - -void WebGraphicsLayer::didChangeGeometry() -{ - didChangeLayerState(); - setShouldUpdateVisibleRect(); -} - -WebGraphicsLayer::WebGraphicsLayer(GraphicsLayerClient* client) - : GraphicsLayer(client) - , m_maskTarget(0) - , m_inUpdateMode(false) - , m_shouldUpdateVisibleRect(true) - , m_shouldSyncLayerState(true) - , m_shouldSyncChildren(true) - , m_fixedToViewport(false) - , m_canvasNeedsDisplay(false) - , m_webGraphicsLayerClient(0) - , m_contentsScale(1) - , m_canvasPlatformLayer(0) -{ - static WebLayerID nextLayerID = 1; - m_id = nextLayerID++; - layerByIDMap().add(id(), this); -} - -WebGraphicsLayer::~WebGraphicsLayer() -{ - layerByIDMap().remove(id()); - - if (m_webGraphicsLayerClient) { - purgeBackingStores(); - m_webGraphicsLayerClient->detachLayer(this); - } - willBeDestroyed(); -} - -void WebGraphicsLayer::willBeDestroyed() -{ - GraphicsLayer::willBeDestroyed(); -} - -bool WebGraphicsLayer::setChildren(const Vector<GraphicsLayer*>& children) -{ - bool ok = GraphicsLayer::setChildren(children); - if (!ok) - return false; - for (int i = 0; i < children.size(); ++i) { - WebGraphicsLayer* child = toWebGraphicsLayer(children[i]); - child->setWebGraphicsLayerClient(m_webGraphicsLayerClient); - child->didChangeLayerState(); - } - didChangeChildren(); - return true; -} - -void WebGraphicsLayer::addChild(GraphicsLayer* layer) -{ - GraphicsLayer::addChild(layer); - toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient); - toWebGraphicsLayer(layer)->didChangeLayerState(); - didChangeChildren(); -} - -void WebGraphicsLayer::addChildAtIndex(GraphicsLayer* layer, int index) -{ - GraphicsLayer::addChildAtIndex(layer, index); - toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient); - toWebGraphicsLayer(layer)->didChangeLayerState(); - didChangeChildren(); -} - -void WebGraphicsLayer::addChildAbove(GraphicsLayer* layer, GraphicsLayer* sibling) -{ - GraphicsLayer::addChildAbove(layer, sibling); - toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient); - toWebGraphicsLayer(layer)->didChangeLayerState(); - didChangeChildren(); -} - -void WebGraphicsLayer::addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling) -{ - GraphicsLayer::addChildBelow(layer, sibling); - toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient); - toWebGraphicsLayer(layer)->didChangeLayerState(); - didChangeChildren(); -} - -bool WebGraphicsLayer::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild) -{ - bool ok = GraphicsLayer::replaceChild(oldChild, newChild); - if (!ok) - return false; - didChangeChildren(); - toWebGraphicsLayer(oldChild)->didChangeLayerState(); - toWebGraphicsLayer(newChild)->setWebGraphicsLayerClient(m_webGraphicsLayerClient); - toWebGraphicsLayer(newChild)->didChangeLayerState(); - return true; -} - -void WebGraphicsLayer::removeFromParent() -{ - if (WebGraphicsLayer* parentLayer = toWebGraphicsLayer(parent())) - parentLayer->didChangeChildren(); - GraphicsLayer::removeFromParent(); - - didChangeLayerState(); -} - -void WebGraphicsLayer::setPosition(const FloatPoint& p) -{ - if (position() == p) - return; - - GraphicsLayer::setPosition(p); - didChangeGeometry(); -} - -void WebGraphicsLayer::setAnchorPoint(const FloatPoint3D& p) -{ - if (anchorPoint() == p) - return; - - GraphicsLayer::setAnchorPoint(p); - didChangeGeometry(); -} - -void WebGraphicsLayer::setSize(const FloatSize& size) -{ - if (this->size() == size) - return; - - GraphicsLayer::setSize(size); - setNeedsDisplay(); - if (maskLayer()) - maskLayer()->setSize(size); - didChangeGeometry(); -} - -void WebGraphicsLayer::setTransform(const TransformationMatrix& t) -{ - if (transform() == t) - return; - - GraphicsLayer::setTransform(t); - didChangeGeometry(); -} - -void WebGraphicsLayer::setChildrenTransform(const TransformationMatrix& t) -{ - if (childrenTransform() == t) - return; - - GraphicsLayer::setChildrenTransform(t); - didChangeGeometry(); -} - -void WebGraphicsLayer::setPreserves3D(bool b) -{ - if (preserves3D() == b) - return; - - GraphicsLayer::setPreserves3D(b); - didChangeGeometry(); -} - -void WebGraphicsLayer::setMasksToBounds(bool b) -{ - if (masksToBounds() == b) - return; - GraphicsLayer::setMasksToBounds(b); - didChangeGeometry(); -} - -void WebGraphicsLayer::setDrawsContent(bool b) -{ - if (drawsContent() == b) - return; - GraphicsLayer::setDrawsContent(b); - - didChangeLayerState(); -} - -void WebGraphicsLayer::setContentsOpaque(bool b) -{ - if (contentsOpaque() == b) - return; - if (m_mainBackingStore) - m_mainBackingStore->setSupportsAlpha(!b); - GraphicsLayer::setContentsOpaque(b); - didChangeLayerState(); -} - -void WebGraphicsLayer::setBackfaceVisibility(bool b) -{ - if (backfaceVisibility() == b) - return; - - GraphicsLayer::setBackfaceVisibility(b); - didChangeLayerState(); -} - -void WebGraphicsLayer::setOpacity(float opacity) -{ - if (this->opacity() == opacity) - return; - - GraphicsLayer::setOpacity(opacity); - didChangeLayerState(); -} - -void WebGraphicsLayer::setContentsRect(const IntRect& r) -{ - if (contentsRect() == r) - return; - - GraphicsLayer::setContentsRect(r); - didChangeLayerState(); -} - -void WebGraphicsLayer::setContentsNeedsDisplay() -{ - RefPtr<Image> image = m_image; - setContentsToImage(0); - setContentsToImage(image.get()); - m_canvasNeedsDisplay = true; - if (client()) - client()->notifySyncRequired(this); -} - -void WebGraphicsLayer::setContentsToCanvas(PlatformLayer* platformLayer) -{ - m_canvasPlatformLayer = platformLayer; - m_canvasNeedsDisplay = true; - if (client()) - client()->notifySyncRequired(this); -} - -#if ENABLE(CSS_FILTERS) -bool WebGraphicsLayer::setFilters(const FilterOperations& newFilters) -{ - if (filters() == newFilters) - return true; - didChangeFilters(); - return GraphicsLayer::setFilters(newFilters); -} -#endif - - -void WebGraphicsLayer::setContentsToImage(Image* image) -{ - if (image == m_image) - return; - int64_t newID = 0; - if (m_webGraphicsLayerClient) { - // We adopt first, in case this is the same frame - that way we avoid destroying and recreating the image. - newID = m_webGraphicsLayerClient->adoptImageBackingStore(image); - m_webGraphicsLayerClient->releaseImageBackingStore(m_layerInfo.imageBackingStoreID); - didChangeLayerState(); - if (m_layerInfo.imageBackingStoreID && newID == m_layerInfo.imageBackingStoreID) - return; - } else { - // If m_webGraphicsLayerClient is not set yet there should be no backing store ID. - ASSERT(!m_layerInfo.imageBackingStoreID); - didChangeLayerState(); - } - - m_layerInfo.imageBackingStoreID = newID; - m_image = image; - GraphicsLayer::setContentsToImage(image); -} - -void WebGraphicsLayer::setMaskLayer(GraphicsLayer* layer) -{ - if (layer == maskLayer()) - return; - - GraphicsLayer::setMaskLayer(layer); - - if (!layer) - return; - - layer->setSize(size()); - WebGraphicsLayer* webGraphicsLayer = toWebGraphicsLayer(layer); - webGraphicsLayer->setWebGraphicsLayerClient(m_webGraphicsLayerClient); - webGraphicsLayer->setMaskTarget(this); - webGraphicsLayer->didChangeLayerState(); - didChangeLayerState(); - -} - -void WebGraphicsLayer::setReplicatedByLayer(GraphicsLayer* layer) -{ - if (layer == replicaLayer()) - return; - - if (layer) - toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient); - - GraphicsLayer::setReplicatedByLayer(layer); - didChangeLayerState(); -} - -void WebGraphicsLayer::setNeedsDisplay() -{ - setNeedsDisplayInRect(IntRect(IntPoint::zero(), IntSize(size().width(), size().height()))); -} - -void WebGraphicsLayer::setNeedsDisplayInRect(const FloatRect& rect) -{ - if (m_mainBackingStore) - m_mainBackingStore->invalidate(IntRect(rect)); - didChangeLayerState(); -} - -WebLayerID WebGraphicsLayer::id() const -{ - return m_id; -} - -void WebGraphicsLayer::syncCompositingState(const FloatRect& rect) -{ - if (WebGraphicsLayer* mask = toWebGraphicsLayer(maskLayer())) - mask->syncCompositingStateForThisLayerOnly(); - - if (WebGraphicsLayer* replica = toWebGraphicsLayer(replicaLayer())) - replica->syncCompositingStateForThisLayerOnly(); - - m_webGraphicsLayerClient->syncFixedLayers(); - - syncCompositingStateForThisLayerOnly(); - - for (size_t i = 0; i < children().size(); ++i) - children()[i]->syncCompositingState(rect); -} - -WebGraphicsLayer* toWebGraphicsLayer(GraphicsLayer* layer) -{ - return static_cast<WebGraphicsLayer*>(layer); -} - -void WebGraphicsLayer::syncChildren() -{ - if (!m_shouldSyncChildren) - return; - m_shouldSyncChildren = false; - Vector<WebLayerID> childIDs; - for (size_t i = 0; i < children().size(); ++i) - childIDs.append(toWebLayerID(children()[i])); - - m_webGraphicsLayerClient->syncLayerChildren(m_id, childIDs); -} - -#if ENABLE(CSS_FILTERS) -void WebGraphicsLayer::syncFilters() -{ - if (!m_shouldSyncFilters) - return; - m_shouldSyncFilters = false; - m_webGraphicsLayerClient->syncLayerFilters(m_id, filters()); -} -#endif - -void WebGraphicsLayer::syncLayerState() -{ - if (!m_shouldSyncLayerState) - return; - m_shouldSyncLayerState = false; - m_layerInfo.fixedToViewport = fixedToViewport(); - - m_layerInfo.anchorPoint = anchorPoint(); - m_layerInfo.backfaceVisible = backfaceVisibility(); - m_layerInfo.childrenTransform = childrenTransform(); - m_layerInfo.contentsOpaque = contentsOpaque(); - m_layerInfo.contentsRect = contentsRect(); - m_layerInfo.drawsContent = drawsContent(); - m_layerInfo.mask = toWebLayerID(maskLayer()); - m_layerInfo.masksToBounds = masksToBounds(); - m_layerInfo.opacity = opacity(); - m_layerInfo.parent = toWebLayerID(parent()); - m_layerInfo.pos = position(); - m_layerInfo.preserves3D = preserves3D(); - m_layerInfo.replica = toWebLayerID(replicaLayer()); - m_layerInfo.size = size(); - m_layerInfo.transform = transform(); - m_webGraphicsLayerClient->syncLayerState(m_id, m_layerInfo); -} - -void WebGraphicsLayer::syncCanvas() -{ - if (!m_canvasNeedsDisplay) - return; - - if (!m_canvasPlatformLayer) - return; - -#if USE(GRAPHICS_SURFACE) - uint32_t graphicsSurfaceToken = m_canvasPlatformLayer->copyToGraphicsSurface(); - m_webGraphicsLayerClient->syncCanvas(m_id, IntSize(size().width(), size().height()), graphicsSurfaceToken); -#endif - m_canvasNeedsDisplay = false; -} - -void WebGraphicsLayer::ensureImageBackingStore() -{ - if (!m_image) - return; - if (!m_layerInfo.imageBackingStoreID) - m_layerInfo.imageBackingStoreID = m_webGraphicsLayerClient->adoptImageBackingStore(m_image.get()); -} - -void WebGraphicsLayer::syncCompositingStateForThisLayerOnly() -{ - // The remote image might have been released by purgeBackingStores. - ensureImageBackingStore(); - computeTransformedVisibleRect(); - syncChildren(); - syncLayerState(); -#if ENABLE(CSS_FILTERS) - syncFilters(); -#endif - updateContentBuffers(); - syncCanvas(); -} - -void WebGraphicsLayer::tiledBackingStorePaintBegin() -{ -} - -void WebGraphicsLayer::setRootLayer(bool isRoot) -{ - m_layerInfo.isRootLayer = isRoot; - didChangeLayerState(); -} - -void WebGraphicsLayer::setVisibleContentRectTrajectoryVector(const FloatPoint& trajectoryVector) -{ - if (m_mainBackingStore) - m_mainBackingStore->coverWithTilesIfNeeded(trajectoryVector); -} - -void WebGraphicsLayer::setContentsScale(float scale) -{ - m_contentsScale = scale; - adjustContentsScale(); -} - -float WebGraphicsLayer::effectiveContentsScale() -{ - return shouldUseTiledBackingStore() ? m_contentsScale : 1; -} - -void WebGraphicsLayer::adjustContentsScale() -{ - if (!drawsContent()) - return; - - if (!m_mainBackingStore || m_mainBackingStore->contentsScale() == effectiveContentsScale()) - return; - - // Between creating the new backing store and painting the content, - // we do not want to drop the previous one as that might result in - // briefly seeing flickering as the old tiles may be dropped before - // something replaces them. - m_previousBackingStore = m_mainBackingStore.release(); - - // No reason to save the previous backing store for non-visible areas. - m_previousBackingStore->removeAllNonVisibleTiles(); - - createBackingStore(); -} - -void WebGraphicsLayer::createBackingStore() -{ - m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemoteTileBackend::create(this))); - m_mainBackingStore->setSupportsAlpha(!contentsOpaque()); - m_mainBackingStore->setContentsScale(effectiveContentsScale()); -} - -void WebGraphicsLayer::tiledBackingStorePaint(GraphicsContext* context, const IntRect& rect) -{ - if (rect.isEmpty()) - return; - paintGraphicsLayerContents(*context, rect); -} - -void WebGraphicsLayer::tiledBackingStorePaintEnd(const Vector<IntRect>& updatedRects) -{ -} - -bool WebGraphicsLayer::tiledBackingStoreUpdatesAllowed() const -{ - if (!m_inUpdateMode) - return false; - return m_webGraphicsLayerClient->layerTreeTileUpdatesAllowed(); -} - -IntRect WebGraphicsLayer::tiledBackingStoreContentsRect() -{ - return IntRect(0, 0, size().width(), size().height()); -} - -bool WebGraphicsLayer::shouldUseTiledBackingStore() -{ - return !selfOrAncestorHaveNonAffineTransforms(); -} - -IntRect WebGraphicsLayer::tiledBackingStoreVisibleRect() -{ - if (!shouldUseTiledBackingStore()) - return tiledBackingStoreContentsRect(); - - // Non-invertible layers are not visible. - if (!m_layerTransform.combined().isInvertible()) - return IntRect(); - - // Return a projection of the visible rect (surface coordinates) onto the layer's plane (layer coordinates). - // The resulting quad might be squewed and the visible rect is the bounding box of this quad, - // so it might spread further than the real visible area (and then even more amplified by the cover rect multiplier). - return enclosingIntRect(m_layerTransform.combined().inverse().clampedBoundsOfProjectedQuad(FloatQuad(FloatRect(m_webGraphicsLayerClient->visibleContentsRect())))); -} - -Color WebGraphicsLayer::tiledBackingStoreBackgroundColor() const -{ - return contentsOpaque() ? Color::white : Color::transparent; -} - -PassOwnPtr<WebCore::GraphicsContext> WebGraphicsLayer::beginContentUpdate(const WebCore::IntSize& size, ShareableSurface::Handle& handle, WebCore::IntPoint& offset) -{ - return m_webGraphicsLayerClient->beginContentUpdate(size, contentsOpaque() ? 0 : ShareableBitmap::SupportsAlpha, handle, offset); -} - -void WebGraphicsLayer::createTile(int tileID, const SurfaceUpdateInfo& updateInfo, const IntRect& targetRect) -{ - m_webGraphicsLayerClient->createTile(id(), tileID, updateInfo, targetRect); -} - -void WebGraphicsLayer::updateTile(int tileID, const SurfaceUpdateInfo& updateInfo, const IntRect& targetRect) -{ - m_webGraphicsLayerClient->updateTile(id(), tileID, updateInfo, targetRect); -} - -void WebGraphicsLayer::removeTile(int tileID) -{ - m_webGraphicsLayerClient->removeTile(id(), tileID); -} - -void WebGraphicsLayer::updateContentBuffers() -{ - if (!drawsContent()) { - m_mainBackingStore.clear(); - m_previousBackingStore.clear(); - return; - } - - m_inUpdateMode = true; - // This is the only place we (re)create the main tiled backing store, once we - // have a remote client and we are ready to send our data to the UI process. - if (!m_mainBackingStore) - createBackingStore(); - m_mainBackingStore->updateTileBuffers(); - m_inUpdateMode = false; - - // The previous backing store is kept around to avoid flickering between - // removing the existing tiles and painting the new ones. The first time - // the visibleRect is full painted we remove the previous backing store. - if (m_mainBackingStore->visibleAreaIsCovered()) - m_previousBackingStore.clear(); -} - -void WebGraphicsLayer::purgeBackingStores() -{ - m_mainBackingStore.clear(); - m_previousBackingStore.clear(); - - if (m_layerInfo.imageBackingStoreID) { - m_webGraphicsLayerClient->releaseImageBackingStore(m_layerInfo.imageBackingStoreID); - m_layerInfo.imageBackingStoreID = 0; - } - - didChangeLayerState(); - didChangeChildren(); -} - -void WebGraphicsLayer::setWebGraphicsLayerClient(WebKit::WebGraphicsLayerClient* client) -{ - if (m_webGraphicsLayerClient == client) - return; - - if (WebGraphicsLayer* replica = toWebGraphicsLayer(replicaLayer())) - replica->setWebGraphicsLayerClient(client); - if (WebGraphicsLayer* mask = toWebGraphicsLayer(maskLayer())) - mask->setWebGraphicsLayerClient(client); - for (size_t i = 0; i < children().size(); ++i) { - WebGraphicsLayer* layer = toWebGraphicsLayer(this->children()[i]); - layer->setWebGraphicsLayerClient(client); - } - - // We have to release resources on the UI process here if the remote client has changed or is removed. - if (m_webGraphicsLayerClient) { - purgeBackingStores(); - m_webGraphicsLayerClient->detachLayer(this); - } - m_webGraphicsLayerClient = client; - if (client) - client->attachLayer(this); -} - -void WebGraphicsLayer::adjustVisibleRect() -{ - if (m_mainBackingStore) - m_mainBackingStore->coverWithTilesIfNeeded(); -} - -void WebGraphicsLayer::computeTransformedVisibleRect() -{ - if (!m_shouldUpdateVisibleRect) - return; - m_shouldUpdateVisibleRect = false; - m_layerTransform.setLocalTransform(transform()); - m_layerTransform.setPosition(position()); - m_layerTransform.setAnchorPoint(anchorPoint()); - m_layerTransform.setSize(size()); - m_layerTransform.setFlattening(!preserves3D()); - m_layerTransform.setChildrenTransform(childrenTransform()); - m_layerTransform.combineTransforms(parent() ? toWebGraphicsLayer(parent())->m_layerTransform.combinedForChildren() : TransformationMatrix()); - - // The combined transform will be used in tiledBackingStoreVisibleRect. - adjustVisibleRect(); - adjustContentsScale(); -} - -static PassOwnPtr<GraphicsLayer> createWebGraphicsLayer(GraphicsLayerClient* client) -{ - return adoptPtr(new WebGraphicsLayer(client)); -} - -void WebGraphicsLayer::initFactory() -{ - GraphicsLayer::setGraphicsLayerFactory(createWebGraphicsLayer); -} - -bool WebGraphicsLayer::selfOrAncestorHaveNonAffineTransforms() -{ - if (!m_layerTransform.combined().isAffine()) - return true; - - return false; -} - -} -#endif diff --git a/Source/WebKit2/WebProcess/WebPage/LayerTreeHost.cpp b/Source/WebKit2/WebProcess/WebPage/LayerTreeHost.cpp index bf011e085..87b46b372 100644 --- a/Source/WebKit2/WebProcess/WebPage/LayerTreeHost.cpp +++ b/Source/WebKit2/WebProcess/WebPage/LayerTreeHost.cpp @@ -34,7 +34,7 @@ #endif #endif -#if PLATFORM(QT) +#if USE(COORDINATED_GRAPHICS) #include "LayerTreeCoordinator.h" #endif @@ -52,7 +52,7 @@ PassRefPtr<LayerTreeHost> LayerTreeHost::create(WebPage* webPage) return LayerTreeHostCAMac::create(webPage); #elif PLATFORM(WIN) && HAVE(WKQCA) return LayerTreeHostCAWin::create(webPage); -#elif PLATFORM(QT) +#elif USE(COORDINATED_GRAPHICS) return LayerTreeCoordinator::create(webPage); #elif PLATFORM(GTK) && USE(TEXTURE_MAPPER_GL) return LayerTreeHostGtk::create(webPage); diff --git a/Source/WebKit2/WebProcess/WebPage/LayerTreeHost.h b/Source/WebKit2/WebProcess/WebPage/LayerTreeHost.h index 1372f2a29..9beeb3d0c 100644 --- a/Source/WebKit2/WebProcess/WebPage/LayerTreeHost.h +++ b/Source/WebKit2/WebProcess/WebPage/LayerTreeHost.h @@ -73,6 +73,7 @@ public: virtual void setNonCompositedContentsNeedDisplay(const WebCore::IntRect&) = 0; virtual void scrollNonCompositedContents(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset) = 0; virtual void forceRepaint() = 0; + virtual bool forceRepaintAsync(uint64_t callbackID) { return false; } virtual void sizeDidChange(const WebCore::IntSize& newSize) = 0; virtual void deviceScaleFactorDidChange() = 0; @@ -85,7 +86,7 @@ public: virtual void pauseRendering() { } virtual void resumeRendering() { } -#if USE(UI_SIDE_COMPOSITING) +#if USE(COORDINATED_GRAPHICS) virtual void setVisibleContentsRect(const WebCore::IntRect&, float scale, const WebCore::FloatPoint&) { } virtual void setVisibleContentsRectForLayer(int layerID, const WebCore::IntRect&) { } virtual void renderNextFrame() { } @@ -105,7 +106,7 @@ public: virtual WebCore::GraphicsDeviceAdapter* graphicsDeviceAdapter() const { return 0; } #endif -#if USE(UI_SIDE_COMPOSITING) +#if USE(COORDINATED_GRAPHICS) virtual void scheduleAnimation() = 0; #endif @@ -114,12 +115,12 @@ protected: WebPage* m_webPage; -#if USE(UI_SIDE_COMPOSITING) +#if USE(COORDINATED_GRAPHICS) bool m_waitingForUIProcess; #endif }; -#if !PLATFORM(WIN) && !PLATFORM(QT) +#if !PLATFORM(WIN) && !USE(COORDINATED_GRAPHICS) inline bool LayerTreeHost::supportsAcceleratedCompositing() { return true; diff --git a/Source/WebKit2/WebProcess/WebPage/UpdateAtlas.cpp b/Source/WebKit2/WebProcess/WebPage/UpdateAtlas.cpp index 0acd3486c..58869f399 100644 --- a/Source/WebKit2/WebProcess/WebPage/UpdateAtlas.cpp +++ b/Source/WebKit2/WebProcess/WebPage/UpdateAtlas.cpp @@ -20,7 +20,7 @@ #include "config.h" #include "UpdateAtlas.h" -#if USE(UI_SIDE_COMPOSITING) +#if USE(COORDINATED_GRAPHICS) #include "GraphicsContext.h" #include "IntRect.h" diff --git a/Source/WebKit2/WebProcess/WebPage/UpdateAtlas.h b/Source/WebKit2/WebProcess/WebPage/UpdateAtlas.h index 74760a5b4..7d2223769 100644 --- a/Source/WebKit2/WebProcess/WebPage/UpdateAtlas.h +++ b/Source/WebKit2/WebProcess/WebPage/UpdateAtlas.h @@ -22,7 +22,7 @@ #include "ShareableSurface.h" -#if USE(UI_SIDE_COMPOSITING) +#if USE(COORDINATED_GRAPHICS) namespace WebCore { class GraphicsContext; class IntRect; diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.cpp b/Source/WebKit2/WebProcess/WebPage/WebPage.cpp index 59d3bc5cb..59617dfd3 100644 --- a/Source/WebKit2/WebProcess/WebPage/WebPage.cpp +++ b/Source/WebKit2/WebProcess/WebPage/WebPage.cpp @@ -120,6 +120,10 @@ #include <WebCore/Range.h> #include <WebCore/VisiblePosition.h> +#if ENABLE(MHTML) +#include <WebCore/MHTMLArchive.h> +#endif + #if ENABLE(PLUGIN_PROCESS) #if PLATFORM(MAC) #include "MachPort.h" @@ -207,6 +211,10 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters) , m_isInRedo(false) , m_isClosed(false) , m_tabToLinks(false) + , m_asynchronousPluginInitializationEnabled(false) + , m_asynchronousPluginInitializationEnabledForAllPlugins(false) + , m_artificialPluginInitializationDelayEnabled(false) + , m_scrollingPerformanceLoggingEnabled(false) #if PLATFORM(MAC) , m_windowIsVisible(false) , m_isSmartInsertDeleteEnabled(parameters.isSmartInsertDeleteEnabled) @@ -296,13 +304,7 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters) WebCore::provideVibrationTo(m_page.get(), new WebVibrationClient(this)); #endif - // Qt does not yet call setIsInWindow. Until it does, just leave - // this line out so plug-ins and video will work. Eventually all platforms - // should call setIsInWindow and this comment and #if should be removed, - // leaving behind the setCanStartMedia call. -#if !PLATFORM(QT) m_page->setCanStartMedia(false); -#endif updatePreferences(parameters.store); @@ -1190,43 +1192,27 @@ void WebPage::uninstallPageOverlay(PageOverlay* pageOverlay, bool fadeOut) #endif } -PassRefPtr<WebImage> WebPage::snapshotInViewCoordinates(const IntRect& rect, ImageOptions options) +static ImageOptions snapshotOptionsToImageOptions(SnapshotOptions snapshotOptions) { - FrameView* frameView = m_mainFrame->coreFrame()->view(); - if (!frameView) - return 0; - - IntSize bitmapSize = rect.size(); - float deviceScaleFactor = corePage()->deviceScaleFactor(); - bitmapSize.scale(deviceScaleFactor); - - RefPtr<WebImage> snapshot = WebImage::create(bitmapSize, options); - if (!snapshot->bitmap()) - return 0; - - OwnPtr<WebCore::GraphicsContext> graphicsContext = snapshot->bitmap()->createGraphicsContext(); - graphicsContext->applyDeviceScaleFactor(deviceScaleFactor); - graphicsContext->translate(-rect.x(), -rect.y()); - - frameView->updateLayoutAndStyleIfNeededRecursive(); + unsigned imageOptions = 0; - PaintBehavior oldBehavior = frameView->paintBehavior(); - frameView->setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers); - frameView->paint(graphicsContext.get(), rect); - frameView->setPaintBehavior(oldBehavior); + if (snapshotOptions & SnapshotOptionsShareable) + imageOptions |= ImageOptionsShareable; - return snapshot.release(); + return static_cast<ImageOptions>(imageOptions); } -PassRefPtr<WebImage> WebPage::scaledSnapshotInDocumentCoordinates(const IntRect& rect, double scaleFactor, ImageOptions options) +PassRefPtr<WebImage> WebPage::scaledSnapshotWithOptions(const IntRect& rect, double scaleFactor, SnapshotOptions options) { FrameView* frameView = m_mainFrame->coreFrame()->view(); if (!frameView) return 0; + IntSize bitmapSize = rect.size(); float combinedScaleFactor = scaleFactor * corePage()->deviceScaleFactor(); - IntSize size(ceil(rect.width() * combinedScaleFactor), ceil(rect.height() * combinedScaleFactor)); - RefPtr<WebImage> snapshot = WebImage::create(size, options); + bitmapSize.scale(combinedScaleFactor); + + RefPtr<WebImage> snapshot = WebImage::create(bitmapSize, snapshotOptionsToImageOptions(options)); if (!snapshot->bitmap()) return 0; @@ -1234,21 +1220,15 @@ PassRefPtr<WebImage> WebPage::scaledSnapshotInDocumentCoordinates(const IntRect& graphicsContext->applyDeviceScaleFactor(combinedScaleFactor); graphicsContext->translate(-rect.x(), -rect.y()); - frameView->updateLayoutAndStyleIfNeededRecursive(); + FrameView::SelectionInSnaphot shouldPaintSelection = FrameView::IncludeSelection; + if (options & SnapshotOptionsExcludeSelectionHighlighting) + shouldPaintSelection = FrameView::ExcludeSelection; - PaintBehavior oldBehavior = frameView->paintBehavior(); - frameView->setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers); - frameView->paintContents(graphicsContext.get(), rect); - frameView->setPaintBehavior(oldBehavior); + frameView->paintContentsForSnapshot(graphicsContext.get(), rect, shouldPaintSelection); return snapshot.release(); } -PassRefPtr<WebImage> WebPage::snapshotInDocumentCoordinates(const IntRect& rect, ImageOptions options) -{ - return scaledSnapshotInDocumentCoordinates(rect, 1, options); -} - void WebPage::pageDidScroll() { m_uiClient.pageDidScroll(this); @@ -1854,6 +1834,22 @@ void WebPage::getContentsAsString(uint64_t callbackID) send(Messages::WebPageProxy::StringCallback(resultString, callbackID)); } +#if ENABLE(MHTML) +void WebPage::getContentsAsMHTMLData(uint64_t callbackID, bool useBinaryEncoding) +{ + CoreIPC::DataReference dataReference; + + RefPtr<SharedBuffer> buffer = useBinaryEncoding + ? MHTMLArchive::generateMHTMLDataUsingBinaryEncoding(m_page.get()) + : MHTMLArchive::generateMHTMLData(m_page.get()); + + if (buffer) + dataReference = CoreIPC::DataReference(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size()); + + send(Messages::WebPageProxy::DataCallback(dataReference, callbackID)); +} +#endif + void WebPage::getRenderTreeExternalRepresentation(uint64_t callbackID) { String resultString = renderTreeExternalRepresentation(); @@ -1976,6 +1972,11 @@ void WebPage::updatePreferences(const WebPreferencesStore& store) Settings* settings = m_page->settings(); m_tabToLinks = store.getBoolValueForKey(WebPreferencesKey::tabsToLinksKey()); + m_asynchronousPluginInitializationEnabled = store.getBoolValueForKey(WebPreferencesKey::asynchronousPluginInitializationEnabledKey()); + m_asynchronousPluginInitializationEnabledForAllPlugins = store.getBoolValueForKey(WebPreferencesKey::asynchronousPluginInitializationEnabledForAllPluginsKey()); + m_artificialPluginInitializationDelayEnabled = store.getBoolValueForKey(WebPreferencesKey::artificialPluginInitializationDelayEnabledKey()); + + m_scrollingPerformanceLoggingEnabled = store.getBoolValueForKey(WebPreferencesKey::scrollingPerformanceLoggingEnabledKey()); // FIXME: This should be generated from macro expansion for all preferences, // but we currently don't match the naming of WebCore exactly so we are @@ -2090,9 +2091,12 @@ void WebPage::updatePreferences(const WebPreferencesStore& store) #endif settings->setShouldRespectImageOrientation(store.getBoolValueForKey(WebPreferencesKey::shouldRespectImageOrientationKey())); + settings->setThirdPartyStorageBlockingEnabled(store.getBoolValueForKey(WebPreferencesKey::thirdPartyStorageBlockingEnabledKey())); settings->setDiagnosticLoggingEnabled(store.getBoolValueForKey(WebPreferencesKey::diagnosticLoggingEnabledKey())); + settings->setScrollingPerformanceLoggingEnabled(m_scrollingPerformanceLoggingEnabled); + platformPreferencesDidChange(store); if (m_drawingArea) @@ -3286,4 +3290,15 @@ void WebPage::setVisibilityState(int visibilityState, bool isInitialState) } #endif +void WebPage::setScrollingPerformanceLoggingEnabled(bool enabled) +{ + m_scrollingPerformanceLoggingEnabled = enabled; + + FrameView* frameView = m_mainFrame->coreFrame()->view(); + if (!frameView) + return; + + frameView->setScrollingPerformanceLoggingEnabled(enabled); +} + } // namespace WebKit diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.h b/Source/WebKit2/WebProcess/WebPage/WebPage.h index e3257a33a..bbfabd04a 100644 --- a/Source/WebKit2/WebProcess/WebPage/WebPage.h +++ b/Source/WebKit2/WebProcess/WebPage/WebPage.h @@ -346,9 +346,7 @@ public: WebCore::IntPoint screenToWindow(const WebCore::IntPoint&); WebCore::IntRect windowToScreen(const WebCore::IntRect&); - PassRefPtr<WebImage> snapshotInViewCoordinates(const WebCore::IntRect&, ImageOptions); - PassRefPtr<WebImage> snapshotInDocumentCoordinates(const WebCore::IntRect&, ImageOptions); - PassRefPtr<WebImage> scaledSnapshotInDocumentCoordinates(const WebCore::IntRect&, double scaleFactor, ImageOptions); + PassRefPtr<WebImage> scaledSnapshotWithOptions(const WebCore::IntRect&, double scaleFactor, SnapshotOptions); static const WebEvent* currentEvent(); @@ -570,6 +568,16 @@ public: uint64_t nativeWindowHandle() { return m_nativeWindowHandle; } #endif + bool asynchronousPluginInitializationEnabled() const { return m_asynchronousPluginInitializationEnabled; } + void setAsynchronousPluginInitializationEnabled(bool enabled) { m_asynchronousPluginInitializationEnabled = enabled; } + bool asynchronousPluginInitializationEnabledForAllPlugins() const { return m_asynchronousPluginInitializationEnabledForAllPlugins; } + void setAsynchronousPluginInitializationEnabledForAllPlugins(bool enabled) { m_asynchronousPluginInitializationEnabledForAllPlugins = enabled; } + bool artificialPluginInitializationDelayEnabled() const { return m_artificialPluginInitializationDelayEnabled; } + void setArtificialPluginInitializationDelayEnabled(bool enabled) { m_artificialPluginInitializationDelayEnabled = enabled; } + + bool scrollingPerformanceLoggingEnabled() const { return m_scrollingPerformanceLoggingEnabled; } + void setScrollingPerformanceLoggingEnabled(bool); + private: WebPage(uint64_t pageID, const WebPageCreationParameters&); @@ -650,6 +658,9 @@ private: void viewWillEndLiveResize(); void getContentsAsString(uint64_t callbackID); +#if ENABLE(MHTML) + void getContentsAsMHTMLData(uint64_t callbackID, bool useBinaryEncoding); +#endif void getMainResourceDataOfFrame(uint64_t frameID, uint64_t callbackID); void getResourceDataFromFrame(uint64_t frameID, const String& resourceURL, uint64_t callbackID); void getRenderTreeExternalRepresentation(uint64_t callbackID); @@ -758,6 +769,12 @@ private: bool m_isClosed; bool m_tabToLinks; + + bool m_asynchronousPluginInitializationEnabled; + bool m_asynchronousPluginInitializationEnabledForAllPlugins; + bool m_artificialPluginInitializationDelayEnabled; + + bool m_scrollingPerformanceLoggingEnabled; #if PLATFORM(MAC) // Whether the containing window is visible or not. diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in b/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in index 39c8114b5..e3ff23cad 100644 --- a/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in +++ b/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in @@ -91,6 +91,9 @@ messages -> WebPage { # Callbacks. GetContentsAsString(uint64_t callbackID) +#if ENABLE(MHTML) + GetContentsAsMHTMLData(uint64_t callbackID, bool useBinaryEncoding) +#endif GetMainResourceDataOfFrame(uint64_t frameID, uint64_t callbackID) GetResourceDataFromFrame(uint64_t frameID, WTF::String resourceURL, uint64_t callbackID) GetRenderTreeExternalRepresentation(uint64_t callbackID) diff --git a/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm b/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm index 4dffb6edd..2433d770f 100644 --- a/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm +++ b/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm @@ -212,7 +212,10 @@ void TiledCoreAnimationDrawingArea::updatePreferences() m_debugInfoLayer = nullptr; } + bool scrollingPerformanceLoggingEnabled = m_webPage->scrollingPerformanceLoggingEnabled(); + ScrollingThread::dispatch(bind(&ScrollingTree::setDebugRootLayer, m_webPage->corePage()->scrollingCoordinator()->scrollingTree(), m_debugInfoLayer)); + ScrollingThread::dispatch(bind(&ScrollingTree::setScrollingPerformanceLoggingEnabled, m_webPage->corePage()->scrollingCoordinator()->scrollingTree(), scrollingPerformanceLoggingEnabled)); } void TiledCoreAnimationDrawingArea::dispatchAfterEnsuringUpdatedScrollPosition(const Function<void ()>& functionRef) diff --git a/Source/WebKit2/WebProcess/efl/WebProcessMainEfl.cpp b/Source/WebKit2/WebProcess/efl/WebProcessMainEfl.cpp index 16278a38e..d03acf97a 100644 --- a/Source/WebKit2/WebProcess/efl/WebProcessMainEfl.cpp +++ b/Source/WebKit2/WebProcess/efl/WebProcessMainEfl.cpp @@ -36,6 +36,10 @@ #include <unistd.h> #include <wtf/MainThread.h> +#if USE(COORDINATED_GRAPHICS) +#include "CoordinatedGraphicsLayer.h" +#endif + using namespace WebCore; namespace WebKit { @@ -76,6 +80,12 @@ WK_EXPORT int WebProcessMainEfl(int argc, char* argv[]) g_object_unref(resolverEfl); } +#if USE(COORDINATED_GRAPHICS) + CoordinatedGraphicsLayer::initFactory(); +#endif + + WebCore::ResourceHandle::setIgnoreSSLErrors(true); + int socket = atoi(argv[1]); WebProcess::shared().initialize(socket, RunLoop::main()); RunLoop::run(); diff --git a/Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.cpp b/Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.cpp index 199957f43..defd418a0 100644 --- a/Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.cpp +++ b/Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.cpp @@ -80,6 +80,9 @@ WK_EXPORT int WebProcessMainGtk(int argc, char* argv[]) soup_session_add_feature(session, SOUP_SESSION_FEATURE(soupCache.get())); soup_cache_load(soupCache.get()); + // This is for compatibility, it will be removed when UI process can handle SSL errors. + WebCore::ResourceHandle::setIgnoreSSLErrors(true); + RunLoop::run(); return 0; diff --git a/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm b/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm index 1b67fc6c2..7e926ad3a 100644 --- a/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm +++ b/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm @@ -47,6 +47,10 @@ #import <wtf/text/CString.h> #import <wtf/text/StringBuilder.h> +#if HAVE(XPC) +#import <xpc/xpc.h> +#endif + #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 extern "C" kern_return_t bootstrap_register2(mach_port_t, name_t, mach_port_t, uint64_t); #endif @@ -61,14 +65,51 @@ extern "C" kern_return_t bootstrap_register2(mach_port_t, name_t, mach_port_t, u using namespace WebCore; +#if HAVE(XPC) namespace WebKit { +int WebProcessMainXPC(xpc_connection_t xpcConnection, mach_port_t serverPort); +} -int WebProcessMain(const CommandLine& commandLine) +extern "C" WK_EXPORT int WebKitMainXPC(xpc_connection_t xpcConnection, mach_port_t serverPort); + +int WebKitMainXPC(xpc_connection_t xpcConnection, mach_port_t serverPort) { - // Remove the WebProcess shim from the DYLD_INSERT_LIBRARIES environment variable so any processes spawned by - // the WebProcess don't try to insert the shim and crash. - EnvironmentUtilities::stripValuesEndingWithString("DYLD_INSERT_LIBRARIES", "/WebProcessShim.dylib"); + ASSERT(!objc_collectingEnabled()); + + return WebKit::WebProcessMainXPC(xpcConnection, serverPort); +} +#endif + +namespace WebKit { + +#if HAVE(XPC) + +int WebProcessMainXPC(xpc_connection_t xpcConnection, mach_port_t serverPort) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + InitWebCoreSystemInterface(); + JSC::initializeThreading(); + WTF::initializeMainThread(); + RunLoop::initializeMainRunLoop(); + + // Initialize the shim. + // FIXME: Make the shim work. + WebProcess::shared().initializeShim(); + + // Create the connection. + WebProcess::shared().initialize(CoreIPC::Connection::Identifier(serverPort, xpcConnection), RunLoop::main()); + + WKAXRegisterRemoteApp(); + [pool drain]; + + return 0; +} +#endif + +int WebProcessMain(const CommandLine& commandLine) +{ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; String serviceName = commandLine["servicename"]; @@ -165,7 +206,7 @@ int WebProcessMain(const CommandLine& commandLine) WebProcess::shared().initializeShim(); // Create the connection. - WebProcess::shared().initialize(serverPort, RunLoop::main()); + WebProcess::shared().initialize(CoreIPC::Connection::Identifier(serverPort), RunLoop::main()); [pool drain]; diff --git a/Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp b/Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp index cb72cb9be..28b200d13 100644 --- a/Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp +++ b/Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp @@ -38,7 +38,7 @@ #include <wtf/MainThread.h> #if USE(ACCELERATED_COMPOSITING) -#include "WebGraphicsLayer.h" +#include "CoordinatedGraphicsLayer.h" #endif #if USE(QTKIT) #include "WebSystemInterface.h" @@ -181,7 +181,7 @@ Q_DECL_EXPORT int WebProcessMainQt(QGuiApplication* app) } #endif #if USE(ACCELERATED_COMPOSITING) - WebGraphicsLayer::initFactory(); + CoordinatedGraphicsLayer::initFactory(); #endif WebKit::WebProcess::shared().initialize(identifier, RunLoop::main()); |
