Beispiel #1
0
bool
pipe_loader_sw_probe_null(struct pipe_loader_device **devs)
{
   struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);

   if (!sdev)
      return false;

   sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
   sdev->base.driver_name = "swrast";
   sdev->base.ops = &pipe_loader_sw_ops;
   sdev->ws = null_sw_create();
   if (!sdev->ws) {
      FREE(sdev);
      return false;
   }
   *devs = &sdev->base;

   return true;
}
Beispiel #2
0
static boolean
null_display_init_screen(struct native_display *ndpy)
{
   struct null_display *null = null_display(ndpy);
   struct sw_winsys *ws;

   ws = null_sw_create();
   if (!ws)
      return FALSE;

   null->base.screen = null->event_handler->new_sw_screen(&null->base, ws);
   if (!null->base.screen) {
      if (ws->destroy)
         ws->destroy(ws);
      return FALSE;
   }

   if (!null_display_init_config(&null->base)) {
      ndpy_uninit(&null->base);
      return FALSE;
   }

   return TRUE;
}
Beispiel #3
0
void
WriteableBitmap::Render (UIElement *element, Transform *transform)
{
	MoonSurface *src;
	Context     *ctx;

	if (!element)
		return;

	cairo_surface_t *surface = GetImageSurface ();
	if (!surface)
		return;

	Rect bounds (0, 0, GetPixelWidth (), GetPixelHeight ());

#ifdef USE_GALLIUM
	struct pipe_resource pt, *texture;
	GalliumSurface       *target;
	struct pipe_screen   *screen =
		swrast_screen_create (null_sw_create ());

	memset (&pt, 0, sizeof (pt));
	pt.target = PIPE_TEXTURE_2D;
	pt.format = PIPE_FORMAT_B8G8R8A8_UNORM;
	pt.width0 = 1;
	pt.height0 = 1;
	pt.depth0 = 1;
	pt.last_level = 0;
	pt.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_TRANSFER_WRITE |
		PIPE_BIND_TRANSFER_READ;

	texture = (*screen->resource_create) (screen, &pt);

	target = new GalliumSurface (texture);
	pipe_resource_reference (&texture, NULL);
	ctx = new GalliumContext (target);
	target->unref ();
#else
	CairoSurface *target;

	target = new CairoSurface (1, 1);
	ctx = new CairoContext (target);
	target->unref ();
#endif

	ctx->Push (Context::Group (bounds));

	cairo_matrix_t xform;
	cairo_matrix_init_identity (&xform);

	if (transform)
		transform->GetTransform (&xform);

	FrameworkElement *fe = (FrameworkElement *)element;
	if (fe->GetFlowDirection () == FlowDirectionRightToLeft) {
		cairo_matrix_translate (&xform, fe->GetActualWidth (), 0.0);
		cairo_matrix_scale (&xform, -1, 1);
	}

	element->Paint (ctx, bounds, &xform);

	bounds = ctx->Pop (&src);
	if (!bounds.IsEmpty ()) {
		cairo_surface_t *image = src->Cairo ();
		cairo_t         *cr = cairo_create (surface);

		cairo_set_source_surface (cr, image, 0, 0);
		cairo_paint (cr);
		cairo_destroy (cr);
		cairo_surface_destroy (image);
		src->unref ();
	}

	delete ctx;

#ifdef USE_GALLIUM
	screen->destroy (screen);
#endif

}
Beispiel #4
0
static void init_prog(struct program *p)
{
	struct pipe_surface surf_tmpl;
	/* create the software rasterizer */
	p->screen = sw_screen_create(null_sw_create());
	/* wrap the screen with any debugger */
	p->screen = debug_screen_wrap(p->screen);

	/* create the pipe driver context and cso context */
	p->pipe = p->screen->context_create(p->screen, NULL);
	p->cso = cso_create_context(p->pipe);

	/* set clear color */
	p->clear_color.f[0] = 0.3;
	p->clear_color.f[1] = 0.1;
	p->clear_color.f[2] = 0.3;
	p->clear_color.f[3] = 1.0;

	/* vertex buffer */
	{
		float vertices[4][2][4] = {
			{
				{ 0.9f, 0.9f, 0.0f, 1.0f },
				{ 1.0f, 1.0f, 0.0f, 1.0f }
			},
			{
				{ -0.9f, 0.9f, 0.0f, 1.0f },
				{  0.0f, 1.0f, 0.0f, 1.0f }
			},
			{
				{ -0.9f, -0.9f, 0.0f, 1.0f },
				{  0.0f,  0.0f, 1.0f, 1.0f }
			},
			{
				{ 0.9f, -0.9f, 0.0f, 1.0f },
				{ 1.0f,  0.0f, 1.0f, 1.0f }
			}
		};

		p->vbuf = pipe_buffer_create(p->screen, PIPE_BIND_VERTEX_BUFFER,
					     PIPE_USAGE_STATIC, sizeof(vertices));
		pipe_buffer_write(p->pipe, p->vbuf, 0, sizeof(vertices), vertices);
	}

	/* render target texture */
	{
		struct pipe_resource tmplt;
		memset(&tmplt, 0, sizeof(tmplt));
		tmplt.target = PIPE_TEXTURE_2D;
		tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */
		tmplt.width0 = WIDTH;
		tmplt.height0 = HEIGHT;
		tmplt.depth0 = 1;
		tmplt.array_size = 1;
		tmplt.last_level = 0;
		tmplt.bind = PIPE_BIND_RENDER_TARGET;

		p->target = p->screen->resource_create(p->screen, &tmplt);
	}

	/* sampler texture */
	{
		uint32_t *ptr;
		struct pipe_transfer *t;
		struct pipe_resource t_tmplt;
		struct pipe_sampler_view v_tmplt;
		struct pipe_box box;

		memset(&t_tmplt, 0, sizeof(t_tmplt));
		t_tmplt.target = PIPE_TEXTURE_2D;
		t_tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */
		t_tmplt.width0 = 2;
		t_tmplt.height0 = 2;
		t_tmplt.depth0 = 1;
		t_tmplt.array_size = 1;
		t_tmplt.last_level = 0;
		t_tmplt.bind = PIPE_BIND_RENDER_TARGET;

		p->tex = p->screen->resource_create(p->screen, &t_tmplt);

		memset(&box, 0, sizeof(box));
		box.width = 2;
		box.height = 2;

		t = p->pipe->get_transfer(p->pipe, p->tex, 0, PIPE_TRANSFER_WRITE, &box);

		ptr = p->pipe->transfer_map(p->pipe, t);
		ptr[0] = 0xffff0000;
		ptr[1] = 0xff0000ff;
		ptr[2] = 0xff00ff00;
		ptr[3] = 0xffffff00;
		p->pipe->transfer_unmap(p->pipe, t);

		p->pipe->transfer_destroy(p->pipe, t);

		u_sampler_view_default_template(&v_tmplt, p->tex, p->tex->format);

		p->view = p->pipe->create_sampler_view(p->pipe, p->tex, &v_tmplt);
	}

	/* disabled blending/masking */
	memset(&p->blend, 0, sizeof(p->blend));
	p->blend.rt[0].colormask = PIPE_MASK_RGBA;

	/* no-op depth/stencil/alpha */
	memset(&p->depthstencil, 0, sizeof(p->depthstencil));

	/* rasterizer */
	memset(&p->rasterizer, 0, sizeof(p->rasterizer));
	p->rasterizer.cull_face = PIPE_FACE_NONE;
	p->rasterizer.gl_rasterization_rules = 1;
	p->rasterizer.depth_clip = 1;

	/* sampler */
	memset(&p->sampler, 0, sizeof(p->sampler));
	p->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
	p->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
	p->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
	p->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
	p->sampler.min_img_filter = PIPE_TEX_MIPFILTER_LINEAR;
	p->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_LINEAR;
	p->sampler.normalized_coords = 1;

	surf_tmpl.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */
	surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
	surf_tmpl.u.tex.level = 0;
	surf_tmpl.u.tex.first_layer = 0;
	surf_tmpl.u.tex.last_layer = 0;
	/* drawing destination */
	memset(&p->framebuffer, 0, sizeof(p->framebuffer));
	p->framebuffer.width = WIDTH;
	p->framebuffer.height = HEIGHT;
	p->framebuffer.nr_cbufs = 1;
	p->framebuffer.cbufs[0] = p->pipe->create_surface(p->pipe, p->target, &surf_tmpl);

	/* viewport, depth isn't really needed */
	{
		float x = 0;
		float y = 0;
		float z = FAR;
		float half_width = (float)WIDTH / 2.0f;
		float half_height = (float)HEIGHT / 2.0f;
		float half_depth = ((float)FAR - (float)NEAR) / 2.0f;
		float scale, bias;

		if (FLIP) {
			scale = -1.0f;
			bias = (float)HEIGHT;
		} else {
			scale = 1.0f;
			bias = 0.0f;
		}

		p->viewport.scale[0] = half_width;
		p->viewport.scale[1] = half_height * scale;
		p->viewport.scale[2] = half_depth;
		p->viewport.scale[3] = 1.0f;

		p->viewport.translate[0] = half_width + x;
		p->viewport.translate[1] = (half_height + y) * scale + bias;
		p->viewport.translate[2] = half_depth + z;
		p->viewport.translate[3] = 0.0f;
	}

	/* vertex elements state */
	memset(p->velem, 0, sizeof(p->velem));
	p->velem[0].src_offset = 0 * 4 * sizeof(float); /* offset 0, first element */
	p->velem[0].instance_divisor = 0;
	p->velem[0].vertex_buffer_index = 0;
	p->velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;

	p->velem[1].src_offset = 1 * 4 * sizeof(float); /* offset 16, second element */
	p->velem[1].instance_divisor = 0;
	p->velem[1].vertex_buffer_index = 0;
	p->velem[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;

	/* vertex shader */
	{
		const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
		                                TGSI_SEMANTIC_GENERIC };
		const uint semantic_indexes[] = { 0, 0 };
		p->vs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes);
	}

	/* fragment shader */
	p->fs = util_make_fragment_tex_shader(p->pipe, TGSI_TEXTURE_2D, TGSI_INTERPOLATE_LINEAR);
}