• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            ++wythern++

            X presents Y for a better Z

            #

            【轉(zhuǎn)】Why your Android Apps Suck

            Original Post is here.

            Why I wrote this article?

            When I learn more about Android’s graphics system, and do more work about how to use CPU/GPU in more paralleled way to improve the graphics performance in Android, I start to think that there are actually some big design mistakes in Android graphics system, especially the rendering architecture in the client side.

            Some mistakes have been solved after 3.x, especially above 4.1, but others can never be solved due to the compatible reason. As developers, we need to know how the Android graphics system work, how to utilize the new features Android 3.x and 4.x provided, and how to do the optimazation and overcome the shortage of Android.

            Direct Rendering

            In the very beginning, Android’s client/server architecture of its graphics system choose the direct rendering mode, Android team develop a lightweight Window Compositor – SurfaceFlinger by themself, it response to create native windows, allocate graphics buffers and composite the window surface to display (via framebuffer). In client side, apps (through Android runtime) can use CPU to access the graphics buffer of native window directly (through Skia), or use GPU to manipulate it indirectly (through GLES). This direct rendeing mode is more appropriate than the traditional X in desktop Linux.

            Window Composite in Server Side

            SurfaceFlinger use GLES1 to do the window composition (via texture operation) in the very beginning, this cause two issues :

            • GPU may have more efficient way to do the window composition than use GLES;
            • When the client side also use GLES to render the window surface, it may competes with the server about the GPU resources;

            Just mention, when GPU do not support GLES1, Android has a built-in SW version GLES1 stack, and it can use copybit HAL module provided by chip vendor to accelerated the texture operation.

            So, after 3.0, Android introduce hwcomposer HAL module to solve these issues, also abandon the old copybit module. Chip vendor can through the implementation of hwcomposer module to declare they can do all of or part of windows’ composition by themselves, usually with dedicated hardware and always more efficient than use GLES. Also, after 4.1, hwcomposer can provide the vsync signal of the display, so that Android can sync three things together :

            • the windows composition in server side
            • the rendering of window surface in client side
            • the refresh of display

            vsync

            Rendering Architecture in Client Side

            The most mistake Android team make is the rendering architecture of its GUI framework :

            1. It do not has a layer rendering architecture (or called scene graph in some GUI fw);
            2. It do not has a dedicated rendering thread to render the window surface;
            3. It’s rendering only use CPU until 3.0;

            The first one is partially support after 3.0, the third is support after 3.0, but the second problem can never be solved…

            Compare to iOS

            In iOS, every View has a Layer as its backing store, app can create more Layers for better performance. View’s content will be drew into its Layer, as long as the content do not changed, the View do not need to draw itself again. iOS do a lot of things to avoid change the content of a View, many many properties of a View can be changed without affect to its content, such as background, border, opacity, position, transformation, even the geometry!!!

            The composition of Layers done by another dedicated rendering thread, it always use GPU to draw each Layer to the window surface. The main thread only reponse to handle touch event, relayout the Views, draw View’s content into its Layer when necessary, etc… So the main thread only use CPU and the rendering thread use GPU mostly, and I think there will be just a few synchronization between these two threads, and they can run concurrently in most of time.

            But in Android, the main thread need to do everything, such as handle touch events, relayout views, dequeue/enqueue graphics buffer, draw views’ content on window surface, and other things need to be done by app… And it only use CPU before 3.0!!! Even the position of a View just change one pixel, Android need to redraw its content along with the contents of other Views overlapped, and the content drawing is very expensive for CPU!!!

            The Improvements

            A lot improvements have been made after 3.0 to overcome the shortage of previous versions. Android 3.0 introduce a new hwui module, and it can use GPU to accelerated the drawing of View’s content, it create a hw accelerated Canvas to replace the old sw Canvas, the new Canvas use OpenGL ES as its backend instead of use SkCanvas from Skia.

            Android 3.0 also introduce the DisplayList mechanism, DisplayList can be considered as a 2D drawing commands buffer, every View has its own DisplayList , and when its onDraw method called, all drawing commands issue through the input Canvas actually store into its own DisplayList. When every DisplayList are ready, Android will draw all the DisplayLists, it actually turn the 2D drawing commands into GLES commands to use GPU to render the window surface. So the rendering of View Hierarchy actually separated into two steps, generate View’s DisplayList, and then draw the DisplayLists, and the second one use GPU mostly.

            When app invalidate a View, Android need to regenerate its DisplayList, but the overlapped View’s DisplayList can keep untouched.  Also, Android 4.1 introduce DisplayList properties, DisplayList now can has many properties such as opacity, transformation, etc…, and the changed of some properties of View will just cause changed of corresponding properties of its DisplayList and need not to regenerate it. These two improvements can save some times by avoid regenerate DisplayLists unnecessary.

            Although Android can never has a layer rendering architecture, it actually introduce some Layer support after 3.0, a View can has a Layer as its backing store. The so called HW Layer actually back by a FBO, if the content of View is too complicated and unlikely to change in the future, use Layer may help. Also, when a View is animating (but content do not change), cache itself and its parent with Layers may also help. But use Layer with caution, because it increase the memory usage, if your want to use Layers during animation, your may need to release them when the animation is finish, Android 4.2 provide new animation API to help you about that. Also, because Android use GLES to draw the content of View, so most Views’ drawing will be fast enough, and the use of Layer may be unnecessary.

            Android 4.0 also introduce a new type of native window – SurfaceTextureClient (back by a SurfaceTexture) and its Java wrapper TextureView, app can create and own this kind of native window and response to its composition. If the content of View is too complicated and continue to change, TextureView will be very helpful, app can use another thread to generate the content of TextureView and notify the main thread to update, and main thread can use the TextureView as a normal texture and draw it directly on the window of current Activity. (TextureView can also replace the usage of original SurfaceView and GLSurfaceView)

            Android 4.1 make the touch event handling and ui drawing sync with the vsync signal of display, it also use triple buffers to avoid block the main thread too often because it need to wait the SurfaceFlinger to do the page flip and release the previous front buffer, and SurfaceFlinger will always sync with vsync signal of display.

            The OpenGL Renderer for hw accelerated Canvas is continue be improved and become faster, especially for complicated shape drawing.

            But…

            But Android can never has a dedicated rendering thread… Although the drawing is much faster than before, and keep the changed of everything as little as possible during animating, it still need to share the 16ms interval with other jobs in main thread to achieve 60 fps.

            So…

            So, as developer, we need to utilize the improvements in higher version Android as much as possible :

            1. Turn on the GPU acceleration switch above Android 3.0;
            2. Use the new Animation Framework for your animation;
            3. Use Layer and TextureView when necessary;
            4. etc…

            And avoid to block the main thread as much as possible, that means :

            1. If your handle the touch events too long, do it in another thread;
            2. If your need to load a file from sdcard or read data from database, do it in another thread;
            3. If your need to decode a bitmap, do it in another thread;
            4. If your View’s content is too complicated, use Layer, if it continue to change, use TextureView and generate its content in another thread;
            5. Even your can use another standalone window (such as SurfaceView) as a overlay and render it in another thread;
            6. etc…

            Golden Rules for Butter Graphics

            • Whatever you can do in another thread, then do it in another thread;
            • Whatever you must do in main thread, then do it fast;
            • Always profiling, it is your most dear friend;

            All you need to do is keep the loop of main thread under 16ms interval, and every frame will be perfect!

            The Last Word

            When I finish this article, what make me think most is, when you make a big design mistake in the very beginning, and you can not change it due to some reasons, no matter how hard you try to patch it in future, it will never get perfect again.

            Android team make huge effects to provide features like Strict Mode, AsyncTask, Concurrent & Background GC, hw accelerated Canvas, hw Layer, TextureView, vsync, triple buffers, etc… All they do just about two things, do everything you can in another thread, and make the must thing in main thread faster, and these actually help a lot. But no matter how hard you try to use these features to improve your app, it is nearly impossible to get every frame perfect, because it is so hard to forecast everything the main thread will do in every loop, it may suddenly jump into something totally uncontrollable by you app and make you break the 16ms curse.

            And the worse is, if you has a good design, you can continue improve it (like utilize more advance hardware), but the developer need not to know anything about this and do not need to change even one line of their code, if the app run on higher version OS with faster device, it just got the performance boost. If you has a bad design, although you do a lot of things to patch it, but the developer need to know why, they need to rewrite their code to use these new features, they need to know how to avoid the trap, they need to know how to make compatible with older version system, and many many other things…

            This is too hard for a developer just want to build a useful and beauty app…

            posted @ 2013-11-04 22:32 wythern 閱讀(701) | 評論 (0)編輯 收藏

            [轉(zhuǎn)] How to add logs into android.mk [to display the information at compile time]

            Original Post is here.

            How to add logs into android.mk file:
             
            This log will be printed whenever we are compiling.
            Usecases: In a large project, somewhere the values will be set, User wont be aware of it.
            So that time,to print which device macro is enabled, we can make use of this warning in android.mk

            within Android.mk,

            ENABLE_CODEC =1
            ifeq(ENABLE_CODEC,true)
            $(warning SUNDARA::ENABLE_CODEC is true)
            else
            $(warning SUNDARA::ENABLE_CODEC is false)
            endif

            #How to print the variable from Android.mk

            TARGET_PLATFORM := MSM7227
            $(warning SUNDARA::Target Plarform is '$(TARGET_PLATFORM)')

            output:
            SUNDARA::ENABLE_CODEC is true
            Target Plarform is MSM7227

            posted @ 2013-10-10 10:25 wythern 閱讀(886) | 評論 (0)編輯 收藏

            Disable XON/XOFF in Putty

            Sometimes I use putty to login my ubuntu machine, and use emacs to edit some text files.
            But it always stop working when I save my edition in emacs ( Ctrl-x Ctrl-s ). I firstly thought it was a network problem, but the frequent happening with fix pattern(hang in save) made me do some investigation.
            Answer founded here. To be briefly, the Ctrl-s is the flow control key which send XOFF to terminal and let it stop output, one may use Ctrl-Q to send XON and enable the output.
            Here is the way to disable this behavior.
               echo "stty -ixon" >> ~/.bashrc
            Now, putty seems ok.

            posted @ 2013-09-10 11:42 wythern 閱讀(318) | 評論 (0)編輯 收藏

            The missing systrace option in Android 4.3

            In Android 4.3, I did not find the "trace option" in setting->"Developer options".
            And the python script(systrace.py) seems buggy, as this stackoverflow post told.

            occasionally I find that "trace option" in eclipse.
            Just like the image below:



            This eclipse is extracted from latest android SDK, downloaded from here.
            Now, I can use systrace as Android4.2.

            posted @ 2013-09-09 18:26 wythern 閱讀(711) | 評論 (0)編輯 收藏

            [轉(zhuǎn)]怎么從Backtrace,找到對應(yīng)的代碼行

            原文在這里

            Backtrace中,一般都只有一些地址。但是利用addr2line這個(gè)工具,就可以找到對應(yīng)的代碼行。前提條件是可執(zhí)行程序或者動(dòng)態(tài)鏈接庫編譯的時(shí)候帶-g選項(xiàng)。

            具體來說,分兩種情況:

            1. 如果關(guān)注的一行backtrace位于一個(gè)可執(zhí)行文件中,那么直接addr2line -e <executable> <address>
            2. 如果關(guān)注的backtrace位于一個(gè)動(dòng)態(tài)鏈接庫中,那么麻煩一些,因?yàn)閯?dòng)態(tài)鏈接庫的基地址不是固定的。這個(gè)時(shí)候,首先要把進(jìn)程的memory map找來。在Linux下,進(jìn)程的memory map可以在/proc/<pid>/maps文件中得到。然后在這個(gè)文件中找到動(dòng)態(tài)鏈接庫的基地址,然后將backtrace中的地址 - 動(dòng)態(tài)鏈接庫的基地址,得到偏移地址offset address, 最后addr2line -e <shared library> <offset address>。

            當(dāng)然,用GDB也可以找出地址對應(yīng)的代碼行。不過相比addr2line,GDB需要將BUG現(xiàn)象重現(xiàn)一遍,所以對于不好重現(xiàn)的BUG,或是隨機(jī)重 現(xiàn)的BUG來說,使用addr2line就可以直接從backtrace找到對應(yīng)的代碼行,不需要重現(xiàn)現(xiàn)象,比GDB使用起來更簡單。

            posted @ 2013-08-29 14:29 wythern 閱讀(565) | 評論 (0)編輯 收藏

            adb shell 設(shè)置 Android Setting

            之前學(xué)習(xí)DisplayManage相關(guān)的東西的時(shí)候用adb shell命令修改了一下setting,避免了每次都重新燒板子的命運(yùn)。

            最近在調(diào)試的時(shí)候經(jīng)常遇到這樣一個(gè)提示(如圖)
            XXXXX is sending a large number of SMS messages.
             
            點(diǎn)擊N多次才能取消掉,忍無可忍無須再忍!
            Google一把,正確解法在這里 這里

            但是在JellyBean的setting database里面找不到這個(gè)Gservice table。
            用“select name from sqlite_master where type='table' order by name;”
            看到settings的database里面有secure,global, etc.,幾個(gè)table,
            其中secure table是后一篇文章(這里)建議修改的地方,但是我改了以后也不起作用。

            看來不是同樣的問題,在Settings.java里面搜索
            "SMS_OUTGOING_CHECK_MAX_COUNT"
            找到 Setting.Global.SMS_OUTGOING_CHECK_MAX_COUNT.
            原來應(yīng)該是在setting database  global table里面設(shè)置這一項(xiàng)。

            接下來的事情就容易了
            INSERT INTO global VALUES ('100', 'SMS_OUTGOING_CEHCK_INTERVAL_MS', '0');
            INSERT INTO global VALUES ('101', 'SMS_OUTGOING_CEHCK_MAX_COUNT', '9999999999');
            重啟,搞定!

            看起來所有的Settings都可以用類似的辦法在adb shell下用sqlite3很容易的進(jìn)行修改。
            比如這里有個(gè)xd這樣改的rotation設(shè)置
            Settings.System. ACCELEROMETER_ROTATIONSettings.System. USER_ROTATION

            發(fā)文以記之!

            posted @ 2013-04-12 15:43 wythern 閱讀(2316) | 評論 (0)編輯 收藏

            【轉(zhuǎn)】Android Settings Reset Using ADB

            原帖在這里

            關(guān)鍵字:
            sqlite3
            com.android.providers.settings/databases/settings.db
            sql select/delete

            posted @ 2013-04-01 09:56 wythern 閱讀(297) | 評論 (0)編輯 收藏

            Android intent-filter 不能收到 ACTION_SCREEN_ON/OFF intent

            這里有解釋

            Android does not seem to support manifest-registered receivers for cases where they really do not want to start up a new process. For example, you will see the same effect with the battery info actions (e.g., BATTERY_LOW). Beyond that, though, I don't have much rationale -- I didn't write it. :-) – CommonsWare Oct 19 '09 at 12:50

            在某些intent broadcasting case下android不希望產(chǎn)生新的process(可能會導(dǎo)致系統(tǒng)響應(yīng)慢),SCREEN_ON / OFF 就屬于這樣的case。
            所以在自己的activity里面registerReceiver()是處理這樣的case的正確選擇。

            posted @ 2013-03-27 16:05 wythern 閱讀(1326) | 評論 (0)編輯 收藏

            [轉(zhuǎn)]Ubuntu gnome3 沒有關(guān)機(jī)按鍵的解決辦法

            搜了半天,答案在:這里

            alternative-status-menu:系統(tǒng)安裝好后默認(rèn)用戶菜單中是沒有關(guān)機(jī)命令的,用戶想要關(guān)機(jī)需要按住Alt鍵才能顯示關(guān)機(jī)。此擴(kuò)展可以在用戶菜單中顯示關(guān)機(jī)命令。

            posted @ 2013-03-04 07:53 wythern 閱讀(405) | 評論 (0)編輯 收藏

            解決XP上Firefox鍵盤輸入沒有響應(yīng)的辦法

            Firefox 在我這筆記本(Win XP)上經(jīng)常會莫名其妙的不響應(yīng)鍵盤輸入,重啟不解決問題,升級到最新版也沒有幫助。
            剛發(fā)現(xiàn)只要鎖屏(Win+L),在重登錄進(jìn)來就好了。
            莫名其妙!

            posted @ 2013-02-04 19:58 wythern 閱讀(313) | 評論 (0)編輯 收藏

            僅列出標(biāo)題
            共6頁: 1 2 3 4 5 6 
            国产精品无码久久久久久| 99久久免费国产精品特黄| 日批日出水久久亚洲精品tv| 国产精品99久久免费观看| 波多野结衣久久一区二区| 日韩AV毛片精品久久久| 精品乱码久久久久久夜夜嗨| 国产精品无码久久久久| 99久久精品国产一区二区三区| 99久久无码一区人妻a黑| 99久久er这里只有精品18| avtt天堂网久久精品| 99精品久久精品一区二区| 色综合久久精品中文字幕首页 | 久久精品夜色噜噜亚洲A∨| 国产高潮国产高潮久久久91| 久久久久国产精品三级网| 久久久网中文字幕| 亚洲精品视频久久久| 亚洲色大成网站WWW久久九九| 久久亚洲精品成人av无码网站| 国产精品一久久香蕉产线看| Xx性欧美肥妇精品久久久久久| 精品久久久久久久久久中文字幕| 一本综合久久国产二区| 久久亚洲精品国产精品| 欧美777精品久久久久网| 伊人久久国产免费观看视频 | 国产精品亚洲美女久久久| 国产亚洲成人久久| 一本色道久久99一综合| 久久国产亚洲精品麻豆| 思思久久精品在热线热| 99久久成人国产精品免费| 久久久久香蕉视频| 国产高潮国产高潮久久久| 欧美久久一区二区三区| 国产美女久久久| 性欧美丰满熟妇XXXX性久久久| 国产免费福利体检区久久| 日本久久久久亚洲中字幕|