PageRenderTime 871ms CodeModel.GetById 222ms app.highlight 308ms RepoModel.GetById 203ms app.codeStats 0ms

/src/backend/android/ftk_display_android_skia.c

http://ftk.googlecode.com/
C | 142 lines | 111 code | 29 blank | 2 comment | 11 complexity | 04d22abff2677075382da05274f3f6b9 MD5 | raw file
  1
  2#include "ftk_jni.h"
  3#include "ftk_event.h"
  4#include "ftk_globals.h"
  5#include "ftk_display_android.h"
  6
  7typedef struct _PrivInfo
  8{
  9	int unused;
 10}PrivInfo;
 11
 12static int screen_width = 320;
 13static int screen_height = 480;
 14
 15void Android_SetScreenResolution(int width, int height)
 16{
 17	screen_width = width;
 18	screen_height = height;
 19}
 20
 21static Ret  ftk_display_android_skia_handle_event(FtkDisplay* thiz, FtkEvent* event)
 22{
 23	Ret ret = RET_OK;
 24	DECL_PRIV(thiz, priv);
 25	return_val_if_fail(priv != NULL && event != NULL, RET_FAIL);
 26
 27	switch(event->type)
 28	{
 29		case FTK_EVT_OS_SCREEN_ROTATED:
 30		{
 31			ftk_wnd_manager_set_rotate(ftk_default_wnd_manager(), (FtkRotate)event->u.extra);
 32			ret = RET_REMOVE;
 33			break;
 34		}
 35		default:break;
 36	}
 37
 38	return ret;
 39}
 40
 41static Ret ftk_display_android_skia_update(FtkDisplay* thiz, FtkBitmap* bitmap, FtkRect* rect, int xoffset, int yoffset)
 42{
 43	int i = 0;
 44	Ret ret = RET_OK;
 45	DECL_PRIV(thiz, priv);
 46
 47	int width = rect->width;
 48	int height = rect->height;
 49	int src_width = ftk_bitmap_width(bitmap);
 50	int src_height = ftk_bitmap_height(bitmap);
 51	FtkColor* src = ftk_bitmap_lock(bitmap);
 52
 53	int dst_width = screen_width;
 54	int dst_height = screen_height;
 55	int* pixels = Android_GetBitmapPixels();
 56	FtkColor* dst = (FtkColor*)pixels;
 57
 58	return_val_if_fail(rect->x < src_width && rect->y < src_height
 59		&& xoffset < dst_width && yoffset < dst_height, RET_FAIL);
 60
 61	width = (xoffset + width) >= dst_width ? dst_width - xoffset : width;
 62	height = (yoffset + height) >= dst_height ? dst_height - yoffset : height;
 63
 64	src += rect->y * src_width + rect->x;
 65	dst += yoffset * dst_width + xoffset;
 66
 67	for(i = 0; i < height; i++)
 68	{
 69		memcpy(dst, src, sizeof(FtkColor) * width);
 70		dst += dst_width;
 71		src += src_width;
 72	}
 73
 74	Android_ReleaseBitmapPixels(pixels);
 75
 76#if 0
 77	Android_DrawBitmap(yoffset * screen_width + xoffset, screen_width, xoffset, yoffset, width, height);
 78#else
 79	Android_DrawBitmap(0, screen_width, 0, 0, screen_width, screen_height);
 80#endif
 81
 82	return ret;
 83}
 84
 85static Ret ftk_display_android_skia_snap(FtkDisplay* thiz, FtkRect* r, FtkBitmap* bitmap)
 86{
 87	int i = 0;
 88	int xoffset = r->x;
 89	int yoffset = r->y;
 90	int width = r->width;
 91	int height = r->height;
 92	DECL_PRIV(thiz, priv);
 93	FtkColor* dst = ftk_bitmap_lock(bitmap);
 94	//FtkColor* src = ftk_bitmap_lock(priv->bitmap);
 95
 96	/*TODO*/
 97
 98	return RET_OK;
 99}
100
101static int ftk_display_android_skia_width(FtkDisplay* thiz)
102{
103	return screen_width;
104}
105
106static int ftk_display_android_skia_height(FtkDisplay* thiz)
107{
108	return screen_height;
109}
110
111static void ftk_display_android_skia_destroy(FtkDisplay* thiz)
112{
113	if(thiz != NULL)
114	{
115		ftk_wnd_manager_remove_global_listener(ftk_default_wnd_manager(),
116			(FtkListener)ftk_display_android_skia_handle_event, thiz);
117
118		FTK_ZFREE(thiz, sizeof(FtkDisplay) + sizeof(PrivInfo));
119	}
120
121	return;
122}
123
124FtkDisplay* ftk_display_android_create(void)
125{
126	FtkDisplay* thiz = NULL;
127
128	thiz = (FtkDisplay*)FTK_ZALLOC(sizeof(FtkDisplay) + sizeof(PrivInfo));
129	if(thiz != NULL)
130	{
131		thiz->update   = ftk_display_android_skia_update;
132		thiz->width    = ftk_display_android_skia_width;
133		thiz->height   = ftk_display_android_skia_height;
134		thiz->snap     = ftk_display_android_skia_snap;
135		thiz->destroy  = ftk_display_android_skia_destroy;
136
137		ftk_wnd_manager_add_global_listener(ftk_default_wnd_manager(),
138			(FtkListener)ftk_display_android_skia_handle_event, thiz);
139	}
140
141	return thiz;
142}