Skip to content
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

8260931: Implement JEP 382: New macOS Rendering Pipeline #2403

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
0b8d96b
Project Lanai Patch
aghaisas Feb 4, 2021
5476874
Merge branch 'master' into 8260931_lanai_JEP_branch
aghaisas Feb 8, 2021
8ed7b5f
Lanai PR#174 - 8261234 - kcr
aghaisas Feb 8, 2021
6044adc
Lanai PR#175 - 8261304 - aghaisas
aghaisas Feb 8, 2021
fdf3be9
Lanai PR#176 - 8261399 - jdv
aghaisas Feb 9, 2021
6417328
Lanai PR#177 - 8261430 - aghaisas
aghaisas Feb 9, 2021
9a72538
Merge branch 'master' into 8260931_lanai_JEP_branch
aghaisas Feb 11, 2021
9c13bb3
Lanai PR#178 - 8261273 - avu
aghaisas Feb 11, 2021
6a3f96e
Lanai PR#179 - 8261402 - avu
aghaisas Feb 11, 2021
102494b
Lanai PR#180 - 8261546 - jdv
aghaisas Feb 11, 2021
7340d06
Lanai PR#181 - 8261143 - aghaisas
aghaisas Feb 11, 2021
a7df89b
Merge branch 'master' into 8260931_lanai_JEP_branch
aghaisas Feb 15, 2021
edf247d
Lanai PR#182 - 8261547 - psadhukhan
aghaisas Feb 15, 2021
8b5bf34
Lanai PR#184 - 8261620 - aghaisas
aghaisas Feb 15, 2021
d2548e0
Lanai PR#185 - 8261632 - jdv
aghaisas Feb 15, 2021
0d8aedc
Lanai PR#186 - 8261638 - avu
aghaisas Feb 15, 2021
3942a5b
Lanai PR#187 - 8261704 - jdv
aghaisas Feb 15, 2021
90af90d
Lanai PR#189 - 8261712 - avu
aghaisas Feb 15, 2021
1c0c0c1
Lanai PR#190 - 8261706 - jdv
aghaisas Feb 15, 2021
7b0b0dc
Lanai PR#191 - 8261705 - jdv
aghaisas Feb 15, 2021
10ebb70
Merge branch 'master' into 8260931_lanai_JEP_branch
aghaisas Feb 21, 2021
9432c5a
Lanai PR#192 - 8261789 - aghaisas
aghaisas Feb 21, 2021
68220fb
Lanai PR#193 - 8261734 - avu
aghaisas Feb 21, 2021
30284b9
Lanai PR#194 - 8261703 - jdv
aghaisas Feb 21, 2021
e2f78dd
Lanai PR#195 - 8261908 - jdv
aghaisas Feb 21, 2021
1e0ff66
Lanai PR#196 - 8260715 - avu
aghaisas Feb 21, 2021
8c598a6
Lanai PR#197 - 8261960 - jdv
aghaisas Feb 21, 2021
a2983f0
Lanai PR#198 - 8261646 - avu
aghaisas Feb 21, 2021
614be05
Lanai PR#199 - 8262091 - aghaisas
aghaisas Feb 21, 2021
30dab8d
Merge branch 'master' into 8260931_lanai_JEP_branch
aghaisas Mar 1, 2021
bf888a2
Lanai PR#200 - 8262115 - aghaisas
aghaisas Mar 1, 2021
6e2e528
Lanai PR#201 - 8261891 - avu
aghaisas Mar 1, 2021
9059255
Lanai PR#202 - 8262293 - avu
aghaisas Mar 1, 2021
e0fbc42
Lanai PR#203 - 8262313 - jdv
aghaisas Mar 1, 2021
c9ebcbc
Lanai PR#205 - 8262496 - avu
aghaisas Mar 1, 2021
5cb1fd9
Lanai PR#206 - 8262729 - aghaisas
aghaisas Mar 1, 2021
09519fd
Merge branch 'master' into 8260931_lanai_JEP_branch
aghaisas Mar 8, 2021
3995be1
Lanai PR#207 - 8262750 - jdv
aghaisas Mar 8, 2021
5660744
Lanai PR#208 - 8262928 - jdv
aghaisas Mar 8, 2021
e459f1a
Lanai PR#209 - 8262936 - jdv
aghaisas Mar 8, 2021
de45693
Lanai PR#210 - 8263159 - jdv
aghaisas Mar 8, 2021
b065a49
Merge branch 'master' into 8260931_lanai_JEP_branch
aghaisas Mar 10, 2021
d27ff90
Lanai PR#211 - 8262882 - aghaisas
aghaisas Mar 10, 2021
9a27831
Lanai PR#212 - 8259825 - aghaisas
aghaisas Mar 10, 2021
3980ecb
Lanai PR#213 - 8263325 - avu
aghaisas Mar 10, 2021
c4309ab
Merge branch 'master' into 8260931_lanai_JEP_branch
aghaisas Mar 11, 2021
369c3d2
Lanai PR#214 - 8263324 - avu
aghaisas Mar 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions make/autoconf/spec.gmk.in
Expand Up @@ -574,6 +574,8 @@ CXXFILT:=@CXXFILT@

LIPO:=@LIPO@
INSTALL_NAME_TOOL:=@INSTALL_NAME_TOOL@
METAL := @METAL@
METALLIB := @METALLIB@

# Options to linker to specify a mapfile.
# (Note absence of := assignment, because we do not want to evaluate the macro body here)
Expand Down
28 changes: 27 additions & 1 deletion make/autoconf/toolchain.m4
@@ -1,5 +1,5 @@
#
# Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -723,6 +723,32 @@ AC_DEFUN_ONCE([TOOLCHAIN_DETECT_TOOLCHAIN_EXTRA],
UTIL_LOOKUP_PROGS(LIPO, lipo)
UTIL_REQUIRE_PROGS(OTOOL, otool)
UTIL_REQUIRE_PROGS(INSTALL_NAME_TOOL, install_name_tool)

UTIL_LOOKUP_TOOLCHAIN_PROGS(METAL, metal)
if test "x$METAL" = x; then
AC_MSG_CHECKING([if metal can be run using xcrun])
METAL="xcrun -sdk macosx metal"
test_metal=`$METAL --version 2>&1`
if test $? -ne 0; then
AC_MSG_RESULT([no])
AC_MSG_ERROR([XCode tool 'metal' neither found in path nor with xcrun])
else
AC_MSG_RESULT([yes, will be using '$METAL'])
fi
fi

UTIL_LOOKUP_TOOLCHAIN_PROGS(METALLIB, metallib)
if test "x$METALLIB" = x; then
AC_MSG_CHECKING([if metallib can be run using xcrun])
METALLIB="xcrun -sdk macosx metallib"
test_metallib=`$METALLIB --version 2>&1`
if test $? -ne 0; then
AC_MSG_RESULT([no])
AC_MSG_ERROR([XCode tool 'metallib' neither found in path nor with xcrun])
else
AC_MSG_RESULT([yes, will be using '$METALLIB'])
fi
fi
fi

if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
Expand Down
3 changes: 2 additions & 1 deletion make/modules/java.desktop/Lib.gmk
@@ -1,5 +1,5 @@
#
# Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,6 +24,7 @@
#

include LibCommon.gmk
include Execute.gmk

# Hook to include the corresponding custom file, if present.
$(eval $(call IncludeCustomExtension, modules/java.desktop/Lib.gmk))
Expand Down
30 changes: 29 additions & 1 deletion make/modules/java.desktop/lib/Awt2dLibraries.gmk
Expand Up @@ -160,6 +160,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBAWT, \
LIBS_macosx := -lmlib_image \
-framework Cocoa \
-framework OpenGL \
-framework Metal \
-framework JavaRuntimeSupport \
-framework ApplicationServices \
-framework AudioToolbox, \
Expand Down Expand Up @@ -766,7 +767,8 @@ ifeq ($(ENABLE_HEADLESS_ONLY), false)
-framework ApplicationServices \
-framework Foundation \
-framework Security \
-framework Cocoa
-framework Cocoa \
-framework Metal
else ifeq ($(call isTargetOs, windows), true)
LIBSPLASHSCREEN_LIBS += kernel32.lib user32.lib gdi32.lib delayimp.lib $(WIN_JAVA_LIB) jvm.lib
else
Expand Down Expand Up @@ -827,6 +829,7 @@ ifeq ($(call isTargetOs, macosx), true)
libawt_lwawt/awt \
libawt_lwawt/font \
libawt_lwawt/java2d/opengl \
libawt_lwawt/java2d/metal \
include \
common/awt/debug \
common/java2d/opengl \
Expand Down Expand Up @@ -862,6 +865,7 @@ ifeq ($(call isTargetOs, macosx), true)
-framework AudioToolbox \
-framework Carbon \
-framework Cocoa \
-framework Metal \
-framework Security \
-framework ExceptionHandling \
-framework JavaRuntimeSupport \
Expand All @@ -884,6 +888,28 @@ endif
################################################################################

ifeq ($(call isTargetOs, macosx), true)
SHADERS_SRC := $(TOPDIR)/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/shaders.metal
SHADERS_SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/native/java.desktop/libosxui
SHADERS_AIR := $(SHADERS_SUPPORT_DIR)/shaders.air
SHADERS_LIB := $(INSTALL_LIBRARIES_HERE)/shaders.metallib
aghaisas marked this conversation as resolved.
Show resolved Hide resolved

$(eval $(call SetupExecute, metal_shaders, \
INFO := Running metal on $(notdir $(SHADERS_SRC)) (for libosxui.dylib), \
DEPS := $(SHADERS_SRC), \
OUTPUT_FILE := $(SHADERS_AIR), \
SUPPORT_DIR := $(SHADERS_SUPPORT_DIR), \
COMMAND := $(METAL) -c -std=osx-metal2.0 -o $(SHADERS_AIR) $(SHADERS_SRC), \
))

$(eval $(call SetupExecute, metallib_shaders, \
INFO := Running metallib on $(notdir $(SHADERS_AIR)) (for libosxui.dylib), \
DEPS := $(SHADERS_AIR), \
OUTPUT_FILE := $(SHADERS_LIB), \
SUPPORT_DIR := $(SHADERS_SUPPORT_DIR), \
COMMAND := $(METALLIB) -o $(SHADERS_LIB) $(SHADERS_AIR), \
))

TARGETS += $(SHADERS_LIB)

$(eval $(call SetupJdkLibrary, BUILD_LIBOSXUI, \
NAME := osxui, \
Expand All @@ -899,13 +925,15 @@ ifeq ($(call isTargetOs, macosx), true)
-L$(INSTALL_LIBRARIES_HERE), \
LIBS := -lawt -losxapp -lawt_lwawt \
-framework Cocoa \
-framework Metal \
-framework Carbon \
-framework ApplicationServices \
-framework JavaRuntimeSupport \
-ljava -ljvm, \
))

TARGETS += $(BUILD_LIBOSXUI)
$(BUILD_LIBOSXUI): $(SHADERS_LIB)

$(BUILD_LIBOSXUI): $(BUILD_LIBAWT)

Expand Down
6 changes: 3 additions & 3 deletions src/java.desktop/macosx/classes/sun/awt/CGraphicsConfig.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -32,8 +32,8 @@
import java.awt.image.ColorModel;

import sun.java2d.SurfaceData;
import sun.java2d.opengl.CGLLayer;
import sun.lwawt.LWGraphicsConfig;
import sun.lwawt.macosx.CFRetainedResource;

public abstract class CGraphicsConfig extends GraphicsConfiguration
implements LWGraphicsConfig {
Expand Down Expand Up @@ -80,7 +80,7 @@ public AffineTransform getNormalizingTransform() {
* Creates a new SurfaceData that will be associated with the given
* CGLLayer.
*/
aghaisas marked this conversation as resolved.
Show resolved Hide resolved
public abstract SurfaceData createSurfaceData(CGLLayer layer);
public abstract SurfaceData createSurfaceData(CFRetainedResource layer);

@Override
public final boolean isTranslucencyCapable() {
Expand Down
72 changes: 69 additions & 3 deletions src/java.desktop/macosx/classes/sun/awt/CGraphicsDevice.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -37,6 +37,8 @@
import java.util.Objects;

import sun.java2d.SunGraphicsEnvironment;
import sun.java2d.MacOSFlags;
import sun.java2d.metal.MTLGraphicsConfig;
import sun.java2d.opengl.CGLGraphicsConfig;

import static java.awt.peer.ComponentPeer.SET_BOUNDS;
Expand All @@ -54,7 +56,10 @@ public final class CGraphicsDevice extends GraphicsDevice
private volatile Rectangle bounds;
private volatile int scale;

private final GraphicsConfiguration config;
private GraphicsConfiguration config;
private static boolean metalPipelineEnabled = false;
private static boolean oglPipelineEnabled = false;


private static AWTPermission fullScreenExclusivePermission;

Expand All @@ -63,7 +68,64 @@ public final class CGraphicsDevice extends GraphicsDevice

public CGraphicsDevice(final int displayID) {
this.displayID = displayID;
config = CGLGraphicsConfig.getConfig(this);

if (MacOSFlags.isMetalEnabled()) {
// Try to create MTLGraphicsConfig, if it fails,
// try to create CGLGraphicsConfig as a fallback
this.config = MTLGraphicsConfig.getConfig(this, displayID);

if (this.config != null) {
metalPipelineEnabled = true;
} else {
// Try falling back to OpenGL pipeline
if (MacOSFlags.isMetalVerbose()) {
System.out.println("Metal rendering pipeline" +
" initialization failed,using OpenGL" +
" rendering pipeline");
}

this.config = CGLGraphicsConfig.getConfig(this);

if (this.config != null) {
oglPipelineEnabled = true;
}
}
} else {
// Try to create CGLGraphicsConfig, if it fails,
// try to create MTLGraphicsConfig as a fallback
this.config = CGLGraphicsConfig.getConfig(this);

if (this.config != null) {
oglPipelineEnabled = true;
} else {
// Try falling back to Metal pipeline
if (MacOSFlags.isOGLVerbose()) {
System.out.println("OpenGL rendering pipeline" +
" initialization failed,using Metal" +
" rendering pipeline");
}

this.config = MTLGraphicsConfig.getConfig(this, displayID);

if (this.config != null) {
metalPipelineEnabled = true;
}
}
}

if (!metalPipelineEnabled && !oglPipelineEnabled) {
// This indicates fallback to other rendering pipeline also failed.
// Should never reach here
throw new InternalError("Error - unable to initialize any" +
" rendering pipeline.");
}

if (metalPipelineEnabled && MacOSFlags.isMetalVerbose()) {
System.out.println("Metal pipeline enabled on screen " + displayID);
} else if (oglPipelineEnabled && MacOSFlags.isOGLVerbose()) {
System.out.println("OpenGL pipeline enabled on screen " + displayID);
}

// initializes default device state, might be redundant step since we
// call "displayChanged()" later anyway, but we do not want to leave the
// device in an inconsistent state after construction
Expand Down Expand Up @@ -265,6 +327,10 @@ public DisplayMode[] getDisplayModes() {
return nativeGetDisplayModes(displayID);
}

public static boolean usingMetalPipeline() {
return metalPipelineEnabled;
}

private void initScaleFactor() {
if (SunGraphicsEnvironment.isUIScaleEnabled()) {
double debugScale = SunGraphicsEnvironment.getDebugScale();
Expand Down