001: /*
002: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.java2d.opengl;
027:
028: import java.awt.AlphaComposite;
029: import java.awt.Composite;
030: import java.awt.Paint;
031: import java.awt.geom.AffineTransform;
032: import sun.java2d.SunGraphics2D;
033: import sun.java2d.pipe.BufferedContext;
034: import sun.java2d.pipe.Region;
035: import sun.java2d.pipe.RenderBuffer;
036: import sun.java2d.pipe.RenderQueue;
037: import static sun.java2d.pipe.BufferedOpCodes.*;
038:
039: /**
040: * Note that the RenderQueue lock must be acquired before calling any of
041: * the methods in this class.
042: */
043: class OGLContext extends BufferedContext {
044:
045: /** Indicates that the context has no capabilities. */
046: static final int CAPS_EMPTY = (0 << 0);
047: /** Indicates that the context is doublebuffered. */
048: static final int CAPS_DOUBLEBUFFERED = (1 << 0);
049: /** Indicates that the context supports a stored alpha channel. */
050: static final int CAPS_STORED_ALPHA = (1 << 1);
051: /** Indicates the presence of the GL_ARB_multitexture extension. */
052: static final int CAPS_EXT_MULTITEXTURE = (1 << 2);
053: /** Indicates the presence of the GL_ARB_texture_non_power_of_two ext. */
054: static final int CAPS_EXT_TEXNONPOW2 = (1 << 3);
055: /**
056: * Indicates the presence of the GL_EXT_framebuffer_object extension.
057: * This cap will only be set if the fbobject system property has been
058: * enabled and we are able to create an FBO with depth buffer.
059: */
060: static final int CAPS_EXT_FBOBJECT = (1 << 4);
061: /**
062: * Indicates the presence of the GL_ARB_fragment_shader extension.
063: * This cap will only be set if the lcdshader system property has been
064: * enabled and the hardware supports the minimum number of texture units.
065: */
066: static final int CAPS_EXT_LCD_SHADER = (1 << 5);
067: /** Indicates the presence of the GL_ARB_texture_rectangle extension. */
068: static final int CAPS_EXT_TEXRECT = (1 << 6);
069: /**
070: * Indicates the presence of the GL_ARB_fragment_shader extension.
071: * This cap will only be set if the biopshader system property has been
072: * enabled and the hardware meets our minimum requirements.
073: */
074: static final int CAPS_EXT_BIOP_SHADER = (1 << 7);
075: /**
076: * Indicates the presence of the GL_ARB_fragment_shader extension.
077: * This cap will only be set if the gradshader system property has been
078: * enabled and the hardware meets our minimum requirements.
079: */
080: static final int CAPS_EXT_GRAD_SHADER = (1 << 8);
081:
082: OGLContext(RenderQueue rq) {
083: super (rq);
084: }
085:
086: /**
087: * Fetches the OGLContext associated with the current GraphicsConfig
088: * and validates the context using the given parameters. Most rendering
089: * operations will call this method first in order to set the necessary
090: * state before issuing rendering commands.
091: */
092: static void validateContext(OGLSurfaceData srcData,
093: OGLSurfaceData dstData, Region clip, Composite comp,
094: AffineTransform xform, Paint paint, SunGraphics2D sg2d,
095: int flags) {
096: // assert rq.lock.isHeldByCurrentThread();
097: OGLContext oglc = dstData.getContext();
098: oglc.validate(srcData, dstData, clip, comp, xform, paint, sg2d,
099: flags);
100: }
101:
102: /**
103: * Simplified version of validateContext() that disables all context
104: * state settings.
105: */
106: static void validateContext(OGLSurfaceData dstData) {
107: // assert rq.lock.isHeldByCurrentThread();
108: validateContext(dstData, dstData, null, null, null, null, null,
109: NO_CONTEXT_FLAGS);
110: }
111:
112: /**
113: * Convenience method that delegates to setScratchSurface() below.
114: */
115: static void setScratchSurface(OGLGraphicsConfig gc) {
116: setScratchSurface(gc.getNativeConfigInfo());
117: }
118:
119: /**
120: * Makes the given GraphicsConfig's context current to its associated
121: * "scratch surface". Each GraphicsConfig maintains a native context
122: * (GLXContext on Unix, HGLRC on Windows) as well as a native pbuffer
123: * known as the "scratch surface". By making the context current to the
124: * scratch surface, we are assured that we have a current context for
125: * the relevant GraphicsConfig, and can therefore perform operations
126: * depending on the capabilities of that GraphicsConfig. For example,
127: * if the GraphicsConfig supports the GL_ARB_texture_non_power_of_two
128: * extension, then we should be able to make a non-pow2 texture for this
129: * GraphicsConfig once we make the context current to the scratch surface.
130: *
131: * This method should be used for operations with an OpenGL texture
132: * as the destination surface (e.g. a sw->texture blit loop), or in those
133: * situations where we may not otherwise have a current context (e.g.
134: * when disposing a texture-based surface).
135: */
136: static void setScratchSurface(long pConfigInfo) {
137: // assert OGLRenderQueue.getInstance().lock.isHeldByCurrentThread();
138:
139: // invalidate the current context
140: currentContext = null;
141:
142: // set the scratch context
143: OGLRenderQueue rq = OGLRenderQueue.getInstance();
144: RenderBuffer buf = rq.getBuffer();
145: rq.ensureCapacityAndAlignment(12, 4);
146: buf.putInt(SET_SCRATCH_SURFACE);
147: buf.putLong(pConfigInfo);
148: }
149:
150: /**
151: * Invalidates the currentContext field to ensure that we properly
152: * revalidate the OGLContext (make it current, etc.) next time through
153: * the validate() method. This is typically invoked from methods
154: * that affect the current context state (e.g. disposing a context or
155: * surface).
156: */
157: static void invalidateCurrentContext() {
158: // assert OGLRenderQueue.getInstance().lock.isHeldByCurrentThread();
159:
160: // first invalidate the context reference at the native level, and
161: // then flush the queue so that we have no pending operations
162: // dependent on the current context
163: OGLRenderQueue rq = OGLRenderQueue.getInstance();
164: rq.ensureCapacity(4);
165: rq.getBuffer().putInt(INVALIDATE_CONTEXT);
166: rq.flushNow();
167:
168: // then invalidate the current Java-level context so that we
169: // revalidate everything the next time around
170: if (currentContext != null) {
171: currentContext.invalidateSurfaces();
172: currentContext = null;
173: }
174: }
175: }
|