Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/skia/src/renderer/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
ViewProps,
} from "react-native";
import { type SharedValue } from "react-native-reanimated";
import type { WebGLOptions } from "canvaskit-wasm";

import { SkiaViewNativeId } from "../views/SkiaViewNativeId";
import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeComponent";
Expand Down Expand Up @@ -56,6 +57,13 @@ export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
onSize?: SharedValue<SkSize>;
colorSpace?: "p3" | "srgb";
ref?: React.Ref<CanvasRef>;
/**
* WebGL context attributes for web platform.
* Allows configuration of the WebGL rendering context.
* Only applicable when running on web platform.
* Uses CanvasKit's WebGLOptions type directly - all values must be numeric (0 or 1 for boolean flags).
*/
webglContextAttributes?: WebGLOptions;
}

export const Canvas = ({
Expand Down
4 changes: 4 additions & 0 deletions packages/skia/src/specs/SkiaPictureViewNativeComponent.web.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import type { ViewProps } from "react-native";
import { createElement } from "react";
import type { WebGLOptions } from "canvaskit-wasm";

import { SkiaPictureView } from "../views/SkiaPictureView.web";

export interface NativeProps extends ViewProps {
debug?: boolean;
opaque?: boolean;
nativeID: string;
webglContextAttributes?: WebGLOptions;
}

const SkiaPictureViewNativeComponent = ({
nativeID,
debug,
opaque,
onLayout,
webglContextAttributes,
...viewProps
}: NativeProps) => {
return createElement(SkiaPictureView, {
nativeID,
debug,
opaque,
onLayout,
webglContextAttributes,
...viewProps,
});
};
Expand Down
7 changes: 6 additions & 1 deletion packages/skia/src/views/SkiaBaseWebView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ export abstract class SkiaBaseWebView<
this.height = canvas.clientHeight;
canvas.width = this.width * pd;
canvas.height = this.height * pd;
const surface = CanvasKit.MakeWebGLCanvasSurface(canvas);

const surface = CanvasKit.MakeWebGLCanvasSurface(
canvas,
undefined, // colorSpace - using undefined to maintain default
this.props.webglContextAttributes // undefined if not explicitly provided
);
const ctx = canvas.getContext("webgl2");
if (ctx) {
ctx.drawingBufferColorSpace = "display-p3";
Expand Down
9 changes: 9 additions & 0 deletions packages/skia/src/views/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ViewProps } from "react-native";
import type { SharedValue } from "react-native-reanimated";
import type { WebGLOptions } from "canvaskit-wasm";

import type { Node } from "../dom/types";
import type { SkImage, SkPicture, SkRect, SkSize } from "../skia/types";
Expand Down Expand Up @@ -31,6 +32,14 @@ export interface SkiaBaseViewProps extends ViewProps {
onSize?: SharedValue<SkSize>;

opaque?: boolean;

/**
* WebGL context attributes for web platform.
* Allows configuration of the WebGL rendering context.
* Only applicable when running on web platform.
* Uses CanvasKit's WebGLOptions type directly - all values must be numeric (0 or 1 for boolean flags).
*/
webglContextAttributes?: WebGLOptions;
}

export interface SkiaPictureViewNativeProps extends SkiaBaseViewProps {
Expand Down
Loading