1 /* 2 * Copyright (c) 2007, 2008, 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 sun.java2d.d3d; 27 28 import javax.tools.annotation.GenerateNativeHeader; 29 import sun.java2d.pipe.BufferedContext; 30 import sun.java2d.pipe.RenderBuffer; 31 import sun.java2d.pipe.RenderQueue; 32 import sun.java2d.pipe.hw.ContextCapabilities; 33 import static sun.java2d.pipe.BufferedOpCodes.*; 34 import static sun.java2d.pipe.hw.ContextCapabilities.*; 35 import static sun.java2d.d3d.D3DContext.D3DContextCaps.*; 36 37 /** 38 * Note that the RenderQueue lock must be acquired before calling any of 39 * the methods in this class. 40 */ 41 /* No native methods here, but the constants are needed in the supporting JNI code */ 42 @GenerateNativeHeader 43 class D3DContext extends BufferedContext { 44 45 private final D3DGraphicsDevice device; 46 47 D3DContext(RenderQueue rq, D3DGraphicsDevice device) { 48 super(rq); 49 this.device = device; 50 } 51 52 /** 53 * Invalidates the currentContext field to ensure that we properly 54 * revalidate the D3DContext (make it current, etc.) next time through 55 * the validate() method. This is typically invoked from methods 56 * that affect the current context state (e.g. disposing a context or 57 * surface). 58 */ 59 static void invalidateCurrentContext() { 60 // assert D3DRenderQueue.getInstance().lock.isHeldByCurrentThread(); 61 62 // invalidate the current Java-level context so that we 126 @Override 127 public void restoreState() { 128 // assert rq.lock.isHeldByCurrentThread(); 129 130 // reset all attributes of this and current contexts 131 invalidateContext(); 132 invalidateCurrentContext(); 133 134 setScratchSurface(this); 135 136 // restore the state on the native level 137 rq.ensureCapacity(4); 138 buf.putInt(RESTORE_STATE); 139 rq.flushNow(); 140 } 141 142 D3DGraphicsDevice getDevice() { 143 return device; 144 } 145 146 /* No native methods here, but the constants are needed in the supporting JNI code */ 147 @GenerateNativeHeader 148 static class D3DContextCaps extends ContextCapabilities { 149 /** 150 * Indicates the presence of pixel shaders (v2.0 or greater). 151 * This cap will only be set if the hardware supports the minimum number 152 * of texture units. 153 */ 154 static final int CAPS_LCD_SHADER = (FIRST_PRIVATE_CAP << 0); 155 /** 156 * Indicates the presence of pixel shaders (v2.0 or greater). 157 * This cap will only be set if the hardware meets our 158 * minimum requirements. 159 */ 160 static final int CAPS_BIOP_SHADER = (FIRST_PRIVATE_CAP << 1); 161 /** 162 * Indicates that the device was successfully initialized and can 163 * be safely used. 164 */ 165 static final int CAPS_DEVICE_OK = (FIRST_PRIVATE_CAP << 2); 166 /** 167 * Indicates that the device has all of the necessary capabilities 168 * to support the Antialiasing Pixel Shader program. 169 */ 170 static final int CAPS_AA_SHADER = (FIRST_PRIVATE_CAP << 3); 171 172 D3DContextCaps(int caps, String adapterId) { 173 super(caps, adapterId); 174 } 175 176 @Override 177 public String toString() { 178 StringBuffer buf = new StringBuffer(super.toString()); 179 if ((caps & CAPS_LCD_SHADER) != 0) { 180 buf.append("CAPS_LCD_SHADER|"); 181 } 182 if ((caps & CAPS_BIOP_SHADER) != 0) { 183 buf.append("CAPS_BIOP_SHADER|"); 184 } 185 if ((caps & CAPS_AA_SHADER) != 0) { 186 buf.append("CAPS_AA_SHADER|"); 187 } 188 if ((caps & CAPS_DEVICE_OK) != 0) { 189 buf.append("CAPS_DEVICE_OK|"); 190 } | 1 /* 2 * Copyright (c) 2007, 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 sun.java2d.d3d; 27 28 import java.lang.annotation.Native; 29 import sun.java2d.pipe.BufferedContext; 30 import sun.java2d.pipe.RenderBuffer; 31 import sun.java2d.pipe.RenderQueue; 32 import sun.java2d.pipe.hw.ContextCapabilities; 33 import static sun.java2d.pipe.BufferedOpCodes.*; 34 import static sun.java2d.pipe.hw.ContextCapabilities.*; 35 import static sun.java2d.d3d.D3DContext.D3DContextCaps.*; 36 37 /** 38 * Note that the RenderQueue lock must be acquired before calling any of 39 * the methods in this class. 40 */ 41 class D3DContext extends BufferedContext { 42 43 private final D3DGraphicsDevice device; 44 45 D3DContext(RenderQueue rq, D3DGraphicsDevice device) { 46 super(rq); 47 this.device = device; 48 } 49 50 /** 51 * Invalidates the currentContext field to ensure that we properly 52 * revalidate the D3DContext (make it current, etc.) next time through 53 * the validate() method. This is typically invoked from methods 54 * that affect the current context state (e.g. disposing a context or 55 * surface). 56 */ 57 static void invalidateCurrentContext() { 58 // assert D3DRenderQueue.getInstance().lock.isHeldByCurrentThread(); 59 60 // invalidate the current Java-level context so that we 124 @Override 125 public void restoreState() { 126 // assert rq.lock.isHeldByCurrentThread(); 127 128 // reset all attributes of this and current contexts 129 invalidateContext(); 130 invalidateCurrentContext(); 131 132 setScratchSurface(this); 133 134 // restore the state on the native level 135 rq.ensureCapacity(4); 136 buf.putInt(RESTORE_STATE); 137 rq.flushNow(); 138 } 139 140 D3DGraphicsDevice getDevice() { 141 return device; 142 } 143 144 static class D3DContextCaps extends ContextCapabilities { 145 /** 146 * Indicates the presence of pixel shaders (v2.0 or greater). 147 * This cap will only be set if the hardware supports the minimum number 148 * of texture units. 149 */ 150 @Native static final int CAPS_LCD_SHADER = (FIRST_PRIVATE_CAP << 0); 151 /** 152 * Indicates the presence of pixel shaders (v2.0 or greater). 153 * This cap will only be set if the hardware meets our 154 * minimum requirements. 155 */ 156 @Native static final int CAPS_BIOP_SHADER = (FIRST_PRIVATE_CAP << 1); 157 /** 158 * Indicates that the device was successfully initialized and can 159 * be safely used. 160 */ 161 @Native static final int CAPS_DEVICE_OK = (FIRST_PRIVATE_CAP << 2); 162 /** 163 * Indicates that the device has all of the necessary capabilities 164 * to support the Antialiasing Pixel Shader program. 165 */ 166 @Native static final int CAPS_AA_SHADER = (FIRST_PRIVATE_CAP << 3); 167 168 D3DContextCaps(int caps, String adapterId) { 169 super(caps, adapterId); 170 } 171 172 @Override 173 public String toString() { 174 StringBuffer buf = new StringBuffer(super.toString()); 175 if ((caps & CAPS_LCD_SHADER) != 0) { 176 buf.append("CAPS_LCD_SHADER|"); 177 } 178 if ((caps & CAPS_BIOP_SHADER) != 0) { 179 buf.append("CAPS_BIOP_SHADER|"); 180 } 181 if ((caps & CAPS_AA_SHADER) != 0) { 182 buf.append("CAPS_AA_SHADER|"); 183 } 184 if ((caps & CAPS_DEVICE_OK) != 0) { 185 buf.append("CAPS_DEVICE_OK|"); 186 } |