Giter VIP home page Giter VIP logo

offscreen_canvas_demo's Introduction

Offscreen Canvas Demo

Transfer Demo

  1. Main thread lanuch worker thread, then ask initialize;
  2. Worker create OffscreenCanvas;
  3. Worker get WebGL Context of OffscreenCanvas and render;
  4. Worker get the buffer of OffscreenCanvas (ImageBitmap), and transfer back to main thread;
  5. Main thread receive the buffer and 'draw' it to two different Canvas, One Canvas use CanvasRenderingContext2D,other use ImageBitmapRenderingContext;
  6. Repeat 3 ~ 5;

Commit Demo

  1. Main thread get Canvas from current DOM and generate an OffscreenCanvas from that Canvas;
  2. Main thread launch worker thread, then ask initialize, transfer OffscreenCanvas as parameter;
  3. Worker receive OffscreenCanvas and initialize;
  4. Worker get WebGL Context of OffscreenCanvas and render;
  5. Worker commit when render complete, and wait the callback;
  6. Worker receive callback then repeat 4 ~ 6;

Transfer Demo

  1. 主线程启动 Worker 线程,并请求初始化;
  2. Worker 线程创建 OffscreenCanvas;
  3. Worker 线程获取 OffscreenCanvas 的 WebGL Context 并进行绘制;
  4. Worker 线程获取 OffscreenCanvas 的缓冲区(ImageBitmap),然后 Transfer 回主线程;
  5. 主线程将 Worker 线程回传的缓冲区分别绘制在两个不同的 Canvas 上,一个 Canvas 使用 CanvasRenderingContext2D,一个 Canvas 使用 ImageBitmapRenderingContext;
  6. 3 ~ 5 重复运行;

Commit Demo

  1. 主线程从当前 DOM 树中的 Canvas 元素生成 OffscreenCanvas;
  2. 主线程启动 Worker 线程并初始化,OffscreenCanvas 作为初始化的参数被 Transfer;
  3. Worker 线程接收 OffscreenCanvas 后完成初始化;
  4. Worker 线程使用 WebGL 对 OffscreenCanvas 进行绘制;
  5. Worker 线程绘制完成后 Commit,然后等待浏览器的回调;
  6. Worker 线程接收到到浏览器的回调后继续绘制下一帧,重复 4 ~ 6;

offscreen_canvas_demo's People

Contributors

rogeryi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.