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
|
/*
* DRM based rotator test program
* Copyright 2012 Samsung Electronics
* YoungJun Cho <yj44.cho@samsung.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "exynos_drm.h"
#include "gem.h"
int util_gem_create_mmap(int fd, struct drm_exynos_gem_create *gem,
struct exynos_gem_mmap_data *mmap,
unsigned int size)
{
struct drm_gem_close args;
/* initialize structure for gem create */
memset(gem, 0x00, sizeof(struct drm_exynos_gem_create));
gem->size = size;
if (exynos_gem_create(fd, gem) < 0) {
fprintf(stderr, "failed to gem create: %d\n", errno);
return -1;
}
/* initialize structure for gem mmap */
memset(mmap, 0x00, sizeof(struct exynos_gem_mmap_data));
mmap->handle = gem->handle;
mmap->size = gem->size;
if (exynos_gem_mmap(fd, mmap) < 0) {
fprintf(stderr, "failed to gem mmap: %d\n", errno);
memset(&args, 0x00, sizeof(struct drm_gem_close));
args.handle = gem->handle;
exynos_gem_close(fd, &args);
return -2;
}
return 0;
}
void util_draw_buffer(void *addr, unsigned int stripe,
unsigned int width, unsigned int height,
unsigned int stride, unsigned int size)
{
if (stripe == 1) {
int i, j;
unsigned int *fb_ptr;
div_t d;
for (j = 0; j < height; j++) {
fb_ptr = (unsigned int *)((char *)addr + j * stride);
for (i = 0; i < width; i++) {
d = div(i, width);
fb_ptr[i] = 0x00130502 * (d.quot >> 6)
+ 0x000a1120 * (d.rem >> 6);
}
}
} else
memset(addr, 0x77, size);
}
int util_write_bmp(const char *file, const void *data, unsigned int width,
unsigned int height)
{
int i;
unsigned int * blocks;
FILE *fp;
struct {
unsigned char magic[2];
} bmpfile_magic = { {'B', 'M'} };
struct {
unsigned int filesz;
unsigned short creator1;
unsigned short creator2;
unsigned int bmp_offset;
} bmpfile_header = { 0, 0, 0, 0x36 };
struct {
unsigned int header_sz;
unsigned int width;
unsigned int height;
unsigned short nplanes;
unsigned short bitspp;
unsigned int compress_type;
unsigned int bmp_bytesz;
unsigned int hres;
unsigned int vres;
unsigned int ncolors;
unsigned int nimpcolors;
} bmp_dib_v3_header_t = { 0x28, 0, 0, 1, 32, 0, 0, 0, 0, 0, 0 };
fp = fopen(file, "wb");
if (fp == NULL) return -1;
bmpfile_header.filesz = sizeof(bmpfile_magic) + sizeof(bmpfile_header)
+ sizeof(bmp_dib_v3_header_t) + width * height * 4;
bmp_dib_v3_header_t.header_sz = sizeof(bmp_dib_v3_header_t);
bmp_dib_v3_header_t.width = width;
bmp_dib_v3_header_t.height = -height;
bmp_dib_v3_header_t.nplanes = 1;
bmp_dib_v3_header_t.bmp_bytesz = width * height * 4;
fwrite(&bmpfile_magic, sizeof(bmpfile_magic), 1, fp);
fwrite(&bmpfile_header, sizeof(bmpfile_header), 1, fp);
fwrite(&bmp_dib_v3_header_t, sizeof(bmp_dib_v3_header_t), 1, fp);
blocks = (unsigned int*)data;
for (i = 0; i < height * width; i++)
fwrite(&blocks[i], 4, 1, fp);
fclose(fp);
return 0;
}
|