Compare commits

...

5 Commits

Author SHA1 Message Date
Vladimir Kharitonov
ac8459aa32 Shared textures opengl windows 2025-05-19 16:21:59 +02:00
Vladimir Kharitonov
353632b773 expose shared context 2025-05-05 23:20:48 +02:00
Vladimir Kharitonov
fdd031997f fix_compile_commands.py 2025-05-05 23:20:11 +02:00
Vladimir Kharitonov
24fd0cad34 my_configure.sh 2025-05-05 15:29:42 +02:00
Vladimir Kharitonov
56ab861c14 fix_compile_commands.py 2025-05-05 15:19:32 +02:00
10 changed files with 310 additions and 38 deletions

77
fix_compile_commands.py Normal file
View File

@@ -0,0 +1,77 @@
import json
import os
import sys
def add_include_paths(compile_commands, paths):
valid_paths = [path for path in paths if os.path.isdir(path)]
if not valid_paths:
print("No valid include paths found.")
return
try:
with open(compile_commands, "r", encoding="utf-8") as file:
commands = json.load(file)
for entry in commands:
command = entry["command"]
for path in valid_paths:
include_flag = f"-I{path}"
if include_flag not in command:
command += f" {include_flag}"
entry["command"] = command
with open(compile_commands, "w", encoding="utf-8") as file:
json.dump(commands, file, indent=4)
print(f"Successfully added valid include paths: {valid_paths}")
except Exception as e:
print(f"Error while processing the file: {e}")
def remove_commands(compile_commands, commands_to_remove):
try:
with open(compile_commands, "r", encoding="utf-8") as file:
commands = json.load(file)
filtered_commands = [
entry for entry in commands
if not any(remove_substring in entry['command'] for remove_substring in commands_to_remove)
]
with open(compile_commands, "w", encoding="utf-8") as file:
json.dump(filtered_commands, file, indent=4)
print(f"Successfully removed commands containing: {commands_to_remove}")
print(f"Remaining entries: {len(filtered_commands)}")
except Exception as e:
print(f"Error while processing the file: {e}")
def main():
if len(sys.argv) != 2:
print("Usage: python script.py <path_to_compile_commands.json>")
sys.exit(1)
compile_commands = sys.argv[1]
if not os.path.isfile(compile_commands):
print(f"Error: The file '{compile_commands}' does not exist or is not a valid file.")
sys.exit(1)
remove_commands(compile_commands, ["ml64.exe"])
include_paths = [
"C:\\\\develop\\\\jetbrainsruntime\\\\src\\\\java.base\\\\share\\\\native\\\\include",
"C:\\\\develop\\\\jetbrainsruntime\\\\src\\\\java.desktop\\\\share\\\\native\\\\libfreetype\\\\include",
]
add_include_paths(compile_commands, include_paths)
if __name__ == "__main__":
main()

1
my_configure.sh Normal file
View File

@@ -0,0 +1 @@
sh configure --with-boot-jdk=/cygdrive/c/users/khari/.jdks/jbr-21.0.6 --disable-warnings-as-errors --with-toolchain-version=2019 --with-debug-level=fastdebug --with-native-debug-symbols=external

View File

@@ -37,6 +37,7 @@ import java.awt.Image;
@JBRApi.Provides("SharedTextures")
public class SharedTextures {
public final static int METAL_TEXTURE_TYPE = 1;
public final static int OPENGL_TEXTURE_TYPE = 2;
private final int textureType;
@@ -67,6 +68,8 @@ public class SharedTextures {
try {
if (SunToolkit.isInstanceOf(gc, "sun.java2d.metal.MTLGraphicsConfig")) {
return METAL_TEXTURE_TYPE;
} else if (SunToolkit.isInstanceOf(gc, "sun.java2d.opengl.WGLGraphicsConfig")) {
return OPENGL_TEXTURE_TYPE;
}
} catch (Exception e) {
throw new InternalError("Unexpected exception during reflection", e);
@@ -74,4 +77,12 @@ public class SharedTextures {
return 0;
}
public long getSharedGLContext(GraphicsConfiguration gc) {
return gc.getSharedContext();
}
public int getGLPixelFormat(GraphicsConfiguration gc) {
return gc.getPixelFormat();
}
}

View File

@@ -32,6 +32,7 @@ import java.awt.image.VolatileImage;
import java.awt.image.WritableRaster;
import sun.awt.image.SunVolatileImage;
import sun.java2d.SurfaceData;
/**
* The {@code GraphicsConfiguration} class describes the
@@ -448,4 +449,29 @@ public abstract class GraphicsConfiguration {
// Overridden in subclasses
return false;
}
/**
* sadfafasdf
* @return asdasd
*/
public int getPixelFormat() {
return -1;
}
/**
* sadfafasdf
* @return sdfasdf
*/
public long getSharedContext() {
return -1;
}
/**
* Some comment
* @param texture - something
* @return something
*/
public Image wrapTextureImage(long texture) {
return null;
}
}

View File

@@ -172,6 +172,8 @@ public abstract class OGLSurfaceData extends SurfaceData
int width, int height);
protected native boolean initFlipBackbuffer(long pData);
protected native boolean initWithTexture(long pData, boolean isOpaque, long textureId);
private native int getTextureTarget(long pData);
private native int getTextureID(long pData);

View File

@@ -388,6 +388,65 @@ OGLSD_InitFBObject(GLuint *fbobjectID, GLuint *depthID,
return JNI_TRUE;
}
JNIEXPORT
jboolean JNICALL Java_sun_java2d_opengl_OGLSurfaceData_initWithTexture
(JNIEnv *env, jobject oglsd, jlong pData, jboolean isOpaque, jlong textureId)
{
OGLSDOps *oglsdo = (OGLSDOps *)jlong_to_ptr(pData);
if (oglsdo == NULL) {
J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSurfaceData_initWithTexture: ops are null");
return JNI_FALSE;
}
j2d_glBindTexture(GL_TEXTURE_2D, textureId);
GLenum error = j2d_glGetError();
if (error != GL_NO_ERROR) {
J2dRlsTraceLn2(J2D_TRACE_ERROR,
"OGLSurfaceData_initWithTexture: could not bind texture: id=%d error=%x",
textureId, error);
return JNI_FALSE;
}
if (!j2d_glIsTexture(textureId)) {
J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSurfaceData_initWithTexture: textureId is not a valid texture id");
j2d_glBindTexture(GL_TEXTURE_2D, 0);
return JNI_FALSE;
}
GLsizei width, height;
j2d_glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
j2d_glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
j2d_glBindTexture(GL_TEXTURE_2D, 0);
GLint texMax;
j2d_glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texMax);
if (width >= texMax || height >= texMax || width <= 0 || height <= 0) {
J2dRlsTraceLn2(J2D_TRACE_ERROR,
"OGLSurfaceData_initWithTexture: wrong texture size %d x %d",
width, height);
return JNI_FALSE;
}
oglsdo->isOpaque = isOpaque;
oglsdo->xOffset = 0;
oglsdo->yOffset = 0;
oglsdo->width = width;
oglsdo->height = height;
oglsdo->textureID = textureId;
oglsdo->textureWidth = width;
oglsdo->textureHeight = height;
oglsdo->textureTarget = GL_TEXTURE_2D;
OGLSD_INIT_TEXTURE_FILTER(oglsdo, GL_NEAREST);
OGLSD_SetNativeDimensions(env, oglsdo, width, height);
oglsdo->drawableType = OGLSD_TEXTURE;
J2dTraceLn3(J2D_TRACE_VERBOSE, "OGLSurfaceData_initWithTexture: wrapped texture: w=%d h=%d id=%d", width, height, textureId);
return JNI_TRUE;
}
/**
* Initializes a framebuffer object, using the given width and height as
* a guide. See OGLSD_InitTextureObject() and OGLSD_InitFBObject()
@@ -663,31 +722,31 @@ OGLSD_SetNativeDimensions(JNIEnv *env, OGLSDOps *oglsdo,
void
OGLSD_Delete(JNIEnv *env, OGLSDOps *oglsdo)
{
J2dTraceLn1(J2D_TRACE_INFO, "OGLSD_Delete: type=%d",
oglsdo->drawableType);
if (oglsdo->drawableType == OGLSD_TEXTURE) {
if (oglsdo->textureID != 0) {
j2d_glDeleteTextures(1, &oglsdo->textureID);
oglsdo->textureID = 0;
}
} else if (oglsdo->drawableType == OGLSD_FBOBJECT) {
if (oglsdo->textureID != 0) {
j2d_glDeleteTextures(1, &oglsdo->textureID);
oglsdo->textureID = 0;
}
if (oglsdo->depthID != 0) {
j2d_glDeleteRenderbuffersEXT(1, &oglsdo->depthID);
oglsdo->depthID = 0;
}
if (oglsdo->fbobjectID != 0) {
j2d_glDeleteFramebuffersEXT(1, &oglsdo->fbobjectID);
oglsdo->fbobjectID = 0;
}
} else {
// dispose windowing system resources (pbuffer, pixmap, etc)
OGLSD_DestroyOGLSurface(env, oglsdo);
}
// J2dTraceLn1(J2D_TRACE_INFO, "OGLSD_Delete: type=%d",
// oglsdo->drawableType);
//
// if (oglsdo->drawableType == OGLSD_TEXTURE) {
// if (oglsdo->textureID != 0) {
// j2d_glDeleteTextures(1, &oglsdo->textureID);
// oglsdo->textureID = 0;
// }
// } else if (oglsdo->drawableType == OGLSD_FBOBJECT) {
// if (oglsdo->textureID != 0) {
// j2d_glDeleteTextures(1, &oglsdo->textureID);
// oglsdo->textureID = 0;
// }
// if (oglsdo->depthID != 0) {
// j2d_glDeleteRenderbuffersEXT(1, &oglsdo->depthID);
// oglsdo->depthID = 0;
// }
// if (oglsdo->fbobjectID != 0) {
// j2d_glDeleteFramebuffersEXT(1, &oglsdo->fbobjectID);
// oglsdo->fbobjectID = 0;
// }
// } else {
// // dispose windowing system resources (pbuffer, pixmap, etc)
// OGLSD_DestroyOGLSurface(env, oglsdo);
// }
}
/**
@@ -709,6 +768,11 @@ OGLSD_Dispose(JNIEnv *env, SurfaceDataOps *ops)
(*env)->DeleteGlobalRef(env, graphicsConfig);
oglsdo->graphicsConfig = NULL;
}
//
//void OGLSD_Dispose_SharedTexture(JNIEnv *env, SurfaceDataOps *ops) {
// OGLSDOps *oglsdo = (OGLSDOps *)ops;
//}
/**
* This is the implementation of the general surface LockFunc defined in

View File

@@ -28,13 +28,11 @@ package sun.java2d;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import sun.awt.image.BufImgVolatileSurfaceManager;
import sun.awt.image.SunVolatileImage;
import sun.awt.image.SurfaceManager;
import sun.awt.image.VolatileSurfaceManager;
import sun.awt.image.*;
import sun.java2d.d3d.D3DGraphicsConfig;
import sun.java2d.d3d.D3DVolatileSurfaceManager;
import sun.java2d.opengl.WGLGraphicsConfig;
import sun.java2d.opengl.WGLSurfaceData;
import sun.java2d.opengl.WGLVolatileSurfaceManager;
/**
@@ -66,7 +64,10 @@ public class WindowsSurfaceManagerFactory extends SurfaceManagerFactory {
}
@Override
public SurfaceManager createTextureWrapperSurfaceManager(GraphicsConfiguration gc, Image image, long texture) {
public SurfaceManager createTextureWrapperSurfaceManager(GraphicsConfiguration gc, Image image, long textureId) {
if (gc instanceof WGLGraphicsConfig) {
return new TextureWrapperSurfaceManager(WGLSurfaceData.createData((WGLGraphicsConfig) gc, image, textureId));
}
throw new UnsupportedOperationException("Not supported");
}
}

View File

@@ -25,20 +25,14 @@
package sun.java2d.opengl;
import java.awt.AWTException;
import java.awt.BufferCapabilities;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.ImageCapabilities;
import java.awt.Transparency;
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.image.ColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DirectColorModel;
import java.awt.image.VolatileImage;
import com.jetbrains.desktop.image.TextureWrapperImage;
import sun.awt.Win32GraphicsConfig;
import sun.awt.Win32GraphicsDevice;
import sun.awt.image.SunVolatileImage;
@@ -76,9 +70,21 @@ public final class WGLGraphicsConfig
private final SurfaceManager.ProxyCache surfaceDataProxyCache = new SurfaceManager.ProxyCache();
public static native int getDefaultPixFmt(int screennum);
/**
* Returns the shared context for this WGLGraphicsConfig. This is
* @return shared context for this WGLGraphicsConfig, or 0 if none.
*/
@Override
public long getSharedContext() {
return n_getSharedContext();
}
private native long n_getSharedContext();
private static native boolean initWGL();
private static native long getWGLConfigInfo(int screennum, int visualnum);
private static native int getOGLCapabilities(long configInfo);
private static native int getPixelFormat(long configInfo);
static {
wglAvailable = initWGL();
@@ -246,6 +252,15 @@ public final class WGLGraphicsConfig
}
}
/**
* Returns the pixel format associated with this WGLGraphicsConfig.
* @return pixel format associated with this WGLGraphicsConfig, or 0 if
*/
@Override
public int getPixelFormat() {
return getPixelFormat(pConfigInfo);
}
@Override
public String toString() {
return ("WGLGraphicsConfig[dev="+getDevice()+",pixfmt="+visual+"]");
@@ -432,4 +447,9 @@ public final class WGLGraphicsConfig
public ContextCapabilities getContextCapabilities() {
return oglCaps;
}
@Override
public Image wrapTextureImage(long texture) {
return new TextureWrapperImage(this, texture);
}
}

View File

@@ -33,6 +33,8 @@ import java.awt.Image;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.image.ColorModel;
import java.util.concurrent.atomic.AtomicBoolean;
import sun.awt.SunToolkit;
import sun.awt.Win32GraphicsDevice;
import sun.awt.windows.WComponentPeer;
@@ -138,6 +140,10 @@ public abstract class WGLSurfaceData extends OGLSurfaceData {
image, cm, type);
}
public static WGLSurfaceData createData(WGLGraphicsConfig gc, Image image, long textureId) {
return new WGLTextureWrapperSurfaceData(gc, image, textureId);
}
public static WGLGraphicsConfig getGC(WComponentPeer peer) {
if (peer != null) {
return (WGLGraphicsConfig)peer.getGraphicsConfiguration();
@@ -259,6 +265,44 @@ public abstract class WGLSurfaceData extends OGLSurfaceData {
}
}
public static class WGLTextureWrapperSurfaceData extends WGLSurfaceData {
private final Image image;
public WGLTextureWrapperSurfaceData(WGLGraphicsConfig gc, Image image, long textureId) {
super(null, gc, ColorModel.getRGBdefault(), RT_TEXTURE);
this.image = image;
OGLRenderQueue rq = OGLRenderQueue.getInstance();
AtomicBoolean success = new AtomicBoolean(false);
rq.lock();
try {
OGLContext.setScratchSurface(gc);
rq.flushAndInvokeNow(() -> success.set(initWithTexture(getNativeOps(), false, textureId)));
} finally {
rq.unlock();
}
if (!success.get()) {
throw new IllegalArgumentException("Failed to init the surface data");
}
}
@Override
public SurfaceData getReplacement() {
throw new UnsupportedOperationException();
}
@Override
public Rectangle getBounds() {
return getNativeBounds();
}
@Override
public Object getDestination() {
return null;
}
}
/**
* Updates the layered window with the contents of the surface.
*

View File

@@ -698,6 +698,13 @@ Java_sun_java2d_opengl_WGLGraphicsConfig_getDefaultPixFmt(JNIEnv *env,
return 0;
}
JNIEXPORT jlong JNICALL
Java_sun_java2d_opengl_WGLGraphicsConfig_n_1getSharedContext(JNIEnv *env,
jobject wglgc)
{
return sharedContext;
}
JNIEXPORT jint JNICALL
Java_sun_java2d_opengl_WGLGraphicsConfig_getOGLCapabilities(JNIEnv *env,
jclass wglgc,
@@ -714,3 +721,22 @@ Java_sun_java2d_opengl_WGLGraphicsConfig_getOGLCapabilities(JNIEnv *env,
return wglinfo->context->caps;
}
JNIEXPORT jint JNICALL
Java_sun_java2d_opengl_WGLGraphicsConfig_getPixelFormat(JNIEnv *env,
jclass wglcl,
jlong pConfigInfo)
{
WGLGraphicsConfigInfo *wglinfo =
(WGLGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
J2dTraceLn(J2D_TRACE_INFO, "WGLGraphicsConfig_getPixelFormat");
if (wglinfo == NULL) {
J2dRlsTraceLn(J2D_TRACE_ERROR,
"WGLGraphicsConfig_getPixelFormat: config info is null");
return 0;
}
return wglinfo->pixfmt;
}