Bug 1318573 - (Part 3) Move CanvasCompositing to BasicRenderingContext2D. r?mstange
MozReview-Commit-ID: 9eE68HybgTS
--- a/dom/canvas/BasicRenderingContext2D.cpp
+++ b/dom/canvas/BasicRenderingContext2D.cpp
@@ -155,16 +155,106 @@ BasicRenderingContext2D::SetTransformInt
void
BasicRenderingContext2D::ResetTransform(ErrorResult& aError)
{
SetTransform(1.0, 0.0, 0.0, 1.0, 0.0, 0.0, aError);
}
//
+// compositing
+//
+
+void
+BasicRenderingContext2D::SetGlobalCompositeOperation(const nsAString& aOp,
+ ErrorResult& aError)
+{
+ CompositionOp comp_op;
+
+#define CANVAS_OP_TO_GFX_OP(cvsop, op2d) \
+ if (aOp.EqualsLiteral(cvsop)) \
+ comp_op = CompositionOp::OP_##op2d;
+
+ CANVAS_OP_TO_GFX_OP("copy", SOURCE)
+ else CANVAS_OP_TO_GFX_OP("source-atop", ATOP)
+ else CANVAS_OP_TO_GFX_OP("source-in", IN)
+ else CANVAS_OP_TO_GFX_OP("source-out", OUT)
+ else CANVAS_OP_TO_GFX_OP("source-over", OVER)
+ else CANVAS_OP_TO_GFX_OP("destination-in", DEST_IN)
+ else CANVAS_OP_TO_GFX_OP("destination-out", DEST_OUT)
+ else CANVAS_OP_TO_GFX_OP("destination-over", DEST_OVER)
+ else CANVAS_OP_TO_GFX_OP("destination-atop", DEST_ATOP)
+ else CANVAS_OP_TO_GFX_OP("lighter", ADD)
+ else CANVAS_OP_TO_GFX_OP("xor", XOR)
+ else CANVAS_OP_TO_GFX_OP("multiply", MULTIPLY)
+ else CANVAS_OP_TO_GFX_OP("screen", SCREEN)
+ else CANVAS_OP_TO_GFX_OP("overlay", OVERLAY)
+ else CANVAS_OP_TO_GFX_OP("darken", DARKEN)
+ else CANVAS_OP_TO_GFX_OP("lighten", LIGHTEN)
+ else CANVAS_OP_TO_GFX_OP("color-dodge", COLOR_DODGE)
+ else CANVAS_OP_TO_GFX_OP("color-burn", COLOR_BURN)
+ else CANVAS_OP_TO_GFX_OP("hard-light", HARD_LIGHT)
+ else CANVAS_OP_TO_GFX_OP("soft-light", SOFT_LIGHT)
+ else CANVAS_OP_TO_GFX_OP("difference", DIFFERENCE)
+ else CANVAS_OP_TO_GFX_OP("exclusion", EXCLUSION)
+ else CANVAS_OP_TO_GFX_OP("hue", HUE)
+ else CANVAS_OP_TO_GFX_OP("saturation", SATURATION)
+ else CANVAS_OP_TO_GFX_OP("color", COLOR)
+ else CANVAS_OP_TO_GFX_OP("luminosity", LUMINOSITY)
+ // XXX ERRMSG we need to report an error to developers here! (bug 329026)
+ else return;
+
+#undef CANVAS_OP_TO_GFX_OP
+ CurrentState().op = comp_op;
+}
+
+void
+BasicRenderingContext2D::GetGlobalCompositeOperation(nsAString& aOp,
+ ErrorResult& aError)
+{
+ CompositionOp comp_op = CurrentState().op;
+
+#define CANVAS_OP_TO_GFX_OP(cvsop, op2d) \
+ if (comp_op == CompositionOp::OP_##op2d) \
+ aOp.AssignLiteral(cvsop);
+
+ CANVAS_OP_TO_GFX_OP("copy", SOURCE)
+ else CANVAS_OP_TO_GFX_OP("destination-atop", DEST_ATOP)
+ else CANVAS_OP_TO_GFX_OP("destination-in", DEST_IN)
+ else CANVAS_OP_TO_GFX_OP("destination-out", DEST_OUT)
+ else CANVAS_OP_TO_GFX_OP("destination-over", DEST_OVER)
+ else CANVAS_OP_TO_GFX_OP("lighter", ADD)
+ else CANVAS_OP_TO_GFX_OP("source-atop", ATOP)
+ else CANVAS_OP_TO_GFX_OP("source-in", IN)
+ else CANVAS_OP_TO_GFX_OP("source-out", OUT)
+ else CANVAS_OP_TO_GFX_OP("source-over", OVER)
+ else CANVAS_OP_TO_GFX_OP("xor", XOR)
+ else CANVAS_OP_TO_GFX_OP("multiply", MULTIPLY)
+ else CANVAS_OP_TO_GFX_OP("screen", SCREEN)
+ else CANVAS_OP_TO_GFX_OP("overlay", OVERLAY)
+ else CANVAS_OP_TO_GFX_OP("darken", DARKEN)
+ else CANVAS_OP_TO_GFX_OP("lighten", LIGHTEN)
+ else CANVAS_OP_TO_GFX_OP("color-dodge", COLOR_DODGE)
+ else CANVAS_OP_TO_GFX_OP("color-burn", COLOR_BURN)
+ else CANVAS_OP_TO_GFX_OP("hard-light", HARD_LIGHT)
+ else CANVAS_OP_TO_GFX_OP("soft-light", SOFT_LIGHT)
+ else CANVAS_OP_TO_GFX_OP("difference", DIFFERENCE)
+ else CANVAS_OP_TO_GFX_OP("exclusion", EXCLUSION)
+ else CANVAS_OP_TO_GFX_OP("hue", HUE)
+ else CANVAS_OP_TO_GFX_OP("saturation", SATURATION)
+ else CANVAS_OP_TO_GFX_OP("color", COLOR)
+ else CANVAS_OP_TO_GFX_OP("luminosity", LUMINOSITY)
+ else {
+ aError.Throw(NS_ERROR_FAILURE);
+ }
+
+#undef CANVAS_OP_TO_GFX_OP
+}
+
+//
// path bits
//
void
BasicRenderingContext2D::TransformWillUpdate()
{
EnsureTarget();
// Store the matrix that would transform the current path to device
--- a/dom/canvas/BasicRenderingContext2D.h
+++ b/dom/canvas/BasicRenderingContext2D.h
@@ -2,20 +2,21 @@
* 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/. */
#ifndef BasicRenderingContext2D_h
#define BasicRenderingContext2D_h
#include "FilterSupport.h"
#include "mozilla/dom/CanvasRenderingContext2DBinding.h"
-#include "mozilla/gfx/Matrix.h"
+#include "mozilla/gfx/2D.h"
#include "nsStyleStruct.h"
#include "nsSVGEffects.h"
+using mozilla::gfx::CompositionOp;
using mozilla::gfx::FilterDescription;
using mozilla::gfx::Matrix;
namespace mozilla {
namespace dom {
class HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap;
typedef HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap
@@ -59,22 +60,34 @@ public:
double aDx, double aDy, mozilla::ErrorResult& aError);
void SetTransform(double aM11, double aM12, double aM21, double aM22,
double aDx, double aDy, mozilla::ErrorResult& aError);
void ResetTransform(mozilla::ErrorResult& aError);
//
// CanvasCompositing
//
- virtual double GlobalAlpha() = 0;
- virtual void SetGlobalAlpha(double aGlobalAlpha) = 0;
- virtual void GetGlobalCompositeOperation(nsAString& aOp,
- mozilla::ErrorResult& aError) = 0;
- virtual void SetGlobalCompositeOperation(const nsAString& aOp,
- mozilla::ErrorResult& aError) = 0;
+ double GlobalAlpha()
+ {
+ return CurrentState().globalAlpha;
+ }
+
+ // Useful for silencing cast warnings
+ static mozilla::gfx::Float ToFloat(double aValue) { return mozilla::gfx::Float(aValue); }
+
+ void SetGlobalAlpha(double aGlobalAlpha)
+ {
+ if (aGlobalAlpha >= 0.0 && aGlobalAlpha <= 1.0) {
+ CurrentState().globalAlpha = ToFloat(aGlobalAlpha);
+ }
+ }
+ void GetGlobalCompositeOperation(nsAString& aOp,
+ mozilla::ErrorResult& aError);
+ void SetGlobalCompositeOperation(const nsAString& aOp,
+ mozilla::ErrorResult& aError);
//
// CanvasImageSmoothing
//
virtual bool ImageSmoothingEnabled() = 0;
virtual void SetImageSmoothingEnabled(bool aImageSmoothingEnabled) = 0;
//
@@ -250,17 +263,17 @@ protected:
ContextState() : textAlign(TextAlign::START),
textBaseline(TextBaseline::ALPHABETIC),
shadowColor(0),
lineWidth(1.0f),
miterLimit(10.0f),
globalAlpha(1.0f),
shadowBlur(0.0),
dashOffset(0.0f),
- op(mozilla::gfx::CompositionOp::OP_OVER),
+ op(CompositionOp::OP_OVER),
fillRule(mozilla::gfx::FillRule::FILL_WINDING),
lineCap(mozilla::gfx::CapStyle::BUTT),
lineJoin(mozilla::gfx::JoinStyle::MITER_OR_BEVEL),
filterString(u"none"),
filterSourceGraphicTainted(false),
imageSmoothingEnabled(true),
fontExplicitLanguage(false)
{ }
@@ -356,17 +369,17 @@ protected:
mozilla::gfx::Point shadowOffset;
mozilla::gfx::Float lineWidth;
mozilla::gfx::Float miterLimit;
mozilla::gfx::Float globalAlpha;
mozilla::gfx::Float shadowBlur;
nsTArray<mozilla::gfx::Float> dash;
mozilla::gfx::Float dashOffset;
- mozilla::gfx::CompositionOp op;
+ CompositionOp op;
mozilla::gfx::FillRule fillRule;
mozilla::gfx::CapStyle lineCap;
mozilla::gfx::JoinStyle lineJoin;
nsString filterString;
nsTArray<nsStyleFilter> filterChain;
RefPtr<nsSVGFilterChainObserver> filterChainObserver;
mozilla::gfx::FilterDescription filter;
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -4949,102 +4949,16 @@ CanvasRenderingContext2D::DrawDirectlyTo
aImage.mWhichFrame, SamplingFilter::GOOD, Some(svgContext), modifiedFlags, 1.0);
if (result != DrawResult::SUCCESS) {
NS_WARNING("imgIContainer::Draw failed");
}
}
void
-CanvasRenderingContext2D::SetGlobalCompositeOperation(const nsAString& aOp,
- ErrorResult& aError)
-{
- CompositionOp comp_op;
-
-#define CANVAS_OP_TO_GFX_OP(cvsop, op2d) \
- if (aOp.EqualsLiteral(cvsop)) \
- comp_op = CompositionOp::OP_##op2d;
-
- CANVAS_OP_TO_GFX_OP("copy", SOURCE)
- else CANVAS_OP_TO_GFX_OP("source-atop", ATOP)
- else CANVAS_OP_TO_GFX_OP("source-in", IN)
- else CANVAS_OP_TO_GFX_OP("source-out", OUT)
- else CANVAS_OP_TO_GFX_OP("source-over", OVER)
- else CANVAS_OP_TO_GFX_OP("destination-in", DEST_IN)
- else CANVAS_OP_TO_GFX_OP("destination-out", DEST_OUT)
- else CANVAS_OP_TO_GFX_OP("destination-over", DEST_OVER)
- else CANVAS_OP_TO_GFX_OP("destination-atop", DEST_ATOP)
- else CANVAS_OP_TO_GFX_OP("lighter", ADD)
- else CANVAS_OP_TO_GFX_OP("xor", XOR)
- else CANVAS_OP_TO_GFX_OP("multiply", MULTIPLY)
- else CANVAS_OP_TO_GFX_OP("screen", SCREEN)
- else CANVAS_OP_TO_GFX_OP("overlay", OVERLAY)
- else CANVAS_OP_TO_GFX_OP("darken", DARKEN)
- else CANVAS_OP_TO_GFX_OP("lighten", LIGHTEN)
- else CANVAS_OP_TO_GFX_OP("color-dodge", COLOR_DODGE)
- else CANVAS_OP_TO_GFX_OP("color-burn", COLOR_BURN)
- else CANVAS_OP_TO_GFX_OP("hard-light", HARD_LIGHT)
- else CANVAS_OP_TO_GFX_OP("soft-light", SOFT_LIGHT)
- else CANVAS_OP_TO_GFX_OP("difference", DIFFERENCE)
- else CANVAS_OP_TO_GFX_OP("exclusion", EXCLUSION)
- else CANVAS_OP_TO_GFX_OP("hue", HUE)
- else CANVAS_OP_TO_GFX_OP("saturation", SATURATION)
- else CANVAS_OP_TO_GFX_OP("color", COLOR)
- else CANVAS_OP_TO_GFX_OP("luminosity", LUMINOSITY)
- // XXX ERRMSG we need to report an error to developers here! (bug 329026)
- else return;
-
-#undef CANVAS_OP_TO_GFX_OP
- CurrentState().op = comp_op;
-}
-
-void
-CanvasRenderingContext2D::GetGlobalCompositeOperation(nsAString& aOp,
- ErrorResult& aError)
-{
- CompositionOp comp_op = CurrentState().op;
-
-#define CANVAS_OP_TO_GFX_OP(cvsop, op2d) \
- if (comp_op == CompositionOp::OP_##op2d) \
- aOp.AssignLiteral(cvsop);
-
- CANVAS_OP_TO_GFX_OP("copy", SOURCE)
- else CANVAS_OP_TO_GFX_OP("destination-atop", DEST_ATOP)
- else CANVAS_OP_TO_GFX_OP("destination-in", DEST_IN)
- else CANVAS_OP_TO_GFX_OP("destination-out", DEST_OUT)
- else CANVAS_OP_TO_GFX_OP("destination-over", DEST_OVER)
- else CANVAS_OP_TO_GFX_OP("lighter", ADD)
- else CANVAS_OP_TO_GFX_OP("source-atop", ATOP)
- else CANVAS_OP_TO_GFX_OP("source-in", IN)
- else CANVAS_OP_TO_GFX_OP("source-out", OUT)
- else CANVAS_OP_TO_GFX_OP("source-over", OVER)
- else CANVAS_OP_TO_GFX_OP("xor", XOR)
- else CANVAS_OP_TO_GFX_OP("multiply", MULTIPLY)
- else CANVAS_OP_TO_GFX_OP("screen", SCREEN)
- else CANVAS_OP_TO_GFX_OP("overlay", OVERLAY)
- else CANVAS_OP_TO_GFX_OP("darken", DARKEN)
- else CANVAS_OP_TO_GFX_OP("lighten", LIGHTEN)
- else CANVAS_OP_TO_GFX_OP("color-dodge", COLOR_DODGE)
- else CANVAS_OP_TO_GFX_OP("color-burn", COLOR_BURN)
- else CANVAS_OP_TO_GFX_OP("hard-light", HARD_LIGHT)
- else CANVAS_OP_TO_GFX_OP("soft-light", SOFT_LIGHT)
- else CANVAS_OP_TO_GFX_OP("difference", DIFFERENCE)
- else CANVAS_OP_TO_GFX_OP("exclusion", EXCLUSION)
- else CANVAS_OP_TO_GFX_OP("hue", HUE)
- else CANVAS_OP_TO_GFX_OP("saturation", SATURATION)
- else CANVAS_OP_TO_GFX_OP("color", COLOR)
- else CANVAS_OP_TO_GFX_OP("luminosity", LUMINOSITY)
- else {
- aError.Throw(NS_ERROR_FAILURE);
- }
-
-#undef CANVAS_OP_TO_GFX_OP
-}
-
-void
CanvasRenderingContext2D::DrawWindow(nsGlobalWindow& aWindow, double aX,
double aY, double aW, double aH,
const nsAString& aBgColor,
uint32_t aFlags, ErrorResult& aError)
{
MOZ_ASSERT(aWindow.IsInnerWindow());
if (int32_t(aW) == 0 || int32_t(aH) == 0) {
--- a/dom/canvas/CanvasRenderingContext2D.h
+++ b/dom/canvas/CanvasRenderingContext2D.h
@@ -15,17 +15,16 @@
#include "mozilla/dom/HTMLVideoElement.h"
#include "gfxTextRun.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BasicRenderingContext2D.h"
#include "mozilla/dom/CanvasGradient.h"
#include "mozilla/dom/CanvasRenderingContext2DBinding.h"
#include "mozilla/dom/CanvasPattern.h"
#include "mozilla/gfx/Rect.h"
-#include "mozilla/gfx/2D.h"
#include "mozilla/UniquePtr.h"
#include "gfx2DGlue.h"
#include "imgIEncoder.h"
#include "nsLayoutUtils.h"
#include "mozilla/EnumeratedArray.h"
#include "Layers.h"
class nsGlobalWindow;
@@ -71,36 +70,16 @@ public:
if (!mCanvasElement || mCanvasElement->IsInNativeAnonymousSubtree()) {
return nullptr;
}
// corresponds to changes to the old bindings made in bug 745025
return mCanvasElement->GetOriginalCanvas();
}
- double GlobalAlpha() override
- {
- return CurrentState().globalAlpha;
- }
-
- // Useful for silencing cast warnings
- static mozilla::gfx::Float ToFloat(double aValue) { return mozilla::gfx::Float(aValue); }
-
- void SetGlobalAlpha(double aGlobalAlpha) override
- {
- if (aGlobalAlpha >= 0.0 && aGlobalAlpha <= 1.0) {
- CurrentState().globalAlpha = ToFloat(aGlobalAlpha);
- }
- }
-
- void GetGlobalCompositeOperation(nsAString& aOp,
- mozilla::ErrorResult& aError) override;
- void SetGlobalCompositeOperation(const nsAString& aOp,
- mozilla::ErrorResult& aError) override;
-
void
GetStrokeStyle(OwningStringOrCanvasGradientOrCanvasPattern& aValue) override
{
GetStyleAsUnion(aValue, Style::STROKE);
}
void
SetStrokeStyle(const StringOrCanvasGradientOrCanvasPattern& aValue) override