1 /*
   2  * Copyright (c) 2018, 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.metal;
  27 
  28 import sun.awt.AWTAccessor;
  29 import sun.awt.image.SunVolatileImage;
  30 import sun.awt.image.VolatileSurfaceManager;
  31 import sun.java2d.SurfaceData;
  32 import sun.java2d.opengl.OGLSurfaceData;
  33 
  34 import java.awt.*;
  35 import java.awt.image.ColorModel;
  36 import java.awt.peer.ComponentPeer;
  37 
  38 public class MetalVolatileSurfaceManager extends VolatileSurfaceManager {
  39     //private final boolean accelerationEnabled;
  40     public MetalVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
  41         super(vImg, context);
  42         
  43         /*
  44          * We will attempt to accelerate this image only under the
  45          * following conditions:
  46          *   - the image is not bitmask AND the GraphicsConfig supports the FBO
  47          *     extension
  48          */
  49         /*int transparency = vImg.getTransparency();
  50          MetalGraphicsConfig gc = (MetalGraphicsConfig) vImg.getGraphicsConfig();
  51          accelerationEnabled = gc.isCapPresent(CAPS_EXT_FBOBJECT)
  52          && transparency != Transparency.BITMASK;*/
  53     }
  54     
  55     protected boolean isAccelerationEnabled() {
  56         return true;
  57     }
  58     
  59     /**
  60      * Create a FBO-based SurfaceData object (or init the backbuffer
  61      * of an existing window if this is a double buffered GraphicsConfig)
  62      */
  63     protected SurfaceData initAcceleratedSurface() {
  64         SurfaceData sData = null;
  65         Component comp = vImg.getComponent();
  66         final AWTAccessor.ComponentAccessor acc = AWTAccessor.getComponentAccessor();
  67         final ComponentPeer peer = (comp != null) ? acc.getPeer(comp) : null;
  68         
  69         try {
  70             /*boolean createVSynced = false;
  71              boolean forceback = false;
  72              if (context instanceof Boolean) {
  73              forceback = ((Boolean)context).booleanValue();
  74              if (forceback && peer instanceof BackBufferCapsProvider) {
  75              BackBufferCapsProvider provider =
  76              (BackBufferCapsProvider)peer;
  77              BufferCapabilities caps = provider.getBackBufferCaps();
  78              if (caps instanceof ExtendedBufferCapabilities) {
  79              ExtendedBufferCapabilities ebc =
  80              (ExtendedBufferCapabilities)caps;
  81              if (ebc.getVSync() == VSYNC_ON &&
  82              ebc.getFlipContents() == COPIED)
  83              {
  84              createVSynced = true;
  85              forceback = false;
  86              }
  87              }
  88              }
  89              }*/
  90             
  91             /*if (forceback) {
  92              // peer must be non-null in this case
  93              // TODO: modify parameter to delegate
  94              //                sData = CGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
  95              } else {*/
  96             MetalGraphicsConfig gc =
  97             (MetalGraphicsConfig)vImg.getGraphicsConfig();
  98             ColorModel cm = gc.getColorModel(vImg.getTransparency());
  99             int type = vImg.getForcedAccelSurfaceType();
 100             // if acceleration type is forced (type != UNDEFINED) then
 101             // use the forced type, otherwise choose FBOBJECT
 102             //if (type == OGLSurfaceData.UNDEFINED) {
 103             //type = OGLSurfaceData.FBOBJECT;
 104             //}
 105             //if (createVSynced) {
 106             /*
 107              * TODO: modify parameter to delegate, this TODO is
 108              * present in OGL also
 109              */
 110             //                  sData = CGLSurfaceData.createData(peer, vImg, type);
 111             //} else {
 112             sData = MetalSurfaceData.createData(gc,
 113                                                 vImg.getWidth(),
 114                                                 vImg.getHeight(),
 115                                                 cm, vImg, type);
 116             //}
 117             //}
 118         } catch (NullPointerException ex) {
 119             sData = null;
 120         } catch (OutOfMemoryError er) {
 121             sData = null;
 122         }
 123         
 124         return sData;
 125     }
 126     
 127     @Override
 128     public void initContents() {
 129         // TODO : Check what is special case of TEXTURE
 130         //if (vImg.getForcedAccelSurfaceType() != OGLSurfaceData.TEXTURE) {
 131         super.initContents();
 132         //}
 133     }
 134 }