Skip to content

Commit

Permalink
[WPE] WPE Platform: Opaque region support
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=267705

Reviewed by Alejandro G. Castro.

Add API to set the opaque region on a WPEView and use it from WebKit to
set the web view region as opaque when the background color is opaque.

* Source/WebKit/UIProcess/API/wpe/WebKitWebViewWPE.cpp:
(webkit_web_view_set_background_color):
* Source/WebKit/WPEPlatform/CMakeLists.txt:
* Source/WebKit/WPEPlatform/wpe/WPERectangle.cpp: Copied from Source/WebKit/WPEPlatform/wpe/wpe-platform.h.
(wpe_rectangle_copy):
(wpe_rectangle_free):
* Source/WebKit/WPEPlatform/wpe/WPERectangle.h: Copied from Source/WebKit/WPEPlatform/wpe/wpe-platform.h.
* Source/WebKit/WPEPlatform/wpe/WPEView.cpp:
(wpe_view_set_opaque_rectangles):
* Source/WebKit/WPEPlatform/wpe/WPEView.h:
* Source/WebKit/WPEPlatform/wpe/wayland/WPEViewWayland.cpp:
(wpeViewWaylandConstructed):
(wpeViewWaylandSetOpaqueRectangles):
(wpe_view_wayland_class_init):
* Source/WebKit/WPEPlatform/wpe/wpe-platform.h:

Canonical link: https://commits.webkit.org/275684@main
  • Loading branch information
carlosgcampos committed Mar 5, 2024
1 parent 6dc9c6a commit 6b96e27
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 67 deletions.
16 changes: 15 additions & 1 deletion Source/WebKit/UIProcess/API/wpe/WebKitWebViewWPE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@
#include "config.h"
#include "WebKitWebView.h"

#include "PageClientImpl.h"
#include "WebKitColorPrivate.h"
#include "WebKitScriptDialogPrivate.h"
#include "WebKitWebViewPrivate.h"

#if ENABLE(WPE_PLATFORM)
#include <wpe/wpe-platform.h>
#endif

gboolean webkitWebViewAuthenticate(WebKitWebView*, WebKitAuthenticationRequest*)
{
Expand Down Expand Up @@ -225,7 +229,17 @@ void webkit_web_view_set_background_color(WebKitWebView* webView, WebKitColor* b
g_return_if_fail(backgroundColor);

auto& page = webkitWebViewGetPage(webView);
page.setBackgroundColor(webkitColorToWebCoreColor(backgroundColor));
auto color = webkitColorToWebCoreColor(backgroundColor);
page.setBackgroundColor(color);
#if ENABLE(WPE_PLATFORM)
if (auto* view = static_cast<WebKit::PageClientImpl&>(page.pageClient()).wpeView()) {
if (color.isOpaque()) {
WPERectangle rect { 0, 0, wpe_view_get_width(view), wpe_view_get_height(view) };
wpe_view_set_opaque_rectangles(view, &rect, 1);
} else
wpe_view_set_opaque_rectangles(view, nullptr, 0);
}
#endif
}

/**
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/WPEPlatform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set(WPEPlatform_SOURCES
${WEBKIT_DIR}/WPEPlatform/wpe/WPEKeymap.cpp
${WEBKIT_DIR}/WPEPlatform/wpe/WPEKeymapXKB.cpp
${WEBKIT_DIR}/WPEPlatform/wpe/WPEMonitor.cpp
${WEBKIT_DIR}/WPEPlatform/wpe/WPERectangle.cpp
${WEBKIT_DIR}/WPEPlatform/wpe/WPEVersion.cpp
${WEBKIT_DIR}/WPEPlatform/wpe/WPEView.cpp
${WPEPlatform_DERIVED_SOURCES_DIR}/wpe/WPEEnumTypes.cpp
Expand All @@ -40,6 +41,7 @@ set(WPEPlatform_INSTALLED_HEADERS
${WEBKIT_DIR}/WPEPlatform/wpe/WPEKeymapXKB.h
${WEBKIT_DIR}/WPEPlatform/wpe/WPEKeysyms.h
${WEBKIT_DIR}/WPEPlatform/wpe/WPEMonitor.h
${WEBKIT_DIR}/WPEPlatform/wpe/WPERectangle.h
${WEBKIT_DIR}/WPEPlatform/wpe/WPEView.h
${WEBKIT_DIR}/WPEPlatform/wpe/wpe-platform.h
${WPEPlatform_DERIVED_SOURCES_DIR}/wpe/WPEConfig.h
Expand Down
55 changes: 55 additions & 0 deletions Source/WebKit/WPEPlatform/wpe/WPERectangle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2024 Igalia S.L.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "WPERectangle.h"

#include <wtf/FastMalloc.h>

/**
* WPERectangle:
* @x: The X coordinate of the top-left corner of the rectangle.
* @y: The Y coordinate of the top-left corner of the rectangle.
* @width: The width of the rectangle.
* @height: The height of the rectangle.
*
* Boxed type representing a rectangle with integer coordinates.
*/

static WPERectangle* wpe_rectangle_copy(WPERectangle* rectangle)
{
g_return_val_if_fail(rectangle, nullptr);

return static_cast<WPERectangle*>(fastMemDup(rectangle, sizeof(WPERectangle)));
}

static void wpe_rectangle_free(WPERectangle* rectangle)
{
g_return_if_fail(rectangle);

fastFree(rectangle);
}

G_DEFINE_BOXED_TYPE(WPERectangle, wpe_rectangle, wpe_rectangle_copy, wpe_rectangle_free)
52 changes: 52 additions & 0 deletions Source/WebKit/WPEPlatform/wpe/WPERectangle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2024 Igalia S.L.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef WPERectangle_h
#define WPERectangle_h

#if !defined(__WPE_PLATFORM_H_INSIDE__) && !defined(BUILDING_WEBKIT)
#error "Only <wpe/wpe-platform.h> can be included directly."
#endif

#include <glib-object.h>
#include <wpe/WPEDefines.h>

G_BEGIN_DECLS

struct _WPERectangle {
int x;
int y;
int width;
int height;
};
typedef struct _WPERectangle WPERectangle;

#define WPE_TYPE_RECTANGLE (wpe_rectangle_get_type())

WPE_API GType wpe_rectangle_get_type (void);

G_END_DECLS

#endif /* WPERectangle_h */
20 changes: 20 additions & 0 deletions Source/WebKit/WPEPlatform/wpe/WPEView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,3 +835,23 @@ GList* wpe_view_get_preferred_dma_buf_formats(WPEView* view)

return wpe_display_get_preferred_dma_buf_formats(view->priv->display.get());
}

/**
* wpe_view_set_opaque_rectangles:
* @view: a #WPEView
* @rects: (nullable) (array length=n_rects): opaque rectangles in view-local coordinates
* @n_rects: the total number of elements in @rects
*
* Set the rectangles of @view that contain opaque content.
* This is an optimization hint that is automatically set by WebKit when the
* web view background color is opaque.
*/
void wpe_view_set_opaque_rectangles(WPEView* view, WPERectangle* rects, guint rectsCount)
{
g_return_if_fail(WPE_IS_VIEW(view));
g_return_if_fail(!rects || rectsCount > 0);

auto* viewClass = WPE_VIEW_GET_CLASS(view);
if (viewClass->set_opaque_rectangles)
viewClass->set_opaque_rectangles(view, rects, rectsCount);
}
135 changes: 71 additions & 64 deletions Source/WebKit/WPEPlatform/wpe/WPEView.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,33 @@ typedef struct _WPEBuffer WPEBuffer;
typedef struct _WPEDisplay WPEDisplay;
typedef struct _WPEEvent WPEEvent;
typedef struct _WPEMonitor WPEMonitor;
typedef struct _WPERectangle WPERectangle;

struct _WPEViewClass
{
GObjectClass parent_class;

gboolean (* render_buffer) (WPEView *view,
WPEBuffer *buffer,
GError **error);
WPEMonitor *(* get_monitor) (WPEView *view);
gboolean (* set_fullscreen) (WPEView *view,
gboolean fullscreen);
gboolean (* set_maximized) (WPEView *view,
gboolean maximized);
GList *(* get_preferred_dma_buf_formats) (WPEView *view);
void (* set_cursor_from_name) (WPEView *view,
const char *name);
void (* set_cursor_from_bytes) (WPEView *view,
GBytes *bytes,
guint width,
guint height,
guint stride,
guint hotspot_x,
guint hotspot_y);
gboolean (* render_buffer) (WPEView *view,
WPEBuffer *buffer,
GError **error);
WPEMonitor *(* get_monitor) (WPEView *view);
gboolean (* set_fullscreen) (WPEView *view,
gboolean fullscreen);
gboolean (* set_maximized) (WPEView *view,
gboolean maximized);
GList *(* get_preferred_dma_buf_formats) (WPEView *view);
void (* set_cursor_from_name) (WPEView *view,
const char *name);
void (* set_cursor_from_bytes) (WPEView *view,
GBytes *bytes,
guint width,
guint height,
guint stride,
guint hotspot_x,
guint hotspot_y);
void (* set_opaque_rectangles) (WPEView *view,
WPERectangle *rects,
guint n_rects);

gpointer padding[32];
};
Expand Down Expand Up @@ -97,52 +101,55 @@ typedef enum {

WPE_API GQuark wpe_view_error_quark (void);

WPE_API WPEView *wpe_view_new (WPEDisplay *display);
WPE_API WPEDisplay *wpe_view_get_display (WPEView *view);
WPE_API int wpe_view_get_width (WPEView *view);
WPE_API int wpe_view_get_height (WPEView *view);
WPE_API void wpe_view_set_width (WPEView *view,
int width);
WPE_API void wpe_view_set_height (WPEView *view,
int height);
WPE_API void wpe_view_resize (WPEView *view,
int width,
int height);
WPE_API gdouble wpe_view_get_scale (WPEView *view);
WPE_API void wpe_view_set_scale (WPEView *view,
gdouble scale);
WPE_API void wpe_view_set_cursor_from_name (WPEView *view,
const char *name);
WPE_API void wpe_view_set_cursor_from_bytes (WPEView *view,
GBytes *bytes,
guint width,
guint height,
guint stride,
guint hotspot_x,
guint hotspot_y);
WPE_API WPEViewState wpe_view_get_state (WPEView *view);
WPE_API void wpe_view_set_state (WPEView *view,
WPEViewState state);
WPE_API WPEMonitor *wpe_view_get_monitor (WPEView *view);
WPE_API gboolean wpe_view_fullscreen (WPEView *view);
WPE_API gboolean wpe_view_unfullscreen (WPEView *view);
WPE_API gboolean wpe_view_maximize (WPEView *view);
WPE_API gboolean wpe_view_unmaximize (WPEView *view);
WPE_API gboolean wpe_view_render_buffer (WPEView *view,
WPEBuffer *buffer,
GError **error);
WPE_API void wpe_view_buffer_rendered (WPEView *view,
WPEBuffer *buffer);
WPE_API void wpe_view_event (WPEView *view,
WPEEvent *event);
WPE_API guint wpe_view_compute_press_count (WPEView *view,
gdouble x,
gdouble y,
guint button,
guint32 time);
WPE_API void wpe_view_focus_in (WPEView *view);
WPE_API void wpe_view_focus_out (WPEView *view);
WPE_API GList *wpe_view_get_preferred_dma_buf_formats (WPEView *view);
WPE_API WPEView *wpe_view_new (WPEDisplay *display);
WPE_API WPEDisplay *wpe_view_get_display (WPEView *view);
WPE_API int wpe_view_get_width (WPEView *view);
WPE_API int wpe_view_get_height (WPEView *view);
WPE_API void wpe_view_set_width (WPEView *view,
int width);
WPE_API void wpe_view_set_height (WPEView *view,
int height);
WPE_API void wpe_view_resize (WPEView *view,
int width,
int height);
WPE_API gdouble wpe_view_get_scale (WPEView *view);
WPE_API void wpe_view_set_scale (WPEView *view,
gdouble scale);
WPE_API void wpe_view_set_cursor_from_name (WPEView *view,
const char *name);
WPE_API void wpe_view_set_cursor_from_bytes (WPEView *view,
GBytes *bytes,
guint width,
guint height,
guint stride,
guint hotspot_x,
guint hotspot_y);
WPE_API WPEViewState wpe_view_get_state (WPEView *view);
WPE_API void wpe_view_set_state (WPEView *view,
WPEViewState state);
WPE_API WPEMonitor *wpe_view_get_monitor (WPEView *view);
WPE_API gboolean wpe_view_fullscreen (WPEView *view);
WPE_API gboolean wpe_view_unfullscreen (WPEView *view);
WPE_API gboolean wpe_view_maximize (WPEView *view);
WPE_API gboolean wpe_view_unmaximize (WPEView *view);
WPE_API gboolean wpe_view_render_buffer (WPEView *view,
WPEBuffer *buffer,
GError **error);
WPE_API void wpe_view_buffer_rendered (WPEView *view,
WPEBuffer *buffer);
WPE_API void wpe_view_event (WPEView *view,
WPEEvent *event);
WPE_API guint wpe_view_compute_press_count (WPEView *view,
gdouble x,
gdouble y,
guint button,
guint32 time);
WPE_API void wpe_view_focus_in (WPEView *view);
WPE_API void wpe_view_focus_out (WPEView *view);
WPE_API GList *wpe_view_get_preferred_dma_buf_formats (WPEView *view);
WPE_API void wpe_view_set_opaque_rectangles (WPEView *view,
WPERectangle *rects,
guint n_rects);

G_END_DECLS

Expand Down
Loading

0 comments on commit 6b96e27

Please sign in to comment.