Skip to content

Commit 2deb416

Browse files
committed
Sync WebGL and acc canvas content with fences when available
1 parent bd90673 commit 2deb416

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

Source/WebCore/platform/graphics/cairo/ImageBufferCairoGLSurfaceBackend.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ void ImageBufferCairoGLSurfaceBackend::swapBuffersIfNeeded()
224224
ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy));
225225

226226
Locker locker { proxy.lock() };
227-
downcast<TextureMapperPlatformLayerProxyGL>(proxy).pushNextBuffer(makeUnique<TextureMapperPlatformLayerBuffer>(m_textures[1], backendSize, TextureMapperGL::ShouldBlend, GL_RGBA), false);
227+
auto layerBuffer = makeUnique<TextureMapperPlatformLayerBuffer>(m_textures[1], backendSize, TextureMapperGL::ShouldBlend, GL_RGBA);
228+
layerBuffer->addFenceSyncIfAvailable();
229+
downcast<TextureMapperPlatformLayerProxyGL>(proxy).pushNextBuffer(WTFMove(layerBuffer), false);
228230
}
229231

230232
if (previousActiveContext)

Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLLayer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ void GCGLLayer::swapBuffersIfNeeded()
132132
auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(m_contentLayer->impl()).proxy();
133133
Locker locker { proxy.lock() };
134134
ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy));
135-
downcast<TextureMapperPlatformLayerProxyGL>(proxy).pushNextBuffer(makeUnique<TextureMapperPlatformLayerBuffer>(m_context.m_compositorTexture, textureSize, flags, m_context.m_internalColorFormat), false);
135+
auto layerBuffer = makeUnique<TextureMapperPlatformLayerBuffer>(m_context.m_compositorTexture, textureSize, flags, m_context.m_internalColorFormat);
136+
layerBuffer->addFenceSyncIfAvailable();
137+
downcast<TextureMapperPlatformLayerProxyGL>(proxy).pushNextBuffer(WTFMove(layerBuffer), false);
136138
}
137139

138140
m_context.markLayerComposited();

Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer(TextureVarian
5858

5959
TextureMapperPlatformLayerBuffer::~TextureMapperPlatformLayerBuffer()
6060
{
61+
if (m_sync)
62+
glDeleteSync(static_cast<GLsync>(m_sync));
6163
}
6264

6365
bool TextureMapperPlatformLayerBuffer::canReuseWithoutReset(const IntSize& size, GLint internalFormat)
@@ -129,6 +131,13 @@ void TextureMapperPlatformLayerBuffer::paintToTextureMapper(TextureMapper& textu
129131
m_unmanagedBufferDataHolder->waitForCPUSync();
130132
#endif // USE(GSTREAMER_GL)
131133

134+
if (m_sync) {
135+
glWaitSync(static_cast<GLsync>(m_sync), 0, GL_TIMEOUT_IGNORED);
136+
glDeleteSync(static_cast<GLsync>(m_sync));
137+
glFlush();
138+
m_sync = nullptr;
139+
}
140+
132141
WTF::switchOn(m_variant,
133142
[&](const RGBTexture& texture) {
134143
ASSERT(texture.id);
@@ -176,6 +185,16 @@ bool TextureMapperPlatformLayerBuffer::isHolePunchBuffer()
176185
return (m_extraFlags & TextureMapperGL::ShouldNotBlend) && !m_texture;
177186
}
178187

188+
void TextureMapperPlatformLayerBuffer::addFenceSyncIfAvailable()
189+
{
190+
unsigned version = GLContext::current()->version();
191+
if (version >= 300 && glFenceSync) {
192+
// GLES 3, so fences are available and we can use them.
193+
m_sync = static_cast<void*>(glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0));
194+
glFlush();
195+
}
196+
}
197+
179198
} // namespace WebCore
180199

181200
#endif // USE(COORDINATED_GRAPHICS)

Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ class TextureMapperPlatformLayerBuffer : public TextureMapperPlatformLayer {
102102
const TextureVariant& textureVariant() const { return m_variant; }
103103
IntSize size() const { return m_size; }
104104

105+
void addFenceSyncIfAvailable();
106+
105107
protected:
106108
TextureVariant m_variant;
107109

@@ -115,6 +117,7 @@ class TextureMapperPlatformLayerBuffer : public TextureMapperPlatformLayer {
115117
bool m_hasManagedTexture;
116118
std::unique_ptr<UnmanagedBufferDataHolder> m_unmanagedBufferDataHolder;
117119
std::unique_ptr<HolePunchClient> m_holePunchClient;
120+
void* m_sync { nullptr };
118121
};
119122

120123
} // namespace WebCore

0 commit comments

Comments
 (0)