Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2009 VMware, Inc.  All Rights Reserved.
  4.  *
  5.  * Permission is hereby granted, free of charge, to any person obtaining a
  6.  * copy of this software and associated documentation files (the
  7.  * "Software"), to deal in the Software without restriction, including
  8.  * without limitation the rights to use, copy, modify, merge, publish,
  9.  * distribute, sub license, and/or sell copies of the Software, and to
  10.  * permit persons to whom the Software is furnished to do so, subject to
  11.  * the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice (including the
  14.  * next paragraph) shall be included in all copies or substantial portions
  15.  * of the Software.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  20.  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  21.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  22.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  23.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24.  *
  25.  **************************************************************************/
  26.  
  27. #include "VG/openvg.h"
  28.  
  29. #include "vg_context.h"
  30. #include "paint.h"
  31. #include "api.h"
  32. #include "handle.h"
  33.  
  34.  
  35. VGPaint vegaCreatePaint(void)
  36. {
  37.    return paint_to_handle(paint_create(vg_current_context()));
  38. }
  39.  
  40. void vegaDestroyPaint(VGPaint p)
  41. {
  42.    struct vg_context *ctx = vg_current_context();
  43.  
  44.    if (p == VG_INVALID_HANDLE) {
  45.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  46.       return;
  47.    }
  48.  
  49.    paint_destroy(handle_to_paint(p));
  50. }
  51.  
  52. void vegaSetPaint(VGPaint paint, VGbitfield paintModes)
  53. {
  54.    struct vg_context *ctx = vg_current_context();
  55.  
  56.    if (paint == VG_INVALID_HANDLE) {
  57.       /* restore the default */
  58.       paint = paint_to_handle(ctx->default_paint);
  59.    } else if (!vg_object_is_valid(paint, VG_OBJECT_PAINT)) {
  60.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  61.       return;
  62.    }
  63.  
  64.    if (!(paintModes & ((VG_FILL_PATH|VG_STROKE_PATH)))) {
  65.       vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
  66.       return;
  67.    }
  68.  
  69.    if (paintModes & VG_FILL_PATH) {
  70.       ctx->state.vg.fill_paint = handle_to_paint(paint);
  71.    }
  72.    if (paintModes & VG_STROKE_PATH) {
  73.       ctx->state.vg.stroke_paint = handle_to_paint(paint);
  74.    }
  75.  
  76.    ctx->state.dirty |= PAINT_DIRTY;
  77. }
  78.  
  79. VGPaint vegaGetPaint(VGPaintMode paintMode)
  80. {
  81.    struct vg_context *ctx = vg_current_context();
  82.    VGPaint paint = VG_INVALID_HANDLE;
  83.  
  84.    if (paintMode < VG_STROKE_PATH || paintMode > VG_FILL_PATH) {
  85.       vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
  86.       return VG_INVALID_HANDLE;
  87.    }
  88.  
  89.    if (paintMode == VG_FILL_PATH)
  90.       paint = paint_to_handle(ctx->state.vg.fill_paint);
  91.    else if (paintMode == VG_STROKE_PATH)
  92.       paint = paint_to_handle(ctx->state.vg.stroke_paint);
  93.  
  94.    if (paint == paint_to_handle(ctx->default_paint))
  95.       paint = VG_INVALID_HANDLE;
  96.  
  97.    return paint;
  98. }
  99.  
  100. void vegaSetColor(VGPaint paint, VGuint rgba)
  101. {
  102.    struct vg_context *ctx = vg_current_context();
  103.    struct vg_paint *p;
  104.  
  105.    if (paint == VG_INVALID_HANDLE) {
  106.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  107.       return;
  108.    }
  109.  
  110.    if (!vg_object_is_valid(paint, VG_OBJECT_PAINT)) {
  111.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  112.       return;
  113.    }
  114.  
  115.    p = handle_to_paint(paint);
  116.    paint_set_colori(p, rgba);
  117.  
  118.    if (ctx->state.vg.fill_paint == p ||
  119.        ctx->state.vg.stroke_paint == p)
  120.       ctx->state.dirty |= PAINT_DIRTY;
  121. }
  122.  
  123. VGuint vegaGetColor(VGPaint paint)
  124. {
  125.    struct vg_context *ctx = vg_current_context();
  126.    struct vg_paint *p;
  127.    VGuint rgba = 0;
  128.  
  129.    if (paint == VG_INVALID_HANDLE) {
  130.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  131.       return rgba;
  132.    }
  133.  
  134.    if (!vg_object_is_valid(paint, VG_OBJECT_PAINT)) {
  135.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  136.       return rgba;
  137.    }
  138.    p = handle_to_paint(paint);
  139.  
  140.    return paint_colori(p);
  141. }
  142.  
  143. void vegaPaintPattern(VGPaint paint, VGImage pattern)
  144. {
  145.    struct vg_context *ctx = vg_current_context();
  146.  
  147.    if (paint == VG_INVALID_HANDLE ||
  148.        !vg_context_is_object_valid(ctx, VG_OBJECT_PAINT, paint)) {
  149.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  150.       return;
  151.    }
  152.  
  153.    if (pattern == VG_INVALID_HANDLE) {
  154.       paint_set_type(handle_to_paint(paint), VG_PAINT_TYPE_COLOR);
  155.       return;
  156.    }
  157.  
  158.    if (!vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, pattern)) {
  159.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  160.       return;
  161.    }
  162.  
  163.  
  164.    if (!vg_object_is_valid(paint, VG_OBJECT_PAINT) ||
  165.        !vg_object_is_valid(pattern, VG_OBJECT_IMAGE)) {
  166.       vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
  167.       return;
  168.    }
  169.    paint_set_pattern(handle_to_paint(paint),
  170.                      handle_to_image(pattern));
  171. }
  172.  
  173.