惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
D
Docker
GbyAI
GbyAI
B
Blog RSS Feed
博客园 - 司徒正美
博客园 - Franky
美团技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
IT之家
IT之家
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
www.infosecurity-magazine.com
www.infosecurity-magazine.com
AI
AI
O
OpenAI News
Attack and Defense Labs
Attack and Defense Labs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
S
Secure Thoughts
博客园 - 聂微东
L
LINUX DO - 最新话题
U
Unit 42
SecWiki News
SecWiki News
A
Arctic Wolf
Schneier on Security
Schneier on Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Visual Studio Blog
量子位
The Cloudflare Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
G
Google Developers Blog
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
B
Blog
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
Last Week in AI
Last Week in AI
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Microsoft Security Blog
Microsoft Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
Latest news
Latest news

David Baron's Weblog

Software engineering, responsibility, and ownership Software engineering, responsibility, and ownership David Baron's weblog: Security and Inequality Running animations on the compositor thread David Baron's weblog: Tying ecosystems through browsers David Baron's weblog: Payments on the Web Thoughts on migrating to a secure Web David Baron's weblog: The need for government David Baron's weblog: Priority of constituencies How browser developers should seek feedback from Web developers A possible approach to shorter release cycles David Baron's weblog: Fifteen years Why debug builds (and assertions) are important Ten years of the Mozilla Foundation Open licensing at the W3C How you can help with removing -moz- prefixes Moving bug history out of the primary display of a bug report Beware of locale-specific behavior in the C library Eating dogfood and shipping software Specification style and the future of the Web The bug system I wish I had CSS border-image changes and unprefixing Improving font size readability on Firefox for Android David Baron's weblog: CSS Animations, part 2 Hue-preserving color inversion with SVG filters Changes to handling of @-moz-keyframes David Baron's weblog: window.matchMedia() David Baron's weblog: CSS Animations What does a blur radius mean? Crash analysis in the future David Baron's weblog: calc() David Baron's weblog: colorDepth David Baron's weblog: Hidden complexity in specifications The most important field in a bug report: the summary WOFF font format submitted to W3C David Baron's weblog: :-moz-any() selector grouping setTimeout with a shorter delay Faster repainting in SVG foreignObject David Baron's weblog: Distributed Extensibility David Baron's weblog: Broadening crash analysis Correlating crashes with binary extensions or plugins David Baron's weblog: ex-HTML Downloadable font formats for the Web Web Accessibility as a Political Movement David Baron's weblog: CSS priorities David Baron's weblog: Bug priorities David Baron's weblog: Semi-vacation Some new CSS features in Firefox 3 David Baron's weblog: New selectors David Baron's weblog: The age of bugs Seeking a good Linux distribution David Baron's weblog: Teaching to the test David Baron's weblog: March 2008 David Baron's weblog: February 2008 David Baron's weblog: January 2008 David Baron's weblog: October 2007 David Baron's weblog: September 2007 David Baron's weblog: August 2007 David Baron's weblog: June 2007 David Baron's weblog: April 2007 David Baron's weblog: March 2007 David Baron's weblog: January 2007 David Baron's weblog: September 2006 David Baron's weblog: August 2006 David Baron's weblog: July 2006 David Baron's weblog: May 2006 David Baron's weblog: February 2006 David Baron's weblog: January 2006 David Baron's weblog: December 2005 David Baron's weblog: October 2005 David Baron's weblog: September 2005 David Baron's weblog: June 2005 David Baron's weblog: May 2005 David Baron's weblog: April 2005 David Baron's weblog: March 2005 David Baron's weblog: February 2005 David Baron's weblog: October 2004 David Baron's weblog: September 2004 David Baron's weblog: August 2004 David Baron's weblog: June 2004 David Baron's weblog: May 2004 David Baron's weblog: April 2004 David Baron's weblog: March 2004 David Baron's weblog: February 2004 David Baron's weblog: January 2004 David Baron's weblog: November 2003 David Baron's weblog: October 2003 David Baron's weblog: September 2003 David Baron's weblog: August 2003 David Baron's weblog: July 2003 David Baron's weblog: June 2003 David Baron's weblog: May 2003 David Baron's weblog: April 2003 David Baron's weblog: March 2003 David Baron's weblog: February 2003 David Baron's weblog: January 2003 David Baron's weblog: December 2002 David Baron's weblog: November 2002 David Baron's weblog: September 2002
Why adding compositing and blending to CSS is harder than it looks
David Baron · 2013-03-07 · via David Baron's Weblog

The Compositing and Blending specification (25 February 2013 editor's draft, latest editor's draft, latest TR draft) proposes the addition of compositing and blending operations to CSS. This proposal adds considerable graphical power to CSS, and could be quite useful. But doing this correctly for a Web with multiple implementations requires some caution. Explaining why this is the case requires a bit of explanation.

Drawing operations in CSS today use source-over compositing with normal blending. This combination has the property that drawing is associative (but not commutative). In other words, when you have three layers, say, rgba(255, 0, 0, 0.6) on top of rgba(128, 128, 0, 0.4) on top of blue, you get the same result (maybe modulo tiny variation for rounding) no matter how the drawing operators are grouped:

(rgba(255, 0, 0, 0.6) over rgba(128, 128, 0, 0.4)) over rgba(0, 0, 255, 1.0)
simplifies to
rgba(227, 26, 0, 0.76) over rgba(0, 0, 255, 1.0)
which simplifies to
rgba(173, 20, 61, 1.0).
rgba(255, 0, 0, 0.6) over (rgba(128, 128, 0, 0.4) over rgba(0, 0, 255, 1.0))
simplifies to
rgba(255, 0, 0, 0.6) over rgba(51, 51, 153, 1.0)
which simplifies to
rgba(173, 20, 61, 1.0).

But this no longer works if we change to a non-default compositing or blending mode. For example, let's replace one of those source-over operations with a source-atop compositing operation, and see what happens with different ways of grouping the operations.

(rgba(255, 0, 0, 0.6) atop rgba(128, 128, 0, 0.4)) over rgba(0, 0, 255, 1.0)
simplifies to
rgba(205, 50, 0, 0.4) over rgba(0, 0, 255, 1.0)
which simplifies to
rgba(82, 20, 153, 1.0).
rgba(255, 0, 0, 0.6) atop (rgba(128, 128, 0, 0.4) over rgba(0, 0, 255, 1.0))
simplifies to
rgba(255, 0, 0, 0.6) atop rgba(51, 51, 153, 1.0)
which simplifies to
rgba(173, 20, 61, 1.0).

Now, CSS specifies the order of drawing operations very carefully. But this specification of order was never a specification of grouping, and implementations have found different ways to group the drawing operations. Many optimizations that authors depend on (for example, that currently-animating elements with a transform set have their own layer that's stored and recomposited on the GPU without any repainting of that layer or the one it's composited into) are optimizations that are based on changing the grouping of drawing operations. Different browsers group drawing operations in different ways. For the most part, drawing is grouped from back to front, but other grouping is forced by opacity (where the specification requires grouping), and in some other cases for performance optimizations (which differ across browsers). [ Wording of last sentence updated 15:30. ]

Furthermore, the way the order of drawing operations in CSS was specified was never intended to be a specification of grouping. The specification was written in certain ways for the convenience of the specification authors or readers, but that manner of specification was not designed to produce good or intuitive results in cases where the grouping of drawing operations is exposed.

In order to specify blending and compositing throughout CSS in a way that will be interoperable across browsers, the grouping in CSS must be specified as clearly and with as much precision as the ordering is. This means that everything in Appendix E of CSS 2.1, plus all the additions to it from newer CSS modules that have not been fully tracked, needs to specify not only the ordering of the drawing operations but also their grouping.

If non-default compositing and blending is limited strictly to elements that create stacking contexts, as I have proposed (which means removing background-composite and background-blend-mode), then the specification problem becomes substantially easier, in that we at least only need to specify and interoperably implement the grouping of those of the drawing operations that involve elements creating stacking contexts, which means, I think, that the grouping would only need to be specified between:

  1. Together, items (1) through (2) in the top level of Appendix E
  2. Each item in item (3) in the top level of Appendix E
  3. Together, items (4) through (7) in the top level of Appendix E
  4. Each item in item (8) in the top level of Appendix E
  5. Each item in item (9) in the top level of Appendix E
  6. Together, (10) in the top level of Appendix E

(Some might object to this on the basis of the priority of constituencies. I believe such an objection is trivial to rebut: we don't have infinite resources and can't develop all features instantaneously. So giving authors a good solution now is often more valuable than a perfect solution later—potentially much later, if getting this specification right drops down in priority.)

There's still another issue, though, which is that the results the spec specifies need to be implementable efficiently (in terms of both performance and memory use) across multiple implementations. That requires not just specifying the rules clearly, but discussing them with implementors who understand the full rendering pipeline of different Web browser engines.

If these issues with the compositing and blending specification are ignored, then we risk either ending up with implementations in different browsers that just match the internals of those browsers, or unnecessarily delaying implementation of these features (or their usability on the Web, across multiple browsers).