1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/*
* secde -- experimental lightweight Wayland/X11 server
* Copyright (C) 2019 Samuel Lidén Borell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <string.h>
#include "fbops.h"
struct FbAddrInfo {
/* TODO support for non byte addressable pixel formats */
unsigned char *start;
};
int fbops_cliprect(struct FbRect *rect,
const struct FbRect *clip)
{
int end, clipend;
/* Left */
if (rect->x < clip->x) {
int diff = clip->x - rect->x;
rect->x += diff;
if (rect->w <= diff) return 0;
rect->w -= diff;
}
/* Top */
if (rect->y < clip->y) {
int diff = clip->y - rect->y;
rect->y += diff;
if (rect->h <= diff) return 0;
rect->h -= diff;
}
/* Right */
end = rect->x + rect->w;
clipend = clip->x + clip->w;
if (end < clipend) {
int diff = clipend - end;
if (rect->w <= diff) return 0;
rect->w -= diff;
}
/* Bottom */
end = rect->y + rect->h;
clipend = clip->y + clip->h;
if (end < clipend) {
int diff = clipend - end;
if (rect->h <= diff) return 0;
rect->h -= diff;
}
return 1;
}
int fbops_cliprect1(struct FbRect *destrect,
struct FbRect *srcrect,
const struct FbRect *destclip)
{
(void) destrect;
(void) srcrect;
(void) destclip;
/* TODO */
return 0;
}
static unsigned char *getaddr(const struct FbPixelFormat *format,
const struct FbSurf *surf,
short x, short y)
{
return &surf->pixels[surf->line_length*y +
format->bytes_per_pixel*x];
}
void fbops_fillrect(struct FbDestSurf *destsurf,
const struct FbRect *rect,
const FbColor color)
{
unsigned char *p = getaddr(destsurf->format, destsurf->surf,
rect->x, rect->y);
short h = rect->h;
short len = rect->w * destsurf->format->bytes_per_pixel;
short linelen = destsurf->surf->line_length;
if (color <= 255) { /* high bits zero = direct byte value */
while (h--) {
memset(p, color, len);
p += linelen;
}
} else {
while (h--) {
/* TODO */
p += linelen;
}
}
}
void fbops_copysurf(struct FbDestSurf *destsurf,
short x, short y,
const struct FbSurf *srcsurf)
{
struct FbRect srcrect = { 0, 0, srcsurf->w, srcsurf->h };
fbops_copysurf1(destsurf, x, y, srcsurf, &srcrect);
}
void fbops_copysurf1(struct FbDestSurf *destsurf,
short x, short y,
const struct FbSurf *srcsurf,
const struct FbRect *srcrect)
{
short h = srcrect->h;
short d_linelen = destsurf->surf->line_length;
short s_linelen = srcsurf->line_length;
short len = srcrect->w * destsurf->format->bytes_per_pixel;
unsigned char *dp, *sp;
dp = getaddr(destsurf->format, destsurf->surf, x, y);
sp = getaddr(destsurf->format, srcsurf,
srcrect->x, srcrect->y);
while (h--) {
memcpy(dp, sp, len);
dp += d_linelen;
sp += s_linelen;
}
}
void fbops_moverect(struct FbDestSurf *destsurf,
short destx, short desty,
const struct FbRect *srcrect)
{
short sx = srcrect->x;
short sy = srcrect->y;
short w = srcrect->w;
short h = srcrect->h;
if (desty < sy ||
destx+w < sx || sx+w > destx ||
desty+h < sy || sy+h > desty) {
/* Non-overlapping copy, or copying "down".
In this case we can use a plain copysurf */
fbops_copysurf1(destsurf, destx, desty, destsurf->surf, srcrect);
return;
}
/* TODO */
}
|