1 /* 2 * Copyright (c) 2013, 2015, 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.prism; 27 28 import com.sun.glass.ui.Application; 29 import com.sun.glass.ui.Pixels; 30 import com.sun.glass.ui.Screen; 31 import com.sun.glass.ui.View; 32 import com.sun.glass.ui.Window; 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 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 int screenHeight; 54 protected int screenWidth; 55 protected boolean isWindowVisible; 56 protected boolean isWindowMinimized; 57 protected float screenScale; 58 protected static final boolean hasWindowManager = 59 Application.GetApplication().hasWindowManager(); 60 // Between PaintCollector and *Painter, there is a window where 61 // the associated View can be closed. This variable allows us 62 // to shortcut the queued *Painter task. 63 protected boolean isClosed; 64 protected final int pixelFormat = Pixels.getNativeFormat(); 65 66 /** Create a PresentableState based on a View. 67 * 68 * Must be called on the event thread. 69 */ 70 public PresentableState() { 71 } 72 73 /** 74 * The screen relative window X 75 * @return The screen relative window X 76 * 77 * May be called on any thread. 78 */ 79 public int getWindowX() { 80 return windowX; 81 } 82 83 /** 84 * The screen relative window Y 85 * @return The screen relative window Y 86 * 87 * May be called on any thread. 88 */ 89 public int getWindowY() { 90 return windowY; 91 } 92 93 /** 94 * @return the width of the View 95 * 96 * May be called on any thread. 97 */ 98 public int getWidth() { 99 return viewWidth; 100 } 101 102 /** 103 * @return the height of the View 104 * 105 * May be called on any thread. 106 */ 107 public int getHeight() { 108 return viewHeight; 109 } 110 111 /** 112 * @return Screen.getScale 113 * 114 * May be called on any thread 115 */ 116 public float getScale() { 117 return screenScale; 118 } 119 120 /** 121 * @return the window's alpha level 122 * 123 * May be called on any thread. 124 */ 125 public float getAlpha() { 126 return windowAlpha; 127 } 128 129 /** 130 * @return the native handle of the window represented by this 131 * PresentableState 132 * 133 * May be called on any thread. 134 */ 135 public long getNativeWindow() { 136 return nativeWindowHandle; 137 } 138 139 /** 140 * @return the native handle of the View represented by this 141 * PresentableState 142 * 143 * May be called on any thread. 144 */ 145 public long getNativeView() { 146 return nativeView; 147 } 148 149 /** 150 * @return the current height of the screen 151 * 152 * May be called on any thread. 153 */ 154 public int getScreenHeight() { 155 return screenHeight; 156 } 157 158 /** 159 * @return the current width of the screen 160 * 161 * May be called on any thread. 162 */ 163 public int getScreenWidth() { 164 return screenWidth; 165 } 166 167 /** 168 * @return true if the underlying View is closed, false otherwise 169 * 170 * May be called on any thread. 171 */ 172 public boolean isViewClosed() { 173 return isClosed; 174 } 175 176 /** 177 * @return true if the underlying Window is minimized, false otherwise 178 * 179 * May be called on any thread. 180 */ 181 public boolean isWindowMinimized() { 182 return isWindowMinimized; 183 } 184 185 /** 186 * @return true if the underlying Window is Visible, false otherwise 187 * 188 * May be called on any thread. 189 */ 190 public boolean isWindowVisible() { 191 return isWindowVisible; 192 } 193 194 /** 195 * @return true if the underlying window is managed by a window manager 196 * external to JavaFX 197 * 198 * May be called on any thread. 199 */ 200 public boolean hasWindowManager() { 201 return hasWindowManager; 202 } 203 204 /** 205 * @return the underlying Window 206 * 207 * May be called on any thread. 208 */ 209 public Window getWindow() { 210 return window; 211 } 212 213 public boolean isMSAA() { return false; } 214 215 /** 216 * @return the underlying View 217 * 218 * May be called on any thread. 219 */ 220 public View getView() { 221 return view; 222 } 223 224 /** 225 * @return native pixel format 226 * 227 * May be called on any thread. 228 */ 229 public int getPixelFormat() { 230 return pixelFormat; 231 } 232 233 /** 234 * @return native native frame buffer 235 * 236 * May be called on any thread. 237 */ 238 public int getNativeFrameBuffer() { 239 return nativeFrameBuffer; 240 } 241 242 /** 243 * Locks the underlying view for rendering 244 * 245 * Must be called on Prism renderer thread. 246 */ 247 public void lock() { 248 if (view != null) { 249 view.lock(); 250 nativeFrameBuffer = view.getNativeFrameBuffer(); 251 } 252 } 253 254 /** 255 * Unlocks the underlying view after rendering 256 * 257 * Must be called on Prism renderer thread. 258 */ 259 public void unlock() { 260 if (view != null) view.unlock(); 261 } 262 263 /** 264 * Put the pixels on the screen. 265 * 266 * @param source - the source for the Pixels object to be uploaded 267 */ 268 public void uploadPixels(PixelSource source) { 269 Pixels pixels = source.getLatestPixels(); 270 if (pixels != null) { 271 try { 272 view.uploadPixels(pixels); 273 } finally { 274 source.doneWithPixels(pixels); 275 } 276 } 277 } 278 279 /** Updates the state of this object based on the current state of its 280 * nativeWindow. 281 * 282 * May only be called from the event thread. 283 */ 284 public void update() { 285 // should only be called on the event thread 286 if (view != null) { 287 viewWidth = view.getWidth(); 288 viewHeight = view.getHeight(); 289 window = view.getWindow(); 290 } else { 291 viewWidth = viewHeight = -1; 292 window = null; 293 } 294 if (window != null) { 295 windowX = window.getX(); 296 windowY = window.getY(); 297 windowAlpha = window.getAlpha(); 298 nativeView = view.getNativeView(); 299 nativeWindowHandle = window.getNativeWindow(); 300 isClosed = view.isClosed(); 301 isWindowVisible = window.isVisible(); 302 isWindowMinimized = window.isMinimized(); 303 Screen screen = window.getScreen(); 304 if (screen != null) { 305 // note only used by Embedded Z order painting 306 // !hasWindowManager so should be safe to ignore 307 // when null, most likely because of "In Browswer" 308 screenHeight = screen.getHeight(); 309 screenWidth = screen.getWidth(); 310 screenScale = screen.getScale(); 311 } else { 312 screenScale = 1.f; 313 } 314 } else { 315 //TODO - should other variables be cleared? 316 nativeView = -1; 317 nativeWindowHandle = -1; 318 isClosed = true; 319 } 320 } 321 }