rtgui_system.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /*
  2. * File : rtgui_system.c
  3. * This file is part of RTGUI in RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-10-04 Bernard first version
  13. */
  14. #include <rtgui/rtgui.h>
  15. #include <rtgui/driver.h>
  16. #include <rtgui/image.h>
  17. #include <rtgui/rtgui_theme.h>
  18. #include <rtgui/rtgui_system.h>
  19. #include <rtgui/rtgui_server.h>
  20. #include <rtgui/widgets/window.h>
  21. // #define RTGUI_EVENT_DEBUG
  22. #ifdef __WIN32__
  23. #define RTGUI_EVENT_DEBUG
  24. #define RTGUI_MEM_TRACE
  25. #endif
  26. void rtgui_system_server_init()
  27. {
  28. /* init image */
  29. rtgui_system_image_init();
  30. /* init font */
  31. rtgui_font_system_init();
  32. /* init rtgui server */
  33. rtgui_panel_init();
  34. rtgui_topwin_init();
  35. rtgui_server_init();
  36. /* init theme */
  37. rtgui_system_theme_init();
  38. }
  39. /************************************************************************/
  40. /* RTGUI Thread Wrapper */
  41. /************************************************************************/
  42. #ifdef RTGUI_EVENT_DEBUG
  43. const char *event_string[] =
  44. {
  45. /* panel event */
  46. "PANEL_ATTACH", /* attach to a panel */
  47. "PANEL_DETACH", /* detach from a panel */
  48. "PANEL_SHOW", /* show in a panel */
  49. "PANEL_HIDE", /* hide from a panel */
  50. "PANEL_INFO", /* panel information */
  51. "PANEL_RESIZE", /* resize panel */
  52. "PANEL_FULLSCREEN", /* to full screen */
  53. "PANEL_NORMAL", /* to normal screen */
  54. /* window event */
  55. "WIN_CREATE", /* create a window */
  56. "WIN_DESTROY", /* destroy a window */
  57. "WIN_SHOW", /* show a window */
  58. "WIN_HIDE", /* hide a window */
  59. "WIN_ACTIVATE", /* activate a window */
  60. "WIN_DEACTIVATE", /* deactivate a window */
  61. "WIN_CLOSE", /* close a window */
  62. "WIN_MOVE", /* move a window */
  63. "WIN_RESIZE", /* resize a window */
  64. "SET_WM", /* set window manager */
  65. "UPDATE_BEGIN", /* begin of update rect */
  66. "UPDATE_END", /* end of update rect */
  67. "MONITOR_ADD", /* add a monitor rect */
  68. "MONITOR_REMOVE", /* remove a monitor rect*/
  69. "PAINT", /* paint on screen */
  70. "TIMER", /* timer */
  71. /* clip rect information */
  72. "CLIP_INFO", /* clip rect info */
  73. /* mouse and keyboard event */
  74. "MOUSE_MOTION", /* mouse motion */
  75. "MOUSE_BUTTON", /* mouse button info */
  76. "KBD", /* keyboard info */
  77. /* user command event */
  78. "COMMAND", /* user command */
  79. /* request's status event */
  80. "STATUS", /* request result */
  81. "SCROLLED", /* scroll bar scrolled */
  82. "RESIZE", /* widget resize */
  83. };
  84. #define DBG_MSG(x) rt_kprintf x
  85. static void rtgui_event_dump(rt_thread_t tid, rtgui_event_t* event)
  86. {
  87. char* sender = "(unknown)";
  88. if (event->sender != RT_NULL) sender = event->sender->name;
  89. if (event->type == RTGUI_EVENT_TIMER)
  90. {
  91. /* don't dump timer event */
  92. return ;
  93. }
  94. rt_kprintf("%s -- %s --> %s ", sender, event_string[event->type], tid->name);
  95. switch (event->type)
  96. {
  97. case RTGUI_EVENT_PAINT:
  98. {
  99. struct rtgui_event_paint *paint = (struct rtgui_event_paint *)event;
  100. if(paint->wid != RT_NULL)
  101. rt_kprintf("win: %s", paint->wid->title);
  102. }
  103. break;
  104. case RTGUI_EVENT_KBD:
  105. {
  106. struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd*) event;
  107. if (ekbd->wid != RT_NULL)
  108. rt_kprintf("win: %s", ekbd->wid->title);
  109. }
  110. break;
  111. case RTGUI_EVENT_CLIP_INFO:
  112. {
  113. struct rtgui_event_clip_info *info = (struct rtgui_event_clip_info *)event;
  114. if(info->wid != RT_NULL)
  115. rt_kprintf("win: %s", info->wid->title);
  116. #ifdef RTGUI_USING_SMALL_SIZE
  117. rt_kprintf(" clip no. %d", info->num_rect);
  118. #else
  119. {
  120. rtgui_rect_t *rect;
  121. rt_uint32_t index;
  122. rect = (rtgui_rect_t*)(info + 1);
  123. for (index = 0; index < info->num_rect; index ++)
  124. {
  125. rt_kprintf(" (x1:%d, y1:%d, x2:%d, y2:%d)", rect->x1, rect->y1, rect->x2, rect->y2);
  126. rect ++;
  127. }
  128. }
  129. #endif
  130. }
  131. break;
  132. case RTGUI_EVENT_WIN_CREATE:
  133. {
  134. struct rtgui_event_win_create *create = (struct rtgui_event_win_create*)event;
  135. rt_kprintf(" win: %s at (x1:%d, y1:%d, x2:%d, y2:%d)",
  136. #ifdef RTGUI_USING_SMALL_SIZE
  137. create->wid->title,
  138. RTGUI_WIDGET(create->wid)->extent.x1,
  139. RTGUI_WIDGET(create->wid)->extent.y1,
  140. RTGUI_WIDGET(create->wid)->extent.x2,
  141. RTGUI_WIDGET(create->wid)->extent.y2);
  142. #else
  143. create->title,
  144. create->extent.x1,
  145. create->extent.y1,
  146. create->extent.x2,
  147. create->extent.y2);
  148. #endif
  149. }
  150. break;
  151. case RTGUI_EVENT_UPDATE_END:
  152. {
  153. struct rtgui_event_update_end* update_end = (struct rtgui_event_update_end*)event;
  154. rt_kprintf("(x:%d, y1:%d, x2:%d, y2:%d)", update_end->rect.x1,
  155. update_end->rect.y1,
  156. update_end->rect.x2,
  157. update_end->rect.y2);
  158. }
  159. break;
  160. case RTGUI_EVENT_WIN_ACTIVATE:
  161. case RTGUI_EVENT_WIN_DEACTIVATE:
  162. case RTGUI_EVENT_WIN_SHOW:
  163. {
  164. struct rtgui_event_win *win = (struct rtgui_event_win *)event;
  165. if(win->wid != RT_NULL)
  166. rt_kprintf("win: %s", win->wid->title);
  167. }
  168. break;
  169. case RTGUI_EVENT_WIN_MOVE:
  170. {
  171. struct rtgui_event_win_move *win = (struct rtgui_event_win_move *)event;
  172. if(win->wid != RT_NULL)
  173. {
  174. rt_kprintf("win: %s", win->wid->title);
  175. rt_kprintf(" to (x:%d, y:%d)", win->x, win->y);
  176. }
  177. }
  178. break;
  179. case RTGUI_EVENT_WIN_RESIZE:
  180. {
  181. struct rtgui_event_win_resize* win = (struct rtgui_event_win_resize *)event;
  182. if (win->wid != RT_NULL)
  183. {
  184. rt_kprintf("win: %s, rect(x1:%d, y1:%d, x2:%d, y2:%d)", win->wid->title,
  185. RTGUI_WIDGET(win->wid)->extent.x1,
  186. RTGUI_WIDGET(win->wid)->extent.y1,
  187. RTGUI_WIDGET(win->wid)->extent.x2,
  188. RTGUI_WIDGET(win->wid)->extent.y2);
  189. }
  190. }
  191. break;
  192. case RTGUI_EVENT_MOUSE_BUTTON:
  193. case RTGUI_EVENT_MOUSE_MOTION:
  194. {
  195. struct rtgui_event_mouse *mouse = (struct rtgui_event_mouse*)event;
  196. if (mouse->button & RTGUI_MOUSE_BUTTON_LEFT) rt_kprintf("left ");
  197. else rt_kprintf("right ");
  198. if (mouse->button & RTGUI_MOUSE_BUTTON_DOWN) rt_kprintf("down ");
  199. else rt_kprintf("up ");
  200. if (mouse->wid != RT_NULL)
  201. rt_kprintf("win: %s at (%d, %d)", mouse->wid->title,
  202. mouse->x, mouse->y);
  203. else
  204. rt_kprintf("(%d, %d)", mouse->x, mouse->y);
  205. }
  206. break;
  207. case RTGUI_EVENT_MONITOR_ADD:
  208. {
  209. struct rtgui_event_monitor *monitor = (struct rtgui_event_monitor*)event;
  210. if (monitor->panel != RT_NULL)
  211. {
  212. #if 0
  213. rt_kprintf("panel: %s, the rect is:(%d, %d) - (%d, %d)", monitor->panel->name,
  214. monitor->rect.x1, monitor->rect.y1,
  215. monitor->rect.x2, monitor->rect.y2);
  216. #endif
  217. rt_kprintf("the rect is:(%d, %d) - (%d, %d)",
  218. monitor->rect.x1, monitor->rect.y1,
  219. monitor->rect.x2, monitor->rect.y2);
  220. }
  221. else if (monitor->wid != RT_NULL)
  222. {
  223. rt_kprintf("win: %s, the rect is:(%d, %d) - (%d, %d)", monitor->wid->title,
  224. monitor->rect.x1, monitor->rect.y1,
  225. monitor->rect.x2, monitor->rect.y2);
  226. }
  227. }
  228. break;
  229. }
  230. rt_kprintf("\n");
  231. }
  232. #else
  233. #define DBG_MSG(x)
  234. #define rtgui_event_dump(tid, event)
  235. #endif
  236. rtgui_thread_t* rtgui_thread_register(rt_thread_t tid, rt_mq_t mq)
  237. {
  238. rtgui_thread_t* thread = rtgui_malloc(sizeof(struct rtgui_thread));
  239. if (thread != RT_NULL)
  240. {
  241. DBG_MSG(("register a rtgui thread: %s, tid: 0x%p\n", tid->name, tid));
  242. /* set tid and mq */
  243. thread->tid = tid;
  244. thread->mq = mq;
  245. thread->widget = RT_NULL;
  246. /* set user thread */
  247. tid->user_data = (rt_uint32_t)thread;
  248. }
  249. return thread;
  250. }
  251. void rtgui_thread_deregister(rt_thread_t tid)
  252. {
  253. struct rtgui_thread* thread;
  254. /* find rtgui_thread */
  255. thread = (struct rtgui_thread*) (tid->user_data);
  256. if (thread != RT_NULL)
  257. {
  258. /* remove rtgui_thread */
  259. tid->user_data = 0;
  260. /* free rtgui_thread */
  261. rtgui_free(thread);
  262. }
  263. }
  264. /* get current gui thread */
  265. rtgui_thread_t* rtgui_thread_self()
  266. {
  267. struct rtgui_thread* thread;
  268. rt_thread_t self;
  269. /* get current thread */
  270. self = rt_thread_self();
  271. thread = (struct rtgui_thread*)(self->user_data);
  272. return thread;
  273. }
  274. extern rt_thread_t rt_thread_find(char* name);
  275. rt_thread_t rtgui_thread_get_server()
  276. {
  277. return rt_thread_find("rtgui");
  278. }
  279. void rtgui_thread_set_widget(struct rtgui_widget* widget)
  280. {
  281. struct rtgui_thread* thread;
  282. /* get rtgui_thread */
  283. thread = (struct rtgui_thread*) (rt_thread_self()->user_data);
  284. if (thread != RT_NULL) thread->widget = widget;
  285. }
  286. struct rtgui_widget* rtgui_thread_get_widget()
  287. {
  288. struct rtgui_thread* thread;
  289. /* get rtgui_thread */
  290. thread = (struct rtgui_thread*) (rt_thread_self()->user_data);
  291. return thread == RT_NULL? RT_NULL : thread->widget;
  292. }
  293. rt_err_t rtgui_thread_send(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
  294. {
  295. rt_err_t result;
  296. struct rtgui_thread* thread;
  297. rtgui_event_dump(tid, event);
  298. /* if (event->type != RTGUI_EVENT_TIMER)
  299. rt_kprintf("event size: %d\n", event_size); */
  300. /* find rtgui_thread */
  301. thread = (struct rtgui_thread*) (tid->user_data);
  302. if (thread == RT_NULL) return -RT_ERROR;
  303. result = rt_mq_send(thread->mq, event, event_size);
  304. if (result != RT_EOK)
  305. {
  306. if (event->type != RTGUI_EVENT_TIMER)
  307. rt_kprintf("send event to %s failed\n", thread->tid->name);
  308. }
  309. return result;
  310. }
  311. rt_err_t rtgui_thread_send_urgent(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
  312. {
  313. rt_err_t result;
  314. struct rtgui_thread* thread;
  315. rtgui_event_dump(tid, event);
  316. rt_kprintf("event size: %d\n", event_size);
  317. /* find rtgui_thread */
  318. thread = (struct rtgui_thread*) (tid->user_data);
  319. if (thread == RT_NULL) return -RT_ERROR;
  320. result = rt_mq_urgent(thread->mq, event, event_size);
  321. if (result != RT_EOK)
  322. rt_kprintf("send ergent event failed\n");
  323. return result;
  324. }
  325. rt_err_t rtgui_thread_send_sync(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
  326. {
  327. rt_err_t r;
  328. struct rtgui_thread* thread;
  329. rt_int32_t ack_buffer, ack_status;
  330. struct rt_mailbox ack_mb;
  331. rtgui_event_dump(tid, event);
  332. rt_kprintf("event size: %d\n", event_size);
  333. /* init ack mailbox */
  334. r = rt_mb_init(&ack_mb, "ack", &ack_buffer, 1, 0);
  335. if ( r!= RT_EOK) goto __return;
  336. /* find rtgui_thread */
  337. thread = (struct rtgui_thread*) (tid->user_data);
  338. if (thread == RT_NULL){ r = RT_ERROR; goto __return; }
  339. event->ack = &ack_mb;
  340. r = rt_mq_send(thread->mq, event, event_size);
  341. if (r != RT_EOK)
  342. {
  343. rt_kprintf("send sync event failed\n");
  344. goto __return;
  345. }
  346. r = rt_mb_recv(&ack_mb, (rt_uint32_t*)&ack_status, RT_WAITING_FOREVER);
  347. if ( r!= RT_EOK) goto __return;
  348. if (ack_status != RTGUI_STATUS_OK) r = -RT_ERROR;
  349. else r = RT_EOK;
  350. /* fini ack mailbox */
  351. rt_mb_detach(&ack_mb);
  352. __return:
  353. return r;
  354. }
  355. rt_err_t rtgui_thread_ack(rtgui_event_t* event, rt_int32_t status)
  356. {
  357. if (event != RT_NULL &&
  358. event->ack != RT_NULL)
  359. {
  360. rt_mb_send(event->ack, status);
  361. }
  362. return RT_EOK;
  363. }
  364. rt_err_t rtgui_thread_recv(rtgui_event_t* event, rt_size_t event_size)
  365. {
  366. struct rtgui_thread* thread;
  367. rt_err_t r;
  368. /* find rtgui_thread */
  369. thread = (struct rtgui_thread*) (rt_thread_self()->user_data);
  370. if (thread == RT_NULL) return -RT_ERROR;
  371. r = rt_mq_recv(thread->mq, event, event_size, RT_WAITING_FOREVER);
  372. return r;
  373. }
  374. rt_err_t rtgui_thread_recv_filter(rt_uint32_t type, rtgui_event_t* event, rt_size_t event_size)
  375. {
  376. struct rtgui_thread* thread;
  377. /* find rtgui_thread */
  378. thread = (struct rtgui_thread*) (rt_thread_self()->user_data);
  379. if (thread == RT_NULL) return -RT_ERROR;
  380. while (rt_mq_recv(thread->mq, event, event_size, RT_WAITING_FOREVER) == RT_EOK)
  381. {
  382. if (event->type == type)
  383. {
  384. return RT_EOK;
  385. }
  386. else
  387. {
  388. /* let widget to handle event */
  389. if (thread->widget != RT_NULL &&
  390. thread->widget->event_handler != RT_NULL)
  391. {
  392. thread->widget->event_handler(thread->widget, event);
  393. }
  394. }
  395. }
  396. return -RT_ERROR;
  397. }
  398. /************************************************************************/
  399. /* RTGUI Timer */
  400. /************************************************************************/
  401. static void rtgui_time_out(void* parameter)
  402. {
  403. rtgui_timer_t* timer;
  404. struct rtgui_event_timer event;
  405. timer = (rtgui_timer_t*)parameter;
  406. /*
  407. * Note: event_timer can not use RTGUI_EVENT_TIMER_INIT to init, for there is no
  408. * thread context
  409. */
  410. event.parent.type = RTGUI_EVENT_TIMER;
  411. event.parent.sender = RT_NULL;
  412. event.timer = timer;
  413. rtgui_thread_send(timer->tid, &(event.parent), sizeof(struct rtgui_event_timer));
  414. }
  415. rtgui_timer_t* rtgui_timer_create(rt_int32_t time, rt_base_t flag, rtgui_timeout_func timeout, void* parameter)
  416. {
  417. rtgui_timer_t* timer;
  418. timer = (rtgui_timer_t*) rtgui_malloc(sizeof(struct rtgui_timer));
  419. timer->tid = rt_thread_self();
  420. timer->timeout = timeout;
  421. timer->user_data = parameter;
  422. /* init rt-thread timer */
  423. rt_timer_init(&(timer->timer), "rtgui", rtgui_time_out, timer, time, (rt_uint8_t)flag);
  424. return timer;
  425. }
  426. void rtgui_timer_destory(rtgui_timer_t* timer)
  427. {
  428. RT_ASSERT(timer != RT_NULL);
  429. /* stop timer firstly */
  430. rtgui_timer_stop(timer);
  431. /* detach rt-thread timer */
  432. rt_timer_detach(&(timer->timer));
  433. rtgui_free(timer);
  434. }
  435. void rtgui_timer_start(rtgui_timer_t* timer)
  436. {
  437. RT_ASSERT(timer != RT_NULL);
  438. /* start rt-thread timer */
  439. rt_timer_start(&(timer->timer));
  440. }
  441. void rtgui_timer_stop (rtgui_timer_t* timer)
  442. {
  443. RT_ASSERT(timer != RT_NULL);
  444. /* stop rt-thread timer */
  445. rt_timer_stop(&(timer->timer));
  446. }
  447. /************************************************************************/
  448. /* RTGUI Memory Management */
  449. /************************************************************************/
  450. #ifdef RTGUI_MEM_TRACE
  451. struct rtgui_mem_info
  452. {
  453. rt_uint32_t allocated_size;
  454. rt_uint32_t max_allocated;
  455. };
  456. struct rtgui_mem_info mem_info;
  457. #define MEMTRACE_MAX 4096
  458. #define MEMTRACE_HASH_SIZE 256
  459. struct rti_memtrace_item
  460. {
  461. void* mb_ptr; /* memory block pointer */
  462. rt_uint32_t mb_len; /* memory block length */
  463. struct rti_memtrace_item* next;
  464. };
  465. struct rti_memtrace_item trace_list[MEMTRACE_MAX];
  466. struct rti_memtrace_item *item_hash[MEMTRACE_HASH_SIZE];
  467. struct rti_memtrace_item *item_free;
  468. rt_bool_t rti_memtrace_inited = 0;
  469. void rti_memtrace_init()
  470. {
  471. struct rti_memtrace_item *item;
  472. rt_uint32_t index;
  473. rt_memset(trace_list, 0, sizeof(trace_list));
  474. rt_memset(item_hash, 0, sizeof(item_hash));
  475. item_free = &trace_list[0];
  476. item = &trace_list[0];
  477. for (index = 1; index < MEMTRACE_HASH_SIZE; index ++)
  478. {
  479. item->next = &trace_list[index];
  480. item = item->next;
  481. }
  482. item->next = RT_NULL;
  483. }
  484. void rti_malloc_hook(void* ptr, rt_uint32_t len)
  485. {
  486. rt_uint32_t index;
  487. struct rti_memtrace_item* item;
  488. if (item_free == RT_NULL) return;
  489. mem_info.allocated_size += len;
  490. if (mem_info.max_allocated < mem_info.allocated_size)
  491. mem_info.max_allocated = mem_info.allocated_size;
  492. /* lock context */
  493. item = item_free;
  494. item_free = item->next;
  495. item->mb_ptr = ptr;
  496. item->mb_len = len;
  497. item->next = RT_NULL;
  498. /* get hash item index */
  499. index = ((rt_uint32_t)ptr) % MEMTRACE_HASH_SIZE;
  500. if (item_hash[index] != RT_NULL)
  501. {
  502. /* add to list */
  503. item->next = item_hash[index];
  504. item_hash[index] = item;
  505. }
  506. else
  507. {
  508. /* set list header */
  509. item_hash[index] = item;
  510. }
  511. /* unlock context */
  512. }
  513. void rti_free_hook(void* ptr)
  514. {
  515. rt_uint32_t index;
  516. struct rti_memtrace_item *item;
  517. /* get hash item index */
  518. index = ((rt_uint32_t)ptr) % MEMTRACE_HASH_SIZE;
  519. if (item_hash[index] != RT_NULL)
  520. {
  521. item = item_hash[index];
  522. if (item->mb_ptr == ptr)
  523. {
  524. /* delete item from list */
  525. item_hash[index] = item->next;
  526. }
  527. else
  528. {
  529. /* find ptr in list */
  530. while (item->next != RT_NULL && item->next->mb_ptr != ptr)
  531. item = item->next;
  532. /* delete item from list */
  533. if (item->next != RT_NULL)
  534. {
  535. struct rti_memtrace_item* i;
  536. i = item->next;
  537. item->next = item->next->next;
  538. item = i;
  539. }
  540. else
  541. {
  542. /* not found */
  543. return;
  544. }
  545. }
  546. /* reduce allocated size */
  547. mem_info.allocated_size -= item->mb_len;
  548. /* clear item */
  549. rt_memset(item, 0, sizeof(struct rti_memtrace_item));
  550. /* add item to the free list */
  551. item->next = item_free;
  552. item_free = item;
  553. }
  554. }
  555. #endif
  556. void* rtgui_malloc(rt_size_t size)
  557. {
  558. void* ptr;
  559. ptr = rt_malloc(size);
  560. #ifdef RTGUI_MEM_TRACE
  561. if (rti_memtrace_inited == 0)
  562. {
  563. rti_memtrace_init();
  564. rti_memtrace_inited = 1;
  565. }
  566. if (ptr != RT_NULL)
  567. rti_malloc_hook(ptr, size);
  568. #endif
  569. return ptr;
  570. }
  571. void rtgui_free(void* ptr)
  572. {
  573. #ifdef RTGUI_MEM_TRACE
  574. if (ptr != RT_NULL)
  575. rti_free_hook(ptr);
  576. #endif
  577. rt_free(ptr);
  578. }