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
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-06-13 19:14:15 +04:00
|
|
|
#include <vector>
|
|
|
|
#include "nsIDOMCanvasRenderingContext2D.h"
|
|
|
|
#include "nsICanvasRenderingContextInternal.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "nsColor.h"
|
2013-01-04 09:16:14 +04:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2013-03-19 16:27:35 +04:00
|
|
|
#include "mozilla/dom/HTMLVideoElement.h"
|
2012-11-14 04:35:36 +04:00
|
|
|
#include "CanvasUtils.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "gfxTextRun.h"
|
2012-06-13 19:14:15 +04:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2013-04-26 18:55:37 +04:00
|
|
|
#include "mozilla/dom/CanvasGradient.h"
|
2013-01-17 06:55:43 +04:00
|
|
|
#include "mozilla/dom/CanvasRenderingContext2DBinding.h"
|
2013-04-19 12:49:22 +04:00
|
|
|
#include "mozilla/dom/CanvasPattern.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"
|
|
|
|
#include "gfx2DGlue.h"
|
2013-10-17 06:55:08 +04:00
|
|
|
#include "imgIEncoder.h"
|
2014-01-13 04:29:48 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2014-04-26 06:34:07 +04:00
|
|
|
#include "mozilla/EnumeratedArray.h"
|
2014-09-24 01:47:18 +04:00
|
|
|
#include "FilterSupport.h"
|
2014-09-24 01:47:19 +04:00
|
|
|
#include "nsSVGEffects.h"
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2013-10-08 19:51:42 +04:00
|
|
|
class nsGlobalWindow;
|
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 {
|
2014-07-12 02:10:49 +04:00
|
|
|
namespace gl {
|
2012-06-13 19:14:15 +04:00
|
|
|
class SourceSurface;
|
|
|
|
}
|
|
|
|
|
2012-10-12 13:42:52 +04:00
|
|
|
namespace dom {
|
2013-07-26 22:25:54 +04:00
|
|
|
class HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement;
|
2013-08-23 09:17:11 +04:00
|
|
|
class ImageData;
|
2013-07-26 22:25:54 +04:00
|
|
|
class StringOrCanvasGradientOrCanvasPattern;
|
2013-09-17 19:16:02 +04:00
|
|
|
class OwningStringOrCanvasGradientOrCanvasPattern;
|
2013-04-19 12:49:22 +04:00
|
|
|
class TextMetrics;
|
2014-08-25 17:03:00 +04:00
|
|
|
class SVGMatrix;
|
2014-09-24 01:47:19 +04:00
|
|
|
class CanvasFilterChainObserver;
|
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;
|
|
|
|
|
2014-05-14 00:22:52 +04:00
|
|
|
class CanvasPath MOZ_FINAL :
|
2014-03-18 16:03:06 +04:00
|
|
|
public nsWrapperCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CanvasPath)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(CanvasPath)
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> GetParentObject() { return mParent; }
|
|
|
|
|
2014-04-09 02:27:18 +04:00
|
|
|
JSObject* WrapObject(JSContext* aCx);
|
2014-03-18 16:03:06 +04:00
|
|
|
|
|
|
|
static already_AddRefed<CanvasPath> Constructor(const GlobalObject& aGlobal,
|
|
|
|
ErrorResult& rv);
|
|
|
|
static already_AddRefed<CanvasPath> Constructor(const GlobalObject& aGlobal,
|
|
|
|
CanvasPath& aCanvasPath,
|
|
|
|
ErrorResult& rv);
|
2014-03-24 17:31:19 +04:00
|
|
|
static already_AddRefed<CanvasPath> Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aPathString,
|
|
|
|
ErrorResult& rv);
|
2014-03-18 16:03:06 +04:00
|
|
|
|
|
|
|
void ClosePath();
|
|
|
|
void MoveTo(double x, double y);
|
|
|
|
void LineTo(double x, double y);
|
|
|
|
void QuadraticCurveTo(double cpx, double cpy, double x, double y);
|
|
|
|
void BezierCurveTo(double cp1x, double cp1y,
|
|
|
|
double cp2x, double cp2y,
|
|
|
|
double x, double y);
|
|
|
|
void ArcTo(double x1, double y1, double x2, double y2, double radius,
|
|
|
|
ErrorResult& error);
|
|
|
|
void Rect(double x, double y, double w, double h);
|
|
|
|
void Arc(double x, double y, double radius,
|
|
|
|
double startAngle, double endAngle, bool anticlockwise,
|
|
|
|
ErrorResult& error);
|
|
|
|
|
|
|
|
void LineTo(const gfx::Point& aPoint);
|
|
|
|
void BezierTo(const gfx::Point& aCP1,
|
|
|
|
const gfx::Point& aCP2,
|
|
|
|
const gfx::Point& aCP3);
|
|
|
|
|
2014-06-17 13:37:46 +04:00
|
|
|
TemporaryRef<gfx::Path> GetPath(const CanvasWindingRule& aWinding,
|
|
|
|
const gfx::DrawTarget* aTarget) const;
|
2014-03-18 16:03:06 +04:00
|
|
|
|
2014-05-14 00:22:52 +04:00
|
|
|
explicit CanvasPath(nsISupports* aParent);
|
2014-06-17 13:37:46 +04:00
|
|
|
// TemporaryRef arg because the return value from Path::CopyToBuilder() is
|
|
|
|
// passed directly and we can't drop the only ref to have a raw pointer.
|
|
|
|
CanvasPath(nsISupports* aParent,
|
|
|
|
TemporaryRef<gfx::PathBuilder> aPathBuilder);
|
2014-03-18 16:03:06 +04:00
|
|
|
|
2014-08-25 17:03:00 +04:00
|
|
|
void AddPath(CanvasPath& aCanvasPath,
|
|
|
|
const Optional<NonNull<SVGMatrix>>& aMatrix);
|
|
|
|
|
2014-03-18 16:03:06 +04:00
|
|
|
private:
|
2014-06-26 17:30:49 +04:00
|
|
|
virtual ~CanvasPath() {}
|
2014-03-18 16:03:06 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> mParent;
|
|
|
|
static gfx::Float ToFloat(double aValue) { return gfx::Float(aValue); }
|
|
|
|
|
2014-03-31 10:55:00 +04:00
|
|
|
mutable RefPtr<gfx::Path> mPath;
|
2014-03-18 16:03:06 +04:00
|
|
|
mutable RefPtr<gfx::PathBuilder> mPathBuilder;
|
2014-03-31 10:55:00 +04:00
|
|
|
|
|
|
|
void EnsurePathBuilder() const;
|
2014-03-18 16:03:06 +04:00
|
|
|
};
|
|
|
|
|
2012-10-12 13:42:52 +04:00
|
|
|
struct CanvasBidiProcessor;
|
|
|
|
class CanvasRenderingContext2DUserData;
|
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
|
|
|
**/
|
2014-08-05 21:33:55 +04:00
|
|
|
class CanvasRenderingContext2D MOZ_FINAL :
|
2012-06-13 19:14:15 +04:00
|
|
|
public nsICanvasRenderingContextInternal,
|
|
|
|
public nsWrapperCache
|
|
|
|
{
|
2013-07-26 22:25:54 +04:00
|
|
|
typedef HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement
|
2012-06-13 19:14:15 +04:00
|
|
|
HTMLImageOrCanvasOrVideoElement;
|
|
|
|
|
2014-06-26 17:30:49 +04:00
|
|
|
virtual ~CanvasRenderingContext2D();
|
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
public:
|
2012-10-12 13:42:52 +04:00
|
|
|
CanvasRenderingContext2D();
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2014-04-09 02:27:18 +04:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
|
2012-05-22 01:30:07 +04:00
|
|
|
|
2013-01-04 09:16:14 +04:00
|
|
|
HTMLCanvasElement* GetCanvas() const
|
2012-06-13 19:14:15 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void Save();
|
|
|
|
void Restore();
|
|
|
|
void Scale(double x, double y, mozilla::ErrorResult& error);
|
|
|
|
void Rotate(double angle, mozilla::ErrorResult& error);
|
|
|
|
void Translate(double x, double y, mozilla::ErrorResult& error);
|
|
|
|
void Transform(double m11, double m12, double m21, double m22, double dx,
|
|
|
|
double dy, mozilla::ErrorResult& error);
|
|
|
|
void SetTransform(double m11, double m12, double m21, double m22, double dx,
|
|
|
|
double dy, mozilla::ErrorResult& error);
|
|
|
|
|
2012-09-11 23:08:24 +04:00
|
|
|
double GlobalAlpha()
|
2012-06-13 19:14:15 +04:00
|
|
|
{
|
|
|
|
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); }
|
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
void SetGlobalAlpha(double globalAlpha)
|
|
|
|
{
|
2012-11-28 00:32:05 +04:00
|
|
|
if (globalAlpha >= 0.0 && globalAlpha <= 1.0) {
|
2013-01-29 05:39:47 +04:00
|
|
|
CurrentState().globalAlpha = ToFloat(globalAlpha);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetGlobalCompositeOperation(nsAString& op, mozilla::ErrorResult& error);
|
|
|
|
void SetGlobalCompositeOperation(const nsAString& op,
|
|
|
|
mozilla::ErrorResult& error);
|
|
|
|
|
2013-09-17 19:16:02 +04:00
|
|
|
void GetStrokeStyle(OwningStringOrCanvasGradientOrCanvasPattern& value)
|
2012-06-13 19:14:15 +04:00
|
|
|
{
|
2014-04-26 06:34:07 +04:00
|
|
|
GetStyleAsUnion(value, Style::STROKE);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2013-07-26 22:25:54 +04:00
|
|
|
void SetStrokeStyle(const StringOrCanvasGradientOrCanvasPattern& value)
|
|
|
|
{
|
2014-04-26 06:34:07 +04:00
|
|
|
SetStyleFromUnion(value, Style::STROKE);
|
2013-07-26 22:25:54 +04:00
|
|
|
}
|
|
|
|
|
2013-09-17 19:16:02 +04:00
|
|
|
void GetFillStyle(OwningStringOrCanvasGradientOrCanvasPattern& value)
|
2013-07-26 22:25:54 +04:00
|
|
|
{
|
2014-04-26 06:34:07 +04:00
|
|
|
GetStyleAsUnion(value, Style::FILL);
|
2013-07-26 22:25:54 +04:00
|
|
|
}
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2013-07-26 22:25:54 +04:00
|
|
|
void SetFillStyle(const StringOrCanvasGradientOrCanvasPattern& value)
|
2012-06-13 19:14:15 +04:00
|
|
|
{
|
2014-04-26 06:34:07 +04:00
|
|
|
SetStyleFromUnion(value, Style::FILL);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2013-04-26 18:55:54 +04:00
|
|
|
already_AddRefed<CanvasGradient>
|
|
|
|
CreateLinearGradient(double x0, double y0, double x1, double y1);
|
|
|
|
already_AddRefed<CanvasGradient>
|
2012-06-13 19:14:15 +04:00
|
|
|
CreateRadialGradient(double x0, double y0, double r0, double x1, double y1,
|
2013-04-26 18:55:54 +04:00
|
|
|
double r1, ErrorResult& aError);
|
2013-04-19 12:49:22 +04:00
|
|
|
already_AddRefed<CanvasPattern>
|
2012-06-13 19:14:15 +04:00
|
|
|
CreatePattern(const HTMLImageOrCanvasOrVideoElement& element,
|
2013-04-26 18:55:54 +04:00
|
|
|
const nsAString& repeat, ErrorResult& error);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2012-09-11 23:08:24 +04:00
|
|
|
double ShadowOffsetX()
|
2012-06-13 19:14:15 +04:00
|
|
|
{
|
|
|
|
return CurrentState().shadowOffset.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetShadowOffsetX(double shadowOffsetX)
|
|
|
|
{
|
2013-01-29 05:39:47 +04:00
|
|
|
CurrentState().shadowOffset.x = ToFloat(shadowOffsetX);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2012-09-11 23:08:24 +04:00
|
|
|
double ShadowOffsetY()
|
2012-06-13 19:14:15 +04:00
|
|
|
{
|
|
|
|
return CurrentState().shadowOffset.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetShadowOffsetY(double shadowOffsetY)
|
|
|
|
{
|
2013-01-29 05:39:47 +04:00
|
|
|
CurrentState().shadowOffset.y = ToFloat(shadowOffsetY);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2012-09-11 23:08:24 +04:00
|
|
|
double ShadowBlur()
|
2012-06-13 19:14:15 +04:00
|
|
|
{
|
|
|
|
return CurrentState().shadowBlur;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetShadowBlur(double shadowBlur)
|
|
|
|
{
|
2012-11-28 00:32:05 +04:00
|
|
|
if (shadowBlur >= 0.0) {
|
2013-01-29 05:39:47 +04:00
|
|
|
CurrentState().shadowBlur = ToFloat(shadowBlur);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetShadowColor(nsAString& shadowColor)
|
|
|
|
{
|
|
|
|
StyleColorToString(CurrentState().shadowColor, shadowColor);
|
|
|
|
}
|
|
|
|
|
2014-09-24 01:44:53 +04:00
|
|
|
void GetFilter(nsAString& filter)
|
|
|
|
{
|
|
|
|
filter = CurrentState().filterString;
|
|
|
|
}
|
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
void SetShadowColor(const nsAString& shadowColor);
|
2014-09-24 01:44:53 +04:00
|
|
|
void SetFilter(const nsAString& filter, mozilla::ErrorResult& error);
|
2012-06-13 19:14:15 +04:00
|
|
|
void ClearRect(double x, double y, double w, double h);
|
|
|
|
void FillRect(double x, double y, double w, double h);
|
|
|
|
void StrokeRect(double x, double y, double w, double h);
|
|
|
|
void BeginPath();
|
2013-01-17 06:55:43 +04:00
|
|
|
void Fill(const CanvasWindingRule& winding);
|
2014-03-18 16:03:06 +04:00
|
|
|
void Fill(const CanvasPath& path, const CanvasWindingRule& winding);
|
2012-06-13 19:14:15 +04:00
|
|
|
void Stroke();
|
2014-03-18 16:03:06 +04:00
|
|
|
void Stroke(const CanvasPath& path);
|
2014-01-15 18:50:31 +04:00
|
|
|
void DrawFocusIfNeeded(mozilla::dom::Element& element);
|
2013-11-04 23:52:24 +04:00
|
|
|
bool DrawCustomFocusRing(mozilla::dom::Element& element);
|
2013-01-17 06:55:43 +04:00
|
|
|
void Clip(const CanvasWindingRule& winding);
|
2014-03-18 16:03:06 +04:00
|
|
|
void Clip(const CanvasPath& path, const CanvasWindingRule& winding);
|
2013-01-17 06:55:43 +04:00
|
|
|
bool IsPointInPath(double x, double y, const CanvasWindingRule& winding);
|
2014-03-19 21:42:38 +04:00
|
|
|
bool IsPointInPath(const CanvasPath& path, double x, double y, const CanvasWindingRule& winding);
|
2012-11-22 17:37:42 +04:00
|
|
|
bool IsPointInStroke(double x, double y);
|
2014-03-19 21:42:38 +04:00
|
|
|
bool IsPointInStroke(const CanvasPath& path, double x, double y);
|
2012-06-13 19:14:15 +04:00
|
|
|
void FillText(const nsAString& text, double x, double y,
|
2013-07-26 22:25:54 +04:00
|
|
|
const Optional<double>& maxWidth,
|
2012-06-13 19:14:15 +04:00
|
|
|
mozilla::ErrorResult& error);
|
|
|
|
void StrokeText(const nsAString& text, double x, double y,
|
2013-07-26 22:25:54 +04:00
|
|
|
const Optional<double>& maxWidth,
|
2012-06-13 19:14:15 +04:00
|
|
|
mozilla::ErrorResult& error);
|
2013-04-19 12:49:22 +04:00
|
|
|
TextMetrics*
|
2012-06-13 19:14:15 +04:00
|
|
|
MeasureText(const nsAString& rawText, mozilla::ErrorResult& error);
|
|
|
|
|
2014-02-21 17:35:36 +04:00
|
|
|
void AddHitRegion(const HitRegionOptions& options, mozilla::ErrorResult& error);
|
2014-02-21 17:35:14 +04:00
|
|
|
void RemoveHitRegion(const nsAString& id);
|
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
void DrawImage(const HTMLImageOrCanvasOrVideoElement& image,
|
|
|
|
double dx, double dy, mozilla::ErrorResult& error)
|
|
|
|
{
|
|
|
|
DrawImage(image, 0.0, 0.0, 0.0, 0.0, dx, dy, 0.0, 0.0, 0, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawImage(const HTMLImageOrCanvasOrVideoElement& image,
|
|
|
|
double dx, double dy, double dw, double dh,
|
|
|
|
mozilla::ErrorResult& error)
|
|
|
|
{
|
|
|
|
DrawImage(image, 0.0, 0.0, 0.0, 0.0, dx, dy, dw, dh, 2, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawImage(const HTMLImageOrCanvasOrVideoElement& image,
|
|
|
|
double sx, double sy, double sw, double sh, double dx,
|
|
|
|
double dy, double dw, double dh, mozilla::ErrorResult& error)
|
|
|
|
{
|
|
|
|
DrawImage(image, sx, sy, sw, sh, dx, dy, dw, dh, 6, error);
|
|
|
|
}
|
|
|
|
|
2013-07-26 22:25:54 +04:00
|
|
|
already_AddRefed<ImageData>
|
2012-06-13 19:14:15 +04:00
|
|
|
CreateImageData(JSContext* cx, double sw, double sh,
|
|
|
|
mozilla::ErrorResult& error);
|
2013-07-26 22:25:54 +04:00
|
|
|
already_AddRefed<ImageData>
|
|
|
|
CreateImageData(JSContext* cx, ImageData& imagedata,
|
2012-06-13 19:14:15 +04:00
|
|
|
mozilla::ErrorResult& error);
|
2013-07-26 22:25:54 +04:00
|
|
|
already_AddRefed<ImageData>
|
2012-06-13 19:14:15 +04:00
|
|
|
GetImageData(JSContext* cx, double sx, double sy, double sw, double sh,
|
|
|
|
mozilla::ErrorResult& error);
|
2013-07-26 22:25:54 +04:00
|
|
|
void PutImageData(ImageData& imageData,
|
2012-06-13 19:14:15 +04:00
|
|
|
double dx, double dy, mozilla::ErrorResult& error);
|
2013-07-26 22:25:54 +04:00
|
|
|
void PutImageData(ImageData& imageData,
|
2012-06-13 19:14:15 +04:00
|
|
|
double dx, double dy, double dirtyX, double dirtyY,
|
|
|
|
double dirtyWidth, double dirtyHeight,
|
|
|
|
mozilla::ErrorResult& error);
|
|
|
|
|
2012-09-11 23:08:24 +04:00
|
|
|
double LineWidth()
|
2012-06-13 19:14:15 +04:00
|
|
|
{
|
|
|
|
return CurrentState().lineWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetLineWidth(double width)
|
|
|
|
{
|
2012-11-28 00:32:05 +04:00
|
|
|
if (width > 0.0) {
|
2013-01-29 05:39:47 +04:00
|
|
|
CurrentState().lineWidth = ToFloat(width);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void GetLineCap(nsAString& linecap);
|
|
|
|
void SetLineCap(const nsAString& linecap);
|
|
|
|
void GetLineJoin(nsAString& linejoin, mozilla::ErrorResult& error);
|
|
|
|
void SetLineJoin(const nsAString& linejoin);
|
|
|
|
|
2012-09-11 23:08:24 +04:00
|
|
|
double MiterLimit()
|
2012-06-13 19:14:15 +04:00
|
|
|
{
|
|
|
|
return CurrentState().miterLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMiterLimit(double miter)
|
|
|
|
{
|
2012-11-28 00:32:05 +04:00
|
|
|
if (miter > 0.0) {
|
2013-01-29 05:39:47 +04:00
|
|
|
CurrentState().miterLimit = ToFloat(miter);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetFont(nsAString& font)
|
|
|
|
{
|
|
|
|
font = GetFont();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetFont(const nsAString& font, mozilla::ErrorResult& error);
|
|
|
|
void GetTextAlign(nsAString& textAlign);
|
|
|
|
void SetTextAlign(const nsAString& textAlign);
|
|
|
|
void GetTextBaseline(nsAString& textBaseline);
|
|
|
|
void SetTextBaseline(const nsAString& textBaseline);
|
|
|
|
|
|
|
|
void ClosePath()
|
|
|
|
{
|
|
|
|
EnsureWritablePath();
|
|
|
|
|
|
|
|
if (mPathBuilder) {
|
|
|
|
mPathBuilder->Close();
|
|
|
|
} else {
|
|
|
|
mDSPathBuilder->Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MoveTo(double x, double y)
|
|
|
|
{
|
2012-11-28 00:32:05 +04:00
|
|
|
EnsureWritablePath();
|
|
|
|
|
|
|
|
if (mPathBuilder) {
|
2013-01-29 05:39:47 +04:00
|
|
|
mPathBuilder->MoveTo(mozilla::gfx::Point(ToFloat(x), ToFloat(y)));
|
2012-11-28 00:32:05 +04:00
|
|
|
} else {
|
|
|
|
mDSPathBuilder->MoveTo(mTarget->GetTransform() *
|
2013-01-29 05:39:47 +04:00
|
|
|
mozilla::gfx::Point(ToFloat(x), ToFloat(y)));
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LineTo(double x, double y)
|
|
|
|
{
|
2012-11-28 00:32:05 +04:00
|
|
|
EnsureWritablePath();
|
2013-07-26 22:25:54 +04:00
|
|
|
|
2013-01-29 05:39:47 +04:00
|
|
|
LineTo(mozilla::gfx::Point(ToFloat(x), ToFloat(y)));
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void QuadraticCurveTo(double cpx, double cpy, double x, double y)
|
|
|
|
{
|
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) {
|
2013-01-29 05:39:47 +04:00
|
|
|
mPathBuilder->QuadraticBezierTo(mozilla::gfx::Point(ToFloat(cpx), ToFloat(cpy)),
|
|
|
|
mozilla::gfx::Point(ToFloat(x), ToFloat(y)));
|
2012-11-28 00:32:05 +04:00
|
|
|
} else {
|
|
|
|
mozilla::gfx::Matrix transform = mTarget->GetTransform();
|
|
|
|
mDSPathBuilder->QuadraticBezierTo(transform *
|
2013-01-29 05:39:47 +04:00
|
|
|
mozilla::gfx::Point(ToFloat(cpx), ToFloat(cpy)),
|
2012-11-28 00:32:05 +04:00
|
|
|
transform *
|
2013-01-29 05:39:47 +04:00
|
|
|
mozilla::gfx::Point(ToFloat(x), ToFloat(y)));
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y)
|
|
|
|
{
|
2012-11-28 00:32:05 +04:00
|
|
|
EnsureWritablePath();
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2013-01-29 05:39:47 +04:00
|
|
|
BezierTo(mozilla::gfx::Point(ToFloat(cp1x), ToFloat(cp1y)),
|
|
|
|
mozilla::gfx::Point(ToFloat(cp2x), ToFloat(cp2y)),
|
|
|
|
mozilla::gfx::Point(ToFloat(x), ToFloat(y)));
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ArcTo(double x1, double y1, double x2, double y2, double radius,
|
|
|
|
mozilla::ErrorResult& error);
|
|
|
|
void Rect(double x, double y, double w, double h);
|
|
|
|
void Arc(double x, double y, double radius, double startAngle,
|
|
|
|
double endAngle, bool anticlockwise, mozilla::ErrorResult& error);
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void GetMozCurrentTransform(JSContext* cx,
|
2014-07-12 00:45:22 +04:00
|
|
|
JS::MutableHandle<JSObject*> result,
|
|
|
|
mozilla::ErrorResult& error) const;
|
2013-05-16 20:36:55 +04:00
|
|
|
void SetMozCurrentTransform(JSContext* cx,
|
|
|
|
JS::Handle<JSObject*> currentTransform,
|
2012-06-13 19:14:15 +04:00
|
|
|
mozilla::ErrorResult& error);
|
2014-06-12 00:26:52 +04:00
|
|
|
void GetMozCurrentTransformInverse(JSContext* cx,
|
2014-07-12 00:45:22 +04:00
|
|
|
JS::MutableHandle<JSObject*> result,
|
|
|
|
mozilla::ErrorResult& error) const;
|
2013-05-16 20:36:55 +04:00
|
|
|
void SetMozCurrentTransformInverse(JSContext* cx,
|
|
|
|
JS::Handle<JSObject*> currentTransform,
|
2012-06-13 19:14:15 +04:00
|
|
|
mozilla::ErrorResult& error);
|
|
|
|
void GetFillRule(nsAString& fillRule);
|
|
|
|
void SetFillRule(const nsAString& fillRule);
|
2014-06-12 00:26:52 +04:00
|
|
|
void GetMozDash(JSContext* cx, JS::MutableHandle<JS::Value> retval,
|
2014-07-12 00:45:22 +04:00
|
|
|
mozilla::ErrorResult& error);
|
2012-06-13 19:14:15 +04:00
|
|
|
void SetMozDash(JSContext* cx, const JS::Value& mozDash,
|
|
|
|
mozilla::ErrorResult& error);
|
|
|
|
|
2014-01-22 23:37:10 +04:00
|
|
|
void SetLineDash(const Sequence<double>& mSegments);
|
2013-10-16 16:27:59 +04:00
|
|
|
void GetLineDash(nsTArray<double>& mSegments) const;
|
|
|
|
|
|
|
|
void SetLineDashOffset(double mOffset);
|
|
|
|
double LineDashOffset() const;
|
|
|
|
|
2012-09-11 23:08:24 +04:00
|
|
|
double MozDashOffset()
|
2012-06-13 19:14:15 +04:00
|
|
|
{
|
|
|
|
return CurrentState().dashOffset;
|
|
|
|
}
|
2012-11-14 04:35:36 +04:00
|
|
|
void SetMozDashOffset(double mozDashOffset);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
|
|
|
void GetMozTextStyle(nsAString& mozTextStyle)
|
|
|
|
{
|
|
|
|
GetFont(mozTextStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMozTextStyle(const nsAString& mozTextStyle,
|
|
|
|
mozilla::ErrorResult& error)
|
|
|
|
{
|
|
|
|
SetFont(mozTextStyle, error);
|
|
|
|
}
|
|
|
|
|
2012-09-11 23:08:24 +04:00
|
|
|
bool ImageSmoothingEnabled()
|
2012-06-13 19:14:15 +04:00
|
|
|
{
|
|
|
|
return CurrentState().imageSmoothingEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetImageSmoothingEnabled(bool imageSmoothingEnabled)
|
|
|
|
{
|
|
|
|
if (imageSmoothingEnabled != CurrentState().imageSmoothingEnabled) {
|
|
|
|
CurrentState().imageSmoothingEnabled = imageSmoothingEnabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-08 19:51:42 +04:00
|
|
|
void DrawWindow(nsGlobalWindow& window, double x, double y, double w, double h,
|
2012-06-13 19:14:15 +04:00
|
|
|
const nsAString& bgColor, uint32_t flags,
|
|
|
|
mozilla::ErrorResult& error);
|
2013-01-29 21:51:55 +04:00
|
|
|
void AsyncDrawXULElement(nsXULElement& elem, double x, double y, double w,
|
2012-06-13 19:14:15 +04:00
|
|
|
double h, const nsAString& bgColor, uint32_t flags,
|
|
|
|
mozilla::ErrorResult& error);
|
|
|
|
|
2014-09-03 03:26:36 +04:00
|
|
|
enum RenderingMode {
|
|
|
|
SoftwareBackendMode,
|
|
|
|
OpenGLBackendMode,
|
|
|
|
DefaultBackendMode
|
|
|
|
};
|
|
|
|
|
|
|
|
bool SwitchRenderingMode(RenderingMode aRenderingMode);
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2013-10-01 01:02:40 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
virtual int32_t GetWidth() const MOZ_OVERRIDE;
|
|
|
|
virtual int32_t GetHeight() const MOZ_OVERRIDE;
|
|
|
|
#endif
|
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
|
|
|
|
*/
|
|
|
|
virtual nsIPresShell *GetPresShell() MOZ_OVERRIDE {
|
|
|
|
if (mCanvasElement) {
|
|
|
|
return mCanvasElement->OwnerDoc()->GetShell();
|
|
|
|
}
|
|
|
|
if (mDocShell) {
|
|
|
|
return mDocShell->GetPresShell();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-30 00:43:41 +04:00
|
|
|
NS_IMETHOD SetDimensions(int32_t width, int32_t height) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD InitializeWithSurface(nsIDocShell *shell, gfxASurface *surface, int32_t width, int32_t height) MOZ_OVERRIDE;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
|
|
|
NS_IMETHOD GetInputStream(const char* aMimeType,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aEncoderOptions,
|
2013-05-30 00:43:41 +04:00
|
|
|
nsIInputStream **aStream) MOZ_OVERRIDE;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2014-04-17 09:28:17 +04:00
|
|
|
mozilla::TemporaryRef<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(bool* aPremultAlpha = nullptr) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
EnsureTarget();
|
|
|
|
if (aPremultAlpha) {
|
|
|
|
*aPremultAlpha = true;
|
|
|
|
}
|
|
|
|
return mTarget->Snapshot();
|
|
|
|
}
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
NS_IMETHOD SetIsOpaque(bool isOpaque) MOZ_OVERRIDE;
|
2014-03-16 23:34:14 +04:00
|
|
|
bool GetIsOpaque() MOZ_OVERRIDE { return mOpaque; }
|
2013-05-30 00:43:41 +04:00
|
|
|
NS_IMETHOD Reset() MOZ_OVERRIDE;
|
2012-06-13 19:14:15 +04:00
|
|
|
already_AddRefed<CanvasLayer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
|
2012-10-12 13:42:53 +04:00
|
|
|
CanvasLayer *aOldLayer,
|
2013-05-30 00:43:41 +04:00
|
|
|
LayerManager *aManager) MOZ_OVERRIDE;
|
|
|
|
virtual bool ShouldForceInactiveLayer(LayerManager *aManager) MOZ_OVERRIDE;
|
|
|
|
void MarkContextClean() MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD SetIsIPC(bool isIPC) MOZ_OVERRIDE;
|
2012-06-13 19:14:15 +04:00
|
|
|
// this rect is in canvas device space
|
|
|
|
void Redraw(const mozilla::gfx::Rect &r);
|
2013-05-30 00:43:41 +04:00
|
|
|
NS_IMETHOD Redraw(const gfxRect &r) MOZ_OVERRIDE { Redraw(ToRect(r)); return NS_OK; }
|
2013-12-21 01:50:48 +04:00
|
|
|
NS_IMETHOD SetContextOptions(JSContext* aCx, JS::Handle<JS::Value> aOptions) MOZ_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.
|
|
|
|
*/
|
|
|
|
virtual void DidRefresh() MOZ_OVERRIDE;
|
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
// this rect is in mTarget's current user space
|
|
|
|
void RedrawUser(const gfxRect &r);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2014-04-26 06:34:07 +04:00
|
|
|
MOZ_BEGIN_NESTED_ENUM_CLASS(CanvasMultiGetterType, uint8_t)
|
|
|
|
STRING = 0,
|
|
|
|
PATTERN = 1,
|
|
|
|
GRADIENT = 2
|
|
|
|
MOZ_END_NESTED_ENUM_CLASS(CanvasMultiGetterType)
|
|
|
|
|
|
|
|
MOZ_BEGIN_NESTED_ENUM_CLASS(Style, uint8_t)
|
|
|
|
STROKE = 0,
|
|
|
|
FILL,
|
|
|
|
MAX
|
|
|
|
MOZ_END_NESTED_ENUM_CLASS(Style)
|
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 {
|
|
|
|
mDSPathBuilder->LineTo(mTarget->GetTransform() * aPoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
mDSPathBuilder->BezierTo(transform * aCP1,
|
|
|
|
transform * aCP2,
|
|
|
|
transform * aCP3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 13:42:52 +04:00
|
|
|
friend class CanvasRenderingContext2DUserData;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2013-10-17 06:55:08 +04:00
|
|
|
virtual void GetImageBuffer(uint8_t** aImageBuffer, int32_t* aFormat);
|
|
|
|
|
2014-05-20 08:54:00 +04:00
|
|
|
|
|
|
|
// Given a point, return hit region ID if it exists
|
|
|
|
nsString GetHitRegion(const mozilla::gfx::Point& aPoint);
|
|
|
|
|
|
|
|
|
2014-05-19 03:43:00 +04:00
|
|
|
// return true and fills in the bound rect if element has a hit region.
|
|
|
|
bool GetHitRegionRect(Element* aElement, nsRect& aRect);
|
|
|
|
|
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,
|
|
|
|
JSObject** aRetval);
|
|
|
|
|
2012-11-14 04:35:36 +04:00
|
|
|
nsresult PutImageData_explicit(int32_t x, int32_t y, uint32_t w, uint32_t h,
|
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-28 01:32:41 +04:00
|
|
|
dom::Uint8ClampedArray* aArray,
|
2012-11-14 04:35:36 +04:00
|
|
|
bool hasDirtyRect, int32_t dirtyX, int32_t dirtyY,
|
|
|
|
int32_t dirtyWidth, int32_t dirtyHeight);
|
|
|
|
|
2012-07-24 14:18:39 +04:00
|
|
|
/**
|
|
|
|
* Internal method to complete initialisation, expects mTarget to have been set
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult Initialize(int32_t width, int32_t height);
|
2012-07-24 14:18:39 +04:00
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
nsresult InitializeWithTarget(mozilla::gfx::DrawTarget *surface,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t width, int32_t height);
|
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.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sNumLivingContexts;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup table used to speed up GetImageData().
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint8_t (*sUnpremultiplyTable)[256];
|
2012-06-13 19:14:15 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup table used to speed up PutImageData().
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint8_t (*sPremultiplyTable)[256];
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2012-05-31 04:47:27 +04:00
|
|
|
static mozilla::gfx::DrawTarget* sErrorTarget;
|
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
// Some helpers. Doesn't modify a color on failure.
|
2013-07-26 22:25:54 +04:00
|
|
|
void SetStyleFromUnion(const StringOrCanvasGradientOrCanvasPattern& value,
|
|
|
|
Style whichStyle);
|
2012-06-13 19:14:15 +04:00
|
|
|
void SetStyleFromString(const nsAString& str, Style whichStyle);
|
|
|
|
|
2013-07-26 22:25:54 +04:00
|
|
|
void SetStyleFromGradient(CanvasGradient& gradient, Style whichStyle)
|
2012-06-13 19:14:15 +04:00
|
|
|
{
|
2013-07-26 22:25:54 +04:00
|
|
|
CurrentState().SetGradientStyle(whichStyle, &gradient);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2013-07-26 22:25:54 +04:00
|
|
|
void SetStyleFromPattern(CanvasPattern& pattern, Style whichStyle)
|
2012-06-13 19:14:15 +04:00
|
|
|
{
|
2013-07-26 22:25:54 +04:00
|
|
|
CurrentState().SetPatternStyle(whichStyle, &pattern);
|
2012-06-13 19:14:15 +04:00
|
|
|
}
|
|
|
|
|
2013-09-17 19:16:02 +04:00
|
|
|
void GetStyleAsUnion(OwningStringOrCanvasGradientOrCanvasPattern& 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.
|
|
|
|
bool ParseColor(const nsAString& aString, nscolor* aColor);
|
|
|
|
|
|
|
|
static void StyleColorToString(const nscolor& aColor, nsAString& aStr);
|
|
|
|
|
2014-09-24 01:46:11 +04:00
|
|
|
// Returns whether a filter was successfully parsed.
|
|
|
|
bool ParseFilter(const nsAString& aString,
|
|
|
|
nsTArray<nsStyleFilter>& aFilterChain,
|
|
|
|
ErrorResult& error);
|
|
|
|
|
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.
|
2013-05-06 23:28:13 +04:00
|
|
|
void EnsureUserSpacePath(const CanvasWindingRule& winding = 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
|
|
|
*
|
|
|
|
* Returns the actual rendering mode being used by the created target.
|
2012-05-31 04:47:27 +04:00
|
|
|
*/
|
2014-09-03 03:26:36 +04:00
|
|
|
RenderingMode EnsureTarget(RenderingMode aRenderMode = RenderingMode::DefaultBackendMode);
|
2012-05-31 04:47:27 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disposes an old target and prepares to lazily create a new target.
|
|
|
|
*/
|
|
|
|
void ClearTarget();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the target is valid after calling EnsureTarget.
|
|
|
|
*/
|
2014-10-15 06:25:57 +04:00
|
|
|
bool IsTargetValid() const {
|
|
|
|
return mTarget != sErrorTarget && mTarget != nullptr;
|
|
|
|
}
|
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;
|
|
|
|
|
2014-09-24 01:47:18 +04:00
|
|
|
/**
|
|
|
|
* Update CurrentState().filter with the filter description for
|
|
|
|
* CurrentState().filterChain.
|
|
|
|
*/
|
|
|
|
void UpdateFilter();
|
|
|
|
|
2014-10-29 18:17:00 +03:00
|
|
|
nsLayoutUtils::SurfaceFromElementResult
|
|
|
|
CachedSurfaceFromElement(Element* aElement);
|
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
void DrawImage(const HTMLImageOrCanvasOrVideoElement &imgElt,
|
|
|
|
double sx, double sy, double sw, double sh,
|
2014-07-12 00:45:22 +04:00
|
|
|
double dx, double dy, double dw, double dh,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t optional_argc, mozilla::ErrorResult& error);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2014-01-13 04:29:48 +04:00
|
|
|
void DrawDirectlyToCanvas(const nsLayoutUtils::DirectDrawInfo& image,
|
2014-08-23 00:12:38 +04:00
|
|
|
mozilla::gfx::Rect* bounds,
|
|
|
|
mozilla::gfx::Rect dest,
|
|
|
|
mozilla::gfx::Rect src,
|
|
|
|
gfxIntSize imgSize);
|
2014-01-13 04:29:48 +04:00
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
nsString& GetFont()
|
|
|
|
{
|
|
|
|
/* will initilize the value if not set, else does nothing */
|
|
|
|
GetCurrentFontStyle();
|
|
|
|
|
|
|
|
return CurrentState().font;
|
|
|
|
}
|
|
|
|
|
2013-06-29 06:58:40 +04:00
|
|
|
static std::vector<CanvasRenderingContext2D*>& DemotableContexts();
|
|
|
|
static void DemoteOldestContextIfNecessary();
|
2013-08-23 17:52:32 +04:00
|
|
|
|
2013-06-29 06:58:40 +04:00
|
|
|
static void AddDemotableContext(CanvasRenderingContext2D* context);
|
2013-08-23 17:52:32 +04:00
|
|
|
static void RemoveDemotableContext(CanvasRenderingContext2D* context);
|
2013-06-29 06:58:40 +04:00
|
|
|
|
2014-09-03 03:26:36 +04:00
|
|
|
RenderingMode mRenderingMode;
|
2013-06-29 06:58:40 +04:00
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
// 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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2012-10-12 13:42:52 +04:00
|
|
|
nsTArray<CanvasRenderingContext2DUserData*> mUserDatas;
|
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.
|
2012-06-13 19:14:15 +04:00
|
|
|
mozilla::RefPtr<mozilla::gfx::DrawTarget> mTarget;
|
|
|
|
|
2014-10-15 06:25:57 +04:00
|
|
|
uint32_t SkiaGLTex() const;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// This is stored after GetThebesSurface has been called once to avoid
|
|
|
|
// excessive ThebesSurface initialization overhead.
|
|
|
|
nsRefPtr<gfxASurface> mThebesSurface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
mozilla::RefPtr<mozilla::gfx::Path> mPath;
|
|
|
|
mozilla::RefPtr<mozilla::gfx::PathBuilder> mDSPathBuilder;
|
|
|
|
mozilla::RefPtr<mozilla::gfx::PathBuilder> mPathBuilder;
|
|
|
|
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
|
2014-02-21 17:35:36 +04:00
|
|
|
{
|
2014-05-19 03:43:00 +04:00
|
|
|
nsString mId;
|
|
|
|
// fallback element for a11y
|
2014-02-21 17:35:36 +04:00
|
|
|
nsRefPtr<Element> mElement;
|
2014-05-19 03:43:00 +04:00
|
|
|
// Path of the hit region in the 2d context coordinate space (not user space)
|
|
|
|
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
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
bool NeedToApplyFilter()
|
|
|
|
{
|
|
|
|
const ContextState& state = CurrentState();
|
|
|
|
return state.filter.mPrimitives.Length() > 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2014-04-26 06:34:07 +04:00
|
|
|
public: // These enums are public only to accomodate non-C++11 legacy path of
|
|
|
|
// MOZ_FINISH_NESTED_ENUM_CLASS. Can move back to protected as soon
|
|
|
|
// as that legacy path is dropped.
|
|
|
|
MOZ_BEGIN_NESTED_ENUM_CLASS(TextAlign, uint8_t)
|
|
|
|
START,
|
|
|
|
END,
|
|
|
|
LEFT,
|
|
|
|
RIGHT,
|
|
|
|
CENTER
|
|
|
|
MOZ_END_NESTED_ENUM_CLASS(TextAlign)
|
|
|
|
|
|
|
|
MOZ_BEGIN_NESTED_ENUM_CLASS(TextBaseline, uint8_t)
|
|
|
|
TOP,
|
|
|
|
HANGING,
|
|
|
|
MIDDLE,
|
|
|
|
ALPHABETIC,
|
|
|
|
IDEOGRAPHIC,
|
|
|
|
BOTTOM
|
|
|
|
MOZ_END_NESTED_ENUM_CLASS(TextBaseline)
|
|
|
|
|
|
|
|
MOZ_BEGIN_NESTED_ENUM_CLASS(TextDrawOperation, uint8_t)
|
|
|
|
FILL,
|
|
|
|
STROKE,
|
|
|
|
MEASURE
|
|
|
|
MOZ_END_NESTED_ENUM_CLASS(TextDrawOperation)
|
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();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of the fillText, strokeText, and measure functions with
|
|
|
|
* the operation abstracted to a flag.
|
|
|
|
*/
|
|
|
|
nsresult DrawOrMeasureText(const nsAString& text,
|
2012-10-12 13:42:53 +04:00
|
|
|
float x,
|
|
|
|
float y,
|
2013-07-26 22:25:54 +04:00
|
|
|
const Optional<double>& maxWidth,
|
2012-10-12 13:42:53 +04:00
|
|
|
TextDrawOperation op,
|
|
|
|
float* aWidth);
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2014-04-30 06:19:48 +04:00
|
|
|
bool CheckSizeForSkiaGL(mozilla::gfx::IntSize size);
|
|
|
|
|
2012-06-13 19:14:15 +04:00
|
|
|
// state stack handling
|
|
|
|
class ContextState {
|
|
|
|
public:
|
2014-04-26 06:34:07 +04:00
|
|
|
ContextState() : textAlign(TextAlign::START),
|
|
|
|
textBaseline(TextBaseline::ALPHABETIC),
|
2012-10-12 13:42:53 +04:00
|
|
|
lineWidth(1.0f),
|
|
|
|
miterLimit(10.0f),
|
|
|
|
globalAlpha(1.0f),
|
|
|
|
shadowBlur(0.0),
|
|
|
|
dashOffset(0.0f),
|
2014-01-10 23:06:17 +04:00
|
|
|
op(mozilla::gfx::CompositionOp::OP_OVER),
|
|
|
|
fillRule(mozilla::gfx::FillRule::FILL_WINDING),
|
|
|
|
lineCap(mozilla::gfx::CapStyle::BUTT),
|
|
|
|
lineJoin(mozilla::gfx::JoinStyle::MITER_OR_BEVEL),
|
2012-10-12 13:42:53 +04:00
|
|
|
imageSmoothingEnabled(true)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
ContextState(const ContextState& other)
|
|
|
|
: fontGroup(other.fontGroup),
|
2014-09-24 01:47:19 +04:00
|
|
|
fontLanguage(other.fontLanguage),
|
|
|
|
fontFont(other.fontFont),
|
2014-04-26 06:34:07 +04:00
|
|
|
gradientStyles(other.gradientStyles),
|
|
|
|
patternStyles(other.patternStyles),
|
|
|
|
colorStyles(other.colorStyles),
|
2012-10-12 13:42:53 +04:00
|
|
|
font(other.font),
|
|
|
|
textAlign(other.textAlign),
|
|
|
|
textBaseline(other.textBaseline),
|
|
|
|
shadowColor(other.shadowColor),
|
|
|
|
transform(other.transform),
|
|
|
|
shadowOffset(other.shadowOffset),
|
|
|
|
lineWidth(other.lineWidth),
|
|
|
|
miterLimit(other.miterLimit),
|
|
|
|
globalAlpha(other.globalAlpha),
|
|
|
|
shadowBlur(other.shadowBlur),
|
|
|
|
dash(other.dash),
|
|
|
|
dashOffset(other.dashOffset),
|
|
|
|
op(other.op),
|
|
|
|
fillRule(other.fillRule),
|
|
|
|
lineCap(other.lineCap),
|
|
|
|
lineJoin(other.lineJoin),
|
2014-09-24 01:44:53 +04:00
|
|
|
filterString(other.filterString),
|
2014-09-24 01:46:11 +04:00
|
|
|
filterChain(other.filterChain),
|
2014-09-24 01:47:19 +04:00
|
|
|
filterChainObserver(other.filterChainObserver),
|
2014-09-24 01:47:18 +04:00
|
|
|
filter(other.filter),
|
|
|
|
filterAdditionalImages(other.filterAdditionalImages),
|
2012-10-12 13:42:53 +04:00
|
|
|
imageSmoothingEnabled(other.imageSmoothingEnabled)
|
2014-04-26 06:34:07 +04:00
|
|
|
{ }
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2012-10-12 13:42:53 +04:00
|
|
|
void SetColorStyle(Style whichStyle, nscolor color)
|
|
|
|
{
|
|
|
|
colorStyles[whichStyle] = color;
|
|
|
|
gradientStyles[whichStyle] = nullptr;
|
|
|
|
patternStyles[whichStyle] = nullptr;
|
|
|
|
}
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2012-10-12 13:42:53 +04:00
|
|
|
void SetPatternStyle(Style whichStyle, CanvasPattern* pat)
|
|
|
|
{
|
|
|
|
gradientStyles[whichStyle] = nullptr;
|
|
|
|
patternStyles[whichStyle] = pat;
|
|
|
|
}
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2012-10-12 13:42:53 +04:00
|
|
|
void SetGradientStyle(Style whichStyle, CanvasGradient* grad)
|
|
|
|
{
|
|
|
|
gradientStyles[whichStyle] = grad;
|
|
|
|
patternStyles[whichStyle] = nullptr;
|
|
|
|
}
|
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.
|
|
|
|
*/
|
|
|
|
bool StyleIsColor(Style whichStyle) const
|
|
|
|
{
|
|
|
|
return !(patternStyles[whichStyle] || gradientStyles[whichStyle]);
|
|
|
|
}
|
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
|
|
|
|
2012-10-12 13:42:53 +04:00
|
|
|
std::vector<mozilla::RefPtr<mozilla::gfx::Path> > clipsPushed;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2012-10-12 13:42:53 +04:00
|
|
|
nsRefPtr<gfxFontGroup> fontGroup;
|
2014-09-24 01:47:19 +04:00
|
|
|
nsCOMPtr<nsIAtom> fontLanguage;
|
|
|
|
nsFont fontFont;
|
|
|
|
|
2014-04-26 06:34:07 +04:00
|
|
|
EnumeratedArray<Style, Style::MAX, nsRefPtr<CanvasGradient>> gradientStyles;
|
|
|
|
EnumeratedArray<Style, Style::MAX, nsRefPtr<CanvasPattern>> patternStyles;
|
|
|
|
EnumeratedArray<Style, Style::MAX, nscolor> colorStyles;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2012-10-12 13:42:53 +04:00
|
|
|
nsString font;
|
|
|
|
TextAlign textAlign;
|
|
|
|
TextBaseline textBaseline;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2012-10-12 13:42:53 +04:00
|
|
|
nscolor shadowColor;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2012-10-12 13:42:53 +04:00
|
|
|
mozilla::gfx::Matrix transform;
|
|
|
|
mozilla::gfx::Point shadowOffset;
|
|
|
|
mozilla::gfx::Float lineWidth;
|
|
|
|
mozilla::gfx::Float miterLimit;
|
|
|
|
mozilla::gfx::Float globalAlpha;
|
|
|
|
mozilla::gfx::Float shadowBlur;
|
|
|
|
FallibleTArray<mozilla::gfx::Float> dash;
|
|
|
|
mozilla::gfx::Float dashOffset;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2012-10-12 13:42:53 +04:00
|
|
|
mozilla::gfx::CompositionOp op;
|
|
|
|
mozilla::gfx::FillRule fillRule;
|
|
|
|
mozilla::gfx::CapStyle lineCap;
|
|
|
|
mozilla::gfx::JoinStyle lineJoin;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
2014-09-24 01:44:53 +04:00
|
|
|
nsString filterString;
|
2014-09-24 01:46:11 +04:00
|
|
|
nsTArray<nsStyleFilter> filterChain;
|
2014-09-24 01:47:19 +04:00
|
|
|
nsRefPtr<nsSVGFilterChainObserver> filterChainObserver;
|
2014-09-24 01:47:18 +04:00
|
|
|
mozilla::gfx::FilterDescription filter;
|
|
|
|
nsTArray<mozilla::RefPtr<mozilla::gfx::SourceSurface>> filterAdditionalImages;
|
|
|
|
|
2012-10-12 13:42:53 +04:00
|
|
|
bool imageSmoothingEnabled;
|
2012-06-13 19:14:15 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
nsAutoTArray<ContextState, 3> mStyleStack;
|
|
|
|
|
|
|
|
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;
|
2014-09-24 01:47:19 +04:00
|
|
|
friend class CanvasFilterChainObserver;
|
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
|
2013-02-20 01:46:27 +04:00
|
|
|
void GetAppUnitsValues(int32_t *perDevPixel, int32_t *perCSSPixel)
|
2012-10-12 13:42:53 +04:00
|
|
|
{
|
2012-06-13 19:14:15 +04:00
|
|
|
// If we don't have a canvas element, we just return something generic.
|
2013-02-20 01:46:27 +04:00
|
|
|
int32_t devPixel = 60;
|
|
|
|
int32_t cssPixel = 60;
|
2012-06-13 19:14:15 +04:00
|
|
|
|
|
|
|
nsIPresShell *ps = GetPresShell();
|
|
|
|
nsPresContext *pc;
|
|
|
|
|
|
|
|
if (!ps) goto FINISH;
|
|
|
|
pc = ps->GetPresContext();
|
|
|
|
if (!pc) goto FINISH;
|
|
|
|
devPixel = pc->AppUnitsPerDevPixel();
|
|
|
|
cssPixel = pc->AppUnitsPerCSSPixel();
|
|
|
|
|
|
|
|
FINISH:
|
|
|
|
if (perDevPixel)
|
|
|
|
*perDevPixel = devPixel;
|
|
|
|
if (perCSSPixel)
|
|
|
|
*perCSSPixel = cssPixel;
|
|
|
|
}
|
|
|
|
|
2012-10-12 13:42:52 +04:00
|
|
|
friend struct CanvasBidiProcessor;
|
2012-06-13 19:14:15 +04:00
|
|
|
};
|
|
|
|
|
2014-04-26 06:34:07 +04:00
|
|
|
MOZ_FINISH_NESTED_ENUM_CLASS(CanvasRenderingContext2D::CanvasMultiGetterType)
|
|
|
|
MOZ_FINISH_NESTED_ENUM_CLASS(CanvasRenderingContext2D::Style)
|
|
|
|
MOZ_FINISH_NESTED_ENUM_CLASS(CanvasRenderingContext2D::TextAlign)
|
|
|
|
MOZ_FINISH_NESTED_ENUM_CLASS(CanvasRenderingContext2D::TextBaseline)
|
|
|
|
MOZ_FINISH_NESTED_ENUM_CLASS(CanvasRenderingContext2D::TextDrawOperation)
|
|
|
|
|
2012-10-12 13:42:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CanvasRenderingContext2D_h */
|