Diff
Modified: trunk/Source/WebCore/ChangeLog (193722 => 193723)
--- trunk/Source/WebCore/ChangeLog 2015-12-08 08:35:25 UTC (rev 193722)
+++ trunk/Source/WebCore/ChangeLog 2015-12-08 08:36:02 UTC (rev 193723)
@@ -1,3 +1,42 @@
+2015-12-08 Gwang Yoon Hwang <y...@igalia.com>
+
+ [ThreadedCompositor] Support WebGL for OpenGL.
+ https://bugs.webkit.org/show_bug.cgi?id=143300
+
+ Reviewed by Žan Doberšek.
+
+ To remove pixel transfer operation, this patch adds m_compositorFBO which uses same depth and stencil
+ buffer with m_fbo but uses m_compositorTexture as a color attachment in GraphicsContext3D.
+ Because switching target framebuffer is cheaper than pixel transfer operation and switching color
+ attachment of m_fbo. In Threaded Compositor, when WebGL renders a scene, prepareTexture swaps
+ m_fbo with m_compositorFBO and send the color attachment to the compositor thread.
+ This patch only supports WebGL for OpenGL. OpenGLES will be covered in following-up patches.
+
+ No new tests needed.
+
+ * platform/graphics/GraphicsContext3D.h:
+ * platform/graphics/GraphicsContext3DPrivate.cpp:
+ (WebCore::GraphicsContext3DPrivate::GraphicsContext3DPrivate):
+ (WebCore::GraphicsContext3DPrivate::proxy):
+ (WebCore::GraphicsContext3DPrivate::swapBuffersIfNeeded):
+ Implement interfaces to pass a rendered texture to the compositing
+ thread.
+ * platform/graphics/GraphicsContext3DPrivate.h:
+ * platform/graphics/cairo/GraphicsContext3DCairo.cpp:
+ (WebCore::GraphicsContext3D::GraphicsContext3D):
+ (WebCore::GraphicsContext3D::~GraphicsContext3D):
+ Create additional compositing texture and FBO to swaping buffers for
+ threaded compositor.
+ * platform/graphics/opengl/GraphicsContext3DOpenGL.cpp:
+ (WebCore::GraphicsContext3D::reshapeFBOs):
+ (WebCore::GraphicsContext3D::attachDepthAndStencilBufferIfNeeded):
+ Split attaching depth and stencil buffer codes from reshapeFBOs
+ to make complete framebuffer with not only m_fbo but m_compositorFBO also.
+ * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
+ (WebCore::GraphicsContext3D::prepareTexture):
+ If we are in the threaded compositor, we will swap m_fbo with
+ m_compositorFBO instead of copying it.
+
2015-12-07 Zalan Bujtas <za...@apple.com>
Make paintTextWithShadows a member function (TextPainter).
Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h (193722 => 193723)
--- trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h 2015-12-08 08:35:25 UTC (rev 193722)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h 2015-12-08 08:36:02 UTC (rev 193723)
@@ -1293,6 +1293,7 @@
bool reshapeFBOs(const IntSize&);
void resolveMultisamplingIfNecessary(const IntRect& = IntRect());
+ void attachDepthAndStencilBufferIfNeeded(GLuint internalDepthStencilFormat, int width, int height);
#if PLATFORM(EFL) && USE(GRAPHICS_SURFACE)
void createGraphicsSurfaces(const IntSize&);
#endif
@@ -1417,6 +1418,9 @@
GC3Duint m_texture;
GC3Duint m_compositorTexture;
GC3Duint m_fbo;
+#if USE(COORDINATED_GRAPHICS_THREADED)
+ GC3Duint m_compositorFBO;
+#endif
GC3Duint m_depthBuffer;
GC3Duint m_stencilBuffer;
Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext3DPrivate.cpp (193722 => 193723)
--- trunk/Source/WebCore/platform/graphics/GraphicsContext3DPrivate.cpp 2015-12-08 08:35:25 UTC (rev 193722)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext3DPrivate.cpp 2015-12-08 08:36:02 UTC (rev 193723)
@@ -41,6 +41,10 @@
#include <texmap/TextureMapperGL.h>
#endif
+#if USE(COORDINATED_GRAPHICS_THREADED)
+#include "TextureMapperPlatformLayerBuffer.h"
+#endif
+
using namespace std;
namespace WebCore {
@@ -59,6 +63,11 @@
ASSERT_NOT_REACHED();
break;
}
+
+#if USE(COORDINATED_GRAPHICS_THREADED)
+ if (m_renderStyle == GraphicsContext3D::RenderOffscreen)
+ m_platformLayerProxy = adoptRef(new TextureMapperPlatformLayerProxy());
+#endif
}
GraphicsContext3DPrivate::~GraphicsContext3DPrivate()
@@ -82,10 +91,27 @@
#if USE(COORDINATED_GRAPHICS_THREADED)
RefPtr<TextureMapperPlatformLayerProxy> GraphicsContext3DPrivate::proxy() const
{
- notImplemented();
- return nullptr;
+ return m_platformLayerProxy.copyRef();
}
-#elif USE(TEXTURE_MAPPER)
+
+void GraphicsContext3DPrivate::swapBuffersIfNeeded()
+{
+ ASSERT(m_renderStyle == GraphicsContext3D::RenderOffscreen);
+ if (m_context->layerComposited())
+ return;
+
+ m_context->prepareTexture();
+ IntSize textureSize(m_context->m_currentWidth, m_context->m_currentHeight);
+ TextureMapperGL::Flags flags = TextureMapperGL::ShouldFlipTexture | (m_context->m_attrs.alpha ? TextureMapperGL::ShouldBlend : 0);
+
+ {
+ LockHolder holder(m_platformLayerProxy->lock());
+ m_platformLayerProxy->pushNextBuffer(std::make_unique<TextureMapperPlatformLayerBuffer>(m_context->m_compositorTexture, textureSize, flags));
+ }
+
+ m_context->markLayerComposited();
+}
+#elif USE(TEXTURE_MAPPER) && !USE(COORDINATED_GRAPHICS_THREADED)
void GraphicsContext3DPrivate::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity)
{
if (!m_glContext)
Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext3DPrivate.h (193722 => 193723)
--- trunk/Source/WebCore/platform/graphics/GraphicsContext3DPrivate.h 2015-12-08 08:35:25 UTC (rev 193722)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext3DPrivate.h 2015-12-08 08:36:02 UTC (rev 193723)
@@ -24,6 +24,7 @@
#include "GraphicsContext3D.h"
#if USE(COORDINATED_GRAPHICS_THREADED)
+#include "BitmapTextureGL.h"
#include "TextureMapperPlatformLayerProxy.h"
#elif USE(TEXTURE_MAPPER)
#include "TextureMapperPlatformLayer.h"
@@ -48,7 +49,7 @@
#if USE(COORDINATED_GRAPHICS_THREADED)
virtual RefPtr<TextureMapperPlatformLayerProxy> proxy() const override;
- virtual void swapBuffersIfNeeded() override { };
+ virtual void swapBuffersIfNeeded() override;
#elif USE(TEXTURE_MAPPER)
virtual void paintToTextureMapper(TextureMapper*, const FloatRect& target, const TransformationMatrix&, float opacity);
#endif
@@ -57,6 +58,11 @@
GraphicsContext3D* m_context;
std::unique_ptr<GLContext> m_glContext;
GraphicsContext3D::RenderStyle m_renderStyle;
+
+#if USE(COORDINATED_GRAPHICS_THREADED)
+ RefPtr<TextureMapperPlatformLayerProxy> m_platformLayerProxy;
+ RefPtr<BitmapTextureGL> m_compositorTexture;
+#endif
};
}
Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp (193722 => 193723)
--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp 2015-12-08 08:35:25 UTC (rev 193722)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp 2015-12-08 08:36:02 UTC (rev 193723)
@@ -85,7 +85,11 @@
, m_texture(0)
, m_compositorTexture(0)
, m_fbo(0)
+#if USE(COORDINATED_GRAPHICS_THREADED)
+ , m_compositorFBO(0)
+#endif
, m_depthStencilBuffer(0)
+ , m_layerComposited(false)
, m_multisampleFBO(0)
, m_multisampleDepthStencilBuffer(0)
, m_multisampleColorBuffer(0)
@@ -109,6 +113,17 @@
::glGenFramebuffers(1, &m_fbo);
::glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
+#if USE(COORDINATED_GRAPHICS_THREADED)
+ ::glGenFramebuffers(1, &m_compositorFBO);
+ ::glGenTextures(1, &m_compositorTexture);
+ ::glBindTexture(GL_TEXTURE_2D, m_compositorTexture);
+ ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ ::glBindTexture(GL_TEXTURE_2D, 0);
+#endif
+
m_state.boundFBO = m_fbo;
if (!m_attrs.antialias && (m_attrs.stencil || m_attrs.depth))
::glGenRenderbuffers(1, &m_depthStencilBuffer);
@@ -174,6 +189,9 @@
::glDeleteRenderbuffers(1, &m_depthStencilBuffer);
}
::glDeleteFramebuffers(1, &m_fbo);
+#if USE(COORDINATED_GRAPHICS_THREADED)
+ ::glDeleteFramebuffers(1, &m_compositorFBO);
+#endif
}
GraphicsContext3D::ImageExtractor::~ImageExtractor()
Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp (193722 => 193723)
--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp 2015-12-08 08:35:25 UTC (rev 193722)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp 2015-12-08 08:36:02 UTC (rev 193723)
@@ -172,9 +172,32 @@
::glBindTexture(GL_TEXTURE_2D, m_compositorTexture);
::glTexImage2D(GL_TEXTURE_2D, 0, m_internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
::glBindTexture(GL_TEXTURE_2D, 0);
+#if USE(COORDINATED_GRAPHICS_THREADED)
+ ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_compositorFBO);
+ ::glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_compositorTexture, 0);
+ attachDepthAndStencilBufferIfNeeded(internalDepthStencilFormat, width, height);
+ ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
+#endif
}
#endif
+ attachDepthAndStencilBufferIfNeeded(internalDepthStencilFormat, width, height);
+
+ bool mustRestoreFBO = true;
+ if (m_attrs.antialias) {
+ ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO);
+ if (m_state.boundFBO == m_multisampleFBO)
+ mustRestoreFBO = false;
+ } else {
+ if (m_state.boundFBO == m_fbo)
+ mustRestoreFBO = false;
+ }
+
+ return mustRestoreFBO;
+}
+
+void GraphicsContext3D::attachDepthAndStencilBufferIfNeeded(GLuint internalDepthStencilFormat, int width, int height)
+{
if (!m_attrs.antialias && (m_attrs.stencil || m_attrs.depth)) {
::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthStencilBuffer);
::glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, internalDepthStencilFormat, width, height);
@@ -189,18 +212,6 @@
// FIXME: cleanup
notImplemented();
}
-
- bool mustRestoreFBO = true;
- if (m_attrs.antialias) {
- ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO);
- if (m_state.boundFBO == m_multisampleFBO)
- mustRestoreFBO = false;
- } else {
- if (m_state.boundFBO == m_fbo)
- mustRestoreFBO = false;
- }
-
- return mustRestoreFBO;
}
void GraphicsContext3D::resolveMultisamplingIfNecessary(const IntRect& rect)
Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp (193722 => 193723)
--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp 2015-12-08 08:35:25 UTC (rev 193722)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp 2015-12-08 08:36:02 UTC (rev 193723)
@@ -223,12 +223,25 @@
makeContextCurrent();
+#if !USE(COORDINATED_GRAPHICS_THREADED)
TemporaryOpenGLSetting scopedScissor(GL_SCISSOR_TEST, GL_FALSE);
TemporaryOpenGLSetting scopedDither(GL_DITHER, GL_FALSE);
-
+#endif
+
if (m_attrs.antialias)
resolveMultisamplingIfNecessary();
+#if USE(COORDINATED_GRAPHICS_THREADED)
+ std::swap(m_fbo, m_compositorFBO);
+ std::swap(m_texture, m_compositorTexture);
+
+ if (m_state.boundFBO != m_compositorFBO)
+ ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_state.boundFBO);
+ else
+ ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_fbo);
+ return;
+#endif
+
::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_fbo);
::glActiveTexture(GL_TEXTURE0);
::glBindTexture(GL_TEXTURE_2D, m_compositorTexture);
Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp (193722 => 193723)
--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp 2015-12-08 08:35:25 UTC (rev 193722)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp 2015-12-08 08:36:02 UTC (rev 193723)
@@ -386,6 +386,9 @@
#if USE(GRAPHICS_SURFACE)
if (m_platformLayer)
m_pendingPlatformLayerOperation |= SyncPlatformLayer;
+#elif USE(COORDINATED_GRAPHICS_THREADED)
+ if (m_platformLayer)
+ m_shouldSyncPlatformLayer = true;
#endif
notifyFlushRequired();