main.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. /* SCE CONFIDENTIAL
  2. $PSLibId$
  3. * Copyright (C) 2011 Sony Computer Entertainment Inc.
  4. * All Rights Reserved.
  5. */
  6. #define USE_PSP2_DUMP_RENDER 0
  7. #if USE_PSP2_DUMP_RENDER
  8. #include "config.h"
  9. #include "psp2-test.h"
  10. #include "AccessibilityController.h"
  11. #include "EditingCallbacks.h"
  12. #include "EventSender.h"
  13. #include "GCController.h"
  14. #include "LayoutTestController.h"
  15. #include "PixelDumpSupport.h"
  16. #include "SelfScrollingWebKitWebView.h"
  17. #include "TextInputController.h"
  18. #include "WebCoreSupport/DumpRenderTreeSupportManx.h"
  19. #include "WebCoreTestSupport.h"
  20. #include "WorkQueue.h"
  21. #include "WorkQueueItem.h"
  22. #endif
  23. #include <time.h>
  24. #include "common.h" //current
  25. #include "event.h" //current
  26. #include "render.h" //current
  27. #include <string.h> //sys/sdk/target/include/string.h
  28. #include <libdbg.h> //sys/sdk/target/include_common/libdbg.h
  29. #include <ctrl.h> //sys/sdk/target/include/ctrl.h
  30. #include <libdbgfont.h> //sys/sdk/target/include/libdbgfont.h
  31. #include <stdio.h> //psp2/dist/include/psp2-compat/stdio.h →/sys/sdk/target/include/stdio.h
  32. #include <net.h> //sys/sdk/target/include/net.h
  33. #include <libsysmodule.h>//sys/sdk/target/include/libsysmodule.h
  34. //#include <touch.h> //this file included in the event.h
  35. #include <libperf.h> //sys/sdk/target/include/libperf.h
  36. #include <stdlib.h> //sys/sdk/target/include/stdlib.h
  37. //#include <stdio.h> //double include?
  38. #if defined(USE_WEBKIT)
  39. // WebView interface
  40. #if defined(__SNC__)
  41. #include <webkit/WebView.h>
  42. #else
  43. #include "../builder/psp2-release/include/webkit-1.0/webkit/WebView.h"
  44. #endif
  45. #else
  46. // Dummy interface
  47. #include "WebViewDummy.h"
  48. #endif
  49. extern "C" int setenv(const char *name, const char *value, int overwrite);
  50. // Enable the following define to allow Razor HUD.
  51. //#define ENABLE_RAZOR_HUD
  52. // Enable the following define to create a Razor capture file.
  53. //#define ENABLE_RAZOR_GPU_CAPTURE
  54. #define ENABLE_RAZOE_CPU_CAPTURE
  55. #ifdef ENABLE_RAZOR_GPU_CAPTURE
  56. #include <razor_capture.h>
  57. #endif
  58. // Resource path
  59. #define WEBKIT_FONT_FILE "sa0:/data/font/pvf/jpn0.pvf"
  60. #define WEBKIT_THEME_PATH "host0:/resource/theme"
  61. #define URL_LIST_PATH "app0:/Webkit_RegressionTest_UrlList.txt"
  62. // Device parameters
  63. #define ANALOGSTICK_DEADZONE_LOW (0x60)
  64. #define ANALOGSTICK_DEADZONE_HIGH (0xa0)
  65. // control data
  66. bool g_quit = false;
  67. enum {
  68. DESTROYED,
  69. RUNNING,
  70. FINISHED,
  71. DESTROYING,
  72. } g_test_status;
  73. SceCtrlData g_ctrlData;
  74. TouchEventInfo g_touchEventInfo;
  75. TouchEventInfo g_backtouchEventInfo;
  76. // webview
  77. WebView *g_webView;
  78. // FILE
  79. FILE* fp;
  80. unsigned long g_filesize = 0;
  81. int g_viewcount =0;
  82. // TIME
  83. time_t g_start,g_end;
  84. // Provided for common
  85. int renderDbgFont(void);
  86. // User main thread parameters
  87. extern const char sceUserMainThreadName[] = "libgxm_render_main_thr";
  88. extern const int sceUserMainThreadPriority = SCE_KERNEL_DEFAULT_PRIORITY_USER;
  89. extern const unsigned int sceUserMainThreadStackSize = SCE_KERNEL_STACK_SIZE_DEFAULT_USER_MAIN;
  90. // Libc parameters
  91. unsigned int sceLibcHeapExtendedAlloc = 1;
  92. unsigned int sceLibcHeapSize = SCE_LIBC_HEAP_SIZE_EXTENDED_ALLOC_NO_LIMIT;
  93. // Net
  94. static char s_net_memory[16 * 1024];
  95. // performance analizer
  96. static void init_perf()
  97. {
  98. // Razorの初期化
  99. int ret = sceSysmoduleLoadModule( SCE_SYSMODULE_PERF );
  100. if( ret < 0 )
  101. {
  102. printf( "sceSysmoduleLoadModule failed (0x%08x)\n", ret );
  103. }
  104. ret = scePerfArmPmonReset( SCE_PERF_ARM_PMON_THREAD_ID_ALL );
  105. if( ret < 0 )
  106. {
  107. printf( "scePerfArmPmonReset() failed (0x%08x)\n", ret );
  108. }
  109. char event_code[ SCE_PERF_ARM_PMON_PMCNT_NUM ] =
  110. {
  111. SCE_PERF_ARM_PMON_ICACHE_STALL,
  112. SCE_PERF_ARM_PMON_DCACHE_STALL,
  113. SCE_PERF_ARM_PMON_BRANCH_MISPREDICT,
  114. SCE_PERF_ARM_PMON_PREDICT_BRANCH,
  115. SCE_PERF_ARM_PMON_DATA_READ,
  116. SCE_PERF_ARM_PMON_DATA_WRITE
  117. };
  118. for ( unsigned int i = 0; i < SCE_PERF_ARM_PMON_PMCNT_NUM; ++i)
  119. {
  120. ret = scePerfArmPmonSelectEvent( SCE_PERF_ARM_PMON_THREAD_ID_ALL, i, event_code[i] );
  121. if( ret < 0 )
  122. {
  123. printf( "scePerfArmPmonSelectEvent() failed (0x%08x)\n", ret );
  124. }
  125. }
  126. ret = scePerfArmPmonStart( SCE_PERF_ARM_PMON_THREAD_ID_ALL );
  127. if( ret < 0 )
  128. {
  129. printf( "scePerfArmPmonStart() failed (0x%08x)\n", ret );
  130. }
  131. }
  132. bool fileOpen()
  133. {
  134. if((fp = fopen(URL_LIST_PATH,"r")) == NULL)
  135. {
  136. printf("UrlListFile Open Failed\n");
  137. return false;
  138. }else{
  139. printf("UrllistFile Open Success\n");
  140. fseek(fp, 0L, SEEK_END);
  141. g_filesize = ftell(fp);
  142. fseek(fp, 0L, SEEK_SET);
  143. }
  144. return true;
  145. }
  146. char* fileRead()
  147. {
  148. g_viewcount++;
  149. static char url_buf[2048];
  150. memset(url_buf,0x00,sizeof(url_buf));
  151. if (fgets(url_buf,g_filesize,fp) != NULL){
  152. printf("\n#%06d url:%s",g_viewcount,url_buf);
  153. while((strncmp(url_buf,"//",2)==0)){
  154. memset(url_buf,0x00,sizeof(url_buf));
  155. if (fgets(url_buf,g_filesize,fp) != NULL){
  156. g_viewcount++;
  157. printf("#%06d url:%s",g_viewcount,url_buf);
  158. }
  159. }
  160. }
  161. return url_buf;
  162. }
  163. void memoryCheck(const char *argv) {
  164. struct std::malloc_managed_size mmsize;
  165. malloc_stats(&mmsize);
  166. printf("#%s#current_system_size \/ max_system_size: %09d \/ %09d\n", argv,mmsize.current_system_size,mmsize.max_system_size);
  167. printf("# current_inuse_size \/ max_inuse_size : %09d \/ %09d\n", mmsize.current_inuse_size,mmsize.max_inuse_size);
  168. }
  169. class WebViewStatus {
  170. char *_title;
  171. char *_url;
  172. uint8_t _progress;
  173. public:
  174. WebViewStatus() :
  175. _title(new char[1024]),
  176. _url(new char[1024]),
  177. _progress(0)
  178. {}
  179. ~WebViewStatus() {
  180. delete [] _title;
  181. delete [] _url;
  182. }
  183. float fps() { return 0.f; }
  184. float updateTime() { return 0.f; }
  185. float renderTime() { return 0.f; }
  186. const char * title() { return _title; }
  187. void setTitle(const char *title) {
  188. if (!title) title = "about:blank";
  189. strncpy(_title, title, 1024);
  190. }
  191. const char * url() { return _url; }
  192. void setUrl(const char *url) {
  193. if (!url) url = "about:blank";
  194. strncpy(_url, url, 1024);
  195. }
  196. uint8_t progress() { return _progress; }
  197. void setProgress(uint8_t progress) { _progress = progress; }
  198. };
  199. static WebViewStatus g_webViewStatus;
  200. static bool g_backingStoreUpdated;
  201. static float g_location_x = 0;
  202. static float g_location_y = 0;
  203. static float g_scale = 1.0f;
  204. static bool webViewCallback(WebView *webView, void *userData, CallbackType type, const CallbackData *in, CallbackData *out)
  205. {
  206. switch (type) {
  207. case CALLBACK_SET_TEXTURE:
  208. memcpy(g_testTextureData, in[0].type_uchar_ptr, in[1].type_int);
  209. return true;
  210. case CALLBACK_SET_BACKINGSTORE:
  211. g_backingStoreUpdated = true;
  212. return true;
  213. case CALLBACK_SET_TITLE:
  214. g_webViewStatus.setTitle(in[0].type_char_ptr);
  215. return true;
  216. case CALLBACK_SET_URL:
  217. g_webViewStatus.setUrl(in[0].type_char_ptr);
  218. return true;
  219. case CALLBACK_HOVER_LINK_URL:
  220. return true;
  221. case CALLBACK_SHOW_POPUP_MENU:
  222. return true;
  223. case CALLBACK_HIDE_POPUP_MENU:
  224. return true;
  225. case CALLBACK_LOAD_STARTED:
  226. g_webViewStatus.setProgress(0);
  227. return true;
  228. case CALLBACK_LOAD_FINISHED:
  229. printf("LoadFinished\n");
  230. g_webViewStatus.setProgress(100);
  231. g_test_status = FINISHED;
  232. return true;
  233. case CALLBACK_LOAD_PROGRESS_CHANGED:
  234. g_webViewStatus.setProgress((int)(in[0].type_float * 100));
  235. return true;
  236. case CALLBACK_LOAD_FAILED:
  237. printf("Load Failed: '%s' - %s (%d)\n", in[2].type_const_char_ptr, in[3].type_const_char_ptr, in[0].type_int);
  238. g_end = clock();
  239. printf("%.2f[sec]\n", (double)(g_end - g_start) / CLOCKS_PER_SEC);
  240. //g_quit = true;
  241. return true;
  242. case CALLBACK_JAVASCRIPT_ALERT:
  243. printf("JavaScript Alert: %s\n", in[0].type_const_char_ptr);
  244. return true;
  245. case CALLBACK_JAVASCRIPT_CONFIRM:
  246. printf("JavaScript Confirm: %s\n", in[0].type_const_char_ptr);
  247. printf("Returning 'true'\n");
  248. out[0].type_bool = true;
  249. return true;
  250. case CALLBACK_JAVASCRIPT_PROMPT:
  251. printf("JavaScript Prompt: %s (default: '%s')\n", in[0].type_const_char_ptr, in[1].type_const_char_ptr);
  252. printf("Returning default: '%s'\n", in[1].type_const_char_ptr ? in[1].type_const_char_ptr : "null");
  253. out[0].type_const_char_ptr = in[1].type_const_char_ptr;
  254. return true;
  255. case CALLBACK_DESTROY_WEBVIEW:
  256. g_test_status = DESTROYED;
  257. return true;
  258. default:
  259. return false;
  260. }
  261. }
  262. void initEvent()
  263. {
  264. int err = SCE_OK;
  265. // setup pad events
  266. err = sceCtrlSetSamplingMode(SCE_CTRL_MODE_DIGITALANALOG);
  267. SCE_DBG_ASSERT(err == SCE_OK);
  268. // setup touch events
  269. err = sceTouchSetSamplingState(SCE_TOUCH_PORT_FRONT, SCE_TOUCH_SAMPLING_STATE_START);
  270. sceTouchSetSamplingState(SCE_TOUCH_PORT_BACK, SCE_TOUCH_SAMPLING_STATE_START);
  271. SCE_DBG_ASSERT(err == SCE_OK);
  272. err = sceTouchEnableTouchForce(SCE_TOUCH_PORT_FRONT);
  273. SCE_DBG_ASSERT(err == SCE_OK);
  274. err = touchEventInit(&g_touchEventInfo);
  275. err = touchEventInit(&g_backtouchEventInfo);
  276. SCE_DBG_ASSERT(err == SCE_OK);
  277. err = touchEventSetMoveThreshold(&g_touchEventInfo, MOVE_THRESHOLD);
  278. err = touchEventSetMoveThreshold(&g_backtouchEventInfo, 5);
  279. SCE_DBG_ASSERT(err == SCE_OK);
  280. }
  281. void initApp()
  282. {
  283. #if defined(USE_WEBKIT)
  284. // set env
  285. setenv("WEBKIT_FONT_FILE", WEBKIT_FONT_FILE, 0);
  286. #if 0
  287. setenv("WEBKIT_THEME_PATH", WEBKIT_THEME_PATH, 0);
  288. setenv("WEBKIT_IGNORE_SSL_ERRORS", "", 0);
  289. #endif
  290. #endif
  291. // create webview instance
  292. memoryCheck("InitApp\n");
  293. WebViewManager::init(true, webViewCallback, NULL);
  294. g_webView = WebViewManager::create(WEBVIEW_WIDTH, WEBVIEW_HEIGHT);
  295. g_test_status = DESTROYED;
  296. fileOpen();
  297. }
  298. void updateApp()
  299. {
  300. switch (g_test_status) {
  301. case DESTROYED:
  302. char *url = fileRead();
  303. if (url[0] == '\0') {
  304. printf("All URLs have been tested.\n");
  305. g_end = clock();
  306. printf("%.2f[sec]\n", (double)(g_end - g_start) / CLOCKS_PER_SEC);
  307. g_quit = true;
  308. return;
  309. }
  310. g_webView = WebViewManager::create(WEBVIEW_WIDTH, WEBVIEW_HEIGHT);
  311. memoryCheck("Just before CreatedWebView\n");
  312. if (!g_webView) {
  313. printf("WebView creation failed.\n");
  314. g_quit = true;
  315. return;
  316. }
  317. g_test_status = RUNNING;
  318. g_webView->loadUrl(url);
  319. return;
  320. case RUNNING:
  321. break;
  322. case FINISHED:
  323. if (g_webView) {
  324. memoryCheck("Just before WebViewDestroyed\n");
  325. WebViewManager::destroy(g_webView);
  326. g_test_status = DESTROYING;
  327. }
  328. else {
  329. g_test_status = DESTROYED;
  330. }
  331. return;
  332. case DESTROYING:
  333. return;
  334. }
  335. float x = g_location_x;
  336. float y = g_location_y;
  337. float scale = g_scale;
  338. float delta = 80.0f;
  339. delta /= scale;
  340. if (g_ctrlData.lx < ANALOGSTICK_DEADZONE_LOW) {
  341. x += delta;
  342. }
  343. if (g_ctrlData.lx > ANALOGSTICK_DEADZONE_HIGH) {
  344. x -= delta;
  345. }
  346. if (g_ctrlData.ly < ANALOGSTICK_DEADZONE_LOW) {
  347. y += delta;
  348. }
  349. if (g_ctrlData.ly > ANALOGSTICK_DEADZONE_HIGH) {
  350. y -= delta;
  351. }
  352. if (g_ctrlData.ry < ANALOGSTICK_DEADZONE_LOW) {
  353. scale *= 1.05f;
  354. }
  355. if (g_ctrlData.ry > ANALOGSTICK_DEADZONE_HIGH) {
  356. scale /= 1.05f;
  357. }
  358. do {
  359. // get contents size
  360. int w, h;
  361. g_webView->getContentsSize(w, h);
  362. if (w <= 0 || h <= 0) return;
  363. // adjust scale
  364. if (scale > 2.0f) scale = 2.0f;
  365. if (scale < 1.0f) {
  366. if (scale * w < WEBVIEW_WIDTH) scale = (float)WEBVIEW_WIDTH / w;
  367. if (scale * h < WEBVIEW_HEIGHT) scale = (float)WEBVIEW_HEIGHT / h;
  368. }
  369. // adjust location
  370. if (x < 0) x = 0;
  371. if (x + WEBVIEW_WIDTH / scale > w)
  372. x = w - WEBVIEW_WIDTH / scale;
  373. if (y < 0) y = 0;
  374. if (y + WEBVIEW_HEIGHT / scale > h)
  375. y = h - WEBVIEW_HEIGHT / scale;
  376. if (g_location_x == x && g_location_y == y && g_scale == scale) {
  377. // nothing to do
  378. // break;
  379. }
  380. g_location_x = x;
  381. g_location_y = y;
  382. g_webView->drawRect((int)g_location_x, (int)g_location_y, (int)(WEBVIEW_WIDTH / scale), (int)(WEBVIEW_HEIGHT / scale), &g_target, sizeof(g_target));
  383. if (scale == g_scale) {
  384. g_webView->setClipRect((int)g_location_x, (int)g_location_y, (int)(WEBVIEW_WIDTH / scale), (int)(WEBVIEW_HEIGHT / scale));
  385. }
  386. g_scale = scale;
  387. } while (0);
  388. // heartbeat
  389. WebViewManager::update();
  390. }
  391. // Dispatch pad events
  392. static void dispatchPadEvent(SceUInt32 pressed, SceUInt32 released)
  393. {
  394. if (g_webView) {
  395. if (pressed & SCE_CTRL_L && g_webView->canGoBack()) {
  396. g_webView->goBack();
  397. }
  398. if (pressed & SCE_CTRL_R && g_webView->canGoForward()) {
  399. g_webView->goForward();
  400. }
  401. if (pressed & SCE_CTRL_UP) {
  402. g_webView->sendHtmlEvent(HTML_NODE_FOCUS_UP);
  403. }
  404. if (pressed & SCE_CTRL_DOWN) {
  405. g_webView->sendHtmlEvent(HTML_NODE_FOCUS_DOWN);
  406. }
  407. if (pressed & SCE_CTRL_LEFT) {
  408. g_webView->sendHtmlEvent(HTML_NODE_FOCUS_LEFT);
  409. }
  410. if (pressed & SCE_CTRL_RIGHT) {
  411. g_webView->sendHtmlEvent(HTML_NODE_FOCUS_RIGHT);
  412. }
  413. if (pressed & SCE_CTRL_CIRCLE) {
  414. g_webView->sendKeyEvent(KEY_EVENT_PRESSED, KEY_ENTER);
  415. }
  416. if (released & SCE_CTRL_CIRCLE) {
  417. g_webView->sendKeyEvent(KEY_EVENT_RELEASED, KEY_ENTER);
  418. }
  419. if (pressed & SCE_CTRL_CROSS) {
  420. g_webView->stop();
  421. }
  422. if (pressed & SCE_CTRL_START) {
  423. g_webView->reload();
  424. }
  425. }
  426. }
  427. // Dispatch touch events
  428. static void dispatchTouchEventSingleTouch(TouchEventElem *elm, MouseEventType type)
  429. {
  430. // using namespace sce::Vectormath::Simd::Aos;
  431. if (g_webView && elm) {
  432. SceUInt8 touchId = elm->id;
  433. SceInt16 x = elm->curX >> 1;
  434. SceInt16 y = elm->curY >> 1;
  435. if (elm->pNext == NULL) {
  436. if (convertScreenToLocalCSS(x, y)) {
  437. g_webView->sendMouseEvent(type, MOUSE_BUTTON_LEFT, x, y);
  438. }
  439. }
  440. }
  441. }
  442. static void dispatchTouchEventBack(TouchEventElem *elm, MouseEventType type)
  443. {
  444. if (elm) {
  445. SceInt16 x = elm->curX >> 1;
  446. SceInt16 y = elm->curY >> 1;
  447. if (type == MOUSE_EVENT_PRESSED) {
  448. if (convertScreenToLocalCSS(x, y)) {
  449. popup_mag(1.5f, 1.25f, -0.1f, 2.f, 3.f, (float)x, (float)y, 320.f, 272.f);
  450. }
  451. }
  452. else if (type == MOUSE_EVENT_MOVED) {
  453. if (elm->pNext == NULL) {
  454. if (convertScreenToLocalCSS(x, y)) {
  455. update_mag((float)x, (float)y, 320.f, 272.f);
  456. }
  457. }
  458. }
  459. else if (type == MOUSE_EVENT_RELEASED) {
  460. dismiss_mag();
  461. }
  462. }
  463. }
  464. // Update all hardware events
  465. static void updateEvent()
  466. {
  467. // update control buffer
  468. SceUInt32 prev = g_ctrlData.buttons;
  469. sceCtrlPeekBufferPositive(0, &g_ctrlData, 1);
  470. SceUInt32 pressed = g_ctrlData.buttons & ~prev;
  471. SceUInt32 released = ~g_ctrlData.buttons & prev;
  472. dispatchPadEvent(pressed, released);
  473. // update touch info
  474. SceTouchData data;
  475. int err = sceTouchRead(SCE_TOUCH_PORT_FRONT, &data, 1);
  476. SCE_DBG_ASSERT(err >= SCE_OK);
  477. err = touchEventUpdate(&data, &g_touchEventInfo);
  478. err = sceTouchRead(SCE_TOUCH_PORT_BACK, &data, 1);
  479. err = touchEventUpdate(&data, &g_backtouchEventInfo);
  480. SCE_DBG_ASSERT(err == SCE_OK);
  481. dispatchTouchEventSingleTouch(g_touchEventInfo.pPress, MOUSE_EVENT_PRESSED);
  482. dispatchTouchEventSingleTouch(g_touchEventInfo.pMove, MOUSE_EVENT_MOVED);
  483. dispatchTouchEventSingleTouch(g_touchEventInfo.pRelease, MOUSE_EVENT_RELEASED);
  484. dispatchTouchEventBack(g_backtouchEventInfo.pPress, MOUSE_EVENT_PRESSED);
  485. dispatchTouchEventBack(g_backtouchEventInfo.pMove, MOUSE_EVENT_MOVED);
  486. dispatchTouchEventBack(g_backtouchEventInfo.pRelease, MOUSE_EVENT_RELEASED);
  487. }
  488. // Power Tick Thread to prevent suspend.
  489. static SceInt32 PowerTickLoop(SceSize /*argSize*/, void */*pArgBlock*/)
  490. {
  491. while (!g_quit) {
  492. sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DISABLE_AUTO_SUSPEND);
  493. sceKernelDelayThread(10 * 1000 * 1000 /*us*/);
  494. }
  495. return SCE_OK;
  496. }
  497. static void init_power_tick_thread()
  498. {
  499. SceUID res = sceKernelCreateThread("PowerTick",
  500. PowerTickLoop,
  501. SCE_KERNEL_DEFAULT_PRIORITY_USER,
  502. SCE_KERNEL_STACK_SIZE_DEFAULT_USER_MAIN,
  503. 0,
  504. SCE_KERNEL_CPU_MASK_USER_ALL,
  505. NULL);
  506. if (res < 0) {
  507. printf("!!!!! PowerTick Thread creation failed %x !!!!\n", res);
  508. SCE_DBG_ASSERT(res >= 0);
  509. }
  510. SceUID thrid = res;
  511. res = sceKernelStartThread(thrid, 0, NULL);
  512. if (res != SCE_OK) {
  513. printf("!!!!! PowerTick Thread cannot start %x !!!!\n", res);
  514. SCE_DBG_ASSERT(res == SCE_OK);
  515. }
  516. }
  517. // Entry point
  518. int main(void)
  519. {
  520. int err = SCE_OK;
  521. UNUSED(err);
  522. init_power_tick_thread();
  523. #ifdef ENABLE_RAZOE_CPU_CAPTURE
  524. init_perf();
  525. #endif
  526. #ifdef ENABLE_RAZOR_HUD
  527. // Initialize the Razor HUD system.
  528. // This should be done before the call to sceGxmInitialize().
  529. err = sceSysmoduleLoadModule( SCE_SYSMODULE_RAZOR_HUD );
  530. SCE_DBG_ASSERT(err == SCE_OK);
  531. #endif
  532. #ifdef ENABLE_RAZOR_GPU_CAPTURE
  533. // Initialize the Razor capture system.
  534. // This should be done before the call to sceGxmInitialize().
  535. err = sceSysmoduleLoadModule( SCE_SYSMODULE_RAZOR_CAPTURE );
  536. SCE_DBG_ASSERT(err == SCE_OK);
  537. // Trigger a capture after 100 frames.
  538. sceRazorGpuCaptureSetTrigger( 100, "app0:render_to_texture.sgx" );
  539. #endif
  540. // initialize network library
  541. err = sceSysmoduleLoadModule( SCE_SYSMODULE_NET );
  542. SCE_DBG_ASSERT(err == SCE_OK);
  543. SceNetInitParam param;
  544. param.memory = s_net_memory;
  545. param.size = sizeof( s_net_memory );
  546. param.flags = 0;
  547. err = sceNetInit( &param );
  548. SCE_DBG_ASSERT(err == SCE_OK);
  549. // Load WebKit module
  550. err = sceKernelLoadStartModule("app0:ScePsp2Compat.suprx", 0, 0, 0, SCE_NULL, NULL);
  551. SCE_DBG_ASSERT(err > 0);
  552. err = sceKernelLoadStartModule("app0:SceTileBackend.suprx", 0, 0, 0, SCE_NULL, NULL);
  553. SCE_DBG_ASSERT(err > 0);
  554. err = sceKernelLoadStartModule("app0:SceWebKitModule.suprx", 0, 0, 0, SCE_NULL, NULL);
  555. SCE_DBG_ASSERT(err > 0);
  556. sceKernelChangeThreadPriority(SCE_KERNEL_THREAD_ID_SELF, SCE_KERNEL_DEFAULT_PRIORITY_USER-10);
  557. // initialize
  558. initDbgFont();
  559. initGxm();
  560. // create graphics data
  561. createClearData();
  562. createTestTextureData(WEBVIEW_WIDTH, WEBVIEW_HEIGHT, WEBVIEW_FORMAT);
  563. createCubeData();
  564. createOffscreenBuffer();
  565. updateRender(); // call once
  566. initEvent();
  567. initApp();
  568. // loop until exit
  569. //Test Start
  570. g_start = clock();
  571. while (!g_quit) {
  572. // do update step
  573. updateEvent();
  574. updateApp();
  575. // render
  576. // renderOffscreen();
  577. renderMain();
  578. // queue a display swap and cycle our buffers
  579. cycleDisplayBuffers();
  580. }
  581. // wait until rendering is done
  582. sceGxmFinish(g_context);
  583. // destroy graphics data
  584. destroyOffscreenBuffer();
  585. destroyCubeData();
  586. destroyTestTextureData();
  587. destroyClearData();
  588. // terminate graphics
  589. termGxm();
  590. termDbgFont();
  591. // terminate network library
  592. sceNetTerm();
  593. sceSysmoduleUnloadModule( SCE_SYSMODULE_NET );
  594. #ifdef ENABLE_RAZOR_GPU_CAPTURE
  595. // Terminate Razor capture.
  596. // This should be done after the call to sceGxmTerminate().
  597. sceSysmoduleUnloadModule( SCE_SYSMODULE_RAZOR_CAPTURE );
  598. #endif
  599. #ifdef ENABLE_RAZOR_HUD
  600. // Terminate Razor HUD.
  601. // This should be done after the call to sceGxmTerminate().
  602. sceSysmoduleUnloadModule( SCE_SYSMODULE_RAZOR_HUD );
  603. #endif
  604. fclose(fp);
  605. return SCE_OK;
  606. }
  607. static SceInt32 g_text_x = 0, g_text_y = 0;
  608. #define TEXT_LINE_HEIGHT 16
  609. void debugPrintf(const char *s)
  610. {
  611. if (s) {
  612. #if !defined(DISABLE_DEBUG_FONT)
  613. sceDbgFontPrint(g_text_x, g_text_y, 0xffffffff, (const SceChar8 *)s);
  614. #endif
  615. g_text_y += TEXT_LINE_HEIGHT;
  616. } else {
  617. g_text_y += (TEXT_LINE_HEIGHT / 2);
  618. }
  619. }
  620. void touchTrace(TouchEventElem *elm)
  621. {
  622. while (elm) {
  623. // TouchEvent touchEvent = elm->event;
  624. SceUInt8 touchId = elm->id;
  625. SceInt16 touchEventX = elm->curX;
  626. SceInt16 touchEventY = elm->curY;
  627. // SceInt16 touchEventF = elm->curF;
  628. // SceInt16 touchDeltaX = elm->deltaX;
  629. // SceInt16 touchDeltaY = elm->deltaY;
  630. // SceInt16 touchDeltaF = elm->deltaF;
  631. // SceUInt64 touchDeltaTime = elm->deltaT;
  632. // SceUInt64 touchElapsedTime = elm->elapsedT;
  633. char str[32];
  634. // snprintf(str, sizeof(str), "Touch event (%d) x:%04d y:%04d f:%04d dx:%04d dy:%04d df:%04d time:%ld elapsedTime:%ld\n", touchId, touchEventX, touchEventY, touchEventF, touchDeltaX, touchDeltaY, touchDeltaF, touchDeltaTime, touchElapsedTime);
  635. snprintf(str, sizeof(str), "Touch event (%d) x:%04d y:%04d\n", touchId, touchEventX, touchEventY);
  636. debugPrintf(str);
  637. elm = elm->pNext;
  638. }
  639. }
  640. int renderDbgFont(void)
  641. {
  642. // status
  643. g_text_x = 20;
  644. g_text_y = 20;
  645. debugPrintf("WebKit Test");
  646. debugPrintf(0);
  647. #if 0
  648. {
  649. char str[32];
  650. snprintf(str, sizeof(str), "FPS: %.2f", g_webViewStatus.fps());
  651. debugPrintf(str);
  652. }
  653. {
  654. char str[32];
  655. snprintf(str, sizeof(str), "Update Time: %.3f ms", g_webViewStatus.updateTime());
  656. debugPrintf(str);
  657. }
  658. {
  659. char str[32];
  660. snprintf(str, sizeof(str), "Render Time: %.3f ms", g_webViewStatus.renderTime());
  661. debugPrintf(str);
  662. }
  663. #endif
  664. {
  665. debugPrintf("Title");
  666. char str[64];
  667. snprintf(str, sizeof(str), "%s", g_webViewStatus.title());
  668. debugPrintf(str);
  669. }
  670. debugPrintf(0);
  671. {
  672. debugPrintf("URL");
  673. char str[64];
  674. snprintf(str, sizeof(str), "%s", g_webViewStatus.url());
  675. debugPrintf(str);
  676. }
  677. debugPrintf(0);
  678. {
  679. debugPrintf("Loading");
  680. char str[32];
  681. snprintf(str, sizeof(str), "%d%%", g_webViewStatus.progress());
  682. debugPrintf(str);
  683. }
  684. debugPrintf(0);
  685. #if 0
  686. {
  687. bool buttonUp = g_ctrlData.buttons & SCE_CTRL_UP;
  688. bool buttonDown = g_ctrlData.buttons & SCE_CTRL_DOWN;
  689. bool buttonLeft = g_ctrlData.buttons & SCE_CTRL_LEFT;
  690. bool buttonRight = g_ctrlData.buttons & SCE_CTRL_RIGHT;
  691. bool buttonStart = g_ctrlData.buttons & SCE_CTRL_START;
  692. bool buttonSelect = g_ctrlData.buttons & SCE_CTRL_SELECT;
  693. bool buttonCircle = g_ctrlData.buttons & SCE_CTRL_CIRCLE;
  694. bool buttonCross = g_ctrlData.buttons & SCE_CTRL_CROSS;
  695. bool buttonSquare = g_ctrlData.buttons & SCE_CTRL_SQUARE;
  696. bool buttonTriangle = g_ctrlData.buttons & SCE_CTRL_TRIANGLE;
  697. bool buttonL = g_ctrlData.buttons & SCE_CTRL_L;
  698. bool buttonR = g_ctrlData.buttons & SCE_CTRL_R;
  699. char str[32];
  700. snprintf(str, sizeof(str), "KeyState: %d%d%d%d %d%d%d%d %d%d%d%d", buttonUp, buttonDown, buttonLeft, buttonRight, buttonTriangle, buttonCross, buttonSquare, buttonCircle, buttonL, buttonR, buttonSelect, buttonStart);
  701. debugPrintf(str);
  702. }
  703. debugPrintf(0);
  704. {
  705. touchTrace(g_touchEventInfo.pPress);
  706. touchTrace(g_touchEventInfo.pHold);
  707. touchTrace(g_touchEventInfo.pMove);
  708. touchTrace(g_touchEventInfo.pAbort);
  709. touchTrace(g_touchEventInfo.pRelease);
  710. }
  711. #endif
  712. // usage
  713. g_text_x = 760;
  714. g_text_y = 350;
  715. debugPrintf("Pad Controls");
  716. debugPrintf(0);
  717. debugPrintf("Arrow : Focus navi");
  718. debugPrintf("CIRCLE : Decide");
  719. debugPrintf("CROSS : Stop loading");
  720. debugPrintf("START : Reload");
  721. debugPrintf("L : Go back");
  722. debugPrintf("R : Go forward");
  723. debugPrintf("L-Stick : Scroll");
  724. return SCE_OK;
  725. }
  726. extern "C" void *nullptr = 0;