2012-06-13 15:14:15 +00: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/. */
|
|
|
|
|
2012-10-12 09:42:52 +00:00
|
|
|
#ifndef CanvasRenderingContext2D_h
|
|
|
|
#define CanvasRenderingContext2D_h
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-06-13 15:14:15 +00:00
|
|
|
#include <vector>
|
|
|
|
#include "nsICanvasRenderingContextInternal.h"
|
2015-10-18 05:24:48 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2012-06-13 15:14:15 +00:00
|
|
|
#include "nsColor.h"
|
2013-01-04 05:16:14 +00:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2013-03-19 12:27:35 +00:00
|
|
|
#include "mozilla/dom/HTMLVideoElement.h"
|
2012-06-13 15:14:15 +00:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2017-02-02 21:43:00 +00:00
|
|
|
#include "mozilla/dom/BasicRenderingContext2D.h"
|
2013-04-26 14:55:37 +00:00
|
|
|
#include "mozilla/dom/CanvasGradient.h"
|
2013-01-17 02:55:43 +00:00
|
|
|
#include "mozilla/dom/CanvasRenderingContext2DBinding.h"
|
2013-04-19 08:49:22 +00:00
|
|
|
#include "mozilla/dom/CanvasPattern.h"
|
2013-05-29 13:32:30 +00:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
2013-10-07 23:15:59 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2019-03-29 15:12:47 +00:00
|
|
|
#include "mozilla/PresShell.h"
|
2015-10-26 18:31:12 +00:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2013-10-07 23:15:59 +00:00
|
|
|
#include "gfx2DGlue.h"
|
2013-10-17 02:55:08 +00:00
|
|
|
#include "imgIEncoder.h"
|
2014-01-13 00:29:48 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2014-04-26 02:34:07 +00:00
|
|
|
#include "mozilla/EnumeratedArray.h"
|
2014-09-23 21:47:18 +00:00
|
|
|
#include "FilterSupport.h"
|
2017-08-30 13:14:46 +00:00
|
|
|
#include "SVGObserverUtils.h"
|
2015-06-18 23:07:21 +00:00
|
|
|
#include "Layers.h"
|
2017-02-26 01:40:09 +00:00
|
|
|
#include "nsBidi.h"
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2019-04-01 14:32:32 +00:00
|
|
|
class gfxFontGroup;
|
2017-11-03 22:25:38 +00:00
|
|
|
class nsGlobalWindowInner;
|
2013-01-29 17:51:55 +00:00
|
|
|
class nsXULElement;
|
2012-11-14 00:35:36 +00:00
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
namespace mozilla {
|
2014-07-11 22:10:49 +00:00
|
|
|
namespace gl {
|
2012-06-13 15:14:15 +00:00
|
|
|
class SourceSurface;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace gl
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2012-10-12 09:42:52 +00:00
|
|
|
namespace dom {
|
2017-07-19 15:48:49 +00:00
|
|
|
class
|
|
|
|
HTMLImageElementOrSVGImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap;
|
|
|
|
typedef HTMLImageElementOrSVGImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap
|
|
|
|
CanvasImageSource;
|
2018-11-06 22:31:34 +00:00
|
|
|
class ImageBitmap;
|
2013-08-23 05:17:11 +00:00
|
|
|
class ImageData;
|
2013-07-26 18:25:54 +00:00
|
|
|
class StringOrCanvasGradientOrCanvasPattern;
|
2013-09-17 15:16:02 +00:00
|
|
|
class OwningStringOrCanvasGradientOrCanvasPattern;
|
2013-04-19 08:49:22 +00:00
|
|
|
class TextMetrics;
|
2015-03-03 15:57:51 +00:00
|
|
|
class CanvasPath;
|
2013-04-19 08:49:22 +00:00
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
extern const mozilla::gfx::Float SIGMA_MAX;
|
|
|
|
|
2012-10-12 09:42:52 +00:00
|
|
|
template <typename T>
|
|
|
|
class Optional;
|
|
|
|
|
|
|
|
struct CanvasBidiProcessor;
|
|
|
|
class CanvasRenderingContext2DUserData;
|
2014-09-10 20:15:43 +00:00
|
|
|
class CanvasDrawObserver;
|
2016-07-01 08:58:18 +00:00
|
|
|
class CanvasShutdownObserver;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2019-07-11 06:14:58 +00:00
|
|
|
class DOMMatrix;
|
|
|
|
class DOMMatrixReadOnly;
|
|
|
|
struct DOMMatrix2DInit;
|
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
/**
|
2012-10-12 09:42:52 +00:00
|
|
|
** CanvasRenderingContext2D
|
2012-06-13 15:14:15 +00:00
|
|
|
**/
|
|
|
|
class CanvasRenderingContext2D final : public nsICanvasRenderingContextInternal,
|
2017-02-02 21:43:00 +00:00
|
|
|
public nsWrapperCache,
|
|
|
|
public BasicRenderingContext2D {
|
2014-06-26 13:30:49 +00:00
|
|
|
virtual ~CanvasRenderingContext2D();
|
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
public:
|
2016-11-03 14:57:33 +00:00
|
|
|
explicit CanvasRenderingContext2D(layers::LayersBackend aCompositorBackend);
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2012-05-21 21:30:07 +00:00
|
|
|
|
2013-01-04 05:16:14 +00:00
|
|
|
HTMLCanvasElement* GetCanvas() const {
|
2016-11-03 14:57:33 +00:00
|
|
|
if (!mCanvasElement || mCanvasElement->IsInNativeAnonymousSubtree()) {
|
2015-11-15 13:48:32 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-11-21 21:55:36 +00:00
|
|
|
// corresponds to changes to the old bindings made in bug 745025
|
|
|
|
return mCanvasElement->GetOriginalCanvas();
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void Save() override;
|
|
|
|
void Restore() override;
|
|
|
|
void Scale(double aX, double aY, mozilla::ErrorResult& aError) override;
|
|
|
|
void Rotate(double aAngle, mozilla::ErrorResult& aError) override;
|
|
|
|
void Translate(double aX, double aY, mozilla::ErrorResult& aError) override;
|
|
|
|
void Transform(double aM11, double aM12, double aM21, double aM22, double aDx,
|
|
|
|
double aDy, mozilla::ErrorResult& aError) override;
|
2019-07-11 22:36:44 +00:00
|
|
|
already_AddRefed<DOMMatrix> GetTransform(
|
|
|
|
mozilla::ErrorResult& aError) override;
|
2017-02-02 21:43:00 +00:00
|
|
|
void SetTransform(double aM11, double aM12, double aM21, double aM22,
|
|
|
|
double aDx, double aDy,
|
|
|
|
mozilla::ErrorResult& aError) override;
|
2019-07-11 06:14:58 +00:00
|
|
|
void SetTransform(const DOMMatrix2DInit& aInit,
|
|
|
|
mozilla::ErrorResult& aError) override;
|
2017-02-02 21:43:00 +00:00
|
|
|
void ResetTransform(mozilla::ErrorResult& aError) override;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
|
|
|
double GlobalAlpha() override { return CurrentState().globalAlpha; }
|
|
|
|
|
2013-01-29 01:39:47 +00:00
|
|
|
// Useful for silencing cast warnings
|
|
|
|
static mozilla::gfx::Float ToFloat(double aValue) {
|
|
|
|
return mozilla::gfx::Float(aValue);
|
|
|
|
}
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void SetGlobalAlpha(double aGlobalAlpha) override {
|
2016-02-01 08:39:08 +00:00
|
|
|
if (aGlobalAlpha >= 0.0 && aGlobalAlpha <= 1.0) {
|
|
|
|
CurrentState().globalAlpha = ToFloat(aGlobalAlpha);
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void GetGlobalCompositeOperation(nsAString& aOp,
|
|
|
|
mozilla::ErrorResult& aError) override;
|
2016-02-01 08:39:08 +00:00
|
|
|
void SetGlobalCompositeOperation(const nsAString& aOp,
|
2017-02-02 21:43:00 +00:00
|
|
|
mozilla::ErrorResult& aError) override;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void GetStrokeStyle(
|
|
|
|
OwningStringOrCanvasGradientOrCanvasPattern& aValue) override {
|
2016-02-01 08:39:08 +00:00
|
|
|
GetStyleAsUnion(aValue, Style::STROKE);
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void SetStrokeStyle(
|
|
|
|
const StringOrCanvasGradientOrCanvasPattern& aValue) override {
|
2016-02-01 08:39:08 +00:00
|
|
|
SetStyleFromUnion(aValue, Style::STROKE);
|
2013-07-26 18:25:54 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void GetFillStyle(
|
|
|
|
OwningStringOrCanvasGradientOrCanvasPattern& aValue) override {
|
2016-02-01 08:39:08 +00:00
|
|
|
GetStyleAsUnion(aValue, Style::FILL);
|
2013-07-26 18:25:54 +00:00
|
|
|
}
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void SetFillStyle(
|
|
|
|
const StringOrCanvasGradientOrCanvasPattern& aValue) override {
|
2016-02-01 08:39:08 +00:00
|
|
|
SetStyleFromUnion(aValue, Style::FILL);
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
already_AddRefed<CanvasGradient> CreateLinearGradient(double aX0, double aY0,
|
|
|
|
double aX1,
|
|
|
|
double aY1) override;
|
2013-04-26 14:55:54 +00:00
|
|
|
already_AddRefed<CanvasGradient> CreateRadialGradient(
|
2017-02-02 21:43:00 +00:00
|
|
|
double aX0, double aY0, double aR0, double aX1, double aY1, double aR1,
|
|
|
|
ErrorResult& aError) override;
|
2013-04-19 08:49:22 +00:00
|
|
|
already_AddRefed<CanvasPattern> CreatePattern(
|
2016-02-01 08:39:08 +00:00
|
|
|
const CanvasImageSource& aElement, const nsAString& aRepeat,
|
2017-02-02 21:43:00 +00:00
|
|
|
ErrorResult& aError) override;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
double ShadowOffsetX() override { return CurrentState().shadowOffset.x; }
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void SetShadowOffsetX(double aShadowOffsetX) override {
|
2016-02-01 08:39:08 +00:00
|
|
|
CurrentState().shadowOffset.x = ToFloat(aShadowOffsetX);
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double ShadowOffsetY() override { return CurrentState().shadowOffset.y; }
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void SetShadowOffsetY(double aShadowOffsetY) override {
|
2016-02-01 08:39:08 +00:00
|
|
|
CurrentState().shadowOffset.y = ToFloat(aShadowOffsetY);
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double ShadowBlur() override { return CurrentState().shadowBlur; }
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void SetShadowBlur(double aShadowBlur) override {
|
2016-02-01 08:39:08 +00:00
|
|
|
if (aShadowBlur >= 0.0) {
|
|
|
|
CurrentState().shadowBlur = ToFloat(aShadowBlur);
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void GetShadowColor(nsAString& aShadowColor) override {
|
2016-02-01 08:39:08 +00:00
|
|
|
StyleColorToString(CurrentState().shadowColor, aShadowColor);
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
void GetFilter(nsAString& aFilter) { aFilter = CurrentState().filterString; }
|
2014-09-23 21:44:53 +00:00
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void SetShadowColor(const nsAString& aShadowColor) override;
|
2016-02-01 08:39:08 +00:00
|
|
|
void SetFilter(const nsAString& aFilter, mozilla::ErrorResult& aError);
|
2017-02-02 21:43:00 +00:00
|
|
|
void ClearRect(double aX, double aY, double aW, double aH) override;
|
|
|
|
void FillRect(double aX, double aY, double aW, double aH) override;
|
|
|
|
void StrokeRect(double aX, double aY, double aW, double aH) override;
|
2012-06-13 15:14:15 +00:00
|
|
|
void BeginPath();
|
2016-02-01 08:39:08 +00:00
|
|
|
void Fill(const CanvasWindingRule& aWinding);
|
|
|
|
void Fill(const CanvasPath& aPath, const CanvasWindingRule& aWinding);
|
2012-06-13 15:14:15 +00:00
|
|
|
void Stroke();
|
2016-02-01 08:39:08 +00:00
|
|
|
void Stroke(const CanvasPath& aPath);
|
|
|
|
void DrawFocusIfNeeded(mozilla::dom::Element& aElement, ErrorResult& aRv);
|
|
|
|
bool DrawCustomFocusRing(mozilla::dom::Element& aElement);
|
|
|
|
void Clip(const CanvasWindingRule& aWinding);
|
|
|
|
void Clip(const CanvasPath& aPath, const CanvasWindingRule& aWinding);
|
2018-05-14 18:49:32 +00:00
|
|
|
bool IsPointInPath(JSContext* aCx, double aX, double aY,
|
|
|
|
const CanvasWindingRule& aWinding,
|
|
|
|
nsIPrincipal& aSubjectPrincipal);
|
|
|
|
bool IsPointInPath(JSContext* aCx, const CanvasPath& aPath, double aX,
|
|
|
|
double aY, const CanvasWindingRule& aWinding,
|
|
|
|
nsIPrincipal&);
|
|
|
|
bool IsPointInStroke(JSContext* aCx, double aX, double aY,
|
|
|
|
nsIPrincipal& aSubjectPrincipal);
|
|
|
|
bool IsPointInStroke(JSContext* aCx, const CanvasPath& aPath, double aX,
|
|
|
|
double aY, nsIPrincipal&);
|
2016-02-01 08:39:08 +00:00
|
|
|
void FillText(const nsAString& aText, double aX, double aY,
|
|
|
|
const Optional<double>& aMaxWidth,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
void StrokeText(const nsAString& aText, double aX, double aY,
|
|
|
|
const Optional<double>& aMaxWidth,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
TextMetrics* MeasureText(const nsAString& aRawText,
|
|
|
|
mozilla::ErrorResult& aError);
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
void AddHitRegion(const HitRegionOptions& aOptions,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
void RemoveHitRegion(const nsAString& aId);
|
2015-01-09 14:41:00 +00:00
|
|
|
void ClearHitRegions();
|
2014-02-21 13:35:14 +00:00
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void DrawImage(const CanvasImageSource& aImage, double aDx, double aDy,
|
|
|
|
mozilla::ErrorResult& aError) override {
|
2016-02-01 08:39:08 +00:00
|
|
|
DrawImage(aImage, 0.0, 0.0, 0.0, 0.0, aDx, aDy, 0.0, 0.0, 0, aError);
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void DrawImage(const CanvasImageSource& aImage, double aDx, double aDy,
|
|
|
|
double aDw, double aDh,
|
|
|
|
mozilla::ErrorResult& aError) override {
|
2016-02-01 08:39:08 +00:00
|
|
|
DrawImage(aImage, 0.0, 0.0, 0.0, 0.0, aDx, aDy, aDw, aDh, 2, aError);
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
void DrawImage(const CanvasImageSource& aImage, double aSx, double aSy,
|
2017-02-02 21:43:00 +00:00
|
|
|
double aSw, double aSh, double aDx, double aDy, double aDw,
|
|
|
|
double aDh, mozilla::ErrorResult& aError) override {
|
2016-02-01 08:39:08 +00:00
|
|
|
DrawImage(aImage, aSx, aSy, aSw, aSh, aDx, aDy, aDw, aDh, 6, aError);
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
already_AddRefed<ImageData> CreateImageData(JSContext* aCx, double aSw,
|
|
|
|
double aSh,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
already_AddRefed<ImageData> CreateImageData(JSContext* aCx,
|
|
|
|
ImageData& aImagedata,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
already_AddRefed<ImageData> GetImageData(JSContext* aCx, double aSx,
|
|
|
|
double aSy, double aSw, double aSh,
|
2018-05-14 18:49:32 +00:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-02-01 08:39:08 +00:00
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
void PutImageData(ImageData& aImageData, double aDx, double aDy,
|
|
|
|
mozilla::ErrorResult& aError);
|
2017-02-02 21:43:00 +00:00
|
|
|
void PutImageData(ImageData& aImageData, double aDx, double aDy,
|
2016-02-01 08:39:08 +00:00
|
|
|
double aDirtyX, double aDirtyY, double aDirtyWidth,
|
2017-02-02 21:43:00 +00:00
|
|
|
double aDirtyHeight, mozilla::ErrorResult& aError);
|
2012-06-13 15:14:15 +00:00
|
|
|
|
|
|
|
double LineWidth() override { return CurrentState().lineWidth; }
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void SetLineWidth(double aWidth) override {
|
2016-02-01 08:39:08 +00:00
|
|
|
if (aWidth > 0.0) {
|
|
|
|
CurrentState().lineWidth = ToFloat(aWidth);
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-02 21:43:00 +00:00
|
|
|
void GetLineCap(nsAString& aLinecapStyle) override;
|
|
|
|
void SetLineCap(const nsAString& aLinecapStyle) override;
|
|
|
|
void GetLineJoin(nsAString& aLinejoinStyle,
|
|
|
|
mozilla::ErrorResult& aError) override;
|
|
|
|
void SetLineJoin(const nsAString& aLinejoinStyle) override;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
|
|
|
double MiterLimit() override { return CurrentState().miterLimit; }
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void SetMiterLimit(double aMiter) override {
|
2016-02-01 08:39:08 +00:00
|
|
|
if (aMiter > 0.0) {
|
|
|
|
CurrentState().miterLimit = ToFloat(aMiter);
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
void GetFont(nsAString& aFont) { aFont = GetFont(); }
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
void SetFont(const nsAString& aFont, mozilla::ErrorResult& aError);
|
|
|
|
void GetTextAlign(nsAString& aTextAlign);
|
|
|
|
void SetTextAlign(const nsAString& aTextAlign);
|
|
|
|
void GetTextBaseline(nsAString& aTextBaseline);
|
|
|
|
void SetTextBaseline(const nsAString& aTextBaseline);
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void ClosePath() override {
|
2012-06-13 15:14:15 +00:00
|
|
|
EnsureWritablePath();
|
|
|
|
|
|
|
|
if (mPathBuilder) {
|
|
|
|
mPathBuilder->Close();
|
|
|
|
} else {
|
|
|
|
mDSPathBuilder->Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void MoveTo(double aX, double aY) override {
|
2012-11-27 20:32:05 +00:00
|
|
|
EnsureWritablePath();
|
|
|
|
|
|
|
|
if (mPathBuilder) {
|
2016-02-01 08:39:08 +00:00
|
|
|
mPathBuilder->MoveTo(mozilla::gfx::Point(ToFloat(aX), ToFloat(aY)));
|
2012-11-27 20:32:05 +00:00
|
|
|
} else {
|
2016-09-08 16:26:03 +00:00
|
|
|
mDSPathBuilder->MoveTo(mTarget->GetTransform().TransformPoint(
|
|
|
|
mozilla::gfx::Point(ToFloat(aX), ToFloat(aY))));
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void LineTo(double aX, double aY) override {
|
2012-11-27 20:32:05 +00:00
|
|
|
EnsureWritablePath();
|
2013-07-26 18:25:54 +00:00
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
LineTo(mozilla::gfx::Point(ToFloat(aX), ToFloat(aY)));
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void QuadraticCurveTo(double aCpx, double aCpy, double aX,
|
|
|
|
double aY) override {
|
2012-11-27 20:32:05 +00:00
|
|
|
EnsureWritablePath();
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2012-11-27 20:32:05 +00:00
|
|
|
if (mPathBuilder) {
|
2016-02-01 08:39:08 +00:00
|
|
|
mPathBuilder->QuadraticBezierTo(
|
|
|
|
mozilla::gfx::Point(ToFloat(aCpx), ToFloat(aCpy)),
|
|
|
|
mozilla::gfx::Point(ToFloat(aX), ToFloat(aY)));
|
2012-11-27 20:32:05 +00:00
|
|
|
} else {
|
|
|
|
mozilla::gfx::Matrix transform = mTarget->GetTransform();
|
2016-09-08 16:26:03 +00:00
|
|
|
mDSPathBuilder->QuadraticBezierTo(
|
|
|
|
transform.TransformPoint(
|
|
|
|
mozilla::gfx::Point(ToFloat(aCpx), ToFloat(aCpy))),
|
|
|
|
transform.TransformPoint(
|
|
|
|
mozilla::gfx::Point(ToFloat(aX), ToFloat(aY))));
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void BezierCurveTo(double aCp1x, double aCp1y, double aCp2x, double aCp2y,
|
|
|
|
double aX, double aY) override {
|
2012-11-27 20:32:05 +00:00
|
|
|
EnsureWritablePath();
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
BezierTo(mozilla::gfx::Point(ToFloat(aCp1x), ToFloat(aCp1y)),
|
|
|
|
mozilla::gfx::Point(ToFloat(aCp2x), ToFloat(aCp2y)),
|
|
|
|
mozilla::gfx::Point(ToFloat(aX), ToFloat(aY)));
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void ArcTo(double aX1, double aY1, double aX2, double aY2, double aRadius,
|
|
|
|
mozilla::ErrorResult& aError) override;
|
|
|
|
void Rect(double aX, double aY, double aW, double aH) override;
|
2016-02-01 08:39:08 +00:00
|
|
|
void Arc(double aX, double aY, double aRadius, double aStartAngle,
|
2017-02-02 21:43:00 +00:00
|
|
|
double aEndAngle, bool aAnticlockwise,
|
|
|
|
mozilla::ErrorResult& aError) override;
|
2016-03-14 23:53:00 +00:00
|
|
|
void Ellipse(double aX, double aY, double aRadiusX, double aRadiusY,
|
|
|
|
double aRotation, double aStartAngle, double aEndAngle,
|
2017-02-02 21:43:00 +00:00
|
|
|
bool aAnticlockwise, ErrorResult& aError) override;
|
2016-02-01 08:39:08 +00:00
|
|
|
|
|
|
|
void GetMozCurrentTransform(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JSObject*> aResult,
|
2016-10-03 03:55:00 +00:00
|
|
|
mozilla::ErrorResult& aError);
|
2016-02-01 08:39:08 +00:00
|
|
|
void SetMozCurrentTransform(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aCurrentTransform,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
void GetMozCurrentTransformInverse(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JSObject*> aResult,
|
2016-10-03 03:55:00 +00:00
|
|
|
mozilla::ErrorResult& aError);
|
2016-02-01 08:39:08 +00:00
|
|
|
void SetMozCurrentTransformInverse(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aCurrentTransform,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
void GetFillRule(nsAString& aFillRule);
|
|
|
|
void SetFillRule(const nsAString& aFillRule);
|
|
|
|
|
|
|
|
void SetLineDash(const Sequence<double>& aSegments,
|
2017-02-02 21:43:00 +00:00
|
|
|
mozilla::ErrorResult& aRv) override;
|
|
|
|
void GetLineDash(nsTArray<double>& aSegments) const override;
|
2013-10-16 12:27:59 +00:00
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void SetLineDashOffset(double aOffset) override;
|
|
|
|
double LineDashOffset() const override;
|
2013-10-16 12:27:59 +00:00
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
void GetMozTextStyle(nsAString& aMozTextStyle) { GetFont(aMozTextStyle); }
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
void SetMozTextStyle(const nsAString& aMozTextStyle,
|
|
|
|
mozilla::ErrorResult& aError) {
|
|
|
|
SetFont(aMozTextStyle, aError);
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
bool ImageSmoothingEnabled() override {
|
2012-06-13 15:14:15 +00:00
|
|
|
return CurrentState().imageSmoothingEnabled;
|
|
|
|
}
|
|
|
|
|
2017-02-02 21:43:00 +00:00
|
|
|
void SetImageSmoothingEnabled(bool aImageSmoothingEnabled) override {
|
2016-02-01 08:39:08 +00:00
|
|
|
if (aImageSmoothingEnabled != CurrentState().imageSmoothingEnabled) {
|
|
|
|
CurrentState().imageSmoothingEnabled = aImageSmoothingEnabled;
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-06 22:52:14 +00:00
|
|
|
void DrawWindow(nsGlobalWindowInner& aWindow, double aX, double aY, double aW,
|
2016-02-01 08:39:08 +00:00
|
|
|
double aH, const nsAString& aBgColor, uint32_t aFlags,
|
|
|
|
mozilla::ErrorResult& aError);
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2014-09-02 23:26:36 +00:00
|
|
|
// Eventually this should be deprecated. Keeping for now to keep the binding
|
|
|
|
// functional.
|
2013-08-23 13:52:32 +00:00
|
|
|
void Demote();
|
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
nsresult Redraw();
|
|
|
|
|
2016-09-01 13:51:09 +00:00
|
|
|
gfx::IntSize GetSize() const { return gfx::IntSize(mWidth, mHeight); }
|
2017-12-22 01:14:54 +00:00
|
|
|
virtual int32_t GetWidth() override { return GetSize().width; }
|
|
|
|
virtual int32_t GetHeight() override { return GetSize().height; }
|
2015-10-02 07:18:26 +00:00
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
// nsICanvasRenderingContextInternal
|
2014-09-10 01:40:51 +00:00
|
|
|
/**
|
|
|
|
* Gets the pres shell from either the canvas element or the doc shell
|
|
|
|
*/
|
2019-04-13 01:03:13 +00:00
|
|
|
PresShell* GetPresShell() final {
|
2014-09-10 01:40:51 +00:00
|
|
|
if (mCanvasElement) {
|
2019-03-29 15:12:47 +00:00
|
|
|
return mCanvasElement->OwnerDoc()->GetPresShell();
|
2014-09-10 01:40:51 +00:00
|
|
|
}
|
|
|
|
if (mDocShell) {
|
|
|
|
return mDocShell->GetPresShell();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-02-01 08:39:08 +00:00
|
|
|
NS_IMETHOD SetDimensions(int32_t aWidth, int32_t aHeight) override;
|
2016-04-21 09:30:38 +00:00
|
|
|
NS_IMETHOD InitializeWithDrawTarget(
|
2016-08-23 08:41:21 +00:00
|
|
|
nsIDocShell* aShell, NotNull<gfx::DrawTarget*> aTarget) override;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
|
|
|
NS_IMETHOD GetInputStream(const char* aMimeType,
|
2019-04-08 01:51:17 +00:00
|
|
|
const nsAString& aEncoderOptions,
|
2016-02-01 08:39:08 +00:00
|
|
|
nsIInputStream** aStream) override;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2017-04-12 09:55:23 +00:00
|
|
|
already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(
|
2018-12-02 14:19:11 +00:00
|
|
|
gfxAlphaType* aOutAlphaType = nullptr) override;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2018-05-02 15:23:53 +00:00
|
|
|
virtual void SetOpaqueValueFromOpaqueAttr(bool aOpaqueAttrValue) override;
|
2015-03-21 16:28:04 +00:00
|
|
|
bool GetIsOpaque() override { return mOpaque; }
|
|
|
|
NS_IMETHOD Reset() override;
|
2015-12-18 06:52:17 +00:00
|
|
|
already_AddRefed<Layer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
|
2016-02-01 08:39:08 +00:00
|
|
|
Layer* aOldLayer,
|
2017-09-15 22:06:56 +00:00
|
|
|
LayerManager* aManager) override;
|
2017-10-28 10:07:27 +00:00
|
|
|
|
|
|
|
bool UpdateWebRenderCanvasData(nsDisplayListBuilder* aBuilder,
|
|
|
|
WebRenderCanvasData* aCanvasData) override;
|
|
|
|
|
2017-08-18 07:13:29 +00:00
|
|
|
bool InitializeCanvasRenderer(nsDisplayListBuilder* aBuilder,
|
2017-09-15 22:06:56 +00:00
|
|
|
CanvasRenderer* aRenderer) override;
|
2016-02-01 08:39:08 +00:00
|
|
|
virtual bool ShouldForceInactiveLayer(LayerManager* aManager) override;
|
2015-03-21 16:28:04 +00:00
|
|
|
void MarkContextClean() override;
|
2015-09-17 03:37:05 +00:00
|
|
|
void MarkContextCleanForFrameCapture() override;
|
|
|
|
bool IsContextCleanForFrameCapture() override;
|
2016-02-01 08:39:08 +00:00
|
|
|
NS_IMETHOD SetIsIPC(bool aIsIPC) override;
|
2012-06-13 15:14:15 +00:00
|
|
|
// this rect is in canvas device space
|
2016-02-01 08:39:08 +00:00
|
|
|
void Redraw(const mozilla::gfx::Rect& aR);
|
|
|
|
NS_IMETHOD Redraw(const gfxRect& aR) override {
|
|
|
|
Redraw(ToRect(aR));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-10-18 11:14:22 +00:00
|
|
|
NS_IMETHOD SetContextOptions(JSContext* aCx, JS::Handle<JS::Value> aOptions,
|
|
|
|
ErrorResult& aRvForDictionaryInit) override;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2014-09-10 01:40:51 +00:00
|
|
|
/**
|
|
|
|
* An abstract base class to be implemented by callers wanting to be notified
|
|
|
|
* that a refresh has occurred. Callers must ensure an observer is removed
|
|
|
|
* before it is destroyed.
|
|
|
|
*/
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void DidRefresh() override;
|
2014-09-10 01:40:51 +00:00
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
// this rect is in mTarget's current user space
|
2016-02-01 08:39:08 +00:00
|
|
|
void RedrawUser(const gfxRect& aR);
|
2012-06-13 15:14:15 +00:00
|
|
|
|
|
|
|
// nsISupports interface + CC
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
|
2012-11-14 00:35:36 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(
|
|
|
|
CanvasRenderingContext2D)
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2015-01-25 22:22:08 +00:00
|
|
|
enum class CanvasMultiGetterType : uint8_t {
|
2014-04-26 02:34:07 +00:00
|
|
|
STRING = 0,
|
|
|
|
PATTERN = 1,
|
|
|
|
GRADIENT = 2
|
2015-01-25 22:22:08 +00:00
|
|
|
};
|
2014-04-26 02:34:07 +00:00
|
|
|
|
2015-01-25 22:22:08 +00:00
|
|
|
enum class Style : uint8_t { STROKE = 0, FILL, MAX };
|
2012-06-13 15:14:15 +00:00
|
|
|
|
|
|
|
nsINode* GetParentObject() { return mCanvasElement; }
|
|
|
|
|
|
|
|
void LineTo(const mozilla::gfx::Point& aPoint) {
|
|
|
|
if (mPathBuilder) {
|
|
|
|
mPathBuilder->LineTo(aPoint);
|
|
|
|
} else {
|
2016-09-08 16:26:03 +00:00
|
|
|
mDSPathBuilder->LineTo(mTarget->GetTransform().TransformPoint(aPoint));
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BezierTo(const mozilla::gfx::Point& aCP1,
|
|
|
|
const mozilla::gfx::Point& aCP2,
|
|
|
|
const mozilla::gfx::Point& aCP3) {
|
|
|
|
if (mPathBuilder) {
|
|
|
|
mPathBuilder->BezierTo(aCP1, aCP2, aCP3);
|
|
|
|
} else {
|
|
|
|
mozilla::gfx::Matrix transform = mTarget->GetTransform();
|
2016-09-08 16:26:03 +00:00
|
|
|
mDSPathBuilder->BezierTo(transform.TransformPoint(aCP1),
|
|
|
|
transform.TransformPoint(aCP2),
|
|
|
|
transform.TransformPoint(aCP3));
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 09:42:52 +00:00
|
|
|
friend class CanvasRenderingContext2DUserData;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2015-10-26 18:31:12 +00:00
|
|
|
virtual UniquePtr<uint8_t[]> GetImageBuffer(int32_t* aFormat) override;
|
2013-10-17 02:55:08 +00:00
|
|
|
|
2014-05-20 04:54:00 +00:00
|
|
|
// Given a point, return hit region ID if it exists
|
2015-03-21 16:28:04 +00:00
|
|
|
nsString GetHitRegion(const mozilla::gfx::Point& aPoint) override;
|
2014-05-20 04:54:00 +00:00
|
|
|
|
2014-05-18 23:43:00 +00:00
|
|
|
// return true and fills in the bound rect if element has a hit region.
|
2015-03-21 16:28:04 +00:00
|
|
|
bool GetHitRegionRect(Element* aElement, nsRect& aRect) override;
|
2014-05-18 23:43:00 +00:00
|
|
|
|
2016-07-01 08:58:18 +00:00
|
|
|
void OnShutdown();
|
2016-11-03 14:57:33 +00:00
|
|
|
|
2018-09-03 10:24:27 +00:00
|
|
|
/**
|
|
|
|
* Update CurrentState().filter with the filter description for
|
|
|
|
* CurrentState().filterChain.
|
|
|
|
* Flushes the PresShell, so the world can change if you call this function.
|
|
|
|
*/
|
2019-04-13 12:43:57 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY void UpdateFilter();
|
2018-09-03 10:24:27 +00:00
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
protected:
|
|
|
|
nsresult GetImageDataArray(JSContext* aCx, int32_t aX, int32_t aY,
|
|
|
|
uint32_t aWidth, uint32_t aHeight,
|
2018-05-14 18:49:32 +00:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2012-06-13 15:14:15 +00:00
|
|
|
JSObject** aRetval);
|
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
nsresult PutImageData_explicit(int32_t aX, int32_t aY, uint32_t aW,
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-27 21:32:41 +00:00
|
|
|
uint32_t aH, dom::Uint8ClampedArray* aArray,
|
2016-02-01 08:39:08 +00:00
|
|
|
bool aHasDirtyRect, int32_t aDirtyX,
|
|
|
|
int32_t aDirtyY, int32_t aDirtyWidth,
|
|
|
|
int32_t aDirtyHeight);
|
2012-11-14 00:35:36 +00:00
|
|
|
|
2016-11-24 14:08:10 +00:00
|
|
|
bool CopyBufferProvider(layers::PersistentBufferProvider& aOld,
|
|
|
|
gfx::DrawTarget& aTarget, gfx::IntRect aCopyRect);
|
|
|
|
|
2012-07-24 10:18:39 +00:00
|
|
|
/**
|
|
|
|
* Internal method to complete initialisation, expects mTarget to have been
|
|
|
|
* set
|
|
|
|
*/
|
2016-02-01 08:39:08 +00:00
|
|
|
nsresult Initialize(int32_t aWidth, int32_t aHeight);
|
2012-07-24 10:18:39 +00:00
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
nsresult InitializeWithTarget(mozilla::gfx::DrawTarget* aSurface,
|
|
|
|
int32_t aWidth, int32_t aHeight);
|
2012-06-13 15:14:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The number of living nsCanvasRenderingContexts. When this goes down to
|
|
|
|
* 0, we free the premultiply and unpremultiply tables, if they exist.
|
|
|
|
*/
|
2017-05-03 14:40:51 +00:00
|
|
|
static uintptr_t sNumLivingContexts;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2012-05-31 00:47:27 +00:00
|
|
|
static mozilla::gfx::DrawTarget* sErrorTarget;
|
|
|
|
|
2016-08-10 12:30:51 +00:00
|
|
|
void SetTransformInternal(const mozilla::gfx::Matrix& aTransform);
|
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
// Some helpers. Doesn't modify a color on failure.
|
2016-02-01 08:39:08 +00:00
|
|
|
void SetStyleFromUnion(const StringOrCanvasGradientOrCanvasPattern& aValue,
|
|
|
|
Style aWhichStyle);
|
|
|
|
void SetStyleFromString(const nsAString& aStr, Style aWhichStyle);
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
void SetStyleFromGradient(CanvasGradient& aGradient, Style aWhichStyle) {
|
|
|
|
CurrentState().SetGradientStyle(aWhichStyle, &aGradient);
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
void SetStyleFromPattern(CanvasPattern& aPattern, Style aWhichStyle) {
|
|
|
|
CurrentState().SetPatternStyle(aWhichStyle, &aPattern);
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
2013-09-17 15:16:02 +00:00
|
|
|
void GetStyleAsUnion(OwningStringOrCanvasGradientOrCanvasPattern& aValue,
|
2013-07-26 18:25:54 +00:00
|
|
|
Style aWhichStyle);
|
2012-06-13 15:14:15 +00:00
|
|
|
|
|
|
|
// Returns whether a color was successfully parsed.
|
|
|
|
bool ParseColor(const nsAString& aString, nscolor* aColor);
|
|
|
|
|
|
|
|
static void StyleColorToString(const nscolor& aColor, nsAString& aStr);
|
|
|
|
|
2014-09-23 21:46:11 +00:00
|
|
|
// Returns whether a filter was successfully parsed.
|
|
|
|
bool ParseFilter(const nsAString& aString,
|
2019-05-27 12:37:37 +00:00
|
|
|
StyleOwnedSlice<StyleFilter>& aFilterChain,
|
|
|
|
ErrorResult& aError);
|
2014-09-23 21:46:11 +00:00
|
|
|
|
2015-07-14 20:59:12 +00:00
|
|
|
// Returns whether the font was successfully updated.
|
2016-02-01 08:39:08 +00:00
|
|
|
bool SetFontInternal(const nsAString& aFont, mozilla::ErrorResult& aError);
|
2015-07-14 20:59:12 +00:00
|
|
|
|
2018-05-02 15:23:53 +00:00
|
|
|
// Clears the target and updates mOpaque based on mOpaqueAttrValue and
|
|
|
|
// mContextAttributesHasAlpha.
|
|
|
|
void UpdateIsOpaque();
|
2015-07-14 20:59:12 +00:00
|
|
|
|
2012-05-31 00:47:27 +00:00
|
|
|
/**
|
|
|
|
* Creates the error target, if it doesn't exist
|
|
|
|
*/
|
|
|
|
static void EnsureErrorTarget();
|
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
/* This function ensures there is a writable pathbuilder available, this
|
|
|
|
* pathbuilder may be working in user space or in device space or
|
|
|
|
* device space.
|
2012-07-24 10:18:38 +00:00
|
|
|
* After calling this function mPathTransformWillUpdate will be false
|
2012-06-13 15:14:15 +00:00
|
|
|
*/
|
|
|
|
void EnsureWritablePath();
|
|
|
|
|
|
|
|
// Ensures a path in UserSpace is available.
|
2016-02-01 08:39:08 +00:00
|
|
|
void EnsureUserSpacePath(
|
|
|
|
const CanvasWindingRule& aWinding = CanvasWindingRule::Nonzero);
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2012-05-31 00:47:27 +00:00
|
|
|
/**
|
|
|
|
* Needs to be called before updating the transform. This makes a call to
|
|
|
|
* EnsureTarget() so you don't have to.
|
|
|
|
*/
|
2012-06-13 15:14:15 +00:00
|
|
|
void TransformWillUpdate();
|
|
|
|
|
|
|
|
// Report the fillRule has changed.
|
|
|
|
void FillRuleChanged();
|
|
|
|
|
2012-05-31 00:47:27 +00:00
|
|
|
/**
|
|
|
|
* Create the backing surfacing, if it doesn't exist. If there is an error
|
|
|
|
* in creating the target then it will put sErrorTarget in place. If there
|
|
|
|
* is in turn an error in creating the sErrorTarget then they would both
|
|
|
|
* be null so IsTargetValid() would still return null.
|
2014-09-02 23:26:36 +00:00
|
|
|
*
|
2019-02-28 14:58:19 +00:00
|
|
|
* Returns true on success.
|
2012-05-31 00:47:27 +00:00
|
|
|
*/
|
2019-03-01 17:23:02 +00:00
|
|
|
bool EnsureTarget(const gfx::Rect* aCoveredRect = nullptr,
|
|
|
|
bool aWillClear = false);
|
2012-05-31 00:47:27 +00:00
|
|
|
|
2016-08-26 12:31:58 +00:00
|
|
|
void RestoreClipsAndTransformToTarget();
|
|
|
|
|
2016-09-01 13:51:09 +00:00
|
|
|
bool TrySharedTarget(RefPtr<gfx::DrawTarget>& aOutDT,
|
|
|
|
RefPtr<layers::PersistentBufferProvider>& aOutProvider);
|
|
|
|
|
|
|
|
bool TryBasicTarget(RefPtr<gfx::DrawTarget>& aOutDT,
|
|
|
|
RefPtr<layers::PersistentBufferProvider>& aOutProvider);
|
|
|
|
|
|
|
|
void RegisterAllocation();
|
|
|
|
|
|
|
|
void SetInitialState();
|
|
|
|
|
|
|
|
void SetErrorState();
|
|
|
|
|
2016-07-01 08:58:20 +00:00
|
|
|
/**
|
|
|
|
* This method is run at the end of the event-loop spin where
|
|
|
|
* ScheduleStableStateCallback was called.
|
|
|
|
*
|
|
|
|
* We use it to unlock resources that need to be locked while drawing.
|
|
|
|
*/
|
|
|
|
void OnStableState();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cf. OnStableState.
|
|
|
|
*/
|
|
|
|
void ScheduleStableStateCallback();
|
|
|
|
|
2015-07-14 20:59:12 +00:00
|
|
|
/**
|
2012-05-31 00:47:27 +00:00
|
|
|
* Disposes an old target and prepares to lazily create a new target.
|
2018-05-17 08:49:58 +00:00
|
|
|
*
|
|
|
|
* Parameters are the new dimensions to be used, or if either is negative,
|
|
|
|
* existing dimensions will be left unchanged.
|
2012-05-31 00:47:27 +00:00
|
|
|
*/
|
2018-05-17 08:49:58 +00:00
|
|
|
void ClearTarget(int32_t aWidth = -1, int32_t aHeight = -1);
|
2012-05-31 00:47:27 +00:00
|
|
|
|
2015-06-18 23:07:21 +00:00
|
|
|
/*
|
|
|
|
* Returns the target to the buffer provider. i.e. this will queue a frame for
|
|
|
|
* rendering.
|
|
|
|
*/
|
2016-08-19 10:00:26 +00:00
|
|
|
void ReturnTarget(bool aForceReset = false);
|
2015-06-18 23:07:21 +00:00
|
|
|
|
2012-05-31 00:47:27 +00:00
|
|
|
/**
|
|
|
|
* Check if the target is valid after calling EnsureTarget.
|
|
|
|
*/
|
2016-11-28 19:32:49 +00:00
|
|
|
bool IsTargetValid() const { return !!mTarget && mTarget != sErrorTarget; }
|
2012-05-31 00:47:27 +00:00
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
/**
|
|
|
|
* Returns the surface format this canvas should be allocated using. Takes
|
|
|
|
* into account mOpaque, platform requirements, etc.
|
|
|
|
*/
|
|
|
|
mozilla::gfx::SurfaceFormat GetSurfaceFormat() const;
|
|
|
|
|
2016-07-01 08:58:06 +00:00
|
|
|
/**
|
|
|
|
* Returns true if we know for sure that the pattern for a given style is
|
|
|
|
* opaque. Usefull to know if we can discard the content below in certain
|
2019-03-01 17:23:02 +00:00
|
|
|
* situations. Optionally checks if the pattern is a color pattern.
|
2016-07-01 08:58:06 +00:00
|
|
|
*/
|
2019-03-01 17:23:02 +00:00
|
|
|
bool PatternIsOpaque(Style aStyle, bool* aIsColor = nullptr) const;
|
2016-07-01 08:58:06 +00:00
|
|
|
|
2014-10-29 15:17:00 +00:00
|
|
|
nsLayoutUtils::SurfaceFromElementResult CachedSurfaceFromElement(
|
|
|
|
Element* aElement);
|
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
void DrawImage(const CanvasImageSource& aImgElt, double aSx, double aSy,
|
|
|
|
double aSw, double aSh, double aDx, double aDy, double aDw,
|
|
|
|
double aDh, uint8_t aOptional_argc,
|
|
|
|
mozilla::ErrorResult& aError);
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
void DrawDirectlyToCanvas(const nsLayoutUtils::DirectDrawInfo& aImage,
|
|
|
|
mozilla::gfx::Rect* aBounds,
|
2018-02-19 20:15:23 +00:00
|
|
|
mozilla::gfx::Rect aDest, mozilla::gfx::Rect aSrc,
|
|
|
|
gfx::IntSize aImgSize);
|
2014-01-13 00:29:48 +00:00
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
nsString& GetFont() {
|
|
|
|
/* will initilize the value if not set, else does nothing */
|
|
|
|
GetCurrentFontStyle();
|
|
|
|
|
|
|
|
return CurrentState().font;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Member vars
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mWidth, mHeight;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
|
|
|
// This is true when the canvas is valid, but of zero size, this requires
|
|
|
|
// specific behavior on some operations.
|
|
|
|
bool mZero;
|
|
|
|
|
2018-05-02 15:23:53 +00:00
|
|
|
// The two ways to set the opaqueness of the canvas.
|
|
|
|
// mOpaqueAttrValue: Whether the <canvas> element has the moz-opaque attribute
|
|
|
|
// set. Can change during the lifetime of the context. Non-standard, should
|
|
|
|
// hopefully go away soon.
|
|
|
|
// mContextAttributesHasAlpha: The standard way of setting canvas opaqueness.
|
|
|
|
// Set at context initialization time and never changes.
|
|
|
|
bool mOpaqueAttrValue;
|
|
|
|
bool mContextAttributesHasAlpha;
|
|
|
|
|
|
|
|
// Determines the context's opaqueness. Is computed from mOpaqueAttrValue and
|
|
|
|
// mContextAttributesHasAlpha in UpdateIsOpaque().
|
2012-06-13 15:14:15 +00:00
|
|
|
bool mOpaque;
|
|
|
|
|
|
|
|
// This is true when the next time our layer is retrieved we need to
|
|
|
|
// recreate it (i.e. our backing surface changed)
|
|
|
|
bool mResetLayer;
|
|
|
|
// This is needed for drawing in drawAsyncXULElement
|
|
|
|
bool mIPC;
|
|
|
|
|
2016-07-01 08:58:20 +00:00
|
|
|
bool mHasPendingStableStateCallback;
|
|
|
|
|
2012-10-12 09:42:52 +00:00
|
|
|
nsTArray<CanvasRenderingContext2DUserData*> mUserDatas;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
|
|
|
// If mCanvasElement is not provided, then a docshell is
|
|
|
|
nsCOMPtr<nsIDocShell> mDocShell;
|
|
|
|
|
2012-05-31 00:47:27 +00:00
|
|
|
// This is created lazily so it is necessary to call EnsureTarget before
|
|
|
|
// accessing it. In the event of an error it will be equal to
|
|
|
|
// sErrorTarget.
|
2017-01-17 21:58:02 +00:00
|
|
|
RefPtr<mozilla::gfx::DrawTarget> mTarget;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::layers::PersistentBufferProvider> mBufferProvider;
|
2015-06-18 23:07:21 +00:00
|
|
|
|
2016-07-01 08:58:18 +00:00
|
|
|
RefPtr<CanvasShutdownObserver> mShutdownObserver;
|
|
|
|
void RemoveShutdownObserver();
|
|
|
|
bool AlreadyShutDown() const { return !mShutdownObserver; }
|
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
/**
|
|
|
|
* Flag to avoid duplicate calls to InvalidateFrame. Set to true whenever
|
|
|
|
* Redraw is called, reset to false when Render is called.
|
|
|
|
*/
|
|
|
|
bool mIsEntireFrameInvalid;
|
|
|
|
/**
|
|
|
|
* When this is set, the first call to Redraw(gfxRect) should set
|
|
|
|
* mIsEntireFrameInvalid since we expect it will be followed by
|
|
|
|
* many more Redraw calls.
|
|
|
|
*/
|
|
|
|
bool mPredictManyRedrawCalls;
|
|
|
|
|
2015-09-17 03:37:05 +00:00
|
|
|
/**
|
|
|
|
* Flag to avoid unnecessary surface copies to FrameCaptureListeners in the
|
|
|
|
* case when the canvas is not currently being drawn into and not rendered
|
|
|
|
* but canvas capturing is still ongoing.
|
|
|
|
*/
|
|
|
|
bool mIsCapturedFrameInvalid;
|
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
/**
|
|
|
|
* We also have a device space pathbuilder. The reason for this is as
|
|
|
|
* follows, when a path is being built, but the transform changes, we
|
|
|
|
* can no longer keep a single path in userspace, considering there's
|
|
|
|
* several 'user spaces' now. We therefore transform the current path
|
|
|
|
* into device space, and add all operations to this path in device
|
|
|
|
* space.
|
|
|
|
*
|
|
|
|
* When then finally executing a render, the Azure drawing API expects
|
|
|
|
* the path to be in userspace. We could then set an identity transform
|
|
|
|
* on the DrawTarget and do all drawing in device space. This is
|
|
|
|
* undesirable because it requires transforming patterns, gradients,
|
|
|
|
* clips, etc. into device space and it would not work for stroking.
|
|
|
|
* What we do instead is convert the path back to user space when it is
|
|
|
|
* drawn, and draw it with the current transform. This makes all drawing
|
|
|
|
* occur correctly.
|
|
|
|
*
|
|
|
|
* There's never both a device space path builder and a user space path
|
|
|
|
* builder present at the same time. There is also never a path and a
|
|
|
|
* path builder present at the same time. When writing proceeds on an
|
|
|
|
* existing path the Path is cleared and a new builder is created.
|
|
|
|
*
|
|
|
|
* mPath is always in user-space.
|
|
|
|
*/
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::gfx::Path> mPath;
|
|
|
|
RefPtr<mozilla::gfx::PathBuilder> mDSPathBuilder;
|
|
|
|
RefPtr<mozilla::gfx::PathBuilder> mPathBuilder;
|
2012-06-13 15:14:15 +00:00
|
|
|
bool mPathTransformWillUpdate;
|
|
|
|
mozilla::gfx::Matrix mPathToDS;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of times we've invalidated before calling redraw
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mInvalidateCount;
|
|
|
|
static const uint32_t kCanvasMaxInvalidateCount = 100;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2014-02-21 13:35:36 +00:00
|
|
|
/**
|
|
|
|
* State information for hit regions
|
|
|
|
*/
|
2014-05-18 23:43:00 +00:00
|
|
|
struct RegionInfo {
|
|
|
|
nsString mId;
|
|
|
|
// fallback element for a11y
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Element> mElement;
|
2014-05-18 23:43:00 +00:00
|
|
|
// Path of the hit region in the 2d context coordinate space (not user
|
|
|
|
// space)
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<gfx::Path> mPath;
|
2014-02-21 13:35:36 +00:00
|
|
|
};
|
|
|
|
|
2014-05-18 23:43:00 +00:00
|
|
|
nsTArray<RegionInfo> mHitRegionsOptions;
|
2014-02-21 13:35:36 +00:00
|
|
|
|
2017-02-26 01:40:09 +00:00
|
|
|
nsBidi mBidiEngine;
|
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
/**
|
|
|
|
* Returns true if a shadow should be drawn along with a
|
|
|
|
* drawing operation.
|
|
|
|
*/
|
|
|
|
bool NeedToDrawShadow() {
|
|
|
|
const ContextState& state = CurrentState();
|
|
|
|
|
|
|
|
// The spec says we should not draw shadows if the operator is OVER.
|
|
|
|
// If it's over and the alpha value is zero, nothing needs to be drawn.
|
2014-07-11 20:45:22 +00:00
|
|
|
return NS_GET_A(state.shadowColor) != 0 &&
|
2014-08-19 17:08:16 +00:00
|
|
|
(state.shadowBlur != 0.f || state.shadowOffset.x != 0.f ||
|
|
|
|
state.shadowOffset.y != 0.f);
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
2014-09-23 21:47:18 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the result of a drawing operation should be
|
|
|
|
* drawn with a filter.
|
|
|
|
*/
|
2016-10-25 18:00:21 +00:00
|
|
|
bool NeedToApplyFilter() {
|
|
|
|
return EnsureUpdatedFilter().mPrimitives.Length() > 0;
|
|
|
|
}
|
2016-08-27 00:21:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls UpdateFilter if the canvas's WriteOnly state has changed between the
|
|
|
|
* last call to UpdateFilter and now.
|
|
|
|
*/
|
2016-10-25 18:00:21 +00:00
|
|
|
const gfx::FilterDescription& EnsureUpdatedFilter() {
|
|
|
|
bool isWriteOnly = mCanvasElement && mCanvasElement->IsWriteOnly();
|
2016-10-25 17:44:19 +00:00
|
|
|
if (CurrentState().filterSourceGraphicTainted != isWriteOnly) {
|
2016-10-25 18:00:21 +00:00
|
|
|
UpdateFilter();
|
2017-01-03 17:01:11 +00:00
|
|
|
EnsureTarget();
|
2016-10-25 18:00:21 +00:00
|
|
|
}
|
2016-10-25 17:44:19 +00:00
|
|
|
MOZ_ASSERT(CurrentState().filterSourceGraphicTainted == isWriteOnly);
|
|
|
|
return CurrentState().filter;
|
2016-10-25 18:00:21 +00:00
|
|
|
}
|
2014-09-23 21:47:18 +00:00
|
|
|
|
2014-09-23 21:47:19 +00:00
|
|
|
bool NeedToCalculateBounds() {
|
|
|
|
return NeedToDrawShadow() || NeedToApplyFilter();
|
|
|
|
}
|
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
mozilla::gfx::CompositionOp UsedOperation() {
|
2014-09-23 21:47:20 +00:00
|
|
|
if (NeedToDrawShadow() || NeedToApplyFilter()) {
|
|
|
|
// In this case the shadow or filter rendering will use the operator.
|
2014-01-10 19:06:17 +00:00
|
|
|
return mozilla::gfx::CompositionOp::OP_OVER;
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return CurrentState().op;
|
|
|
|
}
|
|
|
|
|
|
|
|
// text
|
|
|
|
|
2015-01-25 22:22:08 +00:00
|
|
|
protected:
|
|
|
|
enum class TextAlign : uint8_t { START, END, LEFT, RIGHT, CENTER };
|
2014-04-26 02:34:07 +00:00
|
|
|
|
2015-01-25 22:22:08 +00:00
|
|
|
enum class TextBaseline : uint8_t {
|
2014-04-26 02:34:07 +00:00
|
|
|
TOP,
|
|
|
|
HANGING,
|
|
|
|
MIDDLE,
|
|
|
|
ALPHABETIC,
|
|
|
|
IDEOGRAPHIC,
|
|
|
|
BOTTOM
|
2015-01-25 22:22:08 +00:00
|
|
|
};
|
2014-04-26 02:34:07 +00:00
|
|
|
|
2015-01-25 22:22:08 +00:00
|
|
|
enum class TextDrawOperation : uint8_t { FILL, STROKE, MEASURE };
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2014-04-26 02:34:07 +00:00
|
|
|
protected:
|
2012-06-13 15:14:15 +00:00
|
|
|
gfxFontGroup* GetCurrentFontStyle();
|
|
|
|
|
2015-07-14 20:59:12 +00:00
|
|
|
/**
|
|
|
|
* Implementation of the fillText, strokeText, and measure functions with
|
|
|
|
* the operation abstracted to a flag.
|
|
|
|
*/
|
2016-02-01 08:39:08 +00:00
|
|
|
nsresult DrawOrMeasureText(const nsAString& aText, float aX, float aY,
|
|
|
|
const Optional<double>& aMaxWidth,
|
|
|
|
TextDrawOperation aOp, float* aWidth);
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2016-08-10 12:30:51 +00:00
|
|
|
// A clip or a transform, recorded and restored in order.
|
|
|
|
struct ClipState {
|
|
|
|
explicit ClipState(mozilla::gfx::Path* aClip) : clip(aClip) {}
|
|
|
|
|
|
|
|
explicit ClipState(const mozilla::gfx::Matrix& aTransform)
|
|
|
|
: transform(aTransform) {}
|
|
|
|
|
|
|
|
bool IsClip() const { return !!clip; }
|
|
|
|
|
|
|
|
RefPtr<mozilla::gfx::Path> clip;
|
|
|
|
mozilla::gfx::Matrix transform;
|
|
|
|
};
|
|
|
|
|
2012-06-13 15:14:15 +00:00
|
|
|
// state stack handling
|
|
|
|
class ContextState {
|
|
|
|
public:
|
2019-04-01 14:32:32 +00:00
|
|
|
ContextState();
|
|
|
|
ContextState(const ContextState& aOther);
|
|
|
|
~ContextState();
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
void SetColorStyle(Style aWhichStyle, nscolor aColor) {
|
|
|
|
colorStyles[aWhichStyle] = aColor;
|
|
|
|
gradientStyles[aWhichStyle] = nullptr;
|
|
|
|
patternStyles[aWhichStyle] = nullptr;
|
2012-10-12 09:42:53 +00:00
|
|
|
}
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
void SetPatternStyle(Style aWhichStyle, CanvasPattern* aPat) {
|
|
|
|
gradientStyles[aWhichStyle] = nullptr;
|
|
|
|
patternStyles[aWhichStyle] = aPat;
|
2012-10-12 09:42:53 +00:00
|
|
|
}
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2016-02-01 08:39:08 +00:00
|
|
|
void SetGradientStyle(Style aWhichStyle, CanvasGradient* aGrad) {
|
|
|
|
gradientStyles[aWhichStyle] = aGrad;
|
|
|
|
patternStyles[aWhichStyle] = nullptr;
|
2012-10-12 09:42:53 +00:00
|
|
|
}
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2012-10-12 09:42:53 +00:00
|
|
|
/**
|
|
|
|
* returns true iff the given style is a solid color.
|
|
|
|
*/
|
2016-02-01 08:39:08 +00:00
|
|
|
bool StyleIsColor(Style aWhichStyle) const {
|
|
|
|
return !(patternStyles[aWhichStyle] || gradientStyles[aWhichStyle]);
|
2012-10-12 09:42:53 +00:00
|
|
|
}
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2014-09-23 21:47:20 +00:00
|
|
|
int32_t ShadowBlurRadius() const {
|
|
|
|
static const gfxFloat GAUSSIAN_SCALE_FACTOR =
|
|
|
|
(3 * sqrt(2 * M_PI) / 4) * 1.5;
|
|
|
|
return (int32_t)floor(ShadowBlurSigma() * GAUSSIAN_SCALE_FACTOR + 0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::gfx::Float ShadowBlurSigma() const {
|
|
|
|
return std::min(SIGMA_MAX, shadowBlur / 2.0f);
|
|
|
|
}
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2016-08-10 12:30:51 +00:00
|
|
|
nsTArray<ClipState> clipsAndTransforms;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<gfxFontGroup> fontGroup;
|
2017-10-02 22:05:19 +00:00
|
|
|
RefPtr<nsAtom> fontLanguage;
|
2014-09-23 21:47:19 +00:00
|
|
|
nsFont fontFont;
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
EnumeratedArray<Style, Style::MAX, RefPtr<CanvasGradient>> gradientStyles;
|
|
|
|
EnumeratedArray<Style, Style::MAX, RefPtr<CanvasPattern>> patternStyles;
|
2014-04-26 02:34:07 +00:00
|
|
|
EnumeratedArray<Style, Style::MAX, nscolor> colorStyles;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2012-10-12 09:42:53 +00:00
|
|
|
nsString font;
|
2019-04-02 17:00:41 +00:00
|
|
|
TextAlign textAlign = TextAlign::START;
|
|
|
|
TextBaseline textBaseline = TextBaseline::ALPHABETIC;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2019-04-02 17:00:41 +00:00
|
|
|
nscolor shadowColor = 0;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2012-10-12 09:42:53 +00:00
|
|
|
mozilla::gfx::Matrix transform;
|
|
|
|
mozilla::gfx::Point shadowOffset;
|
2019-04-02 17:00:41 +00:00
|
|
|
mozilla::gfx::Float lineWidth = 1.0f;
|
|
|
|
mozilla::gfx::Float miterLimit = 10.0f;
|
|
|
|
mozilla::gfx::Float globalAlpha = 1.0f;
|
|
|
|
mozilla::gfx::Float shadowBlur = 0.0f;
|
|
|
|
|
2015-07-13 06:19:12 +00:00
|
|
|
nsTArray<mozilla::gfx::Float> dash;
|
2019-04-02 17:00:41 +00:00
|
|
|
mozilla::gfx::Float dashOffset = 0.0f;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2019-04-02 17:00:41 +00:00
|
|
|
mozilla::gfx::CompositionOp op = mozilla::gfx::CompositionOp::OP_OVER;
|
|
|
|
mozilla::gfx::FillRule fillRule = mozilla::gfx::FillRule::FILL_WINDING;
|
|
|
|
mozilla::gfx::CapStyle lineCap = mozilla::gfx::CapStyle::BUTT;
|
|
|
|
mozilla::gfx::JoinStyle lineJoin = mozilla::gfx::JoinStyle::MITER_OR_BEVEL;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
2019-04-02 17:00:41 +00:00
|
|
|
nsString filterString = nsString(u"none");
|
2019-05-27 12:37:37 +00:00
|
|
|
StyleOwnedSlice<StyleFilter> filterChain;
|
2018-09-03 10:24:27 +00:00
|
|
|
// RAII object that we obtain when we start to observer SVG filter elements
|
|
|
|
// for rendering changes. When released we stop observing the SVG elements.
|
|
|
|
nsCOMPtr<nsISupports> autoSVGFiltersObserver;
|
2014-09-23 21:47:18 +00:00
|
|
|
mozilla::gfx::FilterDescription filter;
|
2015-10-18 05:24:48 +00:00
|
|
|
nsTArray<RefPtr<mozilla::gfx::SourceSurface>> filterAdditionalImages;
|
2016-10-11 19:18:45 +00:00
|
|
|
|
|
|
|
// This keeps track of whether the canvas was "tainted" or not when
|
|
|
|
// we last used a filter. This is a security measure, whereby the
|
|
|
|
// canvas is flipped to write-only if a cross-origin image is drawn to it.
|
|
|
|
// This is to stop bad actors from reading back data they shouldn't have
|
|
|
|
// access to.
|
|
|
|
//
|
|
|
|
// This also limits what filters we can apply to the context; in particular
|
|
|
|
// feDisplacementMap is restricted.
|
|
|
|
//
|
|
|
|
// We keep track of this to ensure that if this gets out of sync with the
|
|
|
|
// tainted state of the canvas itself, we update our filters accordingly.
|
2019-04-02 17:00:41 +00:00
|
|
|
bool filterSourceGraphicTainted = false;
|
2014-09-23 21:47:18 +00:00
|
|
|
|
2019-04-02 17:00:41 +00:00
|
|
|
bool imageSmoothingEnabled = true;
|
|
|
|
bool fontExplicitLanguage = false;
|
2012-06-13 15:14:15 +00:00
|
|
|
};
|
|
|
|
|
2016-02-02 15:36:30 +00:00
|
|
|
AutoTArray<ContextState, 3> mStyleStack;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
|
|
|
inline ContextState& CurrentState() {
|
|
|
|
return mStyleStack[mStyleStack.Length() - 1];
|
|
|
|
}
|
|
|
|
|
2013-10-16 12:27:59 +00:00
|
|
|
inline const ContextState& CurrentState() const {
|
|
|
|
return mStyleStack[mStyleStack.Length() - 1];
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:20:13 +00:00
|
|
|
friend class CanvasGeneralPattern;
|
2012-06-13 15:14:15 +00:00
|
|
|
friend class AdjustedTarget;
|
2014-09-23 21:47:20 +00:00
|
|
|
friend class AdjustedTargetForShadow;
|
2014-09-23 21:47:20 +00:00
|
|
|
friend class AdjustedTargetForFilter;
|
2012-06-13 15:14:15 +00:00
|
|
|
|
|
|
|
// other helpers
|
2016-02-01 08:39:08 +00:00
|
|
|
void GetAppUnitsValues(int32_t* aPerDevPixel, int32_t* aPerCSSPixel) {
|
2012-06-13 15:14:15 +00:00
|
|
|
// If we don't have a canvas element, we just return something generic.
|
2019-04-30 01:35:30 +00:00
|
|
|
if (aPerDevPixel) {
|
|
|
|
*aPerDevPixel = 60;
|
|
|
|
}
|
|
|
|
if (aPerCSSPixel) {
|
|
|
|
*aPerCSSPixel = 60;
|
|
|
|
}
|
|
|
|
PresShell* presShell = GetPresShell();
|
|
|
|
if (!presShell) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsPresContext* presContext = presShell->GetPresContext();
|
|
|
|
if (!presContext) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aPerDevPixel) {
|
|
|
|
*aPerDevPixel = presContext->AppUnitsPerDevPixel();
|
|
|
|
}
|
|
|
|
if (aPerCSSPixel) {
|
|
|
|
*aPerCSSPixel = AppUnitsPerCSSPixel();
|
|
|
|
}
|
2012-06-13 15:14:15 +00:00
|
|
|
}
|
|
|
|
|
2012-10-12 09:42:52 +00:00
|
|
|
friend struct CanvasBidiProcessor;
|
2014-09-10 20:15:43 +00:00
|
|
|
friend class CanvasDrawObserver;
|
2018-11-06 22:31:34 +00:00
|
|
|
friend class ImageBitmap;
|
|
|
|
|
2019-02-20 22:54:04 +00:00
|
|
|
void SetWriteOnly();
|
2018-11-06 22:31:34 +00:00
|
|
|
|
|
|
|
bool IsWriteOnly() const { return mWriteOnly; }
|
|
|
|
|
|
|
|
bool mWriteOnly;
|
2012-06-13 15:14:15 +00:00
|
|
|
};
|
|
|
|
|
2017-09-13 10:21:12 +00:00
|
|
|
size_t BindingJSObjectMallocBytes(CanvasRenderingContext2D* aContext);
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2012-10-12 09:42:52 +00:00
|
|
|
|
|
|
|
#endif /* CanvasRenderingContext2D_h */
|