pixman-solid-fill.c revision d0321353
1317c648bSmrg/*
2317c648bSmrg * Copyright © 2000 SuSE, Inc.
3317c648bSmrg * Copyright © 2007, 2009 Red Hat, Inc.
4317c648bSmrg * Copyright © 2009 Soren Sandmann
5317c648bSmrg *
6317c648bSmrg * Permission to use, copy, modify, distribute, and sell this software and its
7317c648bSmrg * documentation for any purpose is hereby granted without fee, provided that
8317c648bSmrg * the above copyright notice appear in all copies and that both that
9317c648bSmrg * copyright notice and this permission notice appear in supporting
10317c648bSmrg * documentation, and that the name of SuSE not be used in advertising or
11317c648bSmrg * publicity pertaining to distribution of the software without specific,
12317c648bSmrg * written prior permission.  SuSE makes no representations about the
13317c648bSmrg * suitability of this software for any purpose.  It is provided "as is"
14317c648bSmrg * without express or implied warranty.
15317c648bSmrg *
16317c648bSmrg * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17317c648bSmrg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
18317c648bSmrg * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19317c648bSmrg * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20317c648bSmrg * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21317c648bSmrg * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22317c648bSmrg */
23317c648bSmrg
24317c648bSmrg#include <config.h>
25317c648bSmrg#include "pixman-private.h"
26317c648bSmrg
27317c648bSmrgstatic void
28d0321353Smrgsolid_fill_get_scanline_32 (pixman_image_t *image,
29d0321353Smrg                            int             x,
30d0321353Smrg                            int             y,
31d0321353Smrg                            int             width,
32d0321353Smrg                            uint32_t *      buffer,
33d0321353Smrg                            const uint32_t *mask,
34d0321353Smrg                            uint32_t        mask_bits)
35317c648bSmrg{
36317c648bSmrg    uint32_t *end = buffer + width;
37317c648bSmrg    register uint32_t color = ((solid_fill_t *)image)->color;
38d0321353Smrg
39317c648bSmrg    while (buffer < end)
40317c648bSmrg	*(buffer++) = color;
41d0321353Smrg
42317c648bSmrg    return;
43317c648bSmrg}
44317c648bSmrg
45317c648bSmrgstatic source_pict_class_t
46317c648bSmrgsolid_fill_classify (pixman_image_t *image,
47d0321353Smrg                     int             x,
48d0321353Smrg                     int             y,
49d0321353Smrg                     int             width,
50d0321353Smrg                     int             height)
51317c648bSmrg{
52317c648bSmrg    return (image->source.class = SOURCE_IMAGE_CLASS_HORIZONTAL);
53317c648bSmrg}
54317c648bSmrg
55317c648bSmrgstatic void
56317c648bSmrgsolid_fill_property_changed (pixman_image_t *image)
57317c648bSmrg{
58dc259aabSmrg    image->common.get_scanline_32 = solid_fill_get_scanline_32;
59d0321353Smrg    image->common.get_scanline_64 = _pixman_image_get_scanline_generic_64;
60317c648bSmrg}
61317c648bSmrg
62317c648bSmrgstatic uint32_t
63317c648bSmrgcolor_to_uint32 (const pixman_color_t *color)
64317c648bSmrg{
65317c648bSmrg    return
66d0321353Smrg        (color->alpha >> 8 << 24) |
67d0321353Smrg        (color->red >> 8 << 16) |
68317c648bSmrg        (color->green & 0xff00) |
69d0321353Smrg        (color->blue >> 8);
70317c648bSmrg}
71317c648bSmrg
72317c648bSmrgPIXMAN_EXPORT pixman_image_t *
73317c648bSmrgpixman_image_create_solid_fill (pixman_color_t *color)
74317c648bSmrg{
75d0321353Smrg    pixman_image_t *img = _pixman_image_allocate ();
76d0321353Smrg
77317c648bSmrg    if (!img)
78317c648bSmrg	return NULL;
79317c648bSmrg
80317c648bSmrg    img->type = SOLID;
81317c648bSmrg    img->solid.color = color_to_uint32 (color);
82317c648bSmrg
83317c648bSmrg    img->source.class = SOURCE_IMAGE_CLASS_UNKNOWN;
84317c648bSmrg    img->common.classify = solid_fill_classify;
85317c648bSmrg    img->common.property_changed = solid_fill_property_changed;
86317c648bSmrg
87317c648bSmrg    solid_fill_property_changed (img);
88d0321353Smrg
89317c648bSmrg    return img;
90317c648bSmrg}
91d0321353Smrg
92