Changeset 260816 in webkit
- Timestamp:
- Apr 28, 2020 4:28:36 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r260807 r260816 1 2020-04-28 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK4][Wayland] Add support for rendering web view contents 4 https://bugs.webkit.org/show_bug.cgi?id=211021 5 6 Reviewed by Adrian Perez de Castro. 7 8 Implement GtkWidgetClass::snapshot and GtkWidgetClass::measure instead of GtkWidgetClass::draw and 9 GtkWidgetClass::get_preferred_width|height. Add AcceleratedBackingStore::snapshot() pure virtual to be used with 10 GTK4 instead of AcceleratedBackingStore::paint(), and implement it for Wayland. 11 12 * UIProcess/API/gtk/WebKitWebViewBase.cpp: 13 (webkitWebViewBaseSnapshot): Call AcceleratedBackingStore::snapshot(). 14 (webkitWebViewBaseMeasure): Return the natural width/height for the WebView. 15 (webkit_web_view_base_class_init): Add implementations for snapshot and measure vfuncs. 16 * UIProcess/gtk/AcceleratedBackingStore.h: 17 * UIProcess/gtk/AcceleratedBackingStoreWayland.cpp: 18 (WebKit::AcceleratedBackingStoreWayland::tryEnsureGLContext): Always try to realize the context here, since that 19 can fail too. 20 (WebKit::AcceleratedBackingStoreWayland::tryEnsureTexture): Helper to share the code to prepare the texture. 21 (WebKit::AcceleratedBackingStoreWayland::downloadTexture): Helper to share the code to download the texture. 22 (WebKit::AcceleratedBackingStoreWayland::snapshot): Use gtk_snapshot_append_texture(). 23 (WebKit::AcceleratedBackingStoreWayland::paint): Use new helpers. 24 * UIProcess/gtk/AcceleratedBackingStoreWayland.h: 25 * UIProcess/gtk/AcceleratedBackingStoreX11.cpp: 26 (WebKit::AcceleratedBackingStoreX11::snapshot): 27 * UIProcess/gtk/AcceleratedBackingStoreX11.h: 28 * UIProcess/gtk/HardwareAccelerationManager.cpp: 29 (WebKit::HardwareAccelerationManager::HardwareAccelerationManager): Force accelerated compositing mode for GTK4. 30 1 31 2020-04-27 Devin Rousso <drousso@apple.com> 2 32 -
trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp
r260752 r260816 615 615 } 616 616 617 #if !USE(GTK4) 617 #if USE(GTK4) 618 void webkitWebViewBaseSnapshot(GtkWidget* widget, GtkSnapshot* snapshot) 619 { 620 int scaleFactor = gtk_widget_get_scale_factor(widget); 621 int width = gtk_widget_get_width(widget) * scaleFactor; 622 int height = gtk_widget_get_height(widget) * scaleFactor; 623 if (!width || !height) 624 return; 625 626 WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget); 627 auto* drawingArea = static_cast<DrawingAreaProxyCoordinatedGraphics*>(webViewBase->priv->pageProxy->drawingArea()); 628 if (!drawingArea) 629 return; 630 631 ASSERT(drawingArea->isInAcceleratedCompositingMode()); 632 webViewBase->priv->acceleratedBackingStore->snapshot(snapshot); 633 } 634 #else 618 635 static gboolean webkitWebViewBaseDraw(GtkWidget* widget, cairo_t* cr) 619 636 { … … 721 738 } 722 739 723 #if !USE(GTK4) 740 #if USE(GTK4) 741 static void webkitWebViewBaseMeasure(GtkWidget* widget, GtkOrientation orientation, int, int* minimumSize, int* naturalSize, int*, int*) 742 { 743 WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv; 744 switch (orientation) { 745 case GTK_ORIENTATION_HORIZONTAL: 746 *naturalSize = priv->contentsSize.width(); 747 break; 748 case GTK_ORIENTATION_VERTICAL: 749 *naturalSize = priv->contentsSize.height(); 750 break; 751 } 752 753 *minimumSize = 0; 754 } 755 #else 724 756 static void webkitWebViewBaseGetPreferredWidth(GtkWidget* widget, gint* minimumSize, gint* naturalSize) 725 757 { … … 1477 1509 widgetClass->realize = webkitWebViewBaseRealize; 1478 1510 widgetClass->unrealize = webkitWebViewBaseUnrealize; 1479 #if !USE(GTK4) 1511 #if USE(GTK4) 1512 widgetClass->snapshot = webkitWebViewBaseSnapshot; 1513 #else 1480 1514 widgetClass->draw = webkitWebViewBaseDraw; 1481 1515 #endif 1482 1516 widgetClass->size_allocate = webkitWebViewBaseSizeAllocate; 1483 #if !USE(GTK4) 1517 #if USE(GTK4) 1518 widgetClass->measure = webkitWebViewBaseMeasure; 1519 #else 1484 1520 widgetClass->get_preferred_width = webkitWebViewBaseGetPreferredWidth; 1485 1521 widgetClass->get_preferred_height = webkitWebViewBaseGetPreferredHeight; -
trunk/Source/WebKit/UIProcess/gtk/AcceleratedBackingStore.h
r249947 r260816 30 30 typedef struct _cairo cairo_t; 31 31 32 #if USE(GTK4) 33 typedef struct _GdkSnapshot GdkSnapshot; 34 typedef GdkSnapshot GtkSnapshot; 35 #endif 36 32 37 namespace WebCore { 33 38 class IntRect; … … 47 52 48 53 virtual void update(const LayerTreeContext&) { } 54 #if USE(GTK4) 55 virtual void snapshot(GtkSnapshot*) = 0; 56 #else 49 57 virtual bool paint(cairo_t*, const WebCore::IntRect&) = 0; 58 #endif 50 59 virtual void realize() { }; 51 60 virtual void unrealize() { }; -
trunk/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreWayland.cpp
r260752 r260816 215 215 216 216 m_glContextInitialized = true; 217 218 #if !USE(GTK4)219 217 GUniqueOutPtr<GError> error; 218 #if USE(GTK4) 219 m_gdkGLContext = adoptGRef(gdk_surface_create_gl_context(gtk_native_get_surface(gtk_widget_get_native(m_webPage.viewWidget())), &error.outPtr())); 220 #else 220 221 m_gdkGLContext = adoptGRef(gdk_window_create_gl_context(gtk_widget_get_window(m_webPage.viewWidget()), &error.outPtr())); 222 #endif 221 223 if (m_gdkGLContext) { 222 224 #if USE(OPENGL_ES) 223 225 gdk_gl_context_set_use_es(m_gdkGLContext.get(), TRUE); 224 226 #endif 225 return; 227 gdk_gl_context_realize(m_gdkGLContext.get(), &error.outPtr()); 228 if (!error) 229 return; 226 230 } 227 231 228 232 g_warning("GDK is not able to create a GL context, falling back to glReadPixels (slow!): %s", error->message); 229 #endif230 233 231 234 m_glContext = GLContext::createOffscreenContext(); … … 279 282 #endif 280 283 281 bool AcceleratedBackingStoreWayland::paint(cairo_t* cr, const IntRect& clipRect) 282 { 283 GLuint texture; 284 IntSize textureSize; 285 284 bool AcceleratedBackingStoreWayland::tryEnsureTexture(unsigned& texture, IntSize& textureSize) 285 { 286 286 #if USE(WPE_RENDERER) 287 287 if (!makeContextCurrent()) 288 return true;288 return false; 289 289 290 290 if (m_pendingImage) { … … 298 298 299 299 if (!m_committedImage) 300 return true;300 return false; 301 301 302 302 if (!m_viewTexture) { … … 318 318 #endif 319 319 320 cairo_save(cr); 321 322 #if !USE(GTK4) 323 if (m_gdkGLContext) { 324 gdk_cairo_draw_from_gl(cr, gtk_widget_get_window(m_webPage.viewWidget()), texture, GL_TEXTURE, m_webPage.deviceScaleFactor(), 0, 0, textureSize.width(), textureSize.height()); 325 cairo_restore(cr); 326 return true; 327 } 328 #endif 329 320 return true; 321 } 322 323 void AcceleratedBackingStoreWayland::downloadTexture(unsigned texture, const IntSize& textureSize) 324 { 330 325 ASSERT(m_glContext); 331 326 … … 367 362 glDeleteFramebuffers(1, &fb); 368 363 369 // The surface can be modified by the web process at any time, so we mark it370 // as dirty to ensure we always render the updated contents as soon as possible.371 364 cairo_surface_mark_dirty(m_surface.get()); 365 } 366 367 #if USE(GTK4) 368 void AcceleratedBackingStoreWayland::snapshot(GtkSnapshot* gtkSnapshot) 369 { 370 GLuint texture; 371 IntSize textureSize; 372 if (!tryEnsureTexture(texture, textureSize)) 373 return; 374 375 FloatSize viewSize(gtk_widget_get_width(m_webPage.viewWidget()), gtk_widget_get_height(m_webPage.viewWidget())); 376 if (m_gdkGLContext) { 377 GRefPtr<GdkTexture> gdkTexture = adoptGRef(gdk_gl_texture_new(m_gdkGLContext.get(), texture, textureSize.width(), textureSize.height(), nullptr, nullptr)); 378 graphene_rect_t rect = GRAPHENE_RECT_INIT(0, 0, viewSize.width(), viewSize.height()); 379 gtk_snapshot_append_texture(gtkSnapshot, gdkTexture.get(), &rect); 380 return; 381 } 382 383 downloadTexture(texture, textureSize); 384 385 graphene_rect_t rect = GRAPHENE_RECT_INIT(0, 0, viewSize.width(), viewSize.height()); 386 RefPtr<cairo_t> cr = adoptRef(gtk_snapshot_append_cairo(gtkSnapshot, &rect)); 387 388 // The compositor renders the texture flipped for gdk, fix that here. 389 cairo_matrix_t transform; 390 cairo_matrix_init(&transform, 1, 0, 0, -1, 0, textureSize.height() / m_webPage.deviceScaleFactor()); 391 cairo_transform(cr.get(), &transform); 392 393 cairo_set_source_surface(cr.get(), m_surface.get(), 0, 0); 394 cairo_set_operator(cr.get(), CAIRO_OPERATOR_OVER); 395 cairo_paint(cr.get()); 396 } 397 #else 398 bool AcceleratedBackingStoreWayland::paint(cairo_t* cr, const IntRect& clipRect) 399 { 400 GLuint texture; 401 IntSize textureSize; 402 if (!tryEnsureTexture(texture, textureSize)) 403 return true; 404 405 cairo_save(cr); 406 407 if (m_gdkGLContext) { 408 gdk_cairo_draw_from_gl(cr, gtk_widget_get_window(m_webPage.viewWidget()), texture, GL_TEXTURE, m_webPage.deviceScaleFactor(), 0, 0, textureSize.width(), textureSize.height()); 409 cairo_restore(cr); 410 return true; 411 } 412 413 downloadTexture(texture, textureSize); 372 414 373 415 // The compositor renders the texture flipped for gdk_cairo_draw_from_gl, fix that here. … … 385 427 return true; 386 428 } 429 #endif 387 430 388 431 } // namespace WebKit -
trunk/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreWayland.h
r249947 r260816 44 44 namespace WebCore { 45 45 class GLContext; 46 class IntSize; 46 47 } 47 48 … … 64 65 void displayBuffer(struct wpe_fdo_egl_exported_image*); 65 66 #endif 67 bool tryEnsureTexture(unsigned&, WebCore::IntSize&); 68 void downloadTexture(unsigned, const WebCore::IntSize&); 66 69 70 #if USE(GTK4) 71 void snapshot(GtkSnapshot*) override; 72 #else 67 73 bool paint(cairo_t*, const WebCore::IntRect&) override; 74 #endif 68 75 void realize() override; 69 76 void unrealize() override; -
trunk/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreX11.cpp
r260752 r260816 196 196 } 197 197 198 #if USE(GTK4) 199 void AcceleratedBackingStoreX11::snapshot(GtkSnapshot*) 200 { 201 // FIXME: Implement this. 202 } 203 #else 198 204 bool AcceleratedBackingStoreX11::paint(cairo_t* cr, const IntRect& clipRect) 199 205 { … … 217 223 return true; 218 224 } 225 #endif 219 226 220 227 } // namespace WebKit -
trunk/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreX11.h
r247563 r260816 48 48 49 49 void update(const LayerTreeContext&) override; 50 #if USE(GTK4) 51 void snapshot(GtkSnapshot*) override; 52 #else 50 53 bool paint(cairo_t*, const WebCore::IntRect&) override; 54 #endif 51 55 52 56 RefPtr<cairo_surface_t> m_surface; -
trunk/Source/WebKit/UIProcess/gtk/HardwareAccelerationManager.cpp
r260760 r260816 47 47 #endif 48 48 49 #if USE(GTK4) 50 RELEASE_ASSERT(AcceleratedBackingStore::checkRequirements()); 51 m_forceHardwareAcceleration = true; 52 #endif 53 49 54 const char* disableCompositing = getenv("WEBKIT_DISABLE_COMPOSITING_MODE"); 50 55 if (disableCompositing && strcmp(disableCompositing, "0")) { -
trunk/Tools/ChangeLog
r260811 r260816 1 2020-04-28 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK4][Wayland] Add support for rendering web view contents 4 https://bugs.webkit.org/show_bug.cgi?id=211021 5 6 Reviewed by Adrian Perez de Castro. 7 8 Set vertical expand of web view to TRUE. 9 10 * MiniBrowser/gtk/BrowserTab.c: 11 (browserTabConstructed): 12 1 13 2020-04-27 Philippe Normand <pnormand@igalia.com> 2 14 -
trunk/Tools/MiniBrowser/gtk/BrowserTab.c
r260752 r260816 428 428 gtk_widget_show(GTK_WIDGET(tab->webView)); 429 429 #else 430 gtk_widget_set_vexpand(GTK_WIDGET(tab->webView), TRUE); 430 431 gtk_container_add(GTK_CONTAINER(tab), GTK_WIDGET(tab->webView)); 431 432 #endif
Note: See TracChangeset
for help on using the changeset viewer.