Use VectorIcons in Android |
||
Issue descriptionMany of the image resources used in Chrome on Desktop are present as VectorIcons (.icon files, eg [1]). These consist of drawing instructions, are included in the generated vector_icons.cc [2] file and used in desktop code. Android uses mostly pngs [3] for displaying icons and many images are present as both pngs and VectorIcons. We could save on binary size by allowing Android code to display VectorIcons. We should also look in to any performance implications. [1] https://cs.chromium.org/chromium/src/chrome/app/vector_icons/credit_card.icon?q=credit_card.icon&dr [2] https://cs.chromium.org/chromium/src/out/Debug/gen/chrome/app/vector_icons/vector_icons.cc?type=cs&q=vector_icons.cc+creditcard [3] https://cs.chromium.org/chromium/src/chrome/android/java/res/drawable-xxxhdpi/infobar_autofill_cc.png?q=autofill_cc.png&dr
,
Jun 13 2017
I looked through the png files contained in a local build of Chrome.apk and compared them with the icon files surfaced in ChromeAssetsViewer[1]. Here is a list of pngs where I found a matching icon file. The size is the sum of all the resolutions of the png. Bytes Icon File png 2461 account_child_circle ic_account_child_20dp.png 6247 account_child_circle ic_account_child_grey600_36dp.png 773 back_arrow ic_arrow_back_white_24dp.png 504 business controlled_setting_mandatory.png 2477 cookie.icon permission_cookie.png 1279 credit_card infobar_autofill_cc.png 646 default_favicon default_favicon_white.png 663 default_favicon default_favicon.png 748 default_favicon ic_omnibox_page.png 834 file_download infobar_downloading.png 1068 folder bookmark_folder.png 961 folder ic_folder_white_24dp.png 1765 https_invalid omnibox_https_invalid.png 1272 https_valid omnibox_https_valid.png 1766 image ic_image_white_24dp.png 2589 image ic_image_white_36dp.png 5002 incognito ic_omnibox_incognito_badge.png 3075 incognito incognito_statusbar.png 2957 info_outline btn_info.png 2393 info_outline omnibox_info.png 3614 location_bar_star btn_star.png 4637 location_on ic_place_googblue_36dp.png 3052 location_on infobar_geolocation.png 2505 location_on permission_location.png 940 menu_check bookmark_check_gray.png 1024 menu_check ic_check_googblue_24dp.png 2380 microphone btn_mic.png 3370 microphone infobar_microphone.png 2586 microphone permission_mic.png 2396 microphone webrtc_audio.png 901 midi infobar_midi.png 875 midi permission_midi.png 1977 mode_edit bookmark_edit_active.png 1091 navigate_back back_normal.png 1009 navigate_back btn_left.png 1944 navigate_home btn_toolbar_home.png 5084 navigate_reload btn_toolbar_reload.png 2628 notifications infobar_desktop_notifications.png 1945 notifications permission_push_notification.png 3822 omnibox_star btn_star_filled.png 2520 photo_camera ic_photo_camera.png 4087 product ic_chrome.png 4989 product infobar_chrome.png 1454 sad_tab infobar_restore.png 893 sad_tab sad_tab.png 2728 search ic_search.png 4706 search ic_suggestion_magnifier.png 2026 settings_menu_usb settings_usb.png 2361 star/star_active star_gray.png 3048 star/star_active star_green.png 3799 sync_problem sync_error.png 1801 system_menu_cast ic_cast_dark_off.png 2507 system_menu_cast_enabled ic_cast_dark_on.png (maybe also system_tray_cast) 7485 system_menu_cast_enabled cast_playing_square.png 4188 system_menu_help ic_help_and_feedback.png 3272 system_menu_help ic_help_white_24dp.png 1691 system_menu_info ic_info_grey.png 2613 system_menu_update badge_update_dark.png 2595 system_menu_update badge_update_light.png 2944 system_menu_update menu_update.png (maybe also system_tray_update, browser_tools_update) 2509 tab_close_hovered_pressed btn_delete_url.png 1075 tab_close_normal btn_close_white.png 1123 tab_close_normal btn_close.png 1263 videocam infobar_camera.png 1040 videocam permission_camera.png 2132 warning exclamation_triangle.png 1988 warning ic_warning_white_24dp.png 3170 warning infobar_warning.png 1146 warning_badge ic_warning.png 1003 web ic_drive_site_white_24dp.png 1457 web ic_drive_site_white_36dp.png 912 widget_control_right_snapped breadcrumb_arrow.png Interestingly there were often multiple pngs that could be replaced by the same icon file. This is sometimes because there are duplicates and sometimes because the pngs exist in multiple colours. When rendering an icon file you can pass the primary colour, so different coloured versions can use the same icon file. This gives a total of 168kB as an upper limit on the space saved. [1] https://alpha-1-dot-chrome-assets.googleplex.com
,
Jun 14 2017
Using VectorIcons in Android seems simple enough, the following two lines create an image that can be passed across the JNI: gfx::ImageSkia image = gfx::CreateVectorIcon(kCookieIcon, 180, static_cast<SkColor>(0xFF0000FF)); base::android::ScopedJavaLocalRef<jobject> j_image = gfx::ConvertToJavaBitmap(image.bitmap()); The 180 refers to the requested size. From experimentation you get good results if this is the size the image is going to be used at in pixels. The SkColor is the drawing colour. Obviously both of these should be parameters. The tricky part will be specifying which icon file to use. Icons are stored as static constants, so there is no easy identifier we can hand across the JNI to get them. These constants are automatically generated, so it would be possible to give them an ID and spit out these IDs in a generated Java file.
,
Jan 21
(2 days ago)
Marking this as a duplicate of a similar (archived) bug. Currently, there are no plans to pursue this. We came across it in a binary size bug triage session. |
||
►
Sign in to add a comment |
||
Comment 1 by peconn@chromium.org
, Jun 13 2017