WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-236836-20220218153710.patch (text/plain), 50.24 KB, created by
Zan Dobersek
on 2022-02-18 06:37:12 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Zan Dobersek
Created:
2022-02-18 06:37:12 PST
Size:
50.24 KB
patch
obsolete
>Subversion Revision: 290121 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 08e737f6707b49f7c2b532825f0561de84cea650..bd0ce4b62bd95c8f7ac6d9b4c8e0ad6d32e9eab9 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,81 @@ >+2022-02-18 Zan Dobersek <zdobersek@igalia.com> >+ >+ [TextureMapper] Refactor TextureMapperPlatformLayerProxy into specializable implementations >+ https://bugs.webkit.org/show_bug.cgi?id=236836 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Turn TextureMapperPlatformLayerProxy into an abstract class from which >+ different specializations can then be derived. Current implementation is >+ spun off into the TextureMapperPlatformLayerProxyGL class, and type >+ traits specialization facilities are provided for future parallel >+ implementations (e.g. a DMABuf-consuming proxy class). >+ >+ Existing uses of TextureMapperPlatformLayerProxy are updated to use >+ the TextureMapperPlatformLayerProxyGL class instead. Downcasting is >+ done as necessary, with asserts checking for the expected implementation >+ type. >+ >+ No change in functionality, only refactoring existing code. >+ >+ * platform/TextureMapper.cmake: >+ * platform/graphics/gstreamer/GStreamerVideoFrameHolder.h: >+ * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: >+ (WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer): >+ (WebCore::MediaPlayerPrivateGStreamer::pushTextureToCompositor): >+ (WebCore::MediaPlayerPrivateGStreamer::triggerRepaint): >+ (WebCore::MediaPlayerPrivateGStreamer::flushCurrentBuffer): >+ (WebCore::MediaPlayerPrivateGStreamer::pushNextHolePunchBuffer): >+ * platform/graphics/holepunch/MediaPlayerPrivateHolePunch.cpp: >+ (WebCore::MediaPlayerPrivateHolePunch::MediaPlayerPrivateHolePunch): >+ (WebCore::MediaPlayerPrivateHolePunch::pushNextHolePunchBuffer): >+ * platform/graphics/nicosia/NicosiaImageBufferPipe.cpp: >+ (Nicosia::NicosiaImageBufferPipeSource::handle): >+ * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp: >+ (Nicosia::ContentLayerTextureMapperImpl::createFactory): >+ (Nicosia::ContentLayerTextureMapperImpl::ContentLayerTextureMapperImpl): >+ * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.h: >+ * platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp: >+ (Nicosia::GCGLANGLELayer::swapBuffersIfNeeded): >+ * platform/graphics/nicosia/texmap/NicosiaGCGLLayer.cpp: >+ (Nicosia::GCGLLayer::swapBuffersIfNeeded): >+ * platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp: >+ (WebCore::TextureMapperGCGLPlatformLayer::TextureMapperGCGLPlatformLayer): >+ (WebCore::TextureMapperGCGLPlatformLayer::swapBuffersIfNeeded): >+ * platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp: >+ (WebCore::TextureMapperPlatformLayerProxy::TextureMapperPlatformLayerProxy): Deleted. >+ (WebCore::TextureMapperPlatformLayerProxy::~TextureMapperPlatformLayerProxy): Deleted. >+ (WebCore::TextureMapperPlatformLayerProxy::activateOnCompositingThread): Deleted. >+ (WebCore::TextureMapperPlatformLayerProxy::invalidate): Deleted. >+ (WebCore::TextureMapperPlatformLayerProxy::pushNextBuffer): Deleted. >+ (WebCore::TextureMapperPlatformLayerProxy::getAvailableBuffer): Deleted. >+ (WebCore::TextureMapperPlatformLayerProxy::appendToUnusedBuffers): Deleted. >+ (WebCore::TextureMapperPlatformLayerProxy::scheduleReleaseUnusedBuffers): Deleted. >+ (WebCore::TextureMapperPlatformLayerProxy::releaseUnusedBuffersTimerFired): Deleted. >+ (WebCore::TextureMapperPlatformLayerProxy::swapBuffer): Deleted. >+ (WebCore::TextureMapperPlatformLayerProxy::dropCurrentBufferWhilePreservingTexture): Deleted. >+ (WebCore::TextureMapperPlatformLayerProxy::scheduleUpdateOnCompositorThread): Deleted. >+ (WebCore::TextureMapperPlatformLayerProxy::compositorThreadUpdateTimerFired): Deleted. >+ * platform/graphics/texmap/TextureMapperPlatformLayerProxy.h: >+ (WebCore::TextureMapperPlatformLayerProxy::isGLBased const): >+ (WebCore::TextureMapperPlatformLayerProxy::isDMABufBased const): >+ (WebCore::TextureMapperPlatformLayerProxy::WTF_RETURNS_LOCK): >+ (WebCore::TextureMapperPlatformLayerProxy::WTF_GUARDED_BY_LOCK): Deleted. >+ * platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.cpp: Copied from Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp. >+ (WebCore::TextureMapperPlatformLayerProxyGL::~TextureMapperPlatformLayerProxyGL): >+ (WebCore::TextureMapperPlatformLayerProxyGL::activateOnCompositingThread): >+ (WebCore::TextureMapperPlatformLayerProxyGL::invalidate): >+ (WebCore::TextureMapperPlatformLayerProxyGL::pushNextBuffer): >+ (WebCore::TextureMapperPlatformLayerProxyGL::getAvailableBuffer): >+ (WebCore::TextureMapperPlatformLayerProxyGL::appendToUnusedBuffers): >+ (WebCore::TextureMapperPlatformLayerProxyGL::scheduleReleaseUnusedBuffers): >+ (WebCore::TextureMapperPlatformLayerProxyGL::releaseUnusedBuffersTimerFired): >+ (WebCore::TextureMapperPlatformLayerProxyGL::swapBuffer): >+ (WebCore::TextureMapperPlatformLayerProxyGL::dropCurrentBufferWhilePreservingTexture): >+ (WebCore::TextureMapperPlatformLayerProxyGL::scheduleUpdateOnCompositorThread): >+ (WebCore::TextureMapperPlatformLayerProxyGL::compositorThreadUpdateTimerFired): >+ * platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.h: Copied from Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h. >+ > 2022-02-18 Antoine Quint <graouts@webkit.org> > > [frame-rate] animation with different but compatible frame rates should be aligned >diff --git a/Source/WebCore/platform/TextureMapper.cmake b/Source/WebCore/platform/TextureMapper.cmake >index f6c6eefd8a928b827c82b888af14a57dbda44461..e32f26d527df5131e7998387c5401b30e5676919 100644 >--- a/Source/WebCore/platform/TextureMapper.cmake >+++ b/Source/WebCore/platform/TextureMapper.cmake >@@ -36,6 +36,7 @@ list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS > platform/graphics/texmap/TextureMapperLayer.h > platform/graphics/texmap/TextureMapperPlatformLayer.h > platform/graphics/texmap/TextureMapperPlatformLayerProxy.h >+ platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.h > platform/graphics/texmap/TextureMapperPlatformLayerProxyProvider.h > platform/graphics/texmap/TextureMapperSolidColorLayer.h > platform/graphics/texmap/TextureMapperTile.h >@@ -61,6 +62,7 @@ if (USE_COORDINATED_GRAPHICS) > platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp > platform/graphics/texmap/TextureMapperPlatformLayerDmabuf.cpp > platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp >+ platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.cpp > > platform/graphics/texmap/coordinated/CoordinatedBackingStore.cpp > platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp >diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameHolder.h b/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameHolder.h >index ecd1b19b6176ea4ce3c17e9f25c4318d3f34bda9..fe49b584cda9d135136112fd7c88cfaa44f587fa 100644 >--- a/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameHolder.h >+++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameHolder.h >@@ -24,7 +24,6 @@ > > #include "MediaPlayerPrivateGStreamer.h" > #include "TextureMapperPlatformLayerBuffer.h" >-#include "TextureMapperPlatformLayerProxy.h" > > namespace WebCore { > >diff --git a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp >index 70c696d8853b7d7c28c40e4fdd25d56572500b0e..0fd367e4f69d7fff8e817811ba2959416ed6228c 100644 >--- a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp >+++ b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp >@@ -115,7 +115,7 @@ > #include "GStreamerVideoFrameHolder.h" > #include "TextureMapperContextAttributes.h" > #include "TextureMapperPlatformLayerBuffer.h" >-#include "TextureMapperPlatformLayerProxy.h" >+#include "TextureMapperPlatformLayerProxyGL.h" > #endif // USE(TEXTURE_MAPPER_GL) > > #if USE(WPE_VIDEO_PLANE_DISPLAY_DMABUF) >@@ -160,7 +160,7 @@ MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer(MediaPlayer* player) > #if USE(NICOSIA) > , m_nicosiaLayer(Nicosia::ContentLayer::create(Nicosia::ContentLayerTextureMapperImpl::createFactory(*this))) > #else >- , m_platformLayerProxy(adoptRef(new TextureMapperPlatformLayerProxy())) >+ , m_platformLayerProxy(adoptRef(new TextureMapperPlatformLayerProxyGL)) > #endif > #endif > #if !RELEASE_LOG_DISABLED >@@ -2919,7 +2919,7 @@ void MediaPlayerPrivateGStreamer::pushTextureToCompositor() > > ++m_sampleCount; > >- auto internalCompositingOperation = [this](TextureMapperPlatformLayerProxy& proxy, std::unique_ptr<GstVideoFrameHolder>&& frameHolder) { >+ auto internalCompositingOperation = [this](TextureMapperPlatformLayerProxyGL& proxy, std::unique_ptr<GstVideoFrameHolder>&& frameHolder) { > std::unique_ptr<TextureMapperPlatformLayerBuffer> layerBuffer; > if (frameHolder->hasMappedTextures()) { > layerBuffer = frameHolder->platformLayerBuffer(); >@@ -2941,7 +2941,7 @@ void MediaPlayerPrivateGStreamer::pushTextureToCompositor() > > #if USE(WPE_VIDEO_PLANE_DISPLAY_DMABUF) > auto proxyOperation = >- [this, internalCompositingOperation](TextureMapperPlatformLayerProxy& proxy) >+ [this, internalCompositingOperation](TextureMapperPlatformLayerProxyGL& proxy) > { > Locker locker { proxy.lock() }; > >@@ -2959,7 +2959,7 @@ void MediaPlayerPrivateGStreamer::pushTextureToCompositor() > }; > #else > auto proxyOperation = >- [this, internalCompositingOperation](TextureMapperPlatformLayerProxy& proxy) >+ [this, internalCompositingOperation](TextureMapperPlatformLayerProxyGL& proxy) > { > Locker locker { proxy.lock() }; > >@@ -2972,7 +2972,9 @@ void MediaPlayerPrivateGStreamer::pushTextureToCompositor() > #endif // USE(WPE_VIDEO_PLANE_DISPLAY_DMABUF) > > #if USE(NICOSIA) >- proxyOperation(downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy()); >+ auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy(); >+ ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy)); >+ proxyOperation(downcast<TextureMapperPlatformLayerProxyGL>(proxy)); > #else > proxyOperation(*m_platformLayerProxy); > #endif >@@ -3168,12 +3170,14 @@ void MediaPlayerPrivateGStreamer::triggerRepaint(GstSample* sample) > if (m_isUsingFallbackVideoSink) { > Locker locker { m_drawLock }; > auto proxyOperation = >- [this](TextureMapperPlatformLayerProxy& proxy) >+ [this](TextureMapperPlatformLayerProxyGL& proxy) > { > return proxy.scheduleUpdateOnCompositorThread([this] { this->pushTextureToCompositor(); }); > }; > #if USE(NICOSIA) >- if (!proxyOperation(downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy())) >+ auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy(); >+ ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy)); >+ if (!proxyOperation(downcast<TextureMapperPlatformLayerProxyGL>(proxy))) > return; > #else > if (!proxyOperation(*m_platformLayerProxy)) >@@ -3231,7 +3235,7 @@ void MediaPlayerPrivateGStreamer::flushCurrentBuffer() > } > > bool shouldWait = m_videoDecoderPlatform == GstVideoDecoderPlatform::Video4Linux; >- auto proxyOperation = [shouldWait, pipeline = pipeline()](TextureMapperPlatformLayerProxy& proxy) { >+ auto proxyOperation = [shouldWait, pipeline = pipeline()](TextureMapperPlatformLayerProxyGL& proxy) { > GST_DEBUG_OBJECT(pipeline, "Flushing video sample %s", shouldWait ? "synchronously" : ""); > if (shouldWait) { > if (proxy.isActive()) >@@ -3244,7 +3248,9 @@ void MediaPlayerPrivateGStreamer::flushCurrentBuffer() > }; > > #if USE(NICOSIA) >- proxyOperation(downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy()); >+ auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy(); >+ if (is<TextureMapperPlatformLayerProxyGL>(proxy)) >+ proxyOperation(downcast<TextureMapperPlatformLayerProxyGL>(proxy)); > #else > proxyOperation(*m_platformLayerProxy); > #endif >@@ -3471,7 +3477,7 @@ GstElement* MediaPlayerPrivateGStreamer::createHolePunchVideoSink() > void MediaPlayerPrivateGStreamer::pushNextHolePunchBuffer() > { > auto proxyOperation = >- [this](TextureMapperPlatformLayerProxy& proxy) >+ [this](TextureMapperPlatformLayerProxyGL& proxy) > { > Locker locker { proxy.lock() }; > std::unique_ptr<TextureMapperPlatformLayerBuffer> layerBuffer = makeUnique<TextureMapperPlatformLayerBuffer>(0, m_size, TextureMapperGL::ShouldNotBlend, GL_DONT_CARE); >@@ -3481,7 +3487,9 @@ void MediaPlayerPrivateGStreamer::pushNextHolePunchBuffer() > }; > > #if USE(NICOSIA) >- proxyOperation(downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy()); >+ auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy(); >+ ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy)); >+ proxyOperation(downcast<TextureMapperPlatformLayerProxyGL>(proxy)); > #else > proxyOperation(*m_platformLayerProxy); > #endif >diff --git a/Source/WebCore/platform/graphics/holepunch/MediaPlayerPrivateHolePunch.cpp b/Source/WebCore/platform/graphics/holepunch/MediaPlayerPrivateHolePunch.cpp >index 901d57efd6f4139a9d3a2c8c11bccecabbc10c07..b37d5cc1cafec689c6b2aeef92f79298c597e9fc 100644 >--- a/Source/WebCore/platform/graphics/holepunch/MediaPlayerPrivateHolePunch.cpp >+++ b/Source/WebCore/platform/graphics/holepunch/MediaPlayerPrivateHolePunch.cpp >@@ -24,7 +24,7 @@ > #if USE(EXTERNAL_HOLEPUNCH) > #include "MediaPlayer.h" > #include "TextureMapperPlatformLayerBuffer.h" >-#include "TextureMapperPlatformLayerProxy.h" >+#include "TextureMapperPlatformLayerProxyGL.h" > > namespace WebCore { > >@@ -36,7 +36,7 @@ MediaPlayerPrivateHolePunch::MediaPlayerPrivateHolePunch(MediaPlayer* player) > #if USE(NICOSIA) > , m_nicosiaLayer(Nicosia::ContentLayer::create(Nicosia::ContentLayerTextureMapperImpl::createFactory(*this))) > #else >- , m_platformLayerProxy(adoptRef(new TextureMapperPlatformLayerProxy())) >+ , m_platformLayerProxy(adoptRef(new TextureMapperPlatformLayerProxyGL)) > #endif > { > pushNextHolePunchBuffer(); >@@ -73,7 +73,7 @@ FloatSize MediaPlayerPrivateHolePunch::naturalSize() const > void MediaPlayerPrivateHolePunch::pushNextHolePunchBuffer() > { > auto proxyOperation = >- [this](TextureMapperPlatformLayerProxy& proxy) >+ [this](TextureMapperPlatformLayerProxyGL& proxy) > { > Locker locker { proxy.lock() }; > std::unique_ptr<TextureMapperPlatformLayerBuffer> layerBuffer = makeUnique<TextureMapperPlatformLayerBuffer>(0, m_size, TextureMapperGL::ShouldNotBlend, GL_DONT_CARE); >@@ -81,7 +81,9 @@ void MediaPlayerPrivateHolePunch::pushNextHolePunchBuffer() > }; > > #if USE(NICOSIA) >- proxyOperation(downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy()); >+ auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy(); >+ ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy)); >+ proxyOperation(downcast<TextureMapperPlatformLayerProxyGL>(proxy)); > #else > proxyOperation(*m_platformLayerProxy); > #endif >diff --git a/Source/WebCore/platform/graphics/nicosia/NicosiaImageBufferPipe.cpp b/Source/WebCore/platform/graphics/nicosia/NicosiaImageBufferPipe.cpp >index 638463fb3f25e5bdbdaf9789e4af90714a656961..d8cc9815d9a857cd1fcc1e1079256ed18dc6259d 100644 >--- a/Source/WebCore/platform/graphics/nicosia/NicosiaImageBufferPipe.cpp >+++ b/Source/WebCore/platform/graphics/nicosia/NicosiaImageBufferPipe.cpp >@@ -31,7 +31,7 @@ > #include "NativeImage.h" > #include "NicosiaPlatformLayer.h" > #include "TextureMapperPlatformLayerBuffer.h" >-#include "TextureMapperPlatformLayerProxy.h" >+#include "TextureMapperPlatformLayerProxyGL.h" > > #if USE(CAIRO) > #include <cairo.h> >@@ -62,7 +62,7 @@ void NicosiaImageBufferPipeSource::handle(RefPtr<ImageBuffer>&& buffer) > > if (!m_imageBuffer) { > auto proxyOperation = [this] (TextureMapperPlatformLayerProxy& proxy) mutable { >- return proxy.scheduleUpdateOnCompositorThread([this] () mutable { >+ return downcast<TextureMapperPlatformLayerProxyGL>(proxy).scheduleUpdateOnCompositorThread([this] () mutable { > auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy(); > Locker locker { proxy.lock() }; > >@@ -95,7 +95,7 @@ void NicosiaImageBufferPipeSource::handle(RefPtr<ImageBuffer>&& buffer) > > auto layerBuffer = makeUnique<TextureMapperPlatformLayerBuffer>(WTFMove(texture)); > layerBuffer->setExtraFlags(TextureMapperGL::ShouldBlend); >- proxy.pushNextBuffer(WTFMove(layerBuffer)); >+ downcast<TextureMapperPlatformLayerProxyGL>(proxy).pushNextBuffer(WTFMove(layerBuffer)); > }); > }; > proxyOperation(downcast<Nicosia::ContentLayerTextureMapperImpl>(m_nicosiaLayer->impl()).proxy()); >diff --git a/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp b/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp >index f623e6342545a889d2e04adb98ea1cdad7e960ef..022844b32670453c6cc775544c296b5d6083c4e9 100644 >--- a/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp >+++ b/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp >@@ -31,7 +31,7 @@ > > #if USE(TEXTURE_MAPPER) > >-#include "TextureMapperPlatformLayerProxy.h" >+#include "TextureMapperPlatformLayerProxyGL.h" > > namespace Nicosia { > >@@ -39,12 +39,12 @@ auto ContentLayerTextureMapperImpl::createFactory(Client& client) -> Factory > { > return Factory( > [&client](ContentLayer&) { >- return makeUnique<ContentLayerTextureMapperImpl>(client); >+ return makeUnique<ContentLayerTextureMapperImpl>(client, adoptRef(*new WebCore::TextureMapperPlatformLayerProxyGL)); > }); > } > >-ContentLayerTextureMapperImpl::ContentLayerTextureMapperImpl(Client& client) >- : m_proxy(adoptRef(*new WebCore::TextureMapperPlatformLayerProxy)) >+ContentLayerTextureMapperImpl::ContentLayerTextureMapperImpl(Client& client, Ref<WebCore::TextureMapperPlatformLayerProxy>&& proxy) >+ : m_proxy(WTFMove(proxy)) > , m_client { { }, &client } > { > } >diff --git a/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.h b/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.h >index b0105b73ac2264f57ca7b7e503ecf70da527da7e..97e305913cc8426b37b837c4d3e69da7e3b3076b 100644 >--- a/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.h >+++ b/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.h >@@ -51,7 +51,7 @@ public: > > static Factory createFactory(Client&); > >- explicit ContentLayerTextureMapperImpl(Client&); >+ explicit ContentLayerTextureMapperImpl(Client&, Ref<WebCore::TextureMapperPlatformLayerProxy>&&); > virtual ~ContentLayerTextureMapperImpl(); > bool isTextureMapperImpl() const override { return true; } > >diff --git a/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp b/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp >index 70f962247998c56fe43be5a68699105acb7ab18c..991741836d441bf9681cde9662c27528c5d070b6 100644 >--- a/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp >+++ b/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp >@@ -36,7 +36,7 @@ > #include "Logging.h" > #include "TextureMapperGL.h" > #include "TextureMapperPlatformLayerDmabuf.h" >-#include "TextureMapperPlatformLayerProxy.h" >+#include "TextureMapperPlatformLayerProxyGL.h" > > namespace Nicosia { > >@@ -62,7 +62,8 @@ void GCGLANGLELayer::swapBuffersIfNeeded() > > { > Locker locker { proxy.lock() }; >- proxy.pushNextBuffer(makeUnique<TextureMapperPlatformLayerDmabuf>(size, format, stride, fd)); >+ ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy)); >+ downcast<TextureMapperPlatformLayerProxyGL>(proxy).pushNextBuffer(makeUnique<TextureMapperPlatformLayerDmabuf>(size, format, stride, fd)); > } > > m_context.markLayerComposited(); >@@ -78,14 +79,15 @@ void GCGLANGLELayer::swapBuffersIfNeeded() > auto flags = m_context.contextAttributes().alpha ? BitmapTexture::SupportsAlpha : BitmapTexture::NoFlag; > { > Locker locker { proxy.lock() }; >- std::unique_ptr<TextureMapperPlatformLayerBuffer> layerBuffer = proxy.getAvailableBuffer(size, m_context.m_internalColorFormat); >+ ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy)); >+ std::unique_ptr<TextureMapperPlatformLayerBuffer> layerBuffer = downcast<TextureMapperPlatformLayerProxyGL>(proxy).getAvailableBuffer(size, m_context.m_internalColorFormat); > if (!layerBuffer) { > auto texture = BitmapTextureGL::create(TextureMapperContextAttributes::get(), flags, m_context.m_internalColorFormat); > layerBuffer = makeUnique<TextureMapperPlatformLayerBuffer>(WTFMove(texture), flags); > } > > layerBuffer->textureGL().setPendingContents(ImageBuffer::sinkIntoImage(WTFMove(imageBuffer))); >- proxy.pushNextBuffer(WTFMove(layerBuffer)); >+ downcast<TextureMapperPlatformLayerProxyGL>(proxy).pushNextBuffer(WTFMove(layerBuffer)); > } > m_context.markLayerComposited(); > } >diff --git a/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLLayer.cpp b/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLLayer.cpp >index 010cc7c33becbb2b8f6ab070fd735efab00e27e4..aa2b1e67d90b621770e725812aec43dfa39e6d9a 100644 >--- a/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLLayer.cpp >+++ b/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLLayer.cpp >@@ -34,7 +34,7 @@ > #if USE(COORDINATED_GRAPHICS) > #include "TextureMapperGL.h" > #include "TextureMapperPlatformLayerBuffer.h" >-#include "TextureMapperPlatformLayerProxy.h" >+#include "TextureMapperPlatformLayerProxyGL.h" > #endif > > #include "GLContext.h" >@@ -83,7 +83,8 @@ void GCGLLayer::swapBuffersIfNeeded() > { > auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(m_contentLayer->impl()).proxy(); > Locker locker { proxy.lock() }; >- proxy.pushNextBuffer(makeUnique<TextureMapperPlatformLayerBuffer>(m_context.m_compositorTexture, textureSize, flags, m_context.m_internalColorFormat)); >+ ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy)); >+ downcast<TextureMapperPlatformLayerProxyGL>(proxy).pushNextBuffer(makeUnique<TextureMapperPlatformLayerBuffer>(m_context.m_compositorTexture, textureSize, flags, m_context.m_internalColorFormat)); > } > > m_context.markLayerComposited(); >diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp >index e5334ee2f7574925f3863b95f531fdc82629feb2..b5606b388e752e34908368a3cc40900743f8a672 100644 >--- a/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp >+++ b/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp >@@ -44,7 +44,7 @@ TextureMapperGCGLPlatformLayer::TextureMapperGCGLPlatformLayer(GraphicsContextGL > #endif > > #if USE(COORDINATED_GRAPHICS) >- m_platformLayerProxy = adoptRef(new TextureMapperPlatformLayerProxy()); >+ m_platformLayerProxy = adoptRef(new TextureMapperPlatformLayerProxyGL); > #endif > } > >@@ -97,7 +97,7 @@ void TextureMapperGCGLPlatformLayer::swapBuffersIfNeeded() > > { > Locker locker { m_platformLayerProxy->lock() }; >- m_platformLayerProxy->pushNextBuffer(makeUnique<TextureMapperPlatformLayerBuffer>(m_context.m_compositorTexture, textureSize, flags, m_context.m_internalColorFormat)); >+ downcast<TextureMapperPlatformLayerProxyGL>(*m_platformLayerProxy).pushNextBuffer(makeUnique<TextureMapperPlatformLayerBuffer>(m_context.m_compositorTexture, textureSize, flags, m_context.m_internalColorFormat)); > } > > m_context.markLayerComposited(); >diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp >index b04f9c6b97a69a68ef3a8d8a21ac76509e2d10c1..0ce3d45a049a25794179a72a4f84d3d1ee171cce 100644 >--- a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp >+++ b/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp >@@ -28,89 +28,10 @@ > > #if USE(COORDINATED_GRAPHICS) > >-#include "BitmapTextureGL.h" >-#include "TextureMapperGL.h" >-#include "TextureMapperLayer.h" >-#include "TextureMapperPlatformLayerBuffer.h" >- >-#if USE(GLIB_EVENT_LOOP) >-#include <wtf/glib/RunLoopSourcePriority.h> >-#endif >-#include <wtf/Scope.h> >- >-static const Seconds releaseUnusedSecondsTolerance { 1_s }; >-static const Seconds releaseUnusedBuffersTimerInterval = { 500_ms }; >- > namespace WebCore { > >-TextureMapperPlatformLayerProxy::TextureMapperPlatformLayerProxy() >- : m_compositor(nullptr) >- , m_targetLayer(nullptr) >-{ >-} >- >-TextureMapperPlatformLayerProxy::~TextureMapperPlatformLayerProxy() >-{ >- Locker locker { m_lock }; >- if (m_targetLayer) >- m_targetLayer->setContentsLayer(nullptr); >-} >- >-void TextureMapperPlatformLayerProxy::activateOnCompositingThread(Compositor* compositor, TextureMapperLayer* targetLayer) >-{ >-#ifndef NDEBUG >- if (!m_compositorThread) >- m_compositorThread = &Thread::current(); >-#endif >- ASSERT(m_compositorThread == &Thread::current()); >- ASSERT(compositor); >- ASSERT(targetLayer); >- Function<void()> updateFunction; >- { >- Locker locker { m_lock }; >- m_compositor = compositor; >- m_targetLayer = targetLayer; >- if (m_targetLayer && m_currentBuffer) >- m_targetLayer->setContentsLayer(m_currentBuffer.get()); >- >- m_releaseUnusedBuffersTimer = makeUnique<RunLoop::Timer<TextureMapperPlatformLayerProxy>>(RunLoop::current(), this, &TextureMapperPlatformLayerProxy::releaseUnusedBuffersTimerFired); >- m_compositorThreadUpdateTimer = makeUnique<RunLoop::Timer<TextureMapperPlatformLayerProxy>>(RunLoop::current(), this, &TextureMapperPlatformLayerProxy::compositorThreadUpdateTimerFired); >- >-#if USE(GLIB_EVENT_LOOP) >- m_compositorThreadUpdateTimer->setPriority(RunLoopSourcePriority::CompositingThreadUpdateTimer); >- m_releaseUnusedBuffersTimer->setPriority(RunLoopSourcePriority::ReleaseUnusedResourcesTimer); >-#endif >- >- if (!m_compositorThreadUpdateFunction) >- return; >- updateFunction = WTFMove(m_compositorThreadUpdateFunction); >- } >- updateFunction(); >-} >- >-void TextureMapperPlatformLayerProxy::invalidate() >-{ >- ASSERT(m_compositorThread == &Thread::current()); >- Function<void()> updateFunction; >- { >- Locker locker { m_lock }; >- m_compositor = nullptr; >- m_targetLayer = nullptr; >- >- m_currentBuffer = nullptr; >- m_pendingBuffer = nullptr; >- m_releaseUnusedBuffersTimer = nullptr; >- m_usedBuffers.clear(); >- >- // Clear the timer and dispatch the update function manually now. >- m_compositorThreadUpdateTimer = nullptr; >- if (!m_compositorThreadUpdateFunction) >- return; >- updateFunction = WTFMove(m_compositorThreadUpdateFunction); >- } >- >- updateFunction(); >-} >+TextureMapperPlatformLayerProxy::TextureMapperPlatformLayerProxy() = default; >+TextureMapperPlatformLayerProxy::~TextureMapperPlatformLayerProxy() = default; > > bool TextureMapperPlatformLayerProxy::isActive() > { >@@ -118,168 +39,6 @@ bool TextureMapperPlatformLayerProxy::isActive() > return !!m_targetLayer && !!m_compositor; > } > >-void TextureMapperPlatformLayerProxy::pushNextBuffer(std::unique_ptr<TextureMapperPlatformLayerBuffer>&& newBuffer) >-{ >- ASSERT(m_lock.isHeld()); >-#if USE(ANGLE) >- // When the newBuffer overwrites m_pendingBuffer that is not swapped yet, >- // the layer related to m_pendingBuffer is flickering since its texture is destroyed. >- if (m_pendingBuffer && m_pendingBuffer->hasManagedTexture()) >- return; >-#endif >- m_pendingBuffer = WTFMove(newBuffer); >- m_wasBufferDropped = false; >- >- if (m_compositor) >- m_compositor->onNewBufferAvailable(); >-} >- >-std::unique_ptr<TextureMapperPlatformLayerBuffer> TextureMapperPlatformLayerProxy::getAvailableBuffer(const IntSize& size, GLint internalFormat) >-{ >- ASSERT(m_lock.isHeld()); >- ASSERT(m_compositorThread == &Thread::current()); >- std::unique_ptr<TextureMapperPlatformLayerBuffer> availableBuffer; >- >- auto buffers = WTFMove(m_usedBuffers); >- for (auto& buffer : buffers) { >- if (!buffer) >- continue; >- >- if (!availableBuffer && buffer->canReuseWithoutReset(size, internalFormat)) { >- availableBuffer = WTFMove(buffer); >- availableBuffer->markUsed(); >- continue; >- } >- m_usedBuffers.append(WTFMove(buffer)); >- } >- >- if (!m_usedBuffers.isEmpty()) >- scheduleReleaseUnusedBuffers(); >- return availableBuffer; >-} >- >-void TextureMapperPlatformLayerProxy::appendToUnusedBuffers(std::unique_ptr<TextureMapperPlatformLayerBuffer> buffer) >-{ >- ASSERT(m_lock.isHeld()); >- ASSERT(m_compositorThread == &Thread::current()); >- m_usedBuffers.append(WTFMove(buffer)); >- scheduleReleaseUnusedBuffers(); >-} >- >-void TextureMapperPlatformLayerProxy::scheduleReleaseUnusedBuffers() >-{ >- if (!m_releaseUnusedBuffersTimer->isActive()) >- m_releaseUnusedBuffersTimer->startOneShot(releaseUnusedBuffersTimerInterval); >-} >- >-void TextureMapperPlatformLayerProxy::releaseUnusedBuffersTimerFired() >-{ >- Locker locker { m_lock }; >- if (m_usedBuffers.isEmpty()) >- return; >- >- auto buffers = WTFMove(m_usedBuffers); >- MonotonicTime minUsedTime = MonotonicTime::now() - releaseUnusedSecondsTolerance; >- >- for (auto& buffer : buffers) { >- if (buffer && buffer->lastUsedTime() >= minUsedTime) >- m_usedBuffers.append(WTFMove(buffer)); >- } >-} >- >-void TextureMapperPlatformLayerProxy::swapBuffer() >-{ >- ASSERT(m_compositorThread == &Thread::current()); >- Locker locker { m_lock }; >- if (!m_targetLayer || !m_pendingBuffer) >- return; >- >- auto prevBuffer = WTFMove(m_currentBuffer); >- >- m_currentBuffer = WTFMove(m_pendingBuffer); >- m_targetLayer->setContentsLayer(m_currentBuffer.get()); >- >- if (prevBuffer && prevBuffer->hasManagedTexture()) >- appendToUnusedBuffers(WTFMove(prevBuffer)); >-} >- >-void TextureMapperPlatformLayerProxy::dropCurrentBufferWhilePreservingTexture(bool shouldWait) >-{ >- if (!shouldWait) >- ASSERT(m_lock.isHeld()); >- >- if (m_pendingBuffer && m_pendingBuffer->hasManagedTexture()) { >- m_usedBuffers.append(WTFMove(m_pendingBuffer)); >- scheduleReleaseUnusedBuffers(); >- } >- >- if (!m_compositorThreadUpdateTimer) >- return; >- >- m_compositorThreadUpdateFunction = >- [this, shouldWait] { >- Locker locker { m_lock }; >- >- auto maybeNotifySynchronousOperation = makeScopeExit([this, shouldWait]() { >- if (shouldWait) { >- Locker locker { m_wasBufferDroppedLock }; >- m_wasBufferDropped = true; >- m_wasBufferDroppedCondition.notifyAll(); >- } >- }); >- >- if (!m_compositor || !m_targetLayer || !m_currentBuffer) >- return; >- >- m_pendingBuffer = m_currentBuffer->clone(); >- auto prevBuffer = WTFMove(m_currentBuffer); >- m_currentBuffer = WTFMove(m_pendingBuffer); >- m_targetLayer->setContentsLayer(m_currentBuffer.get()); >- >- if (prevBuffer->hasManagedTexture()) >- appendToUnusedBuffers(WTFMove(prevBuffer)); >- }; >- >- if (shouldWait) { >- Locker locker { m_wasBufferDroppedLock }; >- m_wasBufferDropped = false; >- } >- >- m_compositorThreadUpdateTimer->startOneShot(0_s); >- if (shouldWait) { >- Locker locker { m_wasBufferDroppedLock }; >- m_wasBufferDroppedCondition.wait(m_wasBufferDroppedLock, [this] { >- assertIsHeld(m_wasBufferDroppedLock); >- return m_wasBufferDropped; >- }); >- } >-} >- >-bool TextureMapperPlatformLayerProxy::scheduleUpdateOnCompositorThread(Function<void()>&& updateFunction) >-{ >- Locker locker { m_lock }; >- m_compositorThreadUpdateFunction = WTFMove(updateFunction); >- >- if (!m_compositorThreadUpdateTimer) >- return false; >- >- m_compositorThreadUpdateTimer->startOneShot(0_s); >- return true; >-} >- >-void TextureMapperPlatformLayerProxy::compositorThreadUpdateTimerFired() >-{ >- Function<void()> updateFunction; >- { >- Locker locker { m_lock }; >- if (!m_compositorThreadUpdateFunction) >- return; >- updateFunction = WTFMove(m_compositorThreadUpdateFunction); >- } >- >- updateFunction(); >-} >- > } // namespace WebCore > > #endif // USE(COORDINATED_GRAPHICS) >diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h b/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h >index fdbbd24b728b4521341a15a66a261255ffdf52cb..e3fcd0e1694b80b1c40b3cd8a101433353db8754 100644 >--- a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h >+++ b/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h >@@ -27,17 +27,8 @@ > > #if USE(COORDINATED_GRAPHICS) > >-#include "TextureMapperGLHeaders.h" >-#include <wtf/Condition.h> >-#include <wtf/Function.h> > #include <wtf/Lock.h> >-#include <wtf/RunLoop.h> > #include <wtf/ThreadSafeRefCounted.h> >-#include <wtf/Vector.h> >- >-#ifndef NDEBUG >-#include <wtf/Threading.h> >-#endif > > namespace WebCore { > >@@ -57,51 +48,27 @@ public: > TextureMapperPlatformLayerProxy(); > virtual ~TextureMapperPlatformLayerProxy(); > >- // To avoid multiple lock/release situation to update a single frame, >- // the implementation of TextureMapperPlatformLayerProxyProvider should >- // aquire / release the lock explicitly to use below methods. >+ virtual bool isGLBased() const { return false; } >+ virtual bool isDMABufBased() const { return false; } >+ > Lock& lock() WTF_RETURNS_LOCK(m_lock) { return m_lock; } >- std::unique_ptr<TextureMapperPlatformLayerBuffer> getAvailableBuffer(const IntSize&, GLint internalFormat); >- void pushNextBuffer(std::unique_ptr<TextureMapperPlatformLayerBuffer>&&); > bool isActive(); > >- WEBCORE_EXPORT void activateOnCompositingThread(Compositor*, TextureMapperLayer*); >- WEBCORE_EXPORT void invalidate(); >- >- WEBCORE_EXPORT void swapBuffer(); >- void dropCurrentBufferWhilePreservingTexture(bool shouldWait = false); >- >- bool scheduleUpdateOnCompositorThread(Function<void()>&&); >- >-private: >- void appendToUnusedBuffers(std::unique_ptr<TextureMapperPlatformLayerBuffer>); >- void scheduleReleaseUnusedBuffers(); >- void releaseUnusedBuffersTimerFired(); >- >- Compositor* m_compositor; >- TextureMapperLayer* m_targetLayer; >- >- std::unique_ptr<TextureMapperPlatformLayerBuffer> m_currentBuffer; >- std::unique_ptr<TextureMapperPlatformLayerBuffer> m_pendingBuffer; >+ virtual void activateOnCompositingThread(Compositor*, TextureMapperLayer*) = 0; >+ virtual void invalidate() = 0; >+ virtual void swapBuffer() = 0; > >+protected: > Lock m_lock; >- >- Lock m_wasBufferDroppedLock; >- Condition m_wasBufferDroppedCondition; >- bool m_wasBufferDropped WTF_GUARDED_BY_LOCK(m_wasBufferDroppedLock) { false }; >- >- Vector<std::unique_ptr<TextureMapperPlatformLayerBuffer>> m_usedBuffers; >- std::unique_ptr<RunLoop::Timer<TextureMapperPlatformLayerProxy>> m_releaseUnusedBuffersTimer; >- >-#ifndef NDEBUG >- RefPtr<Thread> m_compositorThread; >-#endif >- >- void compositorThreadUpdateTimerFired(); >- std::unique_ptr<RunLoop::Timer<TextureMapperPlatformLayerProxy>> m_compositorThreadUpdateTimer; >- Function<void()> m_compositorThreadUpdateFunction; >+ Compositor* m_compositor { nullptr }; >+ TextureMapperLayer* m_targetLayer { nullptr }; > }; > > } // namespace WebCore > >+#define SPECIALIZE_TYPE_TRAITS_TEXTUREMAPPER_PLATFORMLAYERPROXY(ToClassName, predicate) \ >+ SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToClassName) \ >+ static bool isType(const WebCore::TextureMapperPlatformLayerProxy& proxy) { return proxy.predicate; } \ >+ SPECIALIZE_TYPE_TRAITS_END() >+ > #endif // USE(COORDINATED_GRAPHICS) >diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..9be902b76cc3b4da4ce00a3e94bef74e02416764 >--- /dev/null >+++ b/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.cpp >@@ -0,0 +1,275 @@ >+/* >+ * Copyright (C) 2015 Igalia S.L. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "TextureMapperPlatformLayerProxyGL.h" >+ >+#if USE(COORDINATED_GRAPHICS) >+ >+#include "BitmapTextureGL.h" >+#include "TextureMapperGL.h" >+#include "TextureMapperLayer.h" >+#include "TextureMapperPlatformLayerBuffer.h" >+ >+#if USE(GLIB_EVENT_LOOP) >+#include <wtf/glib/RunLoopSourcePriority.h> >+#endif >+#include <wtf/Scope.h> >+ >+static const Seconds releaseUnusedSecondsTolerance { 1_s }; >+static const Seconds releaseUnusedBuffersTimerInterval = { 500_ms }; >+ >+namespace WebCore { >+ >+TextureMapperPlatformLayerProxyGL::TextureMapperPlatformLayerProxyGL() = default; >+ >+TextureMapperPlatformLayerProxyGL::~TextureMapperPlatformLayerProxyGL() >+{ >+ Locker locker { m_lock }; >+ if (m_targetLayer) >+ m_targetLayer->setContentsLayer(nullptr); >+} >+ >+void TextureMapperPlatformLayerProxyGL::activateOnCompositingThread(Compositor* compositor, TextureMapperLayer* targetLayer) >+{ >+#ifndef NDEBUG >+ if (!m_compositorThread) >+ m_compositorThread = &Thread::current(); >+#endif >+ ASSERT(m_compositorThread == &Thread::current()); >+ ASSERT(compositor); >+ ASSERT(targetLayer); >+ Function<void()> updateFunction; >+ { >+ Locker locker { m_lock }; >+ m_compositor = compositor; >+ m_targetLayer = targetLayer; >+ if (m_targetLayer && m_currentBuffer) >+ m_targetLayer->setContentsLayer(m_currentBuffer.get()); >+ >+ m_releaseUnusedBuffersTimer = makeUnique<RunLoop::Timer<TextureMapperPlatformLayerProxyGL>>(RunLoop::current(), this, &TextureMapperPlatformLayerProxyGL::releaseUnusedBuffersTimerFired); >+ m_compositorThreadUpdateTimer = makeUnique<RunLoop::Timer<TextureMapperPlatformLayerProxyGL>>(RunLoop::current(), this, &TextureMapperPlatformLayerProxyGL::compositorThreadUpdateTimerFired); >+ >+#if USE(GLIB_EVENT_LOOP) >+ m_compositorThreadUpdateTimer->setPriority(RunLoopSourcePriority::CompositingThreadUpdateTimer); >+ m_releaseUnusedBuffersTimer->setPriority(RunLoopSourcePriority::ReleaseUnusedResourcesTimer); >+#endif >+ >+ if (!m_compositorThreadUpdateFunction) >+ return; >+ updateFunction = WTFMove(m_compositorThreadUpdateFunction); >+ } >+ updateFunction(); >+} >+ >+void TextureMapperPlatformLayerProxyGL::invalidate() >+{ >+ ASSERT(m_compositorThread == &Thread::current()); >+ Function<void()> updateFunction; >+ { >+ Locker locker { m_lock }; >+ m_compositor = nullptr; >+ m_targetLayer = nullptr; >+ >+ m_currentBuffer = nullptr; >+ m_pendingBuffer = nullptr; >+ m_releaseUnusedBuffersTimer = nullptr; >+ m_usedBuffers.clear(); >+ >+ // Clear the timer and dispatch the update function manually now. >+ m_compositorThreadUpdateTimer = nullptr; >+ if (!m_compositorThreadUpdateFunction) >+ return; >+ updateFunction = WTFMove(m_compositorThreadUpdateFunction); >+ } >+ >+ updateFunction(); >+} >+ >+void TextureMapperPlatformLayerProxyGL::pushNextBuffer(std::unique_ptr<TextureMapperPlatformLayerBuffer>&& newBuffer) >+{ >+ ASSERT(m_lock.isHeld()); >+#if USE(ANGLE) >+ // When the newBuffer overwrites m_pendingBuffer that is not swapped yet, >+ // the layer related to m_pendingBuffer is flickering since its texture is destroyed. >+ if (m_pendingBuffer && m_pendingBuffer->hasManagedTexture()) >+ return; >+#endif >+ m_pendingBuffer = WTFMove(newBuffer); >+ m_wasBufferDropped = false; >+ >+ if (m_compositor) >+ m_compositor->onNewBufferAvailable(); >+} >+ >+std::unique_ptr<TextureMapperPlatformLayerBuffer> TextureMapperPlatformLayerProxyGL::getAvailableBuffer(const IntSize& size, GLint internalFormat) >+{ >+ ASSERT(m_lock.isHeld()); >+ ASSERT(m_compositorThread == &Thread::current()); >+ std::unique_ptr<TextureMapperPlatformLayerBuffer> availableBuffer; >+ >+ auto buffers = WTFMove(m_usedBuffers); >+ for (auto& buffer : buffers) { >+ if (!buffer) >+ continue; >+ >+ if (!availableBuffer && buffer->canReuseWithoutReset(size, internalFormat)) { >+ availableBuffer = WTFMove(buffer); >+ availableBuffer->markUsed(); >+ continue; >+ } >+ m_usedBuffers.append(WTFMove(buffer)); >+ } >+ >+ if (!m_usedBuffers.isEmpty()) >+ scheduleReleaseUnusedBuffers(); >+ return availableBuffer; >+} >+ >+void TextureMapperPlatformLayerProxyGL::appendToUnusedBuffers(std::unique_ptr<TextureMapperPlatformLayerBuffer> buffer) >+{ >+ ASSERT(m_lock.isHeld()); >+ ASSERT(m_compositorThread == &Thread::current()); >+ m_usedBuffers.append(WTFMove(buffer)); >+ scheduleReleaseUnusedBuffers(); >+} >+ >+void TextureMapperPlatformLayerProxyGL::scheduleReleaseUnusedBuffers() >+{ >+ if (!m_releaseUnusedBuffersTimer->isActive()) >+ m_releaseUnusedBuffersTimer->startOneShot(releaseUnusedBuffersTimerInterval); >+} >+ >+void TextureMapperPlatformLayerProxyGL::releaseUnusedBuffersTimerFired() >+{ >+ Locker locker { m_lock }; >+ if (m_usedBuffers.isEmpty()) >+ return; >+ >+ auto buffers = WTFMove(m_usedBuffers); >+ MonotonicTime minUsedTime = MonotonicTime::now() - releaseUnusedSecondsTolerance; >+ >+ for (auto& buffer : buffers) { >+ if (buffer && buffer->lastUsedTime() >= minUsedTime) >+ m_usedBuffers.append(WTFMove(buffer)); >+ } >+} >+ >+void TextureMapperPlatformLayerProxyGL::swapBuffer() >+{ >+ ASSERT(m_compositorThread == &Thread::current()); >+ Locker locker { m_lock }; >+ if (!m_targetLayer || !m_pendingBuffer) >+ return; >+ >+ auto prevBuffer = WTFMove(m_currentBuffer); >+ >+ m_currentBuffer = WTFMove(m_pendingBuffer); >+ m_targetLayer->setContentsLayer(m_currentBuffer.get()); >+ >+ if (prevBuffer && prevBuffer->hasManagedTexture()) >+ appendToUnusedBuffers(WTFMove(prevBuffer)); >+} >+ >+void TextureMapperPlatformLayerProxyGL::dropCurrentBufferWhilePreservingTexture(bool shouldWait) >+{ >+ if (!shouldWait) >+ ASSERT(m_lock.isHeld()); >+ >+ if (m_pendingBuffer && m_pendingBuffer->hasManagedTexture()) { >+ m_usedBuffers.append(WTFMove(m_pendingBuffer)); >+ scheduleReleaseUnusedBuffers(); >+ } >+ >+ if (!m_compositorThreadUpdateTimer) >+ return; >+ >+ m_compositorThreadUpdateFunction = >+ [this, shouldWait] { >+ Locker locker { m_lock }; >+ >+ auto maybeNotifySynchronousOperation = makeScopeExit([this, shouldWait]() { >+ if (shouldWait) { >+ Locker locker { m_wasBufferDroppedLock }; >+ m_wasBufferDropped = true; >+ m_wasBufferDroppedCondition.notifyAll(); >+ } >+ }); >+ >+ if (!m_compositor || !m_targetLayer || !m_currentBuffer) >+ return; >+ >+ m_pendingBuffer = m_currentBuffer->clone(); >+ auto prevBuffer = WTFMove(m_currentBuffer); >+ m_currentBuffer = WTFMove(m_pendingBuffer); >+ m_targetLayer->setContentsLayer(m_currentBuffer.get()); >+ >+ if (prevBuffer->hasManagedTexture()) >+ appendToUnusedBuffers(WTFMove(prevBuffer)); >+ }; >+ >+ if (shouldWait) { >+ Locker locker { m_wasBufferDroppedLock }; >+ m_wasBufferDropped = false; >+ } >+ >+ m_compositorThreadUpdateTimer->startOneShot(0_s); >+ if (shouldWait) { >+ Locker locker { m_wasBufferDroppedLock }; >+ m_wasBufferDroppedCondition.wait(m_wasBufferDroppedLock, [this] { >+ assertIsHeld(m_wasBufferDroppedLock); >+ return m_wasBufferDropped; >+ }); >+ } >+} >+ >+bool TextureMapperPlatformLayerProxyGL::scheduleUpdateOnCompositorThread(Function<void()>&& updateFunction) >+{ >+ Locker locker { m_lock }; >+ m_compositorThreadUpdateFunction = WTFMove(updateFunction); >+ >+ if (!m_compositorThreadUpdateTimer) >+ return false; >+ >+ m_compositorThreadUpdateTimer->startOneShot(0_s); >+ return true; >+} >+ >+void TextureMapperPlatformLayerProxyGL::compositorThreadUpdateTimerFired() >+{ >+ Function<void()> updateFunction; >+ { >+ Locker locker { m_lock }; >+ if (!m_compositorThreadUpdateFunction) >+ return; >+ updateFunction = WTFMove(m_compositorThreadUpdateFunction); >+ } >+ >+ updateFunction(); >+} >+ >+} // namespace WebCore >+ >+#endif // USE(COORDINATED_GRAPHICS) >diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.h b/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.h >new file mode 100644 >index 0000000000000000000000000000000000000000..f521c1fe7ba339e237f7a03b153d09649ce04906 >--- /dev/null >+++ b/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyGL.h >@@ -0,0 +1,91 @@ >+/* >+ * Copyright (C) 2015 Igalia S.L. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#include "TextureMapperPlatformLayerProxy.h" >+ >+#if USE(COORDINATED_GRAPHICS) >+ >+#include "TextureMapperGLHeaders.h" >+#include <wtf/Condition.h> >+#include <wtf/Function.h> >+#include <wtf/RunLoop.h> >+#include <wtf/Vector.h> >+ >+#ifndef NDEBUG >+#include <wtf/Threading.h> >+#endif >+ >+namespace WebCore { >+ >+class TextureMapperPlatformLayerProxyGL final : public TextureMapperPlatformLayerProxy { >+ WTF_MAKE_FAST_ALLOCATED(); >+public: >+ TextureMapperPlatformLayerProxyGL(); >+ virtual ~TextureMapperPlatformLayerProxyGL(); >+ >+ bool isGLBased() const override { return true; } >+ >+ WEBCORE_EXPORT void activateOnCompositingThread(Compositor*, TextureMapperLayer*) override; >+ WEBCORE_EXPORT void invalidate() override; >+ WEBCORE_EXPORT void swapBuffer() override; >+ >+ std::unique_ptr<TextureMapperPlatformLayerBuffer> getAvailableBuffer(const IntSize&, GLint internalFormat); >+ void pushNextBuffer(std::unique_ptr<TextureMapperPlatformLayerBuffer>&&); >+ >+ void dropCurrentBufferWhilePreservingTexture(bool shouldWait = false); >+ >+ bool scheduleUpdateOnCompositorThread(Function<void()>&&); >+ >+private: >+ void appendToUnusedBuffers(std::unique_ptr<TextureMapperPlatformLayerBuffer>); >+ void scheduleReleaseUnusedBuffers(); >+ void releaseUnusedBuffersTimerFired(); >+ >+ std::unique_ptr<TextureMapperPlatformLayerBuffer> m_currentBuffer; >+ std::unique_ptr<TextureMapperPlatformLayerBuffer> m_pendingBuffer; >+ >+ Lock m_wasBufferDroppedLock; >+ Condition m_wasBufferDroppedCondition; >+ bool m_wasBufferDropped WTF_GUARDED_BY_LOCK(m_wasBufferDroppedLock) { false }; >+ >+ Vector<std::unique_ptr<TextureMapperPlatformLayerBuffer>> m_usedBuffers; >+ std::unique_ptr<RunLoop::Timer<TextureMapperPlatformLayerProxyGL>> m_releaseUnusedBuffersTimer; >+ >+#ifndef NDEBUG >+ RefPtr<Thread> m_compositorThread; >+#endif >+ >+ void compositorThreadUpdateTimerFired(); >+ std::unique_ptr<RunLoop::Timer<TextureMapperPlatformLayerProxyGL>> m_compositorThreadUpdateTimer; >+ Function<void()> m_compositorThreadUpdateFunction; >+}; >+ >+} // namespace WebCore >+ >+SPECIALIZE_TYPE_TRAITS_TEXTUREMAPPER_PLATFORMLAYERPROXY(TextureMapperPlatformLayerProxyGL, isGLBased()); >+ >+#endif // USE(COORDINATED_GRAPHICS)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 236836
: 452514