1 /**************************************************************************
3 xserver-xorg-video-emulfb
5 Copyright 2010 - 2011 Samsung Electronics co., Ltd. All Rights Reserved.
7 Contact: YoungHoon Jung <yhoon.jung@samsung.com>
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sub license, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial portions
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
33 #include <sys/types.h>
37 #include "X11/XWDFile.h"
39 #include "fbdev_util.h"
41 int fbdev_util_dump_raw(const char * file, const void * data, int width, int height)
43 unsigned int * blocks;
45 FILE * fp = fopen(file, "w+");
49 blocks = (unsigned int *) data;
50 fwrite(blocks, 4, width*height, fp);
58 #define RR_Rotate_All (RR_Rotate_0|RR_Rotate_90|RR_Rotate_180|RR_Rotate_270)
61 int fbdev_util_degree_to_rotate(int degree)
71 rotate = RR_Rotate_90;
74 rotate = RR_Rotate_180;
77 rotate = RR_Rotate_270;
80 rotate = 0; /* ERROR */
87 int fbdev_util_rotate_to_degree(int rotate)
91 switch(rotate & RR_Rotate_All)
106 degree = -1; /* ERROR */
114 _fbdev_util_rotate_to_int(int rot)
116 switch(rot & RR_Rotate_All)
131 int fbdev_util_rotate_add(int rot_a, int rot_b)
133 int a = _fbdev_util_rotate_to_int(rot_a);
134 int b = _fbdev_util_rotate_to_int(rot_b);
136 return (int)((1 << ((a+b)%4))&RR_Rotate_All);
140 fbdev_util_get_window_property(WindowPtr pWin, const char* prop_name)
143 Mask prop_mode = DixReadAccess;
147 property = MakeAtom(prop_name, strlen(prop_name), FALSE);
151 rc = dixLookupProperty(&pProp, pWin, property, serverClient, prop_mode);
152 if (rc == Success && pProp->data)
162 fbdev_util_rotate_rect (int xres,
171 return_if_fail (src != NULL);
173 if (src_rot == dst_rot)
176 diff = (dst_rot - src_rot);
180 if (src_rot % 180 && diff % 180)
186 temp.x = yres - (src->y + src->height);
188 temp.width = src->height;
189 temp.height = src->width;
192 temp.x = xres - (src->x + src->width);
193 temp.y = yres - (src->y + src->height);
194 temp.width = src->width;
195 temp.height = src->height;
199 temp.y = xres - (src->x + src->width);
200 temp.width = src->height;
201 temp.height = src->width;
206 temp.width = src->width;
207 temp.height = src->height;
215 fbdev_util_align_rect (int src_w, int src_h, int dst_w, int dst_h, xRectangle *fit, Bool hw)
224 return_if_fail (src_w > 0 && src_h > 0);
225 return_if_fail (dst_w > 0 && dst_h > 0);
227 rw = (float)src_w / dst_w;
228 rh = (float)src_h / dst_h;
231 fit_width = src_w / max;
232 fit_height = src_h / max;
237 fit->x = (dst_w - fit_width) / 2;
238 fit->y = (dst_h - fit_height) / 2;
239 fit->width = fit_width;
240 fit->height = fit_height;
245 drvlog (const char * f, ...)
251 vsnprintf (temp, sizeof (temp), f, args);
254 fwrite (temp, strlen (temp), 1, stderr);