static struct pipe_context * trace_screen_context_create(struct pipe_screen *_screen, void *priv) { struct trace_screen *tr_scr = trace_screen(_screen); struct pipe_screen *screen = tr_scr->screen; struct pipe_context *result; trace_dump_call_begin("pipe_screen", "context_create"); trace_dump_arg(ptr, screen); result = screen->context_create(screen, priv); trace_dump_ret(ptr, result); trace_dump_call_end(); result = trace_context_create(tr_scr, result); return result; }
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; }
struct st_context * st_context_create(struct st_device *st_dev) { struct st_context *st_ctx; st_ctx = CALLOC_STRUCT(st_context); if(!st_ctx) return NULL; st_device_reference(&st_ctx->st_dev, st_dev); st_ctx->real_pipe = st_dev->st_ws->context_create(st_dev->real_screen); if(!st_ctx->real_pipe) { st_context_destroy(st_ctx); return NULL; } st_ctx->pipe = trace_context_create(st_dev->screen, st_ctx->real_pipe); if(!st_ctx->pipe) { st_context_destroy(st_ctx); return NULL; } st_ctx->cso = cso_create_context(st_ctx->pipe); if(!st_ctx->cso) { st_context_destroy(st_ctx); return NULL; } /* disabled blending/masking */ { struct pipe_blend_state blend; memset(&blend, 0, sizeof(blend)); blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE; blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE; blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; blend.colormask = PIPE_MASK_RGBA; cso_set_blend(st_ctx->cso, &blend); } /* no-op depth/stencil/alpha */ { struct pipe_depth_stencil_alpha_state depthstencil; memset(&depthstencil, 0, sizeof(depthstencil)); cso_set_depth_stencil_alpha(st_ctx->cso, &depthstencil); } /* rasterizer */ { struct pipe_rasterizer_state rasterizer; memset(&rasterizer, 0, sizeof(rasterizer)); rasterizer.front_winding = PIPE_WINDING_CW; rasterizer.cull_mode = PIPE_WINDING_NONE; cso_set_rasterizer(st_ctx->cso, &rasterizer); } /* clip */ { struct pipe_clip_state clip; memset(&clip, 0, sizeof(clip)); st_ctx->pipe->set_clip_state(st_ctx->pipe, &clip); } /* identity viewport */ { struct pipe_viewport_state viewport; viewport.scale[0] = 1.0; viewport.scale[1] = 1.0; viewport.scale[2] = 1.0; viewport.scale[3] = 1.0; viewport.translate[0] = 0.0; viewport.translate[1] = 0.0; viewport.translate[2] = 0.0; viewport.translate[3] = 0.0; cso_set_viewport(st_ctx->cso, &viewport); } /* samplers */ { struct pipe_sampler_state sampler; unsigned i; memset(&sampler, 0, sizeof(sampler)); sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST; sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST; sampler.normalized_coords = 1; for (i = 0; i < PIPE_MAX_SAMPLERS; i++) cso_single_sampler(st_ctx->cso, i, &sampler); cso_single_sampler_done(st_ctx->cso); } /* default textures */ { struct pipe_screen *screen = st_dev->screen; struct pipe_texture templat; struct pipe_transfer *transfer; unsigned i; memset( &templat, 0, sizeof( templat ) ); templat.target = PIPE_TEXTURE_2D; templat.format = PIPE_FORMAT_A8R8G8B8_UNORM; templat.block.size = 4; templat.block.width = 1; templat.block.height = 1; templat.width[0] = 1; templat.height[0] = 1; templat.depth[0] = 1; templat.last_level = 0; st_ctx->default_texture = screen->texture_create( screen, &templat ); if(st_ctx->default_texture) { transfer = screen->get_tex_transfer(screen, st_ctx->default_texture, 0, 0, 0, PIPE_TRANSFER_WRITE, 0, 0, st_ctx->default_texture->width[0], st_ctx->default_texture->height[0]); if (transfer) { uint32_t *map; map = (uint32_t *) screen->transfer_map(screen, transfer); if(map) { *map = 0x00000000; screen->transfer_unmap(screen, transfer); } screen->tex_transfer_destroy(transfer); } } for (i = 0; i < PIPE_MAX_SAMPLERS; i++) pipe_texture_reference(&st_ctx->sampler_textures[i], st_ctx->default_texture); cso_set_sampler_textures(st_ctx->cso, PIPE_MAX_SAMPLERS, st_ctx->sampler_textures); } /* vertex shader */ { const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_GENERIC }; const uint semantic_indexes[] = { 0, 0 }; st_ctx->vs = util_make_vertex_passthrough_shader(st_ctx->pipe, 2, semantic_names, semantic_indexes); cso_set_vertex_shader_handle(st_ctx->cso, st_ctx->vs); } /* fragment shader */ { st_ctx->fs = util_make_fragment_passthrough_shader(st_ctx->pipe); cso_set_fragment_shader_handle(st_ctx->cso, st_ctx->fs); } return st_ctx; }