mmx: Use Loongson pextrh instruction in expand565
[profile/ivi/pixman.git] / pixman / pixman-noop.c
1 /* -*- Mode: c; c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t; -*- */
2 /*
3  * Copyright © 2011 Red Hat, Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 #include <string.h>
28 #include <stdlib.h>
29 #include "pixman-private.h"
30 #include "pixman-combine32.h"
31 #include "pixman-inlines.h"
32
33 static void
34 noop_composite (pixman_implementation_t *imp,
35                 pixman_composite_info_t *info)
36 {
37     return;
38 }
39
40 static void
41 dest_write_back_direct (pixman_iter_t *iter)
42 {
43     iter->buffer += iter->image->bits.rowstride;
44 }
45
46 static uint32_t *
47 noop_get_scanline (pixman_iter_t *iter, const uint32_t *mask)
48 {
49     uint32_t *result = iter->buffer;
50
51     iter->buffer += iter->image->bits.rowstride;
52
53     return result;
54 }
55
56 static uint32_t *
57 get_scanline_null (pixman_iter_t *iter, const uint32_t *mask)
58 {
59     return NULL;
60 }
61
62 static void
63 noop_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
64 {
65     pixman_image_t *image = iter->image;
66
67 #define FLAGS                                           \
68     (FAST_PATH_STANDARD_FLAGS | FAST_PATH_ID_TRANSFORM)
69
70     if (!image)
71     {
72         iter->get_scanline = get_scanline_null;
73     }
74     else if ((iter->flags & (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB)) ==
75              (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB))
76     {
77         iter->get_scanline = _pixman_iter_get_scanline_noop;
78     }
79     else if (image->common.extended_format_code == PIXMAN_solid         &&
80              ((image->common.flags & (FAST_PATH_BITS_IMAGE | FAST_PATH_NO_ALPHA_MAP)) ==
81               (FAST_PATH_BITS_IMAGE | FAST_PATH_NO_ALPHA_MAP)))
82     {
83         bits_image_t *bits = &image->bits;
84
85         if (iter->flags & ITER_NARROW)
86         {
87             uint32_t color = bits->fetch_pixel_32 (bits, 0, 0);
88             uint32_t *buffer = iter->buffer;
89             uint32_t *end = buffer + iter->width;
90
91             while (buffer < end)
92                 *(buffer++) = color;
93         }
94         else
95         {
96             uint64_t color = bits->fetch_pixel_64 (bits, 0, 0);
97             uint64_t *buffer = (uint64_t *)iter->buffer;
98             uint64_t *end = buffer + iter->width;
99
100             while (buffer < end)
101                 *(buffer++) = color;
102         }
103
104         iter->get_scanline = _pixman_iter_get_scanline_noop;
105     }
106     else if (image->common.extended_format_code == PIXMAN_a8r8g8b8      &&
107              (iter->flags & ITER_NARROW)                                &&
108              (image->common.flags & FLAGS) == FLAGS                     &&
109              iter->x >= 0 && iter->y >= 0                               &&
110              iter->x + iter->width <= image->bits.width                 &&
111              iter->y + iter->height <= image->bits.height)
112     {
113         iter->buffer =
114             image->bits.bits + iter->y * image->bits.rowstride + iter->x;
115
116         iter->get_scanline = noop_get_scanline;
117     }
118     else
119     {
120         (* imp->delegate->src_iter_init) (imp->delegate, iter);
121     }
122 }
123
124 static void
125 noop_dest_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
126 {
127     pixman_image_t *image = iter->image;
128     uint32_t image_flags = image->common.flags;
129     uint32_t iter_flags = iter->flags;
130     
131     if ((image_flags & FAST_PATH_STD_DEST_FLAGS) == FAST_PATH_STD_DEST_FLAGS    &&
132         (iter_flags & ITER_NARROW) == ITER_NARROW                               &&
133         ((image->common.extended_format_code == PIXMAN_a8r8g8b8)        ||
134          (image->common.extended_format_code == PIXMAN_x8r8g8b8 &&
135           (iter_flags & (ITER_LOCALIZED_ALPHA)))))
136     {
137         iter->buffer = image->bits.bits + iter->y * image->bits.rowstride + iter->x;
138
139         iter->get_scanline = _pixman_iter_get_scanline_noop;
140         iter->write_back = dest_write_back_direct;
141     }
142     else
143     {
144         (* imp->delegate->dest_iter_init) (imp->delegate, iter);
145     }
146 }
147
148 static const pixman_fast_path_t noop_fast_paths[] =
149 {
150     { PIXMAN_OP_DST, PIXMAN_any, 0, PIXMAN_any, 0, PIXMAN_any, 0, noop_composite },
151     { PIXMAN_OP_NONE },
152 };
153
154 pixman_implementation_t *
155 _pixman_implementation_create_noop (pixman_implementation_t *fallback)
156 {
157     pixman_implementation_t *imp =
158         _pixman_implementation_create (fallback, noop_fast_paths);
159
160     imp->src_iter_init = noop_src_iter_init;
161     imp->dest_iter_init = noop_dest_iter_init;
162
163     return imp;
164 }