Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render()增加lv参数,标明本次渲染是repaint/reflow,布局缓存,渲染缓存 #87

Closed
army8735 opened this issue Aug 30, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@army8735
Copy link
Member

army8735 commented Aug 30, 2020

局部布局缓存,没有变化时无需重新布局。
在一个节点无需重新布局但因为外部/兄弟节点变化造成偏移时,特殊进行offset操作而不是重新布局。

渲染方面,一个节点无动画等变化时,根据复杂情况canvas离屏绘制缓存,再次刷新时刻直接利用drawImage离屏内容;
svg也是直接利用生成好的virtualDom,新的根据位置插入,对matrix/opacity/filter进行特殊优化,大部分动画是变化matrix,此时也不重新生成virtualDom,只改变transform值且只对比diff本transform即可。

@army8735 army8735 added the enhancement New feature or request label Aug 30, 2020
@army8735 army8735 self-assigned this Aug 30, 2020
@army8735 army8735 changed the title render()增加lv参数,标明本次渲染是repaint/reflow render()增加lv参数,标明本次渲染是repaint/reflow,布局缓存 Aug 30, 2020
@army8735 army8735 changed the title render()增加lv参数,标明本次渲染是repaint/reflow,布局缓存 render()增加lv参数,标明本次渲染是repaint/reflow,布局缓存,渲染缓存 Sep 6, 2020
@army8735
Copy link
Member Author

army8735 commented Sep 18, 2020

  • 除首次外每次刷新前检查reflow列表,计算需要reflow的节点局部重新布局
  • 当一个元素absolute时,其变化不会影响父元素和兄弟元素,直接自己重新局部LAYOUT包含子节点
  • 当text变化时,如果是reflow视为其parent变化
  • 当inline变化时,视为其最近block/flex父变化
  • 当block变化时,如父是flex往上查找最上层flex视为其变化,如不是则影响后面兄弟和父resize
  • 当flex变化时,如父是flex往上查找最上层flex视为其变化,如不是则影响所有递归子节点和父resize
  • 以上3种情况向上查找时遇到absolute父均提前跳出,并标记absolute父LAYOUT
  • 当relative只变化left/top/right/bottom时,自己重新layout
  • 检测节点时记录影响的所有节点,最终形成一棵或n棵局部树
  • 一般需要重新布局的记作LAYOUT,被兄弟影响只需偏移的记作OFFSET,OFFSET可能会重复变为LAYOUT
  • 上述情况倘若发生包含重复,去掉子树,因子树视为被包含的重新布局
  • 如果有从root开始的,直接重新布局像首次那样即可
  • 如果非root,所有树根按先根顺序记录下来,依次执行局部布局

@army8735
Copy link
Member Author

army8735 commented Sep 18, 2020

style/currentStyle/computedStyle上的属性以getter形式提供
updateStyle和animate事件中的callback同时提供Promise即async方式,参数除了第一个diff时间外增加第二个参数表明是否有效应用,被覆盖或销毁时为false。

低优先级

@army8735
Copy link
Member Author

army8735 commented Sep 21, 2020

updateStyle/animate覆盖currentStyle逻辑应该统一放到refresh前,因为会有重复甚至改变再还原,此时进行repaint等级计算,且isDestroy的不执行。

渲染位图缓存采用page内存分页碎片管理的方式,以某个尺寸为基准1,如8px * 8px,一个dom的内容尺寸都视作这个方块大小,页按8 * 8个单位算,这样一页最多可以存放8 * 8=64个单位尺寸图片。低于1的按1计算。
尺寸往上按倍数增加,基准2的用一种页,单位是16px * 16px,(8, 16]的都在这个范围。
以此类推。
特别大的图根据上限不再分页缓存。

不同浏览器对于canvas尺寸有限制,目前主流都在4096 * 4096以上,按此为最大。因此常规单位尺寸最大为512。
8、 16、 32、64、128、256、512,会有这些等级。小的其实可以增大画布尺寸提升数量,但不利于循环查找,在更好的算法找到前锁死数量。
如果页单位数量缩小到4 * 4,则放宽到1024px * 1024px,存16个。
页单位数量缩小到2 * 2,则放宽到2048px * 2048px,存4个。
页单位数量缩小到1 * 1,则放宽到4096px * 4096px,存1个。

pc比较大,mobile会小点。pc中ie垫底8192,mobile中iphone6垫底4096。
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas

@army8735
Copy link
Member Author

army8735 commented Sep 23, 2020

对path绘制的大概测试,对比drawImage缓存。当5个lineTo时和位图缓存大约持平,当3个lineTo+1个曲线时大约持平。
因此lineTo记1分,贝塞尔曲线记2分,总分>5分时可认为矢量绘制时间超过位图缓存。

为了dom缓存孩子节点,孩子不能直接绘制在主canvas上,因此无分数概念只要有内容就缓存

army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 24, 2020
army8735 added a commit that referenced this issue Sep 25, 2020
army8735 added a commit that referenced this issue Sep 25, 2020
army8735 added a commit that referenced this issue Oct 14, 2020
army8735 added a commit that referenced this issue Oct 15, 2020
army8735 added a commit that referenced this issue Oct 16, 2020
army8735 added a commit that referenced this issue Oct 16, 2020
army8735 added a commit that referenced this issue Oct 16, 2020
army8735 added a commit that referenced this issue Oct 16, 2020
army8735 added a commit that referenced this issue Oct 17, 2020
army8735 added a commit that referenced this issue Oct 18, 2020
army8735 added a commit that referenced this issue Oct 18, 2020
army8735 added a commit that referenced this issue Oct 19, 2020
army8735 added a commit that referenced this issue Oct 19, 2020
army8735 added a commit that referenced this issue Oct 19, 2020
army8735 added a commit that referenced this issue Oct 19, 2020
army8735 added a commit that referenced this issue Oct 19, 2020
army8735 added a commit that referenced this issue Oct 19, 2020
army8735 added a commit that referenced this issue Oct 19, 2020
army8735 added a commit that referenced this issue Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant