Skip to content

Commit 751b9a0

Browse files
Merge pull request #1491 from LibertyGlobal/tkarczewski/2.38/ThreadedCompositor_resize_wayland_surfaces_at_suspend_painting
ThreadedCompositor: resize wayland surfaces at suspend painting
2 parents 14f26b6 + c82128a commit 751b9a0

3 files changed

Lines changed: 38 additions & 3 deletions

File tree

Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ void ThreadedCompositor::resume()
169169
m_scene->setActive(true);
170170
m_suspendToTransparentState = SuspendToTransparentState::None;
171171
});
172+
#if ENABLE(RESIZE_WAYLAND_SURFACES_ON_SUSPEND_PAINTING)
173+
if (!m_nonCompositedWebGLEnabled) {
174+
// need to resize the view on resume
175+
Locker locker { m_attributes.lock };
176+
m_attributes.needsResize = true;
177+
}
178+
#endif
179+
172180
m_compositingRunLoop->resume();
173181
m_compositingRunLoop->scheduleUpdate();
174182
}
@@ -281,9 +289,20 @@ void ThreadedCompositor::renderLayerTree()
281289
// GL viewport is updated separately, if necessary. This establishes sequencing where
282290
// everything inside the will-render and did-render scope is done for a constant-sized scene,
283291
// and similarly all GL operations are done inside that specific scope.
284-
292+
#if !ENABLE(RESIZE_WAYLAND_SURFACES_ON_SUSPEND_PAINTING)
285293
if (needsResize)
286294
m_client.resize(viewportSize);
295+
#else
296+
// since we got this far, we know m_nonCompositedWebGLEnabled is false, no need to check
297+
if (needsResize && m_suspendToTransparentState != SuspendToTransparentState::Requested) {
298+
m_client.resize(viewportSize);
299+
} else if (m_suspendToTransparentState == SuspendToTransparentState::Requested) {
300+
// resizing the surfaces, to conserve the memory; going too small (like 1x1) will not properly work
301+
// on some platformns, so choosing 16x16 (should only take around 3*1kB in suspended, instead of eg. 3*8MB for HD)
302+
constexpr IntSize suspendedSize(16, 16);
303+
m_client.resize(suspendedSize);
304+
}
305+
#endif
287306

288307
m_client.willRenderFrame();
289308

@@ -301,6 +320,21 @@ void ThreadedCompositor::renderLayerTree()
301320

302321
m_context->swapBuffers();
303322

323+
#if ENABLE(RESIZE_WAYLAND_SURFACES_ON_SUSPEND_PAINTING)
324+
// since we got this far, we know m_nonCompositedWebGLEnabled is false, no need to check
325+
if (m_suspendToTransparentState == SuspendToTransparentState::WaitingForFrameComplete) {
326+
/* With triple buffering we normally have 3 screen buffers. The backing surfaces may only be really
327+
resized when they're presented - so we need 3 buffer swaps to make sure all these surfaces
328+
are resized to the requested suspendedSize, thus saving the memory in suspend
329+
(one swapBuffers is already done above) */
330+
for (int i=0; i<2; ++i) {
331+
glClearColor(0, 0, 0, 0);
332+
glClear(GL_COLOR_BUFFER_BIT);
333+
m_context->swapBuffers();
334+
}
335+
}
336+
#endif
337+
304338
if (m_scene->isActive())
305339
m_client.didRenderFrame();
306340
}

Source/WebKit/WebProcess/WebPage/libwpe/AcceleratedSurfaceLibWPE.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ uint64_t AcceleratedSurfaceLibWPE::surfaceID() const
9797
void AcceleratedSurfaceLibWPE::clientResize(const IntSize& size)
9898
{
9999
ASSERT(m_backend);
100-
wpe_renderer_backend_egl_target_resize(m_backend, std::max(1, m_size.width()), std::max(1, m_size.height()));
100+
wpe_renderer_backend_egl_target_resize(m_backend, std::max(1, size.width()), std::max(1, size.height()));
101101
}
102102

103103
void AcceleratedSurfaceLibWPE::willRenderFrame()

Source/cmake/OptionsWPE.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ WEBKIT_OPTION_DEFINE(USE_EXTERNAL_HOLEPUNCH "Whether to enable external holepunc
107107
WEBKIT_OPTION_DEFINE(ENABLE_ACCELERATED_2D_CANVAS "Whether to enable accelerated 2D canvas" PRIVATE OFF)
108108
WEBKIT_OPTION_DEFINE(ENABLE_OIPF_VK "Whether to enable OIPF keys for DAE applications" PRIVATE OFF)
109109
WEBKIT_OPTION_DEFINE(USE_LINUX_FTRACE "Whether to use ftrace based webkit tracing" PRIVATE OFF)
110+
WEBKIT_OPTION_DEFINE(ENABLE_RESIZE_WAYLAND_SURFACES_ON_SUSPEND_PAINTING "Whether to enable resizing of wayland surfaces when painting is suspended" PRIVATE OFF)
110111

111112
# Supported platforms.
112113
WEBKIT_OPTION_DEFINE(USE_WPEWEBKIT_PLATFORM_WESTEROS "Whether to enable support for the Westeros platform" PUBLIC OFF)
@@ -441,4 +442,4 @@ if (USE_LIBBACKTRACE)
441442
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}${CMAKE_COMPILER_SIZE_OPT_FLAGS} -funwind-tables")
442443

443444
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}${CMAKE_COMPILER_SIZE_OPT_FLAGS} -funwind-tables")
444-
endif ()
445+
endif ()

0 commit comments

Comments
 (0)