-
Notifications
You must be signed in to change notification settings - Fork 253
Shared textures OpenGL #548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ujpv
wants to merge
1
commit into
kharitonov/shared_texture_refactor_metal
Choose a base branch
from
kharitonov/shared_texture_opengl
base: kharitonov/shared_texture_refactor_metal
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/java.desktop/linux/classes/com/jetbrains/desktop/SharedTexturesService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * Copyright 2025 JetBrains s.r.o. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. Oracle designates this | ||
| * particular file as subject to the "Classpath" exception as provided | ||
| * by Oracle in the LICENSE file that accompanied this code. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| package com.jetbrains.desktop; | ||
|
|
||
| import com.jetbrains.desktop.image.TextureWrapperSurfaceManager; | ||
| import com.jetbrains.exported.JBRApi; | ||
| import sun.awt.image.SurfaceManager; | ||
| import sun.java2d.SurfaceData; | ||
|
|
||
| import sun.java2d.opengl.*; | ||
|
|
||
| import java.awt.GraphicsConfiguration; | ||
| import java.awt.Image; | ||
|
|
||
| @JBRApi.Service | ||
| @JBRApi.Provides("SharedTextures") | ||
| public class SharedTexturesService extends SharedTextures { | ||
| @Override | ||
| public int getTextureType(GraphicsConfiguration gc) { | ||
| if (gc instanceof GLXGraphicsConfig) { | ||
| return OPENGL_TEXTURE_TYPE; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| @Override | ||
| public long[] getOpenGLContextInfo(GraphicsConfiguration gc) { | ||
| if (gc instanceof GLXGraphicsConfig glxGraphicsConfig) { | ||
| return new long[] { | ||
| GLXGraphicsConfigExt.getSharedContext(), | ||
| GLXGraphicsConfigExt.getAwtDisplay(), | ||
| GLXGraphicsConfigExt.getFBConfig(glxGraphicsConfig), | ||
| }; | ||
| } | ||
|
|
||
| throw new UnsupportedOperationException("Unsupported graphics configuration: " + gc); | ||
| } | ||
|
|
||
| @Override | ||
| public SurfaceManager createSurfaceManager(GraphicsConfiguration gc, Image image, long texture) { | ||
| SurfaceData sd; | ||
| if (gc instanceof GLXGraphicsConfig glxGraphicsConfig) { | ||
| sd = new GLXTextureWrapperSurfaceData(glxGraphicsConfig, image, texture); | ||
| } else { | ||
| throw new UnsupportedOperationException("Unsupported graphics configuration: " + gc); | ||
| } | ||
|
|
||
| return new TextureWrapperSurfaceManager(sd); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/java.desktop/macosx/classes/sun/java2d/opengl/CGLGraphicsConfigExt.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package sun.java2d.opengl; | ||
|
|
||
| public class CGLGraphicsConfigExt { | ||
| public static native long getSharedContext(); | ||
| public static native long getPixelFormat(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/java.desktop/macosx/classes/sun/java2d/opengl/CGLTextureWrapperSurfaceData.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package sun.java2d.opengl; | ||
|
|
||
| import sun.java2d.SurfaceData; | ||
|
|
||
| import java.awt.*; | ||
| import java.awt.image.ColorModel; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
|
|
||
| public class CGLTextureWrapperSurfaceData extends CGLSurfaceData { | ||
|
|
||
| public CGLTextureWrapperSurfaceData(CGLGraphicsConfig gc, Image image, long textureId) { | ||
| super(null, gc, gc.getColorModel(TRANSLUCENT), RT_TEXTURE, 0, 0); | ||
|
|
||
| OGLRenderQueue rq = OGLRenderQueue.getInstance(); | ||
| AtomicBoolean success = new AtomicBoolean(false); | ||
| rq.lock(); | ||
| try { | ||
| OGLContext.setScratchSurface(gc); | ||
| rq.flushAndInvokeNow(() -> success.set(OGLSurfaceDataExt.initWithTexture(this, 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; | ||
| } | ||
|
|
||
| @Override | ||
| public void flush() { | ||
| // reset the texture id first to avoid the texture deallocation | ||
| OGLSurfaceDataExt.resetTextureId(this); | ||
| super.flush(); | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfigExt.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #import "sun_java2d_opengl_CGLGraphicsConfigExt.h" | ||
|
|
||
| #import "JNIUtilities.h" | ||
|
|
||
| extern NSOpenGLContext *sharedContext; | ||
| extern NSOpenGLPixelFormat *sharedPixelFormat; | ||
|
|
||
| JNIEXPORT jlong JNICALL | ||
| Java_sun_java2d_opengl_CGLGraphicsConfigExt_getSharedContext | ||
| (JNIEnv *env, jclass cls) | ||
| { | ||
| return ptr_to_jlong(sharedContext.CGLContextObj); | ||
| } | ||
|
|
||
| JNIEXPORT jlong JNICALL | ||
| Java_sun_java2d_opengl_CGLGraphicsConfigExt_getPixelFormat | ||
| (JNIEnv *env, jclass cls) | ||
| { | ||
| return ptr_to_jlong(sharedPixelFormat.CGLPixelFormatObj); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/java.desktop/share/classes/sun/java2d/opengl/OGLGraphicsConfigExt.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright 2025 JetBrains s.r.o. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. Oracle designates this | ||
| * particular file as subject to the "Classpath" exception as provided | ||
| * by Oracle in the LICENSE file that accompanied this code. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| package sun.java2d.opengl; | ||
|
|
||
| import java.awt.*; | ||
|
|
||
| public class OGLGraphicsConfigExt { | ||
| public static long getSharedContext(GraphicsConfiguration gc) { | ||
| if (gc instanceof OGLGraphicsConfig) { | ||
| return getSharedContext(); | ||
| } | ||
|
|
||
| throw new IllegalArgumentException("Not an OpenGL graphics config: " + gc); | ||
| } | ||
|
|
||
| public static long getPixelFormat(GraphicsConfiguration gc) { | ||
| if (gc instanceof OGLGraphicsConfig oglGc) { | ||
| return getPixelFormat(oglGc.getNativeConfigInfo()); | ||
| } | ||
|
|
||
| throw new IllegalArgumentException("Not an OpenGL graphics config: " + gc); | ||
| } | ||
|
|
||
| private static native long getPixelFormat(long pConfigInfo); | ||
| private static native long getSharedContext(); | ||
| } |
39 changes: 39 additions & 0 deletions
39
src/java.desktop/share/classes/sun/java2d/opengl/OGLSurfaceDataExt.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * Copyright 2025 JetBrains s.r.o. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. Oracle designates this | ||
| * particular file as subject to the "Classpath" exception as provided | ||
| * by Oracle in the LICENSE file that accompanied this code. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| package sun.java2d.opengl; | ||
|
|
||
| public class OGLSurfaceDataExt { | ||
| public static boolean initWithTexture(OGLSurfaceData surfaceData, long textureId) { | ||
| return OGLSurfaceDataExt.initWithTexture(surfaceData.getNativeOps(), textureId); | ||
| } | ||
|
|
||
| public static void resetTextureId(OGLSurfaceData surfaceData) { | ||
| resetTextureId(surfaceData.getNativeOps()); | ||
| } | ||
|
|
||
| private static native boolean initWithTexture(long pData, long textureId); | ||
| private static native void resetTextureId(long pData); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot whether I already asked this, but do we really need an OGL implementation on macOS, given that it's deprecated there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we talked about it and concluded that it won't heart. :)
We still have this pipeline, the OS still supports it so far.