--- old/glass/glass-lib-lens/build.xml 2013-02-28 10:19:40.939618172 -0500 +++ new/glass/glass-lib-lens/build.xml 2013-02-28 10:19:40.144620073 -0500 @@ -87,7 +87,6 @@ - --- old/glass/glass-lib-lens/src/LensApplication.c 2013-02-28 10:19:41.851618310 -0500 +++ new/glass/glass-lib-lens/src/LensApplication.c 2013-02-28 10:19:41.716636276 -0500 @@ -184,7 +184,11 @@ JNIEXPORT jboolean JNICALL Java_com_sun_glass_ui_lens_LensApplication__1initialize (JNIEnv *env, jclass jApplicationClass) { - return lens_wm_initialize(env); + jboolean ret = lens_wm_initialize(env); + if (ret) { + glass_screen_notifySettingsChanged(env); + } + return ret; } JNIEXPORT void JNICALL Java_com_sun_glass_ui_lens_LensApplication_registerApplication --- old/glass/glass-lib-lens/src/LensCommon.h 2013-02-28 10:19:42.447618290 -0500 +++ new/glass/glass-lib-lens/src/LensCommon.h 2013-02-28 10:19:42.136620255 -0500 @@ -268,6 +268,12 @@ jint *pixels); +/** + * Call to notify Java of a intial/changed Screen configuration. + * @param env the JNI environment + */ +void glass_screen_notifySettingsChanged(JNIEnv *env); + /////////////Aplication /** --- old/glass/glass-lib-lens/src/LensScreen.c 2013-02-28 10:19:43.071618072 -0500 +++ new/glass/glass-lib-lens/src/LensScreen.c 2013-02-28 10:19:42.927635379 -0500 @@ -24,67 +24,79 @@ */ #include "LensCommon.h" -#include "com_sun_glass_ui_lens_LensScreen.h" -/* - * Class: com_sun_glass_ui_lens_LensScreen - * Method: _getMainScreen - * Signature: (Lcom/sun/glass/ui/Screen;)Lcom/sun/glass/ui/Screen; - */ -JNIEXPORT jobject JNICALL Java_com_sun_glass_ui_lens_LensScreen__1getMainScreen -(JNIEnv *env, jclass clazz, jobject jscreen) { - NativeScreen screen; - jclass jScreenClass = (*env)->FindClass(env, "com/sun/glass/ui/Screen"); - - screen = glass_screen_getMainScreen(); - GLASS_LOG_FINE("screen=%p", screen); - - if (jscreen != NULL) { - (*env)->SetLongField(env, jscreen, - (*env)->GetFieldID(env, jScreenClass, "ptr", "J"), - ptr_to_jlong(screen)); - (*env)->SetIntField(env, jscreen, - (*env)->GetFieldID(env, jScreenClass, "depth", "I"), - screen->depth); - (*env)->SetIntField(env, jscreen, - (*env)->GetFieldID(env, jScreenClass, "x", "I"), - screen->x); - (*env)->SetIntField(env, jscreen, - (*env)->GetFieldID(env, jScreenClass, "y", "I"), - screen->y); - (*env)->SetIntField(env, jscreen, - (*env)->GetFieldID(env, jScreenClass, "width", "I"), - screen->width); - (*env)->SetIntField(env, jscreen, - (*env)->GetFieldID(env, jScreenClass, "height", "I"), - screen->height); - - (*env)->SetIntField(env, jscreen, - (*env)->GetFieldID(env, jScreenClass, "visibleX", "I"), - screen->visibleX); - (*env)->SetIntField(env, jscreen, - (*env)->GetFieldID(env, jScreenClass, "visibleY", "I"), - screen->visibleY); - (*env)->SetIntField(env, jscreen, - (*env)->GetFieldID(env, jScreenClass, "visibleWidth", "I"), - screen->visibleWidth); - (*env)->SetIntField(env, jscreen, - (*env)->GetFieldID(env, jScreenClass, "visibleHeight", "I"), - screen->visibleHeight); - - (*env)->SetFloatField(env, jscreen, - (*env)->GetFieldID(env, jScreenClass, "scale", "F"), 1.0); - (*env)->SetIntField(env, jscreen, - (*env)->GetFieldID(env, jScreenClass, "resolutionX", "I"), - screen->resolutionX); - (*env)->SetIntField(env, jscreen, - (*env)->GetFieldID(env, jScreenClass, "resolutionY", "I"), - screen->resolutionY); - GLASS_CHECK_EXCEPTION(env); - } else { - GLASS_LOG_SEVERE("Failed to allocate screen"); +static jobject createJavaScreen(JNIEnv *env, NativeScreen screen) { + // already allocated globally, leaving here only for reference + //jclass jScreenClass = (*env)->FindClass(env, "com/sun/glass/ui/Screen"); + + jmethodID screenInit = (*env)->GetMethodID(env, jScreenClass, + "", + "(JIIIIIIIIIIIF)V"); + GLASS_CHECK_EXCEPTION(env); + + if (!screenInit) { + glass_throw_exception_by_name(env, glass_RuntimeException,"missing Screen()"); + return 0; + } + + jobject newScreen = (jobject)(*env)->NewObject(env, jScreenClass, screenInit, + ptr_to_jlong(screen), + + screen->depth, + + screen->x, + screen->y, + screen->width, + screen->height, + + screen->visibleX, + screen->visibleY, + screen->visibleWidth, + screen->visibleHeight, + + screen->resolutionX, + screen->resolutionY, + + 1.0f); + GLASS_CHECK_EXCEPTION(env); + + return newScreen; +} + +void glass_screen_notifySettingsChanged(JNIEnv *env) { + // Update the Java notion of our Screens[] + + // create our one Screen object + jobject defScreen = createJavaScreen(env, glass_screen_getMainScreen()); + if (defScreen == NULL) { + glass_throw_exception_by_name(env, glass_RuntimeException,"failed to create default Screen"); + return; + } + + // create our Screen[] + // with only one element because we know that is all we currently support + int screenCount = 1; + jobjectArray screenArray = (*env)->NewObjectArray(env, + screenCount, + jScreenClass, + NULL); + (*env)->SetObjectArrayElement(env, screenArray, 0, defScreen); + + // call Screen.notifySettingsChanged() + // lets not cache this id, not called often enough. + jmethodID notifySettingsChanged = (*env)->GetStaticMethodID(env, jScreenClass, + "notifySettingsChanged", "([Lcom/sun/glass/ui/Screen;)V"); + GLASS_CHECK_EXCEPTION(env); + + if (!notifySettingsChanged) { + glass_throw_exception_by_name(env, glass_RuntimeException,"missing Screen.notifySettingsChanged"); + return; } - return jscreen; + (*env)->CallVoidMethod(env, jScreenClass, notifySettingsChanged, + screenArray, + defScreen); + + GLASS_CHECK_EXCEPTION(env); } --- old/glass/glass/src/com/sun/glass/ui/Application.java 2013-02-28 10:19:43.571618283 -0500 +++ new/glass/glass/src/com/sun/glass/ui/Application.java 2013-02-28 10:19:43.402976519 -0500 @@ -132,7 +132,7 @@ protected Application() { } - + // May be called on any thread. public static void run(final Runnable launchable) { if (application != null) { @@ -544,6 +544,7 @@ public abstract Robot createRobot(); protected abstract double staticScreen_getVideoRefreshPeriod(); + //NOTE: these can be removed when all the platforms are fixed protected abstract Screen staticScreen_getDeepestScreen(); protected abstract Screen staticScreen_getMainScreen(); protected abstract Screen staticScreen_getScreenForLocation(int x, int y); --- old/glass/glass/src/com/sun/glass/ui/Screen.java 2013-02-28 10:19:44.015618711 -0500 +++ new/glass/glass/src/com/sun/glass/ui/Screen.java 2013-02-28 10:19:43.882241275 -0500 @@ -24,9 +24,16 @@ */ package com.sun.glass.ui; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; public final class Screen { + + // the list of attached screens provided by native. + // screens[0] is the default/main Screen + private static Screen[] screens = null; public static class EventHandler { public void handleSettingsChanged() { @@ -34,160 +41,219 @@ } public static double getVideoRefreshPeriod() { - Application.checkEventThread(); return Application.GetApplication().staticScreen_getVideoRefreshPeriod(); } public static Screen getDeepestScreen() { - Application.checkEventThread(); - return Application.GetApplication().staticScreen_getDeepestScreen(); + // a copy of the list in case it changes on another thread + final Screen[] list = _getScreens(); + + Screen deepest = list[0]; + int i; + for(i=1;i= s.x && x <= s.x + s.width) && + (y >= s.y && y <= s.y + s.height)) { + return s; + } + } + return null; } // used by Window.notifyMoveToAnotherScreen static Screen getScreenForPtr(long screenPtr) { - Application.checkEventThread(); - return Application.GetApplication().staticScreen_getScreenForPtr(screenPtr); + // a copy of the list in case it changes on another thread + final Screen[] list = _getScreens(); + + int i; + for(i=0;i getScreens() { - //Application.checkEventThread(); // Quantum - return Application.GetApplication().staticScreen_getScreens(); + // a copy of the list in case it changes on another thread + final Screen[] list = _getScreens(); + return Collections.unmodifiableList(Arrays.asList(list)); } private static EventHandler eventHandler; - private long ptr; + private final long ptr; - private int depth; + private final int depth; - private int x; - private int y; - private int width; - private int height; + private final int x; + private final int y; + private final int width; + private final int height; - private int visibleX; - private int visibleY; - private int visibleWidth; - private int visibleHeight; + private final int visibleX; + private final int visibleY; + private final int visibleWidth; + private final int visibleHeight; - private int resolutionX; - private int resolutionY; + private final int resolutionX; + private final int resolutionY; - private float scale; + private final float scale; - public Screen() { - //Application.checkEventThread(); // Quantum - this.ptr = 0L; + protected Screen( + long nativePtr, + + int depth, + int x, + int y, + int width, + int height, + + int visibleX, + int visibleY, + int visibleWidth, + int visibleHeight, + + int resolutionX, + int resolutionY, - this.depth = 0; + float scale + ) { + this.ptr = nativePtr; - this.x = 0; - this.y = 0; - this.width = 0; - this.height = 0; + this.depth = depth; - this.visibleX = 0; - this.visibleY = 0; - this.visibleWidth = 0; - this.visibleHeight = 0; + this.x = x; + this.y = y; + this.width = width; + this.height = height; - this.resolutionX = 0; - this.resolutionY = 0; + this.visibleX = visibleX; + this.visibleY = visibleY; + this.visibleWidth = visibleWidth; + this.visibleHeight = visibleHeight; - this.scale = 0.0f; + this.resolutionX = resolutionX; + this.resolutionY = resolutionY; + + this.scale = scale; + } + + //NOTE: THIS WOULD GO AWAY + public Screen() { + this( 0L, + 0, + 0,0,0,0, + 0,0,0,0, + 0,0, + 0.0f); } public int getDepth() { - Application.checkEventThread(); return this.depth; } public int getX() { - Application.checkEventThread(); return this.x; } public int getY() { - Application.checkEventThread(); return this.y; } public int getWidth() { - Application.checkEventThread(); return this.width; } public int getHeight() { - Application.checkEventThread(); return this.height; } public int getVisibleX() { - Application.checkEventThread(); return this.visibleX; } public int getVisibleY() { - Application.checkEventThread(); return this.visibleY; } public int getVisibleWidth() { - Application.checkEventThread(); return this.visibleWidth; } public int getVisibleHeight() { - Application.checkEventThread(); return this.visibleHeight; } public int getResolutionX() { - Application.checkEventThread(); return this.resolutionX; } public int getResolutionY() { - Application.checkEventThread(); return this.resolutionY; } public float getScale() { - Application.checkEventThread(); return this.scale; } public long getNativeScreen() { - //Application.checkEventThread(); // Quantum return this.ptr; } public static EventHandler getEventHandler() { - Application.checkEventThread(); return eventHandler; } public static void setEventHandler(EventHandler eh) { - Application.checkEventThread(); eventHandler = eh; } - private static void notifySettingsChanged() { + /** + * Called from native to change the Screen definitions. Should be either called + * prior to the creation of the main Application.runLoop or on the + * event thread. + * The newScreen[0] instance will be the default screen + * @param newScreens The Screens present + */ + private static void notifySettingsChanged(Screen[] newScreens) { + + screens = newScreens; + if (eventHandler != null) { eventHandler.handleSettingsChanged(); } } - + + private static Screen[] _getScreens() { + final Screen[] ss = screens; + if (ss == null) { + throw new RuntimeException("Internal graphics not initialized yet"); + } + return ss; + } + @Override public String toString() { return "Screen:"+"\n"+ " ptr:"+getNativeScreen()+"\n"+ --- old/glass/glass/src/com/sun/glass/ui/lens/LensApplication.java 2013-02-28 10:19:44.519618379 -0500 +++ new/glass/glass/src/com/sun/glass/ui/lens/LensApplication.java 2013-02-28 10:19:44.373826377 -0500 @@ -1442,29 +1442,31 @@ return new LensRobot(); } + //NOTE: this block of staticScreen* should go away... + // is is only called from *Screen and LensScreen is now gone @Override protected Screen staticScreen_getDeepestScreen() { - return LensScreen.getDeepestScreen_impl(); + throw new RuntimeException("unused"); } @Override protected Screen staticScreen_getMainScreen() { - return LensScreen.getMainScreen_impl(); + throw new RuntimeException("unused"); } @Override protected Screen staticScreen_getScreenForLocation(int x, int y) { - return LensScreen.getScreenForLocation_impl(x, y); + throw new RuntimeException("unused"); } @Override protected Screen staticScreen_getScreenForPtr(long screenPtr) { - return LensScreen.getScreenForPtr_impl(screenPtr); + throw new RuntimeException("unused"); } @Override protected List staticScreen_getScreens() { - return LensScreen.getScreens_impl(); + throw new RuntimeException("unused"); } @Override protected double staticScreen_getVideoRefreshPeriod() { --- old/glass/glass/src/com/sun/glass/ui/lens/LensScreen.java 2013-02-28 10:19:44.967618334 -0500 +++ /dev/null 2013-02-21 11:41:44.011620085 -0500 @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2012, 2013, 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 com.sun.glass.ui.lens; - -import com.sun.glass.ui.Screen; -import java.util.Vector; - -final class LensScreen { - - private static Screen defaultScreen; - - protected LensScreen() { - super(); - } - - native private static Screen _getMainScreen(Screen screen); - - static Screen getDeepestScreen_impl() { - //No support for multiply screens, return the default - return getMainScreen_impl(); - } - - static Screen getMainScreen_impl() { - if (defaultScreen == null) { - defaultScreen = _getMainScreen(new Screen()); - } - - return defaultScreen; - } - - static Screen getScreenForLocation_impl(int x, int y) { - - //No support for multiply screens, return the default - return getMainScreen_impl(); - } - - static Screen getScreenForPtr_impl(long screenPtr) { - //No support for multiply screens, return the default - return getMainScreen_impl(); - } - - static Vector getScreens_impl() { - //only main screen supported - Vector screens = new Vector(); - screens.add(getMainScreen_impl()); - return screens; - } - -}