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.javafx.tk.quantum; 27 28 import com.sun.glass.ui.Pixels; 29 import com.sun.prism.PixelSource; 30 31 /** 32 * EmbeddedState is intended to provide for a shadow copy the View/Scene state 33 * similar to the shadow Graph, providing a static snapshot until the Scene 34 * is rendered. EmbeddedState captures state that is specific to embedding. 35 */ 36 final class EmbeddedState extends SceneState { 37 38 public EmbeddedState(GlassScene vs) { 39 super(vs); 40 } 41 42 /** 43 * Put the pixels on the screen. 44 * 45 * @param source - the source for the Pixels object to be uploaded 46 */ 47 @Override 48 public void uploadPixels(PixelSource source) { 49 if (isValid()) { 50 Pixels pixels = source.getLatestPixels(); 51 if (pixels != null) { 52 try { 53 EmbeddedScene escene = (EmbeddedScene) scene; 54 // Pixels are always stored in an IntBuffer for uploading 55 escene.uploadPixels(pixels); 56 } finally { 57 source.doneWithPixels(pixels); 58 } 59 } 60 } else { 61 source.skipLatestPixels(); 62 } 63 } 64 65 /** 66 * Drawing can occur when there is an embedded scene that has a host. 67 * 68 * @return true if drawing can occur; false otherwise 69 * 70 * May be called on any thread. 71 */ 72 @Override 73 public boolean isValid() { 74 return scene != null && getWidth() > 0 && getHeight() > 0; 75 } 76 77 /** Updates the state of this object based on the current state of its 78 * nativeWindow. 79 * 80 * May only be called from the event thread. 81 */ 82 @Override 83 public void update() { 84 super.update(); 85 float scalex = ((EmbeddedScene) scene).getRenderScaleX(); 86 float scaley = ((EmbeddedScene) scene).getRenderScaleY(); 87 update(1.0f, 1.0f, scalex, scaley, scalex, scaley); 88 if (scene != null) { 89 // These variables and others from the super class need be kept up to date to 90 // minimize rendering. For now, claim that the embedded scene is always visible 91 // and not minimized so that rendering can occur 92 isWindowVisible = true; 93 isWindowMinimized = false; 94 } 95 } 96 }