Copy as Markdown

Other Tools

/* THIS FILE IS AUTOGENERATED FROM OffscreenCanvas.webidl BY Codegen.py - DO NOT EDIT */
#ifndef DOM_OFFSCREENCANVASBINDING_H_
#define DOM_OFFSCREENCANVASBINDING_H_
#include "js/CallAndConstruct.h"
#include "js/RootingAPI.h"
#include "js/TypeDecls.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/EnumTypeTraits.h"
#include "mozilla/Span.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/FakeString.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/PrototypeList.h"
#include "mozilla/dom/UnionMember.h"
namespace mozilla {
class ClientWebGLContext;
namespace dom {
class ImageBitmapRenderingContext;
struct ImageEncodeOptionsAtoms;
struct NativePropertyHooks;
class OffscreenCanvas;
class OffscreenCanvasRenderingContext2D;
class OwningOffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext;
class ProtoAndIfaceCache;
} // namespace dom
namespace webgpu {
class CanvasContext;
} // namespace webgpu
} // namespace mozilla
namespace mozilla {
namespace dom {
enum class OffscreenRenderingContextId : uint8_t {
_2d,
Bitmaprenderer,
Webgl,
Webgl2,
Webgpu,
};
namespace binding_detail {
template <> struct EnumStrings<OffscreenRenderingContextId> {
static constexpr nsLiteralCString Values[5] {
"2d"_ns,
"bitmaprenderer"_ns,
"webgl"_ns,
"webgl2"_ns,
"webgpu"_ns,
};
};
} // namespace binding_detail
bool
ToJSValue(JSContext* aCx, OffscreenRenderingContextId aArgument, JS::MutableHandle<JS::Value> aValue);
void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningOffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext& aUnion, const char* aName, uint32_t aFlags = 0);
void
ImplCycleCollectionUnlink(OwningOffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext& aUnion);
struct ImageEncodeOptions : public DictionaryBase
{
MOZ_INIT_OUTSIDE_CTOR Optional<double> mQuality;
MOZ_INIT_OUTSIDE_CTOR nsString mType;
ImageEncodeOptions();
explicit inline ImageEncodeOptions(const FastDictionaryInitializer& )
{
// Do nothing here; this is used by our "Fast" subclass
}
ImageEncodeOptions(ImageEncodeOptions&& aOther) = default;
explicit inline ImageEncodeOptions(const ImageEncodeOptions& aOther)
{
*this = aOther;
}
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> val, const char* sourceDescription = "Value", bool passedToJSImpl = false);
void
TraceDictionary(JSTracer* trc);
ImageEncodeOptions&
operator=(const ImageEncodeOptions& aOther);
private:
static bool
InitIds(JSContext* cx, ImageEncodeOptionsAtoms* atomsCache);
};
namespace binding_detail {
struct FastImageEncodeOptions : public ImageEncodeOptions
{
inline FastImageEncodeOptions()
: ImageEncodeOptions(FastDictionaryInitializer())
{
// Doesn't matter what int we pass to the parent constructor
}
};
} // namespace binding_detail
class OffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext : public AllUnionBase
{
enum TypeOrUninit
{
eUninitialized,
eOffscreenCanvasRenderingContext2D,
eImageBitmapRenderingContext,
eWebGLRenderingContext,
eWebGL2RenderingContext,
eGPUCanvasContext
};
public:
enum class Type
{
eOffscreenCanvasRenderingContext2D = TypeOrUninit::eOffscreenCanvasRenderingContext2D,
eImageBitmapRenderingContext = TypeOrUninit::eImageBitmapRenderingContext,
eWebGLRenderingContext = TypeOrUninit::eWebGLRenderingContext,
eWebGL2RenderingContext = TypeOrUninit::eWebGL2RenderingContext,
eGPUCanvasContext = TypeOrUninit::eGPUCanvasContext
};
private:
union Value
{
UnionMember<NonNull<mozilla::dom::OffscreenCanvasRenderingContext2D> > mOffscreenCanvasRenderingContext2D;
UnionMember<NonNull<mozilla::dom::ImageBitmapRenderingContext> > mImageBitmapRenderingContext;
UnionMember<NonNull<mozilla::ClientWebGLContext> > mWebGLRenderingContext;
UnionMember<NonNull<mozilla::ClientWebGLContext> > mWebGL2RenderingContext;
UnionMember<NonNull<mozilla::webgpu::CanvasContext> > mGPUCanvasContext;
};
TypeOrUninit mType;
Value mValue;
OffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext(const OffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext&) = delete;
OffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext& operator=(const OffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext&) = delete;
public:
explicit inline OffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext()
: mType(eUninitialized)
{
}
inline ~OffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext()
{
Uninit();
}
[[nodiscard]] inline NonNull<mozilla::dom::OffscreenCanvasRenderingContext2D>&
RawSetAsOffscreenCanvasRenderingContext2D()
{
if (mType == eOffscreenCanvasRenderingContext2D) {
return mValue.mOffscreenCanvasRenderingContext2D.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eOffscreenCanvasRenderingContext2D;
return mValue.mOffscreenCanvasRenderingContext2D.SetValue();
}
[[nodiscard]] inline NonNull<mozilla::dom::OffscreenCanvasRenderingContext2D>&
SetAsOffscreenCanvasRenderingContext2D()
{
if (mType == eOffscreenCanvasRenderingContext2D) {
return mValue.mOffscreenCanvasRenderingContext2D.Value();
}
Uninit();
mType = eOffscreenCanvasRenderingContext2D;
return mValue.mOffscreenCanvasRenderingContext2D.SetValue();
}
inline bool
IsOffscreenCanvasRenderingContext2D() const
{
return mType == eOffscreenCanvasRenderingContext2D;
}
inline NonNull<mozilla::dom::OffscreenCanvasRenderingContext2D>&
GetAsOffscreenCanvasRenderingContext2D()
{
MOZ_RELEASE_ASSERT(IsOffscreenCanvasRenderingContext2D(), "Wrong type!");
return mValue.mOffscreenCanvasRenderingContext2D.Value();
}
inline mozilla::dom::OffscreenCanvasRenderingContext2D&
GetAsOffscreenCanvasRenderingContext2D() const
{
MOZ_RELEASE_ASSERT(IsOffscreenCanvasRenderingContext2D(), "Wrong type!");
return mValue.mOffscreenCanvasRenderingContext2D.Value();
}
[[nodiscard]] inline NonNull<mozilla::dom::ImageBitmapRenderingContext>&
RawSetAsImageBitmapRenderingContext()
{
if (mType == eImageBitmapRenderingContext) {
return mValue.mImageBitmapRenderingContext.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eImageBitmapRenderingContext;
return mValue.mImageBitmapRenderingContext.SetValue();
}
[[nodiscard]] inline NonNull<mozilla::dom::ImageBitmapRenderingContext>&
SetAsImageBitmapRenderingContext()
{
if (mType == eImageBitmapRenderingContext) {
return mValue.mImageBitmapRenderingContext.Value();
}
Uninit();
mType = eImageBitmapRenderingContext;
return mValue.mImageBitmapRenderingContext.SetValue();
}
inline bool
IsImageBitmapRenderingContext() const
{
return mType == eImageBitmapRenderingContext;
}
inline NonNull<mozilla::dom::ImageBitmapRenderingContext>&
GetAsImageBitmapRenderingContext()
{
MOZ_RELEASE_ASSERT(IsImageBitmapRenderingContext(), "Wrong type!");
return mValue.mImageBitmapRenderingContext.Value();
}
inline mozilla::dom::ImageBitmapRenderingContext&
GetAsImageBitmapRenderingContext() const
{
MOZ_RELEASE_ASSERT(IsImageBitmapRenderingContext(), "Wrong type!");
return mValue.mImageBitmapRenderingContext.Value();
}
[[nodiscard]] inline NonNull<mozilla::ClientWebGLContext>&
RawSetAsWebGLRenderingContext()
{
if (mType == eWebGLRenderingContext) {
return mValue.mWebGLRenderingContext.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eWebGLRenderingContext;
return mValue.mWebGLRenderingContext.SetValue();
}
[[nodiscard]] inline NonNull<mozilla::ClientWebGLContext>&
SetAsWebGLRenderingContext()
{
if (mType == eWebGLRenderingContext) {
return mValue.mWebGLRenderingContext.Value();
}
Uninit();
mType = eWebGLRenderingContext;
return mValue.mWebGLRenderingContext.SetValue();
}
inline bool
IsWebGLRenderingContext() const
{
return mType == eWebGLRenderingContext;
}
inline NonNull<mozilla::ClientWebGLContext>&
GetAsWebGLRenderingContext()
{
MOZ_RELEASE_ASSERT(IsWebGLRenderingContext(), "Wrong type!");
return mValue.mWebGLRenderingContext.Value();
}
inline mozilla::ClientWebGLContext&
GetAsWebGLRenderingContext() const
{
MOZ_RELEASE_ASSERT(IsWebGLRenderingContext(), "Wrong type!");
return mValue.mWebGLRenderingContext.Value();
}
[[nodiscard]] inline NonNull<mozilla::ClientWebGLContext>&
RawSetAsWebGL2RenderingContext()
{
if (mType == eWebGL2RenderingContext) {
return mValue.mWebGL2RenderingContext.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eWebGL2RenderingContext;
return mValue.mWebGL2RenderingContext.SetValue();
}
[[nodiscard]] inline NonNull<mozilla::ClientWebGLContext>&
SetAsWebGL2RenderingContext()
{
if (mType == eWebGL2RenderingContext) {
return mValue.mWebGL2RenderingContext.Value();
}
Uninit();
mType = eWebGL2RenderingContext;
return mValue.mWebGL2RenderingContext.SetValue();
}
inline bool
IsWebGL2RenderingContext() const
{
return mType == eWebGL2RenderingContext;
}
inline NonNull<mozilla::ClientWebGLContext>&
GetAsWebGL2RenderingContext()
{
MOZ_RELEASE_ASSERT(IsWebGL2RenderingContext(), "Wrong type!");
return mValue.mWebGL2RenderingContext.Value();
}
inline mozilla::ClientWebGLContext&
GetAsWebGL2RenderingContext() const
{
MOZ_RELEASE_ASSERT(IsWebGL2RenderingContext(), "Wrong type!");
return mValue.mWebGL2RenderingContext.Value();
}
[[nodiscard]] inline NonNull<mozilla::webgpu::CanvasContext>&
RawSetAsGPUCanvasContext()
{
if (mType == eGPUCanvasContext) {
return mValue.mGPUCanvasContext.Value();
}
MOZ_ASSERT(mType == eUninitialized);
mType = eGPUCanvasContext;
return mValue.mGPUCanvasContext.SetValue();
}
[[nodiscard]] inline NonNull<mozilla::webgpu::CanvasContext>&
SetAsGPUCanvasContext()
{
if (mType == eGPUCanvasContext) {
return mValue.mGPUCanvasContext.Value();
}
Uninit();
mType = eGPUCanvasContext;
return mValue.mGPUCanvasContext.SetValue();
}
inline bool
IsGPUCanvasContext() const
{
return mType == eGPUCanvasContext;
}
inline NonNull<mozilla::webgpu::CanvasContext>&
GetAsGPUCanvasContext()
{
MOZ_RELEASE_ASSERT(IsGPUCanvasContext(), "Wrong type!");
return mValue.mGPUCanvasContext.Value();
}
inline mozilla::webgpu::CanvasContext&
GetAsGPUCanvasContext() const
{
MOZ_RELEASE_ASSERT(IsGPUCanvasContext(), "Wrong type!");
return mValue.mGPUCanvasContext.Value();
}
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription = "Value", bool passedToJSImpl = false);
inline void
Uninit()
{
switch (mType) {
case eUninitialized: {
break;
}
case eOffscreenCanvasRenderingContext2D: {
DestroyOffscreenCanvasRenderingContext2D();
break;
}
case eImageBitmapRenderingContext: {
DestroyImageBitmapRenderingContext();
break;
}
case eWebGLRenderingContext: {
DestroyWebGLRenderingContext();
break;
}
case eWebGL2RenderingContext: {
DestroyWebGL2RenderingContext();
break;
}
case eGPUCanvasContext: {
DestroyGPUCanvasContext();
break;
}
}
}
bool
ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;
private:
bool
TrySetToOffscreenCanvasRenderingContext2D(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToOffscreenCanvasRenderingContext2D(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
inline void
DestroyOffscreenCanvasRenderingContext2D()
{
MOZ_RELEASE_ASSERT(IsOffscreenCanvasRenderingContext2D(), "Wrong type!");
mValue.mOffscreenCanvasRenderingContext2D.Destroy();
mType = eUninitialized;
}
bool
TrySetToImageBitmapRenderingContext(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToImageBitmapRenderingContext(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
inline void
DestroyImageBitmapRenderingContext()
{
MOZ_RELEASE_ASSERT(IsImageBitmapRenderingContext(), "Wrong type!");
mValue.mImageBitmapRenderingContext.Destroy();
mType = eUninitialized;
}
bool
TrySetToWebGLRenderingContext(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToWebGLRenderingContext(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
inline void
DestroyWebGLRenderingContext()
{
MOZ_RELEASE_ASSERT(IsWebGLRenderingContext(), "Wrong type!");
mValue.mWebGLRenderingContext.Destroy();
mType = eUninitialized;
}
bool
TrySetToWebGL2RenderingContext(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToWebGL2RenderingContext(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
inline void
DestroyWebGL2RenderingContext()
{
MOZ_RELEASE_ASSERT(IsWebGL2RenderingContext(), "Wrong type!");
mValue.mWebGL2RenderingContext.Destroy();
mType = eUninitialized;
}
bool
TrySetToGPUCanvasContext(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToGPUCanvasContext(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
inline void
DestroyGPUCanvasContext()
{
MOZ_RELEASE_ASSERT(IsGPUCanvasContext(), "Wrong type!");
mValue.mGPUCanvasContext.Destroy();
mType = eUninitialized;
}
};
class OwningOffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext : public AllOwningUnionBase
{
friend void ImplCycleCollectionUnlink(OwningOffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext& aUnion);
enum TypeOrUninit
{
eUninitialized,
eOffscreenCanvasRenderingContext2D,
eImageBitmapRenderingContext,
eWebGLRenderingContext,
eWebGL2RenderingContext,
eGPUCanvasContext
};
public:
enum class Type
{
eOffscreenCanvasRenderingContext2D = TypeOrUninit::eOffscreenCanvasRenderingContext2D,
eImageBitmapRenderingContext = TypeOrUninit::eImageBitmapRenderingContext,
eWebGLRenderingContext = TypeOrUninit::eWebGLRenderingContext,
eWebGL2RenderingContext = TypeOrUninit::eWebGL2RenderingContext,
eGPUCanvasContext = TypeOrUninit::eGPUCanvasContext
};
private:
union Value
{
UnionMember<OwningNonNull<mozilla::dom::OffscreenCanvasRenderingContext2D> > mOffscreenCanvasRenderingContext2D;
UnionMember<OwningNonNull<mozilla::dom::ImageBitmapRenderingContext> > mImageBitmapRenderingContext;
UnionMember<OwningNonNull<mozilla::ClientWebGLContext> > mWebGLRenderingContext;
UnionMember<OwningNonNull<mozilla::ClientWebGLContext> > mWebGL2RenderingContext;
UnionMember<OwningNonNull<mozilla::webgpu::CanvasContext> > mGPUCanvasContext;
};
TypeOrUninit mType;
Value mValue;
public:
explicit inline OwningOffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext()
: mType(eUninitialized)
{
}
OwningOffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext(OwningOffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext&& aOther);
explicit inline OwningOffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext(const OwningOffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext& aOther)
: mType(eUninitialized)
{
*this = aOther;
}
inline ~OwningOffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext()
{
Uninit();
}
[[nodiscard]] OwningNonNull<mozilla::dom::OffscreenCanvasRenderingContext2D>&
RawSetAsOffscreenCanvasRenderingContext2D();
[[nodiscard]] OwningNonNull<mozilla::dom::OffscreenCanvasRenderingContext2D>&
SetAsOffscreenCanvasRenderingContext2D();
inline bool
IsOffscreenCanvasRenderingContext2D() const
{
return mType == eOffscreenCanvasRenderingContext2D;
}
inline OwningNonNull<mozilla::dom::OffscreenCanvasRenderingContext2D>&
GetAsOffscreenCanvasRenderingContext2D()
{
MOZ_RELEASE_ASSERT(IsOffscreenCanvasRenderingContext2D(), "Wrong type!");
return mValue.mOffscreenCanvasRenderingContext2D.Value();
}
inline OwningNonNull<mozilla::dom::OffscreenCanvasRenderingContext2D> const &
GetAsOffscreenCanvasRenderingContext2D() const
{
MOZ_RELEASE_ASSERT(IsOffscreenCanvasRenderingContext2D(), "Wrong type!");
return mValue.mOffscreenCanvasRenderingContext2D.Value();
}
[[nodiscard]] OwningNonNull<mozilla::dom::ImageBitmapRenderingContext>&
RawSetAsImageBitmapRenderingContext();
[[nodiscard]] OwningNonNull<mozilla::dom::ImageBitmapRenderingContext>&
SetAsImageBitmapRenderingContext();
inline bool
IsImageBitmapRenderingContext() const
{
return mType == eImageBitmapRenderingContext;
}
inline OwningNonNull<mozilla::dom::ImageBitmapRenderingContext>&
GetAsImageBitmapRenderingContext()
{
MOZ_RELEASE_ASSERT(IsImageBitmapRenderingContext(), "Wrong type!");
return mValue.mImageBitmapRenderingContext.Value();
}
inline OwningNonNull<mozilla::dom::ImageBitmapRenderingContext> const &
GetAsImageBitmapRenderingContext() const
{
MOZ_RELEASE_ASSERT(IsImageBitmapRenderingContext(), "Wrong type!");
return mValue.mImageBitmapRenderingContext.Value();
}
[[nodiscard]] OwningNonNull<mozilla::ClientWebGLContext>&
RawSetAsWebGLRenderingContext();
[[nodiscard]] OwningNonNull<mozilla::ClientWebGLContext>&
SetAsWebGLRenderingContext();
inline bool
IsWebGLRenderingContext() const
{
return mType == eWebGLRenderingContext;
}
inline OwningNonNull<mozilla::ClientWebGLContext>&
GetAsWebGLRenderingContext()
{
MOZ_RELEASE_ASSERT(IsWebGLRenderingContext(), "Wrong type!");
return mValue.mWebGLRenderingContext.Value();
}
inline OwningNonNull<mozilla::ClientWebGLContext> const &
GetAsWebGLRenderingContext() const
{
MOZ_RELEASE_ASSERT(IsWebGLRenderingContext(), "Wrong type!");
return mValue.mWebGLRenderingContext.Value();
}
[[nodiscard]] OwningNonNull<mozilla::ClientWebGLContext>&
RawSetAsWebGL2RenderingContext();
[[nodiscard]] OwningNonNull<mozilla::ClientWebGLContext>&
SetAsWebGL2RenderingContext();
inline bool
IsWebGL2RenderingContext() const
{
return mType == eWebGL2RenderingContext;
}
inline OwningNonNull<mozilla::ClientWebGLContext>&
GetAsWebGL2RenderingContext()
{
MOZ_RELEASE_ASSERT(IsWebGL2RenderingContext(), "Wrong type!");
return mValue.mWebGL2RenderingContext.Value();
}
inline OwningNonNull<mozilla::ClientWebGLContext> const &
GetAsWebGL2RenderingContext() const
{
MOZ_RELEASE_ASSERT(IsWebGL2RenderingContext(), "Wrong type!");
return mValue.mWebGL2RenderingContext.Value();
}
[[nodiscard]] OwningNonNull<mozilla::webgpu::CanvasContext>&
RawSetAsGPUCanvasContext();
[[nodiscard]] OwningNonNull<mozilla::webgpu::CanvasContext>&
SetAsGPUCanvasContext();
inline bool
IsGPUCanvasContext() const
{
return mType == eGPUCanvasContext;
}
inline OwningNonNull<mozilla::webgpu::CanvasContext>&
GetAsGPUCanvasContext()
{
MOZ_RELEASE_ASSERT(IsGPUCanvasContext(), "Wrong type!");
return mValue.mGPUCanvasContext.Value();
}
inline OwningNonNull<mozilla::webgpu::CanvasContext> const &
GetAsGPUCanvasContext() const
{
MOZ_RELEASE_ASSERT(IsGPUCanvasContext(), "Wrong type!");
return mValue.mGPUCanvasContext.Value();
}
bool
Init(BindingCallContext& cx, JS::Handle<JS::Value> value, const char* sourceDescription = "Value", bool passedToJSImpl = false);
bool
Init(JSContext* cx_, JS::Handle<JS::Value> value, const char* sourceDescription = "Value", bool passedToJSImpl = false);
void
Uninit();
bool
ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const;
OwningOffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext&
operator=(OwningOffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext&& aOther);
inline Type
GetType() const
{
MOZ_RELEASE_ASSERT(mType != eUninitialized);
return static_cast<Type>(mType);
}
OwningOffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext&
operator=(const OwningOffscreenCanvasRenderingContext2DOrImageBitmapRenderingContextOrWebGLRenderingContextOrWebGL2RenderingContextOrGPUCanvasContext& aOther);
private:
bool
TrySetToOffscreenCanvasRenderingContext2D(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToOffscreenCanvasRenderingContext2D(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
void
DestroyOffscreenCanvasRenderingContext2D();
bool
TrySetToImageBitmapRenderingContext(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToImageBitmapRenderingContext(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
void
DestroyImageBitmapRenderingContext();
bool
TrySetToWebGLRenderingContext(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToWebGLRenderingContext(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
void
DestroyWebGLRenderingContext();
bool
TrySetToWebGL2RenderingContext(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToWebGL2RenderingContext(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
void
DestroyWebGL2RenderingContext();
bool
TrySetToGPUCanvasContext(BindingCallContext& cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
bool
TrySetToGPUCanvasContext(JSContext* cx_, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl = false);
void
DestroyGPUCanvasContext();
};
namespace OffscreenCanvas_Binding {
typedef mozilla::dom::OffscreenCanvas NativeType;
bool
Wrap(JSContext* aCx, mozilla::dom::OffscreenCanvas* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);
template <class T>
inline JSObject* Wrap(JSContext* aCx, T* aObject, JS::Handle<JSObject*> aGivenProto)
{
JS::Rooted<JSObject*> reflector(aCx);
return Wrap(aCx, aObject, aObject, aGivenProto, &reflector) ? reflector.get() : nullptr;
}
void
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, DefineInterfaceProperty aDefineOnGlobal);
JS::Handle<JSObject*>
GetConstructorObjectHandle(JSContext* aCx);
inline bool CreateAndDefineOnGlobal(JSContext* aCx)
{
// Get the interface or namespace object for this class. This will
// create the object as needed and always define the properties for
// it on the global. The caller should make sure the interface or
// namespace is exposed on the global before calling this.
return GetPerInterfaceObjectHandle(aCx, constructors::id::OffscreenCanvas,
&CreateInterfaceObjects,
DefineInterfaceProperty::Always);
}
} // namespace OffscreenCanvas_Binding
} // namespace dom
template <>
struct MaxContiguousEnumValue<dom::OffscreenRenderingContextId>
{
static constexpr dom::OffscreenRenderingContextId value = dom::OffscreenRenderingContextId::Webgpu;
static_assert(static_cast<uint8_t>(dom::OffscreenRenderingContextId::_2d) == 0,
"We rely on this in ContiguousEnumValues");
static_assert(std::size(dom::binding_detail::EnumStrings<dom::OffscreenRenderingContextId>::Values) - 1 == UnderlyingValue(value),
"Mismatch between enum strings and enum count");
};
} // namespace mozilla
#endif // DOM_OFFSCREENCANVASBINDING_H_