Skip to content

Commit

Permalink
[WebGPU] Crash PresentationContextIOSurface::getCurrentTexture if con…
Browse files Browse the repository at this point in the history
…text is not configured

https://bugs.webkit.org/show_bug.cgi?id=269103
<radar://122671890>

Reviewed by Dan Glastonbury.

An IPC call made directly to getCurrentTexture may result in a scenario where
the IOSurfaces have not yet been created. In this case, we want to return nullptr
to the caller.

* Source/WebCore/Modules/WebGPU/Implementation/WebGPUPresentationContextImpl.cpp:
(WebCore::WebGPU::PresentationContextImpl::getCurrentTexture):
* Source/WebGPU/WebGPU/PresentationContextIOSurface.mm:
(WebGPU::PresentationContextIOSurface::getCurrentTexture):
(WebGPU::PresentationContextIOSurface::getCurrentTextureView):

Canonical link: https://commits.webkit.org/274452@main
  • Loading branch information
mwyrzykowski committed Feb 12, 2024
1 parent c2fcf98 commit 5bb758b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ RefPtr<Texture> PresentationContextImpl::getCurrentTexture()
return nullptr; // FIXME: This should return an invalid texture instead.

if (!m_currentTexture) {
ASSERT(m_swapChain);
m_currentTexture = TextureImpl::create(WebGPUPtr<WGPUTexture> { wgpuSwapChainGetCurrentTexture(m_swapChain.get()) }, m_format, TextureDimension::_2d, m_convertToBackingContext);
auto texturePtr = wgpuSwapChainGetCurrentTexture(m_swapChain.get());
if (!texturePtr)
return nullptr;
m_currentTexture = TextureImpl::create(WebGPUPtr<WGPUTexture> { texturePtr }, m_format, TextureDimension::_2d, m_convertToBackingContext);
}

return m_currentTexture;
Expand Down
8 changes: 6 additions & 2 deletions Source/WebGPU/WebGPU/PresentationContextIOSurface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,19 @@

Texture* PresentationContextIOSurface::getCurrentTexture()
{
ASSERT(m_ioSurfaces.count == m_renderBuffers.size());
if (m_ioSurfaces.count != m_renderBuffers.size() || m_renderBuffers.size() <= m_currentIndex)
return nullptr;

auto& texture = m_renderBuffers[m_currentIndex].texture;
texture->recreateIfNeeded();
return texture.ptr();
}

TextureView* PresentationContextIOSurface::getCurrentTextureView()
{
ASSERT(m_ioSurfaces.count == m_renderBuffers.size());
if (m_ioSurfaces.count != m_renderBuffers.size() || m_renderBuffers.size() <= m_currentIndex)
return nullptr;

return m_renderBuffers[m_currentIndex].textureView.ptr();
}

Expand Down

0 comments on commit 5bb758b

Please sign in to comment.