Skip to content

Commit 041ce0f

Browse files
committed
feat: implement platform-specific accelerated paint info for Windows, macOS, and Linux
1 parent 6a9e244 commit 041ce0f

File tree

6 files changed

+147
-71
lines changed

6 files changed

+147
-71
lines changed

java/org/cef/handler/CefAcceleratedPaintInfo.java

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,31 @@
55
package org.cef.handler;
66

77
/**
8-
* Structure representing shared texture info for accelerated painting.
8+
* Base structure representing accelerated paint info. Platform-specific
9+
* details are provided by subclasses.
910
*/
10-
public class CefAcceleratedPaintInfo {
11-
/**
12-
* Shared texture handle. The meaning depends on the platform:
13-
* - Windows: HANDLE to a texture that can be opened with D3D11 OpenSharedResource
14-
* - macOS: Not used; todo: IOSurface pointer that can be opened with Metal or OpenGL
15-
* - Linux: Not used; dmabuf planes are exposed via the plane_* fields
16-
*/
17-
public long shared_texture_handle = 0;
18-
11+
public class CefAcceleratedPaintInfo implements Cloneable {
1912
/**
2013
* Format of the shared texture.
2114
*/
2215
public int format = 0;
23-
16+
2417
/**
2518
* Size information for the shared texture.
2619
*/
2720
public int width = 0;
2821
public int height = 0;
2922

30-
/**
31-
* Linux-only dmabuf plane count.
32-
*/
33-
public int plane_count = 0;
34-
35-
/**
36-
* Linux-only dmabuf plane file descriptors.
37-
*/
38-
public int[] plane_fds = null;
39-
40-
/**
41-
* Linux-only dmabuf plane strides (bytes per row).
42-
*/
43-
public int[] plane_strides = null;
44-
45-
/**
46-
* Linux-only dmabuf plane offsets.
47-
*/
48-
public long[] plane_offsets = null;
49-
50-
/**
51-
* Linux-only dmabuf plane sizes.
52-
*/
53-
public long[] plane_sizes = null;
54-
55-
/**
56-
* Linux-only dmabuf modifier.
57-
*/
58-
public long modifier = 0;
59-
6023
public CefAcceleratedPaintInfo() {}
61-
62-
public CefAcceleratedPaintInfo(long shared_texture_handle, int format, int width, int height) {
63-
this.shared_texture_handle = shared_texture_handle;
24+
25+
protected CefAcceleratedPaintInfo(int format, int width, int height) {
6426
this.format = format;
6527
this.width = width;
6628
this.height = height;
6729
}
6830

69-
public boolean hasDmaBufPlanes() {
70-
return plane_count > 0 && plane_fds != null && plane_strides != null && plane_offsets != null;
71-
}
72-
7331
@Override
7432
public CefAcceleratedPaintInfo clone() {
75-
CefAcceleratedPaintInfo clone = new CefAcceleratedPaintInfo(shared_texture_handle, format, width, height);
76-
clone.plane_count = plane_count;
77-
clone.modifier = modifier;
78-
clone.plane_fds = plane_fds != null ? plane_fds.clone() : null;
79-
clone.plane_strides = plane_strides != null ? plane_strides.clone() : null;
80-
clone.plane_offsets = plane_offsets != null ? plane_offsets.clone() : null;
81-
clone.plane_sizes = plane_sizes != null ? plane_sizes.clone() : null;
82-
return clone;
33+
return new CefAcceleratedPaintInfo(format, width, height);
8334
}
8435
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights
2+
// reserved. Use of this source code is governed by a BSD-style license that
3+
// can be found in the LICENSE file.
4+
5+
package org.cef.handler;
6+
7+
/**
8+
* Linux-specific accelerated paint info (dmabuf planes).
9+
*/
10+
public class CefAcceleratedPaintInfoLinux extends CefAcceleratedPaintInfo {
11+
/**
12+
* dmabuf plane count.
13+
*/
14+
public int plane_count = 0;
15+
16+
/**
17+
* dmabuf plane file descriptors.
18+
*/
19+
public int[] plane_fds = null;
20+
21+
/**
22+
* dmabuf plane strides (bytes per row).
23+
*/
24+
public int[] plane_strides = null;
25+
26+
/**
27+
* dmabuf plane offsets.
28+
*/
29+
public long[] plane_offsets = null;
30+
31+
/**
32+
* dmabuf plane sizes.
33+
*/
34+
public long[] plane_sizes = null;
35+
36+
/**
37+
* dmabuf modifier.
38+
*/
39+
public long modifier = 0;
40+
41+
public CefAcceleratedPaintInfoLinux() {}
42+
43+
public CefAcceleratedPaintInfoLinux(int format, int width, int height) {
44+
super(format, width, height);
45+
}
46+
47+
public boolean hasDmaBufPlanes() {
48+
return plane_count > 0 && plane_fds != null && plane_strides != null && plane_offsets != null;
49+
}
50+
51+
@Override
52+
public CefAcceleratedPaintInfoLinux clone() {
53+
CefAcceleratedPaintInfoLinux clone = new CefAcceleratedPaintInfoLinux(format, width, height);
54+
clone.plane_count = plane_count;
55+
clone.modifier = modifier;
56+
clone.plane_fds = plane_fds != null ? plane_fds.clone() : null;
57+
clone.plane_strides = plane_strides != null ? plane_strides.clone() : null;
58+
clone.plane_offsets = plane_offsets != null ? plane_offsets.clone() : null;
59+
clone.plane_sizes = plane_sizes != null ? plane_sizes.clone() : null;
60+
return clone;
61+
}
62+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights
2+
// reserved. Use of this source code is governed by a BSD-style license that
3+
// can be found in the LICENSE file.
4+
5+
package org.cef.handler;
6+
7+
/**
8+
* macOS-specific accelerated paint info.
9+
*/
10+
public class CefAcceleratedPaintInfoMac extends CefAcceleratedPaintInfo {
11+
/**
12+
* IOSurface handle that can be opened with Metal or OpenGL.
13+
*/
14+
public long shared_texture_io_surface = 0;
15+
16+
public CefAcceleratedPaintInfoMac() {}
17+
18+
public CefAcceleratedPaintInfoMac(long shared_texture_io_surface, int format, int width, int height) {
19+
super(format, width, height);
20+
this.shared_texture_io_surface = shared_texture_io_surface;
21+
}
22+
23+
@Override
24+
public CefAcceleratedPaintInfoMac clone() {
25+
return new CefAcceleratedPaintInfoMac(shared_texture_io_surface, format, width, height);
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights
2+
// reserved. Use of this source code is governed by a BSD-style license that
3+
// can be found in the LICENSE file.
4+
5+
package org.cef.handler;
6+
7+
/**
8+
* Windows-specific accelerated paint info.
9+
*/
10+
public class CefAcceleratedPaintInfoWin extends CefAcceleratedPaintInfo {
11+
/**
12+
* HANDLE to a texture that can be opened with D3D11 OpenSharedResource.
13+
*/
14+
public long shared_texture_handle = 0;
15+
16+
public CefAcceleratedPaintInfoWin() {}
17+
18+
public CefAcceleratedPaintInfoWin(long shared_texture_handle, int format, int width, int height) {
19+
super(format, width, height);
20+
this.shared_texture_handle = shared_texture_handle;
21+
}
22+
23+
@Override
24+
public CefAcceleratedPaintInfoWin clone() {
25+
return new CefAcceleratedPaintInfoWin(shared_texture_handle, format, width, height);
26+
}
27+
}

java/org/cef/handler/CefRenderHandler.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,18 @@ public interface CefRenderHandler {
6868
public void onPaint(CefBrowser browser, boolean popup, Rectangle[] dirtyRects,
6969
ByteBuffer buffer, int width, int height);
7070

71-
/**
72-
* Called when an element has been rendered to the shared texture handle.
73-
* This method is only called when CefWindowInfo::shared_texture_enabled is set to true.
74-
* @param browser The browser generating the event.
75-
* @param popup True if painting a popup window.
76-
* @param dirtyRects Array of dirty regions.
77-
* @param info Contains the shared handle and texture information.
78-
*/
71+
/**
72+
* Called when an element has been rendered to the shared texture handle.
73+
* This method is only called when CefWindowInfo::shared_texture_enabled is set to true.
74+
* @param browser The browser generating the event.
75+
* @param popup True if painting a popup window.
76+
* @param dirtyRects Array of dirty regions.
77+
* @param info Platform-specific info instance. Expect one of
78+
* {@link CefAcceleratedPaintInfoWin},
79+
* {@link CefAcceleratedPaintInfoMac},
80+
* {@link CefAcceleratedPaintInfoLinux}, or a base
81+
* {@link CefAcceleratedPaintInfo} on unsupported platforms.
82+
*/
7983
public void onAcceleratedPaint(CefBrowser browser, boolean popup, Rectangle[] dirtyRects,
8084
CefAcceleratedPaintInfo info);
8185

native/render_handler.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,16 @@ void RenderHandler::OnAcceleratedPaint(CefRefPtr<CefBrowser> browser,
284284
jboolean jtype = type == PET_VIEW ? JNI_FALSE : JNI_TRUE;
285285
ScopedJNIObjectLocal jrectArray(env, NewJNIRectArray(env, dirtyRects));
286286

287-
// Create CefAcceleratedPaintInfo Java object
287+
// Create platform-specific CefAcceleratedPaintInfo Java object
288+
#if defined(OS_WIN)
289+
ScopedJNIClass cls(env, "org/cef/handler/CefAcceleratedPaintInfoWin");
290+
#elif defined(OS_MACOSX)
291+
ScopedJNIClass cls(env, "org/cef/handler/CefAcceleratedPaintInfoMac");
292+
#elif defined(OS_LINUX)
293+
ScopedJNIClass cls(env, "org/cef/handler/CefAcceleratedPaintInfoLinux");
294+
#else
288295
ScopedJNIClass cls(env, "org/cef/handler/CefAcceleratedPaintInfo");
296+
#endif
289297
if (!cls)
290298
return;
291299
ScopedJNIObjectLocal jpaintInfo(env, NewJNIObject(env, cls));
@@ -299,9 +307,9 @@ void RenderHandler::OnAcceleratedPaint(CefRefPtr<CefBrowser> browser,
299307
#if defined(OS_WIN)
300308
SetJNIFieldLong(env, cls, jpaintInfo, "shared_texture_handle",
301309
reinterpret_cast<jlong>(info.shared_texture_handle));
302-
#else
303-
// On non-Windows platforms, shared_texture_handle is not available
304-
SetJNIFieldLong(env, cls, jpaintInfo, "shared_texture_handle", 0);
310+
#elif defined(OS_MACOSX)
311+
SetJNIFieldLong(env, cls, jpaintInfo, "shared_texture_io_surface",
312+
reinterpret_cast<jlong>(info.shared_texture_io_surface));
305313
#endif
306314
SetJNIFieldInt(env, cls, jpaintInfo, "format", info.format);
307315
SetJNIFieldInt(env, cls, jpaintInfo, "width", viewRect.width);
@@ -351,9 +359,6 @@ void RenderHandler::OnAcceleratedPaint(CefRefPtr<CefBrowser> browser,
351359
}
352360
}
353361
}
354-
#else
355-
SetJNIFieldInt(env, cls, jpaintInfo, "plane_count", 0);
356-
SetJNIFieldLong(env, cls, jpaintInfo, "modifier", 0);
357362
#endif
358363

359364
JNI_CALL_VOID_METHOD(env, handle_, "onAcceleratedPaint",

0 commit comments

Comments
 (0)