#pragma once
#include "IDLTypes.h"
#include "ImageBitmapBacking.h"
#include "ScriptWrappable.h"
#include <wtf/RefCounted.h>
namespace JSC {
class ArrayBuffer;
}
using JSC::ArrayBuffer;
namespace WebCore {
class Blob;
class CanvasBase;
class HTMLCanvasElement;
class HTMLImageElement;
class HTMLVideoElement;
class ImageBitmapImageObserver;
class ImageData;
class IntRect;
class IntSize;
#if ENABLE(OFFSCREEN_CANVAS)
class OffscreenCanvas;
#endif
class PendingImageBitmap;
class ScriptExecutionContext;
class TypedOMCSSImageValue;
struct ImageBitmapOptions;
template<typename IDLType> class DOMPromiseDeferred;
class ImageBitmap final : public ScriptWrappable, public RefCounted<ImageBitmap> {
WTF_MAKE_ISO_ALLOCATED(ImageBitmap);
public:
using Source = Variant<
RefPtr<HTMLImageElement>,
#if ENABLE(VIDEO)
RefPtr<HTMLVideoElement>,
#endif
RefPtr<HTMLCanvasElement>,
RefPtr<ImageBitmap>,
#if ENABLE(OFFSCREEN_CANVAS)
RefPtr<OffscreenCanvas>,
#endif
#if ENABLE(CSS_TYPED_OM)
RefPtr<TypedOMCSSImageValue>,
#endif
RefPtr<Blob>,
RefPtr<ImageData>
>;
using Promise = DOMPromiseDeferred<IDLInterface<ImageBitmap>>;
static void createPromise(ScriptExecutionContext&, Source&&, ImageBitmapOptions&&, Promise&&);
static void createPromise(ScriptExecutionContext&, Source&&, ImageBitmapOptions&&, int sx, int sy, int sw, int sh, Promise&&);
static RefPtr<ImageBuffer> createImageBuffer(ScriptExecutionContext&, const FloatSize&, RenderingMode, float resolutionScale = 1);
static Ref<ImageBitmap> create(ScriptExecutionContext&, const IntSize&);
static Ref<ImageBitmap> create(Optional<ImageBitmapBacking>&&);
~ImageBitmap();
ImageBuffer* buffer() const { return m_backingStore ? m_backingStore->buffer() : nullptr; }
RefPtr<ImageBuffer> takeImageBuffer();
OptionSet<SerializationState> serializationState() const { return m_backingStore ? m_backingStore->serializationState() : SerializationState(); }
unsigned width() const { return m_backingStore ? m_backingStore->width() : 0; }
unsigned height() const { return m_backingStore ? m_backingStore->height() : 0; }
bool originClean() const { return m_backingStore && m_backingStore->originClean(); }
bool premultiplyAlpha() const { return m_backingStore && m_backingStore->premultiplyAlpha(); }
bool forciblyPremultiplyAlpha() const { return m_backingStore && m_backingStore->forciblyPremultiplyAlpha(); }
Optional<ImageBitmapBacking> takeImageBitmapBacking();
bool isDetached() const { return !m_backingStore.hasValue(); }
void close() { takeImageBitmapBacking(); }
static Vector<Optional<ImageBitmapBacking>> detachBitmaps(Vector<RefPtr<ImageBitmap>>&&);
private:
friend class ImageBitmapImageObserver;
friend class PendingImageBitmap;
ImageBitmap(Optional<ImageBitmapBacking>&&);
static void resolveWithBlankImageBuffer(ScriptExecutionContext&, bool originClean, Promise&&);
static void createPromise(ScriptExecutionContext&, RefPtr<HTMLImageElement>&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
#if ENABLE(VIDEO)
static void createPromise(ScriptExecutionContext&, RefPtr<HTMLVideoElement>&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
#endif
static void createPromise(ScriptExecutionContext&, RefPtr<ImageBitmap>&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
static void createPromise(ScriptExecutionContext&, RefPtr<HTMLCanvasElement>&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
#if ENABLE(OFFSCREEN_CANVAS)
static void createPromise(ScriptExecutionContext&, RefPtr<OffscreenCanvas>&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
#endif
static void createPromise(ScriptExecutionContext&, CanvasBase&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
static void createPromise(ScriptExecutionContext&, RefPtr<Blob>&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
static void createPromise(ScriptExecutionContext&, RefPtr<ImageData>&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
static void createPromise(ScriptExecutionContext&, RefPtr<TypedOMCSSImageValue>&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
static void createFromBuffer(ScriptExecutionContext&, Ref<ArrayBuffer>&&, String mimeType, long long expectedContentLength, const URL&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
Optional<ImageBitmapBacking> m_backingStore;
};
}