skia
    Preparing search index...

    Interface Surface

    CanvasKit is built with Emscripten and Embind. Embind adds the following methods to all objects that are exposed with it. This _type field is necessary for the TypeScript compiler to differentiate between opaque types such as Shader and ColorFilter. It doesn't exist at runtime.

    interface Surface {
        _type: "Surface";
        delete(): void;
        deleteLater(): void;
        dispose(): void;
        drawOnce(drawFrame: (_: Canvas) => void): void;
        flush(): void;
        getCanvas(): Canvas;
        height(): number;
        imageInfo(): ImageInfo;
        isAliasOf(other: any): boolean;
        isDeleted(): boolean;
        makeImageFromTexture(tex: WebGLTexture, info: ImageInfo): Image | null;
        makeImageFromTextureSource(
            src: TextureSource,
            info?: ImageInfo | PartialImageInfo,
            srcIsPremul?: boolean,
        ): Image | null;
        makeImageSnapshot(bounds?: InputIRect): Image;
        makeSurface(info: ImageInfo): Surface;
        reportBackendTypeIsGPU(): boolean;
        requestAnimationFrame(drawFrame: (_: Canvas) => void): number;
        sampleCnt(): number;
        updateTextureFromSource(
            img: Image,
            src: TextureSource,
            srcIsPremul?: boolean,
        ): void;
        width(): number;
    }

    Hierarchy (View Summary)

    Index

    Properties

    _type: "Surface"

    Methods

    • Clean up the surface and any extra memory. [Deprecated]: In the future, calls to delete() will be sufficient to clean up the memory.

      Returns void

    • A convenient way to draw exactly once on the canvas associated with this surface. This requires an environment where a global function called requestAnimationFrame is available (e.g. on the web, not on Node). Users do not need to flush the surface, or delete/dispose of it as that is taken care of automatically with this wrapper.

      Node users should call getCanvas() and work with that canvas directly.

      Parameters

      • drawFrame: (_: Canvas) => void

      Returns void

    • Make sure any queued draws are sent to the screen or the GPU.

      Returns void

    • Return a canvas that is backed by this surface. Any draws to the canvas will (eventually) show up on the surface. The returned canvas is owned by the surface and does NOT need to be cleaned up by the client.

      Returns Canvas

    • Returns the height of this surface in pixels.

      Returns number

    • Creates an Image from the provided texture and info. The Image will own the texture; when the image is deleted, the texture will be cleaned up.

      Parameters

      • tex: WebGLTexture
      • info: ImageInfo

        describes the content of the texture.

      Returns Image | null

    • Returns a texture-backed image based on the content in src. It uses RGBA_8888, unpremul and SRGB - for more control, use makeImageFromTexture.

      The underlying texture for this image will be created immediately from src, so it can be disposed of after this call. This image will only be usable for this surface (because WebGL textures are not transferable to other WebGL contexts). For an image that can be used across multiple surfaces, at the cost of being lazily loaded, see MakeLazyImageFromTextureSource.

      Not available for software-backed surfaces.

      Parameters

      • src: TextureSource
      • Optionalinfo: ImageInfo | PartialImageInfo

        If provided, will be used to determine the width/height/format of the source image. If not, sensible defaults will be used.

      • OptionalsrcIsPremul: boolean

        set to true if the src data has premultiplied alpha. Otherwise, it will be assumed to be Unpremultiplied. Note: if this is true and info specifies Unpremul, Skia will not convert the src pixels first.

      Returns Image | null

    • Returns current contents of the surface as an Image. This image will be optimized to be drawn to another surface of the same type. For example, if this surface is backed by the GPU, the returned Image will be backed by a GPU texture.

      Parameters

      Returns Image

    • Returns a compatible Surface, haring the same raster or GPU properties of the original. The pixels are not shared.

      Parameters

      • info: ImageInfo

        width, height, etc of the Surface.

      Returns Surface

    • Returns if this Surface is a GPU-backed surface or not.

      Returns boolean

    • A convenient way to draw multiple frames on the canvas associated with this surface. This requires an environment where a global function called requestAnimationFrame is available (e.g. on the web, not on Node). Users do not need to flush the surface, as that is taken care of automatically with this wrapper.

      Users should probably call surface.requestAnimationFrame in the callback function to draw multiple frames, e.g. of an animation.

      Node users should call getCanvas() and work with that canvas directly.

      Returns the animation id.

      Parameters

      • drawFrame: (_: Canvas) => void

      Returns number

    • If this surface is GPU-backed, return the sample count of the surface.

      Returns number

    • Updates the underlying GPU texture of the image to be the contents of the provided TextureSource. Has no effect on CPU backend or if img was not created with either makeImageFromTextureSource or makeImageFromTexture. If the provided TextureSource is of different dimensions than the Image, the contents will be deformed (e.g. squished). The ColorType, AlphaType, and ColorSpace of src should match the original settings used to create the Image or it may draw strange.

      Parameters

      • img: Image

        A texture-backed Image.

      • src: TextureSource

        A valid texture source of any dimensions.

      • OptionalsrcIsPremul: boolean

        set to true if the src data has premultiplied alpha. Otherwise, it will be assumed to be Unpremultiplied. Note: if this is true and the image was created with Unpremul, Skia will not convert.

      Returns void

    • Returns the width of this surface in pixels.

      Returns number