modules/graphics/src/main/java/com/sun/prism/PresentableState.java

Print this page




  33 
  34 /**
  35  * PresentableState is intended to provide for a shadow copy of View/Window
  36  * state for use off the event thread. It is the task of the invoker of
  37  * Prism to make sure that the state is consistent for a rendering probably
  38  * by use of the AbstractPainter.renderLock to ensure consistent state.
  39  */
  40 public abstract class PresentableState {
  41 
  42     /** The underlying Window and View */
  43     protected Window window;
  44     protected View view;
  45 
  46     // Captured state
  47     protected int nativeFrameBuffer;
  48     protected int windowX, windowY;
  49     protected float windowAlpha;
  50     protected long nativeWindowHandle;
  51     protected long nativeView;
  52     protected int viewWidth, viewHeight;
  53     protected float renderScale;
  54     protected int renderWidth, renderHeight;
  55     protected float outputScale;
  56     protected int outputWidth, outputHeight;
  57     protected int screenHeight;
  58     protected int screenWidth;
  59     protected boolean isWindowVisible;
  60     protected boolean isWindowMinimized;
  61     protected static final boolean hasWindowManager =
  62             Application.GetApplication().hasWindowManager();
  63     // Between PaintCollector and *Painter, there is a window where
  64     // the associated View can be closed. This variable allows us
  65     // to shortcut the queued *Painter task.
  66     protected boolean isClosed;
  67     protected final int pixelFormat = Pixels.getNativeFormat();
  68 
  69     /** Create a PresentableState based on a View.
  70      *
  71      * Must be called on the event thread.
  72      */
  73     public PresentableState() {
  74     }
  75 


 115         return renderWidth;
 116     }
 117 
 118     public int getRenderHeight() {
 119         return renderHeight;
 120     }
 121 
 122     public int getOutputWidth() {
 123         return outputWidth;
 124     }
 125 
 126     public int getOutputHeight() {
 127         return outputHeight;
 128     }
 129 
 130     /**
 131      * @return Screen.getScale
 132      *
 133      * May be called on any thread
 134      */
 135     public float getRenderScale() {
 136         return renderScale;
 137     }
 138 
 139     public float getOutputScale() {
 140         return outputScale;













 141     }
 142 
 143     /**
 144      * @return the window's alpha level
 145      *
 146      * May be called on any thread.
 147      */
 148     public float getAlpha() {
 149         return windowAlpha;
 150     }
 151 
 152     /**
 153      * @return the native handle of the window represented by this
 154      * PresentableState
 155      *
 156      * May be called on any thread.
 157      */
 158     public long getNativeWindow() {
 159         return nativeWindowHandle;
 160     }


 288      *
 289      * @param source - the source for the Pixels object to be uploaded
 290      */
 291     public void uploadPixels(PixelSource source) {
 292         Pixels pixels = source.getLatestPixels();
 293         if (pixels != null) {
 294             try {
 295                 view.uploadPixels(pixels);
 296             } finally {
 297                 source.doneWithPixels(pixels);
 298             }
 299         }
 300     }
 301 
 302     private int scale(int dim, float fromScale, float toScale) {
 303         return (fromScale == toScale)
 304                ? dim
 305                : (int) Math.ceil(dim * toScale / fromScale);
 306     }
 307 
 308     protected void update(float viewScale, float renderScale, float outputScale) {
 309         this.renderScale = renderScale;
 310         this.outputScale = outputScale;
 311         if (renderScale == viewScale) {





 312             renderWidth = viewWidth;
 313             renderHeight = viewHeight;
 314         } else {
 315             renderWidth = scale(viewWidth, viewScale, renderScale);
 316             renderHeight = scale(viewHeight, viewScale, renderScale);
 317         }
 318         if (outputScale == viewScale) {
 319             outputWidth = viewWidth;
 320             outputHeight = viewHeight;
 321         } else if (outputScale == renderScale) {
 322             outputWidth = renderWidth;
 323             outputHeight = renderHeight;
 324         } else {
 325             outputWidth = scale(viewWidth, viewScale, outputScale);
 326             outputHeight = scale(viewHeight, viewScale, outputScale);
 327         }
 328     }
 329 
 330     /** Updates the state of this object based on the current state of its
 331      * nativeWindow.
 332      *
 333      * May only be called from the event thread.
 334      */
 335     public void update() {
 336         // should only be called on the event thread
 337         if (view != null) {
 338             viewWidth = view.getWidth();
 339             viewHeight = view.getHeight();
 340             window = view.getWindow();
 341         } else {
 342             viewWidth = viewHeight = -1;
 343             window = null;
 344         }
 345         if (window != null) {
 346             windowX = window.getX();
 347             windowY = window.getY();
 348             windowAlpha = window.getAlpha();
 349             nativeView = view.getNativeView();
 350             nativeWindowHandle = window.getNativeWindow();
 351             isClosed = view.isClosed();
 352             isWindowVisible = window.isVisible();
 353             isWindowMinimized = window.isMinimized();
 354             update(window.getPlatformScale(),
 355                    window.getRenderScale(),
 356                    window.getOutputScale());
 357             Screen screen = window.getScreen();
 358             if (screen != null) {
 359                 // note only used by Embedded Z order painting
 360                 // !hasWindowManager so should be safe to ignore
 361                 // when null, most likely because of "In Browswer"
 362                 screenHeight = screen.getHeight();
 363                 screenWidth = screen.getWidth();
 364             }
 365         } else {
 366             //TODO - should other variables be cleared?
 367             nativeView = -1;
 368             nativeWindowHandle = -1;
 369             isClosed = true;
 370         }
 371     }
 372 }


  33 
  34 /**
  35  * PresentableState is intended to provide for a shadow copy of View/Window
  36  * state for use off the event thread. It is the task of the invoker of
  37  * Prism to make sure that the state is consistent for a rendering probably
  38  * by use of the AbstractPainter.renderLock to ensure consistent state.
  39  */
  40 public abstract class PresentableState {
  41 
  42     /** The underlying Window and View */
  43     protected Window window;
  44     protected View view;
  45 
  46     // Captured state
  47     protected int nativeFrameBuffer;
  48     protected int windowX, windowY;
  49     protected float windowAlpha;
  50     protected long nativeWindowHandle;
  51     protected long nativeView;
  52     protected int viewWidth, viewHeight;
  53     protected float renderScaleX, renderScaleY;
  54     protected int renderWidth, renderHeight;
  55     protected float outputScaleX, outputScaleY;
  56     protected int outputWidth, outputHeight;
  57     protected int screenHeight;
  58     protected int screenWidth;
  59     protected boolean isWindowVisible;
  60     protected boolean isWindowMinimized;
  61     protected static final boolean hasWindowManager =
  62             Application.GetApplication().hasWindowManager();
  63     // Between PaintCollector and *Painter, there is a window where
  64     // the associated View can be closed. This variable allows us
  65     // to shortcut the queued *Painter task.
  66     protected boolean isClosed;
  67     protected final int pixelFormat = Pixels.getNativeFormat();
  68 
  69     /** Create a PresentableState based on a View.
  70      *
  71      * Must be called on the event thread.
  72      */
  73     public PresentableState() {
  74     }
  75 


 115         return renderWidth;
 116     }
 117 
 118     public int getRenderHeight() {
 119         return renderHeight;
 120     }
 121 
 122     public int getOutputWidth() {
 123         return outputWidth;
 124     }
 125 
 126     public int getOutputHeight() {
 127         return outputHeight;
 128     }
 129 
 130     /**
 131      * @return Screen.getScale
 132      *
 133      * May be called on any thread
 134      */
 135     public float getRenderScaleX() {
 136         return renderScaleX;
 137     }
 138 
 139     /**
 140      * @return Screen.getScale
 141      *
 142      * May be called on any thread
 143      */
 144     public float getRenderScaleY() {
 145         return renderScaleY;
 146     }
 147 
 148     public float getOutputScaleX() {
 149         return outputScaleX;
 150     }
 151 
 152     public float getOutputScaleY() {
 153         return outputScaleY;
 154     }
 155 
 156     /**
 157      * @return the window's alpha level
 158      *
 159      * May be called on any thread.
 160      */
 161     public float getAlpha() {
 162         return windowAlpha;
 163     }
 164 
 165     /**
 166      * @return the native handle of the window represented by this
 167      * PresentableState
 168      *
 169      * May be called on any thread.
 170      */
 171     public long getNativeWindow() {
 172         return nativeWindowHandle;
 173     }


 301      *
 302      * @param source - the source for the Pixels object to be uploaded
 303      */
 304     public void uploadPixels(PixelSource source) {
 305         Pixels pixels = source.getLatestPixels();
 306         if (pixels != null) {
 307             try {
 308                 view.uploadPixels(pixels);
 309             } finally {
 310                 source.doneWithPixels(pixels);
 311             }
 312         }
 313     }
 314 
 315     private int scale(int dim, float fromScale, float toScale) {
 316         return (fromScale == toScale)
 317                ? dim
 318                : (int) Math.ceil(dim * toScale / fromScale);
 319     }
 320 
 321     protected void update(float viewScaleX,   float viewScaleY,
 322                           float renderScaleX, float renderScaleY,
 323                           float outputScaleX, float outputScaleY)
 324     {
 325         this.renderScaleX = renderScaleX;
 326         this.renderScaleY = renderScaleY;
 327         this.outputScaleX = outputScaleX;
 328         this.outputScaleY = outputScaleY;
 329         if (renderScaleX == viewScaleX && renderScaleY == viewScaleY) {
 330             renderWidth = viewWidth;
 331             renderHeight = viewHeight;
 332         } else {
 333             renderWidth = scale(viewWidth, viewScaleX, renderScaleX);
 334             renderHeight = scale(viewHeight, viewScaleY, renderScaleY);
 335         }
 336         if (outputScaleX == viewScaleX && outputScaleY == viewScaleY) {
 337             outputWidth = viewWidth;
 338             outputHeight = viewHeight;
 339         } else if (outputScaleX == renderScaleX && outputScaleY == renderScaleY) {
 340             outputWidth = renderWidth;
 341             outputHeight = renderHeight;
 342         } else {
 343             outputWidth = scale(viewWidth, viewScaleX, outputScaleX);
 344             outputHeight = scale(viewHeight, viewScaleY, outputScaleY);
 345         }
 346     }
 347 
 348     /** Updates the state of this object based on the current state of its
 349      * nativeWindow.
 350      *
 351      * May only be called from the event thread.
 352      */
 353     public void update() {
 354         // should only be called on the event thread
 355         if (view != null) {
 356             viewWidth = view.getWidth();
 357             viewHeight = view.getHeight();
 358             window = view.getWindow();
 359         } else {
 360             viewWidth = viewHeight = -1;
 361             window = null;
 362         }
 363         if (window != null) {
 364             windowX = window.getX();
 365             windowY = window.getY();
 366             windowAlpha = window.getAlpha();
 367             nativeView = view.getNativeView();
 368             nativeWindowHandle = window.getNativeWindow();
 369             isClosed = view.isClosed();
 370             isWindowVisible = window.isVisible();
 371             isWindowMinimized = window.isMinimized();
 372             update(window.getPlatformScaleX(), window.getPlatformScaleY(),
 373                    window.getRenderScaleX(),   window.getRenderScaleY(),
 374                    window.getOutputScaleX(),   window.getOutputScaleY());
 375             Screen screen = window.getScreen();
 376             if (screen != null) {
 377                 // note only used by Embedded Z order painting
 378                 // !hasWindowManager so should be safe to ignore
 379                 // when null, most likely because of "In Browswer"
 380                 screenHeight = screen.getHeight();
 381                 screenWidth = screen.getWidth();
 382             }
 383         } else {
 384             //TODO - should other variables be cleared?
 385             nativeView = -1;
 386             nativeWindowHandle = -1;
 387             isClosed = true;
 388         }
 389     }
 390 }