Skip to content

Commit a69b37e

Browse files
committed
feat: dmabuf planes
1 parent 8f1fdc2 commit a69b37e

2 files changed

Lines changed: 95 additions & 3 deletions

File tree

java/org/cef/handler/CefAcceleratedPaintInfo.java

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public class CefAcceleratedPaintInfo {
1111
/**
1212
* Shared texture handle. The meaning depends on the platform:
1313
* - Windows: HANDLE to a texture that can be opened with D3D11 OpenSharedResource
14-
* - macOS: IOSurface pointer that can be opened with Metal or OpenGL
15-
* - Linux: Contains several planes, each with an fd to the underlying system native buffer
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
1616
*/
1717
public long shared_texture_handle = 0;
1818

@@ -26,6 +26,36 @@ public class CefAcceleratedPaintInfo {
2626
*/
2727
public int width = 0;
2828
public int height = 0;
29+
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;
2959

3060
public CefAcceleratedPaintInfo() {}
3161

@@ -35,9 +65,20 @@ public CefAcceleratedPaintInfo(long shared_texture_handle, int format, int width
3565
this.width = width;
3666
this.height = height;
3767
}
68+
69+
public boolean hasDmaBufPlanes() {
70+
return plane_count > 0 && plane_fds != null && plane_strides != null && plane_offsets != null;
71+
}
3872

3973
@Override
4074
public CefAcceleratedPaintInfo clone() {
41-
return new CefAcceleratedPaintInfo(shared_texture_handle, format, width, height);
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;
4283
}
4384
}

native/render_handler.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "render_handler.h"
66

7+
#include <vector>
8+
79
#include "client_handler.h"
810
#include "jni_util.h"
911

@@ -305,6 +307,55 @@ void RenderHandler::OnAcceleratedPaint(CefRefPtr<CefBrowser> browser,
305307
SetJNIFieldInt(env, cls, jpaintInfo, "width", viewRect.width);
306308
SetJNIFieldInt(env, cls, jpaintInfo, "height", viewRect.height);
307309

310+
#if defined(OS_LINUX)
311+
SetJNIFieldInt(env, cls, jpaintInfo, "plane_count", info.plane_count);
312+
SetJNIFieldLong(env, cls, jpaintInfo, "modifier",
313+
static_cast<jlong>(info.modifier));
314+
315+
const int plane_count = info.plane_count;
316+
if (plane_count > 0) {
317+
std::vector<jint> fds(plane_count);
318+
std::vector<jint> strides(plane_count);
319+
std::vector<jlong> offsets(plane_count);
320+
std::vector<jlong> sizes(plane_count);
321+
322+
for (int i = 0; i < plane_count; ++i) {
323+
fds[i] = info.planes[i].fd;
324+
strides[i] = static_cast<jint>(info.planes[i].stride);
325+
offsets[i] = static_cast<jlong>(info.planes[i].offset);
326+
sizes[i] = static_cast<jlong>(info.planes[i].size);
327+
}
328+
329+
jclass paintInfoClass = cls.get();
330+
jfieldID fdsField = env->GetFieldID(paintInfoClass, "plane_fds", "[I");
331+
jfieldID stridesField = env->GetFieldID(paintInfoClass, "plane_strides", "[I");
332+
jfieldID offsetsField = env->GetFieldID(paintInfoClass, "plane_offsets", "[J");
333+
jfieldID sizesField = env->GetFieldID(paintInfoClass, "plane_sizes", "[J");
334+
335+
if (fdsField && stridesField && offsetsField && sizesField) {
336+
jintArray fdsArray = env->NewIntArray(plane_count);
337+
jintArray stridesArray = env->NewIntArray(plane_count);
338+
jlongArray offsetsArray = env->NewLongArray(plane_count);
339+
jlongArray sizesArray = env->NewLongArray(plane_count);
340+
341+
if (fdsArray && stridesArray && offsetsArray && sizesArray) {
342+
env->SetIntArrayRegion(fdsArray, 0, plane_count, fds.data());
343+
env->SetIntArrayRegion(stridesArray, 0, plane_count, strides.data());
344+
env->SetLongArrayRegion(offsetsArray, 0, plane_count, offsets.data());
345+
env->SetLongArrayRegion(sizesArray, 0, plane_count, sizes.data());
346+
347+
env->SetObjectField(jpaintInfo.get(), fdsField, fdsArray);
348+
env->SetObjectField(jpaintInfo.get(), stridesField, stridesArray);
349+
env->SetObjectField(jpaintInfo.get(), offsetsField, offsetsArray);
350+
env->SetObjectField(jpaintInfo.get(), sizesField, sizesArray);
351+
}
352+
}
353+
}
354+
#else
355+
SetJNIFieldInt(env, cls, jpaintInfo, "plane_count", 0);
356+
SetJNIFieldLong(env, cls, jpaintInfo, "modifier", 0);
357+
#endif
358+
308359
JNI_CALL_VOID_METHOD(env, handle_, "onAcceleratedPaint",
309360
"(Lorg/cef/browser/CefBrowser;Z[Ljava/awt/"
310361
"Rectangle;Lorg/cef/handler/CefAcceleratedPaintInfo;)V",

0 commit comments

Comments
 (0)