html5 globalalpha,alpha - HTML5 canvas performance between strokeStyle rgba/globalAlpha - Stack Over...

这篇博客探讨了浏览器中复合与混合过程如何影响性能,特别是全局Alpha值和背景Alpha设置。内容指出,不同混合模式可能会影响性能,而关闭背景Alpha可以提升性能。所有浏览器使用Porter-Duff复合运算符,公式对于任何Alpha值都是相同的,因此性能差异不大。此外,提到了一个不常见的2D上下文选项参数,即关闭背景Alpha,该选项在某些浏览器中可以提高效率。

No, at least not any noticeable. The blending and compositing process is the same no matter what value you use for global alpha (assuming resulting backdrop alpha never is 1).

What can affect the performance is which blending mode (except lighter aka plus, as this is a composite operation) you choose (blending modes, separable and non-separable such as screen, overlay, color, hue etc. is also set via the globalCompositeOperation), as well as turning off background alpha (see below).

All browsers uses what is called Porter Duff Compositing Operators. This uses the same formula for all compositing types:

co = αs x Fa x Cs + αb x Fb x Cb

or:

color out = alpha source x Fa x Color Source +

alpha background (or destination) x Fb x Color Background

Fa/b varies depending on which operator is used, for example for source-over they would be: Fa = 1; Fb = 1 – αs.

Then the result is "mixed" back on the canvas using global alpha (Cb = containing backdrop alpha).

Cr = (1 - αb) x Cs + αb x B(Cb, Cs) // B() = Blending mode

So no matter value you use for alpha, the pixels are run through the same formulas giving no performance difference (these formulas are usually combined into a single step; for blending only intersecting areas are considered).

In theory, if backdrop alpha was 1 this last mixing stage wouldn't be needed, but as you are using alpha other than 1 for either color or globalAlpha it will need to be "mixed".

There are however a lesser known option parameter for 2D context (CanvasRenderingContext2DSettings, see green box below the interface definition):

var context = canvas.getContext("2D", {alpha: false});

Turning off background alpha can speed up performance quite a bit if you don't need the canvas background to be non-opaque.

It has been supported by old Opera a while, Chrome (or was it FF... can't remember) just recently started to support it and FF (or Chrome)/IE will support it later (it will just be ignored if not supported so there's no harm providing it).

For more details on browser implementation of compositing/blending, see this link.

Hope this gives some input (disclaimer: it's late and head not quite up to long formulas so I'll double-check tomorrow).

源码来自:https://pan.quark.cn/s/a3a3fbe70177 AppBrowser(Application属性查看器,不需要越狱! ! ! ) 不需要越狱,调用私有方法 --- 获取完整的已安装应用列表、打开和删除应用操作、应用运行时相关信息的查看。 支持iOS10.X 注意 目前AppBrowser不支持iOS11应用查看, 由于iOS11目前还处在Beta版, 系统API还没有稳定下来。 等到Private Header更新了iOS11版本,我也会进行更新。 功能 [x] 已安装的应用列表 [x] 应用的详情界面 (打开应用,删除应用,应用的相关信息展示) [x] 应用运行时信息展示(LSApplicationProxy) [ ] 定制喜欢的字段,展示在应用详情界面 介绍 所有已安装应用列表(应用icon+应用名) 为了提供思路,这里只用伪代码,具体的私有代码调用请查看: 获取应用实例: 获取应用名和应用的icon: 应用列表界面展示: 应用列表 应用运行时详情 打开应用: 卸载应用: 获取info.plist文件: 应用运行时详情界面展示: 应用运行时详情 右上角,从左往右第一个按钮用来打开应用;第二个按钮用来卸载这个应用 INFO按钮用来解析并显示出对应的LSApplicationProxy类 树形展示LSApplicationProxy类 通过算法,将LSApplicationProxy类,转换成了字典。 转换规则是:属性名为key,属性值为value,如果value是一个可解析的类(除了NSString,NSNumber...等等)或者是个数组或字典,则继续递归解析。 并且会找到superClass的属性并解析,superClass如...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值