Changes between Version 3 and Version 4 of WebKit/Overview


Ignore:
Timestamp:
Oct 28, 2024, 3:11:01 PM (3 weeks ago)
Author:
nephele
Comment:

Add stuff from zardshards blog

Legend:

Unmodified
Added
Removed
Modified
  • WebKit/Overview

    v3 v4  
    99    Tools/Scripts/build-webkit
    1010
    11 = Source Layout =
     11= Source Overview =
    1212
    1313The sources for WebKit are in the Sources/ directory. There is also a Tools/ directory where you will find HaikuLauncher, the minimal browser used for testing, as well as other tools for the unit tests.
     
    2525So, the main directories for the Haiku-specific sources are: Source/WebCore/platform/graphics/haiku ; Source/WebCore/platform/network/haiku ; Source/WebKitLegacy/haiku . There are a few additional files and in some cases specific code in files shared between platforms.
    2626
     27= Source Tree =
     28---------
     29
     30* Tools/
     31    * HaikuLauncher/ - Test browser for WebKitLegacy
     32    * MiniBrowser/haiku/ - Test browser for WebKit2
     33    * Scripts/check-webkit-style - Checks coding style
     34* Source/
     35    * cmake/ - The core files of the build system
     36        * OptionsHaiku.cmake
     37    * JavaScriptCore/ - Runs JavaScript
     38    * WTF/ - A kind of standard library. Contains string utilities, random number generators, etc.
     39        * wtf/haiku/
     40            * RunLoopHaiku.cpp - Contains our implementation of the run loop
     41    * WebCore/ - The back-end for almost everything web-related
     42        * PlatformHaiku.cmake - The index to everything Haiku-specific in this directory
     43        * platform/haiku/
     44            * DragDataHaiku.cpp
     45            * MainThreadSharedTimerHaiku.cpp
     46            * PlatformKeyboardEventHaiku.cpp
     47            * PlatformMouseEventHaiku.cpp
     48            * SoundHaiku.cpp
     49        * platform/graphics/haiku/
     50            * BitmapImageHaiku.cpp
     51            * FloatPointHaiku.cpp
     52            * FontHaiku.cpp
     53            * ShareableBitmapHaiku.cpp
     54            * GraphicsLayerHaiku.cpp
     55    * WebKit/ - The new API that splits the engine across multiple processes.
     56        * PlatformHaiku.cmake - The index to everything Haiku-specific in this directory
     57        * UIProcess/ - Everything related to the ui process.
     58            * API/haiku/ - Home of WebKit2's API
     59                * WebView.cpp
     60                * misc. support classes
     61            * haiku/
     62                * BackingStoreHaiku.cpp - Holds the rendered web page
     63        * WebProcess/ - Everything related to the web process. The web page runs inside of this process.
     64            * haiku/
     65                * WebProcessMainHaiku.cpp - This contains is the entry-point for WebProcess.
     66                * WebProcessHaiku.cpp
     67        * NetworkProcess/ - Everything related to the network process. This does the networking.
     68        * Shared/ - Code shared across the three processes
     69            * CoordinatedGraphics/ - Allows WebProcess to draw and UIProcess to display
     70            * haiku/
     71                * NativeWebMouseEventHaiku.cpp
     72                * ProcessExecutablePathHaiku.cpp
     73        * Platform/ - Also code shared across the three processes?
     74            * IPC/ - Allows the three processes to communicate with each other
     75                * haiku/
     76                * unix/ - Yes, we use UNIX sockets for IPC.
     77    * WebKitLegacy/ - The old API. It runs everything in a single process.
     78
     79[What is WebKit?](https://github.com/WebKit/WebKit/blob/main/Introduction.md#what-is-webkit) also has a nice explanation for some of the folders.
     80
     81
     82=Other ports =
     83
     84As you browse the directory tree, you'll see several folders over and over again in different directories. These contain technology-specific code. They can contain inspiration for how to implement unimplemented functions on Haiku.
     85
     86Some of the folders you'll find repeated across WebKit relate to the ports of WebKit. They are
     87
     88* haiku - that's us!
     89* gtk - https://www.webkitgtk.org/
     90* wpe - https://wpewebkit.org/
     91* playstation
     92* win - Windows
     93* ios
     94* mac
     95
     96Here are some of the other folders. They don't relate directly with any of the ports, but are used in some of them:
     97
     98* glib - Contains implementations of functions using the [GLib](https://docs.gtk.org/glib/index.html) library.
     99* unix - Contains implementations of functions using things available on UNIX.
     100* cocoa - Contains implementations of functions using the [cocoa](https://en.wikipedia.org/wiki/Cocoa_\(API\)) API.
     101* soup - Uses [libsoup](https://libsoup.org/libsoup-3.0/)
     102* curl - Uses curl
     103* skia - Uses [skia](https://skia.org/)
     104* cairo - Uses [cairo](https://www.cairographics.org/)
     105* and several others
     106
     107**See also:**
     108* https://docs.webkit.org/Ports/Introduction.html
     109
     110
     111= Other Notes=
     112
     113PLATFORM vs HAVE vs USE vs OS
     114-----------------------------
     115
     116Quite often in the code, you'll see `#if PLATFORM(HAIKU)` or `#if OS(HAIKU)`. They're all quite similar, but there is a way to use them properly. Source/WTF/wtf/Platform.h's comments explain when to use these quite nicely.
     117
     118
     119
     120Rendering
     121---------
     122
     123### Coordinated graphics
     124
     125As far as I've been able to figure out, coordinated graphics refers to WebProcess and UIProcess coordinating graphics with each other. The UI process has to tell the web process about resizing, scrolling, etc. and the web process has to do the actual painting and then tell the UI process to update what has been displayed.
     126
     127A nice overview of coordinated graphics (and how rendering is done in general) is given at https://www.chromium.org/developers/design-documents/gpu-accelerated-compositing-in-chrome/. Yes, it's for chromium, but it matches what happens in WebKit *very* closely. Also see https://trac.webkit.org/wiki/CoordinatedGraphicsSystem
     128
    27129= Philosophy of WebKit Porting =
    28130
    29131There is usually little subclassing. Usually, a single .h file defines the API and each platform has the matching .cpp file implementing it. This means the .h may need to have some per platform #if when there are fields or methods specific to one or another platform. The idea is that this saves vtable overhead when there is going to be only one implementation compiled in.
     132
     133
     134= Logging =
     135
     136Logs are not printed to the console, but to a special program called DevConsole.
     137
     138> To facilitate debugging with multiple processes, logging is done using the DevConsole tool. This allows clearly tagging each log with the originating process (especially useful for WebKit2 where there are multiple processes).
     139>
     140> Logging can be controlled using the WEBKIT_DEBUG environment variable. The default is to have all logs disabled. You can enable everythin by setting the variable to "all", or enable specific debug sources. Most logs require some compile time options as well.
     141>
     142> ([source](https://github.com/haiku/haikuwebkit/?tab=readme-ov-file#logging))
     143
     144
     145Further reading
     146---------------
     147
     148* [Introduction.md in WebKit's source](https://github.com/WebKit/WebKit/blob/main/Introduction.md)
     149* https://www.haiku-os.org/blog/pulkomandy/2024-02-28_so_you_want_to_help_with_webkit#working-on-webkit2
     150* https://trac.webkit.org/wiki