EGL_CONTEXT_T *egl_context_create(EGL_CONTEXT_T *share_context, EGLContext name, EGLDisplay display, EGLConfig configname, EGL_CONTEXT_TYPE_T type) { EGL_CONTEXT_T *context = (EGL_CONTEXT_T *)khrn_platform_malloc(sizeof(EGL_CONTEXT_T), "EGL_CONTEXT_T"); if (!context) return 0; context->name = name; context->display = display; context->configname = configname; context->type = type; context->renderbuffer = EGL_NONE; context->is_current = false; context->is_destroyed = false; switch (type) { #ifndef NO_OPENVG case OPENVG: { VG_CLIENT_SHARED_STATE_T *shared_state; if (share_context) { shared_state = ((VG_CLIENT_STATE_T *)share_context->state)->shared_state; vg_client_shared_state_acquire(shared_state); } else { shared_state = vg_client_shared_state_alloc(); if (!shared_state) { khrn_platform_free(context); return 0; } } context->state = vg_client_state_alloc(shared_state); vg_client_shared_state_release(shared_state); if (!context->state) { khrn_platform_free(context); return 0; } { CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE(); /* uint64_t pid = khronos_platform_get_process_id(); */ /* unused */ context->servercontext = RPC_UINT_RES(RPC_CALL2_RES(eglIntCreateVG_impl, thread, EGLINTCREATEVG_ID, share_context ? share_context->servercontext : 0, share_context ? share_context->type : OPENVG/*ignored*/)); } if (!context->servercontext) { vg_client_state_free((VG_CLIENT_STATE_T *)context->state); khrn_platform_free(context); return 0; } break; } #endif /* NO_OPENVG */ case OPENGL_ES_11: { GLXX_CLIENT_STATE_T *state = (GLXX_CLIENT_STATE_T *)khrn_platform_malloc(sizeof(GLXX_CLIENT_STATE_T), "GLXX_CLIENT_STATE_T"); if (!state) { khrn_platform_free(context); return 0; } context->state = state; if (gl11_client_state_init(state)) { CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE(); context->servercontext = RPC_UINT_RES(RPC_CALL2_RES(eglIntCreateGLES11_impl, thread, EGLINTCREATEGLES11_ID, share_context ? share_context->servercontext : 0, share_context ? share_context->type : OPENGL_ES_11/*ignored*/)); if (!context->servercontext) { glxx_client_state_free(state); khrn_platform_free(context); return 0; } } break; } case OPENGL_ES_20: { GLXX_CLIENT_STATE_T *state = (GLXX_CLIENT_STATE_T *)khrn_platform_malloc(sizeof(GLXX_CLIENT_STATE_T), "GLXX_CLIENT_STATE_T"); if (!state) { khrn_platform_free(context); return 0; } context->state = state; if (gl20_client_state_init(state)) { CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE(); context->servercontext = RPC_UINT_RES(RPC_CALL2_RES(eglIntCreateGLES20_impl, thread, EGLINTCREATEGLES20_ID, share_context ? share_context->servercontext : 0, share_context ? share_context->type : OPENGL_ES_20/*ignored*/)); if (!context->servercontext) { glxx_client_state_free(state); khrn_platform_free(context); return 0; } } break; } default: UNREACHABLE(); break; } return context; }
void rpc_send_ctrl_end(void) { CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE(); vcos_assert(thread->merge_pos == thread->merge_end); }
uint64_t khronos_platform_get_process_id() { CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE(); return rpc_get_client_id(thread); }
void rpc_flush(void) { merge_flush(CLIENT_GET_THREAD_STATE()); }
bool platform_get_pixmap_info(EGLNativePixmapType pixmap, KHRN_IMAGE_WRAP_T *image) { Window r; int x, y; unsigned int w, h, b, d; KHRN_IMAGE_FORMAT_T format; XImage *xi; XWindowAttributes attr; Status rc; vcos_log_trace("platform_get_pixmap_info !!!"); if (!XGetGeometry(hacky_display, (Drawable)pixmap, &r, &x, &y, &w, &h, &b, &d)) return false; vcos_log_trace("platform_get_pixmap_info %d geometry = %d %d %d %d",(int)pixmap, x, y, w, h); xi = XGetImage(hacky_display, (Drawable)pixmap, 0, 0, w, h, 0xffffffff, ZPixmap); if (xi == NULL) return false; vcos_log_trace("platform_get_pixmap_info ximage = %d %d %d 0x%08x %d %x %x %x", xi->width, xi->height, xi->bytes_per_line, (uint32_t)xi->data, xi->bits_per_pixel, (uint32_t)xi->red_mask, (uint32_t)xi->green_mask, (uint32_t)xi->blue_mask); format = ximage_to_image_format(xi->bits_per_pixel, xi->red_mask, xi->green_mask, xi->blue_mask); if (format == IMAGE_FORMAT_INVALID) { XDestroyImage(xi); return false; } image->format = format; image->width = xi->width; image->height = xi->height; image->stride = xi->bytes_per_line; image->aux = NULL; image->storage = xi->data; //hacking to see if this pixmap is actually the offscreen pixmap for the window that is our current surface { int xw, yw; unsigned int ww, hw, bw, dw; unsigned long pixel; Window rw,win = (Window)CLIENT_GET_THREAD_STATE()->opengl.draw->win; vcos_log_trace("current EGL surface win %d ", (int)win); if(win!=0) { /* Install our error handler to override Xlib's termination behavior */ old_handler = XSetErrorHandler(application_error_handler) ; XGetGeometry(hacky_display, (Drawable)win, &rw, &xw, &yw, &ww, &hw, &bw, &dw); vcos_log_trace("%dx%d", ww, hw); if(ww==w && hw==h) { //this pixmap is the same size as our current window pixel = XGetPixel(xi,w/2,h/2); vcos_log_trace("Pixmap centre pixel 0x%lx%s",pixel,pixel==CHROMA_KEY_565 ? "- chroma key!!" : ""); if(pixel == CHROMA_KEY_565)//the pixmap is also full of our magic chroma key colour, we want to copy the server side EGL surface. image->aux = (void *)CLIENT_GET_THREAD_STATE()->opengl.draw->serverbuffer ; } (void) XSetErrorHandler(old_handler) ; } } // current_ximage = xi; return true; }