rename the directory
[AROS.git] / arch / all-android / hidd / androidgfx / abitmap.c
blobdda2f7c2a2b607dc0c2dd7184c2812fe43f6be5c
1 /*
2 Copyright 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Android bitmap class.
6 Lang: English.
7 */
9 #define DEBUG 0
10 #define DNEW(x)
11 #define DUPD(x)
13 #include <sys/types.h>
14 #include <android/configuration.h>
16 #include <aros/debug.h>
17 #include <hidd/graphics.h>
18 #include <oop/oop.h>
19 #include <proto/hostlib.h>
20 #include <proto/oop.h>
21 #include <proto/utility.h>
23 #include "agfx.h"
24 #include "agfx_bitmap.h"
25 #include "server.h"
27 /****************************************************************************************/
29 OOP_Object *ABitmap__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
31 DNEW(bug("ABitmap::New()\n"));
33 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
34 if (o)
36 struct bitmap_data *data = OOP_INST_DATA(cl, o);
38 OOP_Object *gfx = NULL;
39 OOP_Object *sync = NULL;
40 OOP_Object *pixfmt = NULL;
41 HIDDT_ModeID modeid = vHidd_ModeID_Invalid;
42 IPTR width = 0;
43 IPTR height = 0;
44 IPTR mod = 0;
46 /* For faster operation we cache some data about ourselves */
47 OOP_GetAttr(o, aHidd_BitMap_Width , &width);
48 OOP_GetAttr(o, aHidd_BitMap_Height, &height);
49 OOP_GetAttr(o, aHidd_BitMap_BytesPerRow, &mod);
50 OOP_GetAttr(o, aHidd_BitMap_ModeID, &modeid);
51 OOP_GetAttr(o, aHidd_BitMap_GfxHidd, (IPTR *)&gfx);
52 OOP_GetAttr(o, aHidd_ChunkyBM_Buffer, &data->pixels);
54 data->bm_width = width;
55 data->bm_height = height;
56 data->mod = mod;
58 * Orientation currently depend on width:height ratio.
59 * For all existing devices this seems to be true. However it's not perfect. Perhaps we need to
60 * add Orientation attribute to sync class. Or introduce ability to subclass syncs.
61 * In fact would be good to have own support for screen rotation in AROS. This is not designed yet.
63 data->orientation = (width > height) ? ACONFIGURATION_ORIENTATION_LAND : ACONFIGURATION_ORIENTATION_PORT;
65 DNEW(bug("[ABitmap] Created bitmap %ldx%ld\n", width, height));
66 DNEW(bug("[ABitmap] Buffer at 0x%p, %ld bytes per row\n", data->pixels, mod));
67 DNEW(bug("[ABitmap] Display driver object: 0x%p\n", gfx));
69 HIDD_Gfx_GetMode(gfx, modeid, &sync, &pixfmt);
70 OOP_GetAttr(sync, aHidd_Sync_HDisp, &width);
71 OOP_GetAttr(sync, aHidd_Sync_VDisp, &height);
73 data->win_width = width;
74 data->win_height = height;
75 DNEW(bug("[ABitmap] Display window size: %dx%d\n", win_width, win_height));
78 return o;
81 /****************************************************************************************/
83 VOID ABitmap__Root__Get(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
85 struct bitmap_data *data = OOP_INST_DATA(cl, o);
86 ULONG idx;
88 if (IS_BM_ATTR(msg->attrID, idx))
90 switch (idx)
92 case aoHidd_BitMap_LeftEdge:
93 *msg->storage = data->bm_left;
94 return;
96 case aoHidd_BitMap_TopEdge:
97 *msg->storage = data->bm_top;
98 return;
101 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
104 /****************************************************************************************/
106 VOID ABitmap__Root__Set(OOP_Class *cl, OOP_Object *obj, struct pRoot_Set *msg)
108 struct bitmap_data *data = OOP_INST_DATA(cl, obj);
109 struct TagItem *tag, *tstate;
110 ULONG idx;
111 #ifdef ENABLE_SCROLL
112 BOOL change_position = FALSE;
113 #endif
114 BOOL show = FALSE;
116 tstate = msg->attrList;
117 while((tag = NextTagItem(&tstate)))
119 if (IS_BM_ATTR(tag->ti_Tag, idx))
121 switch(idx)
123 #ifdef ENABLE_SCROLL
124 case aoHidd_BitMap_LeftEdge:
125 data->bm_left = tag->ti_Data;
126 change_position = TRUE;
127 break;
129 case aoHidd_BitMap_TopEdge:
130 data->bm_top = tag->ti_Data;
131 change_position = TRUE;
132 break;
133 #endif
135 case aoHidd_BitMap_Visible:
136 data->visible = tag->ti_Data;
137 show = tag->ti_Data;
138 break;
143 #ifdef ENABLE_SCROLL
144 if (change_position)
146 /* Fix up position. We can completely scroll out
147 of our window into all 4 sides, but not more */
148 if (data->bm_left > data->win_width)
149 data->bm_left = data->win_width;
150 else if (data->bm_left < -data->bm_width)
151 data->bm_left = -data->bm_width;
152 if (data->bm_top > data->win_height)
153 data->bm_top = data->win_height;
154 else if (data->bm_top < -data->bm_height)
155 data->bm_top = -data->bm_height;
157 /* TODO */
159 #endif
161 if (show)
163 struct ShowRequest show;
165 show.req.cmd = cmd_Show;
166 show.req.len = 8;
167 show.displayid = 0;
168 show.left = data->bm_left;
169 show.top = data->bm_top;
170 show.width = data->bm_width;
171 show.height = data->bm_height;
172 show.mod = data->mod;
173 show.orientation = data->orientation;
174 show.addr = data->pixels;
176 DoRequest(&show.req, XSD(cl));
179 OOP_DoSuperMethod(cl, obj, (OOP_Msg)msg);
182 /****************************************************************************************/
184 VOID ABitmap__Hidd_BitMap__UpdateRect(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_UpdateRect *msg)
186 struct bitmap_data *data = OOP_INST_DATA(cl, o);
188 if (data->visible)
190 struct UpdateRequest update;
192 DUPD(bug("[ABitmap 0x%p] UpdateRect(%d, %d, %d, %d)\n", o, msg->x, msg->y, msg->width, msg->height));
194 update.req.cmd = cmd_Update;
195 update.req.len = 5;
196 update.id = 0;
197 update.left = msg->x;
198 update.top = msg->y;
199 update.width = msg->width;
200 update.height = msg->height;
202 SendRequest(&update.req, XSD(cl));