2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2013-01-04 09:16:14 +04:00
|
|
|
#if !defined(mozilla_dom_HTMLCanvasElement_h)
|
|
|
|
# define mozilla_dom_HTMLCanvasElement_h
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
# include "mozilla/Attributes.h"
|
2015-09-17 07:36:57 +03:00
|
|
|
# include "mozilla/WeakPtr.h"
|
2015-10-12 06:21:03 +03:00
|
|
|
# include "nsIDOMEventListener.h"
|
|
|
|
# include "nsIObserver.h"
|
2010-05-18 08:04:22 +04:00
|
|
|
# include "nsGenericHTMLElement.h"
|
|
|
|
# include "nsGkAtoms.h"
|
|
|
|
# include "nsSize.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
# include "nsError.h"
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2016-11-15 08:18:32 +03:00
|
|
|
# include "mozilla/dom/BindingDeclarations.h"
|
2015-10-12 06:21:03 +03:00
|
|
|
# include "mozilla/dom/CanvasRenderingContextHelper.h"
|
2013-05-29 17:32:30 +04:00
|
|
|
# include "mozilla/gfx/Rect.h"
|
2015-10-12 06:21:03 +03:00
|
|
|
# include "mozilla/layers/LayersTypes.h"
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2020-09-18 21:32:13 +03:00
|
|
|
class nsDisplayListBuilder;
|
2012-06-06 11:42:47 +04:00
|
|
|
class nsICanvasRenderingContextInternal;
|
2020-11-23 19:21:38 +03:00
|
|
|
class nsIInputStream;
|
2012-08-31 21:45:45 +04:00
|
|
|
class nsITimerCallback;
|
2020-02-11 04:23:12 +03:00
|
|
|
enum class gfxAlphaType;
|
2010-09-18 05:14:59 +04:00
|
|
|
|
2012-07-31 04:42:26 +04:00
|
|
|
namespace mozilla {
|
2012-11-04 12:05:25 +04:00
|
|
|
|
2020-01-09 01:19:14 +03:00
|
|
|
class ClientWebGLContext;
|
2015-10-12 06:21:03 +03:00
|
|
|
|
2012-07-31 04:42:26 +04:00
|
|
|
namespace layers {
|
2017-08-03 08:55:14 +03:00
|
|
|
class CanvasRenderer;
|
2012-07-31 04:42:26 +04:00
|
|
|
class CanvasLayer;
|
2015-09-17 07:36:57 +03:00
|
|
|
class Image;
|
2015-12-18 09:52:17 +03:00
|
|
|
class Layer;
|
2012-07-31 04:42:26 +04:00
|
|
|
class LayerManager;
|
2020-01-09 01:19:14 +03:00
|
|
|
class OOPCanvasRenderer;
|
2016-02-25 02:54:50 +03:00
|
|
|
class SharedSurfaceTextureClient;
|
2017-10-28 13:07:27 +03:00
|
|
|
class WebRenderCanvasData;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
2014-04-17 09:29:52 +04:00
|
|
|
namespace gfx {
|
|
|
|
class SourceSurface;
|
2016-02-25 02:54:50 +03:00
|
|
|
class VRLayerChild;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
2020-04-07 01:29:18 +03:00
|
|
|
namespace webgpu {
|
|
|
|
class CanvasContext;
|
|
|
|
} // namespace webgpu
|
2012-11-04 12:05:25 +04:00
|
|
|
|
2013-01-04 09:16:14 +04:00
|
|
|
namespace dom {
|
2016-11-03 09:57:34 +03:00
|
|
|
class BlobCallback;
|
2015-05-13 09:04:30 +03:00
|
|
|
class CanvasCaptureMediaStream;
|
2014-10-08 20:15:23 +04:00
|
|
|
class File;
|
2013-01-04 09:16:14 +04:00
|
|
|
class HTMLCanvasPrintState;
|
2015-10-12 06:21:03 +03:00
|
|
|
class OffscreenCanvas;
|
2013-09-12 02:35:51 +04:00
|
|
|
class PrintCallback;
|
2020-01-09 01:19:14 +03:00
|
|
|
class PWebGLChild;
|
2015-09-17 07:36:57 +03:00
|
|
|
class RequestedFrameRefreshObserver;
|
2012-07-31 04:42:26 +04:00
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
// Listen visibilitychange and memory-pressure event and inform
|
|
|
|
// context when event is fired.
|
|
|
|
class HTMLCanvasElementObserver final : public nsIObserver,
|
|
|
|
public nsIDOMEventListener {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
|
|
|
|
|
|
|
explicit HTMLCanvasElementObserver(HTMLCanvasElement* aElement);
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
void RegisterVisibilityChangeEvent();
|
|
|
|
void UnregisterVisibilityChangeEvent();
|
|
|
|
|
2020-02-24 14:21:27 +03:00
|
|
|
void RegisterObserverEvents();
|
|
|
|
void UnregisterObserverEvents();
|
2015-10-12 06:21:03 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
~HTMLCanvasElementObserver();
|
|
|
|
|
|
|
|
HTMLCanvasElement* mElement;
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2014-11-11 02:16:50 +03:00
|
|
|
|
2015-09-17 07:36:57 +03:00
|
|
|
/*
|
|
|
|
* FrameCaptureListener is used by captureStream() as a way of getting video
|
|
|
|
* frames from the canvas. On a refresh driver tick after something has been
|
|
|
|
* drawn to the canvas since the last such tick, all registered
|
|
|
|
* FrameCaptureListeners whose `mFrameCaptureRequested` equals `true`,
|
|
|
|
* will be given a copy of the just-painted canvas.
|
|
|
|
* All FrameCaptureListeners get the same copy.
|
|
|
|
*/
|
2020-07-23 17:51:46 +03:00
|
|
|
class FrameCaptureListener : public SupportsWeakPtr {
|
2015-09-17 07:36:57 +03:00
|
|
|
public:
|
|
|
|
FrameCaptureListener() : mFrameCaptureRequested(false) {}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when a frame capture is desired on next paint.
|
|
|
|
*/
|
|
|
|
void RequestFrameCapture() { mFrameCaptureRequested = true; }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Indicates to the canvas whether or not this listener has requested a frame.
|
|
|
|
*/
|
|
|
|
bool FrameCaptureRequested() const { return mFrameCaptureRequested; }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interface through which new video frames will be provided while
|
|
|
|
* `mFrameCaptureRequested` is `true`.
|
|
|
|
*/
|
2017-01-13 13:56:03 +03:00
|
|
|
virtual void NewFrame(already_AddRefed<layers::Image> aImage,
|
|
|
|
const TimeStamp& aTime) = 0;
|
2015-09-17 07:36:57 +03:00
|
|
|
|
|
|
|
protected:
|
2020-02-20 19:19:15 +03:00
|
|
|
virtual ~FrameCaptureListener() = default;
|
2015-09-17 07:36:57 +03:00
|
|
|
|
|
|
|
bool mFrameCaptureRequested;
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class HTMLCanvasElement final : public nsGenericHTMLElement,
|
2020-04-21 02:50:04 +03:00
|
|
|
public CanvasRenderingContextHelper,
|
2020-07-23 17:51:46 +03:00
|
|
|
public SupportsWeakPtr {
|
2013-04-13 11:05:40 +04:00
|
|
|
enum { DEFAULT_CANVAS_WIDTH = 300, DEFAULT_CANVAS_HEIGHT = 150 };
|
|
|
|
|
2017-08-03 08:55:14 +03:00
|
|
|
typedef layers::CanvasRenderer CanvasRenderer;
|
2013-01-04 09:16:14 +04:00
|
|
|
typedef layers::CanvasLayer CanvasLayer;
|
2015-12-18 09:52:17 +03:00
|
|
|
typedef layers::Layer Layer;
|
2013-01-04 09:16:14 +04:00
|
|
|
typedef layers::LayerManager LayerManager;
|
2017-10-28 13:07:27 +03:00
|
|
|
typedef layers::WebRenderCanvasData WebRenderCanvasData;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
public:
|
2018-09-21 23:45:49 +03:00
|
|
|
explicit HTMLCanvasElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLCanvasElement, canvas)
|
2012-09-26 18:17:51 +04:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2010-06-16 01:38:05 +04:00
|
|
|
// CC
|
2013-01-04 09:16:14 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLCanvasElement,
|
2011-06-22 01:12:50 +04:00
|
|
|
nsGenericHTMLElement)
|
2010-06-16 01:38:05 +04:00
|
|
|
|
2013-04-13 11:05:40 +04:00
|
|
|
// WebIDL
|
|
|
|
uint32_t Height() {
|
|
|
|
return GetUnsignedIntAttr(nsGkAtoms::height, DEFAULT_CANVAS_HEIGHT);
|
|
|
|
}
|
|
|
|
void SetHeight(uint32_t aHeight, ErrorResult& aRv) {
|
2015-10-12 06:21:03 +03:00
|
|
|
if (mOffscreenCanvas) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-05 21:29:54 +03:00
|
|
|
SetUnsignedIntAttr(nsGkAtoms::height, aHeight, DEFAULT_CANVAS_HEIGHT, aRv);
|
2013-04-13 11:05:40 +04:00
|
|
|
}
|
|
|
|
uint32_t Width() {
|
|
|
|
return GetUnsignedIntAttr(nsGkAtoms::width, DEFAULT_CANVAS_WIDTH);
|
|
|
|
}
|
|
|
|
void SetWidth(uint32_t aWidth, ErrorResult& aRv) {
|
2015-10-12 06:21:03 +03:00
|
|
|
if (mOffscreenCanvas) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-05 21:29:54 +03:00
|
|
|
SetUnsignedIntAttr(nsGkAtoms::width, aWidth, DEFAULT_CANVAS_WIDTH, aRv);
|
2013-04-13 11:05:40 +04:00
|
|
|
}
|
2015-10-12 06:21:03 +03:00
|
|
|
|
|
|
|
virtual already_AddRefed<nsISupports> GetContext(
|
2013-04-13 11:05:40 +04:00
|
|
|
JSContext* aCx, const nsAString& aContextId,
|
2013-06-07 22:42:12 +04:00
|
|
|
JS::Handle<JS::Value> aContextOptions, ErrorResult& aRv) override;
|
2015-10-12 06:21:03 +03:00
|
|
|
|
2013-04-13 11:05:51 +04:00
|
|
|
void ToDataURL(JSContext* aCx, const nsAString& aType,
|
2014-02-19 19:13:38 +04:00
|
|
|
JS::Handle<JS::Value> aParams, nsAString& aDataURL,
|
2018-05-14 21:49:32 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-07-24 15:17:00 +04:00
|
|
|
void ToBlob(JSContext* aCx, BlobCallback& aCallback, const nsAString& aType,
|
2018-05-14 21:49:32 +03:00
|
|
|
JS::Handle<JS::Value> aParams, nsIPrincipal& aSubjectPrincipal,
|
2013-09-12 02:35:51 +04:00
|
|
|
ErrorResult& aRv);
|
2013-04-13 11:05:40 +04:00
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
OffscreenCanvas* TransferControlToOffscreen(ErrorResult& aRv);
|
|
|
|
|
2013-04-13 11:05:40 +04:00
|
|
|
bool MozOpaque() const { return GetBoolAttr(nsGkAtoms::moz_opaque); }
|
|
|
|
void SetMozOpaque(bool aValue, ErrorResult& aRv) {
|
2015-10-12 06:21:03 +03:00
|
|
|
if (mOffscreenCanvas) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-13 11:05:40 +04:00
|
|
|
SetHTMLBoolAttr(nsGkAtoms::moz_opaque, aValue, aRv);
|
|
|
|
}
|
2014-10-08 20:15:23 +04:00
|
|
|
already_AddRefed<File> MozGetAsFile(const nsAString& aName,
|
|
|
|
const nsAString& aType,
|
2018-05-14 21:49:32 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2014-10-08 20:15:23 +04:00
|
|
|
ErrorResult& aRv);
|
2013-04-13 11:05:40 +04:00
|
|
|
already_AddRefed<nsISupports> MozGetIPCContext(const nsAString& aContextId,
|
2016-11-15 08:18:32 +03:00
|
|
|
ErrorResult& aRv);
|
2013-09-12 02:35:51 +04:00
|
|
|
PrintCallback* GetMozPrintCallback() const;
|
|
|
|
void SetMozPrintCallback(PrintCallback* aCallback);
|
2013-04-13 11:05:40 +04:00
|
|
|
|
2015-05-13 09:04:30 +03:00
|
|
|
already_AddRefed<CanvasCaptureMediaStream> CaptureStream(
|
2018-05-14 21:49:32 +03:00
|
|
|
const Optional<double>& aFrameRate, nsIPrincipal& aSubjectPrincipal,
|
|
|
|
ErrorResult& aRv);
|
2015-05-13 09:04:30 +03:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
/**
|
|
|
|
* Get the size in pixels of this canvas element
|
|
|
|
*/
|
|
|
|
nsIntSize GetSize();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the canvas is write-only.
|
|
|
|
*/
|
2018-11-07 01:31:34 +03:00
|
|
|
bool IsWriteOnly() const;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Force the canvas to be write-only.
|
|
|
|
*/
|
|
|
|
void SetWriteOnly();
|
|
|
|
|
2018-09-26 21:29:36 +03:00
|
|
|
/**
|
|
|
|
* Force the canvas to be write-only, except for readers from
|
|
|
|
* a specific extension's content script expanded principal.
|
|
|
|
*/
|
|
|
|
void SetWriteOnly(nsIPrincipal* aExpandedReader);
|
|
|
|
|
2011-03-28 03:59:47 +04:00
|
|
|
/**
|
|
|
|
* Notify that some canvas content has changed and the window may
|
|
|
|
* need to be updated. aDamageRect is in canvas coordinates.
|
|
|
|
*/
|
2012-11-04 12:05:25 +04:00
|
|
|
void InvalidateCanvasContent(const mozilla::gfx::Rect* aDamageRect);
|
2010-05-18 08:04:22 +04:00
|
|
|
/*
|
2011-03-28 03:59:47 +04:00
|
|
|
* Notify that we need to repaint the entire canvas, including updating of
|
|
|
|
* the layer tree.
|
2010-05-18 08:04:22 +04:00
|
|
|
*/
|
2011-03-28 03:59:47 +04:00
|
|
|
void InvalidateCanvas();
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2020-09-02 17:20:50 +03:00
|
|
|
nsICanvasRenderingContextInternal* GetCurrentContext() {
|
|
|
|
return mCurrentContext;
|
|
|
|
}
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns true if the canvas context content is guaranteed to be opaque
|
|
|
|
* across its entire area.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetIsOpaque();
|
2015-10-12 06:21:03 +03:00
|
|
|
virtual bool GetOpaqueAttr() override;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2017-04-12 12:55:23 +03:00
|
|
|
virtual already_AddRefed<gfx::SourceSurface> GetSurfaceSnapshot(
|
|
|
|
gfxAlphaType* aOutAlphaType = nullptr);
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2015-09-17 07:36:57 +03:00
|
|
|
/*
|
|
|
|
* Register a FrameCaptureListener with this canvas.
|
|
|
|
* The canvas hooks into the RefreshDriver while there are
|
|
|
|
* FrameCaptureListeners registered.
|
|
|
|
* The registered FrameCaptureListeners are stored as WeakPtrs, thus it's the
|
|
|
|
* caller's responsibility to keep them alive. Once a registered
|
|
|
|
* FrameCaptureListener is destroyed it will be automatically deregistered.
|
|
|
|
*/
|
2017-08-22 09:23:41 +03:00
|
|
|
nsresult RegisterFrameCaptureListener(FrameCaptureListener* aListener,
|
|
|
|
bool aReturnPlaceholderData);
|
2015-09-17 07:36:57 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns true when there is at least one registered FrameCaptureListener
|
|
|
|
* that has requested a frame capture.
|
|
|
|
*/
|
|
|
|
bool IsFrameCaptureRequested() const;
|
|
|
|
|
2016-09-12 18:59:38 +03:00
|
|
|
/*
|
|
|
|
* Processes destroyed FrameCaptureListeners and removes them if necessary.
|
|
|
|
* Should there be none left, the FrameRefreshObserver will be unregistered.
|
|
|
|
*/
|
|
|
|
void ProcessDestroyedFrameListeners();
|
|
|
|
|
2015-09-17 07:36:57 +03:00
|
|
|
/*
|
|
|
|
* Called by the RefreshDriver hook when a frame has been captured.
|
|
|
|
* Makes a copy of the provided surface and hands it to all
|
|
|
|
* FrameCaptureListeners having requested frame capture.
|
|
|
|
*/
|
2017-01-13 13:56:03 +03:00
|
|
|
void SetFrameCapture(already_AddRefed<gfx::SourceSurface> aSurface,
|
|
|
|
const TimeStamp& aTime);
|
2015-09-17 07:36:57 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
2010-05-18 08:04:22 +04:00
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAttrValue& aResult) override;
|
2017-10-03 01:05:19 +03:00
|
|
|
nsChangeHint GetAttributeChangeHint(const nsAtom* aAttribute,
|
|
|
|
int32_t aModType) const override;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2018-08-09 02:58:44 +03:00
|
|
|
virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
|
|
|
|
nsresult CopyInnerTo(HTMLCanvasElement* aDest);
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
|
2014-05-20 08:54:00 +04:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
/*
|
|
|
|
* Helpers called by various users of Canvas
|
|
|
|
*/
|
|
|
|
|
2015-12-18 09:52:17 +03:00
|
|
|
already_AddRefed<Layer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
Layer* aOldLayer,
|
|
|
|
LayerManager* aManager);
|
2017-10-28 13:07:27 +03:00
|
|
|
bool UpdateWebRenderCanvasData(nsDisplayListBuilder* aBuilder,
|
|
|
|
WebRenderCanvasData* aCanvasData);
|
2017-08-18 10:13:29 +03:00
|
|
|
bool InitializeCanvasRenderer(nsDisplayListBuilder* aBuilder,
|
2017-08-03 08:55:14 +03:00
|
|
|
CanvasRenderer* aRenderer);
|
2011-07-08 14:42:21 +04:00
|
|
|
// Should return true if the canvas layer should always be marked inactive.
|
|
|
|
// We should return true here if we can't do accelerated compositing with
|
|
|
|
// a non-BasicCanvasLayer.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ShouldForceInactiveLayer(LayerManager* aManager);
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2011-03-28 03:59:47 +04:00
|
|
|
// Call this whenever we need future changes to the canvas
|
|
|
|
// to trigger fresh invalidation requests. This needs to be called
|
|
|
|
// whenever we render the canvas contents to the screen, or whenever we
|
|
|
|
// take a snapshot of the canvas that needs to be "live" (e.g. -moz-element).
|
2010-05-18 08:04:22 +04:00
|
|
|
void MarkContextClean();
|
|
|
|
|
2015-09-17 06:37:05 +03:00
|
|
|
// Call this after capturing a frame, so we can avoid unnecessary surface
|
|
|
|
// copies for future frames when no drawing has occurred.
|
|
|
|
void MarkContextCleanForFrameCapture();
|
|
|
|
|
|
|
|
// Starts returning false when something is drawn.
|
|
|
|
bool IsContextCleanForFrameCapture();
|
|
|
|
|
2013-04-13 11:05:33 +04:00
|
|
|
nsresult GetContext(const nsAString& aContextId, nsISupports** aContext);
|
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
layers::LayersBackend GetCompositorBackendType() const;
|
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
void OnVisibilityChange();
|
|
|
|
void OnMemoryPressure();
|
2020-02-24 14:21:27 +03:00
|
|
|
void OnDeviceReset();
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
already_AddRefed<layers::SharedSurfaceTextureClient> GetVRFrame();
|
2019-10-29 03:35:35 +03:00
|
|
|
void ClearVRFrame();
|
2016-02-25 02:54:50 +03:00
|
|
|
|
2018-10-18 23:16:45 +03:00
|
|
|
bool MaybeModified() const { return mMaybeModified; };
|
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
protected:
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~HTMLCanvasElement();
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2013-04-13 11:05:51 +04:00
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
virtual nsIntSize GetWidthHeight() override;
|
|
|
|
|
|
|
|
virtual already_AddRefed<nsICanvasRenderingContextInternal> CreateContext(
|
|
|
|
CanvasContextType aContextType) override;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2017-08-22 09:23:41 +03:00
|
|
|
nsresult ExtractData(JSContext* aCx, nsIPrincipal& aSubjectPrincipal,
|
2010-09-18 05:14:59 +04:00
|
|
|
nsAString& aType, const nsAString& aOptions,
|
2013-10-17 06:55:08 +04:00
|
|
|
nsIInputStream** aStream);
|
2013-04-13 11:05:22 +04:00
|
|
|
nsresult ToDataURLImpl(JSContext* aCx, nsIPrincipal& aSubjectPrincipal,
|
|
|
|
const nsAString& aMimeType,
|
|
|
|
const JS::Value& aEncoderOptions, nsAString& aDataURL);
|
2016-11-15 08:18:32 +03:00
|
|
|
nsresult MozGetAsFileImpl(const nsAString& aName, const nsAString& aType,
|
2018-05-14 21:49:32 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal, File** aResult);
|
2012-08-31 21:45:45 +04:00
|
|
|
void CallPrintCallback();
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
2017-06-07 20:28:20 +03:00
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue,
|
2017-10-10 00:33:38 +03:00
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
2017-06-07 20:28:20 +03:00
|
|
|
bool aNotify) override;
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsAtom* aName,
|
2017-06-07 20:28:20 +03:00
|
|
|
const nsAttrValueOrString& aValue,
|
|
|
|
bool aNotify) override;
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
public:
|
|
|
|
ClientWebGLContext* GetWebGLContext();
|
2020-04-07 01:29:18 +03:00
|
|
|
webgpu::CanvasContext* GetWebGPUContext();
|
2015-10-12 06:21:02 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
protected:
|
2015-10-12 06:21:03 +03:00
|
|
|
bool mResetLayer;
|
2018-10-18 23:16:45 +03:00
|
|
|
bool mMaybeModified; // we fetched the context, so we may have written to the
|
|
|
|
// canvas
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLCanvasElement> mOriginalCanvas;
|
|
|
|
RefPtr<PrintCallback> mPrintCallback;
|
|
|
|
RefPtr<HTMLCanvasPrintState> mPrintState;
|
2015-09-17 07:36:57 +03:00
|
|
|
nsTArray<WeakPtr<FrameCaptureListener>> mRequestedFrameListeners;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<RequestedFrameRefreshObserver> mRequestedFrameRefreshObserver;
|
2020-06-15 21:25:55 +03:00
|
|
|
RefPtr<CanvasRenderer> mCanvasRenderer;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<OffscreenCanvas> mOffscreenCanvas;
|
|
|
|
RefPtr<HTMLCanvasElementObserver> mContextObserver;
|
2013-04-13 11:03:57 +04:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
public:
|
|
|
|
// Record whether this canvas should be write-only or not.
|
|
|
|
// We set this when script paints an image from a different origin.
|
|
|
|
// We also transitively set it when script paints a canvas which
|
|
|
|
// is itself write-only.
|
2018-09-26 21:29:36 +03:00
|
|
|
bool mWriteOnly;
|
|
|
|
|
|
|
|
// When this canvas is (only) tainted by an image from an extension
|
|
|
|
// content script, allow reads from the same extension afterwards.
|
|
|
|
RefPtr<nsIPrincipal> mExpandedReader;
|
2012-08-31 21:45:45 +04:00
|
|
|
|
2018-09-26 21:29:36 +03:00
|
|
|
// Determines if the caller should be able to read the content.
|
|
|
|
bool CallerCanRead(JSContext* aCx);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-31 21:45:45 +04:00
|
|
|
bool IsPrintCallbackDone();
|
|
|
|
|
2020-02-11 04:23:12 +03:00
|
|
|
void HandlePrintCallback(nsPresContext*);
|
2012-08-31 21:45:45 +04:00
|
|
|
|
|
|
|
nsresult DispatchPrintCallback(nsITimerCallback* aCallback);
|
|
|
|
|
|
|
|
void ResetPrintCallback();
|
|
|
|
|
2013-01-04 09:16:14 +04:00
|
|
|
HTMLCanvasElement* GetOriginalCanvas();
|
2015-07-30 21:47:00 +03:00
|
|
|
|
2020-01-08 04:12:50 +03:00
|
|
|
CanvasContextType GetCurrentContextType();
|
2017-06-07 20:28:20 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* This function is called by AfterSetAttr and OnAttrSetButNotChanged.
|
|
|
|
* This function will be called by AfterSetAttr whether the attribute is being
|
|
|
|
* set or unset.
|
|
|
|
*
|
|
|
|
* @param aNamespaceID the namespace of the attr being set
|
|
|
|
* @param aName the localname of the attribute being set
|
|
|
|
* @param aNotify Whether we plan to notify document observers.
|
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
void AfterMaybeChangeAttr(int32_t aNamespaceID, nsAtom* aName, bool aNotify);
|
2010-05-18 08:04:22 +04:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class HTMLCanvasPrintState final : public nsWrapperCache {
|
2013-09-12 02:35:51 +04:00
|
|
|
public:
|
|
|
|
HTMLCanvasPrintState(HTMLCanvasElement* aCanvas,
|
|
|
|
nsICanvasRenderingContextInternal* aContext,
|
|
|
|
nsITimerCallback* aCallback);
|
|
|
|
|
|
|
|
nsISupports* Context() const;
|
|
|
|
|
|
|
|
void Done();
|
|
|
|
|
|
|
|
void NotifyDone();
|
|
|
|
|
|
|
|
bool mIsDone;
|
|
|
|
|
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(HTMLCanvasPrintState)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(HTMLCanvasPrintState)
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* cx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2013-09-12 02:35:51 +04:00
|
|
|
|
|
|
|
HTMLCanvasElement* GetParentObject() { return mCanvas; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
~HTMLCanvasPrintState();
|
|
|
|
bool mPendingNotify;
|
|
|
|
|
|
|
|
protected:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLCanvasElement> mCanvas;
|
2013-09-12 02:35:51 +04:00
|
|
|
nsCOMPtr<nsICanvasRenderingContextInternal> mContext;
|
|
|
|
nsCOMPtr<nsITimerCallback> mCallback;
|
|
|
|
};
|
|
|
|
|
2013-01-04 09:16:14 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_HTMLCanvasElement_h */
|