Skip to content
Permalink
Browse files
8226384: Implement a better logic to switch between OpenGL and Metal …
…pipeline

Reviewed-by: prr
  • Loading branch information
jayathirthrao committed May 10, 2021
1 parent 1603ca2 commit 53db2a0acd4e208fb5cfb7108206ec667c7c4131
@@ -28,14 +28,11 @@
import sun.java2d.NullSurfaceData;
import sun.java2d.SurfaceData;
import sun.lwawt.LWWindowPeer;
import sun.lwawt.macosx.CFRetainedResource;

import sun.lwawt.macosx.CFLayer;
import java.awt.GraphicsConfiguration;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Transparency;

public class MTLLayer extends CFRetainedResource {
public class MTLLayer extends CFLayer {

private native long nativeCreateLayer();
private static native void nativeSetScale(long layerPtr, double scale);
@@ -45,42 +42,15 @@
private static native void validate(long layerPtr, MTLSurfaceData mtlsd);
private static native void blitTexture(long layerPtr);

private LWWindowPeer peer;
private int scale = 1;

private SurfaceData surfaceData; // represents intermediate buffer (texture)

public MTLLayer(LWWindowPeer peer) {
super(0, true);

setPtr(nativeCreateLayer());
this.peer = peer;
}

public long getPointer() {
return ptr;
}

public Rectangle getBounds() {
return peer.getBounds();
}

public GraphicsConfiguration getGraphicsConfiguration() {
return peer.getGraphicsConfiguration();
}

public boolean isOpaque() {
return !peer.isTranslucent();
}

public int getTransparency() {
return isOpaque() ? Transparency.OPAQUE : Transparency.TRANSLUCENT;
}

public Object getDestination() {
return peer.getTarget();
}

public SurfaceData replaceSurfaceData() {
if (getBounds().isEmpty()) {
surfaceData = NullSurfaceData.theInstance;
@@ -105,10 +75,6 @@ public SurfaceData replaceSurfaceData() {
return surfaceData;
}

public SurfaceData getSurfaceData() {
return surfaceData;
}

public void validate(final MTLSurfaceData mtlsd) {
MTLRenderQueue rq = MTLRenderQueue.getInstance();
rq.lock();
@@ -26,58 +26,28 @@
package sun.java2d.opengl;

import java.awt.GraphicsConfiguration;
import java.awt.Rectangle;
import java.awt.Transparency;

import sun.awt.CGraphicsConfig;
import sun.java2d.NullSurfaceData;
import sun.java2d.SurfaceData;
import sun.lwawt.LWWindowPeer;
import sun.lwawt.macosx.CFRetainedResource;
import sun.java2d.SurfaceData;
import sun.lwawt.macosx.CFLayer;

public class CGLLayer extends CFRetainedResource {
public class CGLLayer extends CFLayer {

private native long nativeCreateLayer();
private static native void nativeSetScale(long layerPtr, double scale);
private static native void validate(long layerPtr, CGLSurfaceData cglsd);
private static native void blitTexture(long layerPtr);

private LWWindowPeer peer;
private int scale = 1;

private SurfaceData surfaceData; // represents intermediate buffer (texture)

public CGLLayer(LWWindowPeer peer) {
super(0, true);

setPtr(nativeCreateLayer());
this.peer = peer;
}

public long getPointer() {
return ptr;
}

public Rectangle getBounds() {
return peer.getBounds();
}

public GraphicsConfiguration getGraphicsConfiguration() {
return peer.getGraphicsConfiguration();
}

public boolean isOpaque() {
return !peer.isTranslucent();
}

public int getTransparency() {
return isOpaque() ? Transparency.OPAQUE : Transparency.TRANSLUCENT;
}

public Object getDestination() {
return peer.getTarget();
}

public SurfaceData replaceSurfaceData() {
if (getBounds().isEmpty()) {
surfaceData = NullSurfaceData.theInstance;
@@ -98,10 +68,6 @@ public SurfaceData replaceSurfaceData() {
return surfaceData;
}

public SurfaceData getSurfaceData() {
return surfaceData;
}

public void validate(final CGLSurfaceData cglsd) {
OGLRenderQueue rq = OGLRenderQueue.getInstance();
rq.lock();
@@ -0,0 +1,80 @@
/*
* Copyright (c) 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
* 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.lwawt.macosx;

import sun.java2d.SurfaceData;
import sun.java2d.NullSurfaceData;
import java.awt.GraphicsConfiguration;
import java.awt.Rectangle;
import java.awt.Transparency;
import sun.lwawt.LWWindowPeer;

/**
* Common layer class between OpenGl and Metal.
*/
public abstract class CFLayer extends CFRetainedResource {
protected SurfaceData surfaceData; // represents intermediate buffer (texture)
protected LWWindowPeer peer;

protected CFLayer(long ptr, boolean disposeOnAppKitThread) {
super(ptr, disposeOnAppKitThread);
}

public abstract SurfaceData replaceSurfaceData();

@Override
public void dispose() {
super.dispose();
}

public long getPointer() {
return ptr;
}

public SurfaceData getSurfaceData() {
return surfaceData;
}

public Rectangle getBounds() {
return peer.getBounds();
}

public GraphicsConfiguration getGraphicsConfiguration() {
return peer.getGraphicsConfiguration();
}

public boolean isOpaque() {
return !peer.isTranslucent();
}

public int getTransparency() {
return isOpaque() ? Transparency.OPAQUE : Transparency.TRANSLUCENT;
}

public Object getDestination() {
return peer.getTarget();
}
}
@@ -32,9 +32,9 @@
import sun.java2d.SurfaceData;
import sun.java2d.metal.MTLLayer;
import sun.java2d.opengl.CGLLayer;
import sun.lwawt.macosx.CFLayer;
import sun.lwawt.LWWindowPeer;
import sun.lwawt.PlatformWindow;
import sun.lwawt.macosx.CFRetainedResource;
import sun.util.logging.PlatformLogger;


@@ -46,7 +46,7 @@
private static final PlatformLogger focusLogger = PlatformLogger.getLogger(
"sun.lwawt.macosx.focus.CPlatformEmbeddedFrame");

private CFRetainedResource windowLayer;
private CFLayer windowLayer;
private LWWindowPeer peer;
private CEmbeddedFrame target;

@@ -71,20 +71,12 @@ public LWWindowPeer getPeer() {

@Override
public long getLayerPtr() {
if (CGraphicsDevice.usingMetalPipeline()) {
return ((MTLLayer)windowLayer).getPointer();
} else {
return ((CGLLayer)windowLayer).getPointer();
}
return windowLayer.getPointer();
}

@Override
public void dispose() {
if (CGraphicsDevice.usingMetalPipeline()) {
((MTLLayer)windowLayer).dispose();
} else {
((CGLLayer)windowLayer).dispose();
}
windowLayer.dispose();
}

@Override
@@ -115,20 +107,12 @@ public FontMetrics getFontMetrics(Font f) {

@Override
public SurfaceData getScreenSurface() {
if ( CGraphicsDevice.usingMetalPipeline()) {
return ((MTLLayer)windowLayer).getSurfaceData();
} else {
return ((CGLLayer)windowLayer).getSurfaceData();
}
return windowLayer.getSurfaceData();
}

@Override
public SurfaceData replaceSurfaceData() {
if (CGraphicsDevice.usingMetalPipeline()) {
return ((MTLLayer)windowLayer).replaceSurfaceData();
} else {
return ((CGLLayer)windowLayer).replaceSurfaceData();
}
return windowLayer.replaceSurfaceData();
}

@Override
@@ -41,6 +41,7 @@

import sun.java2d.SurfaceData;
import sun.java2d.opengl.CGLLayer;
import sun.lwawt.macosx.CFLayer;

public class CPlatformView extends CFRetainedResource {
private native long nativeCreateView(int x, int y, int width, int height, long windowLayerPtr);
@@ -51,7 +52,7 @@

private LWWindowPeer peer;
private SurfaceData surfaceData;
private CFRetainedResource windowLayer;
private CFLayer windowLayer;
private CPlatformResponder responder;

public CPlatformView() {
@@ -104,10 +105,7 @@ public void setToolTip(String msg) {
// PAINTING METHODS
// ----------------------------------------------------------------------
public SurfaceData replaceSurfaceData() {
surfaceData = (CGraphicsDevice.usingMetalPipeline()) ?
((MTLLayer)windowLayer).replaceSurfaceData() :
((CGLLayer)windowLayer).replaceSurfaceData()
;
surfaceData = windowLayer.replaceSurfaceData();
return surfaceData;
}

@@ -122,9 +120,7 @@ public void dispose() {
}

public long getWindowLayerPtr() {
return CGraphicsDevice.usingMetalPipeline() ?
((MTLLayer)windowLayer).getPointer() :
((CGLLayer)windowLayer).getPointer();
return windowLayer.getPointer();
}

public void setAutoResizable(boolean toResize) {

1 comment on commit 53db2a0

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 53db2a0 May 10, 2021

Please sign in to comment.