History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/java2d/opengl/OGLContext.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/java2d/opengl/OGLContext.java+220−0
@@ -0,0 +1,220 @@
1+/*
2+ * Copyright (c) 2004, 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.opengl;
27+
28+import sun.java2d.pipe.BufferedContext;
29+import sun.java2d.pipe.RenderBuffer;
30+import sun.java2d.pipe.RenderQueue;
31+import sun.java2d.pipe.hw.ContextCapabilities;
32+import static sun.java2d.pipe.BufferedOpCodes.*;
33+import static sun.java2d.pipe.hw.ContextCapabilities.*;
34+
35+/**
36+ * Note that the RenderQueue lock must be acquired before calling any of
37+ * the methods in this class.
38+ */
39+public class OGLContext extends BufferedContext {
40+
41+ private final OGLGraphicsConfig config;
42+
43+ OGLContext(RenderQueue rq, OGLGraphicsConfig config) {
44+ super(rq);
45+ this.config = config;
46+ }
47+
48+ /**
49+ * Convenience method that delegates to setScratchSurface() below.
50+ */
51+ static void setScratchSurface(OGLGraphicsConfig gc) {
52+ setScratchSurface(gc.getNativeConfigInfo());
53+ }
54+
55+ /**
56+ * Makes the given GraphicsConfig's context current to its associated
57+ * "scratch surface". Each GraphicsConfig maintains a native context
58+ * (GLXContext on Unix, HGLRC on Windows) as well as a native pbuffer
59+ * known as the "scratch surface". By making the context current to the
60+ * scratch surface, we are assured that we have a current context for
61+ * the relevant GraphicsConfig, and can therefore perform operations
62+ * depending on the capabilities of that GraphicsConfig. For example,
63+ * if the GraphicsConfig supports the GL_ARB_texture_non_power_of_two
64+ * extension, then we should be able to make a non-pow2 texture for this
65+ * GraphicsConfig once we make the context current to the scratch surface.
66+ *
67+ * This method should be used for operations with an OpenGL texture
68+ * as the destination surface (e.g. a sw->texture blit loop), or in those
69+ * situations where we may not otherwise have a current context (e.g.
70+ * when disposing a texture-based surface).
71+ */
72+ static void setScratchSurface(long pConfigInfo) {
73+ // assert OGLRenderQueue.getInstance().lock.isHeldByCurrentThread();
74+
75+ // invalidate the current context
76+ currentContext = null;
77+
78+ // set the scratch context
79+ OGLRenderQueue rq = OGLRenderQueue.getInstance();
80+ RenderBuffer buf = rq.getBuffer();
81+ rq.ensureCapacityAndAlignment(12, 4);
82+ buf.putInt(SET_SCRATCH_SURFACE);
83+ buf.putLong(pConfigInfo);
84+ }
85+
86+ /**
87+ * Invalidates the currentContext field to ensure that we properly
88+ * revalidate the OGLContext (make it current, etc.) next time through
89+ * the validate() method. This is typically invoked from methods
90+ * that affect the current context state (e.g. disposing a context or
91+ * surface).
92+ */
93+ static void invalidateCurrentContext() {
94+ // assert OGLRenderQueue.getInstance().lock.isHeldByCurrentThread();
95+
96+ // invalidate the current Java-level context so that we
97+ // revalidate everything the next time around
98+ if (currentContext != null) {
99+ currentContext.invalidateContext();
100+ currentContext = null;
101+ }
102+
103+ // invalidate the context reference at the native level, and
104+ // then flush the queue so that we have no pending operations
105+ // dependent on the current context
106+ OGLRenderQueue rq = OGLRenderQueue.getInstance();
107+ rq.ensureCapacity(4);
108+ rq.getBuffer().putInt(INVALIDATE_CONTEXT);
109+ rq.flushNow();
110+ }
111+
112+ public RenderQueue getRenderQueue() {
113+ return OGLRenderQueue.getInstance();
114+ }
115+
116+ /**
117+ * Returns a string representing adapter id (vendor, renderer, version).
118+ * Must be called on the rendering thread.
119+ *
120+ * @return an id string for the adapter
121+ */
122+ static final native String getOGLIdString();
123+
124+ @Override
125+ public void saveState() {
126+ // assert rq.lock.isHeldByCurrentThread();
127+
128+ // reset all attributes of this and current contexts
129+ invalidateContext();
130+ invalidateCurrentContext();
131+
132+ setScratchSurface(config);
133+
134+ // save the state on the native level
135+ rq.ensureCapacity(4);
136+ buf.putInt(SAVE_STATE);
137+ rq.flushNow();
138+ }
139+
140+ @Override
141+ public void restoreState() {
142+ // assert rq.lock.isHeldByCurrentThread();
143+
144+ // reset all attributes of this and current contexts
145+ invalidateContext();
146+ invalidateCurrentContext();
147+
148+ setScratchSurface(config);
149+
150+ // restore the state on the native level
151+ rq.ensureCapacity(4);
152+ buf.putInt(RESTORE_STATE);
153+ rq.flushNow();
154+ }
155+
156+ static class OGLContextCaps extends ContextCapabilities {
157+ /**
158+ * Indicates the presence of the GL_EXT_framebuffer_object extension.
159+ * This cap will only be set if the fbobject system property has been
160+ * enabled and we are able to create an FBO with depth buffer.
161+ */
162+ static final int CAPS_EXT_FBOBJECT =
163+ (CAPS_RT_TEXTURE_ALPHA | CAPS_RT_TEXTURE_OPAQUE);
164+ /** Indicates that the context supports a stored alpha channel. */
165+ static final int CAPS_STORED_ALPHA = CAPS_RT_PLAIN_ALPHA;
166+ /** Indicates that the context is doublebuffered. */
167+ static final int CAPS_DOUBLEBUFFERED = (FIRST_PRIVATE_CAP << 0);
168+ /**
169+ * Indicates the presence of the GL_ARB_fragment_shader extension.
170+ * This cap will only be set if the lcdshader system property has been
171+ * enabled and the hardware supports the minimum number of texture units
172+ */
173+ static final int CAPS_EXT_LCD_SHADER = (FIRST_PRIVATE_CAP << 1);
174+ /**
175+ * Indicates the presence of the GL_ARB_fragment_shader extension.
176+ * This cap will only be set if the biopshader system property has been
177+ * enabled and the hardware meets our minimum requirements.
178+ */
179+ static final int CAPS_EXT_BIOP_SHADER = (FIRST_PRIVATE_CAP << 2);
180+ /**
181+ * Indicates the presence of the GL_ARB_fragment_shader extension.
182+ * This cap will only be set if the gradshader system property has been
183+ * enabled and the hardware meets our minimum requirements.
184+ */
185+ static final int CAPS_EXT_GRAD_SHADER = (FIRST_PRIVATE_CAP << 3);
186+ /** Indicates the presence of the GL_ARB_texture_rectangle extension. */
187+ static final int CAPS_EXT_TEXRECT = (FIRST_PRIVATE_CAP << 4);
188+
189+ OGLContextCaps(int caps, String adapterId) {
190+ super(caps, adapterId);
191+ }
192+
193+ @Override
194+ public String toString() {
195+ StringBuffer buf = new StringBuffer(super.toString());
196+ if ((caps & CAPS_EXT_FBOBJECT) != 0) {
197+ buf.append("CAPS_EXT_FBOBJECT|");
198+ }
199+ if ((caps & CAPS_STORED_ALPHA) != 0) {
200+ buf.append("CAPS_STORED_ALPHA|");
201+ }
202+ if ((caps & CAPS_DOUBLEBUFFERED) != 0) {
203+ buf.append("CAPS_DOUBLEBUFFERED|");
204+ }
205+ if ((caps & CAPS_EXT_LCD_SHADER) != 0) {
206+ buf.append("CAPS_EXT_LCD_SHADER|");
207+ }
208+ if ((caps & CAPS_EXT_BIOP_SHADER) != 0) {
209+ buf.append("CAPS_BIOP_SHADER|");
210+ }
211+ if ((caps & CAPS_EXT_GRAD_SHADER) != 0) {
212+ buf.append("CAPS_EXT_GRAD_SHADER|");
213+ }
214+ if ((caps & CAPS_EXT_TEXRECT) != 0) {
215+ buf.append("CAPS_EXT_TEXRECT|");
216+ }
217+ return buf.toString();
218+ }
219+ }
220+}