2 * DRM based fimc test program
3 * Copyright 2012 Samsung Electronics
4 * Eunchul Kim <chulspro.kim@sasmsung.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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 THE
19 * 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 DEALINGS
32 #include "exynos_drm.h"
35 int util_gem_create_mmap(int fd, struct drm_exynos_gem_create *gem,
36 struct drm_exynos_gem_mmap *mmap,
39 /* initialize structure for gem create */
40 memset(gem, 0x00, sizeof(struct drm_exynos_gem_create));
43 if (exynos_gem_create(fd, gem) < 0) {
44 fprintf(stderr, "failed to gem create: %s\n", strerror(errno));
48 /* initialize structure for gem mmap */
49 memset(mmap, 0x00, sizeof(struct drm_exynos_gem_mmap));
50 mmap->handle = gem->handle;
51 mmap->size = gem->size;
53 if (exynos_gem_mmap(fd, mmap) < 0) {
54 fprintf(stderr, "failed to gem mmap: %s\n", strerror(errno));
61 void util_draw_buffer(void *addr, unsigned int stripe,
62 unsigned int width, unsigned int height,
63 unsigned int stride, unsigned int size)
70 for (j = 0; j < height; j++) {
71 fb_ptr = (unsigned int *)((char *)addr + j * stride);
72 for (i = 0; i < width; i++) {
74 fb_ptr[i] = 0x00130502 * (d.quot >> 6)
75 + 0x000a1120 * (d.rem >> 6);
79 memset(addr, 0x77, size);
82 int util_write_bmp(const char *file, const void *data, unsigned int width,
86 unsigned int * blocks;
89 unsigned char magic[2];
90 } bmpfile_magic = { {'B', 'M'} };
93 unsigned short creator1;
94 unsigned short creator2;
95 unsigned int bmp_offset;
96 } bmpfile_header = { 0, 0, 0, 0x36 };
98 unsigned int header_sz;
101 unsigned short nplanes;
102 unsigned short bitspp;
103 unsigned int compress_type;
104 unsigned int bmp_bytesz;
107 unsigned int ncolors;
108 unsigned int nimpcolors;
109 } bmp_dib_v3_header_t = { 0x28, 0, 0, 1, 32, 0, 0, 0, 0, 0, 0 };
111 fp = fopen(file, "wb");
112 if (fp == NULL) return -1;
114 bmpfile_header.filesz = sizeof(bmpfile_magic) + sizeof(bmpfile_header)
115 + sizeof(bmp_dib_v3_header_t) + width * height * 4;
116 bmp_dib_v3_header_t.header_sz = sizeof(bmp_dib_v3_header_t);
117 bmp_dib_v3_header_t.width = width;
118 bmp_dib_v3_header_t.height = -height;
119 bmp_dib_v3_header_t.nplanes = 1;
120 bmp_dib_v3_header_t.bmp_bytesz = width * height * 4;
122 fwrite(&bmpfile_magic, sizeof(bmpfile_magic), 1, fp);
123 fwrite(&bmpfile_header, sizeof(bmpfile_header), 1, fp);
124 fwrite(&bmp_dib_v3_header_t, sizeof(bmp_dib_v3_header_t), 1, fp);
126 blocks = (unsigned int*)data;
127 for (i = 0; i < height * width; i++)
128 fwrite(&blocks[i], 4, 1, fp);