示例#1
0
void
SvgWindow::updateSvgContext ()
{
    if (context)
    {
	finiTexture (context->texture[0]);
	finiTexture (context->texture[1]);
    }
    else
    {
	context = new SvgContext;

	if (!context)
	    return;
    }

    int      x1, y1, x2, y2;
    CompSize wSize;

    initTexture (source, context->texture[1], context->size);

    context->source = source;

    wSize.setWidth (window->geometry ().width ());
    wSize.setHeight (window->geometry ().height ());

    decor_apply_gravity (source->p1.gravity,
			 source->p1.x, source->p1.y,
			 wSize.width (), wSize.height (),
			 &x1, &y1);

    decor_apply_gravity (source->p2.gravity,
			 source->p2.x, source->p2.y,
			 wSize.width (), wSize.height (),
			 &x2, &y2);

    x1 = MAX (x1, 0);
    y1 = MAX (y1, 0);
    x2 = MIN (x2, wSize.width ());
    y2 = MIN (y2, wSize.height ());

    if (!initTexture (source, context->texture[0], wSize))
    {
	delete context;
	context = NULL;
    }
    else
    {
	renderSvg (source, context->texture[0], wSize, 0.0f, 0.0f, 1.0f, 1.0f);

	initTexture (source, context->texture[1], CompSize ());

	context->box += CompRect (x1, y1, x2 - x1, y2 - y1);
	context->box.translate (window->geometry ().x (), window->geometry ().y ());

	updateSvgMatrix ();
    }
}
示例#2
0
文件: video.c 项目: zmike/compiz
static void
updateWindowVideoContext(CompWindow *w,
                         VideoSource *source)
{
   int x1, y1, x2, y2;

   VIDEO_WINDOW(w);

   if (!vw->context)
     {
        vw->context = malloc(sizeof (VideoContext));
        if (!vw->context)
          return;
     }

   vw->context->source = source;

   vw->context->box.rects = &vw->context->box.extents;
   vw->context->box.numRects = 1;

   decor_apply_gravity(source->p1.gravity,
                       source->p1.x, source->p1.y,
                       w->width, w->height,
                       &x1, &y1);

   decor_apply_gravity(source->p2.gravity,
                       source->p2.x, source->p2.y,
                       w->width, w->height,
                       &x2, &y2);

   x1 = MAX(x1, 0);
   y1 = MAX(y1, 0);
   x2 = MIN(x2, w->width);
   y2 = MIN(y2, w->height);

   vw->context->width = x2 - x1;
   vw->context->height = y2 - y1;

   vw->context->panX = 0.0f;
   vw->context->panY = 0.0f;

   if (source->aspect)
     {
        float aspect, width, height, v;

        width = vw->context->width;
        height = vw->context->height;

        aspect = width / height;

        if (aspect < source->aspectRatio)
          {
             v = (width + width * source->panScan) / source->aspectRatio;
             height = MIN(vw->context->height, v);
             width = height * source->aspectRatio;
          }
        else
          {
             v = (height + height * source->panScan) * source->aspectRatio;
             width = MIN(vw->context->width, v);
             height = width / source->aspectRatio;
          }

        x1 = (vw->context->width / 2.0f) - (width / 2.0f);
        y1 = (vw->context->height / 2.0f) - (height / 2.0f);
        x2 = ((vw->context->width / 2.0f) + (width / 2.0f) + 0.5f);
        y2 = ((vw->context->height / 2.0f) + (height / 2.0f) + 0.5f);

        vw->context->width = x2 - x1;
        vw->context->height = y2 - y1;

        if (x1 < 0)
          vw->context->panX = -x1;

        if (y1 < 0)
          vw->context->panY = -y1;

        x1 = MAX(x1, 0);
        y1 = MAX(y1, 0);
        x2 = MIN(x2, w->width);
        y2 = MIN(y2, w->height);
     }

   if (x1 == 0 &&
       y1 == 0 &&
       x2 == w->width &&
       y2 == w->height)
     {
        vw->context->full = TRUE;
     }
   else
     {
        vw->context->full = FALSE;
     }

   vw->context->box.extents.x1 = x1;
   vw->context->box.extents.y1 = y1;
   vw->context->box.extents.x2 = x2;
   vw->context->box.extents.y2 = y2;

   vw->context->box.extents.x1 += w->attrib.x;
   vw->context->box.extents.y1 += w->attrib.y;
   vw->context->box.extents.x2 += w->attrib.x;
   vw->context->box.extents.y2 += w->attrib.y;

   updateWindowVideoMatrix(w);
}
示例#3
0
文件: svg.c 项目: zmike/compiz
static void
updateWindowSvgContext(CompWindow *w,
                       SvgSource *source)
{
    int x1, y1, x2, y2;

    SVG_WINDOW(w);

    if (sw->context)
    {
        finiSvgTexture(w->screen, &sw->context->texture[0]);
        finiSvgTexture(w->screen, &sw->context->texture[1]);
    }
    else
    {
        sw->context = malloc(sizeof (SvgContext));
        if (!sw->context)
            return;
    }

    memset(&sw->context->rect, 0, sizeof (BoxRec));

    sw->context->width = 0;
    sw->context->height = 0;

    initSvgTexture(w, source, &sw->context->texture[1], 0, 0);

    sw->context->source = source;

    sw->context->box.rects = &sw->context->box.extents;
    sw->context->box.numRects = 1;

    decor_apply_gravity(source->p1.gravity,
                        source->p1.x, source->p1.y,
                        w->width, w->height,
                        &x1, &y1);

    decor_apply_gravity(source->p2.gravity,
                        source->p2.x, source->p2.y,
                        w->width, w->height,
                        &x2, &y2);

    x1 = MAX(x1, 0);
    y1 = MAX(y1, 0);
    x2 = MIN(x2, w->width);
    y2 = MIN(y2, w->height);

    if (!initSvgTexture(w, source, &sw->context->texture[0],
                        w->width, w->height))
    {
        free(sw->context);
        sw->context = NULL;
    }
    else
    {
        renderSvg(w->screen, source, &sw->context->texture[0],
                  0.0f, 0.0f, 1.0f, 1.0f, w->width, w->height);

        initSvgTexture(w, source, &sw->context->texture[1], 0, 0);

        sw->context->box.extents.x1 = x1;
        sw->context->box.extents.y1 = y1;
        sw->context->box.extents.x2 = x2;
        sw->context->box.extents.y2 = y2;

        sw->context->box.extents.x1 += w->attrib.x;
        sw->context->box.extents.y1 += w->attrib.y;
        sw->context->box.extents.x2 += w->attrib.x;
        sw->context->box.extents.y2 += w->attrib.y;

        updateWindowSvgMatrix(w);
    }
}
示例#4
0
static void
computeQuadBox (decor_quad_t *q,
		int	     width,
		int	     height,
		int	     *return_x1,
		int	     *return_y1,
		int	     *return_x2,
		int	     *return_y2,
		float        *return_sx,
		float        *return_sy)
{
    int   x1, y1, x2, y2;
    float sx = 1.0f;
    float sy = 1.0f;

    decor_apply_gravity (q->p1.gravity, q->p1.x, q->p1.y, width, height,
			 &x1, &y1);
    decor_apply_gravity (q->p2.gravity, q->p2.x, q->p2.y, width, height,
			 &x2, &y2);

    if (q->clamp & CLAMP_HORZ)
    {
	if (x1 < 0)
	    x1 = 0;
	if (x2 > width)
	    x2 = width;
    }

    if (q->clamp & CLAMP_VERT)
    {
	if (y1 < 0)
	    y1 = 0;
	if (y2 > height)
	    y2 = height;
    }

    if (q->stretch & STRETCH_X)
    {
	sx = (float)q->max_width / ((float)(x2 - x1));
    }
    else if (q->max_width < x2 - x1)
    {
	if (q->align & ALIGN_RIGHT)
	    x1 = x2 - q->max_width;
	else
	    x2 = x1 + q->max_width;
    }

    if (q->stretch & STRETCH_Y)
    {
	sy = (float)q->max_height / ((float)(y2 - y1));
    }
    else if (q->max_height < y2 - y1)
    {
	if (q->align & ALIGN_BOTTOM)
	    y1 = y2 - q->max_height;
	else
	    y2 = y1 + q->max_height;
    }

    *return_x1 = x1;
    *return_y1 = y1;
    *return_x2 = x2;
    *return_y2 = y2;

    if (return_sx)
	*return_sx = sx;
    if (return_sy)
	*return_sy = sy;
}