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

Print this page




   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.lwawt.macosx;
  27 
  28 import java.awt.*;
  29 import java.awt.image.VolatileImage;
  30 
  31 import sun.awt.CGraphicsConfig;
  32 import sun.lwawt.LWWindowPeer;
  33 import sun.lwawt.macosx.event.NSEvent;
  34 
  35 import sun.java2d.SurfaceData;
  36 import sun.java2d.opengl.CGLLayer;
  37 import sun.java2d.opengl.CGLSurfaceData;
  38 
  39 public class CPlatformView extends CFRetainedResource {
  40     private native long nativeCreateView(int x, int y, int width, int height, long windowLayerPtr);
  41 
  42     private LWWindowPeer peer;
  43     private SurfaceData surfaceData;
  44     private CGLLayer windowLayer;
  45     private CPlatformResponder responder;
  46 
  47     public CPlatformView() {
  48         super(0, true);
  49     }


  98         } finally {
  99             CWrapper.NSObject.release(screenPtr);
 100         }
 101 
 102         // the move/size notification from the underlying system comes
 103         // but it contains a bounds smaller than the whole screen
 104         // and therefore we need to create the synthetic notifications
 105         peer.notifyReshape(screenBounds.x - insets.left,
 106                            screenBounds.y - insets.bottom,
 107                            screenBounds.width + insets.left + insets.right,
 108                            screenBounds.height + insets.top + insets.bottom);
 109     }
 110 
 111     public void exitFullScreenMode() {
 112         CWrapper.NSView.exitFullScreenMode(ptr);
 113     }
 114 
 115     // ----------------------------------------------------------------------
 116     // PAINTING METHODS
 117     // ----------------------------------------------------------------------
 118 
 119     public void drawImageOnPeer(VolatileImage xBackBuffer, int x1, int y1, int x2, int y2) {
 120         Graphics g = peer.getGraphics();
 121         try {
 122             g.drawImage(xBackBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
 123         } finally {
 124             g.dispose();
 125         }
 126     }
 127 
 128     public Image createBackBuffer() {
 129         Rectangle r = peer.getBounds();
 130         Image im = null;
 131         if (!r.isEmpty()) {
 132             int transparency = (isOpaque() ? Transparency.OPAQUE : Transparency.TRANSLUCENT);
 133             im = peer.getGraphicsConfiguration().createCompatibleImage(r.width, r.height, transparency);
 134         }
 135         return im;
 136     }
 137 
 138     public SurfaceData replaceSurfaceData() {
 139         if (!LWCToolkit.getSunAwtDisableCALayers()) {
 140             surfaceData = windowLayer.replaceSurfaceData();
 141         } else {
 142             if (surfaceData == null) {
 143                 CGraphicsConfig graphicsConfig = (CGraphicsConfig)peer.getGraphicsConfiguration();
 144                 surfaceData = graphicsConfig.createSurfaceData(this);
 145             } else {
 146                 validateSurface();
 147             }
 148         }
 149         return surfaceData;
 150     }
 151 
 152     private void validateSurface() {
 153         if (surfaceData != null) {
 154             ((CGLSurfaceData)surfaceData).validate();
 155         }
 156     }
 157 




   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.lwawt.macosx;
  27 
  28 import java.awt.*;

  29 
  30 import sun.awt.CGraphicsConfig;
  31 import sun.lwawt.LWWindowPeer;
  32 import sun.lwawt.macosx.event.NSEvent;
  33 
  34 import sun.java2d.SurfaceData;
  35 import sun.java2d.opengl.CGLLayer;
  36 import sun.java2d.opengl.CGLSurfaceData;
  37 
  38 public class CPlatformView extends CFRetainedResource {
  39     private native long nativeCreateView(int x, int y, int width, int height, long windowLayerPtr);
  40 
  41     private LWWindowPeer peer;
  42     private SurfaceData surfaceData;
  43     private CGLLayer windowLayer;
  44     private CPlatformResponder responder;
  45 
  46     public CPlatformView() {
  47         super(0, true);
  48     }


  97         } finally {
  98             CWrapper.NSObject.release(screenPtr);
  99         }
 100 
 101         // the move/size notification from the underlying system comes
 102         // but it contains a bounds smaller than the whole screen
 103         // and therefore we need to create the synthetic notifications
 104         peer.notifyReshape(screenBounds.x - insets.left,
 105                            screenBounds.y - insets.bottom,
 106                            screenBounds.width + insets.left + insets.right,
 107                            screenBounds.height + insets.top + insets.bottom);
 108     }
 109 
 110     public void exitFullScreenMode() {
 111         CWrapper.NSView.exitFullScreenMode(ptr);
 112     }
 113 
 114     // ----------------------------------------------------------------------
 115     // PAINTING METHODS
 116     // ----------------------------------------------------------------------




















 117     public SurfaceData replaceSurfaceData() {
 118         if (!LWCToolkit.getSunAwtDisableCALayers()) {
 119             surfaceData = windowLayer.replaceSurfaceData();
 120         } else {
 121             if (surfaceData == null) {
 122                 CGraphicsConfig graphicsConfig = (CGraphicsConfig)peer.getGraphicsConfiguration();
 123                 surfaceData = graphicsConfig.createSurfaceData(this);
 124             } else {
 125                 validateSurface();
 126             }
 127         }
 128         return surfaceData;
 129     }
 130 
 131     private void validateSurface() {
 132         if (surfaceData != null) {
 133             ((CGLSurfaceData)surfaceData).validate();
 134         }
 135     }
 136