Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /* cairo - a vector graphics library with display and print output
  2.  *
  3.  * Copyright © 2011 Intel Corporation
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it either under the terms of the GNU Lesser General Public
  7.  * License version 2.1 as published by the Free Software Foundation
  8.  * (the "LGPL") or, at your option, under the terms of the Mozilla
  9.  * Public License Version 1.1 (the "MPL"). If you do not alter this
  10.  * notice, a recipient may use your version of this file under either
  11.  * the MPL or the LGPL.
  12.  *
  13.  * You should have received a copy of the LGPL along with this library
  14.  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
  15.  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
  16.  * You should have received a copy of the MPL along with this library
  17.  * in the file COPYING-MPL-1.1
  18.  *
  19.  * The contents of this file are subject to the Mozilla Public License
  20.  * Version 1.1 (the "License"); you may not use this file except in
  21.  * compliance with the License. You may obtain a copy of the License at
  22.  * http://www.mozilla.org/MPL/
  23.  *
  24.  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
  25.  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
  26.  * the specific language governing rights and limitations.
  27.  *
  28.  * The Original Code is the cairo graphics library.
  29.  *
  30.  * The Initial Developer of the Original Code is Intel Corporation
  31.  *
  32.  * Contributor(s):
  33.  *      Chris Wilson <chris@chris-wilson.co.uk>
  34.  */
  35.  
  36.  
  37. #include "cairoint.h"
  38.  
  39. #include "test-null-compositor-surface.h"
  40.  
  41. #include "cairo-compositor-private.h"
  42. #include "cairo-default-context-private.h"
  43. #include "cairo-error-private.h"
  44. #include "cairo-image-surface-private.h"
  45. #include "cairo-surface-backend-private.h"
  46. #include "cairo-spans-compositor-private.h"
  47. #include "cairo-spans-private.h"
  48.  
  49. typedef struct _test_compositor_surface {
  50.     cairo_image_surface_t base;
  51. } test_compositor_surface_t;
  52.  
  53. static const cairo_surface_backend_t test_compositor_surface_backend;
  54.  
  55. static cairo_surface_t *
  56. test_compositor_surface_create (const cairo_compositor_t *compositor,
  57.                                 cairo_content_t content,
  58.                                 int             width,
  59.                                 int             height)
  60. {
  61.     test_compositor_surface_t *surface;
  62.     pixman_image_t *pixman_image;
  63.     pixman_format_code_t pixman_format;
  64.  
  65.     switch (content) {
  66.     case CAIRO_CONTENT_ALPHA:
  67.         pixman_format = PIXMAN_a8;
  68.         break;
  69.     case CAIRO_CONTENT_COLOR:
  70.         pixman_format = PIXMAN_x8r8g8b8;
  71.         break;
  72.     case CAIRO_CONTENT_COLOR_ALPHA:
  73.         pixman_format = PIXMAN_a8r8g8b8;
  74.         break;
  75.     default:
  76.         return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT));
  77.     }
  78.  
  79.     pixman_image = pixman_image_create_bits (pixman_format, width, height,
  80.                                              NULL, 0);
  81.     if (unlikely (pixman_image == NULL))
  82.         return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
  83.  
  84.     surface = malloc (sizeof (test_compositor_surface_t));
  85.     if (unlikely (surface == NULL)) {
  86.         pixman_image_unref (pixman_image);
  87.         return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
  88.     }
  89.  
  90.     _cairo_surface_init (&surface->base.base,
  91.                          &test_compositor_surface_backend,
  92.                          NULL, /* device */
  93.                          content);
  94.     _cairo_image_surface_init (&surface->base, pixman_image, pixman_format);
  95.  
  96.     surface->base.compositor = compositor;
  97.  
  98.     return &surface->base.base;
  99. }
  100.  
  101. static cairo_surface_t *
  102. test_compositor_surface_create_similar (void            *abstract_surface,
  103.                                         cairo_content_t  content,
  104.                                         int              width,
  105.                                         int              height)
  106. {
  107.     test_compositor_surface_t *surface = abstract_surface;
  108.  
  109.     return test_compositor_surface_create (surface->base.compositor,
  110.                                            content, width, height);
  111. }
  112.  
  113. static cairo_int_status_t
  114. test_compositor_surface_paint (void                     *_surface,
  115.                                cairo_operator_t          op,
  116.                                const cairo_pattern_t    *source,
  117.                                const cairo_clip_t       *clip)
  118. {
  119.     test_compositor_surface_t *surface = _surface;
  120.     return _cairo_compositor_paint (surface->base.compositor,
  121.                                     _surface, op, source,
  122.                                     clip);
  123. }
  124.  
  125. static cairo_int_status_t
  126. test_compositor_surface_mask (void                      *_surface,
  127.                               cairo_operator_t           op,
  128.                               const cairo_pattern_t     *source,
  129.                               const cairo_pattern_t     *mask,
  130.                               const cairo_clip_t        *clip)
  131. {
  132.     test_compositor_surface_t *surface = _surface;
  133.     return _cairo_compositor_mask (surface->base.compositor,
  134.                                    _surface, op, source, mask,
  135.                                     clip);
  136. }
  137.  
  138. static cairo_int_status_t
  139. test_compositor_surface_stroke (void                            *_surface,
  140.                                 cairo_operator_t                 op,
  141.                                 const cairo_pattern_t           *source,
  142.                                 const cairo_path_fixed_t        *path,
  143.                                 const cairo_stroke_style_t      *style,
  144.                                 const cairo_matrix_t            *ctm,
  145.                                 const cairo_matrix_t            *ctm_inverse,
  146.                                 double                           tolerance,
  147.                                 cairo_antialias_t                antialias,
  148.                                 const cairo_clip_t              *clip)
  149. {
  150.     test_compositor_surface_t *surface = _surface;
  151.     return _cairo_compositor_stroke (surface->base.compositor,
  152.                                      _surface, op, source,
  153.                                      path, style, ctm, ctm_inverse,
  154.                                      tolerance, antialias,
  155.                                      clip);
  156. }
  157.  
  158. static cairo_int_status_t
  159. test_compositor_surface_fill (void                      *_surface,
  160.                               cairo_operator_t           op,
  161.                               const cairo_pattern_t     *source,
  162.                               const cairo_path_fixed_t  *path,
  163.                               cairo_fill_rule_t          fill_rule,
  164.                               double                     tolerance,
  165.                               cairo_antialias_t          antialias,
  166.                               const cairo_clip_t        *clip)
  167. {
  168.     test_compositor_surface_t *surface = _surface;
  169.     return _cairo_compositor_fill (surface->base.compositor,
  170.                                    _surface, op, source,
  171.                                    path, fill_rule, tolerance, antialias,
  172.                                    clip);
  173. }
  174.  
  175. static cairo_int_status_t
  176. test_compositor_surface_glyphs (void                    *_surface,
  177.                                 cairo_operator_t         op,
  178.                                 const cairo_pattern_t   *source,
  179.                                 cairo_glyph_t           *glyphs,
  180.                                 int                      num_glyphs,
  181.                                 cairo_scaled_font_t     *scaled_font,
  182.                                 const cairo_clip_t      *clip)
  183. {
  184.     test_compositor_surface_t *surface = _surface;
  185.     return _cairo_compositor_glyphs (surface->base.compositor,
  186.                                      _surface, op, source,
  187.                                      glyphs, num_glyphs, scaled_font,
  188.                                      clip);
  189. }
  190.  
  191. static const cairo_surface_backend_t test_compositor_surface_backend = {
  192.     CAIRO_SURFACE_TYPE_IMAGE,
  193.     _cairo_image_surface_finish,
  194.     _cairo_default_context_create,
  195.  
  196.     test_compositor_surface_create_similar,
  197.     NULL, /* create similar image */
  198.     _cairo_image_surface_map_to_image,
  199.     _cairo_image_surface_unmap_image,
  200.  
  201.     _cairo_image_surface_source,
  202.     _cairo_image_surface_acquire_source_image,
  203.     _cairo_image_surface_release_source_image,
  204.     NULL, /* snapshot */
  205.  
  206.     NULL, /* copy_page */
  207.     NULL, /* show_page */
  208.  
  209.     _cairo_image_surface_get_extents,
  210.     _cairo_image_surface_get_font_options,
  211.  
  212.     NULL, /* flush */
  213.     NULL, /* mark_dirty_rectangle */
  214.  
  215.     test_compositor_surface_paint,
  216.     test_compositor_surface_mask,
  217.     test_compositor_surface_stroke,
  218.     test_compositor_surface_fill,
  219.     NULL, /* fill/stroke */
  220.     test_compositor_surface_glyphs,
  221. };
  222.  
  223. static cairo_int_status_t
  224. acquire (void *abstract_dst)
  225. {
  226.     return CAIRO_STATUS_SUCCESS;
  227. }
  228.  
  229. static cairo_int_status_t
  230. release (void *abstract_dst)
  231. {
  232.     return CAIRO_STATUS_SUCCESS;
  233. }
  234.  
  235. static cairo_int_status_t
  236. set_clip_region (void *_surface,
  237.                  cairo_region_t *region)
  238. {
  239.     return CAIRO_STATUS_SUCCESS;
  240. }
  241.  
  242. static cairo_surface_t *
  243. pattern_to_surface (cairo_surface_t *dst,
  244.                     const cairo_pattern_t *pattern,
  245.                     cairo_bool_t is_mask,
  246.                     const cairo_rectangle_int_t *extents,
  247.                     const cairo_rectangle_int_t *sample,
  248.                     int *src_x, int *src_y)
  249. {
  250.     return cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0);
  251. }
  252.  
  253. static cairo_int_status_t
  254. fill_boxes (void                *_dst,
  255.             cairo_operator_t     op,
  256.             const cairo_color_t *color,
  257.             cairo_boxes_t       *boxes)
  258. {
  259.     return CAIRO_STATUS_SUCCESS;
  260. }
  261.  
  262. static cairo_int_status_t
  263. draw_image_boxes (void *_dst,
  264.                   cairo_image_surface_t *image,
  265.                   cairo_boxes_t *boxes,
  266.                   int dx, int dy)
  267. {
  268.     return CAIRO_STATUS_SUCCESS;
  269. }
  270.  
  271. static cairo_int_status_t
  272. composite (void                 *_dst,
  273.            cairo_operator_t     op,
  274.            cairo_surface_t      *abstract_src,
  275.            cairo_surface_t      *abstract_mask,
  276.            int                  src_x,
  277.            int                  src_y,
  278.            int                  mask_x,
  279.            int                  mask_y,
  280.            int                  dst_x,
  281.            int                  dst_y,
  282.            unsigned int         width,
  283.            unsigned int         height)
  284. {
  285.     return CAIRO_STATUS_SUCCESS;
  286. }
  287.  
  288. static cairo_int_status_t
  289. lerp (void                      *_dst,
  290.       cairo_surface_t           *abstract_src,
  291.       cairo_surface_t           *abstract_mask,
  292.       int                       src_x,
  293.       int                       src_y,
  294.       int                       mask_x,
  295.       int                       mask_y,
  296.       int                       dst_x,
  297.       int                       dst_y,
  298.       unsigned int              width,
  299.       unsigned int              height)
  300. {
  301.     return CAIRO_STATUS_SUCCESS;
  302. }
  303.  
  304. static cairo_int_status_t
  305. composite_boxes (void                   *_dst,
  306.                  cairo_operator_t       op,
  307.                  cairo_surface_t        *abstract_src,
  308.                  cairo_surface_t        *abstract_mask,
  309.                  int                    src_x,
  310.                  int                    src_y,
  311.                  int                    mask_x,
  312.                  int                    mask_y,
  313.                  int                    dst_x,
  314.                  int                    dst_y,
  315.                  cairo_boxes_t          *boxes,
  316.                  const cairo_rectangle_int_t  *extents)
  317. {
  318.     return CAIRO_STATUS_SUCCESS;
  319. }
  320.  
  321. static cairo_int_status_t
  322. composite_traps (void                   *_dst,
  323.                  cairo_operator_t       op,
  324.                  cairo_surface_t        *abstract_src,
  325.                  int                    src_x,
  326.                  int                    src_y,
  327.                  int                    dst_x,
  328.                  int                    dst_y,
  329.                  const cairo_rectangle_int_t *extents,
  330.                  cairo_antialias_t      antialias,
  331.                  cairo_traps_t          *traps)
  332. {
  333.     return CAIRO_STATUS_SUCCESS;
  334. }
  335.  
  336. static cairo_int_status_t
  337. check_composite_glyphs (const cairo_composite_rectangles_t *extents,
  338.                         cairo_scaled_font_t *scaled_font,
  339.                         cairo_glyph_t *glyphs,
  340.                         int *num_glyphs)
  341. {
  342.     return CAIRO_STATUS_SUCCESS;
  343. }
  344.  
  345. static cairo_int_status_t
  346. composite_glyphs (void                          *_dst,
  347.                   cairo_operator_t               op,
  348.                   cairo_surface_t               *_src,
  349.                   int                            src_x,
  350.                   int                            src_y,
  351.                   int                            dst_x,
  352.                   int                            dst_y,
  353.                   cairo_composite_glyphs_info_t *info)
  354. {
  355.     return CAIRO_STATUS_SUCCESS;
  356. }
  357.  
  358. static cairo_status_t
  359. spans (void *abstract_renderer,
  360.        int y, int height,
  361.        const cairo_half_open_span_t *spans,
  362.        unsigned num_spans)
  363. {
  364.     return CAIRO_STATUS_SUCCESS;
  365. }
  366.  
  367. static cairo_status_t
  368. finish_spans (void *abstract_renderer)
  369. {
  370.     return CAIRO_STATUS_SUCCESS;
  371. }
  372.  
  373. static cairo_int_status_t
  374. span_renderer_init (cairo_abstract_span_renderer_t      *_r,
  375.                     const cairo_composite_rectangles_t *composite,
  376.                     cairo_antialias_t                   antialias,
  377.                     cairo_bool_t                        needs_clip)
  378. {
  379.     cairo_span_renderer_t *r = (cairo_span_renderer_t *)_r;
  380.     r->render_rows = spans;
  381.     r->finish = finish_spans;
  382.     return CAIRO_STATUS_SUCCESS;
  383. }
  384.  
  385. static void
  386. span_renderer_fini (cairo_abstract_span_renderer_t *_r,
  387.                     cairo_int_status_t status)
  388. {
  389. }
  390.  
  391. static const cairo_compositor_t *
  392. no_fallback_compositor_get (void)
  393. {
  394.     return &__cairo_no_compositor;
  395. }
  396.  
  397. static cairo_int_status_t
  398. check_composite (const cairo_composite_rectangles_t *extents)
  399. {
  400.     return CAIRO_STATUS_SUCCESS;
  401. }
  402.  
  403. static const cairo_compositor_t *
  404. no_traps_compositor_get (void)
  405. {
  406.     static cairo_traps_compositor_t compositor;
  407.  
  408.     if (compositor.base.delegate == NULL) {
  409.         _cairo_traps_compositor_init (&compositor,
  410.                                       no_fallback_compositor_get ());
  411.  
  412.         compositor.acquire = acquire;
  413.         compositor.release = release;
  414.         compositor.set_clip_region = set_clip_region;
  415.         compositor.pattern_to_surface = pattern_to_surface;
  416.         compositor.draw_image_boxes = draw_image_boxes;
  417.         //compositor.copy_boxes = copy_boxes;
  418.         compositor.fill_boxes = fill_boxes;
  419.         compositor.check_composite = check_composite;
  420.         compositor.composite = composite;
  421.         compositor.lerp = lerp;
  422.         //compositor.check_composite_boxes = check_composite_boxes;
  423.         compositor.composite_boxes = composite_boxes;
  424.         //compositor.check_composite_traps = check_composite_traps;
  425.         compositor.composite_traps = composite_traps;
  426.         compositor.check_composite_glyphs = check_composite_glyphs;
  427.         compositor.composite_glyphs = composite_glyphs;
  428.     }
  429.  
  430.     return &compositor.base;
  431. }
  432.  
  433. static const cairo_compositor_t *
  434. no_spans_compositor_get (void)
  435. {
  436.     static cairo_spans_compositor_t compositor;
  437.  
  438.     if (compositor.base.delegate == NULL) {
  439.         _cairo_spans_compositor_init (&compositor,
  440.                                       no_traps_compositor_get());
  441.  
  442.         //compositor.acquire = acquire;
  443.         //compositor.release = release;
  444.         compositor.fill_boxes = fill_boxes;
  445.         //compositor.check_composite_boxes = check_composite_boxes;
  446.         compositor.composite_boxes = composite_boxes;
  447.         //compositor.check_span_renderer = check_span_renderer;
  448.         compositor.renderer_init = span_renderer_init;
  449.         compositor.renderer_fini = span_renderer_fini;
  450.     }
  451.  
  452.     return &compositor.base;
  453. }
  454.  
  455. cairo_surface_t *
  456. _cairo_test_no_fallback_compositor_surface_create (cairo_content_t      content,
  457.                                                    int          width,
  458.                                                    int          height)
  459. {
  460.     return test_compositor_surface_create (no_fallback_compositor_get(),
  461.                                            content, width, height);
  462. }
  463.  
  464. cairo_surface_t *
  465. _cairo_test_no_traps_compositor_surface_create (cairo_content_t content,
  466.                                                 int             width,
  467.                                                 int             height)
  468. {
  469.     return test_compositor_surface_create (no_traps_compositor_get(),
  470.                                            content, width, height);
  471. }
  472.  
  473. cairo_surface_t *
  474. _cairo_test_no_spans_compositor_surface_create (cairo_content_t content,
  475.                                              int                width,
  476.                                              int                height)
  477. {
  478.     return test_compositor_surface_create (no_spans_compositor_get(),
  479.                                            content, width, height);
  480. }
  481.