/** * Called via eglCreateContext(), drv->API.CreateContext(). */ static EGLContext xlib_eglCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list) { struct xlib_egl_driver *xdrv = xlib_egl_driver(drv); _EGLConfig *conf = _eglLookupConfig(drv, dpy, config); struct xlib_egl_context *ctx; struct st_context *share_ctx = NULL; /* XXX fix */ __GLcontextModes visual; ctx = CALLOC_STRUCT(xlib_egl_context); if (!ctx) return EGL_NO_CONTEXT; /* let EGL lib init the common stuff */ if (!_eglInitContext(drv, dpy, &ctx->Base, config, attrib_list)) { free(ctx); return EGL_NO_CONTEXT; } /* API-dependent context creation */ switch (ctx->Base.ClientAPI) { case EGL_OPENVG_API: case EGL_OPENGL_ES_API: _eglLog(_EGL_DEBUG, "Create Context for ES version %d\n", ctx->Base.ClientVersion); /* fall-through */ case EGL_OPENGL_API: /* create a softpipe context */ ctx->pipe = softpipe_create(xdrv->screen, xdrv->winsys, NULL); /* Now do xlib / state tracker inits here */ _eglConfigToContextModesRec(conf, &visual); ctx->Context = st_create_context(ctx->pipe, &visual, share_ctx); break; default: _eglError(EGL_BAD_MATCH, "eglCreateContext(unsupported API)"); free(ctx); return EGL_NO_CONTEXT; } _eglSaveContext(&ctx->Base); return _eglGetContextHandle(&ctx->Base); }
GLboolean nouveau_context_create(const __GLcontextModes *glVis, __DRIcontextPrivate *driContextPriv, void *sharedContextPrivate) { __DRIscreenPrivate *driScrnPriv = driContextPriv->driScreenPriv; struct nouveau_screen *nv_screen = driScrnPriv->private; struct nouveau_context *nv; struct pipe_context *pipe; struct st_context *st_share = NULL; if (sharedContextPrivate) st_share = ((struct nouveau_context *)sharedContextPrivate)->st; nv = CALLOC_STRUCT(nouveau_context); if (!nv) return GL_FALSE; { struct nouveau_device_priv *nvdev = nouveau_device(nv_screen->device); nvdev->ctx = driContextPriv->hHWContext; nvdev->lock = (drmLock *)&driScrnPriv->pSAREA->lock; } pipe = drm_api_hooks.create_context(nv_screen->pscreen); if (!pipe) { FREE(nv); return GL_FALSE; } pipe->priv = nv; driContextPriv->driverPrivate = nv; nv->dri_screen = driScrnPriv; driParseConfigFiles(&nv->dri_option_cache, &nv_screen->option_cache, nv->dri_screen->myNum, "nouveau"); nv->st = st_create_context(pipe, glVis, st_share); return GL_TRUE; }
static struct st_context_iface * st_api_create_context(struct st_api *stapi, struct st_manager *smapi, const struct st_context_attribs *attribs, enum st_context_error *error, struct st_context_iface *shared_stctxi) { struct st_context *shared_ctx = (struct st_context *) shared_stctxi; struct st_context *st; struct pipe_context *pipe; struct gl_config mode; gl_api api; if (!(stapi->profile_mask & (1 << attribs->profile))) return NULL; switch (attribs->profile) { case ST_PROFILE_DEFAULT: api = API_OPENGL; break; case ST_PROFILE_OPENGL_ES1: api = API_OPENGLES; break; case ST_PROFILE_OPENGL_ES2: api = API_OPENGLES2; break; case ST_PROFILE_OPENGL_CORE: default: *error = ST_CONTEXT_ERROR_BAD_API; return NULL; break; } pipe = smapi->screen->context_create(smapi->screen, NULL); if (!pipe) { *error = ST_CONTEXT_ERROR_NO_MEMORY; return NULL; } st_visual_to_context_mode(&attribs->visual, &mode); st = st_create_context(api, pipe, &mode, shared_ctx); if (!st) { *error = ST_CONTEXT_ERROR_NO_MEMORY; pipe->destroy(pipe); return NULL; } /* need to perform version check */ if (attribs->major > 1 || attribs->minor > 0) { _mesa_compute_version(st->ctx); /* Is the actual version less than the requested version? Mesa can't * yet enforce the added restrictions of a forward-looking context, so * fail that too. */ if (st->ctx->VersionMajor * 10 + st->ctx->VersionMinor < attribs->major * 10 + attribs->minor || (attribs->flags & ~ST_CONTEXT_FLAG_DEBUG) != 0) { *error = ST_CONTEXT_ERROR_BAD_VERSION; st_destroy_context(st); return NULL; } } st->invalidate_on_gl_viewport = smapi->get_param(smapi, ST_MANAGER_BROKEN_INVALIDATE); st->iface.destroy = st_context_destroy; st->iface.flush = st_context_flush; st->iface.teximage = st_context_teximage; st->iface.copy = st_context_copy; st->iface.share = st_context_share; st->iface.st_context_private = (void *) smapi; *error = ST_CONTEXT_SUCCESS; return &st->iface; }
static struct st_context_iface * st_api_create_context(struct st_api *stapi, struct st_manager *smapi, const struct st_context_attribs *attribs, enum st_context_error *error, struct st_context_iface *shared_stctxi) { struct st_context *shared_ctx = (struct st_context *) shared_stctxi; struct st_context *st; struct pipe_context *pipe; struct gl_config mode; gl_api api; if (!(stapi->profile_mask & (1 << attribs->profile))) return NULL; switch (attribs->profile) { case ST_PROFILE_DEFAULT: api = API_OPENGL_COMPAT; break; case ST_PROFILE_OPENGL_ES1: api = API_OPENGLES; break; case ST_PROFILE_OPENGL_ES2: api = API_OPENGLES2; break; case ST_PROFILE_OPENGL_CORE: api = API_OPENGL_CORE; break; default: *error = ST_CONTEXT_ERROR_BAD_API; return NULL; break; } pipe = smapi->screen->context_create(smapi->screen, NULL); if (!pipe) { *error = ST_CONTEXT_ERROR_NO_MEMORY; return NULL; } st_visual_to_context_mode(&attribs->visual, &mode); st = st_create_context(api, pipe, &mode, shared_ctx, &attribs->options); if (!st) { *error = ST_CONTEXT_ERROR_NO_MEMORY; pipe->destroy(pipe); return NULL; } st->ctx->Debug.DebugOutput = GL_FALSE; if (attribs->flags & ST_CONTEXT_FLAG_DEBUG){ st->ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_DEBUG_BIT; st->ctx->Debug.DebugOutput = GL_TRUE; } if (attribs->flags & ST_CONTEXT_FLAG_FORWARD_COMPATIBLE) st->ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT; /* need to perform version check */ if (attribs->major > 1 || attribs->minor > 0) { /* Is the actual version less than the requested version? */ if (st->ctx->Version < attribs->major * 10 + attribs->minor) { *error = ST_CONTEXT_ERROR_BAD_VERSION; st_destroy_context(st); return NULL; } } st->invalidate_on_gl_viewport = smapi->get_param(smapi, ST_MANAGER_BROKEN_INVALIDATE); st->iface.destroy = st_context_destroy; st->iface.flush = st_context_flush; st->iface.teximage = st_context_teximage; st->iface.copy = st_context_copy; st->iface.share = st_context_share; st->iface.st_context_private = (void *) smapi; st->iface.cso_context = st->cso_context; st->iface.pipe = st->pipe; *error = ST_CONTEXT_SUCCESS; return &st->iface; }
uint64 hsp_create_layer_context(Bitmap *bitmap, int layerPlane) { TRACE("%s(bitmap: %p layerPlane: %d)\n", __FUNCTION__, bitmap, layerPlane); time_t total_beg, total_end; time_t beg, end; total_beg = time(NULL); struct hsp_context *ctx = NULL; struct pipe_screen *screen = NULL; GLvisual *visual = NULL; struct pipe_context *pipe = NULL; uint ctxId = 0; if (!hsp_dev) { TRACE("%s> there is no hsp_dev!\n", __FUNCTION__); return 0; } if (layerPlane != 0) { TRACE("%s> layerPlane != 0\n", __FUNCTION__); return 0; } ctx = CALLOC_STRUCT(hsp_context); if (!ctx) { TRACE("%s> can't alloc hsp_context!\n", __FUNCTION__); goto no_ctx; } ctx->bitmap = bitmap; ctx->colorSpace = get_bitmap_color_space(bitmap); ctx->draw = NULL; ctx->read = NULL; screen = hsp_dev->screen; #ifdef DEBUG /* Unwrap screen */ if (hsp_dev->trace_running) screen = trace_screen(screen)->screen; #endif ulong options = hsp_dev->options; const GLboolean rgbFlag = ((options & BGL_INDEX) == 0); const GLboolean alphaFlag = ((options & BGL_ALPHA) == BGL_ALPHA); const GLboolean dblFlag = ((options & BGL_DOUBLE) == BGL_DOUBLE); const GLboolean stereoFlag = false; const GLint depth = (options & BGL_DEPTH) ? 24 : 0; const GLint stencil = (options & BGL_STENCIL) ? 8 : 0; const GLint accum = 0; // (options & BGL_ACCUM) ? 16 : 0; const GLint index = 0; // (options & BGL_INDEX) ? 32 : 0; const GLint red = rgbFlag ? 8 : 0; const GLint green = rgbFlag ? 8 : 0; const GLint blue = rgbFlag ? 8 : 0; const GLint alpha = alphaFlag ? 8 : 0; TRACE("rgb :\t%d\n", (bool)rgbFlag); TRACE("alpha :\t%d\n", (bool)alphaFlag); TRACE("dbl :\t%d\n", (bool)dblFlag); TRACE("stereo :\t%d\n", (bool)stereoFlag); TRACE("depth :\t%d\n", depth); TRACE("stencil :\t%d\n", stencil); TRACE("accum :\t%d\n", accum); TRACE("index :\t%d\n", index); TRACE("red :\t%d\n", red); TRACE("green :\t%d\n", green); TRACE("blue :\t%d\n", blue); TRACE("alpha :\t%d\n", alpha); visual = _mesa_create_visual( rgbFlag, dblFlag, stereoFlag, red, green, blue, alpha, index, depth, stencil, accum, accum, accum, alpha ? accum : 0, 1); TRACE("depthBits :\t%d\n", visual->depthBits); TRACE("stencilBits :\t%d\n", visual->stencilBits); if (!visual) { TRACE("%s> can't create mesa visual!\n", __FUNCTION__); goto no_ctx_id; } pipe = hsp_dev->hsp_winsys->create_context(screen); if (!pipe) { TRACE("%s> can't create pipe!\n", __FUNCTION__); goto no_pipe; } #ifdef DEBUG if (hsp_dev->trace_running) pipe = trace_context_create(hsp_dev->screen, pipe); #endif assert(!pipe->priv); pipe->priv = bitmap; ctx->st = st_create_context(pipe, visual, NULL); if (!ctx->st) { TRACE("%s> can't create mesa statetracker context!\n", __FUNCTION__); goto no_st_ctx; } ctx->st->ctx->DriverCtx = ctx; pipe_mutex_lock(hsp_dev->mutex); uint64 i; for (i = 0; i < HSP_CONTEXT_MAX; i++) { if (hsp_dev->ctx_array[i].ctx == NULL) { hsp_dev->ctx_array[i].ctx = ctx; ctxId = i + 1; break; } } pipe_mutex_unlock(hsp_dev->mutex); if (ctxId != 0) return ctxId; no_ctx_id: TRACE("%s> no_ctx_id!\n", __FUNCTION__); _mesa_destroy_visual(visual); st_destroy_context(ctx->st); goto no_pipe; /* st_context_destroy already destroy pipe */ no_st_ctx: TRACE("%s> no_st_ctx!\n", __FUNCTION__); pipe->destroy(pipe); no_pipe: TRACE("%s> no_pipe!\n", __FUNCTION__); FREE(ctx); no_ctx: TRACE("%s> no_ctx!\n", __FUNCTION__); return 0; }
static struct st_context_iface * st_api_create_context(struct st_api *stapi, struct st_manager *smapi, const struct st_context_attribs *attribs, struct st_context_iface *shared_stctxi) { struct st_context *shared_ctx = (struct st_context *) shared_stctxi; struct st_context *st; struct pipe_context *pipe; struct gl_config mode; gl_api api; if (!(stapi->profile_mask & (1 << attribs->profile))) return NULL; switch (attribs->profile) { case ST_PROFILE_DEFAULT: api = API_OPENGL; break; case ST_PROFILE_OPENGL_ES1: api = API_OPENGLES; break; case ST_PROFILE_OPENGL_ES2: api = API_OPENGLES2; break; case ST_PROFILE_OPENGL_CORE: default: return NULL; break; } pipe = smapi->screen->context_create(smapi->screen, NULL); if (!pipe) return NULL; st_visual_to_context_mode(&attribs->visual, &mode); st = st_create_context(api, pipe, &mode, shared_ctx); if (!st) { pipe->destroy(pipe); return NULL; } /* need to perform version check */ if (attribs->major > 1 || attribs->minor > 0) { _mesa_compute_version(st->ctx); /* is the actual version less than the requested version? */ if (st->ctx->VersionMajor * 10 + st->ctx->VersionMinor < attribs->major * 10 + attribs->minor) { st_destroy_context(st); return NULL; } } st->invalidate_on_gl_viewport = smapi->get_param(smapi, ST_MANAGER_BROKEN_INVALIDATE); st->iface.destroy = st_context_destroy; st->iface.notify_invalid_framebuffer = st_context_notify_invalid_framebuffer; st->iface.flush = st_context_flush; st->iface.teximage = st_context_teximage; st->iface.copy = st_context_copy; st->iface.share = st_context_share; st->iface.st_context_private = (void *) smapi; return &st->iface; }