Skip to content

Commit

Permalink
Migrated to OffscreenCanvas 2D rendering context
Browse files Browse the repository at this point in the history
  • Loading branch information
GarrisonD committed Aug 29, 2020
1 parent ee18d04 commit 03fb2fb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/components/CanvasOnSteroids.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const GET_CONTEXT_2D_FAILED_MSG =
"Getting of 2D Context failed... May your browser not support it?..";

type CanvasOnSteroidsProps = {
onContextReady: (context: CanvasRenderingContext2D) => void;
onContextReady: (context: OffscreenCanvasRenderingContext2D) => void;
onWheel: Required<React.DOMAttributes<HTMLCanvasElement>>["onWheel"];
scale?: number;
// Keep these two props grouped:
Expand All @@ -25,7 +25,7 @@ const CanvasOnSteroids: React.FC<CanvasOnSteroidsProps> = ({
React.useLayoutEffect(() => {
const canvas = canvasRef.current!;

const context = canvas.getContext("2d", {
const context = canvas.transferControlToOffscreen().getContext("2d", {
alpha: false,
desynchronized: true,
});
Expand Down
4 changes: 2 additions & 2 deletions src/utils/canvas-drawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CanvasDrawer implements Drawer {
static readonly CONTEXT_2D_MISSING_MSG =
"2D Context is missing... I suppose you forget to call #prepare...";

private readonly context: CanvasRenderingContext2D;
private readonly context: OffscreenCanvasRenderingContext2D;

private readonly width: number;
private readonly height: number;
Expand All @@ -26,7 +26,7 @@ class CanvasDrawer implements Drawer {
lastVisibleCandleIndex = 0;

constructor(
context: CanvasRenderingContext2D,
context: OffscreenCanvasRenderingContext2D,
width: number,
height: number,
candlesticks: Candlestick[]
Expand Down

0 comments on commit 03fb2fb

Please sign in to comment.