summaryrefslogtreecommitdiffstats
path: root/exynos5/hal/libhdmi/SecHdmi/fimd_api.c
blob: 0f14f5dd56cd7834373a95bf18de906f087bec5b (plain)
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
* Copyright@ Samsung Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <linux/vt.h>
#include <fcntl.h>
#include <unistd.h>
#include <poll.h>
#include <signal.h>
#include <cutils/log.h>

#include "fimd_api.h"

int fb_open(int win)
{
    char node[20];
    int fp = -1;

    sprintf(node, "%s%d", PFX_NODE_FB, win);

    fp = open(node, O_RDWR);
    if (fp < 0)
        ALOGE("%s: fb[%d] open failed", __func__, win);

    return fp;
}

int fb_close(int fp)
{
    if (fp)
        close(fp);
    else
        ALOGE("%s: fb is not allocated %d", __func__, fp);

    return 0;
}

int get_fscreeninfo(int fp, struct fb_fix_screeninfo *fix)
{
    int ret = -1;

    ret = ioctl(fp, FBIOGET_FSCREENINFO, fix);
    if (ret)
        ALOGE("%s: FBIOGET_FSCREENINFO failed", __func__);

    return ret;
}

int get_vscreeninfo(int fp, struct fb_var_screeninfo *var)
{
    int ret = -1;

    ret = ioctl(fp, FBIOGET_VSCREENINFO, var);
    if (ret)
        ALOGE("%s:: FBIOGET_VSCREENINFO failed", __func__);

    return ret;
}

int put_vscreeninfo(int fp, struct fb_var_screeninfo *var)
{
    int ret = -1;

    ret = ioctl(fp, FBIOPUT_VSCREENINFO, var);
    if (ret)
        ALOGE("%s:: FBIOPUT_VSCREENINFO failed", __func__);

    return ret;
}

int get_bytes_per_pixel(int bits_per_pixel)
{
    return (bits_per_pixel == 24 || bits_per_pixel == 25 ||
        bits_per_pixel == 28) ? 4 : bits_per_pixel / 8;
}

char *fb_mmap(__u32 size, int fp)
{
    char *buffer;

    buffer = (char *)mmap(0, size, PROT_READ | PROT_WRITE,
                  MAP_SHARED, fp, 0);
    if (!buffer) {
        ALOGE("%s:: mmap failed", __func__);
        return NULL;
    }

    return buffer;
}

int fb_ioctl(int fp, __u32 cmd, void *arg)
{
    int ret = -1;

    ret = ioctl(fp, cmd, arg);
    if (ret < 0)
        ALOGE("%s:: ioctl (%d) failed", __func__, cmd);

    return ret;
}

int fb_on(int fp)
{
    int ret = -1;

    ret = ioctl(fp, FBIOBLANK, FB_BLANK_UNBLANK);
    if (ret)
        ALOGE("%s:: FBIOBLANK failed", __func__);

    return ret;
}

int fb_off(int fp)
{
    int ret = -1;

    ret = ioctl(fp, FBIOBLANK, FB_BLANK_POWERDOWN);
    if (ret)
        ALOGE("%s:: FBIOBLANK failed", __func__);

    return ret;
}

int fb_off_all()
{
    int fp, i;

    for (i = 0; i < TOTAL_FB_NUM; i++) {
        fp = fb_open(i);
        if (fp < 0)
            return -1;

        if (ioctl(fp, FBIOBLANK, FB_BLANK_POWERDOWN) < 0)
            ALOGE("%s:: FBIOBLANK failed", __func__);

        fb_off(fp);
        fb_close(fp);
    }

    return 0;
}

char *fb_init_display(int fp, int width, int height, int left_x, int top_y,
              int bpp)
{
    struct fb_var_screeninfo var;
    struct s5ptvfb_user_window window;
    int fb_size;
    char *fb = NULL;

    var.xres = width;
    var.yres = height;
    var.bits_per_pixel = bpp;
    window.x = left_x;
    window.y = top_y;

    var.xres_virtual = var.xres;
    var.yres_virtual = var.yres;
    var.xoffset = 0;
    var.yoffset = 0;
    var.width = 0;
    var.height = 0;
    var.transp.length = 0;
    var.activate = FB_ACTIVATE_FORCE;
    fb_size = var.xres_virtual * var.yres_virtual * bpp / 8;

    /* FBIOPUT_VSCREENINFO should be first */
    put_vscreeninfo(fp, &var);
    fb_ioctl(fp, S5PTVFB_WIN_POSITION, &window);

    /* draw image */
    fb = fb_mmap(fb_size, fp);
    memset(fb, 0x0, fb_size);

    return fb;
}

int simple_draw(char *dest, const char *src, int img_width,
        struct fb_var_screeninfo *var)
{
    int bytes_per_pixel = get_bytes_per_pixel(var->bits_per_pixel);
    unsigned int y;

    for (y = 0; y < var->yres; y++)
        memcpy(dest + y * var->xres * bytes_per_pixel,
               src + y * img_width * bytes_per_pixel,
               var->xres * bytes_per_pixel);

    return 0;
}

int draw(char *dest, const char *src, int img_width,
     struct fb_var_screeninfo *var)
{
    int bytes_per_pixel = get_bytes_per_pixel(var->bits_per_pixel);
    unsigned int y;

    if (var->bits_per_pixel == 16) {
        memcpy(dest, src, var->xres * var->yres * 2);
    } else {
        for (y = 0; y < var->yres; y++)
            memcpy(dest + y * var->xres * bytes_per_pixel,
                   src + y * img_width * bytes_per_pixel,
                   var->xres * bytes_per_pixel);
    }

    return 0;
}