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"
|
2010-05-18 08:04:22 +04:00
|
|
|
#include "nsIDOMHTMLCanvasElement.h"
|
2015-10-12 06:21:03 +03:00
|
|
|
#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
|
|
|
|
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
|
|
|
|
2012-06-06 11:42:47 +04:00
|
|
|
class nsICanvasRenderingContextInternal;
|
2012-08-31 21:45:45 +04:00
|
|
|
class nsITimerCallback;
|
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
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
class WebGLContext;
|
|
|
|
|
2012-07-31 04:42:26 +04:00
|
|
|
namespace layers {
|
2015-10-12 06:21:02 +03:00
|
|
|
class AsyncCanvasRenderer;
|
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;
|
2016-02-25 02:54:50 +03:00
|
|
|
class SharedSurfaceTextureClient;
|
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
|
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;
|
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();
|
|
|
|
|
|
|
|
void RegisterMemoryPressureEvent();
|
|
|
|
void UnregisterMemoryPressureEvent();
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
class FrameCaptureListener : public SupportsWeakPtr<FrameCaptureListener>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(FrameCaptureListener)
|
|
|
|
|
|
|
|
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`.
|
|
|
|
*/
|
|
|
|
virtual void NewFrame(already_AddRefed<layers::Image> aImage) = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~FrameCaptureListener() {}
|
|
|
|
|
|
|
|
bool mFrameCaptureRequested;
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class HTMLCanvasElement final : public nsGenericHTMLElement,
|
2015-10-12 06:21:03 +03:00
|
|
|
public nsIDOMHTMLCanvasElement,
|
|
|
|
public CanvasRenderingContextHelper
|
2010-05-18 08:04:22 +04:00
|
|
|
{
|
2013-04-13 11:05:40 +04:00
|
|
|
enum {
|
|
|
|
DEFAULT_CANVAS_WIDTH = 300,
|
|
|
|
DEFAULT_CANVAS_HEIGHT = 150
|
|
|
|
};
|
|
|
|
|
2015-10-12 06:21:02 +03:00
|
|
|
typedef layers::AsyncCanvasRenderer AsyncCanvasRenderer;
|
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;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
public:
|
2014-08-05 17:19:51 +04:00
|
|
|
explicit HTMLCanvasElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2013-01-04 09:16:14 +04:00
|
|
|
NS_IMPL_FROMCONTENT_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
|
|
|
|
|
|
|
|
// nsIDOMHTMLCanvasElement
|
|
|
|
NS_DECL_NSIDOMHTMLCANVASELEMENT
|
|
|
|
|
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>
|
2013-04-13 11:05:40 +04:00
|
|
|
GetContext(JSContext* aCx, const nsAString& aContextId,
|
2013-06-07 22:42:12 +04:00
|
|
|
JS::Handle<JS::Value> aContextOptions,
|
2015-10-12 06:21:03 +03:00
|
|
|
ErrorResult& aRv) override;
|
|
|
|
|
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,
|
2013-05-16 20:36:54 +04:00
|
|
|
nsAString& aDataURL, ErrorResult& aRv)
|
2013-04-13 11:05:40 +04:00
|
|
|
{
|
2014-02-19 19:13:38 +04:00
|
|
|
aRv = ToDataURL(aType, aParams, aCx, aDataURL);
|
2013-04-13 11:05:40 +04:00
|
|
|
}
|
2015-10-12 06:21:03 +03:00
|
|
|
|
2013-07-24 15:17:00 +04:00
|
|
|
void ToBlob(JSContext* aCx,
|
2016-11-03 09:57:34 +03:00
|
|
|
BlobCallback& aCallback,
|
2013-07-24 15:17:00 +04:00
|
|
|
const nsAString& aType,
|
2014-02-19 19:13:38 +04:00
|
|
|
JS::Handle<JS::Value> aParams,
|
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,
|
|
|
|
ErrorResult& aRv);
|
2013-04-13 11:05:40 +04:00
|
|
|
already_AddRefed<nsISupports> MozGetIPCContext(const nsAString& aContextId,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> context;
|
|
|
|
aRv = MozGetIPCContext(aContextId, getter_AddRefs(context));
|
|
|
|
return context.forget();
|
|
|
|
}
|
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(const Optional<double>& aFrameRate, ErrorResult& aRv);
|
|
|
|
|
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.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsWriteOnly();
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Force the canvas to be write-only.
|
|
|
|
*/
|
|
|
|
void SetWriteOnly();
|
|
|
|
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the number of contexts in this canvas, and request a context at
|
|
|
|
* an index.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t CountContexts ();
|
|
|
|
nsICanvasRenderingContextInternal *GetContextAtIndex (int32_t index);
|
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
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<gfx::SourceSurface> GetSurfaceSnapshot(bool* aPremultAlpha = 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.
|
|
|
|
*/
|
2015-12-22 06:29:26 +03:00
|
|
|
nsresult RegisterFrameCaptureListener(FrameCaptureListener* aListener);
|
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.
|
|
|
|
*/
|
|
|
|
void SetFrameCapture(already_AddRefed<gfx::SourceSurface> aSurface);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual bool ParseAttribute(int32_t aNamespaceID,
|
2010-05-18 08:04:22 +04:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAttrValue& aResult) override;
|
|
|
|
nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute, int32_t aModType) const override;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
// SetAttr override. C++ is stupid, so have to override both
|
|
|
|
// overloaded methods.
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2011-09-29 10:19:26 +04:00
|
|
|
const nsAString& aValue, bool aNotify)
|
2010-05-18 08:04:22 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify);
|
2010-05-18 08:04:22 +04:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2010-05-18 08:04:22 +04:00
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aNotify) override;
|
2013-10-01 01:02:40 +04:00
|
|
|
|
|
|
|
virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aNotify) override;
|
2013-10-01 01:02:40 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;
|
2012-11-15 02:10:08 +04:00
|
|
|
nsresult CopyInnerTo(mozilla::dom::Element* aDest);
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult PreHandleEvent(mozilla::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);
|
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();
|
|
|
|
|
2015-10-12 06:21:02 +03:00
|
|
|
static void SetAttrFromAsyncCanvasRenderer(AsyncCanvasRenderer *aRenderer);
|
2015-10-12 06:21:03 +03:00
|
|
|
static void InvalidateFromAsyncCanvasRenderer(AsyncCanvasRenderer *aRenderer);
|
2015-10-12 06:21:02 +03:00
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
void StartVRPresentation();
|
|
|
|
void StopVRPresentation();
|
|
|
|
already_AddRefed<layers::SharedSurfaceTextureClient> GetVRFrame();
|
|
|
|
|
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
|
|
|
|
2013-10-17 06:55:08 +04:00
|
|
|
nsresult ExtractData(nsAString& aType,
|
2010-09-18 05:14:59 +04:00
|
|
|
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,
|
|
|
|
const nsAString& aMimeType,
|
|
|
|
const JS::Value& aEncoderOptions,
|
2010-05-18 08:04:22 +04:00
|
|
|
nsAString& aDataURL);
|
2015-05-12 15:11:03 +03:00
|
|
|
nsresult MozGetAsBlobImpl(const nsAString& aName,
|
2010-09-18 05:14:59 +04:00
|
|
|
const nsAString& aType,
|
2015-05-18 16:52:26 +03:00
|
|
|
nsISupports** aResult);
|
2012-08-31 21:45:45 +04:00
|
|
|
void CallPrintCallback();
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2015-10-12 06:21:02 +03:00
|
|
|
AsyncCanvasRenderer* GetAsyncCanvasRenderer();
|
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
bool mResetLayer;
|
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;
|
|
|
|
RefPtr<AsyncCanvasRenderer> mAsyncCanvasRenderer;
|
|
|
|
RefPtr<OffscreenCanvas> mOffscreenCanvas;
|
|
|
|
RefPtr<HTMLCanvasElementObserver> mContextObserver;
|
2016-02-25 02:54:50 +03:00
|
|
|
bool mVRPresentationActive;
|
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.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mWriteOnly;
|
2012-08-31 21:45:45 +04:00
|
|
|
|
|
|
|
bool IsPrintCallbackDone();
|
|
|
|
|
|
|
|
void HandlePrintCallback(nsPresContext::nsPresContextType aType);
|
|
|
|
|
|
|
|
nsresult DispatchPrintCallback(nsITimerCallback* aCallback);
|
|
|
|
|
|
|
|
void ResetPrintCallback();
|
|
|
|
|
2013-01-04 09:16:14 +04:00
|
|
|
HTMLCanvasElement* GetOriginalCanvas();
|
2015-07-30 21:47:00 +03:00
|
|
|
|
|
|
|
CanvasContextType GetCurrentContextType() {
|
|
|
|
return mCurrentContextType;
|
|
|
|
}
|
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 */
|