1 /*
2 * Copyright (c) 2004, 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
41 */
42
43 extern LockFunc OGLSD_Lock;
44 extern GetRasInfoFunc OGLSD_GetRasInfo;
45 extern UnlockFunc OGLSD_Unlock;
46 extern DisposeFunc OGLSD_Dispose;
47
48 extern OGLPixelFormat PixelFormats[];
49 extern void AwtWindow_UpdateWindow(JNIEnv *env, jobject peer,
50 jint w, jint h, HBITMAP hBitmap);
51 extern HBITMAP BitmapUtil_CreateBitmapFromARGBPre(int width, int height,
52 int srcStride,
53 int* imageData);
54 extern void AwtComponent_GetInsets(JNIEnv *env, jobject peer, RECT *insets);
55
56 extern void
57 OGLSD_SetNativeDimensions(JNIEnv *env, OGLSDOps *oglsdo, jint w, jint h);
58
59 JNIEXPORT void JNICALL
60 Java_sun_java2d_opengl_WGLSurfaceData_initOps(JNIEnv *env, jobject wglsd,
61 jlong pConfigInfo,
62 jobject peer, jlong hwnd)
63 {
64 OGLSDOps *oglsdo = (OGLSDOps *)SurfaceData_InitOps(env, wglsd,
65 sizeof(OGLSDOps));
66 WGLSDOps *wglsdo = (WGLSDOps *)malloc(sizeof(WGLSDOps));
67
68 J2dTraceLn(J2D_TRACE_INFO, "WGLSurfaceData_initOps");
69
70 if (wglsdo == NULL) {
71 JNU_ThrowOutOfMemoryError(env, "creating native wgl ops");
72 return;
73 }
74 if (oglsdo == NULL) {
75 free(wglsdo);
76 JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
77 return;
78 }
79
80 oglsdo->privOps = wglsdo;
81
82 oglsdo->sdOps.Lock = OGLSD_Lock;
83 oglsdo->sdOps.GetRasInfo = OGLSD_GetRasInfo;
84 oglsdo->sdOps.Unlock = OGLSD_Unlock;
85 oglsdo->sdOps.Dispose = OGLSD_Dispose;
86
143
144 J2dTraceLn(J2D_TRACE_INFO, "WGLSD_MakeCurrentToScratch");
145
146 if (oglc == NULL) {
147 J2dRlsTraceLn(J2D_TRACE_ERROR,
148 "WGLSD_MakeCurrentToScratch: context is null");
149 return JNI_FALSE;
150 }
151
152 ctxInfo = (WGLCtxInfo *)oglc->ctxInfo;
153 if (!j2d_wglMakeCurrent(ctxInfo->scratchSurfaceDC, ctxInfo->context)) {
154 J2dRlsTraceLn(J2D_TRACE_ERROR,
155 "WGLSD_MakeCurrentToScratch: could not make current");
156 return JNI_FALSE;
157 }
158
159 return JNI_TRUE;
160 }
161
162 /**
163 * Returns a pointer (as a jlong) to the native WGLGraphicsConfigInfo
164 * associated with the given OGLSDOps. This method can be called from
165 * shared code to retrieve the native GraphicsConfig data in a platform-
166 * independent manner.
167 */
168 jlong
169 OGLSD_GetNativeConfigInfo(OGLSDOps *oglsdo)
170 {
171 WGLSDOps *wglsdo;
172
173 if (oglsdo == NULL) {
174 J2dRlsTraceLn(J2D_TRACE_ERROR,
175 "OGLSD_GetNativeConfigInfo: ops are null");
176 return 0L;
177 }
178
179 wglsdo = (WGLSDOps *)oglsdo->privOps;
180 if (wglsdo == NULL) {
181 J2dRlsTraceLn(J2D_TRACE_ERROR,
182 "OGLSD_GetNativeConfigInfo: wgl ops are null");
183 return 0L;
184 }
185
186 return ptr_to_jlong(wglsdo->configInfo);
187 }
188
189 /**
190 * Makes the given GraphicsConfig's context current to its associated
191 * "scratch" surface. If there is a problem making the context current,
192 * this method will return NULL; otherwise, returns a pointer to the
193 * OGLContext that is associated with the given GraphicsConfig.
194 */
195 OGLContext *
196 OGLSD_SetScratchSurface(JNIEnv *env, jlong pConfigInfo)
197 {
198 WGLGraphicsConfigInfo *wglInfo =
199 (WGLGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
200 OGLContext *oglc;
201
202 J2dTraceLn(J2D_TRACE_INFO, "OGLSD_SetScratchContext");
203
204 if (wglInfo == NULL) {
205 J2dRlsTraceLn(J2D_TRACE_ERROR,
206 "OGLSD_SetScratchContext: wgl config info is null");
207 return NULL;
208 }
209
|
1 /*
2 * Copyright (c) 2004, 2019, 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
41 */
42
43 extern LockFunc OGLSD_Lock;
44 extern GetRasInfoFunc OGLSD_GetRasInfo;
45 extern UnlockFunc OGLSD_Unlock;
46 extern DisposeFunc OGLSD_Dispose;
47
48 extern OGLPixelFormat PixelFormats[];
49 extern void AwtWindow_UpdateWindow(JNIEnv *env, jobject peer,
50 jint w, jint h, HBITMAP hBitmap);
51 extern HBITMAP BitmapUtil_CreateBitmapFromARGBPre(int width, int height,
52 int srcStride,
53 int* imageData);
54 extern void AwtComponent_GetInsets(JNIEnv *env, jobject peer, RECT *insets);
55
56 extern void
57 OGLSD_SetNativeDimensions(JNIEnv *env, OGLSDOps *oglsdo, jint w, jint h);
58
59 JNIEXPORT void JNICALL
60 Java_sun_java2d_opengl_WGLSurfaceData_initOps(JNIEnv *env, jobject wglsd,
61 jobject gc, jlong pConfigInfo,
62 jobject peer, jlong hwnd)
63 {
64 OGLSDOps *oglsdo;
65 WGLSDOps *wglsdo;
66
67 gc = (*env)->NewGlobalRef(env, gc);
68 if (gc == NULL) {
69 JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
70 return;
71 }
72
73 oglsdo = (OGLSDOps *)SurfaceData_InitOps(env, wglsd,
74 sizeof(OGLSDOps));
75 if (oglsdo == NULL) {
76 (*env)->DeleteGlobalRef(env, gc);
77 JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
78 return;
79 }
80 // later the graphicsConfig will be used for deallocation of oglsdo
81 oglsdo->graphicsConfig = gc;
82
83 wglsdo = (WGLSDOps *)malloc(sizeof(WGLSDOps));
84
85 J2dTraceLn(J2D_TRACE_INFO, "WGLSurfaceData_initOps");
86
87 if (wglsdo == NULL) {
88 JNU_ThrowOutOfMemoryError(env, "creating native wgl ops");
89 return;
90 }
91 if (oglsdo == NULL) {
92 free(wglsdo);
93 JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
94 return;
95 }
96
97 oglsdo->privOps = wglsdo;
98
99 oglsdo->sdOps.Lock = OGLSD_Lock;
100 oglsdo->sdOps.GetRasInfo = OGLSD_GetRasInfo;
101 oglsdo->sdOps.Unlock = OGLSD_Unlock;
102 oglsdo->sdOps.Dispose = OGLSD_Dispose;
103
160
161 J2dTraceLn(J2D_TRACE_INFO, "WGLSD_MakeCurrentToScratch");
162
163 if (oglc == NULL) {
164 J2dRlsTraceLn(J2D_TRACE_ERROR,
165 "WGLSD_MakeCurrentToScratch: context is null");
166 return JNI_FALSE;
167 }
168
169 ctxInfo = (WGLCtxInfo *)oglc->ctxInfo;
170 if (!j2d_wglMakeCurrent(ctxInfo->scratchSurfaceDC, ctxInfo->context)) {
171 J2dRlsTraceLn(J2D_TRACE_ERROR,
172 "WGLSD_MakeCurrentToScratch: could not make current");
173 return JNI_FALSE;
174 }
175
176 return JNI_TRUE;
177 }
178
179 /**
180 * Makes the given GraphicsConfig's context current to its associated
181 * "scratch" surface. If there is a problem making the context current,
182 * this method will return NULL; otherwise, returns a pointer to the
183 * OGLContext that is associated with the given GraphicsConfig.
184 */
185 OGLContext *
186 OGLSD_SetScratchSurface(JNIEnv *env, jlong pConfigInfo)
187 {
188 WGLGraphicsConfigInfo *wglInfo =
189 (WGLGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
190 OGLContext *oglc;
191
192 J2dTraceLn(J2D_TRACE_INFO, "OGLSD_SetScratchContext");
193
194 if (wglInfo == NULL) {
195 J2dRlsTraceLn(J2D_TRACE_ERROR,
196 "OGLSD_SetScratchContext: wgl config info is null");
197 return NULL;
198 }
199
|