Skip to content

Commit 33501e8

Browse files
committed
Add CefMacOsIOSurface (OC++/Java)
1 parent 6a29c74 commit 33501e8

3 files changed

Lines changed: 58 additions & 2 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2026 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 IOSurface helpers used by accelerated off-screen rendering.
9+
*/
10+
public final class CefMacOsIOSurface {
11+
private CefMacOsIOSurface() {}
12+
13+
/**
14+
* Binds the IOSurface to the currently bound GL_TEXTURE_RECTANGLE texture in
15+
* the current CGL context.
16+
*
17+
* @return CGLError, where 0 means success.
18+
*/
19+
public static native int bindToCurrentTexture(long ioSurface, int width, int height);
20+
}

native/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ set(JCEF_SRCS_LINUX
158158
util_posix.cpp
159159
)
160160
set(JCEF_SRCS_MAC
161+
CefMacOsIOSurface_N.mm
161162
critical_wait_posix.cpp
162163
temp_window_mac.h
163164
temp_window_mac.mm
@@ -312,7 +313,7 @@ if(OS_MAC)
312313
add_library(${JCEF_TARGET} SHARED ${JCEF_RESOURCES_SRCS} ${JCEF_SRCS})
313314
SET_EXECUTABLE_TARGET_PROPERTIES(${JCEF_TARGET})
314315
add_dependencies(${JCEF_TARGET} libcef_dll_wrapper)
315-
target_link_libraries(${JCEF_TARGET} libcef_dll_wrapper ${CEF_STANDARD_LIBS} ${JNI_LIBRARIES})
316+
target_link_libraries(${JCEF_TARGET} libcef_dll_wrapper ${CEF_STANDARD_LIBS} ${JNI_LIBRARIES} "-framework OpenGL")
316317
target_include_directories(${JCEF_TARGET} PUBLIC ${JNI_INCLUDE_DIRS})
317318

318319
# Compile flags specific to the JCEF library target.
@@ -431,4 +432,3 @@ if(OS_WINDOWS)
431432
COPY_FILES("${JCEF_TARGET}" "${CEF_BINARY_FILES}" "${CEF_BINARY_DIR}" "${CEF_TARGET_OUT_DIR}")
432433
COPY_FILES("${JCEF_TARGET}" "${CEF_RESOURCE_FILES}" "${CEF_RESOURCE_DIR}" "${CEF_TARGET_OUT_DIR}")
433434
endif()
434-

native/CefMacOsIOSurface_N.mm

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2026 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+
#include <jni.h>
6+
7+
#include <OpenGL/CGLIOSurface.h>
8+
#include <OpenGL/gl3.h>
9+
#include <OpenGL/OpenGL.h>
10+
11+
JNIEXPORT jint JNICALL
12+
Java_org_cef_handler_CefMacOsIOSurface_bindToCurrentTexture(JNIEnv*,
13+
jclass,
14+
jlong io_surface,
15+
jint width,
16+
jint height) {
17+
if (io_surface == 0 || width <= 0 || height <= 0) {
18+
return kCGLBadValue;
19+
}
20+
21+
CGLContextObj context = CGLGetCurrentContext();
22+
if (context == nullptr) {
23+
return kCGLBadContext;
24+
}
25+
26+
return CGLTexImageIOSurface2D(
27+
context,
28+
GL_TEXTURE_RECTANGLE,
29+
GL_RGBA,
30+
width,
31+
height,
32+
GL_BGRA,
33+
GL_UNSIGNED_INT_8_8_8_8_REV,
34+
reinterpret_cast<IOSurfaceRef>(io_surface),
35+
0);
36+
}

0 commit comments

Comments
 (0)