{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/j2me.js/pulls/comments/27696867","id":27696867,"diff_hunk":"@@ -112,8 +112,35 @@ var currentlyFocusedTextEditor;\n         return 1;\n     };\n \n+    var hasNewFrame = true;\n+    var ctxToExecuteOnNewFrame;\n+    function gotNewFrame(timestamp) {\n+        if (ctxToExecuteOnNewFrame) {\n+            var ctx = ctxToExecuteOnNewFrame;\n+            ctxToExecuteOnNewFrame = null;\n+            window.requestAnimationFrame(gotNewFrame);\n+            ctx.execute();\n+        } else {\n+            hasNewFrame = true;\n+        }\n+    }\n \n-    addUnimplementedNative(\"com/sun/midp/lcdui/DisplayDevice.refresh0.(IIIIII)V\");\n+    Native[\"com/sun/midp/lcdui/DisplayDevice.refresh0.(IIIIII)V\"] = function() {\n+        // This is a no-op: The foreground display gets drawn directly\n+        // to the screen.\n+        //\n+        // However, we sometimes \"draw\" more frequently than the\n+        // screen can update. By calling `requestAnimationFrame` here,\n+        // we ensure that whatever we just drew will stick around for\n+        // one frame\n+        if (hasNewFrame) {\n+            hasNewFrame = false;\n+            window.requestAnimationFrame(gotNewFrame);\n+        } else {\n+            ctxToExecuteOnNewFrame = $.ctx;\n+            $.pause(asyncImplStringAsync);","path":"midp/gfx.js","position":23,"original_position":31,"commit_id":"6f1dfda3f0835817efb45cf83943f5da5e56a957","original_commit_id":"099cecacd62574ef2b4b842e58420c9d36107cbe","user":{"login":"TimAbraldes","id":955084,"avatar_url":"https://avatars.githubusercontent.com/u/955084?v=3","gravatar_id":"","url":"https://api.github.com/users/TimAbraldes","html_url":"https://github.com/TimAbraldes","followers_url":"https://api.github.com/users/TimAbraldes/followers","following_url":"https://api.github.com/users/TimAbraldes/following{/other_user}","gists_url":"https://api.github.com/users/TimAbraldes/gists{/gist_id}","starred_url":"https://api.github.com/users/TimAbraldes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimAbraldes/subscriptions","organizations_url":"https://api.github.com/users/TimAbraldes/orgs","repos_url":"https://api.github.com/users/TimAbraldes/repos","events_url":"https://api.github.com/users/TimAbraldes/events{/privacy}","received_events_url":"https://api.github.com/users/TimAbraldes/received_events","type":"User","site_admin":false},"body":"My understanding is that this could potentially cause us to wait when we don't need to.\r\n\r\nLet's say that our screen can refresh once every 20ms, and that all of our application logic means that it takes 21ms from one call of `waitForAnimationFrame` to the next. In this scenario, by the time `waitForAnimationFrame` is called, we can already immediately draw to the screen but we will instead call `window.requestAnimationFrame` and wait for a future opportunity to draw.\r\n\r\nThis is what `hasNewFrame` and `gotNewFrame` are intended to avoid. The idea is that, if we call `waitForAnimationFrame` but we know that we don't need to wait for a new frame, we should just go ahead and draw without waiting.\r\n\r\nLet me know if my analysis is flawed.","created_at":"2015-04-02T21:02:33Z","updated_at":"2015-04-02T21:02:33Z","html_url":"https://github.com/mozilla/j2me.js/pull/1315#discussion_r27696867","pull_request_url":"https://api.github.com/repos/mozilla/j2me.js/pulls/1315","_links":{"self":{"href":"https://api.github.com/repos/mozilla/j2me.js/pulls/comments/27696867"},"html":{"href":"https://github.com/mozilla/j2me.js/pull/1315#discussion_r27696867"},"pull_request":{"href":"https://api.github.com/repos/mozilla/j2me.js/pulls/1315"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/j2me.js/pulls/1315","id":31980359,"html_url":"https://github.com/mozilla/j2me.js/pull/1315","diff_url":"https://github.com/mozilla/j2me.js/pull/1315.diff","patch_url":"https://github.com/mozilla/j2me.js/pull/1315.patch","issue_url":"https://api.github.com/repos/mozilla/j2me.js/issues/1315","number":1315,"state":"open","locked":false,"title":"Limit refresh rate to that of screen. Update tests","user":{"login":"TimAbraldes","id":955084,"avatar_url":"https://avatars.githubusercontent.com/u/955084?v=3","gravatar_id":"","url":"https://api.github.com/users/TimAbraldes","html_url":"https://github.com/TimAbraldes","followers_url":"https://api.github.com/users/TimAbraldes/followers","following_url":"https://api.github.com/users/TimAbraldes/following{/other_user}","gists_url":"https://api.github.com/users/TimAbraldes/gists{/gist_id}","starred_url":"https://api.github.com/users/TimAbraldes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimAbraldes/subscriptions","organizations_url":"https://api.github.com/users/TimAbraldes/orgs","repos_url":"https://api.github.com/users/TimAbraldes/repos","events_url":"https://api.github.com/users/TimAbraldes/events{/privacy}","received_events_url":"https://api.github.com/users/TimAbraldes/received_events","type":"User","site_admin":false},"body":"This prevents us from attempting to paint multiple times to the screen\r\nwhen the screen can't actually keep up due to its refresh rate.\r\n\r\nUpdate the asteroids test to use the accepted mechanism for doing 1\r\ncalculation per frame.\r\n\r\nAdd a benchmark test for `Graphics.drawRegion` performance.","created_at":"2015-03-26T00:44:29Z","updated_at":"2015-04-02T21:02:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"55335472e5c9818b34a35ae01afd4544ac73abc8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/j2me.js/pulls/1315/commits","review_comments_url":"https://api.github.com/repos/mozilla/j2me.js/pulls/1315/comments","review_comment_url":"https://api.github.com/repos/mozilla/j2me.js/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/j2me.js/issues/1315/comments","statuses_url":"https://api.github.com/repos/mozilla/j2me.js/statuses/6f1dfda3f0835817efb45cf83943f5da5e56a957","head":{"label":"TimAbraldes:refresh","ref":"refresh","sha":"6f1dfda3f0835817efb45cf83943f5da5e56a957","user":{"login":"TimAbraldes","id":955084,"avatar_url":"https://avatars.githubusercontent.com/u/955084?v=3","gravatar_id":"","url":"https://api.github.com/users/TimAbraldes","html_url":"https://github.com/TimAbraldes","followers_url":"https://api.github.com/users/TimAbraldes/followers","following_url":"https://api.github.com/users/TimAbraldes/following{/other_user}","gists_url":"https://api.github.com/users/TimAbraldes/gists{/gist_id}","starred_url":"https://api.github.com/users/TimAbraldes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimAbraldes/subscriptions","organizations_url":"https://api.github.com/users/TimAbraldes/orgs","repos_url":"https://api.github.com/users/TimAbraldes/repos","events_url":"https://api.github.com/users/TimAbraldes/events{/privacy}","received_events_url":"https://api.github.com/users/TimAbraldes/received_events","type":"User","site_admin":false},"repo":{"id":25228954,"name":"j2me.js","full_name":"TimAbraldes/j2me.js","owner":{"login":"TimAbraldes","id":955084,"avatar_url":"https://avatars.githubusercontent.com/u/955084?v=3","gravatar_id":"","url":"https://api.github.com/users/TimAbraldes","html_url":"https://github.com/TimAbraldes","followers_url":"https://api.github.com/users/TimAbraldes/followers","following_url":"https://api.github.com/users/TimAbraldes/following{/other_user}","gists_url":"https://api.github.com/users/TimAbraldes/gists{/gist_id}","starred_url":"https://api.github.com/users/TimAbraldes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimAbraldes/subscriptions","organizations_url":"https://api.github.com/users/TimAbraldes/orgs","repos_url":"https://api.github.com/users/TimAbraldes/repos","events_url":"https://api.github.com/users/TimAbraldes/events{/privacy}","received_events_url":"https://api.github.com/users/TimAbraldes/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/TimAbraldes/j2me.js","description":"J2ME VM in JavaScript","fork":true,"url":"https://api.github.com/repos/TimAbraldes/j2me.js","forks_url":"https://api.github.com/repos/TimAbraldes/j2me.js/forks","keys_url":"https://api.github.com/repos/TimAbraldes/j2me.js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TimAbraldes/j2me.js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TimAbraldes/j2me.js/teams","hooks_url":"https://api.github.com/repos/TimAbraldes/j2me.js/hooks","issue_events_url":"https://api.github.com/repos/TimAbraldes/j2me.js/issues/events{/number}","events_url":"https://api.github.com/repos/TimAbraldes/j2me.js/events","assignees_url":"https://api.github.com/repos/TimAbraldes/j2me.js/assignees{/user}","branches_url":"https://api.github.com/repos/TimAbraldes/j2me.js/branches{/branch}","tags_url":"https://api.github.com/repos/TimAbraldes/j2me.js/tags","blobs_url":"https://api.github.com/repos/TimAbraldes/j2me.js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TimAbraldes/j2me.js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TimAbraldes/j2me.js/git/refs{/sha}","trees_url":"https://api.github.com/repos/TimAbraldes/j2me.js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TimAbraldes/j2me.js/statuses/{sha}","languages_url":"https://api.github.com/repos/TimAbraldes/j2me.js/languages","stargazers_url":"https://api.github.com/repos/TimAbraldes/j2me.js/stargazers","contributors_url":"https://api.github.com/repos/TimAbraldes/j2me.js/contributors","subscribers_url":"https://api.github.com/repos/TimAbraldes/j2me.js/subscribers","subscription_url":"https://api.github.com/repos/TimAbraldes/j2me.js/subscription","commits_url":"https://api.github.com/repos/TimAbraldes/j2me.js/commits{/sha}","git_commits_url":"https://api.github.com/repos/TimAbraldes/j2me.js/git/commits{/sha}","comments_url":"https://api.github.com/repos/TimAbraldes/j2me.js/comments{/number}","issue_comment_url":"https://api.github.com/repos/TimAbraldes/j2me.js/issues/comments{/number}","contents_url":"https://api.github.com/repos/TimAbraldes/j2me.js/contents/{+path}","compare_url":"https://api.github.com/repos/TimAbraldes/j2me.js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TimAbraldes/j2me.js/merges","archive_url":"https://api.github.com/repos/TimAbraldes/j2me.js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TimAbraldes/j2me.js/downloads","issues_url":"https://api.github.com/repos/TimAbraldes/j2me.js/issues{/number}","pulls_url":"https://api.github.com/repos/TimAbraldes/j2me.js/pulls{/number}","milestones_url":"https://api.github.com/repos/TimAbraldes/j2me.js/milestones{/number}","notifications_url":"https://api.github.com/repos/TimAbraldes/j2me.js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TimAbraldes/j2me.js/labels{/name}","releases_url":"https://api.github.com/repos/TimAbraldes/j2me.js/releases{/id}","created_at":"2014-10-14T22:14:36Z","updated_at":"2015-04-02T12:44:59Z","pushed_at":"2015-04-02T17:46:20Z","git_url":"git://github.com/TimAbraldes/j2me.js.git","ssh_url":"git@github.com:TimAbraldes/j2me.js.git","clone_url":"https://github.com/TimAbraldes/j2me.js.git","svn_url":"https://github.com/TimAbraldes/j2me.js","homepage":null,"size":28291,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"mozilla:master","ref":"master","sha":"1ddcbaa23a0b0a8f96c9a65f88a8efb318282a80","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":21724513,"name":"j2me.js","full_name":"mozilla/j2me.js","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/j2me.js","description":"J2ME VM in JavaScript","fork":false,"url":"https://api.github.com/repos/mozilla/j2me.js","forks_url":"https://api.github.com/repos/mozilla/j2me.js/forks","keys_url":"https://api.github.com/repos/mozilla/j2me.js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/j2me.js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/j2me.js/teams","hooks_url":"https://api.github.com/repos/mozilla/j2me.js/hooks","issue_events_url":"https://api.github.com/repos/mozilla/j2me.js/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/j2me.js/events","assignees_url":"https://api.github.com/repos/mozilla/j2me.js/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/j2me.js/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/j2me.js/tags","blobs_url":"https://api.github.com/repos/mozilla/j2me.js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/j2me.js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/j2me.js/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/j2me.js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/j2me.js/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/j2me.js/languages","stargazers_url":"https://api.github.com/repos/mozilla/j2me.js/stargazers","contributors_url":"https://api.github.com/repos/mozilla/j2me.js/contributors","subscribers_url":"https://api.github.com/repos/mozilla/j2me.js/subscribers","subscription_url":"https://api.github.com/repos/mozilla/j2me.js/subscription","commits_url":"https://api.github.com/repos/mozilla/j2me.js/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/j2me.js/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/j2me.js/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/j2me.js/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/j2me.js/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/j2me.js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/j2me.js/merges","archive_url":"https://api.github.com/repos/mozilla/j2me.js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/j2me.js/downloads","issues_url":"https://api.github.com/repos/mozilla/j2me.js/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/j2me.js/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/j2me.js/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/j2me.js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/j2me.js/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/j2me.js/releases{/id}","created_at":"2014-07-11T06:23:27Z","updated_at":"2015-04-02T11:45:04Z","pushed_at":"2015-04-02T18:21:00Z","git_url":"git://github.com/mozilla/j2me.js.git","ssh_url":"git@github.com:mozilla/j2me.js.git","clone_url":"https://github.com/mozilla/j2me.js.git","svn_url":"https://github.com/mozilla/j2me.js","homepage":null,"size":38025,"stargazers_count":68,"watchers_count":68,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":20,"mirror_url":null,"open_issues_count":202,"forks":20,"open_issues":202,"watchers":68,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/j2me.js/pulls/1315"},"html":{"href":"https://github.com/mozilla/j2me.js/pull/1315"},"issue":{"href":"https://api.github.com/repos/mozilla/j2me.js/issues/1315"},"comments":{"href":"https://api.github.com/repos/mozilla/j2me.js/issues/1315/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/j2me.js/pulls/1315/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/j2me.js/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/j2me.js/pulls/1315/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/j2me.js/statuses/6f1dfda3f0835817efb45cf83943f5da5e56a957"}}}}