1 /*
   2  * Copyright (c) 2011, 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.awt;
  27 
  28 import java.awt.*;
  29 import java.awt.geom.*;
  30 import java.awt.image.*;
  31 
  32 import sun.java2d.SurfaceData;
  33 import sun.java2d.opengl.CGLLayer;
  34 import sun.lwawt.macosx.CPlatformView;
  35 
  36 public class CGraphicsConfig extends GraphicsConfiguration {
  37     private final CGraphicsDevice device;
  38     private ColorModel colorModel;
  39 
  40     public CGraphicsConfig(CGraphicsDevice device) {
  41         this.device = device;
  42     }
  43 
  44     @Override
  45     public BufferedImage createCompatibleImage(int width, int height) {
  46         throw new UnsupportedOperationException("not implemented");
  47     }
  48 
  49     private static native Rectangle2D nativeGetBounds(int screen);
  50 
  51     @Override
  52     public Rectangle getBounds() {
  53         final Rectangle2D nativeBounds = nativeGetBounds(device.getCoreGraphicsScreen());
  54         return nativeBounds.getBounds(); // does integer rounding
  55     }
  56 
  57     @Override
  58     public ColorModel getColorModel() {
  59         if (colorModel == null) {
  60             colorModel = getColorModel(Transparency.OPAQUE);
  61         }
  62         return colorModel;
  63     }
  64 
  65     @Override
  66     public ColorModel getColorModel(int transparency) {
  67         throw new UnsupportedOperationException("not implemented");
  68     }
  69 
  70     @Override
  71     public AffineTransform getDefaultTransform() {
  72         return new AffineTransform();
  73     }
  74 
  75     @Override
  76     public CGraphicsDevice getDevice() {
  77         return device;
  78     }
  79 
  80     @Override
  81     public AffineTransform getNormalizingTransform() {
  82         double xscale = device.getXResolution() / 72.0;
  83         double yscale = device.getYResolution() / 72.0;
  84         return new AffineTransform(xscale, 0.0, 0.0, yscale, 0.0, 0.0);
  85     }
  86 
  87 
  88     /**
  89      * The following methods are invoked from CToolkit.java and
  90      * LWWindowPeer.java rather than having the native
  91      * implementations hardcoded in those classes.  This way the appropriate
  92      * actions are taken based on the peer's GraphicsConfig, whether it is
  93      * an CGLGraphicsConfig or something else.
  94      */
  95 
  96     /**
  97      * Creates a new SurfaceData that will be associated with the given
  98      * LWWindowPeer.
  99      */
 100     public SurfaceData createSurfaceData(CPlatformView pView) {
 101         throw new UnsupportedOperationException("not implemented");
 102     }
 103 
 104     /**
 105      * Creates a new SurfaceData that will be associated with the given
 106      * CGLLayer.
 107      */
 108     public SurfaceData createSurfaceData(CGLLayer layer) {
 109         throw new UnsupportedOperationException("not implemented");
 110     }
 111 
 112     /**
 113      * Creates a new hidden-acceleration image of the given width and height
 114      * that is associated with the target Component.
 115      */
 116     public Image createAcceleratedImage(Component target,
 117                                         int width, int height)
 118     {
 119         throw new UnsupportedOperationException("not implemented");
 120     }
 121 
 122     /**
 123      * The following methods correspond to the multibuffering methods in
 124      * LWWindowPeer.java...
 125      */
 126 
 127     /**
 128      * Attempts to create a native backbuffer for the given peer.  If
 129      * the requested configuration is not natively supported, an AWTException
 130      * is thrown.  Otherwise, if the backbuffer creation is successful, a
 131      * handle to the native backbuffer is returned.
 132      */
 133     public long createBackBuffer(CPlatformView pView,
 134                                  int numBuffers, BufferCapabilities caps)
 135         throws AWTException
 136     {
 137         throw new UnsupportedOperationException("not implemented");
 138     }
 139 
 140     public void destroyBackBuffer(long backBuffer)
 141         throws AWTException
 142     {
 143         throw new UnsupportedOperationException("not implemented");
 144     }
 145 
 146     /**
 147      * Creates a VolatileImage that essentially wraps the target Component's
 148      * backbuffer, using the provided backbuffer handle.
 149      */
 150     public VolatileImage createBackBufferImage(Component target,
 151                                                long backBuffer)
 152     {
 153         throw new UnsupportedOperationException("not implemented");
 154     }
 155 
 156     /**
 157      * Performs the native flip operation for the given target Component.
 158      */
 159     public void flip(CPlatformView delegate,
 160                      Component target, VolatileImage xBackBuffer,
 161                      int x1, int y1, int x2, int y2,
 162                      BufferCapabilities.FlipContents flipAction)
 163     {
 164         throw new UnsupportedOperationException("not implemented");
 165     }
 166 
 167     @Override
 168     public boolean isTranslucencyCapable() {
 169         //we know for sure we have capable config :)
 170         return true;
 171     }
 172 }