in skiko/src/awtMain/cpp/windows/AngleRedrawer.cc [92:180]
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_AngleRedrawerKt_createAngleDevice(
JNIEnv *env, jobject redrawer, jlong platformInfoPtr, jboolean transparency)
{
__try
{
JAWT_Win32DrawingSurfaceInfo *dsi_win = fromJavaPointer<JAWT_Win32DrawingSurfaceInfo *>(platformInfoPtr);
HWND hwnd = dsi_win->hwnd;
HDC hdc = GetDC(hwnd);
if (transparency)
{
enableTransparentWindow(hwnd);
}
AngleDevice *angleDevice = new AngleDevice();
angleDevice->window = hwnd;
angleDevice->device = hdc;
angleDevice->display = getAngleEGLDisplay(angleDevice->device);
if (EGL_NO_DISPLAY == angleDevice->display)
{
throwJavaRenderExceptionWithMessage(env, __FUNCTION__, "Could not get display!");
return (jlong) 0;
}
EGLint majorVersion;
EGLint minorVersion;
if (!eglInitialize(angleDevice->display, &majorVersion, &minorVersion))
{
throwJavaRenderExceptionWithMessage(env, __FUNCTION__, "Could not initialize display!");
return (jlong) 0;
}
static constexpr int fSampleCount = 1;
static constexpr int sampleBuffers = fSampleCount > 1 ? 1 : 0;
static constexpr int eglSampleCnt = fSampleCount > 1 ? fSampleCount : 0;
static constexpr EGLint configAttribs[] = {
// We currently only support ES3.
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_SAMPLE_BUFFERS, sampleBuffers,
EGL_SAMPLES, eglSampleCnt,
EGL_NONE, EGL_NONE
};
EGLint numConfigs;
if (!eglChooseConfig(angleDevice->display, configAttribs, &angleDevice->surfaceConfig, 1, &numConfigs))
{
throwJavaRenderExceptionWithMessage(env, __FUNCTION__, "Could not create choose config!");
return (jlong) 0;
}
// We currently only support ES3.
static constexpr EGLint contextAttribs[] = {
EGL_CONTEXT_MAJOR_VERSION, 3,
EGL_CONTEXT_MINOR_VERSION, 0,
EGL_NONE, EGL_NONE
};
angleDevice->context = eglCreateContext(angleDevice->display, angleDevice->surfaceConfig, nullptr, contextAttribs);
if (EGL_NO_CONTEXT == angleDevice->context)
{
throwJavaRenderExceptionWithMessage(env, __FUNCTION__, "Could not create context!");
return (jlong) 0;
}
// initial surface
if (!initAngleSurface(env, angleDevice, 0, 0))
{
throwJavaRenderExceptionWithMessage(env, __FUNCTION__, "Could not create surface!");
return (jlong) 0;
}
sk_sp<const GrGLInterface> glInterface(GrGLMakeAssembledInterface(
nullptr,
[](void *ctx, const char name[]) -> GrGLFuncPtr { return eglGetProcAddress(name); }));
angleDevice->backendContext = glInterface;
return toJavaPointer(angleDevice);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
auto code = GetExceptionCode();
throwJavaRenderExceptionByExceptionCode(env, __FUNCTION__, code);
}
return (jlong) 0;
}