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


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. live555例子程序编译连接时发现函数未定义问题

    1 调整连接库的顺序. 2 更新头文件与所用的库一致

  2. Linq简单使用

    简单使用 from子查询 关联多个数据源 分组 let 子句 查询对象(上例中为list变量)为IEnumerable<T>或IQueryable<T>类型 查询返回结果同样为 ...

  3. elementUI 学习入门之 Button 按钮

    基础按钮用法 按钮分为:默认按钮.朴素按钮(plain).圆角按钮(round).圆形按钮(circle).eg: <el-button plain>朴素按钮</el-button& ...

  4. ref:PHP反序列化漏洞成因及漏洞挖掘技巧与案例

    ref:https://www.anquanke.com/post/id/84922 PHP反序列化漏洞成因及漏洞挖掘技巧与案例 一.序列化和反序列化 序列化和反序列化的目的是使得程序间传输对象会更加 ...

  5. Web后门工具WeBaCoo

    Web后门工具WeBaCoo   WeBaCoo是使用Perl语言编写的Web后门工具.渗透测试人员首先使用该工具生成一个后门PHP页面.然后,将该页面上传到目标服务器上.最后,在本地终端直接访问该页 ...

  6. javascript中Date对象的应用

    前面的话 简易日历作为javascript中Date对象的常见应用,用途较广泛.本文将详细说明简易日历的实现思路 效果演示 HTML说明 使用type=number的两个input分别作为年和月的输入 ...

  7. Cable master POJ - 1064

    Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Commi ...

  8. Python中的模块(2)

    1.内置模块2.扩展的 例如:django3.自定义的 文件import demodef read(): print('my read func')demo.read()print(demo.mone ...

  9. Codeforces 980 D. Perfect Groups

    \(>Codeforces\space980 D. Perfect Groups<\) 题目大意 : 设 \(F(S)\) 表示在集合\(S\)中把元素划分成若干组,使得每组内元素两两相乘 ...

  10. 【KM】BZOJ1937 [Shoi2004]Mst 最小生成树

    这道题拖了好久因为懒,结果1A了,惊讶∑( 口 || [题目大意] 给定一张n个顶点m条边的有权无向图.现要修改各边边权,使得给出n-1条边是这张图的最小生成树,代价为变化量的绝对值.求最小代价之和. ...