antvis / G

💥 A flexible rendering engine for visualization.
https://g.antv.antgroup.com/
1.07k stars 199 forks source link

Image Shape 渲染开销问题 #1248

Closed songhn233 closed 1 year ago

songhn233 commented 1 year ago

What problem does this feature solve?

在 5.0 文档中看到图片的 https://g.antv.antgroup.com/examples/perf/basic#images

API 支持 url、ImageData、和 Canvas,但是看例子似乎都是直接通过 url image node 进行渲染

What does the proposed API look like?

好奇不同的来源对渲染性能会不会有区别,我理解如果有现成的 ImageData 或者 Canvas 那么就可以利用类似双缓存的机制,减少渲染的链路。不知道实际情况是怎么样的

songhn233 commented 1 year ago

写了个 ImageData 的 Demo 但是好像渲染有问题 https://codesandbox.io/s/romantic-nobel-i9sh2f?file=/index.js

xiaoiver commented 1 year ago

我实现了一个 demo,可以直接传入 HTMLCanvasElement,这样就没必要调用 getImageData() 获取 ImageData 再创建 Image 了: https://codesandbox.io/s/relaxed-knuth-e6s2z4?file=/index.js

const image = new GImage({
  style: {
    x: 200,
    y: 100,
    width: 200,
    height: 200,
    src: ctx.canvas
  }
});