modules/graphics/src/main/java/com/sun/javafx/tk/quantum/PresentingPainter.java

Print this page


   1 /*
   2  * Copyright (c) 2011, 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 com.sun.javafx.tk.quantum;
  27 
  28 import com.sun.javafx.logging.PulseLogger;

  29 import com.sun.prism.Graphics;
  30 import com.sun.prism.GraphicsPipeline;
  31 import com.sun.prism.impl.Disposer;
  32 import com.sun.prism.impl.ManagedResource;
  33 
  34 /**
  35  * The PresentingPainter is used when we are rendering to the main screen.
  36  * UploadingPainter is used when we need to render into an offscreen buffer.
  37  */
  38 final class PresentingPainter extends ViewPainter {
  39 
  40     PresentingPainter(ViewScene view) {
  41         super(view);
  42     }
  43 
  44     @Override public void run() {
  45         renderLock.lock();
  46 
  47         boolean locked = false;
  48         boolean valid = false;


  72                 return;
  73             }
  74 
  75             if (presentable != null && presentable.lockResources(sceneState)) {
  76                 disposePresentable();
  77             }
  78             if (presentable == null) {
  79                 presentable = factory.createPresentable(sceneState);
  80                 penWidth  = viewWidth;
  81                 penHeight = viewHeight;
  82             }
  83             
  84             if (presentable != null) {
  85                 Graphics g = presentable.createGraphics();
  86 
  87                 ViewScene vs = (ViewScene) sceneState.getScene();
  88                 if (g != null) {
  89                     paintImpl(g);
  90                 }
  91 
  92                 long start = PulseLogger.PULSE_LOGGING_ENABLED ? System.currentTimeMillis() : 0;
  93                 if (!presentable.prepare(null)) {
  94                     disposePresentable();
  95                     sceneState.getScene().entireSceneNeedsRepaint();
  96                     if (PulseLogger.PULSE_LOGGING_ENABLED) {
  97                         PulseLogger.PULSE_LOGGER.renderMessage(start, System.currentTimeMillis(), "Presentable.prepare");
  98                     }
  99                     return;
 100                 }
 101                 
 102                 /* present for vsync buffer swap */
 103                 start = PulseLogger.PULSE_LOGGING_ENABLED ? System.currentTimeMillis() : 0;
 104                 if (vs.getDoPresent()) {
 105                     if (!presentable.present()) {
 106                         disposePresentable();
 107                         sceneState.getScene().entireSceneNeedsRepaint();
 108                     }
 109                     if (PulseLogger.PULSE_LOGGING_ENABLED) {
 110                         PulseLogger.PULSE_LOGGER.renderMessage(start, System.currentTimeMillis(), "Presentable.present");
 111                     }
 112                 }
 113             }
 114         } catch (Throwable th) {
 115             errored = true;
 116             th.printStackTrace(System.err);
 117         } finally {
 118             if (valid) {
 119                 Disposer.cleanUp();
 120             }
 121             if (locked) {
 122                 sceneState.unlock();
 123             }
 124 
 125             ViewScene viewScene = (ViewScene)sceneState.getScene();
 126             viewScene.setPainting(false);
 127 
 128             ManagedResource.freeDisposalRequestedAndCheckResources(errored);
 129 
 130             renderLock.unlock();
 131             if (PulseLogger.PULSE_LOGGING_ENABLED) {
 132                 PulseLogger.PULSE_LOGGER.renderMessage(System.currentTimeMillis(), System.currentTimeMillis(), "Finished Presenting Painter");
 133             }
 134         }
 135     }
 136 }
   1 /*
   2  * Copyright (c) 2011, 2014, 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 com.sun.javafx.tk.quantum;
  27 
  28 import com.sun.javafx.logging.PulseLogger;
  29 import static com.sun.javafx.logging.PulseLogger.PULSE_LOGGING_ENABLED;
  30 import com.sun.prism.Graphics;
  31 import com.sun.prism.GraphicsPipeline;
  32 import com.sun.prism.impl.Disposer;
  33 import com.sun.prism.impl.ManagedResource;
  34 
  35 /**
  36  * The PresentingPainter is used when we are rendering to the main screen.
  37  * UploadingPainter is used when we need to render into an offscreen buffer.
  38  */
  39 final class PresentingPainter extends ViewPainter {
  40 
  41     PresentingPainter(ViewScene view) {
  42         super(view);
  43     }
  44 
  45     @Override public void run() {
  46         renderLock.lock();
  47 
  48         boolean locked = false;
  49         boolean valid = false;


  73                 return;
  74             }
  75 
  76             if (presentable != null && presentable.lockResources(sceneState)) {
  77                 disposePresentable();
  78             }
  79             if (presentable == null) {
  80                 presentable = factory.createPresentable(sceneState);
  81                 penWidth  = viewWidth;
  82                 penHeight = viewHeight;
  83             }
  84             
  85             if (presentable != null) {
  86                 Graphics g = presentable.createGraphics();
  87 
  88                 ViewScene vs = (ViewScene) sceneState.getScene();
  89                 if (g != null) {
  90                     paintImpl(g);
  91                 }
  92 
  93                 if (PULSE_LOGGING_ENABLED) PulseLogger.newPhase("Presenting");
  94                 if (!presentable.prepare(null)) {
  95                     disposePresentable();
  96                     sceneState.getScene().entireSceneNeedsRepaint();



  97                     return;
  98                 }
  99                 
 100                 /* present for vsync buffer swap */

 101                 if (vs.getDoPresent()) {
 102                     if (!presentable.present()) {
 103                         disposePresentable();
 104                         sceneState.getScene().entireSceneNeedsRepaint();
 105                     }



 106                 }
 107             }
 108         } catch (Throwable th) {
 109             errored = true;
 110             th.printStackTrace(System.err);
 111         } finally {
 112             if (valid) {
 113                 Disposer.cleanUp();
 114             }
 115             if (locked) {
 116                 sceneState.unlock();
 117             }
 118 
 119             ViewScene viewScene = (ViewScene)sceneState.getScene();
 120             viewScene.setPainting(false);
 121 
 122             ManagedResource.freeDisposalRequestedAndCheckResources(errored);
 123 
 124             renderLock.unlock();



 125         }
 126     }
 127 }