Пример #1
0
void vegaPaintPattern(VGPaint paint, VGImage pattern)
{
   struct vg_context *ctx = vg_current_context();

   if (paint == VG_INVALID_HANDLE ||
       !vg_context_is_object_valid(ctx, VG_OBJECT_PAINT, (void *)paint)) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }

   if (pattern == VG_INVALID_HANDLE) {
      paint_set_type((struct vg_paint*)paint, VG_PAINT_TYPE_COLOR);
      return;
   }

   if (!vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, (void *)pattern)) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }


   if (!vg_object_is_valid((void*)paint, VG_OBJECT_PAINT) ||
       !vg_object_is_valid((void*)pattern, VG_OBJECT_IMAGE)) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }
   paint_set_pattern((struct vg_paint*)paint,
                     (struct vg_image*)pattern);
}
Пример #2
0
void vegaSetGlyphToImage(VGFont font,
                         VGuint glyphIndex,
                         VGImage image,
                         const VGfloat glyphOrigin[2],
                         const VGfloat escapement[2])
{
   struct vg_context *ctx = vg_current_context();
   struct vg_image *img_obj;
   struct vg_font *f;

   if (font == VG_INVALID_HANDLE ||
       !vg_context_is_object_valid(ctx, VG_OBJECT_FONT, (void *)font)) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }
   if (!glyphOrigin || !escapement ||
       !is_aligned(glyphOrigin) || !is_aligned(escapement)) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }
   if (image != VG_INVALID_HANDLE &&
       !vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, (void *)image)) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }

   img_obj = (struct vg_image*)image;
   f = (struct vg_font*)font;

   font_set_glyph_to_image(f, glyphIndex, img_obj, glyphOrigin, escapement);
}
Пример #3
0
void vegaSetPaint(VGPaint paint, VGbitfield paintModes)
{
   struct vg_context *ctx = vg_current_context();

   if (paint == VG_INVALID_HANDLE) {
      /* restore the default */
      paint = paint_to_handle(ctx->default_paint);
   } else if (!vg_object_is_valid(paint, VG_OBJECT_PAINT)) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }

   if (!(paintModes & ((VG_FILL_PATH|VG_STROKE_PATH)))) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }

   if (paintModes & VG_FILL_PATH) {
      ctx->state.vg.fill_paint = handle_to_paint(paint);
   }
   if (paintModes & VG_STROKE_PATH) {
      ctx->state.vg.stroke_paint = handle_to_paint(paint);
   }

   ctx->state.dirty |= PAINT_DIRTY;
}
Пример #4
0
void vgDrawGlyph(VGFont font,
                 VGuint glyphIndex,
                 VGbitfield paintModes,
                 VGboolean allowAutoHinting)
{
   struct vg_context *ctx = vg_current_context();
   struct vg_font *f;

   if (font == VG_INVALID_HANDLE) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }
   if (glyphIndex <= 0) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }
   if (paintModes & (~(VG_STROKE_PATH|VG_FILL_PATH))) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }
   f = (struct vg_font*)font;
   if (!font_contains_glyph(f, glyphIndex)) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }
}
Пример #5
0
void vgSetGlyphToImage(VGFont font,
                       VGuint glyphIndex,
                       VGImage image,
                       VGfloat glyphOrigin [2],
                       VGfloat escapement[2])
{
   struct vg_context *ctx = vg_current_context();
   struct vg_object *img_obj;
   struct vg_font *f;

   if (font == VG_INVALID_HANDLE ||
       !vg_context_is_object_valid(ctx, VG_OBJECT_FONT, (void *)font)) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }
   if (!glyphOrigin || !escapement ||
       !is_aligned(glyphOrigin) || !is_aligned(escapement)) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }
   if (image != VG_INVALID_HANDLE &&
       !vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, (void *)image)) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }
   img_obj = (struct vg_object*)image;
   if (img_obj && img_obj->type != VG_OBJECT_IMAGE) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }
   f = (struct vg_font*)font;
   f->glyph_indices[f->num_glyphs] = glyphIndex;
   ++f->num_glyphs;
}
Пример #6
0
void vgClearGlyph(VGFont font,
                  VGuint glyphIndex)
{
   struct vg_context *ctx = vg_current_context();
   struct vg_font *f;
   VGint i;

   if (font == VG_INVALID_HANDLE) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }
   if (glyphIndex <= 0) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }
   f = (struct vg_font*)font;
   if (!font_contains_glyph(f, glyphIndex)) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }

   for (i = 0; i < f->num_glyphs; ++i) {
      if (f->glyph_indices[i] == glyphIndex) {
         /*FIXME*/
         f->glyph_indices[f->num_glyphs] = 0;
         --f->num_glyphs;
         return;
      }
   }
}
Пример #7
0
void image_sub_data(struct vg_image *image,
                    const void * data,
                    VGint dataStride,
                    VGImageFormat dataFormat,
                    VGint x, VGint y,
                    VGint width, VGint height)
{
   const VGint yStep = 1;
   VGubyte *src = (VGubyte *)data;
   VGfloat temp[VEGA_MAX_IMAGE_WIDTH][4];
   VGfloat *df = (VGfloat*)temp;
   VGint i;
   struct vg_context *ctx = vg_current_context();
   struct pipe_context *pipe = ctx->pipe;
   struct pipe_resource *texture = image_texture(image);
   VGint xoffset = 0, yoffset = 0;

   if (x < 0) {
      xoffset -= x;
      width += x;
      x = 0;
   }
   if (y < 0) {
      yoffset -= y;
      height += y;
      y = 0;
   }

   if (width <= 0 || height <= 0) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }

   if (x > image->width || y > image->width) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }

   if (x + width > image->width) {
      width = image->width - x;
   }

   if (y + height > image->height) {
      height = image->height - y;
   }

   { /* upload color_data */
      struct pipe_transfer *transfer = pipe_get_transfer(
         pipe, texture, 0, 0,
         PIPE_TRANSFER_WRITE, 0, 0, texture->width0, texture->height0);
      src += (dataStride * yoffset);
      for (i = 0; i < height; i++) {
         _vega_unpack_float_span_rgba(ctx, width, xoffset, src, dataFormat, temp);
         pipe_put_tile_rgba(pipe, transfer, x+image->x, y+image->y, width, 1, df);
         y += yStep;
         src += dataStride;
      }
      pipe->transfer_destroy(pipe, transfer);
   }
}
Пример #8
0
void image_draw(struct vg_image *img, struct matrix *matrix)
{
   struct vg_context *ctx = vg_current_context();
   struct matrix paint_matrix;
   VGfloat x1, y1;
   VGfloat x2, y2;
   VGfloat x3, y3;
   VGfloat x4, y4;

   if (!vg_get_paint_matrix(ctx,
                            &ctx->state.vg.fill_paint_to_user_matrix,
                            matrix,
                            &paint_matrix))
      return;

   x1 = 0;
   y1 = 0;
   x2 = img->width;
   y2 = 0;
   x3 = img->width;
   y3 = img->height;
   x4 = 0;
   y4 = img->height;

   shader_set_surface_matrix(ctx->shader, matrix);
   shader_set_drawing_image(ctx->shader, VG_TRUE);
   shader_set_paint(ctx->shader, ctx->state.vg.fill_paint);
   shader_set_paint_matrix(ctx->shader, &paint_matrix);
   shader_set_image(ctx->shader, img);
   shader_bind(ctx->shader);

   renderer_texture_quad(ctx->renderer, image_texture(img),
                         img->x, img->y, img->x + img->width, img->y + img->height,
                         x1, y1, x2, y2, x3, y3, x4, y4);
}
Пример #9
0
void vegaMask(VGHandle mask, VGMaskOperation operation,
              VGint x, VGint y,
              VGint width, VGint height)
{
   struct vg_context *ctx = vg_current_context();

   if (width <=0 || height <= 0) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }

   if (operation < VG_CLEAR_MASK || operation > VG_SUBTRACT_MASK) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }


   vg_validate_state(ctx);

   if (operation == VG_CLEAR_MASK) {
      mask_fill(x, y, width, height, 0.f);
   } else if (operation == VG_FILL_MASK) {
      mask_fill(x, y, width, height, 1.f);
   } else if (vg_object_is_valid(mask, VG_OBJECT_IMAGE)) {
      struct vg_image *image = handle_to_image(mask);
      mask_using_image(image, operation, x, y, width, height);
   } else if (vg_object_is_valid(mask, VG_OBJECT_MASK)) {
      struct vg_mask_layer *layer = handle_to_masklayer(mask);
      mask_using_layer(layer, operation, x, y, width, height);
   } else {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
   }
}
Пример #10
0
void vegaCopyMask(VGMaskLayer maskLayer,
                  VGint sx, VGint sy,
                  VGint dx, VGint dy,
                  VGint width, VGint height)
{
   struct vg_context *ctx = vg_current_context();
   struct vg_mask_layer *mask = 0;

   if (maskLayer == VG_INVALID_HANDLE) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }
   if (width <= 0 || height <= 0) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }
   if (!vg_object_is_valid(maskLayer, VG_OBJECT_MASK)) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }

   vg_validate_state(ctx);

   mask = handle_to_masklayer(maskLayer);
   mask_copy(mask, sx, sy, dx, dy, width, height);
}
Пример #11
0
void vegaRenderToMask(VGPath path,
                      VGbitfield paintModes,
                      VGMaskOperation operation)
{
   struct vg_context *ctx = vg_current_context();

   if (path == VG_INVALID_HANDLE) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }
   if (!paintModes || (paintModes&(~(VG_STROKE_PATH|VG_FILL_PATH)))) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }
   if (operation < VG_CLEAR_MASK ||
       operation > VG_SUBTRACT_MASK) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }
   if (!vg_object_is_valid(path, VG_OBJECT_PATH)) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }

   vg_validate_state(ctx);

   mask_render_to(handle_to_path(path), paintModes, operation);
}
Пример #12
0
void vegaColorMatrix(VGImage dst, VGImage src,
                     const VGfloat * matrix)
{
   struct vg_context *ctx = vg_current_context();
   struct vg_image *d, *s;
   struct filter_info info;

   if (dst == VG_INVALID_HANDLE || src == VG_INVALID_HANDLE) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }
   if (!matrix || !is_aligned(matrix)) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }

   d = handle_to_image(dst);
   s = handle_to_image(src);

   if (vg_image_overlaps(d, s)) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }

   info.dst = d;
   info.src = s;
   info.setup_shader = &setup_color_matrix;
   info.user_data = NULL;
   info.const_buffer = matrix;
   info.const_buffer_len = 20 * sizeof(VGfloat);
   info.tiling_mode = VG_TILE_PAD;
   info.extra_texture_view = NULL;
   execute_filter(ctx, &info);
}
Пример #13
0
void vegaSetGlyphToPath(VGFont font,
                        VGuint glyphIndex,
                        VGPath path,
                        VGboolean isHinted,
                        const VGfloat glyphOrigin[2],
                        const VGfloat escapement[2])
{
   struct vg_context *ctx = vg_current_context();
   struct path *pathObj;
   struct vg_font *f;

   if (font == VG_INVALID_HANDLE ||
       !vg_context_is_object_valid(ctx, VG_OBJECT_FONT, (void *)font)) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }
   if (!glyphOrigin || !escapement ||
       !is_aligned(glyphOrigin) || !is_aligned(escapement)) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }
   if (path != VG_INVALID_HANDLE &&
       !vg_context_is_object_valid(ctx, VG_OBJECT_PATH, (void *)path)) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }

   pathObj = (struct path*) path;
   f = (struct vg_font*) font;

   font_set_glyph_to_path(f, glyphIndex, pathObj,
         isHinted, glyphOrigin, escapement);
}
Пример #14
0
VGfloat vgPathLength(VGPath path,
                     VGint startSegment,
                     VGint numSegments)
{
   struct vg_context *ctx = vg_current_context();
   struct path *p = 0;

   if (path == VG_INVALID_HANDLE) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return -1;
   }
   if (startSegment < 0) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return -1;
   }
   if (numSegments <= 0) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return -1;
   }
   p = (struct path*)path;

   if (!(path_capabilities(p) & VG_PATH_CAPABILITY_PATH_LENGTH)) {
      vg_set_error(ctx, VG_PATH_CAPABILITY_ERROR);
      return -1;
   }
   if (startSegment + numSegments > path_num_segments(p)) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return -1;
   }

   return path_length(p, startSegment, numSegments);
}
Пример #15
0
static struct st_context_iface *
vg_api_get_current(struct st_api *stapi)
{
   struct vg_context *ctx = vg_current_context();

   return (ctx) ? &ctx->iface : NULL;
}
Пример #16
0
void vgModifyPathCoords(VGPath dstPath,
                        VGint startIndex,
                        VGint numSegments,
                        const void * pathData)
{
   struct vg_context *ctx = vg_current_context();
   struct path *p = 0;

   if (dstPath == VG_INVALID_HANDLE) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }
   if (startIndex < 0 || numSegments <= 0) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }

   p = (struct path *)dstPath;

   if (!pathData || !is_aligned_to(pathData, path_datatype_size(p))) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }

   if (startIndex + numSegments > path_num_segments(p)) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }
   if (!(path_capabilities(p)&VG_PATH_CAPABILITY_MODIFY)) {
      vg_set_error(ctx, VG_PATH_CAPABILITY_ERROR);
      return;
   }
   path_modify_coords(p, startIndex, numSegments, pathData);
}
Пример #17
0
VGboolean vgInterpolatePath(VGPath dstPath,
                            VGPath startPath,
                            VGPath endPath,
                            VGfloat amount)
{
   struct vg_context *ctx = vg_current_context();
   struct path *start = 0, *dst = 0, *end = 0;

   if (dstPath == VG_INVALID_HANDLE ||
       startPath == VG_INVALID_HANDLE ||
       endPath == VG_INVALID_HANDLE) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return VG_FALSE;
   }
   dst = (struct path *)dstPath;
   start = (struct path *)startPath;
   end = (struct path *)endPath;

   if (!(path_capabilities(dst) & VG_PATH_CAPABILITY_INTERPOLATE_TO) ||
       !(path_capabilities(start) & VG_PATH_CAPABILITY_INTERPOLATE_FROM) ||
       !(path_capabilities(end) & VG_PATH_CAPABILITY_INTERPOLATE_FROM)) {
      vg_set_error(ctx, VG_PATH_CAPABILITY_ERROR);
      return VG_FALSE;
   }

   return path_interpolate(dst,
                           start, end, amount);
}
Пример #18
0
void vgCopyPixels(VGint dx, VGint dy,
                  VGint sx, VGint sy,
                  VGint width, VGint height)
{
   struct vg_context *ctx = vg_current_context();
   struct pipe_framebuffer_state *fb = &ctx->state.g3d.fb;
   struct st_renderbuffer *strb = ctx->draw_buffer->strb;

   if (width <= 0 || height <= 0) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }

   /* do nothing if we copy from outside the fb */
   if (dx >= (VGint)fb->width || dy >= (VGint)fb->height ||
       sx >= (VGint)fb->width || sy >= (VGint)fb->height)
      return;

   vg_validate_state(ctx);
   /* make sure rendering has completed */
   vgFinish();

   vg_copy_surface(ctx, strb->surface, dx, dy,
                   strb->surface, sx, sy, width, height);
}
Пример #19
0
VGImage vgCreateImage(VGImageFormat format,
                      VGint width, VGint height,
                      VGbitfield allowedQuality)
{
   struct vg_context *ctx = vg_current_context();

   if (!supported_image_format(format)) {
      vg_set_error(ctx, VG_UNSUPPORTED_IMAGE_FORMAT_ERROR);
      return VG_INVALID_HANDLE;
   }
   if (width <= 0 || height <= 0) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return VG_INVALID_HANDLE;
   }
   if (width > vgGeti(VG_MAX_IMAGE_WIDTH) ||
       height > vgGeti(VG_MAX_IMAGE_HEIGHT)) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return VG_INVALID_HANDLE;
   }
   if (width * height > vgGeti(VG_MAX_IMAGE_PIXELS)) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return VG_INVALID_HANDLE;
   }

   if (!(allowedQuality & ((VG_IMAGE_QUALITY_NONANTIALIASED |
                           VG_IMAGE_QUALITY_FASTER |
                           VG_IMAGE_QUALITY_BETTER)))) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return VG_INVALID_HANDLE;
   }

   return (VGImage)image_create(format, width, height);
}
Пример #20
0
void vgGetImageSubData(VGImage image,
                       void * data,
                       VGint dataStride,
                       VGImageFormat dataFormat,
                       VGint x, VGint y,
                       VGint width, VGint height)
{
   struct vg_context *ctx = vg_current_context();
   struct vg_image *img;

   if (image == VG_INVALID_HANDLE) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }
   if (!supported_image_format(dataFormat)) {
      vg_set_error(ctx, VG_UNSUPPORTED_IMAGE_FORMAT_ERROR);
      return;
   }
   if (width <= 0 || height <= 0 || !data || !is_aligned(data)) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }
   img = (struct vg_image*)image;
   image_get_sub_data(img, data, dataStride, dataFormat,
                      x, y, width, height);
}
Пример #21
0
VGImage vgChildImage(VGImage parent,
                     VGint x, VGint y,
                     VGint width, VGint height)
{
   struct vg_context *ctx = vg_current_context();
   struct vg_image *p;

   if (parent == VG_INVALID_HANDLE ||
       !vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, (void*)parent) ||
       !vg_object_is_valid((void*)parent, VG_OBJECT_IMAGE)) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return VG_INVALID_HANDLE;
   }
   if (width <= 0 || height <= 0 || x < 0 || y < 0) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return VG_INVALID_HANDLE;
   }
   p = (struct vg_image *)parent;
   if (x > p->width  || y > p->height) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return VG_INVALID_HANDLE;
   }
   if (x + width > p->width  || y + height > p->height) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return VG_INVALID_HANDLE;
   }

   return (VGImage)image_child_image(p, x, y, width, height);
}
Пример #22
0
void font_draw_glyphs(struct vg_font *font,
                      VGint glyphCount,
                      const VGuint *glyphIndices,
                      const VGfloat *adjustments_x,
                      const VGfloat *adjustments_y,
                      VGbitfield paintModes,
                      VGboolean allowAutoHinting)
{
   struct vg_context *ctx = vg_current_context();
   VGint i;

   for (i = 0; i < glyphCount; ++i) {
      if (!get_glyph(font, glyphIndices[i])) {
         vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
         return;
      }
   }

   for (i = 0; i < glyphCount; ++i) {
      struct vg_glyph *glyph;
      VGfloat adj_x, adj_y;

      glyph = get_glyph(font, glyphIndices[i]);

      vg_render_glyph(ctx, glyph, paintModes, allowAutoHinting);

      adj_x = (adjustments_x) ? adjustments_x[i] : 0.0f;
      adj_y = (adjustments_y) ? adjustments_y[i] : 0.0f;
      vg_advance_glyph(ctx, glyph, adj_x, adj_y, (i == glyphCount - 1));
   }
}
Пример #23
0
VGPath vgCreatePath(VGint pathFormat,
                    VGPathDatatype datatype,
                    VGfloat scale, VGfloat bias,
                    VGint segmentCapacityHint,
                    VGint coordCapacityHint,
                    VGbitfield capabilities)
{
   struct vg_context *ctx = vg_current_context();

   if (pathFormat != VG_PATH_FORMAT_STANDARD) {
      vg_set_error(ctx, VG_UNSUPPORTED_PATH_FORMAT_ERROR);
      return VG_INVALID_HANDLE;
   }
   if (datatype < VG_PATH_DATATYPE_S_8 ||
       datatype > VG_PATH_DATATYPE_F) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return VG_INVALID_HANDLE;
   }
   if (!scale) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return VG_INVALID_HANDLE;
   }

   return (VGPath)path_create(datatype, scale, bias,
                              segmentCapacityHint, coordCapacityHint,
                              capabilities);
}
Пример #24
0
void image_draw(struct vg_image *img)
{
   struct vg_context *ctx = vg_current_context();
   VGfloat x1, y1;
   VGfloat x2, y2;
   VGfloat x3, y3;
   VGfloat x4, y4;
   struct matrix *matrix;

   x1 = 0;
   y1 = 0;
   x2 = img->width;
   y2 = 0;
   x3 = img->width;
   y3 = img->height;
   x4 = 0;
   y4 = img->height;

   matrix = &ctx->state.vg.image_user_to_surface_matrix;

   matrix_map_point(matrix, x1, y1, &x1, &y1);
   matrix_map_point(matrix, x2, y2, &x2, &y2);
   matrix_map_point(matrix, x3, y3, &x3, &y3);
   matrix_map_point(matrix, x4, y4, &x4, &y4);

   shader_set_drawing_image(ctx->shader, VG_TRUE);
   shader_set_paint(ctx->shader, ctx->state.vg.fill_paint);
   shader_set_image(ctx->shader, img);
   shader_bind(ctx->shader);

   renderer_texture_quad(ctx->renderer, image_texture(img),
                         img->x, img->y, img->x + img->width, img->y + img->height,
                         x1, y1, x2, y2, x3, y3, x4, y4);
}
Пример #25
0
void st_resize_framebuffer(struct st_framebuffer *stfb,
                           uint width, uint height)
{
   struct vg_context *ctx = vg_current_context();
   struct st_renderbuffer *strb = stfb->strb;
   struct pipe_framebuffer_state *state;

   if (!ctx)
      return;

   state = &ctx->state.g3d.fb;

   /* If this is a noop, exit early and don't do the clear, etc below.
    */
   if (strb->width == width &&
       strb->height == height &&
       state->zsbuf)
      return;

   if (strb->width != width || strb->height != height)
      st_renderbuffer_alloc_storage(ctx, strb,
                                 width, height);

   if (stfb->dsrb->width != width || stfb->dsrb->height != height)
      st_renderbuffer_alloc_storage(ctx, stfb->dsrb,
                                 width, height);

   {
      VGuint i;

      memset(state, 0, sizeof(struct pipe_framebuffer_state));

      state->width  = width;
      state->height = height;

      state->nr_cbufs = 1;
      state->cbufs[0] = strb->surface;
      for (i = 1; i < PIPE_MAX_COLOR_BUFS; ++i)
         state->cbufs[i] = 0;

      state->zsbuf = stfb->dsrb->surface;

      cso_set_framebuffer(ctx->cso_context, state);
   }

   ctx->state.dirty |= VIEWPORT_DIRTY;
   ctx->state.dirty |= DEPTH_STENCIL_DIRTY;/*to reset the scissors*/

   ctx->pipe->clear(ctx->pipe, PIPE_CLEAR_DEPTHSTENCIL,
                    NULL, 0.0, 0);

   /* we need all the other state already set */

   setup_new_alpha_mask(ctx, stfb, width, height);

   pipe_texture_reference( &stfb->blend_texture, NULL );
   stfb->blend_texture = create_texture(ctx->pipe, PIPE_FORMAT_A8R8G8B8_UNORM,
                                        width, height);
}
Пример #26
0
void vgPointAlongPath(VGPath path,
                      VGint startSegment,
                      VGint numSegments,
                      VGfloat distance,
                      VGfloat * x, VGfloat * y,
                      VGfloat * tangentX,
                      VGfloat * tangentY)
{
   struct vg_context *ctx = vg_current_context();
   struct path *p = 0;
   VGbitfield caps;

   if (path == VG_INVALID_HANDLE) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }
   if (startSegment < 0) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }
   if (numSegments <= 0) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }

   if (!is_aligned(x) || !is_aligned(y) ||
       !is_aligned(tangentX) || !is_aligned(tangentY)) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }

   p = (struct path*)path;

   caps = path_capabilities(p);
   if (!(caps & VG_PATH_CAPABILITY_POINT_ALONG_PATH) ||
       !(caps & VG_PATH_CAPABILITY_TANGENT_ALONG_PATH)) {
      vg_set_error(ctx, VG_PATH_CAPABILITY_ERROR);
      return;
   }

   if (startSegment + numSegments > path_num_segments(p)) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }

   {
      VGfloat point[2], normal[2];
      path_point(p, startSegment, numSegments, distance,
                 point, normal);
      if (x)
         *x = point[0];
      if (y)
         *y = point[1];
      if (tangentX)
         *tangentX = -normal[1];
      if (tangentY)
         *tangentY = normal[0];
   }
}
Пример #27
0
void image_destroy(struct vg_image *img)
{
   struct vg_context *ctx = vg_current_context();
   vg_context_remove_object(ctx, VG_OBJECT_IMAGE, img);


   if (img->parent) {
      /* remove img from the parent child array */
      int idx;
      struct vg_image **array =
         (struct vg_image **)img->parent->children_array->data;

      for (idx = 0; idx < img->parent->children_array->num_elements; ++idx) {
         struct vg_image *child = array[idx];
         if (child == img) {
            break;
         }
      }
      debug_assert(idx < img->parent->children_array->num_elements);
      array_remove_element(img->parent->children_array, idx);
   }

   if (img->children_array && img->children_array->num_elements) {
      /* reparent the children */
      VGint i;
      struct vg_image *parent = img->parent;
      struct vg_image **children =
         (struct vg_image **)img->children_array->data;
      if (!parent) {
         VGint min_x = children[0]->x;
         parent = children[0];

         for (i = 1; i < img->children_array->num_elements; ++i) {
            struct vg_image *child = children[i];
            if (child->x < min_x) {
               parent = child;
            }
         }
      }

      for (i = 0; i < img->children_array->num_elements; ++i) {
         struct vg_image *child = children[i];
         if (child != parent) {
            child->parent = parent;
            if (!parent->children_array) {
               parent->children_array = array_create(
                  sizeof(struct vg_image*));
            }
            array_append_data(parent->children_array,
                              &child, 1);
         } else
            child->parent = NULL;
      }
      array_destroy(img->children_array);
   }

   pipe_texture_reference(&img->texture, NULL);
   free(img);
}
Пример #28
0
void font_clear_glyph(struct vg_font *font,
                      VGuint glyphIndex)
{
   if (!del_glyph(font, glyphIndex)) {
      struct vg_context *ctx = vg_current_context();
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
   }
}
Пример #29
0
void vegaLookup(VGImage dst, VGImage src,
                const VGubyte * redLUT,
                const VGubyte * greenLUT,
                const VGubyte * blueLUT,
                const VGubyte * alphaLUT,
                VGboolean outputLinear,
                VGboolean outputPremultiplied)
{
   struct vg_context *ctx = vg_current_context();
   struct vg_image *d, *s;
   VGuint color_data[256];
   VGint i;
   struct pipe_sampler_view *lut_texture_view;
   VGfloat buffer[4];
   struct filter_info info;

   if (dst == VG_INVALID_HANDLE || src == VG_INVALID_HANDLE) {
      vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
      return;
   }

   if (!redLUT || !greenLUT || !blueLUT || !alphaLUT) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }

   d = handle_to_image(dst);
   s = handle_to_image(src);

   if (vg_image_overlaps(d, s)) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return;
   }

   for (i = 0; i < 256; ++i) {
      color_data[i] = blueLUT[i] << 24 | greenLUT[i] << 16 |
                      redLUT[i]  <<  8 | alphaLUT[i];
   }
   lut_texture_view = create_texture_1d_view(ctx, color_data, 255);

   buffer[0] = 0.f;
   buffer[1] = 0.f;
   buffer[2] = 1.f;
   buffer[3] = 1.f;

   info.dst = d;
   info.src = s;
   info.setup_shader = &setup_lookup;
   info.user_data = NULL;
   info.const_buffer = buffer;
   info.const_buffer_len = 4 * sizeof(VGfloat);
   info.tiling_mode = VG_TILE_PAD;
   info.extra_texture_view = lut_texture_view;

   execute_filter(ctx, &info);

   pipe_sampler_view_reference(&lut_texture_view, NULL);
}
Пример #30
0
VGFont vegaCreateFont(VGint glyphCapacityHint)
{
   struct vg_context *ctx = vg_current_context();

   if (glyphCapacityHint < 0) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return VG_INVALID_HANDLE;
   }

   return (VGFont) font_create(glyphCapacityHint);
}