官方文档中对硬件加速的描述


Beginning in Android 3.0 (API level 11), the Android 2D rendering pipeline渲染引擎 supports hardware acceleration, meaning that all drawing operations操作 that are performed执行 on a View's canvas use the GPU. Because of the increased增加 resources required to enable hardware acceleration, your app will consume消耗 more RAM.

Hardware acceleration is enabled by default if your Target API level is >=14, but can also be explicitly明确的 enabled. If your application uses only standard views and Drawables, turning it on globally全局 should not cause any adverse不利的 drawing effects. However, because hardware acceleration is not supported for all of the 2D drawing operations, turning it on might affect some of your custom views自定义控件 or drawing calls. Problems usually manifest themselves as表现为 invisible elements, exceptions, or wrongly rendered pixels. To remedy修改 this, Android gives you the option to enable or disable hardware acceleration at multiple levels多种级别.

If your application performs custom drawing, test your application on actual hardware devices with hardware acceleration turned on to find any problems. The Unsupported drawing operations section章节 describes known issues已知的问题 with hardware acceleration and how to work around绕开、避免 them.

四个层次级别的硬件加速

1、整个应用 Application 层,可以选择打开或关闭
<application android:hardwareAccelerated="true">

2、Activity 层,可以选择打开或关闭

<activity android:hardwareAccelerated="true">

3、Window 层,只能打开(必须在setContentView之前调用)

getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, //
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);

4、View 层,只能关闭。也可在XML使用 android:layerType="software" 来关闭硬件加速

view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
注意:在apk的AndroidManifest中,如果指定了minSDKVersion & targetSDKVersion=7,会使得应用无法使用硬件加速进行绘图。

如何判断一个View是否启用了硬件加速

有两种方式:
  • 使用View的isHardwareAccelerated()
    • 如果View挂在一个开启了硬件加速的Window之下,返回true。也就是说,它在绘制的时候不一定使用了硬件加速。
    • returns true if the View is attached to a hardware accelerated window.
  • 使用Canvas的isHardwareAccelerated()
    • 如果canvas在绘制的时候启用了硬件加速,返回true。
    • 建议在draw的代码块中使用此方法来判断是否开启了硬件加速,因为如果一个View被attach到一个硬件加速的Window上,即使没有硬件加速的Canvas,它也是可以被绘制的。比如:将一个View以bitmap的形式进行缓存
    • returns true if the Canvas is hardware accelerated.

Android中的硬件加速

硬件加速能使用GPU来加速2D图像的渲染速度,但是硬件加速并不能完全支持所有的渲染操作, 针对自定义的View,硬件加速可能导致渲染出现错误。 如果有自定义的View,需要在硬件加速的设备上进行测试,如果出现渲染的问题,需要关闭硬件加速。

不过Android可以保证内置的组件和应用支持硬件加速,因此,如果应用中只使用了标准UI组件,可以放心开启硬件加速。

随着Android的版本升级,相信一段时间之后,硬件加速可以得到完美的支持。

开启硬件加速之后可能的异常反应:
  • 某些UI元素没有显示或者没有更新:可能是没有调用invalidate
  • 绘制不正确或者抛出异常:可能使用了不支持硬件加速的操作, 需要关闭硬件加速或者绕过该操作

硬件加速 Hardware Accelerated 绘制的更多相关文章

  1. CSS开启硬件加速 hardware accelerated

    作者:孙志勇 微博 日期:2016年12月6日 一.时效性 所有信息都具有时效性.文章的价值,往往跟时间有很大关联.特别是技术类文章,请注意本文创建时间,如果本文过于久远,请读者酌情考量,莫要浪费时间 ...

  2. GPU硬件加速原理 /转

    现代浏览器大都可以利用GPU来加速页面渲染.每个人都痴迷于60桢每秒的顺滑动画.在GPU的众多特性之中,它可以存储一定数量的纹理(一个矩形的像素点集合)并且高效地操作这些纹理(比如进行特定的移动.缩放 ...

  3. GPU硬件加速

    现代浏览器大都可以利用GPU来加速页面渲染.每个人都痴迷于60桢每秒的顺滑动画.在GPU的众多特性之中,它可以存储一定数量的纹理(一个矩形的像素点集合)并且高效地操作这些纹理(比如进行特定的移动.缩放 ...

  4. Android 4.0的图形硬件加速及绘制技巧

    转:http://zuiniuwang.blog.51cto.com/3709988/721798 从Android 3.0开始,Android 2D的绘制流程就设计为能够更好地支持硬件加速.使用GP ...

  5. android非硬件加速绘制简单流程

    这里的硬件加速是指openGL + GPU 如果不适用硬件加速: 1 ViewRootImpl.java draw:if (!dirty.isEmpty() || mIsAnimating || ac ...

  6. GPU硬件加速相关

    从android3.0开始,2D渲染开始支持硬件加速,即在view的Canvas上的绘图操作可以用GPU来加速. 硬件加速会使app消耗更多的内存. 如果配置文件中,Target API level  ...

  7. CSS硬件加速的好与坏

    本文翻译自Ariya Hidayat的Hardware Accelerated CSS: The Nice vs The Naughty.感谢Kyle He帮助校对. 每个人都痴迷于60桢每秒的顺滑动 ...

  8. ffmpeg实现dxva2硬件加速

    这几天在做dxva2硬件加速,找不到什么资料,翻译了一下微软的两篇相关文档.这是第二篇,记录用ffmpeg实现dxva2. 第一篇翻译的Direct3D device manager,链接:http: ...

  9. HW Video Acceleration in Chrome/Chromium HTML5 video 视频播放硬件加速

    Introduction Video decode (e.g. YouTube playback) and encode (e.g. video chat applications) are some ...

随机推荐

  1. Mybatis使用入门

    一.Mybatis简介 1.传统JDBC的不足 我们首先看一下JDBC的一般操作流程.比如,我想从user表中获取根据name获取数据,下面是传统JDBC代码: package lkb.webchat ...

  2. python的进阶--爬虫小试

    代理之说 [ python实现代理服务功能实例 ]  --  https://www.jb51.net/article/43266.htm [检测代理是否有效] -- https://blog.csd ...

  3. PHP的数据类型与常量使用

    数据类型之间的相互转换 1.强制转换:setType(变量,类型):这个函数将原变量的类型改变//integer,int,float,double,bool,boolen,string,arry,ob ...

  4. 【BZOJ 2711】 2711: [Violet 2]After 17 (0-1 背包)

    2711: [Violet 2]After 17 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 224  Solved: 153 Description ...

  5. android studio 可以汉化的 文件 地方

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 汉化包 百度云盘 下载地址:https://pan.baidu.com/s/1pLjwy ...

  6. Codeforces 650 D. Zip-line

    $ >Codeforces \space 650 D. Zip-line<$ 题目大意 : 有一个长度为 \(n\) 的序列 \(h\) ,\(m\) 次询问,每一次询问求如果把序列中第 ...

  7. [待码][BZOJ1858]SCOI2010序列操作 jzyzoj1655

    待码的线段树.....太长了看上去不是很想写 [ 什么破理由啊摔,不要脸 ] 嗯先水几道再写

  8. 【推导】【线段树】hdu5929 Basic Data Structure

    题意: 维护一个栈,支持以下操作: 从当前栈顶加入一个0或者1: 从当前栈顶弹掉一个数: 将栈顶指针和栈底指针交换: 询问a[top] nand a[top-1] nand ... nand a[bo ...

  9. Android之View / SurfaceView / GLSurfaceView

    Android游戏当中主要的除了控制类外就是显示类View.SurfaceView是从View基类中派生出来的显示类.android游戏开发中常用的三种视图是:view.SurfaceView和GLS ...

  10. (转)资源监控工具Spotlight监测LINUX

    个人1.安装spotlight,Spotlight on Unix2.配置spotlight,注意spotlight默认不能使用root用户进行连接,需要用户自己创建一个具有root权限的用户.(1) ...