From a69b37e02ad806ab9a6855c76cc3d726312d7a6c Mon Sep 17 00:00:00 2001 From: Izuna Seikatsu Date: Sun, 25 Jan 2026 01:17:17 +0100 Subject: [PATCH 1/5] feat: dmabuf planes --- .../cef/handler/CefAcceleratedPaintInfo.java | 47 +++++++++++++++-- native/render_handler.cpp | 51 +++++++++++++++++++ 2 files changed, 95 insertions(+), 3 deletions(-) diff --git a/java/org/cef/handler/CefAcceleratedPaintInfo.java b/java/org/cef/handler/CefAcceleratedPaintInfo.java index bd8aeedc..16318c30 100644 --- a/java/org/cef/handler/CefAcceleratedPaintInfo.java +++ b/java/org/cef/handler/CefAcceleratedPaintInfo.java @@ -11,8 +11,8 @@ public class CefAcceleratedPaintInfo { /** * Shared texture handle. The meaning depends on the platform: * - Windows: HANDLE to a texture that can be opened with D3D11 OpenSharedResource - * - macOS: IOSurface pointer that can be opened with Metal or OpenGL - * - Linux: Contains several planes, each with an fd to the underlying system native buffer + * - macOS: Not used; todo: IOSurface pointer that can be opened with Metal or OpenGL + * - Linux: Not used; dmabuf planes are exposed via the plane_* fields */ public long shared_texture_handle = 0; @@ -26,6 +26,36 @@ public class CefAcceleratedPaintInfo { */ public int width = 0; public int height = 0; + + /** + * Linux-only dmabuf plane count. + */ + public int plane_count = 0; + + /** + * Linux-only dmabuf plane file descriptors. + */ + public int[] plane_fds = null; + + /** + * Linux-only dmabuf plane strides (bytes per row). + */ + public int[] plane_strides = null; + + /** + * Linux-only dmabuf plane offsets. + */ + public long[] plane_offsets = null; + + /** + * Linux-only dmabuf plane sizes. + */ + public long[] plane_sizes = null; + + /** + * Linux-only dmabuf modifier. + */ + public long modifier = 0; public CefAcceleratedPaintInfo() {} @@ -35,9 +65,20 @@ public CefAcceleratedPaintInfo(long shared_texture_handle, int format, int width this.width = width; this.height = height; } + + public boolean hasDmaBufPlanes() { + return plane_count > 0 && plane_fds != null && plane_strides != null && plane_offsets != null; + } @Override public CefAcceleratedPaintInfo clone() { - return new CefAcceleratedPaintInfo(shared_texture_handle, format, width, height); + CefAcceleratedPaintInfo clone = new CefAcceleratedPaintInfo(shared_texture_handle, format, width, height); + clone.plane_count = plane_count; + clone.modifier = modifier; + clone.plane_fds = plane_fds != null ? plane_fds.clone() : null; + clone.plane_strides = plane_strides != null ? plane_strides.clone() : null; + clone.plane_offsets = plane_offsets != null ? plane_offsets.clone() : null; + clone.plane_sizes = plane_sizes != null ? plane_sizes.clone() : null; + return clone; } } diff --git a/native/render_handler.cpp b/native/render_handler.cpp index cedb72ef..046a8332 100644 --- a/native/render_handler.cpp +++ b/native/render_handler.cpp @@ -4,6 +4,8 @@ #include "render_handler.h" +#include + #include "client_handler.h" #include "jni_util.h" @@ -305,6 +307,55 @@ void RenderHandler::OnAcceleratedPaint(CefRefPtr browser, SetJNIFieldInt(env, cls, jpaintInfo, "width", viewRect.width); SetJNIFieldInt(env, cls, jpaintInfo, "height", viewRect.height); +#if defined(OS_LINUX) + SetJNIFieldInt(env, cls, jpaintInfo, "plane_count", info.plane_count); + SetJNIFieldLong(env, cls, jpaintInfo, "modifier", + static_cast(info.modifier)); + + const int plane_count = info.plane_count; + if (plane_count > 0) { + std::vector fds(plane_count); + std::vector strides(plane_count); + std::vector offsets(plane_count); + std::vector sizes(plane_count); + + for (int i = 0; i < plane_count; ++i) { + fds[i] = info.planes[i].fd; + strides[i] = static_cast(info.planes[i].stride); + offsets[i] = static_cast(info.planes[i].offset); + sizes[i] = static_cast(info.planes[i].size); + } + + jclass paintInfoClass = cls.get(); + jfieldID fdsField = env->GetFieldID(paintInfoClass, "plane_fds", "[I"); + jfieldID stridesField = env->GetFieldID(paintInfoClass, "plane_strides", "[I"); + jfieldID offsetsField = env->GetFieldID(paintInfoClass, "plane_offsets", "[J"); + jfieldID sizesField = env->GetFieldID(paintInfoClass, "plane_sizes", "[J"); + + if (fdsField && stridesField && offsetsField && sizesField) { + jintArray fdsArray = env->NewIntArray(plane_count); + jintArray stridesArray = env->NewIntArray(plane_count); + jlongArray offsetsArray = env->NewLongArray(plane_count); + jlongArray sizesArray = env->NewLongArray(plane_count); + + if (fdsArray && stridesArray && offsetsArray && sizesArray) { + env->SetIntArrayRegion(fdsArray, 0, plane_count, fds.data()); + env->SetIntArrayRegion(stridesArray, 0, plane_count, strides.data()); + env->SetLongArrayRegion(offsetsArray, 0, plane_count, offsets.data()); + env->SetLongArrayRegion(sizesArray, 0, plane_count, sizes.data()); + + env->SetObjectField(jpaintInfo.get(), fdsField, fdsArray); + env->SetObjectField(jpaintInfo.get(), stridesField, stridesArray); + env->SetObjectField(jpaintInfo.get(), offsetsField, offsetsArray); + env->SetObjectField(jpaintInfo.get(), sizesField, sizesArray); + } + } + } +#else + SetJNIFieldInt(env, cls, jpaintInfo, "plane_count", 0); + SetJNIFieldLong(env, cls, jpaintInfo, "modifier", 0); +#endif + JNI_CALL_VOID_METHOD(env, handle_, "onAcceleratedPaint", "(Lorg/cef/browser/CefBrowser;Z[Ljava/awt/" "Rectangle;Lorg/cef/handler/CefAcceleratedPaintInfo;)V", From c60db55c15fc74d61ee3c103d2bda3f0c2e03ab0 Mon Sep 17 00:00:00 2001 From: Izuna Seikatsu Date: Sun, 25 Jan 2026 01:24:38 +0100 Subject: [PATCH 2/5] fix(ci): mac-os runners --- .github/workflows/build-jcef.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-jcef.yml b/.github/workflows/build-jcef.yml index e0df7752..8c12b865 100644 --- a/.github/workflows/build-jcef.yml +++ b/.github/workflows/build-jcef.yml @@ -65,10 +65,14 @@ jobs: if-no-files-found: error java-cef-macos: - runs-on: [macos-13] + runs-on: ${{ matrix.runner }} strategy: matrix: - platform: [amd64, arm64] + include: + - platform: amd64 + runner: macos-15-intel + - platform: arm64 + runner: macos-latest steps: - uses: actions/checkout@v4 - name: Set up Python 3.9 From 6a9e24455115e47650b15f0ed7cfa1f3b96412a0 Mon Sep 17 00:00:00 2001 From: Izuna Seikatsu Date: Sun, 25 Jan 2026 01:25:54 +0100 Subject: [PATCH 3/5] fix(ci): no artifacts on non-main runs --- .github/workflows/build-jcef.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/build-jcef.yml b/.github/workflows/build-jcef.yml index 8c12b865..6c4c9ef2 100644 --- a/.github/workflows/build-jcef.yml +++ b/.github/workflows/build-jcef.yml @@ -26,7 +26,6 @@ jobs: tar -czf linux_${{ matrix.platform }}.tar.gz linux_${{ matrix.platform }} .hash sha256sum linux_${{ matrix.platform }}.tar.gz > linux_${{ matrix.platform }}.tar.gz.sha256 - uses: actions/upload-artifact@v4 - if: ${{ github.ref == 'refs/heads/main' }} with: name: 'linux_${{ matrix.platform }}' path: | @@ -56,7 +55,6 @@ jobs: tar -czf windows_${{ matrix.platform }}.tar.gz windows_${{ matrix.platform }} .hash Get-FileHash -Algorithm SHA256 -Path "windows_${{ matrix.platform }}.tar.gz" | Out-File "windows_${{ matrix.platform }}.tar.gz.sha256" - uses: actions/upload-artifact@v4 - if: ${{ github.ref == 'refs/heads/main' }} with: name: 'windows_${{ matrix.platform }}' path: | @@ -92,7 +90,6 @@ jobs: tar -czf macos_${{ matrix.platform }}.tar.gz macos_${{ matrix.platform }} .hash sha256sum macos_${{ matrix.platform }}.tar.gz > macos_${{ matrix.platform }}.tar.gz.sha256 - uses: actions/upload-artifact@v4 - if: ${{ github.ref == 'refs/heads/main' }} with: name: 'macos_${{ matrix.platform }}' path: | From 041ce0f146e62af024617f5a4d2b2b0c70906789 Mon Sep 17 00:00:00 2001 From: Izuna Seikatsu Date: Sun, 25 Jan 2026 15:27:12 +0100 Subject: [PATCH 4/5] feat: implement platform-specific accelerated paint info for Windows, macOS, and Linux --- .../cef/handler/CefAcceleratedPaintInfo.java | 63 +++---------------- .../handler/CefAcceleratedPaintInfoLinux.java | 62 ++++++++++++++++++ .../handler/CefAcceleratedPaintInfoMac.java | 27 ++++++++ .../handler/CefAcceleratedPaintInfoWin.java | 27 ++++++++ java/org/cef/handler/CefRenderHandler.java | 20 +++--- native/render_handler.cpp | 19 +++--- 6 files changed, 147 insertions(+), 71 deletions(-) create mode 100644 java/org/cef/handler/CefAcceleratedPaintInfoLinux.java create mode 100644 java/org/cef/handler/CefAcceleratedPaintInfoMac.java create mode 100644 java/org/cef/handler/CefAcceleratedPaintInfoWin.java diff --git a/java/org/cef/handler/CefAcceleratedPaintInfo.java b/java/org/cef/handler/CefAcceleratedPaintInfo.java index 16318c30..505a8921 100644 --- a/java/org/cef/handler/CefAcceleratedPaintInfo.java +++ b/java/org/cef/handler/CefAcceleratedPaintInfo.java @@ -5,80 +5,31 @@ package org.cef.handler; /** - * Structure representing shared texture info for accelerated painting. + * Base structure representing accelerated paint info. Platform-specific + * details are provided by subclasses. */ -public class CefAcceleratedPaintInfo { - /** - * Shared texture handle. The meaning depends on the platform: - * - Windows: HANDLE to a texture that can be opened with D3D11 OpenSharedResource - * - macOS: Not used; todo: IOSurface pointer that can be opened with Metal or OpenGL - * - Linux: Not used; dmabuf planes are exposed via the plane_* fields - */ - public long shared_texture_handle = 0; - +public class CefAcceleratedPaintInfo implements Cloneable { /** * Format of the shared texture. */ public int format = 0; - + /** * Size information for the shared texture. */ public int width = 0; public int height = 0; - /** - * Linux-only dmabuf plane count. - */ - public int plane_count = 0; - - /** - * Linux-only dmabuf plane file descriptors. - */ - public int[] plane_fds = null; - - /** - * Linux-only dmabuf plane strides (bytes per row). - */ - public int[] plane_strides = null; - - /** - * Linux-only dmabuf plane offsets. - */ - public long[] plane_offsets = null; - - /** - * Linux-only dmabuf plane sizes. - */ - public long[] plane_sizes = null; - - /** - * Linux-only dmabuf modifier. - */ - public long modifier = 0; - public CefAcceleratedPaintInfo() {} - - public CefAcceleratedPaintInfo(long shared_texture_handle, int format, int width, int height) { - this.shared_texture_handle = shared_texture_handle; + + protected CefAcceleratedPaintInfo(int format, int width, int height) { this.format = format; this.width = width; this.height = height; } - public boolean hasDmaBufPlanes() { - return plane_count > 0 && plane_fds != null && plane_strides != null && plane_offsets != null; - } - @Override public CefAcceleratedPaintInfo clone() { - CefAcceleratedPaintInfo clone = new CefAcceleratedPaintInfo(shared_texture_handle, format, width, height); - clone.plane_count = plane_count; - clone.modifier = modifier; - clone.plane_fds = plane_fds != null ? plane_fds.clone() : null; - clone.plane_strides = plane_strides != null ? plane_strides.clone() : null; - clone.plane_offsets = plane_offsets != null ? plane_offsets.clone() : null; - clone.plane_sizes = plane_sizes != null ? plane_sizes.clone() : null; - return clone; + return new CefAcceleratedPaintInfo(format, width, height); } } diff --git a/java/org/cef/handler/CefAcceleratedPaintInfoLinux.java b/java/org/cef/handler/CefAcceleratedPaintInfoLinux.java new file mode 100644 index 00000000..9c4d7d70 --- /dev/null +++ b/java/org/cef/handler/CefAcceleratedPaintInfoLinux.java @@ -0,0 +1,62 @@ +// Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. + +package org.cef.handler; + +/** + * Linux-specific accelerated paint info (dmabuf planes). + */ +public class CefAcceleratedPaintInfoLinux extends CefAcceleratedPaintInfo { + /** + * dmabuf plane count. + */ + public int plane_count = 0; + + /** + * dmabuf plane file descriptors. + */ + public int[] plane_fds = null; + + /** + * dmabuf plane strides (bytes per row). + */ + public int[] plane_strides = null; + + /** + * dmabuf plane offsets. + */ + public long[] plane_offsets = null; + + /** + * dmabuf plane sizes. + */ + public long[] plane_sizes = null; + + /** + * dmabuf modifier. + */ + public long modifier = 0; + + public CefAcceleratedPaintInfoLinux() {} + + public CefAcceleratedPaintInfoLinux(int format, int width, int height) { + super(format, width, height); + } + + public boolean hasDmaBufPlanes() { + return plane_count > 0 && plane_fds != null && plane_strides != null && plane_offsets != null; + } + + @Override + public CefAcceleratedPaintInfoLinux clone() { + CefAcceleratedPaintInfoLinux clone = new CefAcceleratedPaintInfoLinux(format, width, height); + clone.plane_count = plane_count; + clone.modifier = modifier; + clone.plane_fds = plane_fds != null ? plane_fds.clone() : null; + clone.plane_strides = plane_strides != null ? plane_strides.clone() : null; + clone.plane_offsets = plane_offsets != null ? plane_offsets.clone() : null; + clone.plane_sizes = plane_sizes != null ? plane_sizes.clone() : null; + return clone; + } +} diff --git a/java/org/cef/handler/CefAcceleratedPaintInfoMac.java b/java/org/cef/handler/CefAcceleratedPaintInfoMac.java new file mode 100644 index 00000000..738924a9 --- /dev/null +++ b/java/org/cef/handler/CefAcceleratedPaintInfoMac.java @@ -0,0 +1,27 @@ +// Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. + +package org.cef.handler; + +/** + * macOS-specific accelerated paint info. + */ +public class CefAcceleratedPaintInfoMac extends CefAcceleratedPaintInfo { + /** + * IOSurface handle that can be opened with Metal or OpenGL. + */ + public long shared_texture_io_surface = 0; + + public CefAcceleratedPaintInfoMac() {} + + public CefAcceleratedPaintInfoMac(long shared_texture_io_surface, int format, int width, int height) { + super(format, width, height); + this.shared_texture_io_surface = shared_texture_io_surface; + } + + @Override + public CefAcceleratedPaintInfoMac clone() { + return new CefAcceleratedPaintInfoMac(shared_texture_io_surface, format, width, height); + } +} diff --git a/java/org/cef/handler/CefAcceleratedPaintInfoWin.java b/java/org/cef/handler/CefAcceleratedPaintInfoWin.java new file mode 100644 index 00000000..f87bbc91 --- /dev/null +++ b/java/org/cef/handler/CefAcceleratedPaintInfoWin.java @@ -0,0 +1,27 @@ +// Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. + +package org.cef.handler; + +/** + * Windows-specific accelerated paint info. + */ +public class CefAcceleratedPaintInfoWin extends CefAcceleratedPaintInfo { + /** + * HANDLE to a texture that can be opened with D3D11 OpenSharedResource. + */ + public long shared_texture_handle = 0; + + public CefAcceleratedPaintInfoWin() {} + + public CefAcceleratedPaintInfoWin(long shared_texture_handle, int format, int width, int height) { + super(format, width, height); + this.shared_texture_handle = shared_texture_handle; + } + + @Override + public CefAcceleratedPaintInfoWin clone() { + return new CefAcceleratedPaintInfoWin(shared_texture_handle, format, width, height); + } +} diff --git a/java/org/cef/handler/CefRenderHandler.java b/java/org/cef/handler/CefRenderHandler.java index 47754504..050ab612 100644 --- a/java/org/cef/handler/CefRenderHandler.java +++ b/java/org/cef/handler/CefRenderHandler.java @@ -68,14 +68,18 @@ public interface CefRenderHandler { public void onPaint(CefBrowser browser, boolean popup, Rectangle[] dirtyRects, ByteBuffer buffer, int width, int height); - /** - * Called when an element has been rendered to the shared texture handle. - * This method is only called when CefWindowInfo::shared_texture_enabled is set to true. - * @param browser The browser generating the event. - * @param popup True if painting a popup window. - * @param dirtyRects Array of dirty regions. - * @param info Contains the shared handle and texture information. - */ + /** + * Called when an element has been rendered to the shared texture handle. + * This method is only called when CefWindowInfo::shared_texture_enabled is set to true. + * @param browser The browser generating the event. + * @param popup True if painting a popup window. + * @param dirtyRects Array of dirty regions. + * @param info Platform-specific info instance. Expect one of + * {@link CefAcceleratedPaintInfoWin}, + * {@link CefAcceleratedPaintInfoMac}, + * {@link CefAcceleratedPaintInfoLinux}, or a base + * {@link CefAcceleratedPaintInfo} on unsupported platforms. + */ public void onAcceleratedPaint(CefBrowser browser, boolean popup, Rectangle[] dirtyRects, CefAcceleratedPaintInfo info); diff --git a/native/render_handler.cpp b/native/render_handler.cpp index 046a8332..d1c6a363 100644 --- a/native/render_handler.cpp +++ b/native/render_handler.cpp @@ -284,8 +284,16 @@ void RenderHandler::OnAcceleratedPaint(CefRefPtr browser, jboolean jtype = type == PET_VIEW ? JNI_FALSE : JNI_TRUE; ScopedJNIObjectLocal jrectArray(env, NewJNIRectArray(env, dirtyRects)); - // Create CefAcceleratedPaintInfo Java object + // Create platform-specific CefAcceleratedPaintInfo Java object +#if defined(OS_WIN) + ScopedJNIClass cls(env, "org/cef/handler/CefAcceleratedPaintInfoWin"); +#elif defined(OS_MACOSX) + ScopedJNIClass cls(env, "org/cef/handler/CefAcceleratedPaintInfoMac"); +#elif defined(OS_LINUX) + ScopedJNIClass cls(env, "org/cef/handler/CefAcceleratedPaintInfoLinux"); +#else ScopedJNIClass cls(env, "org/cef/handler/CefAcceleratedPaintInfo"); +#endif if (!cls) return; ScopedJNIObjectLocal jpaintInfo(env, NewJNIObject(env, cls)); @@ -299,9 +307,9 @@ void RenderHandler::OnAcceleratedPaint(CefRefPtr browser, #if defined(OS_WIN) SetJNIFieldLong(env, cls, jpaintInfo, "shared_texture_handle", reinterpret_cast(info.shared_texture_handle)); -#else - // On non-Windows platforms, shared_texture_handle is not available - SetJNIFieldLong(env, cls, jpaintInfo, "shared_texture_handle", 0); +#elif defined(OS_MACOSX) + SetJNIFieldLong(env, cls, jpaintInfo, "shared_texture_io_surface", + reinterpret_cast(info.shared_texture_io_surface)); #endif SetJNIFieldInt(env, cls, jpaintInfo, "format", info.format); SetJNIFieldInt(env, cls, jpaintInfo, "width", viewRect.width); @@ -351,9 +359,6 @@ void RenderHandler::OnAcceleratedPaint(CefRefPtr browser, } } } -#else - SetJNIFieldInt(env, cls, jpaintInfo, "plane_count", 0); - SetJNIFieldLong(env, cls, jpaintInfo, "modifier", 0); #endif JNI_CALL_VOID_METHOD(env, handle_, "onAcceleratedPaint", From 1ea2b074a7a214fa13d7ebcf9fddfc690b700783 Mon Sep 17 00:00:00 2001 From: Izuna Seikatsu Date: Sun, 25 Jan 2026 15:32:50 +0100 Subject: [PATCH 5/5] fix: spacing --- java/org/cef/handler/CefRenderHandler.java | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/java/org/cef/handler/CefRenderHandler.java b/java/org/cef/handler/CefRenderHandler.java index 050ab612..bbe529c7 100644 --- a/java/org/cef/handler/CefRenderHandler.java +++ b/java/org/cef/handler/CefRenderHandler.java @@ -68,18 +68,18 @@ public interface CefRenderHandler { public void onPaint(CefBrowser browser, boolean popup, Rectangle[] dirtyRects, ByteBuffer buffer, int width, int height); - /** - * Called when an element has been rendered to the shared texture handle. - * This method is only called when CefWindowInfo::shared_texture_enabled is set to true. - * @param browser The browser generating the event. - * @param popup True if painting a popup window. - * @param dirtyRects Array of dirty regions. - * @param info Platform-specific info instance. Expect one of - * {@link CefAcceleratedPaintInfoWin}, - * {@link CefAcceleratedPaintInfoMac}, - * {@link CefAcceleratedPaintInfoLinux}, or a base - * {@link CefAcceleratedPaintInfo} on unsupported platforms. - */ + /** + * Called when an element has been rendered to the shared texture handle. + * This method is only called when CefWindowInfo::shared_texture_enabled is set to true. + * @param browser The browser generating the event. + * @param popup True if painting a popup window. + * @param dirtyRects Array of dirty regions. + * @param info Platform-specific info instance. Expect one of + * {@link CefAcceleratedPaintInfoWin}, + * {@link CefAcceleratedPaintInfoMac}, + * {@link CefAcceleratedPaintInfoLinux}, or a base + * {@link CefAcceleratedPaintInfo} on unsupported platforms. + */ public void onAcceleratedPaint(CefBrowser browser, boolean popup, Rectangle[] dirtyRects, CefAcceleratedPaintInfo info);