Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/java2d/opengl/GLXSurfaceData.c
32288 views
1
/*
2
* Copyright (c) 2003, 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
23
* questions.
24
*/
25
26
#include <jlong.h>
27
28
#include "sun_java2d_opengl_GLXSurfaceData.h"
29
30
#include "OGLRenderQueue.h"
31
#include "GLXGraphicsConfig.h"
32
#include "GLXSurfaceData.h"
33
#include "awt_Component.h"
34
#include "awt_GraphicsEnv.h"
35
36
/**
37
* The methods in this file implement the native windowing system specific
38
* layer (GLX) for the OpenGL-based Java 2D pipeline.
39
*/
40
41
#ifndef HEADLESS
42
43
extern LockFunc OGLSD_Lock;
44
extern GetRasInfoFunc OGLSD_GetRasInfo;
45
extern UnlockFunc OGLSD_Unlock;
46
extern DisposeFunc OGLSD_Dispose;
47
48
extern void
49
OGLSD_SetNativeDimensions(JNIEnv *env, OGLSDOps *oglsdo, jint w, jint h);
50
51
jboolean surfaceCreationFailed = JNI_FALSE;
52
53
#endif /* !HEADLESS */
54
55
JNIEXPORT void JNICALL
56
Java_sun_java2d_opengl_GLXSurfaceData_initOps(JNIEnv *env, jobject glxsd,
57
jobject gc,
58
jobject peer, jlong aData)
59
{
60
#ifndef HEADLESS
61
gc = (*env)->NewGlobalRef(env, gc);
62
if (gc == NULL) {
63
JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
64
return;
65
}
66
67
OGLSDOps *oglsdo = (OGLSDOps *)SurfaceData_InitOps(env, glxsd,
68
sizeof(OGLSDOps));
69
if (oglsdo == NULL) {
70
(*env)->DeleteGlobalRef(env, gc);
71
JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
72
return;
73
}
74
// later the graphicsConfig will be used for deallocation of oglsdo
75
oglsdo->graphicsConfig = gc;
76
77
GLXSDOps *glxsdo = (GLXSDOps *)malloc(sizeof(GLXSDOps));
78
79
if (glxsdo == NULL) {
80
JNU_ThrowOutOfMemoryError(env, "creating native GLX ops");
81
return;
82
}
83
84
J2dTraceLn(J2D_TRACE_INFO, "GLXSurfaceData_initOps");
85
86
oglsdo->privOps = glxsdo;
87
88
oglsdo->sdOps.Lock = OGLSD_Lock;
89
oglsdo->sdOps.GetRasInfo = OGLSD_GetRasInfo;
90
oglsdo->sdOps.Unlock = OGLSD_Unlock;
91
oglsdo->sdOps.Dispose = OGLSD_Dispose;
92
93
oglsdo->drawableType = OGLSD_UNDEFINED;
94
oglsdo->activeBuffer = GL_FRONT;
95
oglsdo->needsInit = JNI_TRUE;
96
97
if (peer != NULL) {
98
glxsdo->window = JNU_CallMethodByName(env, NULL, peer,
99
"getContentWindow", "()J").j;
100
} else {
101
glxsdo->window = 0;
102
}
103
glxsdo->configData = (AwtGraphicsConfigDataPtr)jlong_to_ptr(aData);
104
if (glxsdo->configData == NULL) {
105
free(glxsdo);
106
JNU_ThrowNullPointerException(env,
107
"Native GraphicsConfig data block missing");
108
return;
109
}
110
111
if (glxsdo->configData->glxInfo == NULL) {
112
free(glxsdo);
113
JNU_ThrowNullPointerException(env, "GLXGraphicsConfigInfo missing");
114
return;
115
}
116
#endif /* HEADLESS */
117
}
118
119
#ifndef HEADLESS
120
121
/**
122
* This function disposes of any native windowing system resources associated
123
* with this surface. For instance, if the given OGLSDOps is of type
124
* OGLSD_PBUFFER, this method implementation will destroy the actual pbuffer
125
* surface.
126
*/
127
void
128
OGLSD_DestroyOGLSurface(JNIEnv *env, OGLSDOps *oglsdo)
129
{
130
GLXSDOps *glxsdo = (GLXSDOps *)oglsdo->privOps;
131
132
J2dTraceLn(J2D_TRACE_INFO, "OGLSD_DestroyOGLSurface");
133
134
if (oglsdo->drawableType == OGLSD_PBUFFER) {
135
if (glxsdo->drawable != 0) {
136
j2d_glXDestroyPbuffer(awt_display, glxsdo->drawable);
137
glxsdo->drawable = 0;
138
}
139
} else if (oglsdo->drawableType == OGLSD_WINDOW) {
140
// X Window is free'd later by AWT code...
141
}
142
}
143
144
/**
145
* Makes the given context current to its associated "scratch" surface. If
146
* the operation is successful, this method will return JNI_TRUE; otherwise,
147
* returns JNI_FALSE.
148
*/
149
static jboolean
150
GLXSD_MakeCurrentToScratch(JNIEnv *env, OGLContext *oglc)
151
{
152
GLXCtxInfo *ctxInfo;
153
154
J2dTraceLn(J2D_TRACE_INFO, "GLXSD_MakeCurrentToScratch");
155
156
if (oglc == NULL) {
157
J2dRlsTraceLn(J2D_TRACE_ERROR,
158
"GLXSD_MakeCurrentToScratch: context is null");
159
return JNI_FALSE;
160
}
161
162
ctxInfo = (GLXCtxInfo *)oglc->ctxInfo;
163
if (!j2d_glXMakeContextCurrent(awt_display,
164
ctxInfo->scratchSurface,
165
ctxInfo->scratchSurface,
166
ctxInfo->context))
167
{
168
J2dRlsTraceLn(J2D_TRACE_ERROR,
169
"GLXSD_MakeCurrentToScratch: could not make current");
170
return JNI_FALSE;
171
}
172
173
return JNI_TRUE;
174
}
175
176
/**
177
* Makes the given GraphicsConfig's context current to its associated
178
* "scratch" surface. If there is a problem making the context current,
179
* this method will return NULL; otherwise, returns a pointer to the
180
* OGLContext that is associated with the given GraphicsConfig.
181
*/
182
OGLContext *
183
OGLSD_SetScratchSurface(JNIEnv *env, jlong pConfigInfo)
184
{
185
GLXGraphicsConfigInfo *glxInfo =
186
(GLXGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
187
OGLContext *oglc;
188
189
J2dTraceLn(J2D_TRACE_INFO, "OGLSD_SetScratchContext");
190
191
if (glxInfo == NULL) {
192
J2dRlsTraceLn(J2D_TRACE_ERROR,
193
"OGLSD_SetScratchContext: glx config info is null");
194
return NULL;
195
}
196
197
oglc = glxInfo->context;
198
if (!GLXSD_MakeCurrentToScratch(env, oglc)) {
199
return NULL;
200
}
201
202
if (OGLC_IS_CAP_PRESENT(oglc, CAPS_EXT_FBOBJECT)) {
203
// the GL_EXT_framebuffer_object extension is present, so this call
204
// will ensure that we are bound to the scratch pbuffer (and not
205
// some other framebuffer object)
206
j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
207
}
208
209
return oglc;
210
}
211
212
/**
213
* Makes a context current to the given source and destination
214
* surfaces. If there is a problem making the context current, this method
215
* will return NULL; otherwise, returns a pointer to the OGLContext that is
216
* associated with the destination surface.
217
*/
218
OGLContext *
219
OGLSD_MakeOGLContextCurrent(JNIEnv *env, OGLSDOps *srcOps, OGLSDOps *dstOps)
220
{
221
GLXSDOps *dstGLXOps = (GLXSDOps *)dstOps->privOps;
222
OGLContext *oglc;
223
224
J2dTraceLn(J2D_TRACE_INFO, "OGLSD_MakeOGLContextCurrent");
225
226
oglc = dstGLXOps->configData->glxInfo->context;
227
if (oglc == NULL) {
228
J2dRlsTraceLn(J2D_TRACE_ERROR,
229
"OGLSD_MakeOGLContextCurrent: context is null");
230
return NULL;
231
}
232
233
if (dstOps->drawableType == OGLSD_FBOBJECT) {
234
OGLContext *currentContext = OGLRenderQueue_GetCurrentContext();
235
236
// first make sure we have a current context (if the context isn't
237
// already current to some drawable, we will make it current to
238
// its scratch surface)
239
if (oglc != currentContext) {
240
if (!GLXSD_MakeCurrentToScratch(env, oglc)) {
241
return NULL;
242
}
243
}
244
245
// now bind to the fbobject associated with the destination surface;
246
// this means that all rendering will go into the fbobject destination
247
// (note that we unbind the currently bound texture first; this is
248
// recommended procedure when binding an fbobject)
249
j2d_glBindTexture(dstOps->textureTarget, 0);
250
j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, dstOps->fbobjectID);
251
} else {
252
GLXSDOps *srcGLXOps = (GLXSDOps *)srcOps->privOps;
253
GLXCtxInfo *ctxinfo = (GLXCtxInfo *)oglc->ctxInfo;
254
255
// make the context current
256
if (!j2d_glXMakeContextCurrent(awt_display,
257
dstGLXOps->drawable,
258
srcGLXOps->drawable,
259
ctxinfo->context))
260
{
261
J2dRlsTraceLn(J2D_TRACE_ERROR,
262
"OGLSD_MakeOGLContextCurrent: could not make current");
263
return NULL;
264
}
265
266
if (OGLC_IS_CAP_PRESENT(oglc, CAPS_EXT_FBOBJECT)) {
267
// the GL_EXT_framebuffer_object extension is present, so we
268
// must bind to the default (windowing system provided)
269
// framebuffer
270
j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
271
}
272
}
273
274
return oglc;
275
}
276
277
/**
278
* This function initializes a native window surface and caches the window
279
* bounds in the given OGLSDOps. Returns JNI_TRUE if the operation was
280
* successful; JNI_FALSE otherwise.
281
*/
282
jboolean
283
OGLSD_InitOGLWindow(JNIEnv *env, OGLSDOps *oglsdo)
284
{
285
GLXSDOps *glxsdo;
286
Window window;
287
XWindowAttributes attr;
288
289
J2dTraceLn(J2D_TRACE_INFO, "OGLSD_InitOGLWindow");
290
291
if (oglsdo == NULL) {
292
J2dRlsTraceLn(J2D_TRACE_ERROR,
293
"OGLSD_InitOGLWindow: ops are null");
294
return JNI_FALSE;
295
}
296
297
glxsdo = (GLXSDOps *)oglsdo->privOps;
298
if (glxsdo == NULL) {
299
J2dRlsTraceLn(J2D_TRACE_ERROR,
300
"OGLSD_InitOGLWindow: glx ops are null");
301
return JNI_FALSE;
302
}
303
304
window = glxsdo->window;
305
if (window == 0) {
306
J2dRlsTraceLn(J2D_TRACE_ERROR,
307
"OGLSD_InitOGLWindow: window is invalid");
308
return JNI_FALSE;
309
}
310
311
XGetWindowAttributes(awt_display, window, &attr);
312
oglsdo->width = attr.width;
313
oglsdo->height = attr.height;
314
315
oglsdo->drawableType = OGLSD_WINDOW;
316
oglsdo->isOpaque = JNI_TRUE;
317
oglsdo->xOffset = 0;
318
oglsdo->yOffset = 0;
319
glxsdo->drawable = window;
320
glxsdo->xdrawable = window;
321
322
J2dTraceLn2(J2D_TRACE_VERBOSE, " created window: w=%d h=%d",
323
oglsdo->width, oglsdo->height);
324
325
return JNI_TRUE;
326
}
327
328
static int
329
GLXSD_BadAllocXErrHandler(Display *display, XErrorEvent *xerr)
330
{
331
if (xerr->error_code == BadAlloc) {
332
surfaceCreationFailed = JNI_TRUE;
333
}
334
return 0;
335
}
336
337
JNIEXPORT jboolean JNICALL
338
Java_sun_java2d_opengl_GLXSurfaceData_initPbuffer
339
(JNIEnv *env, jobject glxsd,
340
jlong pData, jlong pConfigInfo,
341
jboolean isOpaque,
342
jint width, jint height)
343
{
344
OGLSDOps *oglsdo = (OGLSDOps *)jlong_to_ptr(pData);
345
GLXGraphicsConfigInfo *glxinfo =
346
(GLXGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
347
GLXSDOps *glxsdo;
348
GLXPbuffer pbuffer;
349
int attrlist[] = {GLX_PBUFFER_WIDTH, 0,
350
GLX_PBUFFER_HEIGHT, 0,
351
GLX_PRESERVED_CONTENTS, GL_FALSE, 0};
352
353
J2dTraceLn3(J2D_TRACE_INFO,
354
"GLXSurfaceData_initPbuffer: w=%d h=%d opq=%d",
355
width, height, isOpaque);
356
357
if (oglsdo == NULL) {
358
J2dRlsTraceLn(J2D_TRACE_ERROR,
359
"GLXSurfaceData_initPbuffer: ops are null");
360
return JNI_FALSE;
361
}
362
363
glxsdo = (GLXSDOps *)oglsdo->privOps;
364
if (glxsdo == NULL) {
365
J2dRlsTraceLn(J2D_TRACE_ERROR,
366
"GLXSurfaceData_initPbuffer: glx ops are null");
367
return JNI_FALSE;
368
}
369
370
if (glxinfo == NULL) {
371
J2dRlsTraceLn(J2D_TRACE_ERROR,
372
"GLXSurfaceData_initPbuffer: glx config info is null");
373
return JNI_FALSE;
374
}
375
376
attrlist[1] = width;
377
attrlist[3] = height;
378
379
surfaceCreationFailed = JNI_FALSE;
380
EXEC_WITH_XERROR_HANDLER(
381
GLXSD_BadAllocXErrHandler,
382
pbuffer = j2d_glXCreatePbuffer(awt_display,
383
glxinfo->fbconfig, attrlist));
384
if ((pbuffer == 0) || surfaceCreationFailed) {
385
J2dRlsTraceLn(J2D_TRACE_ERROR,
386
"GLXSurfaceData_initPbuffer: could not create glx pbuffer");
387
return JNI_FALSE;
388
}
389
390
oglsdo->drawableType = OGLSD_PBUFFER;
391
oglsdo->isOpaque = isOpaque;
392
oglsdo->width = width;
393
oglsdo->height = height;
394
oglsdo->xOffset = 0;
395
oglsdo->yOffset = 0;
396
397
glxsdo->drawable = pbuffer;
398
glxsdo->xdrawable = 0;
399
400
OGLSD_SetNativeDimensions(env, oglsdo, width, height);
401
402
return JNI_TRUE;
403
}
404
405
void
406
OGLSD_SwapBuffers(JNIEnv *env, jlong window)
407
{
408
J2dTraceLn(J2D_TRACE_INFO, "OGLSD_SwapBuffers");
409
410
if (window == 0L) {
411
J2dRlsTraceLn(J2D_TRACE_ERROR,
412
"OGLSD_SwapBuffers: window is null");
413
return;
414
}
415
416
j2d_glXSwapBuffers(awt_display, (Window)window);
417
}
418
419
// needed by Mac OS X port, no-op on other platforms
420
void
421
OGLSD_Flush(JNIEnv *env)
422
{
423
}
424
425
#endif /* !HEADLESS */
426
427