Skip to content

Commit f47827c

Browse files
committed
[WPE] Implement non-composited page rendering
https://bugs.webkit.org/show_bug.cgi?id=303170 Reviewed by Carlos Garcia Campos. This change implements the non-composited page rendering for WPE. With this change, it's possible to utilize a simplified frame rendering that does not use compositor at all. It's useful especially on low-end embedded devices where GPU is not powerful or not present at all. The non-composited mode implemented in this change can be enabled using a -AcceleratedCompositing preference. Additionally, this change adds a layout ref-test that protects the new implementation as well as existing, GTK's implementation from regressions. Canonical link: https://commits.webkit.org/304678@main
1 parent fac224c commit f47827c

File tree

10 files changed

+318
-2
lines changed

10 files changed

+318
-2
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html><!-- webkit-test-runner [ AcceleratedCompositingEnabled=true ] -->
2+
<html lang="en">
3+
<body>
4+
This is a text.
5+
<div style="background-color: yellow;">This is a text in block</div>
6+
<b>This is a text in bold</b>
7+
<div style="width: 50px; height: 50px; border: 2px solid blue;"></div>
8+
</body>
9+
</html>
10+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html><!-- webkit-test-runner [ AcceleratedCompositingEnabled=false ] -->
2+
<html lang="en">
3+
<head>
4+
<meta name="fuzzy" content="maxDifference=0-5; totalPixels=0-14" />
5+
</head>
6+
<body>
7+
This is a text.
8+
<div style="background-color: yellow;">This is a text in block</div>
9+
<b>This is a text in bold</b>
10+
<div style="width: 50px; height: 50px; border: 2px solid blue;"></div>
11+
</body>
12+
</html>
13+

Source/WebKit/SourcesWPE.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ WebProcess/WebPage/CoordinatedGraphics/AcceleratedSurface.cpp
328328
WebProcess/WebPage/CoordinatedGraphics/CoordinatedSceneState.cpp
329329
WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp
330330
WebProcess/WebPage/CoordinatedGraphics/LayerTreeHost.cpp
331+
WebProcess/WebPage/CoordinatedGraphics/NonCompositedFrameRenderer.cpp
331332
WebProcess/WebPage/CoordinatedGraphics/ThreadedCompositor.cpp
332333

333334
WebProcess/WebPage/glib/WebPageGLib.cpp

Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/AcceleratedSurface.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
#if USE(COORDINATED_GRAPHICS)
3030
#include "WebPage.h"
3131
#include "WebProcess.h"
32+
#include <WebCore/GLContext.h>
3233
#include <WebCore/GLFence.h>
34+
#include <WebCore/GraphicsContext.h>
3335
#include <WebCore/PlatformDisplay.h>
3436
#include <WebCore/Region.h>
3537
#include <WebCore/ShareableBitmap.h>
@@ -75,6 +77,12 @@
7577
#include <wtf/glib/RunLoopSourcePriority.h>
7678
#endif
7779

80+
#if USE(SKIA)
81+
#include <skia/gpu/ganesh/GrBackendSurface.h>
82+
#include <skia/gpu/ganesh/SkSurfaceGanesh.h>
83+
#include <skia/gpu/ganesh/gl/GrGLBackendSurface.h>
84+
#endif
85+
7886
namespace WebKit {
7987
using namespace WebCore;
8088

@@ -153,6 +161,7 @@ WTF_MAKE_TZONE_ALLOCATED_IMPL(AcceleratedSurface::RenderTargetShareableBuffer);
153161

154162
AcceleratedSurface::RenderTargetShareableBuffer::RenderTargetShareableBuffer(uint64_t surfaceID, const IntSize& size)
155163
: RenderTarget(surfaceID)
164+
, m_initialSize(size)
156165
{
157166
glGenFramebuffers(1, &m_fbo);
158167
glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
@@ -181,6 +190,48 @@ void AcceleratedSurface::RenderTargetShareableBuffer::didRenderFrame(Vector<IntR
181190
WebProcess::singleton().parentProcessConnection()->send(Messages::AcceleratedBackingStore::Frame(m_id, WTFMove(damageRects), WTFMove(m_renderingFenceFD)), m_surfaceID);
182191
}
183192

193+
GraphicsContext* AcceleratedSurface::RenderTargetShareableBuffer::graphicsContext()
194+
{
195+
#if USE(SKIA)
196+
if (!m_graphicsContext.context) {
197+
int stencilBits;
198+
glGetIntegerv(GL_STENCIL_BITS, &stencilBits);
199+
const int sampleCount = 0; // 0 == no MSAA.
200+
GrGLFramebufferInfo fbInfo;
201+
fbInfo.fFBOID = m_fbo;
202+
fbInfo.fFormat = GL_RGBA8;
203+
GrBackendRenderTarget renderTargetSkia = GrBackendRenderTargets::MakeGL(
204+
m_initialSize.width(),
205+
m_initialSize.height(),
206+
sampleCount,
207+
stencilBits,
208+
fbInfo
209+
);
210+
if (!PlatformDisplay::sharedDisplay().skiaGLContext() || !PlatformDisplay::sharedDisplay().skiaGLContext()->makeContextCurrent())
211+
return nullptr;
212+
m_graphicsContext.surface = SkSurfaces::WrapBackendRenderTarget(
213+
PlatformDisplay::sharedDisplay().skiaGrContext(),
214+
renderTargetSkia,
215+
GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin,
216+
SkColorType::kRGBA_8888_SkColorType,
217+
nullptr,
218+
nullptr
219+
);
220+
if (!m_graphicsContext.surface)
221+
return nullptr;
222+
SkCanvas* canvas = m_graphicsContext.surface->getCanvas();
223+
if (!canvas)
224+
return nullptr;
225+
// Fresh buffer should default to non-opaque white.
226+
canvas->clear(SK_ColorWHITE);
227+
m_graphicsContext.context = makeUnique<GraphicsContextSkia>(*canvas, RenderingMode::Accelerated, RenderingPurpose::Unspecified);
228+
}
229+
return m_graphicsContext.context ? &*m_graphicsContext.context : nullptr;
230+
#else
231+
RELEASE_ASSERT_NOT_REACHED();
232+
#endif
233+
}
234+
184235
void AcceleratedSurface::RenderTargetShareableBuffer::willRenderFrame()
185236
{
186237
if (m_releaseFenceFD) {
@@ -205,6 +256,15 @@ std::unique_ptr<GLFence> AcceleratedSurface::RenderTargetShareableBuffer::create
205256

206257
void AcceleratedSurface::RenderTargetShareableBuffer::sync(bool useExplicitSync)
207258
{
259+
#if USE(SKIA)
260+
if (m_graphicsContext.surface) {
261+
PlatformDisplay::sharedDisplay().skiaGrContext()->flushAndSubmit(
262+
m_graphicsContext.surface.get(),
263+
GLFence::isSupported(PlatformDisplay::sharedDisplay().glDisplay()) ? GrSyncCpu::kNo : GrSyncCpu::kYes
264+
);
265+
}
266+
#endif
267+
208268
if (auto fence = createRenderingFence(useExplicitSync)) {
209269
m_renderingFenceFD = fence->exportFD();
210270
if (!m_renderingFenceFD)
@@ -925,6 +985,11 @@ uint64_t AcceleratedSurface::window() const
925985
return 0;
926986
}
927987

988+
GraphicsContext* AcceleratedSurface::graphicsContext()
989+
{
990+
return m_target ? m_target->graphicsContext() : nullptr;
991+
}
992+
928993
void AcceleratedSurface::willRenderFrame(const IntSize& size)
929994
{
930995
bool sizeDidChange = m_swapChain.resize(size);

Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/AcceleratedSurface.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ typedef struct AHardwareBuffer AHardwareBuffer;
5656
typedef void *EGLImage;
5757
#endif
5858

59+
#if USE(SKIA)
60+
#include <WebCore/GraphicsContextSkia.h>
61+
#endif
62+
5963
#if USE(WPE_RENDERER)
6064
struct wpe_renderer_backend_egl_target;
6165
#endif
@@ -66,6 +70,7 @@ class RunLoop;
6670

6771
namespace WebCore {
6872
class GLFence;
73+
class GraphicsContext;
6974
class ShareableBitmap;
7075
class ShareableBitmapHandle;
7176
}
@@ -104,6 +109,8 @@ class AcceleratedSurface final : public ThreadSafeRefCountedAndCanMakeThreadSafe
104109
#endif
105110
}
106111

112+
WebCore::GraphicsContext* graphicsContext();
113+
107114
void willDestroyGLContext();
108115
void willRenderFrame(const WebCore::IntSize&);
109116
void didRenderFrame();
@@ -143,6 +150,8 @@ class AcceleratedSurface final : public ThreadSafeRefCountedAndCanMakeThreadSafe
143150

144151
uint64_t id() const { return m_id; }
145152

153+
virtual WebCore::GraphicsContext* graphicsContext() { RELEASE_ASSERT_NOT_REACHED(); }
154+
146155
virtual void willRenderFrame() { }
147156
virtual void didRenderFrame(Vector<WebCore::IntRect, 1>&&) { }
148157

@@ -177,6 +186,8 @@ class AcceleratedSurface final : public ThreadSafeRefCountedAndCanMakeThreadSafe
177186
protected:
178187
RenderTargetShareableBuffer(uint64_t, const WebCore::IntSize&);
179188

189+
WebCore::GraphicsContext* graphicsContext() override;
190+
180191
void willRenderFrame() override;
181192
void didRenderFrame(Vector<WebCore::IntRect, 1>&&) override;
182193

@@ -188,6 +199,13 @@ class AcceleratedSurface final : public ThreadSafeRefCountedAndCanMakeThreadSafe
188199
unsigned m_depthStencilBuffer { 0 };
189200
UnixFileDescriptor m_renderingFenceFD;
190201
UnixFileDescriptor m_releaseFenceFD;
202+
#if USE(SKIA)
203+
struct {
204+
sk_sp<SkSurface> surface;
205+
std::unique_ptr<WebCore::GraphicsContextSkia> context;
206+
} m_graphicsContext;
207+
#endif
208+
WebCore::IntSize m_initialSize;
191209
};
192210

193211
#if USE(GBM) || OS(ANDROID)

Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
#include "LayerTreeHostTextureMapper.h"
6262
#endif
6363

64+
#if PLATFORM(WPE)
65+
#include "NonCompositedFrameRenderer.h"
66+
#endif
67+
6468
namespace WebKit {
6569
using namespace WebCore;
6670

@@ -96,6 +100,13 @@ void DrawingAreaCoordinatedGraphics::setNeedsDisplayInRect(const IntRect& rect)
96100
#endif
97101
return;
98102
}
103+
#if PLATFORM(WPE)
104+
else if (m_nonCompositedFrameRenderer) {
105+
ASSERT(m_dirtyRegion.isEmpty());
106+
scheduleDisplay();
107+
return;
108+
}
109+
#endif
99110

100111
IntRect dirtyRect = rect;
101112
dirtyRect.intersect(m_webPage->bounds());
@@ -114,6 +125,10 @@ void DrawingAreaCoordinatedGraphics::scroll(const IntRect& scrollRect, const Int
114125
ASSERT(m_dirtyRegion.isEmpty());
115126
return;
116127
}
128+
#if PLATFORM(WPE)
129+
else if (m_nonCompositedFrameRenderer)
130+
return;
131+
#endif
117132

118133
if (scrollRect.isEmpty())
119134
return;
@@ -162,6 +177,12 @@ void DrawingAreaCoordinatedGraphics::scroll(const IntRect& scrollRect, const Int
162177
void DrawingAreaCoordinatedGraphics::updateRenderingWithForcedRepaint()
163178
{
164179
if (!m_layerTreeHost) {
180+
#if PLATFORM(WPE)
181+
if (m_nonCompositedFrameRenderer) {
182+
display();
183+
return;
184+
}
185+
#endif
165186
m_isWaitingForDidUpdate = false;
166187
m_dirtyRegion = m_webPage->bounds();
167188
display();
@@ -240,8 +261,12 @@ void DrawingAreaCoordinatedGraphics::updatePreferences(const WebPreferencesStore
240261
bool DrawingAreaCoordinatedGraphics::enterAcceleratedCompositingModeIfNeeded()
241262
{
242263
ASSERT(!m_layerTreeHost);
243-
if (!m_alwaysUseCompositing)
264+
if (!m_alwaysUseCompositing) {
265+
#if PLATFORM(WPE)
266+
m_nonCompositedFrameRenderer = NonCompositedFrameRenderer::create(m_webPage);
267+
#endif
244268
return false;
269+
}
245270

246271
enterAcceleratedCompositingMode(nullptr);
247272
return true;
@@ -369,6 +394,10 @@ void DrawingAreaCoordinatedGraphics::updateGeometry(const IntSize& size, Complet
369394

370395
if (m_layerTreeHost)
371396
m_layerTreeHost->sizeDidChange();
397+
#if PLATFORM(WPE)
398+
else if (m_nonCompositedFrameRenderer)
399+
m_nonCompositedFrameRenderer->display();
400+
#endif
372401
else {
373402
m_dirtyRegion = IntRect(IntPoint(), size);
374403
UpdateInfo updateInfo;
@@ -412,6 +441,10 @@ void DrawingAreaCoordinatedGraphics::dispatchAfterEnsuringDrawing(IPC::AsyncRepl
412441
}
413442
} else {
414443
if (!m_isPaintingSuspended) {
444+
#if PLATFORM(WPE)
445+
if (!m_nonCompositedFrameRenderer)
446+
#endif
447+
m_dirtyRegion = m_webPage->bounds();
415448
scheduleDisplay();
416449
return;
417450
}
@@ -658,6 +691,14 @@ void DrawingAreaCoordinatedGraphics::display()
658691
if (m_isPaintingSuspended)
659692
return;
660693

694+
#if PLATFORM(WPE)
695+
if (m_nonCompositedFrameRenderer) {
696+
m_nonCompositedFrameRenderer->display();
697+
dispatchPendingCallbacksAfterEnsuringDrawing();
698+
return;
699+
}
700+
#endif
701+
661702
UpdateInfo updateInfo;
662703
display(updateInfo);
663704

@@ -779,6 +820,9 @@ void DrawingAreaCoordinatedGraphics::forceUpdate()
779820
if (m_isWaitingForDidUpdate || m_layerTreeHost)
780821
return;
781822

823+
#if PLATFORM(WPE)
824+
if (!m_nonCompositedFrameRenderer)
825+
#endif
782826
m_dirtyRegion = m_webPage->bounds();
783827
display();
784828
}

Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class GraphicsContext;
3636
}
3737

3838
namespace WebKit {
39+
class NonCompositedFrameRenderer;
3940
struct RenderProcessInfo;
4041
struct UpdateInfo;
4142

@@ -149,6 +150,11 @@ class DrawingAreaCoordinatedGraphics final : public DrawingArea {
149150
// The layer tree host that handles accelerated compositing.
150151
std::unique_ptr<LayerTreeHost> m_layerTreeHost;
151152

153+
#if PLATFORM(WPE)
154+
// Frame renderer used in non-composited mode.
155+
std::unique_ptr<NonCompositedFrameRenderer> m_nonCompositedFrameRenderer;
156+
#endif
157+
152158
WebCore::Region m_dirtyRegion;
153159
WebCore::IntRect m_scrollRect;
154160
WebCore::IntSize m_scrollOffset;

0 commit comments

Comments
 (0)