modules/graphics/src/main/java/com/sun/prism/es2/ES2SwapChain.java

Print this page




  29 import com.sun.javafx.geom.Rectangle;
  30 import com.sun.prism.GraphicsResource;
  31 import com.sun.prism.Presentable;
  32 import com.sun.prism.PresentableState;
  33 import com.sun.prism.RTTexture;
  34 import com.sun.prism.CompositeMode;
  35 import com.sun.prism.impl.PrismSettings;
  36 import com.sun.javafx.PlatformUtil;
  37 import com.sun.prism.ResourceFactory;
  38 import com.sun.prism.Texture.WrapMode;
  39 
  40 class ES2SwapChain implements ES2RenderTarget, Presentable, GraphicsResource {
  41 
  42     private final ES2Context context;
  43     private final PresentableState pState;
  44     // On screen
  45     private GLDrawable drawable;
  46     private boolean needsResize;
  47     private boolean opaque = false;
  48     private int w, h;
  49     private float pixelScaleFactor;

  50     // a value of zero corresponds to the windowing system-provided
  51     // framebuffer object
  52     int nativeDestHandle = 0;
  53     private final boolean msaa;
  54     /**
  55      * An offscreen surface that acts as a persistent backbuffer, currently
  56      * only used when dirty region optimizations are enabled in the scenegraph.
  57      *
  58      * In OpenGL, the contents of a window's (hardware) backbuffer are
  59      * undefined after a swapBuffers() operation.  The dirty region
  60      * optimizations used in the Prism scenegraph require the window's
  61      * backbuffer to be persistent, so when those optimizations are enabled,
  62      * we insert this special stableBackbuffer into the swap chain.
  63      * In createGraphics() we return a Graphics object that points to this
  64      * stableBackbuffer so that the scenegraph gets rendered into it,
  65      * and then at present() time we first copy stableBackbuffer into the
  66      * window's hardware backbuffer prior to calling swapBuffers().
  67      */
  68     private RTTexture stableBackbuffer;
  69     private boolean copyFullBuffer;
  70 
  71     public boolean isOpaque() {
  72         if (stableBackbuffer != null) {
  73             return stableBackbuffer.isOpaque();
  74         } else {
  75             return opaque;
  76         }
  77     }
  78 
  79     public void setOpaque(boolean isOpaque) {
  80         if (stableBackbuffer != null) {
  81             stableBackbuffer.setOpaque(isOpaque);
  82         } else {
  83             this.opaque = isOpaque;
  84         }
  85     }
  86 
  87     ES2SwapChain(ES2Context context, PresentableState pState) {
  88         this.context = context;
  89         this.pState = pState;
  90         this.pixelScaleFactor = pState.getRenderScale();

  91         this.msaa = pState.isMSAA();
  92         long nativeWindow = pState.getNativeWindow();
  93         drawable = ES2Pipeline.glFactory.createGLDrawable(
  94                 nativeWindow, context.getPixelFormat());
  95     }
  96 
  97     public boolean lockResources(PresentableState pState) {
  98         if (this.pState != pState || pixelScaleFactor != pState.getRenderScale()) {



  99             return true;
 100         }
 101         needsResize = (w != pState.getRenderWidth() || h != pState.getRenderHeight());
 102         // the stableBackbuffer will be used as the render target
 103         if (stableBackbuffer != null && !needsResize) {
 104             stableBackbuffer.lock();
 105             if (stableBackbuffer.isSurfaceLost()) {
 106                 stableBackbuffer = null;
 107                 // For resizes we can keep the back buffer, but if we lose
 108                 // the back buffer then we need the caller to know that a
 109                 // new buffer is coming so that the entire scene can be
 110                 // redrawn.  To force this, we return true and the Presentable
 111                 // is recreated and repainted in its entirety.
 112                 return true;
 113             }
 114         }
 115         return false;
 116     }
 117 
 118     public boolean prepare(Rectangle clip) {


 203             } else {
 204                 // RT-27554
 205                 // TODO: this implementation was done to make sure there is a
 206                 // context current for the hardware backbuffer before we start
 207                 // attempting to use the FBO associated with the
 208                 // RTTexture "backbuffer"...
 209                 ES2Graphics.create(context, this);
 210             }
 211             w = pState.getRenderWidth();
 212             h = pState.getRenderHeight();
 213             ResourceFactory factory = context.getResourceFactory();
 214             stableBackbuffer = factory.createRTTexture(w, h,
 215                                                        WrapMode.CLAMP_NOT_NEEDED,
 216                                                        msaa);
 217             if (PrismSettings.dirtyOptsEnabled) {
 218                 stableBackbuffer.contentsUseful();
 219             }
 220             copyFullBuffer = true;
 221         }
 222         ES2Graphics g = ES2Graphics.create(context, stableBackbuffer);
 223         g.scale(pixelScaleFactor, pixelScaleFactor);
 224         return g;
 225     }
 226 
 227     public int getFboID() {
 228         return nativeDestHandle;
 229     }
 230 
 231     public Screen getAssociatedScreen() {
 232         return context.getAssociatedScreen();
 233     }
 234 
 235     public int getPhysicalWidth() {
 236         return pState.getOutputWidth();
 237     }
 238 
 239     public int getPhysicalHeight() {
 240         return pState.getOutputHeight();
 241     }
 242 
 243     public int getContentX() {


 252 
 253     public int getContentY() {
 254         // EGL doesn't have a window manager, so we need to ask the window
 255         // for the x/y offset to use
 256         if (PlatformUtil.useEGL()) {
 257             return pState.getScreenHeight() -
 258                    pState.getOutputHeight() - pState.getWindowY();
 259         } else {
 260             return 0;
 261         }
 262     }
 263 
 264     public int getContentWidth() {
 265         return pState.getOutputWidth();
 266     }
 267 
 268     public int getContentHeight() {
 269         return pState.getOutputHeight();
 270     }
 271 
 272     public float getPixelScaleFactor() {
 273         return pixelScaleFactor;






 274     }
 275 
 276     @Override
 277     public void dispose() {
 278         if (stableBackbuffer != null) {
 279             stableBackbuffer.dispose();
 280             stableBackbuffer = null;
 281         }
 282     }
 283 
 284     public boolean isMSAA() {
 285         return stableBackbuffer != null ? stableBackbuffer.isMSAA() :
 286                 msaa;
 287     }
 288 }


  29 import com.sun.javafx.geom.Rectangle;
  30 import com.sun.prism.GraphicsResource;
  31 import com.sun.prism.Presentable;
  32 import com.sun.prism.PresentableState;
  33 import com.sun.prism.RTTexture;
  34 import com.sun.prism.CompositeMode;
  35 import com.sun.prism.impl.PrismSettings;
  36 import com.sun.javafx.PlatformUtil;
  37 import com.sun.prism.ResourceFactory;
  38 import com.sun.prism.Texture.WrapMode;
  39 
  40 class ES2SwapChain implements ES2RenderTarget, Presentable, GraphicsResource {
  41 
  42     private final ES2Context context;
  43     private final PresentableState pState;
  44     // On screen
  45     private GLDrawable drawable;
  46     private boolean needsResize;
  47     private boolean opaque = false;
  48     private int w, h;
  49     private float pixelScaleFactorX;
  50     private float pixelScaleFactorY;
  51     // a value of zero corresponds to the windowing system-provided
  52     // framebuffer object
  53     int nativeDestHandle = 0;
  54     private final boolean msaa;
  55     /**
  56      * An offscreen surface that acts as a persistent backbuffer, currently
  57      * only used when dirty region optimizations are enabled in the scenegraph.
  58      *
  59      * In OpenGL, the contents of a window's (hardware) backbuffer are
  60      * undefined after a swapBuffers() operation.  The dirty region
  61      * optimizations used in the Prism scenegraph require the window's
  62      * backbuffer to be persistent, so when those optimizations are enabled,
  63      * we insert this special stableBackbuffer into the swap chain.
  64      * In createGraphics() we return a Graphics object that points to this
  65      * stableBackbuffer so that the scenegraph gets rendered into it,
  66      * and then at present() time we first copy stableBackbuffer into the
  67      * window's hardware backbuffer prior to calling swapBuffers().
  68      */
  69     private RTTexture stableBackbuffer;
  70     private boolean copyFullBuffer;
  71 
  72     public boolean isOpaque() {
  73         if (stableBackbuffer != null) {
  74             return stableBackbuffer.isOpaque();
  75         } else {
  76             return opaque;
  77         }
  78     }
  79 
  80     public void setOpaque(boolean isOpaque) {
  81         if (stableBackbuffer != null) {
  82             stableBackbuffer.setOpaque(isOpaque);
  83         } else {
  84             this.opaque = isOpaque;
  85         }
  86     }
  87 
  88     ES2SwapChain(ES2Context context, PresentableState pState) {
  89         this.context = context;
  90         this.pState = pState;
  91         this.pixelScaleFactorX = pState.getRenderScaleX();
  92         this.pixelScaleFactorY = pState.getRenderScaleY();
  93         this.msaa = pState.isMSAA();
  94         long nativeWindow = pState.getNativeWindow();
  95         drawable = ES2Pipeline.glFactory.createGLDrawable(
  96                 nativeWindow, context.getPixelFormat());
  97     }
  98 
  99     public boolean lockResources(PresentableState pState) {
 100         if (this.pState != pState ||
 101             pixelScaleFactorX != pState.getRenderScaleX() ||
 102             pixelScaleFactorY != pState.getRenderScaleY())
 103         {
 104             return true;
 105         }
 106         needsResize = (w != pState.getRenderWidth() || h != pState.getRenderHeight());
 107         // the stableBackbuffer will be used as the render target
 108         if (stableBackbuffer != null && !needsResize) {
 109             stableBackbuffer.lock();
 110             if (stableBackbuffer.isSurfaceLost()) {
 111                 stableBackbuffer = null;
 112                 // For resizes we can keep the back buffer, but if we lose
 113                 // the back buffer then we need the caller to know that a
 114                 // new buffer is coming so that the entire scene can be
 115                 // redrawn.  To force this, we return true and the Presentable
 116                 // is recreated and repainted in its entirety.
 117                 return true;
 118             }
 119         }
 120         return false;
 121     }
 122 
 123     public boolean prepare(Rectangle clip) {


 208             } else {
 209                 // RT-27554
 210                 // TODO: this implementation was done to make sure there is a
 211                 // context current for the hardware backbuffer before we start
 212                 // attempting to use the FBO associated with the
 213                 // RTTexture "backbuffer"...
 214                 ES2Graphics.create(context, this);
 215             }
 216             w = pState.getRenderWidth();
 217             h = pState.getRenderHeight();
 218             ResourceFactory factory = context.getResourceFactory();
 219             stableBackbuffer = factory.createRTTexture(w, h,
 220                                                        WrapMode.CLAMP_NOT_NEEDED,
 221                                                        msaa);
 222             if (PrismSettings.dirtyOptsEnabled) {
 223                 stableBackbuffer.contentsUseful();
 224             }
 225             copyFullBuffer = true;
 226         }
 227         ES2Graphics g = ES2Graphics.create(context, stableBackbuffer);
 228         g.scale(pixelScaleFactorX, pixelScaleFactorY);
 229         return g;
 230     }
 231 
 232     public int getFboID() {
 233         return nativeDestHandle;
 234     }
 235 
 236     public Screen getAssociatedScreen() {
 237         return context.getAssociatedScreen();
 238     }
 239 
 240     public int getPhysicalWidth() {
 241         return pState.getOutputWidth();
 242     }
 243 
 244     public int getPhysicalHeight() {
 245         return pState.getOutputHeight();
 246     }
 247 
 248     public int getContentX() {


 257 
 258     public int getContentY() {
 259         // EGL doesn't have a window manager, so we need to ask the window
 260         // for the x/y offset to use
 261         if (PlatformUtil.useEGL()) {
 262             return pState.getScreenHeight() -
 263                    pState.getOutputHeight() - pState.getWindowY();
 264         } else {
 265             return 0;
 266         }
 267     }
 268 
 269     public int getContentWidth() {
 270         return pState.getOutputWidth();
 271     }
 272 
 273     public int getContentHeight() {
 274         return pState.getOutputHeight();
 275     }
 276 
 277     @Override
 278     public float getPixelScaleFactorX() {
 279         return pixelScaleFactorX;
 280     }
 281 
 282     @Override
 283     public float getPixelScaleFactorY() {
 284         return pixelScaleFactorY;
 285     }
 286 
 287     @Override
 288     public void dispose() {
 289         if (stableBackbuffer != null) {
 290             stableBackbuffer.dispose();
 291             stableBackbuffer = null;
 292         }
 293     }
 294 
 295     public boolean isMSAA() {
 296         return stableBackbuffer != null ? stableBackbuffer.isMSAA() :
 297                 msaa;
 298     }
 299 }