2 Copyright 1995-2017, The AROS Development Team. All rights reserved.
5 Desc: Android bitmap class.
13 #include <sys/types.h>
14 #include <android/configuration.h>
16 #include <aros/debug.h>
19 #include <proto/hostlib.h>
20 #include <proto/oop.h>
21 #include <proto/utility.h>
23 #include "androidgfx_hidd.h"
24 #include "androidgfx_bitmap.h"
25 #include "android_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
);
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
;
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
;
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
));
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
);
88 if (IS_BM_ATTR(msg
->attrID
, idx
))
92 case aoHidd_BitMap_LeftEdge
:
93 *msg
->storage
= data
->bm_left
;
96 case aoHidd_BitMap_TopEdge
:
97 *msg
->storage
= data
->bm_top
;
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
;
112 BOOL change_position
= FALSE
;
116 tstate
= msg
->attrList
;
117 while((tag
= NextTagItem(&tstate
)))
119 if (IS_BM_ATTR(tag
->ti_Tag
, idx
))
124 case aoHidd_BitMap_LeftEdge
:
125 data
->bm_left
= tag
->ti_Data
;
126 change_position
= TRUE
;
129 case aoHidd_BitMap_TopEdge
:
130 data
->bm_top
= tag
->ti_Data
;
131 change_position
= TRUE
;
135 case aoHidd_BitMap_Visible
:
136 data
->visible
= tag
->ti_Data
;
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
;
163 struct ShowRequest show
;
165 show
.req
.cmd
= cmd_Show
;
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
);
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
;
197 update
.left
= msg
->x
;
199 update
.width
= msg
->width
;
200 update
.height
= msg
->height
;
202 SendRequest(&update
.req
, XSD(cl
));