Skip to content
Permalink
Browse files
8260931: Implement JEP 382: New macOS Rendering Pipeline
Co-authored-by: Jayathirth D V <jdv@openjdk.org>
Co-authored-by: Alexey Ushakov <avu@openjdk.org>
Co-authored-by: Artem Bochkarev <abochkarev@openjdk.org>
Co-authored-by: Prasanta Sadhukhan <psadhukhan@openjdk.org>
Co-authored-by: Denis Konoplev <dkonoplev@openjdk.org>
Co-authored-by: Phil Race <prr@openjdk.org>
Co-authored-by: Kevin Rushforth <kcr@openjdk.org>
Co-authored-by: Magnus Ihse Bursie <ihse@openjdk.org>
Co-authored-by: Ajit Ghaisas <aghaisas@openjdk.org>
Reviewed-by: ihse, avu, kcr, gziemski, prr, kizune, jdv, psadhukhan, serb
  • Loading branch information
9 people committed Mar 15, 2021
1 parent 0638303 commit 8afec70c283ee549795996031e3a53a3212bf35a
Showing with 17,610 additions and 39 deletions.
  1. +2 −0 make/autoconf/spec.gmk.in
  2. +27 −1 make/autoconf/toolchain.m4
  3. +2 −1 make/modules/java.desktop/Lib.gmk
  4. +29 −1 make/modules/java.desktop/lib/Awt2dLibraries.gmk
  5. +3 −3 src/java.desktop/macosx/classes/sun/awt/CGraphicsConfig.java
  6. +69 −3 src/java.desktop/macosx/classes/sun/awt/CGraphicsDevice.java
  7. +165 −0 src/java.desktop/macosx/classes/sun/java2d/MacOSFlags.java
  8. +6 −3 src/java.desktop/macosx/classes/sun/java2d/MacosxSurfaceManagerFactory.java
  9. +905 −0 src/java.desktop/macosx/classes/sun/java2d/metal/MTLBlitLoops.java
  10. +117 −0 src/java.desktop/macosx/classes/sun/java2d/metal/MTLBufImgOps.java
  11. +154 −0 src/java.desktop/macosx/classes/sun/java2d/metal/MTLContext.java
  12. +114 −0 src/java.desktop/macosx/classes/sun/java2d/metal/MTLDrawImage.java
  13. +401 −0 src/java.desktop/macosx/classes/sun/java2d/metal/MTLGraphicsConfig.java
  14. +154 −0 src/java.desktop/macosx/classes/sun/java2d/metal/MTLLayer.java
  15. +72 −0 src/java.desktop/macosx/classes/sun/java2d/metal/MTLMaskBlit.java
  16. +85 −0 src/java.desktop/macosx/classes/sun/java2d/metal/MTLMaskFill.java
  17. +199 −0 src/java.desktop/macosx/classes/sun/java2d/metal/MTLPaints.java
  18. +254 −0 src/java.desktop/macosx/classes/sun/java2d/metal/MTLRenderQueue.java
  19. +224 −0 src/java.desktop/macosx/classes/sun/java2d/metal/MTLRenderer.java
  20. +642 −0 src/java.desktop/macosx/classes/sun/java2d/metal/MTLSurfaceData.java
  21. +85 −0 src/java.desktop/macosx/classes/sun/java2d/metal/MTLSurfaceDataProxy.java
  22. +72 −0 src/java.desktop/macosx/classes/sun/java2d/metal/MTLTextRenderer.java
  23. +91 −0 src/java.desktop/macosx/classes/sun/java2d/metal/MTLVolatileSurfaceManager.java
  24. +4 −3 src/java.desktop/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java
  25. +6 −2 src/java.desktop/macosx/classes/sun/lwawt/LWComponentPeer.java
  26. +31 −7 src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java
  27. +19 −6 src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformView.java
  28. +19 −1 src/java.desktop/macosx/classes/sun/lwawt/macosx/CWarningWindow.java
  29. +8 −3 src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
  30. +7 −5 src/java.desktop/macosx/native/libawt_lwawt/awt/AWTSurfaceLayers.m
  31. +101 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/EncoderManager.h
  32. +465 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/EncoderManager.m
  33. +78 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLBlitLoops.h
  34. +822 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLBlitLoops.m
  35. +74 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLBufImgOps.h
  36. +223 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLBufImgOps.m
  37. +86 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLClip.h
  38. +372 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLClip.m
  39. +64 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLComposite.h
  40. +192 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLComposite.m
  41. +244 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.h
  42. +492 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.m
  43. +99 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGlyphCache.h
  44. +364 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGlyphCache.m
  45. +56 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.h
  46. +229 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.m
  47. +75 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.h
  48. +284 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.m
  49. +36 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLMaskBlit.h
  50. +70 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLMaskBlit.m
  51. +36 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLMaskFill.h
  52. +114 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLMaskFill.m
  53. +142 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLPaints.h
  54. +993 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLPaints.m
  55. +77 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLPipelineStatesStorage.h
  56. +325 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLPipelineStatesStorage.m
  57. +106 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderQueue.h
  58. +956 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderQueue.m
  59. +76 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderer.h
  60. +961 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderer.m
  61. +45 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSamplerManager.h
  62. +90 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSamplerManager.m
  63. +42 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLStencilManager.h
  64. +62 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLStencilManager.m
  65. +48 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceData.h
  66. +390 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceData.m
  67. +150 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceDataBase.h
  68. +59 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTextRenderer.h
  69. +777 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTextRenderer.m
  70. +74 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTexturePool.h
  71. +443 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTexurePool.m
  72. +48 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTransform.h
  73. +99 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTransform.m
  74. +33 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLUtils.h
  75. +84 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLUtils.m
  76. +86 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLVertexCache.h
  77. +316 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLVertexCache.m
  78. +45 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/RenderOptions.h
  79. +159 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/common.h
  80. +821 −0 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/shaders.metal
  81. +3 −0 src/java.desktop/share/native/libawt/java2d/loops/GraphicsPrimitiveMgr.h
  82. +79 −0 test/jdk/performance/client/RenderPerfTest/Makefile
  83. +34 −0 test/jdk/performance/client/RenderPerfTest/README
  84. +86 −0 test/jdk/performance/client/RenderPerfTest/build.xml
  85. BIN test/jdk/performance/client/RenderPerfTest/resources/renderperf/images/duke.png
  86. +373 −0 test/jdk/performance/client/RenderPerfTest/src/renderperf/RenderPerfLCDTest.java
  87. +986 −0 test/jdk/performance/client/RenderPerfTest/src/renderperf/RenderPerfTest.java
@@ -576,6 +576,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)
@@ -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
@@ -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
@@ -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
@@ -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))
@@ -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, \
@@ -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
@@ -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 \
@@ -862,6 +865,7 @@ ifeq ($(call isTargetOs, macosx), true)
-framework AudioToolbox \
-framework Carbon \
-framework Cocoa \
-framework Metal \
-framework Security \
-framework ExceptionHandling \
-framework JavaRuntimeSupport \
@@ -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

$(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, \
@@ -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)

@@ -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
@@ -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 {
@@ -80,7 +80,7 @@ public AffineTransform getNormalizingTransform() {
* Creates a new SurfaceData that will be associated with the given
* CGLLayer.
*/
public abstract SurfaceData createSurfaceData(CGLLayer layer);
public abstract SurfaceData createSurfaceData(CFRetainedResource layer);

@Override
public final boolean isTranslucencyCapable() {
@@ -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
@@ -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;
@@ -54,7 +56,10 @@
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;

@@ -63,7 +68,64 @@

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
@@ -265,6 +327,10 @@ public DisplayMode getDisplayMode() {
return nativeGetDisplayModes(displayID);
}

public static boolean usingMetalPipeline() {
return metalPipelineEnabled;
}

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

1 comment on commit 8afec70

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 8afec70 Mar 15, 2021

Please sign in to comment.