2012-06-13 19:14:15 +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/. */
|
|
|
|
|
2012-10-12 13:42:52 +04:00
|
|
|
#ifndef CanvasRenderingContext2D_h
|
|
|
|
#define CanvasRenderingContext2D_h
|
2012-06-13 19:14:15 +04:00
|
|
|
|
|
|
|
#include <vector>
|
2017-02-03 00:43:00 +03:00
|
|
|
#include "mozilla/dom/BasicRenderingContext2D.h"
|
2020-06-25 23:42:49 +03:00
|
|
|
#include "mozilla/dom/CanvasRenderingContext2DBinding.h"
|
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2013-05-29 17:32:30 +04:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
2013-10-08 03:15:59 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2020-06-25 23:42:49 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/EnumeratedArray.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2020-10-01 00:05:34 +03:00
|
|
|
#include "mozilla/SurfaceFromElementResult.h"
|
2015-10-26 21:31:12 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2020-07-21 11:39:35 +03:00
|
|
|
#include "FilterDescription.h"
|
2020-06-25 23:42:49 +03:00
|
|
|
#include "gfx2DGlue.h"
|
|
|
|
#include "nsICanvasRenderingContextInternal.h"
|
2017-02-26 04:40:09 +03:00
|
|
|
#include "nsBidi.h"
|
2020-06-25 23:42:49 +03:00
|
|
|
#include "nsColor.h"
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2019-04-01 17:32:32 +03:00
|
|
|
class gfxFontGroup;
|
2017-11-04 01:25:38 +03:00
|
|
|
class nsGlobalWindowInner;
|
2013-01-29 21:51:55 +04:00
|
|
|
class nsXULElement;
|
2012-11-14 04:35:36 +04:00
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
namespace mozilla {
|
2020-11-23 19:12:02 +03:00
|
|
|
class ErrorResult;
|
2020-11-23 19:08:23 +03:00
|
|
|
class PresShell;
|
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
namespace gl {
|
2012-06-13 19:14:15 +04:00
|
|
|
class SourceSurface;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gl
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2020-11-23 19:09:05 +03:00
|
|
|
namespace layers {
|
|
|
|
class PersistentBufferProvider;
|
|
|
|
enum class LayersBackend : int8_t;
|
|
|
|
} // namespace layers
|
|
|
|
|
2012-10-12 13:42:52 +04:00
|
|
|
namespace dom {
|
2017-07-19 18:48:49 +03:00
|
|
|
class
|
|
|
|
HTMLImageElementOrSVGImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap;
|
|
|
|
typedef HTMLImageElementOrSVGImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap
|
|
|
|
CanvasImageSource;
|
2018-11-07 01:31:34 +03:00
|
|
|
class ImageBitmap;
|
2013-08-23 09:17:11 +04:00
|
|
|
class ImageData;
|
2020-12-17 17:04:35 +03:00
|
|
|
class UTF8StringOrCanvasGradientOrCanvasPattern;
|
|
|
|
class OwningUTF8StringOrCanvasGradientOrCanvasPattern;
|
2013-04-19 12:49:22 +04:00
|
|
|
class TextMetrics;
|
2020-11-23 19:09:05 +03:00
|
|
|
class CanvasGradient;
|
2015-03-03 18:57:51 +03:00
|
|
|
class CanvasPath;
|
2020-11-23 19:09:05 +03:00
|
|
|
class CanvasPattern;
|
2013-04-19 12:49:22 +04:00
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
extern const mozilla::gfx::Float SIGMA_MAX;
|
|
|
|
|
2012-10-12 13:42:52 +04:00
|
|
|
template <typename T>
|
|
|
|
class Optional;
|
|
|
|
|
|
|
|
struct CanvasBidiProcessor;
|
2014-09-11 00:15:43 +04:00
|
|
|
class CanvasDrawObserver;
|
2016-07-01 11:58:18 +03:00
|
|
|
class CanvasShutdownObserver;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2019-07-11 09:14:58 +03:00
|
|
|
class DOMMatrix;
|
|
|
|
class DOMMatrixReadOnly;
|
|
|
|
struct DOMMatrix2DInit;
|
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
/**
|
2012-10-12 13:42:52 +04:00
|
|
|
** CanvasRenderingContext2D
|
2012-06-13 19:14:15 +04:00
|
|
|
**/
|
|
|
|
class CanvasRenderingContext2D final : public nsICanvasRenderingContextInternal,
|
2017-02-03 00:43:00 +03:00
|
|
|
public nsWrapperCache,
|
|
|
|
public BasicRenderingContext2D {
|
2014-06-26 17:30:49 +04:00
|
|
|
virtual ~CanvasRenderingContext2D();
|
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
public:
|
2016-11-03 17:57:33 +03:00
|
|
|
explicit CanvasRenderingContext2D(layers::LayersBackend aCompositorBackend);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2016-02-01 11:39:08 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2012-05-22 01:30:07 +04:00
|
|
|
|
2013-01-04 09:16:14 +04:00
|
|
|
HTMLCanvasElement* GetCanvas() const {
|
2016-11-03 17:57:33 +03:00
|
|
|
if (!mCanvasElement || mCanvasElement->IsInNativeAnonymousSubtree()) {
|
2015-11-15 16:48:32 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-11-22 01:55:36 +04:00
|
|
|
// corresponds to changes to the old bindings made in bug 745025
|
|
|
|
return mCanvasElement->GetOriginalCanvas();
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
void OnBeforePaintTransaction() override;
|
|
|
|
void OnDidPaintTransaction() override;
|
|
|
|
layers::PersistentBufferProvider* GetBufferProvider() override {
|
|
|
|
return mBufferProvider;
|
|
|
|
}
|
|
|
|
|
2017-02-03 00:43:00 +03: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-12 01:36:44 +03:00
|
|
|
already_AddRefed<DOMMatrix> GetTransform(
|
|
|
|
mozilla::ErrorResult& aError) override;
|
2017-02-03 00:43:00 +03:00
|
|
|
void SetTransform(double aM11, double aM12, double aM21, double aM22,
|
|
|
|
double aDx, double aDy,
|
|
|
|
mozilla::ErrorResult& aError) override;
|
2019-07-11 09:14:58 +03:00
|
|
|
void SetTransform(const DOMMatrix2DInit& aInit,
|
|
|
|
mozilla::ErrorResult& aError) override;
|
2017-02-03 00:43:00 +03:00
|
|
|
void ResetTransform(mozilla::ErrorResult& aError) override;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
|
|
|
double GlobalAlpha() override { return CurrentState().globalAlpha; }
|
|
|
|
|
2013-01-29 05:39:47 +04:00
|
|
|
// Useful for silencing cast warnings
|
|
|
|
static mozilla::gfx::Float ToFloat(double aValue) {
|
|
|
|
return mozilla::gfx::Float(aValue);
|
|
|
|
}
|
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void SetGlobalAlpha(double aGlobalAlpha) override {
|
2016-02-01 11:39:08 +03:00
|
|
|
if (aGlobalAlpha >= 0.0 && aGlobalAlpha <= 1.0) {
|
|
|
|
CurrentState().globalAlpha = ToFloat(aGlobalAlpha);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void GetGlobalCompositeOperation(nsAString& aOp,
|
|
|
|
mozilla::ErrorResult& aError) override;
|
2016-02-01 11:39:08 +03:00
|
|
|
void SetGlobalCompositeOperation(const nsAString& aOp,
|
2017-02-03 00:43:00 +03:00
|
|
|
mozilla::ErrorResult& aError) override;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void GetStrokeStyle(
|
2020-12-17 17:04:35 +03:00
|
|
|
OwningUTF8StringOrCanvasGradientOrCanvasPattern& aValue) override {
|
2016-02-01 11:39:08 +03:00
|
|
|
GetStyleAsUnion(aValue, Style::STROKE);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void SetStrokeStyle(
|
2020-12-17 17:04:35 +03:00
|
|
|
const UTF8StringOrCanvasGradientOrCanvasPattern& aValue) override {
|
2016-02-01 11:39:08 +03:00
|
|
|
SetStyleFromUnion(aValue, Style::STROKE);
|
2013-07-26 22:25:54 +04:00
|
|
|
}
|
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void GetFillStyle(
|
2020-12-17 17:04:35 +03:00
|
|
|
OwningUTF8StringOrCanvasGradientOrCanvasPattern& aValue) override {
|
2016-02-01 11:39:08 +03:00
|
|
|
GetStyleAsUnion(aValue, Style::FILL);
|
2013-07-26 22:25:54 +04:00
|
|
|
}
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void SetFillStyle(
|
2020-12-17 17:04:35 +03:00
|
|
|
const UTF8StringOrCanvasGradientOrCanvasPattern& aValue) override {
|
2016-02-01 11:39:08 +03:00
|
|
|
SetStyleFromUnion(aValue, Style::FILL);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
already_AddRefed<CanvasGradient> CreateLinearGradient(double aX0, double aY0,
|
|
|
|
double aX1,
|
|
|
|
double aY1) override;
|
2013-04-26 18:55:54 +04:00
|
|
|
already_AddRefed<CanvasGradient> CreateRadialGradient(
|
2017-02-03 00:43:00 +03:00
|
|
|
double aX0, double aY0, double aR0, double aX1, double aY1, double aR1,
|
|
|
|
ErrorResult& aError) override;
|
2021-01-01 04:50:52 +03:00
|
|
|
already_AddRefed<CanvasGradient> CreateConicGradient(double aAngle,
|
|
|
|
double aCx,
|
|
|
|
double aCy) override;
|
2013-04-19 12:49:22 +04:00
|
|
|
already_AddRefed<CanvasPattern> CreatePattern(
|
2016-02-01 11:39:08 +03:00
|
|
|
const CanvasImageSource& aElement, const nsAString& aRepeat,
|
2017-02-03 00:43:00 +03:00
|
|
|
ErrorResult& aError) override;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2016-02-01 11:39:08 +03:00
|
|
|
double ShadowOffsetX() override { return CurrentState().shadowOffset.x; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void SetShadowOffsetX(double aShadowOffsetX) override {
|
2016-02-01 11:39:08 +03:00
|
|
|
CurrentState().shadowOffset.x = ToFloat(aShadowOffsetX);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
double ShadowOffsetY() override { return CurrentState().shadowOffset.y; }
|
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void SetShadowOffsetY(double aShadowOffsetY) override {
|
2016-02-01 11:39:08 +03:00
|
|
|
CurrentState().shadowOffset.y = ToFloat(aShadowOffsetY);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
double ShadowBlur() override { return CurrentState().shadowBlur; }
|
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void SetShadowBlur(double aShadowBlur) override {
|
2016-02-01 11:39:08 +03:00
|
|
|
if (aShadowBlur >= 0.0) {
|
|
|
|
CurrentState().shadowBlur = ToFloat(aShadowBlur);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
void GetShadowColor(nsACString& aShadowColor) override {
|
2016-02-01 11:39:08 +03:00
|
|
|
StyleColorToString(CurrentState().shadowColor, aShadowColor);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
void GetFilter(nsACString& aFilter) { aFilter = CurrentState().filterString; }
|
2014-09-24 01:44:53 +04:00
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
void SetShadowColor(const nsACString& aShadowColor) override;
|
|
|
|
void SetFilter(const nsACString& aFilter, mozilla::ErrorResult& aError);
|
2017-02-03 00:43:00 +03: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 19:14:15 +04:00
|
|
|
void BeginPath();
|
2016-02-01 11:39:08 +03:00
|
|
|
void Fill(const CanvasWindingRule& aWinding);
|
|
|
|
void Fill(const CanvasPath& aPath, const CanvasWindingRule& aWinding);
|
2012-06-13 19:14:15 +04:00
|
|
|
void Stroke();
|
2016-02-01 11:39:08 +03: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 21:49:32 +03: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 11:39:08 +03: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 19:14:15 +04:00
|
|
|
|
2016-02-01 11:39:08 +03:00
|
|
|
void AddHitRegion(const HitRegionOptions& aOptions,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
void RemoveHitRegion(const nsAString& aId);
|
2015-01-09 17:41:00 +03:00
|
|
|
void ClearHitRegions();
|
2014-02-21 17:35:14 +04:00
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void DrawImage(const CanvasImageSource& aImage, double aDx, double aDy,
|
|
|
|
mozilla::ErrorResult& aError) override {
|
2016-02-01 11:39:08 +03:00
|
|
|
DrawImage(aImage, 0.0, 0.0, 0.0, 0.0, aDx, aDy, 0.0, 0.0, 0, aError);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void DrawImage(const CanvasImageSource& aImage, double aDx, double aDy,
|
|
|
|
double aDw, double aDh,
|
|
|
|
mozilla::ErrorResult& aError) override {
|
2016-02-01 11:39:08 +03:00
|
|
|
DrawImage(aImage, 0.0, 0.0, 0.0, 0.0, aDx, aDy, aDw, aDh, 2, aError);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2016-02-01 11:39:08 +03:00
|
|
|
void DrawImage(const CanvasImageSource& aImage, double aSx, double aSy,
|
2017-02-03 00:43:00 +03:00
|
|
|
double aSw, double aSh, double aDx, double aDy, double aDw,
|
|
|
|
double aDh, mozilla::ErrorResult& aError) override {
|
2016-02-01 11:39:08 +03:00
|
|
|
DrawImage(aImage, aSx, aSy, aSw, aSh, aDx, aDy, aDw, aDh, 6, aError);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2021-01-04 20:48:32 +03:00
|
|
|
already_AddRefed<ImageData> CreateImageData(JSContext*, int32_t aSw,
|
|
|
|
int32_t aSh, ErrorResult&);
|
|
|
|
already_AddRefed<ImageData> CreateImageData(JSContext*, ImageData&,
|
|
|
|
ErrorResult&);
|
|
|
|
already_AddRefed<ImageData> GetImageData(JSContext*, int32_t aSx, int32_t aSy,
|
|
|
|
int32_t aSw, int32_t aSh,
|
2018-05-14 21:49:32 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2021-01-04 20:48:32 +03:00
|
|
|
ErrorResult&);
|
|
|
|
void PutImageData(ImageData&, int32_t aDx, int32_t aDy, ErrorResult&);
|
|
|
|
void PutImageData(ImageData&, int32_t aDx, int32_t aDy, int32_t aDirtyX,
|
|
|
|
int32_t aDirtyY, int32_t aDirtyWidth, int32_t aDirtyHeight,
|
|
|
|
ErrorResult&);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
|
|
|
double LineWidth() override { return CurrentState().lineWidth; }
|
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void SetLineWidth(double aWidth) override {
|
2016-02-01 11:39:08 +03:00
|
|
|
if (aWidth > 0.0) {
|
|
|
|
CurrentState().lineWidth = ToFloat(aWidth);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
}
|
2017-02-03 00:43:00 +03: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 19:14:15 +04:00
|
|
|
|
|
|
|
double MiterLimit() override { return CurrentState().miterLimit; }
|
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void SetMiterLimit(double aMiter) override {
|
2016-02-01 11:39:08 +03:00
|
|
|
if (aMiter > 0.0) {
|
|
|
|
CurrentState().miterLimit = ToFloat(aMiter);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
void GetFont(nsACString& aFont) { aFont = GetFont(); }
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
void SetFont(const nsACString& aFont, mozilla::ErrorResult& aError);
|
2016-02-01 11:39:08 +03:00
|
|
|
void GetTextAlign(nsAString& aTextAlign);
|
|
|
|
void SetTextAlign(const nsAString& aTextAlign);
|
|
|
|
void GetTextBaseline(nsAString& aTextBaseline);
|
|
|
|
void SetTextBaseline(const nsAString& aTextBaseline);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void ClosePath() override {
|
2012-06-13 19:14:15 +04:00
|
|
|
EnsureWritablePath();
|
|
|
|
|
|
|
|
if (mPathBuilder) {
|
|
|
|
mPathBuilder->Close();
|
|
|
|
} else {
|
|
|
|
mDSPathBuilder->Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void MoveTo(double aX, double aY) override {
|
2012-11-28 00:32:05 +04:00
|
|
|
EnsureWritablePath();
|
|
|
|
|
|
|
|
if (mPathBuilder) {
|
2016-02-01 11:39:08 +03:00
|
|
|
mPathBuilder->MoveTo(mozilla::gfx::Point(ToFloat(aX), ToFloat(aY)));
|
2012-11-28 00:32:05 +04:00
|
|
|
} else {
|
2016-09-08 19:26:03 +03:00
|
|
|
mDSPathBuilder->MoveTo(mTarget->GetTransform().TransformPoint(
|
|
|
|
mozilla::gfx::Point(ToFloat(aX), ToFloat(aY))));
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void LineTo(double aX, double aY) override {
|
2012-11-28 00:32:05 +04:00
|
|
|
EnsureWritablePath();
|
2013-07-26 22:25:54 +04:00
|
|
|
|
2016-02-01 11:39:08 +03:00
|
|
|
LineTo(mozilla::gfx::Point(ToFloat(aX), ToFloat(aY)));
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void QuadraticCurveTo(double aCpx, double aCpy, double aX,
|
|
|
|
double aY) override {
|
2012-11-28 00:32:05 +04:00
|
|
|
EnsureWritablePath();
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2012-11-28 00:32:05 +04:00
|
|
|
if (mPathBuilder) {
|
2016-02-01 11:39:08 +03:00
|
|
|
mPathBuilder->QuadraticBezierTo(
|
|
|
|
mozilla::gfx::Point(ToFloat(aCpx), ToFloat(aCpy)),
|
|
|
|
mozilla::gfx::Point(ToFloat(aX), ToFloat(aY)));
|
2012-11-28 00:32:05 +04:00
|
|
|
} else {
|
|
|
|
mozilla::gfx::Matrix transform = mTarget->GetTransform();
|
2016-09-08 19:26:03 +03:00
|
|
|
mDSPathBuilder->QuadraticBezierTo(
|
|
|
|
transform.TransformPoint(
|
|
|
|
mozilla::gfx::Point(ToFloat(aCpx), ToFloat(aCpy))),
|
|
|
|
transform.TransformPoint(
|
|
|
|
mozilla::gfx::Point(ToFloat(aX), ToFloat(aY))));
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void BezierCurveTo(double aCp1x, double aCp1y, double aCp2x, double aCp2y,
|
|
|
|
double aX, double aY) override {
|
2012-11-28 00:32:05 +04:00
|
|
|
EnsureWritablePath();
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2016-02-01 11:39:08 +03: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 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2017-02-03 00:43:00 +03: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 11:39:08 +03:00
|
|
|
void Arc(double aX, double aY, double aRadius, double aStartAngle,
|
2017-02-03 00:43:00 +03:00
|
|
|
double aEndAngle, bool aAnticlockwise,
|
|
|
|
mozilla::ErrorResult& aError) override;
|
2016-03-15 02:53:00 +03:00
|
|
|
void Ellipse(double aX, double aY, double aRadiusX, double aRadiusY,
|
|
|
|
double aRotation, double aStartAngle, double aEndAngle,
|
2017-02-03 00:43:00 +03:00
|
|
|
bool aAnticlockwise, ErrorResult& aError) override;
|
2016-02-01 11:39:08 +03:00
|
|
|
|
|
|
|
void GetMozCurrentTransform(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JSObject*> aResult,
|
2016-10-03 06:55:00 +03:00
|
|
|
mozilla::ErrorResult& aError);
|
2016-02-01 11:39:08 +03:00
|
|
|
void SetMozCurrentTransform(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aCurrentTransform,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
void GetMozCurrentTransformInverse(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JSObject*> aResult,
|
2016-10-03 06:55:00 +03:00
|
|
|
mozilla::ErrorResult& aError);
|
2016-02-01 11:39:08 +03: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-03 00:43:00 +03:00
|
|
|
mozilla::ErrorResult& aRv) override;
|
|
|
|
void GetLineDash(nsTArray<double>& aSegments) const override;
|
2013-10-16 16:27:59 +04:00
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void SetLineDashOffset(double aOffset) override;
|
|
|
|
double LineDashOffset() const override;
|
2013-10-16 16:27:59 +04:00
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
void GetMozTextStyle(nsACString& aMozTextStyle) { GetFont(aMozTextStyle); }
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
void SetMozTextStyle(const nsACString& aMozTextStyle,
|
2016-02-01 11:39:08 +03:00
|
|
|
mozilla::ErrorResult& aError) {
|
|
|
|
SetFont(aMozTextStyle, aError);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
bool ImageSmoothingEnabled() override {
|
2012-06-13 19:14:15 +04:00
|
|
|
return CurrentState().imageSmoothingEnabled;
|
|
|
|
}
|
|
|
|
|
2017-02-03 00:43:00 +03:00
|
|
|
void SetImageSmoothingEnabled(bool aImageSmoothingEnabled) override {
|
2016-02-01 11:39:08 +03:00
|
|
|
if (aImageSmoothingEnabled != CurrentState().imageSmoothingEnabled) {
|
|
|
|
CurrentState().imageSmoothingEnabled = aImageSmoothingEnabled;
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 01:52:14 +03:00
|
|
|
void DrawWindow(nsGlobalWindowInner& aWindow, double aX, double aY, double aW,
|
2020-01-08 04:21:30 +03:00
|
|
|
double aH, const nsACString& aBgColor, uint32_t aFlags,
|
2021-03-15 15:30:54 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-02-01 11:39:08 +03:00
|
|
|
mozilla::ErrorResult& aError);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2014-09-03 03:26:36 +04:00
|
|
|
// Eventually this should be deprecated. Keeping for now to keep the binding
|
|
|
|
// functional.
|
2013-08-23 17:52:32 +04:00
|
|
|
void Demote();
|
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
nsresult Redraw();
|
|
|
|
|
2016-09-01 16:51:09 +03:00
|
|
|
gfx::IntSize GetSize() const { return gfx::IntSize(mWidth, mHeight); }
|
2017-12-22 04:14:54 +03:00
|
|
|
virtual int32_t GetWidth() override { return GetSize().width; }
|
|
|
|
virtual int32_t GetHeight() override { return GetSize().height; }
|
2015-10-02 10:18:26 +03:00
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
// nsICanvasRenderingContextInternal
|
2014-09-10 05:40:51 +04:00
|
|
|
/**
|
|
|
|
* Gets the pres shell from either the canvas element or the doc shell
|
|
|
|
*/
|
2020-11-23 19:07:43 +03:00
|
|
|
PresShell* GetPresShell() final;
|
2016-02-01 11:39:08 +03:00
|
|
|
NS_IMETHOD SetDimensions(int32_t aWidth, int32_t aHeight) override;
|
2016-04-21 12:30:38 +03:00
|
|
|
NS_IMETHOD InitializeWithDrawTarget(
|
2016-08-23 11:41:21 +03:00
|
|
|
nsIDocShell* aShell, NotNull<gfx::DrawTarget*> aTarget) override;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
|
|
|
NS_IMETHOD GetInputStream(const char* aMimeType,
|
2019-04-08 04:51:17 +03:00
|
|
|
const nsAString& aEncoderOptions,
|
2016-02-01 11:39:08 +03:00
|
|
|
nsIInputStream** aStream) override;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2017-04-12 12:55:23 +03:00
|
|
|
already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(
|
2018-12-02 17:19:11 +03:00
|
|
|
gfxAlphaType* aOutAlphaType = nullptr) override;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2018-05-02 18:23:53 +03:00
|
|
|
virtual void SetOpaqueValueFromOpaqueAttr(bool aOpaqueAttrValue) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
bool GetIsOpaque() override { return mOpaque; }
|
|
|
|
NS_IMETHOD Reset() override;
|
2015-12-18 09:52:17 +03:00
|
|
|
already_AddRefed<Layer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
|
2016-02-01 11:39:08 +03:00
|
|
|
Layer* aOldLayer,
|
2017-09-16 01:06:56 +03:00
|
|
|
LayerManager* aManager) override;
|
2017-10-28 13:07:27 +03:00
|
|
|
|
|
|
|
bool UpdateWebRenderCanvasData(nsDisplayListBuilder* aBuilder,
|
|
|
|
WebRenderCanvasData* aCanvasData) override;
|
|
|
|
|
2017-08-18 10:13:29 +03:00
|
|
|
bool InitializeCanvasRenderer(nsDisplayListBuilder* aBuilder,
|
2017-09-16 01:06:56 +03:00
|
|
|
CanvasRenderer* aRenderer) override;
|
2016-02-01 11:39:08 +03:00
|
|
|
virtual bool ShouldForceInactiveLayer(LayerManager* aManager) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
void MarkContextClean() override;
|
2015-09-17 06:37:05 +03:00
|
|
|
void MarkContextCleanForFrameCapture() override;
|
|
|
|
bool IsContextCleanForFrameCapture() override;
|
2016-02-01 11:39:08 +03:00
|
|
|
NS_IMETHOD SetIsIPC(bool aIsIPC) override;
|
2012-06-13 19:14:15 +04:00
|
|
|
// this rect is in canvas device space
|
2016-02-01 11:39:08 +03:00
|
|
|
void Redraw(const mozilla::gfx::Rect& aR);
|
|
|
|
NS_IMETHOD Redraw(const gfxRect& aR) override {
|
|
|
|
Redraw(ToRect(aR));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-10-18 14:14:22 +03:00
|
|
|
NS_IMETHOD SetContextOptions(JSContext* aCx, JS::Handle<JS::Value> aOptions,
|
|
|
|
ErrorResult& aRvForDictionaryInit) override;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2014-09-10 05:40:51 +04: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 19:28:04 +03:00
|
|
|
virtual void DidRefresh() override;
|
2014-09-10 05:40:51 +04:00
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
// this rect is in mTarget's current user space
|
2016-02-01 11:39:08 +03:00
|
|
|
void RedrawUser(const gfxRect& aR);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
|
|
|
// nsISupports interface + CC
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
|
2012-11-14 04:35:36 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(
|
|
|
|
CanvasRenderingContext2D)
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2015-01-26 01:22:08 +03:00
|
|
|
enum class CanvasMultiGetterType : uint8_t {
|
2014-04-26 06:34:07 +04:00
|
|
|
STRING = 0,
|
|
|
|
PATTERN = 1,
|
|
|
|
GRADIENT = 2
|
2015-01-26 01:22:08 +03:00
|
|
|
};
|
2014-04-26 06:34:07 +04:00
|
|
|
|
2015-01-26 01:22:08 +03:00
|
|
|
enum class Style : uint8_t { STROKE = 0, FILL, MAX };
|
2012-06-13 19:14:15 +04:00
|
|
|
|
|
|
|
nsINode* GetParentObject() { return mCanvasElement; }
|
|
|
|
|
|
|
|
void LineTo(const mozilla::gfx::Point& aPoint) {
|
|
|
|
if (mPathBuilder) {
|
|
|
|
mPathBuilder->LineTo(aPoint);
|
|
|
|
} else {
|
2016-09-08 19:26:03 +03:00
|
|
|
mDSPathBuilder->LineTo(mTarget->GetTransform().TransformPoint(aPoint));
|
2012-06-13 19:14:15 +04: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 19:26:03 +03:00
|
|
|
mDSPathBuilder->BezierTo(transform.TransformPoint(aCP1),
|
|
|
|
transform.TransformPoint(aCP2),
|
|
|
|
transform.TransformPoint(aCP3));
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-26 21:31:12 +03:00
|
|
|
virtual UniquePtr<uint8_t[]> GetImageBuffer(int32_t* aFormat) override;
|
2013-10-17 06:55:08 +04:00
|
|
|
|
2014-05-20 08:54:00 +04:00
|
|
|
// Given a point, return hit region ID if it exists
|
2015-03-21 19:28:04 +03:00
|
|
|
nsString GetHitRegion(const mozilla::gfx::Point& aPoint) override;
|
2014-05-20 08:54:00 +04:00
|
|
|
|
2014-05-19 03:43:00 +04:00
|
|
|
// return true and fills in the bound rect if element has a hit region.
|
2015-03-21 19:28:04 +03:00
|
|
|
bool GetHitRegionRect(Element* aElement, nsRect& aRect) override;
|
2014-05-19 03:43:00 +04:00
|
|
|
|
2016-07-01 11:58:18 +03:00
|
|
|
void OnShutdown();
|
2016-11-03 17:57:33 +03:00
|
|
|
|
2018-09-03 13:24:27 +03: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 15:43:57 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY void UpdateFilter();
|
2018-09-03 13:24:27 +03:00
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
protected:
|
|
|
|
nsresult GetImageDataArray(JSContext* aCx, int32_t aX, int32_t aY,
|
|
|
|
uint32_t aWidth, uint32_t aHeight,
|
2018-05-14 21:49:32 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2012-06-13 19:14:15 +04:00
|
|
|
JSObject** aRetval);
|
|
|
|
|
2020-12-10 20:06:46 +03:00
|
|
|
void PutImageData_explicit(int32_t aX, int32_t aY, uint32_t aW, uint32_t aH,
|
|
|
|
dom::Uint8ClampedArray* aArray, bool aHasDirtyRect,
|
|
|
|
int32_t aDirtyX, int32_t aDirtyY,
|
|
|
|
int32_t aDirtyWidth, int32_t aDirtyHeight,
|
|
|
|
ErrorResult&);
|
2012-11-14 04:35:36 +04:00
|
|
|
|
2016-11-24 17:08:10 +03:00
|
|
|
bool CopyBufferProvider(layers::PersistentBufferProvider& aOld,
|
|
|
|
gfx::DrawTarget& aTarget, gfx::IntRect aCopyRect);
|
|
|
|
|
2012-07-24 14:18:39 +04:00
|
|
|
/**
|
|
|
|
* Internal method to complete initialisation, expects mTarget to have been
|
|
|
|
* set
|
|
|
|
*/
|
2016-02-01 11:39:08 +03:00
|
|
|
nsresult Initialize(int32_t aWidth, int32_t aHeight);
|
2012-07-24 14:18:39 +04:00
|
|
|
|
2016-02-01 11:39:08 +03:00
|
|
|
nsresult InitializeWithTarget(mozilla::gfx::DrawTarget* aSurface,
|
|
|
|
int32_t aWidth, int32_t aHeight);
|
2012-06-13 19:14:15 +04: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 17:40:51 +03:00
|
|
|
static uintptr_t sNumLivingContexts;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2012-05-31 04:47:27 +04:00
|
|
|
static mozilla::gfx::DrawTarget* sErrorTarget;
|
|
|
|
|
2016-08-10 15:30:51 +03:00
|
|
|
void SetTransformInternal(const mozilla::gfx::Matrix& aTransform);
|
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
// Some helpers. Doesn't modify a color on failure.
|
2020-12-17 17:04:35 +03:00
|
|
|
void SetStyleFromUnion(
|
|
|
|
const UTF8StringOrCanvasGradientOrCanvasPattern& aValue,
|
|
|
|
Style aWhichStyle);
|
|
|
|
void SetStyleFromString(const nsACString& aStr, Style aWhichStyle);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2016-02-01 11:39:08 +03:00
|
|
|
void SetStyleFromGradient(CanvasGradient& aGradient, Style aWhichStyle) {
|
|
|
|
CurrentState().SetGradientStyle(aWhichStyle, &aGradient);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2016-02-01 11:39:08 +03:00
|
|
|
void SetStyleFromPattern(CanvasPattern& aPattern, Style aWhichStyle) {
|
|
|
|
CurrentState().SetPatternStyle(aWhichStyle, &aPattern);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
void GetStyleAsUnion(OwningUTF8StringOrCanvasGradientOrCanvasPattern& aValue,
|
2013-07-26 22:25:54 +04:00
|
|
|
Style aWhichStyle);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
|
|
|
// Returns whether a color was successfully parsed.
|
2020-01-08 04:21:30 +03:00
|
|
|
bool ParseColor(const nsACString& aString, nscolor* aColor);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
static void StyleColorToString(const nscolor& aColor, nsACString& aStr);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2014-09-24 01:46:11 +04:00
|
|
|
// Returns whether a filter was successfully parsed.
|
2020-12-17 17:04:35 +03:00
|
|
|
bool ParseFilter(const nsACString& aString,
|
2019-05-27 15:37:37 +03:00
|
|
|
StyleOwnedSlice<StyleFilter>& aFilterChain,
|
|
|
|
ErrorResult& aError);
|
2014-09-24 01:46:11 +04:00
|
|
|
|
2015-07-14 23:59:12 +03:00
|
|
|
// Returns whether the font was successfully updated.
|
2020-12-17 17:04:35 +03:00
|
|
|
bool SetFontInternal(const nsACString& aFont, mozilla::ErrorResult& aError);
|
2015-07-14 23:59:12 +03:00
|
|
|
|
2018-05-02 18:23:53 +03:00
|
|
|
// Clears the target and updates mOpaque based on mOpaqueAttrValue and
|
|
|
|
// mContextAttributesHasAlpha.
|
|
|
|
void UpdateIsOpaque();
|
2015-07-14 23:59:12 +03:00
|
|
|
|
2012-05-31 04:47:27 +04:00
|
|
|
/**
|
|
|
|
* Creates the error target, if it doesn't exist
|
|
|
|
*/
|
|
|
|
static void EnsureErrorTarget();
|
|
|
|
|
2012-06-13 19:14:15 +04: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 14:18:38 +04:00
|
|
|
* After calling this function mPathTransformWillUpdate will be false
|
2012-06-13 19:14:15 +04:00
|
|
|
*/
|
|
|
|
void EnsureWritablePath();
|
|
|
|
|
|
|
|
// Ensures a path in UserSpace is available.
|
2016-02-01 11:39:08 +03:00
|
|
|
void EnsureUserSpacePath(
|
|
|
|
const CanvasWindingRule& aWinding = CanvasWindingRule::Nonzero);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2012-05-31 04:47:27 +04:00
|
|
|
/**
|
|
|
|
* Needs to be called before updating the transform. This makes a call to
|
|
|
|
* EnsureTarget() so you don't have to.
|
|
|
|
*/
|
2012-06-13 19:14:15 +04:00
|
|
|
void TransformWillUpdate();
|
|
|
|
|
|
|
|
// Report the fillRule has changed.
|
|
|
|
void FillRuleChanged();
|
|
|
|
|
2012-05-31 04:47:27 +04: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-03 03:26:36 +04:00
|
|
|
*
|
2019-02-28 17:58:19 +03:00
|
|
|
* Returns true on success.
|
2012-05-31 04:47:27 +04:00
|
|
|
*/
|
2019-03-01 20:23:02 +03:00
|
|
|
bool EnsureTarget(const gfx::Rect* aCoveredRect = nullptr,
|
|
|
|
bool aWillClear = false);
|
2012-05-31 04:47:27 +04:00
|
|
|
|
2016-08-26 15:31:58 +03:00
|
|
|
void RestoreClipsAndTransformToTarget();
|
|
|
|
|
2016-09-01 16:51:09 +03: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 11:58:20 +03: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 23:59:12 +03:00
|
|
|
/**
|
2012-05-31 04:47:27 +04:00
|
|
|
* Disposes an old target and prepares to lazily create a new target.
|
2018-05-17 11:49:58 +03:00
|
|
|
*
|
|
|
|
* Parameters are the new dimensions to be used, or if either is negative,
|
|
|
|
* existing dimensions will be left unchanged.
|
2012-05-31 04:47:27 +04:00
|
|
|
*/
|
2018-05-17 11:49:58 +03:00
|
|
|
void ClearTarget(int32_t aWidth = -1, int32_t aHeight = -1);
|
2012-05-31 04:47:27 +04:00
|
|
|
|
2015-06-19 02:07:21 +03:00
|
|
|
/*
|
|
|
|
* Returns the target to the buffer provider. i.e. this will queue a frame for
|
|
|
|
* rendering.
|
|
|
|
*/
|
2016-08-19 13:00:26 +03:00
|
|
|
void ReturnTarget(bool aForceReset = false);
|
2015-06-19 02:07:21 +03:00
|
|
|
|
2012-05-31 04:47:27 +04:00
|
|
|
/**
|
|
|
|
* Check if the target is valid after calling EnsureTarget.
|
|
|
|
*/
|
2016-11-28 22:32:49 +03:00
|
|
|
bool IsTargetValid() const { return !!mTarget && mTarget != sErrorTarget; }
|
2012-05-31 04:47:27 +04:00
|
|
|
|
2012-06-13 19:14:15 +04: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 11:58:06 +03: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 20:23:02 +03:00
|
|
|
* situations. Optionally checks if the pattern is a color pattern.
|
2016-07-01 11:58:06 +03:00
|
|
|
*/
|
2019-03-01 20:23:02 +03:00
|
|
|
bool PatternIsOpaque(Style aStyle, bool* aIsColor = nullptr) const;
|
2016-07-01 11:58:06 +03:00
|
|
|
|
2020-10-01 00:05:34 +03:00
|
|
|
SurfaceFromElementResult CachedSurfaceFromElement(Element* aElement);
|
2014-10-29 18:17:00 +03:00
|
|
|
|
2016-02-01 11:39:08 +03: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 19:14:15 +04:00
|
|
|
|
2020-10-01 00:05:34 +03:00
|
|
|
void DrawDirectlyToCanvas(const DirectDrawInfo& aImage,
|
2016-02-01 11:39:08 +03:00
|
|
|
mozilla::gfx::Rect* aBounds,
|
2018-02-19 23:15:23 +03:00
|
|
|
mozilla::gfx::Rect aDest, mozilla::gfx::Rect aSrc,
|
|
|
|
gfx::IntSize aImgSize);
|
2014-01-13 04:29:48 +04:00
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
nsCString& GetFont() {
|
2012-06-13 19:14:15 +04:00
|
|
|
/* will initilize the value if not set, else does nothing */
|
|
|
|
GetCurrentFontStyle();
|
|
|
|
|
|
|
|
return CurrentState().font;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Member vars
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mWidth, mHeight;
|
2012-06-13 19:14:15 +04: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 18:23:53 +03: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 19:14:15 +04: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 11:58:20 +03:00
|
|
|
bool mHasPendingStableStateCallback;
|
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
// If mCanvasElement is not provided, then a docshell is
|
|
|
|
nsCOMPtr<nsIDocShell> mDocShell;
|
|
|
|
|
2012-05-31 04:47:27 +04: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-18 00:58:02 +03:00
|
|
|
RefPtr<mozilla::gfx::DrawTarget> mTarget;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::layers::PersistentBufferProvider> mBufferProvider;
|
2015-06-19 02:07:21 +03:00
|
|
|
|
2016-07-01 11:58:18 +03:00
|
|
|
RefPtr<CanvasShutdownObserver> mShutdownObserver;
|
|
|
|
void RemoveShutdownObserver();
|
|
|
|
bool AlreadyShutDown() const { return !mShutdownObserver; }
|
|
|
|
|
2012-06-13 19:14:15 +04: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 06:37:05 +03: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 19:14:15 +04: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 08:24:48 +03:00
|
|
|
RefPtr<mozilla::gfx::Path> mPath;
|
|
|
|
RefPtr<mozilla::gfx::PathBuilder> mDSPathBuilder;
|
|
|
|
RefPtr<mozilla::gfx::PathBuilder> mPathBuilder;
|
2012-06-13 19:14:15 +04:00
|
|
|
bool mPathTransformWillUpdate;
|
|
|
|
mozilla::gfx::Matrix mPathToDS;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of times we've invalidated before calling redraw
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mInvalidateCount;
|
|
|
|
static const uint32_t kCanvasMaxInvalidateCount = 100;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2014-02-21 17:35:36 +04:00
|
|
|
/**
|
|
|
|
* State information for hit regions
|
|
|
|
*/
|
2014-05-19 03:43:00 +04:00
|
|
|
struct RegionInfo {
|
|
|
|
nsString mId;
|
|
|
|
// fallback element for a11y
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Element> mElement;
|
2014-05-19 03:43:00 +04:00
|
|
|
// Path of the hit region in the 2d context coordinate space (not user
|
|
|
|
// space)
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfx::Path> mPath;
|
2014-02-21 17:35:36 +04:00
|
|
|
};
|
|
|
|
|
2014-05-19 03:43:00 +04:00
|
|
|
nsTArray<RegionInfo> mHitRegionsOptions;
|
2014-02-21 17:35:36 +04:00
|
|
|
|
2017-02-26 04:40:09 +03:00
|
|
|
nsBidi mBidiEngine;
|
|
|
|
|
2012-06-13 19:14:15 +04: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-12 00:45:22 +04:00
|
|
|
return NS_GET_A(state.shadowColor) != 0 &&
|
2014-08-19 21:08:16 +04:00
|
|
|
(state.shadowBlur != 0.f || state.shadowOffset.x != 0.f ||
|
|
|
|
state.shadowOffset.y != 0.f);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2014-09-24 01:47:18 +04:00
|
|
|
/**
|
|
|
|
* Returns true if the result of a drawing operation should be
|
|
|
|
* drawn with a filter.
|
|
|
|
*/
|
2016-10-25 21:00:21 +03:00
|
|
|
bool NeedToApplyFilter() {
|
|
|
|
return EnsureUpdatedFilter().mPrimitives.Length() > 0;
|
|
|
|
}
|
2016-08-27 03:21:34 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls UpdateFilter if the canvas's WriteOnly state has changed between the
|
|
|
|
* last call to UpdateFilter and now.
|
|
|
|
*/
|
2016-10-25 21:00:21 +03:00
|
|
|
const gfx::FilterDescription& EnsureUpdatedFilter() {
|
|
|
|
bool isWriteOnly = mCanvasElement && mCanvasElement->IsWriteOnly();
|
2016-10-25 20:44:19 +03:00
|
|
|
if (CurrentState().filterSourceGraphicTainted != isWriteOnly) {
|
2016-10-25 21:00:21 +03:00
|
|
|
UpdateFilter();
|
2017-01-03 20:01:11 +03:00
|
|
|
EnsureTarget();
|
2016-10-25 21:00:21 +03:00
|
|
|
}
|
2016-10-25 20:44:19 +03:00
|
|
|
MOZ_ASSERT(CurrentState().filterSourceGraphicTainted == isWriteOnly);
|
|
|
|
return CurrentState().filter;
|
2016-10-25 21:00:21 +03:00
|
|
|
}
|
2014-09-24 01:47:18 +04:00
|
|
|
|
2014-09-24 01:47:19 +04:00
|
|
|
bool NeedToCalculateBounds() {
|
|
|
|
return NeedToDrawShadow() || NeedToApplyFilter();
|
|
|
|
}
|
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
mozilla::gfx::CompositionOp UsedOperation() {
|
2014-09-24 01:47:20 +04:00
|
|
|
if (NeedToDrawShadow() || NeedToApplyFilter()) {
|
|
|
|
// In this case the shadow or filter rendering will use the operator.
|
2014-01-10 23:06:17 +04:00
|
|
|
return mozilla::gfx::CompositionOp::OP_OVER;
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return CurrentState().op;
|
|
|
|
}
|
|
|
|
|
|
|
|
// text
|
|
|
|
|
2015-01-26 01:22:08 +03:00
|
|
|
protected:
|
|
|
|
enum class TextAlign : uint8_t { START, END, LEFT, RIGHT, CENTER };
|
2014-04-26 06:34:07 +04:00
|
|
|
|
2015-01-26 01:22:08 +03:00
|
|
|
enum class TextBaseline : uint8_t {
|
2014-04-26 06:34:07 +04:00
|
|
|
TOP,
|
|
|
|
HANGING,
|
|
|
|
MIDDLE,
|
|
|
|
ALPHABETIC,
|
|
|
|
IDEOGRAPHIC,
|
|
|
|
BOTTOM
|
2015-01-26 01:22:08 +03:00
|
|
|
};
|
2014-04-26 06:34:07 +04:00
|
|
|
|
2015-01-26 01:22:08 +03:00
|
|
|
enum class TextDrawOperation : uint8_t { FILL, STROKE, MEASURE };
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2014-04-26 06:34:07 +04:00
|
|
|
protected:
|
2012-06-13 19:14:15 +04:00
|
|
|
gfxFontGroup* GetCurrentFontStyle();
|
|
|
|
|
2015-07-14 23:59:12 +03:00
|
|
|
/**
|
|
|
|
* Implementation of the fillText, strokeText, and measure functions with
|
|
|
|
* the operation abstracted to a flag.
|
2020-01-18 22:51:04 +03:00
|
|
|
* Returns a TextMetrics object _only_ if the operation is measure;
|
|
|
|
* drawing operations (fill or stroke) always return nullptr.
|
2015-07-14 23:59:12 +03:00
|
|
|
*/
|
2020-01-18 22:51:04 +03:00
|
|
|
TextMetrics* DrawOrMeasureText(const nsAString& aText, float aX, float aY,
|
|
|
|
const Optional<double>& aMaxWidth,
|
|
|
|
TextDrawOperation aOp, ErrorResult& aError);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2016-08-10 15:30:51 +03: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 19:14:15 +04:00
|
|
|
// state stack handling
|
|
|
|
class ContextState {
|
|
|
|
public:
|
2019-04-01 17:32:32 +03:00
|
|
|
ContextState();
|
|
|
|
ContextState(const ContextState& aOther);
|
|
|
|
~ContextState();
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2020-11-23 19:09:05 +03:00
|
|
|
void SetColorStyle(Style aWhichStyle, nscolor aColor);
|
|
|
|
void SetPatternStyle(Style aWhichStyle, CanvasPattern* aPat);
|
|
|
|
void SetGradientStyle(Style aWhichStyle, CanvasGradient* aGrad);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2012-10-12 13:42:53 +04:00
|
|
|
/**
|
|
|
|
* returns true iff the given style is a solid color.
|
|
|
|
*/
|
2016-02-01 11:39:08 +03:00
|
|
|
bool StyleIsColor(Style aWhichStyle) const {
|
|
|
|
return !(patternStyles[aWhichStyle] || gradientStyles[aWhichStyle]);
|
2012-10-12 13:42:53 +04:00
|
|
|
}
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2014-09-24 01:47:20 +04: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 19:14:15 +04:00
|
|
|
|
2016-08-10 15:30:51 +03:00
|
|
|
nsTArray<ClipState> clipsAndTransforms;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFontGroup> fontGroup;
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> fontLanguage;
|
2014-09-24 01:47:19 +04:00
|
|
|
nsFont fontFont;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
EnumeratedArray<Style, Style::MAX, RefPtr<CanvasGradient>> gradientStyles;
|
|
|
|
EnumeratedArray<Style, Style::MAX, RefPtr<CanvasPattern>> patternStyles;
|
2014-04-26 06:34:07 +04:00
|
|
|
EnumeratedArray<Style, Style::MAX, nscolor> colorStyles;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
nsCString font;
|
2019-04-02 20:00:41 +03:00
|
|
|
TextAlign textAlign = TextAlign::START;
|
|
|
|
TextBaseline textBaseline = TextBaseline::ALPHABETIC;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2019-04-02 20:00:41 +03:00
|
|
|
nscolor shadowColor = 0;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2012-10-12 13:42:53 +04:00
|
|
|
mozilla::gfx::Matrix transform;
|
|
|
|
mozilla::gfx::Point shadowOffset;
|
2019-04-02 20:00:41 +03: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 09:19:12 +03:00
|
|
|
nsTArray<mozilla::gfx::Float> dash;
|
2019-04-02 20:00:41 +03:00
|
|
|
mozilla::gfx::Float dashOffset = 0.0f;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2019-04-02 20:00:41 +03: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 19:14:15 +04:00
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
nsCString filterString{"none"};
|
2019-05-27 15:37:37 +03:00
|
|
|
StyleOwnedSlice<StyleFilter> filterChain;
|
2018-09-03 13:24:27 +03: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-24 01:47:18 +04:00
|
|
|
mozilla::gfx::FilterDescription filter;
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<mozilla::gfx::SourceSurface>> filterAdditionalImages;
|
2016-10-11 22:18:45 +03: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 20:00:41 +03:00
|
|
|
bool filterSourceGraphicTainted = false;
|
2014-09-24 01:47:18 +04:00
|
|
|
|
2019-04-02 20:00:41 +03:00
|
|
|
bool imageSmoothingEnabled = true;
|
|
|
|
bool fontExplicitLanguage = false;
|
2012-06-13 19:14:15 +04:00
|
|
|
};
|
|
|
|
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<ContextState, 3> mStyleStack;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
|
|
|
inline ContextState& CurrentState() {
|
|
|
|
return mStyleStack[mStyleStack.Length() - 1];
|
|
|
|
}
|
|
|
|
|
2013-10-16 16:27:59 +04:00
|
|
|
inline const ContextState& CurrentState() const {
|
|
|
|
return mStyleStack[mStyleStack.Length() - 1];
|
|
|
|
}
|
|
|
|
|
2012-06-29 22:20:13 +04:00
|
|
|
friend class CanvasGeneralPattern;
|
2012-06-13 19:14:15 +04:00
|
|
|
friend class AdjustedTarget;
|
2014-09-24 01:47:20 +04:00
|
|
|
friend class AdjustedTargetForShadow;
|
2014-09-24 01:47:20 +04:00
|
|
|
friend class AdjustedTargetForFilter;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
|
|
|
// other helpers
|
2020-11-23 19:08:23 +03:00
|
|
|
void GetAppUnitsValues(int32_t* aPerDevPixel, int32_t* aPerCSSPixel);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2012-10-12 13:42:52 +04:00
|
|
|
friend struct CanvasBidiProcessor;
|
2014-09-11 00:15:43 +04:00
|
|
|
friend class CanvasDrawObserver;
|
2018-11-07 01:31:34 +03:00
|
|
|
friend class ImageBitmap;
|
|
|
|
|
2019-02-21 01:54:04 +03:00
|
|
|
void SetWriteOnly();
|
2018-11-07 01:31:34 +03:00
|
|
|
|
|
|
|
bool IsWriteOnly() const { return mWriteOnly; }
|
|
|
|
|
|
|
|
bool mWriteOnly;
|
2019-11-30 00:55:04 +03:00
|
|
|
bool mClipsNeedConverting = false;
|
2012-06-13 19:14:15 +04:00
|
|
|
};
|
|
|
|
|
2017-09-13 13:21:12 +03:00
|
|
|
size_t BindingJSObjectMallocBytes(CanvasRenderingContext2D* aContext);
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2012-10-12 13:42:52 +04:00
|
|
|
|
|
|
|
#endif /* CanvasRenderingContext2D_h */
|