1 /* 2 * Copyright (c) 2011, 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.sw; 27 28 import com.sun.glass.ui.Pixels; 29 import com.sun.javafx.geom.Rectangle; 30 import com.sun.prism.Presentable; 31 import com.sun.prism.PresentableState; 32 import com.sun.prism.impl.QueuedPixelSource; 33 import java.nio.IntBuffer; 34 35 final class SWPresentable extends SWRTTexture implements Presentable { 36 37 private final PresentableState pState; 38 private Pixels pixels; 39 private QueuedPixelSource pixelSource = new QueuedPixelSource(false); 40 41 public SWPresentable(PresentableState pState, SWResourceFactory factory) { 42 super(factory, pState.getRenderWidth(), pState.getRenderHeight()); 43 this.pState = pState; 44 } 45 46 @Override 47 public boolean lockResources(PresentableState pState) { 48 return (getPhysicalWidth() != pState.getRenderWidth() || 49 getPhysicalHeight() != pState.getRenderHeight()); 50 } 51 52 public boolean prepare(Rectangle dirtyregion) { 53 if (!pState.isViewClosed()) { 54 /* 55 * RT-27374 56 * TODO: make sure the imgrep matches the Pixels.getNativeFormat() 57 * TODO: dirty region support 58 */ 59 int w = getPhysicalWidth(); 60 int h = getPhysicalHeight(); 61 pixels = pixelSource.getUnusedPixels(w, h, 1.0f, 1.0f); 62 IntBuffer pixBuf = (IntBuffer) pixels.getPixels(); 63 IntBuffer buf = getSurface().getDataIntBuffer(); 64 assert buf.hasArray(); 65 System.arraycopy(buf.array(), 0, pixBuf.array(), 0, w*h); 66 return true; 67 } else { 68 return false; 69 } 70 } 71 72 public boolean present() { 73 pixelSource.enqueuePixels(pixels); 74 pState.uploadPixels(pixelSource); 75 return true; 76 } 77 78 @Override 79 public float getPixelScaleFactorX() { 80 return pState.getRenderScaleX(); 81 } 82 83 @Override 84 public float getPixelScaleFactorY() { 85 return pState.getRenderScaleY(); 86 } 87 88 public int getContentWidth() { 89 return pState.getOutputWidth(); 90 } 91 92 public int getContentHeight() { 93 return pState.getOutputHeight(); 94 } 95 96 @Override public boolean isMSAA() { 97 return super.isMSAA(); 98 } 99 }