src/share/classes/sun/java2d/pipe/hw/AccelDeviceEventNotifier.java

Print this page


   1 /*
   2  * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.java2d.pipe.hw;
  27 
  28 import java.util.Collections;
  29 import java.util.HashMap;
  30 import java.util.Iterator;
  31 import java.util.Map;
  32 import java.util.Set;
  33 import javax.tools.annotation.GenerateNativeHeader;
  34 
  35 import javax.tools.annotation.GenerateNativeHeader;
  36 
  37 /**
  38  * This class is used to notify listeners about accelerated device's
  39  * events such as device reset or dispose that are about to occur.
  40  */
  41 /* No native methods here, but the constants are needed in the supporting JNI code */
  42 @GenerateNativeHeader
  43 public class AccelDeviceEventNotifier {
  44 
  45     private static AccelDeviceEventNotifier theInstance;
  46 
  47     /**
  48      * A device is about to be reset. The listeners have to release all
  49      * resources associated with the device which are required for the device
  50      * to be reset.
  51      */
  52     public static final int DEVICE_RESET = 0;
  53 
  54     /**
  55      * A device is about to be disposed. The listeners have to release all
  56      * resources associated with the device.
  57      */
  58     public static final int DEVICE_DISPOSED = 1;
  59 
  60     private final Map<AccelDeviceEventListener, Integer> listeners;
  61 
  62     private AccelDeviceEventNotifier() {
  63         listeners = Collections.synchronizedMap(
  64             new HashMap<AccelDeviceEventListener, Integer>(1));
  65     }
  66 
  67     /**
  68      * Returns a singleton of AccelDeviceEventNotifier if it exists. If the
  69      * passed boolean is false and singleton doesn't exist yet, null is
  70      * returned. If the passed boolean is {@code true} and singleton doesn't
  71      * exist it will be created and returned.
  72      *
  73      * @param create whether to create a singleton instance if doesn't yet
  74      * exist
  75      * @return a singleton instance or null
  76      */
  77     private static synchronized
  78         AccelDeviceEventNotifier getInstance(boolean create)


   1 /*
   2  * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.java2d.pipe.hw;
  27 
  28 import java.util.Collections;
  29 import java.util.HashMap;
  30 import java.util.Iterator;
  31 import java.util.Map;
  32 import java.util.Set;
  33 import java.lang.annotation.Native;
  34 

  35 
  36 /**
  37  * This class is used to notify listeners about accelerated device's
  38  * events such as device reset or dispose that are about to occur.
  39  */


  40 public class AccelDeviceEventNotifier {
  41 
  42     private static AccelDeviceEventNotifier theInstance;
  43 
  44     /**
  45      * A device is about to be reset. The listeners have to release all
  46      * resources associated with the device which are required for the device
  47      * to be reset.
  48      */
  49     @Native public static final int DEVICE_RESET = 0;
  50 
  51     /**
  52      * A device is about to be disposed. The listeners have to release all
  53      * resources associated with the device.
  54      */
  55     @Native public static final int DEVICE_DISPOSED = 1;
  56 
  57     private final Map<AccelDeviceEventListener, Integer> listeners;
  58 
  59     private AccelDeviceEventNotifier() {
  60         listeners = Collections.synchronizedMap(
  61             new HashMap<AccelDeviceEventListener, Integer>(1));
  62     }
  63 
  64     /**
  65      * Returns a singleton of AccelDeviceEventNotifier if it exists. If the
  66      * passed boolean is false and singleton doesn't exist yet, null is
  67      * returned. If the passed boolean is {@code true} and singleton doesn't
  68      * exist it will be created and returned.
  69      *
  70      * @param create whether to create a singleton instance if doesn't yet
  71      * exist
  72      * @return a singleton instance or null
  73      */
  74     private static synchronized
  75         AccelDeviceEventNotifier getInstance(boolean create)