Title: [229857] trunk/Source
Revision
229857
Author
[email protected]
Date
2018-03-22 11:07:05 -0700 (Thu, 22 Mar 2018)

Log Message

[TexMap] Make TextureMapperContextAttributes thread-specific
https://bugs.webkit.org/show_bug.cgi?id=183895

Reviewed by Carlos Garcia Campos.

Source/WebCore:

Store the TextureMapperContextAttributes in a thread-specific manner.
The TextureMapperContextAttributes::get() method is now used to retrieve
a reference to that thread-specific object. If it's not been initialized
yet, then the current GL context is used for the initialization, as it
used to be done in the now-removed initialize() method.

TextureMapperPlatformLayerBuffer::clone() method now doesn't need to
be passed a TextureMapperGL object, since the texture can be created
directly by calling BitmapTextureGL::create(), passing the
TextureMapperContextAttributes object that's retrieved from the
thread-specific storage. This further simplifies the
TextureMapperPlatformLayerProxy::Compositor interface, removing the
texmapGL() getter from it.

* platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:
(WebCore::MediaPlayerPrivateGStreamerBase::pushTextureToCompositor):
* platform/graphics/texmap/TextureMapperContextAttributes.cpp:
(WebCore::threadSpecificAttributes):
(WebCore::TextureMapperContextAttributes::get):
(WebCore::TextureMapperContextAttributes::initialize): Deleted.
* platform/graphics/texmap/TextureMapperContextAttributes.h:
* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::TextureMapperGL::TextureMapperGL):
* platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp:
(WebCore::TextureMapperPlatformLayerBuffer::clone):
* platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h:
* platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp:
(WebCore::TextureMapperPlatformLayerProxy::dropCurrentBufferWhilePreservingTexture):
* platform/graphics/texmap/TextureMapperPlatformLayerProxy.h:

Source/WebKit:

CoordinatedGraphicsScene, as an implementor of the
TextureMapperPlatformLayerProxy::Compositor interface, doesn't have to
implement the texmapGL() method anymore.

* Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:
(WebKit::CoordinatedGraphicsScene::onNewBufferAvailable):
(WebKit::CoordinatedGraphicsScene::texmapGL): Deleted.
* Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (229856 => 229857)


--- trunk/Source/WebCore/ChangeLog	2018-03-22 18:03:36 UTC (rev 229856)
+++ trunk/Source/WebCore/ChangeLog	2018-03-22 18:07:05 UTC (rev 229857)
@@ -1,3 +1,40 @@
+2018-03-22  Zan Dobersek  <[email protected]>
+
+        [TexMap] Make TextureMapperContextAttributes thread-specific
+        https://bugs.webkit.org/show_bug.cgi?id=183895
+
+        Reviewed by Carlos Garcia Campos.
+
+        Store the TextureMapperContextAttributes in a thread-specific manner.
+        The TextureMapperContextAttributes::get() method is now used to retrieve
+        a reference to that thread-specific object. If it's not been initialized
+        yet, then the current GL context is used for the initialization, as it
+        used to be done in the now-removed initialize() method.
+
+        TextureMapperPlatformLayerBuffer::clone() method now doesn't need to
+        be passed a TextureMapperGL object, since the texture can be created
+        directly by calling BitmapTextureGL::create(), passing the
+        TextureMapperContextAttributes object that's retrieved from the
+        thread-specific storage. This further simplifies the
+        TextureMapperPlatformLayerProxy::Compositor interface, removing the
+        texmapGL() getter from it.
+
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:
+        (WebCore::MediaPlayerPrivateGStreamerBase::pushTextureToCompositor):
+        * platform/graphics/texmap/TextureMapperContextAttributes.cpp:
+        (WebCore::threadSpecificAttributes):
+        (WebCore::TextureMapperContextAttributes::get):
+        (WebCore::TextureMapperContextAttributes::initialize): Deleted.
+        * platform/graphics/texmap/TextureMapperContextAttributes.h:
+        * platform/graphics/texmap/TextureMapperGL.cpp:
+        (WebCore::TextureMapperGL::TextureMapperGL):
+        * platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp:
+        (WebCore::TextureMapperPlatformLayerBuffer::clone):
+        * platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h:
+        * platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp:
+        (WebCore::TextureMapperPlatformLayerProxy::dropCurrentBufferWhilePreservingTexture):
+        * platform/graphics/texmap/TextureMapperPlatformLayerProxy.h:
+
 2018-03-22  Zalan Bujtas  <[email protected]>
 
         SVG root is skipped while marking percentage height descendants dirty.

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp (229856 => 229857)


--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp	2018-03-22 18:03:36 UTC (rev 229856)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp	2018-03-22 18:07:05 UTC (rev 229857)
@@ -764,10 +764,7 @@
     IntSize size = IntSize(GST_VIDEO_INFO_WIDTH(&videoInfo), GST_VIDEO_INFO_HEIGHT(&videoInfo));
     std::unique_ptr<TextureMapperPlatformLayerBuffer> buffer = m_platformLayerProxy->getAvailableBuffer(size, GL_DONT_CARE);
     if (UNLIKELY(!buffer)) {
-        TextureMapperContextAttributes contextAttributes;
-        contextAttributes.initialize();
-
-        auto texture = BitmapTextureGL::create(contextAttributes);
+        auto texture = BitmapTextureGL::create(TextureMapperContextAttributes::get());
         texture->reset(size, GST_VIDEO_INFO_HAS_ALPHA(&videoInfo) ? BitmapTexture::SupportsAlpha : BitmapTexture::NoFlag);
         buffer = std::make_unique<TextureMapperPlatformLayerBuffer>(WTFMove(texture));
     }

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperContextAttributes.cpp (229856 => 229857)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperContextAttributes.cpp	2018-03-22 18:03:36 UTC (rev 229856)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperContextAttributes.cpp	2018-03-22 18:07:05 UTC (rev 229857)
@@ -29,25 +29,43 @@
 #if USE(TEXTURE_MAPPER_GL)
 
 #include "TextureMapperGLHeaders.h"
+#include <mutex>
+#include <wtf/ThreadSpecific.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
-void TextureMapperContextAttributes::initialize()
+static WTF::ThreadSpecific<TextureMapperContextAttributes>& threadSpecificAttributes()
 {
+    static WTF::ThreadSpecific<TextureMapperContextAttributes>* s_textureMapperContextAttributes;
+    static std::once_flag s_onceFlag;
+    std::call_once(s_onceFlag,
+        [] {
+            s_textureMapperContextAttributes = new WTF::ThreadSpecific<TextureMapperContextAttributes>;
+        });
+    return *s_textureMapperContextAttributes;
+}
+
+const TextureMapperContextAttributes& TextureMapperContextAttributes::get()
+{
+    auto& attributes = *threadSpecificAttributes();
+    if (!attributes.initialized) {
+        attributes.initialized = true;
 #if USE(OPENGL_ES)
-    isGLES2Compliant = true;
+        attributes.isGLES2Compliant = true;
 
-    String extensionsString(reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)));
-    supportsNPOTTextures = extensionsString.contains(ASCIILiteral("GL_OES_texture_npot"));
-    supportsBGRA8888 = extensionsString.contains(ASCIILiteral("GL_EXT_texture_format_BGRA8888"));
-    supportsUnpackSubimage = extensionsString.contains(ASCIILiteral("GL_EXT_unpack_subimage"));
+        String extensionsString(reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)));
+        attributes.supportsNPOTTextures = extensionsString.contains(ASCIILiteral("GL_OES_texture_npot"));
+        attributes.supportsBGRA8888 = extensionsString.contains(ASCIILiteral("GL_EXT_texture_format_BGRA8888"));
+        attributes.supportsUnpackSubimage = extensionsString.contains(ASCIILiteral("GL_EXT_unpack_subimage"));
 #else
-    isGLES2Compliant = false;
-    supportsNPOTTextures = true;
-    supportsBGRA8888 = true;
-    supportsUnpackSubimage = true;
+        attributes.isGLES2Compliant = false;
+        attributes.supportsNPOTTextures = true;
+        attributes.supportsBGRA8888 = true;
+        attributes.supportsUnpackSubimage = true;
 #endif
+    }
+    return attributes;
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperContextAttributes.h (229856 => 229857)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperContextAttributes.h	2018-03-22 18:03:36 UTC (rev 229856)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperContextAttributes.h	2018-03-22 18:07:05 UTC (rev 229857)
@@ -30,8 +30,9 @@
 namespace WebCore {
 
 struct TextureMapperContextAttributes {
-    void initialize();
+    static const TextureMapperContextAttributes& get();
 
+    bool initialized { false };
     bool isGLES2Compliant { false };
     bool supportsNPOTTextures { false };
     bool supportsBGRA8888 { false };

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp (229856 => 229857)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp	2018-03-22 18:03:36 UTC (rev 229856)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp	2018-03-22 18:07:05 UTC (rev 229857)
@@ -178,10 +178,9 @@
 }
 
 TextureMapperGL::TextureMapperGL()
-    : m_enableEdgeDistanceAntialiasing(false)
+    : m_contextAttributes(TextureMapperContextAttributes::get())
+    , m_enableEdgeDistanceAntialiasing(false)
 {
-    m_contextAttributes.initialize();
-
     void* platformContext = GLContext::current()->platformContext();
     ASSERT(platformContext);
 

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp (229856 => 229857)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp	2018-03-22 18:03:36 UTC (rev 229856)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp	2018-03-22 18:07:05 UTC (rev 229857)
@@ -52,13 +52,13 @@
     return m_texture && (m_texture->size() == size) && (static_cast<BitmapTextureGL*>(m_texture.get())->internalFormat() == internalFormat || internalFormat == GL_DONT_CARE);
 }
 
-std::unique_ptr<TextureMapperPlatformLayerBuffer> TextureMapperPlatformLayerBuffer::clone(TextureMapperGL& texmapGL)
+std::unique_ptr<TextureMapperPlatformLayerBuffer> TextureMapperPlatformLayerBuffer::clone()
 {
     if (m_hasManagedTexture || !m_textureID) {
         notImplemented();
         return nullptr;
     }
-    RefPtr<BitmapTexture> texture = texmapGL.createTexture(m_internalFormat);
+    RefPtr<BitmapTexture> texture = BitmapTextureGL::create(TextureMapperContextAttributes::get(), m_internalFormat);
     texture->reset(m_size);
     static_cast<BitmapTextureGL&>(*texture).copyFromExternalTexture(m_textureID);
     return std::make_unique<TextureMapperPlatformLayerBuffer>(WTFMove(texture), m_extraFlags);

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h (229856 => 229857)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h	2018-03-22 18:03:36 UTC (rev 229856)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h	2018-03-22 18:07:05 UTC (rev 229857)
@@ -63,7 +63,7 @@
     void setUnmanagedBufferDataHolder(std::unique_ptr<UnmanagedBufferDataHolder> holder) { m_unmanagedBufferDataHolder = WTFMove(holder); }
     void setExtraFlags(TextureMapperGL::Flags flags) { m_extraFlags = flags; }
 
-    std::unique_ptr<TextureMapperPlatformLayerBuffer> clone(TextureMapperGL&);
+    std::unique_ptr<TextureMapperPlatformLayerBuffer> clone();
 
 private:
 

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp (229856 => 229857)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp	2018-03-22 18:03:36 UTC (rev 229856)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp	2018-03-22 18:07:05 UTC (rev 229857)
@@ -203,14 +203,10 @@
         [this] {
             LockHolder locker(m_lock);
 
-            if (!m_compositor || !m_targetLayer)
+            if (!m_compositor || !m_targetLayer || !m_currentBuffer)
                 return;
 
-            TextureMapperGL* texmapGL = m_compositor->texmapGL();
-            if (!texmapGL || !m_currentBuffer)
-                return;
-
-            m_pendingBuffer = m_currentBuffer->clone(*texmapGL);
+            m_pendingBuffer = m_currentBuffer->clone();
             auto prevBuffer = WTFMove(m_currentBuffer);
             m_currentBuffer = WTFMove(m_pendingBuffer);
             m_targetLayer->setContentsLayer(m_currentBuffer.get());

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h (229856 => 229857)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h	2018-03-22 18:03:36 UTC (rev 229856)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h	2018-03-22 18:07:05 UTC (rev 229857)
@@ -52,7 +52,6 @@
     class Compositor {
     public:
         virtual void onNewBufferAvailable() = 0;
-        virtual TextureMapperGL* texmapGL() = 0;
     };
 
     TextureMapperPlatformLayerProxy();

Modified: trunk/Source/WebKit/ChangeLog (229856 => 229857)


--- trunk/Source/WebKit/ChangeLog	2018-03-22 18:03:36 UTC (rev 229856)
+++ trunk/Source/WebKit/ChangeLog	2018-03-22 18:07:05 UTC (rev 229857)
@@ -1,3 +1,19 @@
+2018-03-22  Zan Dobersek  <[email protected]>
+
+        [TexMap] Make TextureMapperContextAttributes thread-specific
+        https://bugs.webkit.org/show_bug.cgi?id=183895
+
+        Reviewed by Carlos Garcia Campos.
+
+        CoordinatedGraphicsScene, as an implementor of the
+        TextureMapperPlatformLayerProxy::Compositor interface, doesn't have to
+        implement the texmapGL() method anymore.
+
+        * Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:
+        (WebKit::CoordinatedGraphicsScene::onNewBufferAvailable):
+        (WebKit::CoordinatedGraphicsScene::texmapGL): Deleted.
+        * Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h:
+
 2018-03-21  Frederic Wang  <[email protected]>
 
         Unreviewed, update comment added in r229801.

Modified: trunk/Source/WebKit/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp (229856 => 229857)


--- trunk/Source/WebKit/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp	2018-03-22 18:03:36 UTC (rev 229856)
+++ trunk/Source/WebKit/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp	2018-03-22 18:07:05 UTC (rev 229857)
@@ -146,14 +146,6 @@
 {
     updateViewport();
 }
-
-TextureMapperGL* CoordinatedGraphicsScene::texmapGL()
-{
-    if (!m_textureMapper)
-        return nullptr;
-
-    return static_cast<TextureMapperGL*>(m_textureMapper.get());
-}
 #endif
 
 void CoordinatedGraphicsScene::setLayerRepaintCountIfNeeded(TextureMapperLayer* layer, const CoordinatedGraphicsLayerState& state)

Modified: trunk/Source/WebKit/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h (229856 => 229857)


--- trunk/Source/WebKit/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h	2018-03-22 18:03:36 UTC (rev 229856)
+++ trunk/Source/WebKit/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h	2018-03-22 18:07:05 UTC (rev 229857)
@@ -148,7 +148,6 @@
 
 #if USE(COORDINATED_GRAPHICS_THREADED)
     void onNewBufferAvailable() override;
-    WebCore::TextureMapperGL* texmapGL() override;
 #endif
 
     std::unique_ptr<WebCore::TextureMapper> m_textureMapper;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to