< prev index next >

src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformView.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2011, 2019, 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 --- 1,7 ---- /* ! * Copyright (c) 2011, 2016, 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
*** 31,108 **** import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import sun.awt.CGraphicsConfig; import sun.awt.CGraphicsEnvironment; ! import sun.java2d.metal.MetalLayer; ! import sun.java2d.metal.MetalSurfaceData; import sun.lwawt.LWWindowPeer; import sun.java2d.SurfaceData; import sun.java2d.opengl.CGLLayer; import sun.java2d.opengl.CGLSurfaceData; - import sun.java2d.NullSurfaceData; - public class CPlatformView extends CFRetainedResource { private native long nativeCreateView(int x, int y, int width, int height, long windowLayerPtr); private static native void nativeSetAutoResizable(long awtView, boolean toResize); private static native int nativeGetNSViewDisplayID(long awtView); private static native Rectangle2D nativeGetLocationOnScreen(long awtView); private static native boolean nativeIsViewUnderMouse(long ptr); private LWWindowPeer peer; private SurfaceData surfaceData; ! private CGLLayer windowLayer; ! private MetalLayer windowMetalLayer; //hack : will be null if opengl is used ! //private CFRetainedResource windowLayer; ! //Todo: Have to verify how we can replace CGL layer with more common CFRetaindedResource private CPlatformResponder responder; public CPlatformView() { super(0, true); } - public void initialize(LWWindowPeer peer, CPlatformResponder responder) { initializeBase(peer, responder); if (!LWCToolkit.getSunAwtDisableCALayers()) { ! ! if (isMetalSystemProperty()) { ! this.windowMetalLayer = createMetalLayer(); ! } else { ! this.windowLayer = createCGLayer(); ! } } setPtr(nativeCreateView(0, 0, 0, 0, getWindowLayerPtr())); - - // TODO : We should not simply validate view directly here. - //if (isMetalSystemProperty()) { - //windowMetalLayer.validate(getAWTView()); - //} - } - - private boolean isMetalSystemProperty() { - String str = System.getProperty("sun.java2d.metal"); - - if (str != null) { - System.out.println("Property : sun.java2d.metal=" + str); - if (str.equals("true")) { - return true; - } - } - return false; } public CGLLayer createCGLayer() { return new CGLLayer(peer); } ! public MetalLayer createMetalLayer() { ! return new MetalLayer(peer); } protected void initializeBase(LWWindowPeer peer, CPlatformResponder responder) { this.peer = peer; this.responder = responder; } --- 31,83 ---- import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import sun.awt.CGraphicsConfig; import sun.awt.CGraphicsEnvironment; ! import sun.java2d.macos.MacOSFlags; ! import sun.java2d.metal.MTLLayer; ! import sun.java2d.metal.MTLSurfaceData; import sun.lwawt.LWWindowPeer; import sun.java2d.SurfaceData; import sun.java2d.opengl.CGLLayer; import sun.java2d.opengl.CGLSurfaceData; public class CPlatformView extends CFRetainedResource { private native long nativeCreateView(int x, int y, int width, int height, long windowLayerPtr); private static native void nativeSetAutoResizable(long awtView, boolean toResize); private static native int nativeGetNSViewDisplayID(long awtView); private static native Rectangle2D nativeGetLocationOnScreen(long awtView); private static native boolean nativeIsViewUnderMouse(long ptr); private LWWindowPeer peer; private SurfaceData surfaceData; ! private CFRetainedResource windowLayer; private CPlatformResponder responder; public CPlatformView() { super(0, true); } public void initialize(LWWindowPeer peer, CPlatformResponder responder) { initializeBase(peer, responder); if (!LWCToolkit.getSunAwtDisableCALayers()) { ! this.windowLayer = MacOSFlags.isMetalEnabled()? createMTLLayer() : createCGLayer(); } setPtr(nativeCreateView(0, 0, 0, 0, getWindowLayerPtr())); } public CGLLayer createCGLayer() { return new CGLLayer(peer); } ! public MTLLayer createMTLLayer() { ! return new MTLLayer(peer); } + + protected void initializeBase(LWWindowPeer peer, CPlatformResponder responder) { this.peer = peer; this.responder = responder; }
*** 118,132 **** * All coordinates passed to the method should be based on the origin being in the bottom-left corner (standard * Cocoa coordinates). */ public void setBounds(int x, int y, int width, int height) { execute(ptr->CWrapper.NSView.setFrame(ptr, x, y, width, height)); - - // TODO : Check the use case that why below code is added. - //if (windowMetalLayer != null) { - //windowMetalLayer.validate(getAWTView()); - //} } // REMIND: CGLSurfaceData expects top-level's size public Rectangle getBounds() { return peer.getBounds(); --- 93,102 ----
*** 143,166 **** // ---------------------------------------------------------------------- // PAINTING METHODS // ---------------------------------------------------------------------- public SurfaceData replaceSurfaceData() { if (!LWCToolkit.getSunAwtDisableCALayers()) { ! ! if (isMetalSystemProperty()) { ! surfaceData = windowMetalLayer.replaceSurfaceData(); ! ! // TODO : Why we are checking about NullSurfaceData here ! //if (surfaceData != NullSurfaceData.theInstance) { ! //validateSurface(); ! //windowMetalLayer.drawInMetalContext(getAWTView()); ! //} ! ! } else { ! surfaceData = windowLayer.replaceSurfaceData(); ! } ! } else { if (surfaceData == null) { CGraphicsConfig graphicsConfig = (CGraphicsConfig)getGraphicsConfiguration(); surfaceData = graphicsConfig.createSurfaceData(this); } else { --- 113,126 ---- // ---------------------------------------------------------------------- // PAINTING METHODS // ---------------------------------------------------------------------- public SurfaceData replaceSurfaceData() { if (!LWCToolkit.getSunAwtDisableCALayers()) { ! surfaceData = (MacOSFlags.isMetalEnabled()) ? ! ((MTLLayer)windowLayer).replaceSurfaceData() : ! ((CGLLayer)windowLayer).replaceSurfaceData() ! ; } else { if (surfaceData == null) { CGraphicsConfig graphicsConfig = (CGraphicsConfig)getGraphicsConfiguration(); surfaceData = graphicsConfig.createSurfaceData(this); } else {
*** 169,187 **** } return surfaceData; } private void validateSurface() { - if (surfaceData != null) { ! // TODO : Why we are validating with View here ! if (isMetalSystemProperty()) { ! //((MetalSurfaceData)surfaceData).validate(); ! //windowMetalLayer.validate(getAWTView()); ! ((MetalSurfaceData)surfaceData).validate(); } else { ! ((CGLSurfaceData)surfaceData).validate(); } } } public GraphicsConfiguration getGraphicsConfiguration() { --- 129,143 ---- } return surfaceData; } private void validateSurface() { if (surfaceData != null) { ! if (MacOSFlags.isMetalEnabled()) { ! ((MTLSurfaceData) surfaceData).validate(); } else { ! ((CGLSurfaceData) surfaceData).validate(); } } } public GraphicsConfiguration getGraphicsConfiguration() {
*** 193,218 **** } @Override public void dispose() { if (!LWCToolkit.getSunAwtDisableCALayers()) { - if (isMetalSystemProperty()) { - windowMetalLayer.dispose(); - } else { windowLayer.dispose(); } - } super.dispose(); } public long getWindowLayerPtr() { if (!LWCToolkit.getSunAwtDisableCALayers()) { ! if (isMetalSystemProperty()) { ! return windowMetalLayer.getPointer(); ! } else { ! return windowLayer.getPointer(); ! } } else { return 0; } } --- 149,168 ---- } @Override public void dispose() { if (!LWCToolkit.getSunAwtDisableCALayers()) { windowLayer.dispose(); } super.dispose(); } public long getWindowLayerPtr() { if (!LWCToolkit.getSunAwtDisableCALayers()) { ! return MacOSFlags.isMetalEnabled() ? ! ((MTLLayer)windowLayer).getPointer() : ! ((CGLLayer)windowLayer).getPointer(); } else { return 0; } }
< prev index next >