Skip to content

Commit

Permalink
[GTK] Make it possible to build with Skia instead of Cairo
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=270510

Reviewed by Don Olmstead.

Add build option to enable Skia in the GTK port. This is just an initial
patch, there are many features broken when building with Skia like
printing, non-accelerated mode, favicons, snapshots, etc. We will fix
them all in follow up patches.

* Source/WTF/wtf/PlatformUse.h:
* Source/WebCore/PlatformGTK.cmake:
* Source/WebCore/SourcesGTK.txt:
* Source/WebCore/platform/DragImage.h:
* Source/WebCore/platform/adwaita/ScrollbarThemeAdwaita.cpp:
* Source/WebCore/platform/graphics/IntRect.h:
* Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp:
* Source/WebCore/platform/graphics/cairo/RefPtrCairo.h:
* Source/WebCore/platform/graphics/gstreamer/ImageGStreamerSkia.cpp:
* Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp:
* Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.h:
* Source/WebCore/platform/graphics/gtk/ImageAdapterGtk.cpp:
(WebCore::ImageAdapter::gdkPixbuf):
(WebCore::ImageAdapter::gdkTexture):
* Source/WebCore/platform/gtk/CursorGtk.cpp:
(WebCore::createCustomCursor):
* Source/WebCore/platform/gtk/DragImageGtk.cpp:
(WebCore::dragImageSize):
(WebCore::scaleDragImage):
(WebCore::dissolveDragImageToFraction):
* Source/WebCore/platform/gtk/RenderThemeGadget.cpp:
* Source/WebCore/platform/gtk/RenderThemeGadget.h:
* Source/WebCore/platform/gtk/RenderThemeScrollbar.cpp:
* Source/WebCore/platform/gtk/RenderThemeScrollbar.h:
* Source/WebCore/platform/gtk/ScrollbarThemeGtk.cpp:
* Source/WebCore/platform/gtk/ScrollbarThemeGtk.h:
* Source/WebKit/SourcesGTK.txt:
* Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.cpp:
(API::ProcessPoolConfiguration::copy):
* Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.h:
* Source/WebKit/UIProcess/API/glib/WebKitFaviconDatabase.cpp:
(webkitFaviconDatabaseGetFaviconInternal):
(webkit_favicon_database_get_favicon_finish):
* Source/WebKit/UIProcess/API/glib/WebKitWebContext.cpp:
(webkitWebContextConstructed):
* Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp:
* Source/WebKit/UIProcess/API/gtk/DragSourceGtk3.cpp:
(WebKit::DragSource::begin):
* Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp:
(WebKit::PageClientImpl::setViewNeedsDisplay):
* Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp:
* Source/WebKit/UIProcess/Automation/cairo/WebAutomationSessionCairo.cpp:
* Source/WebKit/UIProcess/BackingStore.h:
* Source/WebKit/UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.cpp:
(WebKit::DrawingAreaProxyCoordinatedGraphics::DrawingAreaProxyCoordinatedGraphics):
(WebKit::DrawingAreaProxyCoordinatedGraphics::setBackingStoreIsDiscardable):
(WebKit::DrawingAreaProxyCoordinatedGraphics::update):
(WebKit::DrawingAreaProxyCoordinatedGraphics::exitAcceleratedCompositingMode):
(WebKit::DrawingAreaProxyCoordinatedGraphics::enterAcceleratedCompositingMode):
* Source/WebKit/UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.h:
* Source/WebKit/UIProcess/ViewGestureController.h:
* Source/WebKit/UIProcess/cairo/BackingStoreCairo.cpp:
(WebKit::BackingStore::incorporateUpdate):
(WebKit::BackingStore::scroll):
* Source/WebKit/UIProcess/glib/WebProcessPoolGLib.cpp:
(WebKit::WebProcessPool::platformInitializeWebProcess):
* Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreDMABuf.cpp:
(WebKit::AcceleratedBackingStoreDMABuf::BufferSHM::didUpdateContents):
* Source/WebKit/UIProcess/gtk/ViewSnapshotStoreGtk3.cpp:
* Source/WebKit/WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp:
(WebKit::WebDragClient::startDrag):
* Source/WebKit/WebProcess/WebPage/gtk/WebPrintOperationGtk.cpp:
(WebKit::WebPrintOperationGtk::startPrint):
(WebKit::WebPrintOperationGtk::rotatePageIfNeeded):
(WebKit::WebPrintOperationGtk::prepareContextToDraw):
(WebKit::WebPrintOperationGtk::renderPage):
(WebKit::WebPrintOperationGtk::printPagesDone):
* Source/WebKit/WebProcess/WebPage/gtk/WebPrintOperationGtk.h:
* Source/WebKit/WebProcess/WebProcess.h:
* Source/WebKit/WebProcess/WebProcess.messages.in:
* Source/WebKit/WebProcess/glib/WebProcessGLib.cpp:
(WebKit::WebProcess::platformInitializeWebProcess):
* Source/WebKit/WebProcess/gtk/GtkSettingsManagerProxy.cpp:
(WebKit::GtkSettingsManagerProxy::applyHintingSettings):
(WebKit::GtkSettingsManagerProxy::applyAntialiasSettings):
* Source/cmake/OptionsGTK.cmake:
* Tools/TestWebKitAPI/glib/WebKitGLib/TestMain.h:
* Tools/WebKitTestRunner/PlatformGTK.cmake:
* Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp:
(WTR::PlatformWebView::windowSnapshotImage):
* Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp:
(WTR::TestController::takeViewPortSnapshot):

Canonical link: https://commits.webkit.org/275829@main
  • Loading branch information
carlosgcampos committed Mar 8, 2024
1 parent 123411a commit 75df56f
Show file tree
Hide file tree
Showing 52 changed files with 290 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Source/WTF/wtf/PlatformUse.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
#define USE_GLIB 1
#endif

#if PLATFORM(GTK) || (PLATFORM(WPE) && !USE(SKIA))
#if ((PLATFORM(GTK) || PLATFORM(WPE)) && !USE(SKIA))
#define USE_FREETYPE 1
#endif

Expand Down
23 changes: 21 additions & 2 deletions Source/WebCore/PlatformGTK.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
include(platform/Adwaita.cmake)
include(platform/Cairo.cmake)
include(platform/FreeType.cmake)
include(platform/GCrypt.cmake)
include(platform/GStreamer.cmake)
include(platform/ImageDecoders.cmake)
include(platform/Soup.cmake)
include(platform/TextureMapper.cmake)

if (USE_CAIRO)
include(platform/Cairo.cmake)
include(platform/FreeType.cmake)
elseif (USE_SKIA)
include(platform/Skia.cmake)
endif ()

list(APPEND WebCore_UNIFIED_SOURCE_LIST_FILES
"SourcesGTK.txt"

Expand Down Expand Up @@ -122,6 +127,20 @@ if (ENABLE_SPEECH_SYNTHESIS)
)
endif ()

if (USE_SKIA)
# When building with Skia we don't build Cairo sources, but since
# Cairo is still needed in the UI process API we need to include
# here the Cairo sources required.
list(APPEND WebCore_SOURCES
platform/graphics/cairo/IntRectCairo.cpp
platform/graphics/cairo/RefPtrCairo.cpp
)

list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS
platform/graphics/cairo/RefPtrCairo.h
)
endif ()

include_directories(SYSTEM
${WebCore_SYSTEM_INCLUDE_DIRECTORIES}
)
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/platform/DragImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ OBJC_CLASS NSImage;
typedef struct HBITMAP__* HBITMAP;
#elif USE(CAIRO)
#include "RefPtrCairo.h"
#elif USE(SKIA)
#include <skia/core/SkImage.h>
#endif

namespace WebCore {
Expand All @@ -61,6 +63,8 @@ typedef RetainPtr<NSImage> DragImageRef;
typedef HBITMAP DragImageRef;
#elif USE(CAIRO)
typedef RefPtr<cairo_surface_t> DragImageRef;
#elif USE(SKIA)
typedef sk_sp<SkImage> DragImageRef;
#else
typedef void* DragImageRef;
#endif
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/adwaita/ScrollbarThemeAdwaita.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ ScrollbarButtonPressAction ScrollbarThemeAdwaita::handleMousePressEvent(Scrollba
return ScrollbarButtonPressAction::None;
}

#if !PLATFORM(GTK) || USE(GTK4)
#if !PLATFORM(GTK) || USE(GTK4) || USE(SKIA)
ScrollbarTheme& ScrollbarTheme::nativeTheme()
{
static ScrollbarThemeAdwaita theme;
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/platform/graphics/IntRect.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ typedef struct _NSRect NSRect;
typedef struct tagRECT RECT;
#endif

#if USE(CAIRO)
#if USE(CAIRO) || PLATFORM(GTK)
typedef struct _cairo_rectangle_int cairo_rectangle_int_t;
#endif

Expand Down Expand Up @@ -198,7 +198,7 @@ class IntRect {
WEBCORE_EXPORT operator RECT() const;
#endif

#if USE(CAIRO)
#if USE(CAIRO) || PLATFORM(GTK)
IntRect(const cairo_rectangle_int_t&);
operator cairo_rectangle_int_t() const;
#endif
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/platform/graphics/cairo/IntRectCairo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "config.h"
#include "IntRect.h"

#if USE(CAIRO)
#if USE(CAIRO) || PLATFORM(GTK)

#include <cairo.h>

Expand All @@ -41,4 +41,4 @@ IntRect::operator cairo_rectangle_int_t() const

} // namespace WebCore

#endif // USE(CAIRO)
#endif // USE(CAIRO) || PLATFORM(GTK)
4 changes: 2 additions & 2 deletions Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "config.h"
#include "RefPtrCairo.h"

#if USE(CAIRO)
#if USE(CAIRO) || PLATFORM(GTK)

#include <cairo.h>

Expand Down Expand Up @@ -105,4 +105,4 @@ void DefaultRefDerefTraits<cairo_region_t>::derefIfNotNull(cairo_region_t* ptr)

} // namespace WTF

#endif // USE(CAIRO)
#endif // USE(CAIRO) || PLATFORM(GTK)
4 changes: 2 additions & 2 deletions Source/WebCore/platform/graphics/cairo/RefPtrCairo.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#pragma once

#if USE(CAIRO)
#if USE(CAIRO) || PLATFORM(GTK)

#include <wtf/RefPtr.h>

Expand Down Expand Up @@ -70,4 +70,4 @@ struct DefaultRefDerefTraits<cairo_region_t> {

} // namespace WTF

#endif // USE(CAIRO)
#endif // USE(CAIRO) || PLATFORM(GTK)
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#if ENABLE(VIDEO) && USE(GSTREAMER) && USE(SKIA)

#include "GStreamerCommon.h"
#include "NotImplemented.h"
#include <gst/gst.h>
#include <gst/video/gstvideometa.h>
#include <skia/core/SkImage.h>
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "config.h"
#include "GdkCairoUtilities.h"

#if USE(CAIRO)

#include "CairoUtilities.h"
#include "IntSize.h"
#include <cairo.h>
Expand Down Expand Up @@ -60,3 +62,5 @@ GRefPtr<GdkTexture> cairoSurfaceToGdkTexture(cairo_surface_t* surface)
#endif

} // namespace WebCore

#endif // #if USE(CAIRO)
4 changes: 4 additions & 0 deletions Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#pragma once

#if USE(CAIRO)

#include <wtf/glib/GRefPtr.h>

#if USE(GTK4)
Expand All @@ -38,3 +40,5 @@ GRefPtr<GdkPixbuf> cairoSurfaceToGdkPixbuf(cairo_surface_t*);
GRefPtr<GdkTexture> cairoSurfaceToGdkTexture(cairo_surface_t*);
#endif
}

#endif // USE(CAIRO)
11 changes: 11 additions & 0 deletions Source/WebCore/platform/graphics/gtk/ImageAdapterGtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "BitmapImage.h"
#include "GdkCairoUtilities.h"
#include "NotImplemented.h"
#include "SharedBuffer.h"
#include <cairo.h>
#include <gdk/gdk.h>
Expand Down Expand Up @@ -60,8 +61,13 @@ GRefPtr<GdkPixbuf> ImageAdapter::gdkPixbuf()
if (!nativeImage)
return nullptr;

#if USE(CAIRO)
auto& surface = nativeImage->platformImage();
return cairoSurfaceToGdkPixbuf(surface.get());
#elif USE(SKIA)
notImplemented();
return nullptr;
#endif
}

#if USE(GTK4)
Expand All @@ -71,8 +77,13 @@ GRefPtr<GdkTexture> ImageAdapter::gdkTexture()
if (!nativeImage)
return nullptr;

#if USE(CAIRO)
auto& surface = nativeImage->platformImage();
return cairoSurfaceToGdkTexture(surface.get());
#elif USE(SKIA)
notImplemented();
return nullptr;
#endif
}
#endif

Expand Down
7 changes: 7 additions & 0 deletions Source/WebCore/platform/gtk/CursorGtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "Image.h"
#include "IntPoint.h"
#include "NotImplemented.h"
#include <gdk/gdk.h>
#include <wtf/NeverDestroyed.h>

Expand Down Expand Up @@ -67,9 +68,15 @@ static GRefPtr<GdkCursor> createCustomCursor(Image* image, const IntPoint& hotSp
if (!nativeImage)
return nullptr;

#if USE(CAIRO)
auto& surface = nativeImage->platformImage();
IntPoint effectiveHotSpot = determineHotSpot(image, hotSpot);
return adoptGRef(gdk_cursor_new_from_surface(gdk_display_get_default(), surface.get(), effectiveHotSpot.x(), effectiveHotSpot.y()));
#elif USE(SKIA)
UNUSED_PARAM(hotSpot);
notImplemented();
return nullptr;
#endif
#endif // USE(GTK4)
}

Expand Down
16 changes: 16 additions & 0 deletions Source/WebCore/platform/gtk/DragImageGtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "Element.h"
#include "Image.h"
#include "NotImplemented.h"
#include "TextFlags.h"
#include "TextIndicator.h"
#include <cairo.h>
Expand All @@ -31,8 +32,13 @@ namespace WebCore {

IntSize dragImageSize(DragImageRef image)
{
#if USE(CAIRO)
if (image)
return { cairo_image_surface_get_width(image.get()), cairo_image_surface_get_height(image.get()) };
#elif USE(SKIA)
notImplemented();
UNUSED_PARAM(image);
#endif

return { 0, 0 };
}
Expand All @@ -54,6 +60,7 @@ DragImageRef scaleDragImage(DragImageRef image, FloatSize scale)
if (imageSize == scaledSize)
return image;

#if USE(CAIRO)
RefPtr<cairo_surface_t> scaledSurface = adoptRef(cairo_surface_create_similar(image.get(), CAIRO_CONTENT_COLOR_ALPHA, scaledSize.width(), scaledSize.height()));

RefPtr<cairo_t> context = adoptRef(cairo_create(scaledSurface.get()));
Expand All @@ -65,6 +72,10 @@ DragImageRef scaleDragImage(DragImageRef image, FloatSize scale)
cairo_paint(context.get());

return scaledSurface;
#elif USE(SKIA)
notImplemented();
return nullptr;
#endif
}

DragImageRef dissolveDragImageToFraction(DragImageRef image, float fraction)
Expand All @@ -77,10 +88,15 @@ DragImageRef dissolveDragImageToFraction(DragImageRef image, float fraction)
return image;
#endif

#if USE(CAIRO)
RefPtr<cairo_t> context = adoptRef(cairo_create(image.get()));
cairo_set_operator(context.get(), CAIRO_OPERATOR_DEST_IN);
cairo_set_source_rgba(context.get(), 0, 0, 0, fraction);
cairo_paint(context.get());
#elif USE(SKIA)
notImplemented();
UNUSED_PARAM(fraction);
#endif
return image;
}

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/platform/gtk/RenderThemeGadget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "config.h"
#include "RenderThemeGadget.h"

#if !USE(GTK4)
#if !USE(GTK4) && USE(CAIRO)

#include "FloatRect.h"
#include "GRefPtrGtk.h"
Expand Down Expand Up @@ -259,4 +259,4 @@ void RenderThemeScrollbarGadget::renderStepper(cairo_t* cr, const FloatRect& pai

} // namespace WebCore

#endif // !USE(GTK4)
#endif // !USE(GTK4) && USE(CAIRO)
4 changes: 2 additions & 2 deletions Source/WebCore/platform/gtk/RenderThemeGadget.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#pragma once

#if !USE(GTK4)
#if !USE(GTK4) && USE(CAIRO)

#include "Color.h"
#include "IntSize.h"
Expand Down Expand Up @@ -112,4 +112,4 @@ class RenderThemeScrollbarGadget final : public RenderThemeGadget {

} // namespace WebCore

#endif // !USE(GTK4)
#endif // !USE(GTK4) && USE(CAIRO)
4 changes: 2 additions & 2 deletions Source/WebCore/platform/gtk/RenderThemeScrollbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "config.h"
#include "RenderThemeScrollbar.h"

#if !USE(GTK4)
#if !USE(GTK4) && USE(CAIRO)

#include "GtkUtilities.h"
#include <wtf/HashMap.h>
Expand Down Expand Up @@ -135,4 +135,4 @@ RenderThemeGadget* RenderThemeScrollbar::stepper(RenderThemeScrollbarGadget::Ste

} // namespace WebCore

#endif // !USE(GTK4)
#endif // !USE(GTK4) && USE(CAIRO)
4 changes: 2 additions & 2 deletions Source/WebCore/platform/gtk/RenderThemeScrollbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#pragma once

#if !USE(GTK4)
#if !USE(GTK4) && USE(CAIRO)

#include "RenderThemeGadget.h"
#include <gtk/gtk.h>
Expand Down Expand Up @@ -68,4 +68,4 @@ class RenderThemeScrollbar {

} // namespace WebCore

#endif // !USE(GTK4)
#endif // !USE(GTK4) && USE(CAIRO)
4 changes: 2 additions & 2 deletions Source/WebCore/platform/gtk/ScrollbarThemeGtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "config.h"
#include "ScrollbarThemeGtk.h"

#if !USE(GTK4)
#if !USE(GTK4) && USE(CAIRO)

#include "GRefPtrGtk.h"
#include "GraphicsContextCairo.h"
Expand Down Expand Up @@ -552,4 +552,4 @@ int ScrollbarThemeGtk::minimumThumbLength(Scrollbar& scrollbar)

} // namespace WebCore

#endif // !USE(GTK4)
#endif // !USE(GTK4) && USE(CAIRO)
4 changes: 2 additions & 2 deletions Source/WebCore/platform/gtk/ScrollbarThemeGtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#pragma once

#if !USE(GTK4)
#if !USE(GTK4) && USE(CAIRO)

#include "ScrollbarThemeAdwaita.h"

Expand Down Expand Up @@ -61,4 +61,4 @@ class ScrollbarThemeGtk final : public ScrollbarThemeAdwaita {

} // namespace WebCore

#endif // !USE(GTK4)
#endif // !USE(GTK4) && USE(CAIRO)
2 changes: 2 additions & 0 deletions Source/WebKit/SourcesGTK.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ Shared/linux/WebMemorySamplerLinux.cpp
Shared/soup/WebCoreArgumentCodersSoup.cpp
Shared/soup/WebErrorsSoup.cpp

Shared/skia/WebCoreArgumentCodersSkia.cpp

Shared/unix/AuxiliaryProcessMain.cpp

UIProcess/DefaultUndoController.cpp
Expand Down
Loading

0 comments on commit 75df56f

Please sign in to comment.