- Revision
- 163972
- Author
- [email protected]
- Date
- 2014-02-12 12:32:46 -0800 (Wed, 12 Feb 2014)
Log Message
[CoordinatedGraphics] Move CoordinatedGraphicsScene, CoordinatedLayerTreeHostProxy to std::function
https://bugs.webkit.org/show_bug.cgi?id=128473
Reviewed by Anders Carlsson.
Source/WebCore:
Move the CoordinatedGraphicsScene class to using std::function instead of WTF::Functional and std::bind
instead of WTF::bind. The function wrapper is now moved through function calls and not passed by reference,
and lambda functions are inlined into the dispatchOnMainThread() calls, with the CoordinatedGraphicsScene
refcount-protected.
* platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.cpp:
(WebCore::CoordinatedGraphicsScene::dispatchOnMainThread):
(WebCore::CoordinatedGraphicsScene::paintToCurrentGLContext):
(WebCore::CoordinatedGraphicsScene::commitSceneState):
(WebCore::CoordinatedGraphicsScene::syncRemoteContent):
(WebCore::CoordinatedGraphicsScene::purgeGLResources):
(WebCore::CoordinatedGraphicsScene::commitScrollOffset):
(WebCore::CoordinatedGraphicsScene::appendUpdate):
(WebCore::CoordinatedGraphicsScene::setActive):
* platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.h:
Source/WebKit2:
Move the CoordinatedLayerTreeHostProxy class to using std::function instead of WTF::Functional. C++11
lambdas are used to construct the update functions, with the CoordinatedGraphicsScene refcount-protected
throughout the lifetime of the function wrapper.
* UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.cpp:
(WebKit::CoordinatedLayerTreeHostProxy::dispatchUpdate):
(WebKit::CoordinatedLayerTreeHostProxy::commitCoordinatedGraphicsState):
(WebKit::CoordinatedLayerTreeHostProxy::setVisibleContentsRect):
(WebKit::CoordinatedLayerTreeHostProxy::setBackgroundColor):
* UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (163971 => 163972)
--- trunk/Source/WebCore/ChangeLog 2014-02-12 20:29:33 UTC (rev 163971)
+++ trunk/Source/WebCore/ChangeLog 2014-02-12 20:32:46 UTC (rev 163972)
@@ -1,3 +1,27 @@
+2014-02-12 Zan Dobersek <[email protected]>
+
+ [CoordinatedGraphics] Move CoordinatedGraphicsScene, CoordinatedLayerTreeHostProxy to std::function
+ https://bugs.webkit.org/show_bug.cgi?id=128473
+
+ Reviewed by Anders Carlsson.
+
+
+ Move the CoordinatedGraphicsScene class to using std::function instead of WTF::Functional and std::bind
+ instead of WTF::bind. The function wrapper is now moved through function calls and not passed by reference,
+ and lambda functions are inlined into the dispatchOnMainThread() calls, with the CoordinatedGraphicsScene
+ refcount-protected.
+
+ * platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.cpp:
+ (WebCore::CoordinatedGraphicsScene::dispatchOnMainThread):
+ (WebCore::CoordinatedGraphicsScene::paintToCurrentGLContext):
+ (WebCore::CoordinatedGraphicsScene::commitSceneState):
+ (WebCore::CoordinatedGraphicsScene::syncRemoteContent):
+ (WebCore::CoordinatedGraphicsScene::purgeGLResources):
+ (WebCore::CoordinatedGraphicsScene::commitScrollOffset):
+ (WebCore::CoordinatedGraphicsScene::appendUpdate):
+ (WebCore::CoordinatedGraphicsScene::setActive):
+ * platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.h:
+
2014-02-12 Eric Carlson <[email protected]>
Cleanup the code added for https://bugs.webkit.org/show_bug.cgi?id=128125.
Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.cpp (163971 => 163972)
--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.cpp 2014-02-12 20:29:33 UTC (rev 163971)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.cpp 2014-02-12 20:32:46 UTC (rev 163972)
@@ -34,12 +34,12 @@
namespace WebCore {
-void CoordinatedGraphicsScene::dispatchOnMainThread(const Function<void()>& function)
+void CoordinatedGraphicsScene::dispatchOnMainThread(std::function<void()> function)
{
if (isMainThread())
function();
else
- callOnMainThread(function);
+ callOnMainThread(std::move(function));
}
static bool layerShouldHaveBackingStore(TextureMapperLayer* layer)
@@ -98,8 +98,12 @@
m_textureMapper->endClip();
m_textureMapper->endPainting();
- if (currentRootLayer->descendantsOrSelfHaveRunningAnimations())
- dispatchOnMainThread(bind(&CoordinatedGraphicsScene::updateViewport, this));
+ if (currentRootLayer->descendantsOrSelfHaveRunningAnimations()) {
+ RefPtr<CoordinatedGraphicsScene> protector(this);
+ dispatchOnMainThread([=] {
+ protector->updateViewport();
+ });
+ }
}
void CoordinatedGraphicsScene::paintToGraphicsContext(PlatformGraphicsContext* platformContext)
@@ -576,7 +580,10 @@
removeReleasedImageBackingsIfNeeded();
// The pending tiles state is on its way for the screen, tell the web process to render the next one.
- dispatchOnMainThread(bind(&CoordinatedGraphicsScene::renderNextFrame, this));
+ RefPtr<CoordinatedGraphicsScene> protector(this);
+ dispatchOnMainThread([=] {
+ protector->renderNextFrame();
+ });
}
void CoordinatedGraphicsScene::renderNextFrame()
@@ -607,16 +614,16 @@
// We enqueue messages and execute them during paint, as they require an active GL context.
ensureRootLayer();
- Vector<Function<void()> > renderQueue;
+ Vector<std::function<void()>> renderQueue;
bool calledOnMainThread = WTF::isMainThread();
if (!calledOnMainThread)
m_renderQueueMutex.lock();
- renderQueue.swap(m_renderQueue);
+ renderQueue = std::move(m_renderQueue);
if (!calledOnMainThread)
m_renderQueueMutex.unlock();
- for (size_t i = 0; i < renderQueue.size(); ++i)
- renderQueue[i]();
+ for (auto& function : renderQueue)
+ function();
}
void CoordinatedGraphicsScene::purgeGLResources()
@@ -637,7 +644,11 @@
m_backingStoresWithPendingBuffers.clear();
setActive(false);
- dispatchOnMainThread(bind(&CoordinatedGraphicsScene::purgeBackingStores, this));
+
+ RefPtr<CoordinatedGraphicsScene> protector(this);
+ dispatchOnMainThread([=] {
+ protector->purgeBackingStores();
+ });
}
void CoordinatedGraphicsScene::dispatchCommitScrollOffset(uint32_t layerID, const IntSize& offset)
@@ -647,7 +658,10 @@
void CoordinatedGraphicsScene::commitScrollOffset(uint32_t layerID, const IntSize& offset)
{
- dispatchOnMainThread(bind(&CoordinatedGraphicsScene::dispatchCommitScrollOffset, this, layerID, offset));
+ RefPtr<CoordinatedGraphicsScene> protector(this);
+ dispatchOnMainThread([=] {
+ protector->dispatchCommitScrollOffset(layerID, offset);
+ });
}
void CoordinatedGraphicsScene::purgeBackingStores()
@@ -671,14 +685,14 @@
m_client = 0;
}
-void CoordinatedGraphicsScene::appendUpdate(const Function<void()>& function)
+void CoordinatedGraphicsScene::appendUpdate(std::function<void()> function)
{
if (!m_isActive)
return;
ASSERT(isMainThread());
MutexLocker locker(m_renderQueueMutex);
- m_renderQueue.append(function);
+ m_renderQueue.append(std::move(function));
}
void CoordinatedGraphicsScene::setActive(bool active)
@@ -691,8 +705,12 @@
// and cannot be applied to the newly created instance.
m_renderQueue.clear();
m_isActive = active;
- if (m_isActive)
- dispatchOnMainThread(bind(&CoordinatedGraphicsScene::renderNextFrame, this));
+ if (m_isActive) {
+ RefPtr<CoordinatedGraphicsScene> protector(this);
+ dispatchOnMainThread([=] {
+ protector->renderNextFrame();
+ });
+ }
}
void CoordinatedGraphicsScene::setBackgroundColor(const Color& color)
Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.h (163971 => 163972)
--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.h 2014-02-12 20:29:33 UTC (rev 163971)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.h 2014-02-12 20:32:46 UTC (rev 163972)
@@ -35,7 +35,7 @@
#include "TextureMapperFPSCounter.h"
#include "TextureMapperLayer.h"
#include "Timer.h"
-#include <wtf/Functional.h>
+#include <functional>
#include <wtf/HashSet.h>
#include <wtf/ThreadingPrimitives.h>
#include <wtf/Vector.h>
@@ -65,7 +65,7 @@
void paintToGraphicsContext(PlatformGraphicsContext*);
void setScrollPosition(const FloatPoint&);
void detach();
- void appendUpdate(const Function<void()>&);
+ void appendUpdate(std::function<void()>);
WebCore::TextureMapperLayer* findScrollableContentsLayerAt(const WebCore::FloatPoint&);
@@ -125,7 +125,7 @@
void syncRemoteContent();
void adjustPositionForFixedLayers();
- void dispatchOnMainThread(const Function<void()>&);
+ void dispatchOnMainThread(std::function<void()>);
void updateViewport();
void renderNextFrame();
void purgeBackingStores();
@@ -146,7 +146,7 @@
void dispatchCommitScrollOffset(uint32_t layerID, const IntSize& offset);
// Render queue can be accessed ony from main thread or updatePaintNode call stack!
- Vector<Function<void()> > m_renderQueue;
+ Vector<std::function<void()>> m_renderQueue;
Mutex m_renderQueueMutex;
OwnPtr<TextureMapper> m_textureMapper;
Modified: trunk/Source/WebKit2/ChangeLog (163971 => 163972)
--- trunk/Source/WebKit2/ChangeLog 2014-02-12 20:29:33 UTC (rev 163971)
+++ trunk/Source/WebKit2/ChangeLog 2014-02-12 20:32:46 UTC (rev 163972)
@@ -1,3 +1,21 @@
+2014-02-12 Zan Dobersek <[email protected]>
+
+ [CoordinatedGraphics] Move CoordinatedGraphicsScene, CoordinatedLayerTreeHostProxy to std::function
+ https://bugs.webkit.org/show_bug.cgi?id=128473
+
+ Reviewed by Anders Carlsson.
+
+ Move the CoordinatedLayerTreeHostProxy class to using std::function instead of WTF::Functional. C++11
+ lambdas are used to construct the update functions, with the CoordinatedGraphicsScene refcount-protected
+ throughout the lifetime of the function wrapper.
+
+ * UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.cpp:
+ (WebKit::CoordinatedLayerTreeHostProxy::dispatchUpdate):
+ (WebKit::CoordinatedLayerTreeHostProxy::commitCoordinatedGraphicsState):
+ (WebKit::CoordinatedLayerTreeHostProxy::setVisibleContentsRect):
+ (WebKit::CoordinatedLayerTreeHostProxy::setBackgroundColor):
+ * UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.h:
+
2014-02-12 Dan Bernstein <[email protected]>
Stop using PLATFORM(MAC) in WebKit2/{Database,Network}Process except where it means “OS X but not iOS”
Modified: trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.cpp (163971 => 163972)
--- trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.cpp 2014-02-12 20:29:33 UTC (rev 163971)
+++ trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.cpp 2014-02-12 20:32:46 UTC (rev 163972)
@@ -52,14 +52,18 @@
m_drawingAreaProxy->updateViewport();
}
-void CoordinatedLayerTreeHostProxy::dispatchUpdate(const Function<void()>& function)
+void CoordinatedLayerTreeHostProxy::dispatchUpdate(std::function<void()> function)
{
- m_scene->appendUpdate(function);
+ m_scene->appendUpdate(std::move(function));
}
void CoordinatedLayerTreeHostProxy::commitCoordinatedGraphicsState(const CoordinatedGraphicsState& graphicsState)
{
- dispatchUpdate(bind(&CoordinatedGraphicsScene::commitSceneState, m_scene.get(), graphicsState));
+ RefPtr<CoordinatedGraphicsScene> sceneProtector(m_scene);
+ dispatchUpdate([=] {
+ sceneProtector->commitSceneState(graphicsState);
+ });
+
updateViewport();
#if USE(TILED_BACKING_STORE)
m_drawingAreaProxy->page()->didRenderFrame(graphicsState.contentsSize, graphicsState.coveredRect);
@@ -69,7 +73,11 @@
void CoordinatedLayerTreeHostProxy::setVisibleContentsRect(const FloatRect& rect, const FloatPoint& trajectoryVector)
{
// Inform the renderer to adjust viewport-fixed layers.
- dispatchUpdate(bind(&CoordinatedGraphicsScene::setScrollPosition, m_scene.get(), rect.location()));
+ RefPtr<CoordinatedGraphicsScene> sceneProtector(m_scene);
+ const FloatPoint& scrollPosition = rect.location();
+ dispatchUpdate([=] {
+ sceneProtector->setScrollPosition(scrollPosition);
+ });
if (rect == m_lastSentVisibleRect && trajectoryVector == m_lastSentTrajectoryVector)
return;
@@ -91,7 +99,10 @@
void CoordinatedLayerTreeHostProxy::setBackgroundColor(const Color& color)
{
- dispatchUpdate(bind(&CoordinatedGraphicsScene::setBackgroundColor, m_scene.get(), color));
+ RefPtr<CoordinatedGraphicsScene> sceneProtector(m_scene);
+ dispatchUpdate([=] {
+ sceneProtector->setBackgroundColor(color);
+ });
}
void CoordinatedLayerTreeHostProxy::commitScrollOffset(uint32_t layerID, const IntSize& offset)
Modified: trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.h (163971 => 163972)
--- trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.h 2014-02-12 20:29:33 UTC (rev 163971)
+++ trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.h 2014-02-12 20:32:46 UTC (rev 163972)
@@ -26,7 +26,7 @@
#include "CoordinatedGraphicsArgumentCoders.h"
#include "MessageReceiver.h"
#include <WebCore/CoordinatedGraphicsScene.h>
-#include <wtf/Functional.h>
+#include <functional>
namespace WebCore {
class CoordinatedGraphicsState;
@@ -57,7 +57,7 @@
virtual void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset);
protected:
- void dispatchUpdate(const Function<void()>&);
+ void dispatchUpdate(std::function<void()>);
// IPC::MessageReceiver
virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override;