View Canvas 硬件加速画图限制

不支持的绘制操作

当启用了硬件加速后,2D渲染管线支持大部分的canvas的常用绘制操作和一些不常用的操作,分别列举一下,其实我们也只有在自定义View的时候才担心canvas调用的函数会不会不支持硬件加速,所以我们只需要真正用到的时候查阅一下即可。

今天的主角

Canvas Scaling

The hardware accelerated 2D rendering pipeline was built first to support unscaled drawing, with some drawing operations degrading quality significantly at higher scale values. These operations are implemented as textures drawn at scale 1.0, transformed by the GPU. In API level <17, using these operations will result in scaling artifacts increasing with scale.

The following table shows when implementation was changed to correctly handle large scales:

Note: ‘Simple’ shapes aredrawRect(),drawCircle(),drawOval(),drawRoundRect(), anddrawArc()(with useCenter=false) commands issued with a Paint that doesn’t have a PathEffect, and doesn’t contain non-default joins (viasetStrokeJoin()/setStrokeMiter()). Other instances of those draw commands fall under ‘Complex,’ in the above chart.

If your application is affected by any of these missing features or limitations, you can turn off hardware acceleration for just the affected portion of your application by callingsetLayerType(View.LAYER_TYPE_SOFTWARE, null). This way, you can still take advantage of hardware acceleration everywhere else. SeeControlling Hardware Accelerationfor more information on how to enable and disable hardware acceleration at different levels in your application.

作者:黑白咖
链接:http://www.jianshu.com/p/9cd7097a4fcf
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。