mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-01 22:07:41 +00:00
Bug 1019257: Canvas pattern setTransform exposed through WebIDL. r=gw280,bz.
--HG-- extra : rebase_source : a12b913bf1cfeb11313aa1525d1ebcae075e1456
This commit is contained in:
parent
d4bc71c172
commit
46fee89d00
@ -20,6 +20,7 @@ class SourceSurface;
|
||||
}
|
||||
|
||||
namespace dom {
|
||||
class SVGMatrix;
|
||||
|
||||
class CanvasPattern MOZ_FINAL : public nsWrapperCache
|
||||
{
|
||||
@ -43,6 +44,7 @@ public:
|
||||
: mContext(aContext)
|
||||
, mSurface(aSurface)
|
||||
, mPrincipal(principalForSecurityCheck)
|
||||
, mTransform()
|
||||
, mForceWriteOnly(forceWriteOnly)
|
||||
, mCORSUsed(CORSUsed)
|
||||
, mRepeat(aRepeat)
|
||||
@ -60,9 +62,13 @@ public:
|
||||
return mContext;
|
||||
}
|
||||
|
||||
// WebIDL
|
||||
void SetTransform(SVGMatrix& matrix);
|
||||
|
||||
nsRefPtr<CanvasRenderingContext2D> mContext;
|
||||
RefPtr<gfx::SourceSurface> mSurface;
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
mozilla::gfx::Matrix mTransform;
|
||||
const bool mForceWriteOnly;
|
||||
const bool mCORSUsed;
|
||||
const RepeatMode mRepeat;
|
||||
|
@ -93,6 +93,7 @@
|
||||
#include "mozilla/dom/HTMLVideoElement.h"
|
||||
#include "mozilla/dom/TextMetrics.h"
|
||||
#include "mozilla/dom/UnionTypes.h"
|
||||
#include "mozilla/dom/SVGMatrix.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
#include "GLContext.h"
|
||||
#include "GLContextProvider.h"
|
||||
@ -262,7 +263,8 @@ public:
|
||||
mode = ExtendMode::REPEAT;
|
||||
}
|
||||
mPattern = new (mSurfacePattern.addr())
|
||||
SurfacePattern(state.patternStyles[aStyle]->mSurface, mode);
|
||||
SurfacePattern(state.patternStyles[aStyle]->mSurface, mode,
|
||||
state.patternStyles[aStyle]->mTransform);
|
||||
}
|
||||
|
||||
return *mPattern;
|
||||
@ -382,6 +384,12 @@ private:
|
||||
mgfx::Rect mTempRect;
|
||||
};
|
||||
|
||||
void
|
||||
CanvasPattern::SetTransform(SVGMatrix& aMatrix)
|
||||
{
|
||||
mTransform = ToMatrix(aMatrix.GetMatrix());
|
||||
}
|
||||
|
||||
void
|
||||
CanvasGradient::AddColorStop(float offset, const nsAString& colorstr, ErrorResult& rv)
|
||||
{
|
||||
|
@ -214,5 +214,6 @@ skip-if = (buildapp == 'b2g' && toolkit != 'gonk')
|
||||
[test_toDataURL_parameters.html]
|
||||
[test_windingRuleUndefined.html]
|
||||
[test_2d.fillText.gradient.html]
|
||||
[test_2d_composite_canvaspattern_setTransform.html]
|
||||
[test_createPattern_broken.html]
|
||||
[test_setlinedash.html]
|
||||
|
@ -0,0 +1,77 @@
|
||||
<!DOCTYPE HTML>
|
||||
<title>Canvas Tests</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
|
||||
<body>
|
||||
<script>
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
const Cc = SpecialPowers.Cc;
|
||||
const Cr = SpecialPowers.Cr;
|
||||
SpecialPowers.setBoolPref("canvas.path.enabled", true);
|
||||
|
||||
function isPixel(ctx, x,y, r,g,b,a, d) {
|
||||
var pos = x + "," + y;
|
||||
var colour = r + "," + g + "," + b + "," + a;
|
||||
var pixel = ctx.getImageData(x, y, 1, 1);
|
||||
var pr = pixel.data[0],
|
||||
pg = pixel.data[1],
|
||||
pb = pixel.data[2],
|
||||
pa = pixel.data[3];
|
||||
ok(r-d <= pr && pr <= r+d &&
|
||||
g-d <= pg && pg <= g+d &&
|
||||
b-d <= pb && pb <= b+d &&
|
||||
a-d <= pa && pa <= a+d,
|
||||
"pixel "+pos+" of "+ctx.canvas.id+" is "+pr+","+pg+","+pb+","+pa+"; expected "+colour+" +/- "+d);
|
||||
}
|
||||
</script>
|
||||
|
||||
<p>Canvas test: 2d.composite.canvaspattern.setTransform</p>
|
||||
<canvas id="ctx" width="100" height="50"><p class="fallback">FAIL
|
||||
(fallback content)</p></canvas>
|
||||
<svg id="svg1"></svg>
|
||||
<img src="image_rgrg-256x256.png" id="rgrg-256x256.png" width="32"
|
||||
height="32" class="resource">
|
||||
|
||||
<script>
|
||||
|
||||
function test_2d_canvaspattern_setTransform() {
|
||||
|
||||
var canvas = document.getElementById('ctx');
|
||||
var ctx = canvas.getContext('2d');
|
||||
ctx.clearRect(0,0,canvas.width,canvas.height);
|
||||
var img = document.getElementById("rgrg-256x256.png");
|
||||
var pat = ctx.createPattern(img,"repeat");
|
||||
|
||||
var svg = document.getElementById("svg1");
|
||||
var mtx = svg1.createSVGMatrix();
|
||||
pat.setTransform(mtx.rotate(-45).scale(0.1));
|
||||
ctx.fillStyle = pat;
|
||||
ctx.fillRect(0, 0, 100, 50);
|
||||
|
||||
// If the pattern doesn't get transformed, or only gets rotated or
|
||||
// scaled, but not both, this will not be green and will fail.
|
||||
isPixel(ctx, 90,14, 0,255,0,255, 0);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
|
||||
function runTests() {
|
||||
try {
|
||||
test_2d_canvaspattern_setTransform();
|
||||
} catch(e) {
|
||||
throw e;
|
||||
ok(false, "unexpected exception thrown in: test_2d_canvaspattern_setTransform");
|
||||
}
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
addLoadEvent(runTests);
|
||||
|
||||
// Don't leak the world via the Path2D reference to its window.
|
||||
document.all;
|
||||
window.p = new Path2D();
|
||||
|
||||
</script>
|
||||
|
@ -286,7 +286,11 @@ interface CanvasGradient {
|
||||
|
||||
interface CanvasPattern {
|
||||
// opaque object
|
||||
// void setTransform(SVGMatrix transform);
|
||||
// [Throws, LenientFloat] - could not do this overload because of bug 1020975
|
||||
// void setTransform(double a, double b, double c, double d, double e, double f);
|
||||
|
||||
// No throw necessary here - SVGMatrix is always good.
|
||||
void setTransform(SVGMatrix matrix);
|
||||
};
|
||||
|
||||
interface TextMetrics {
|
||||
|
Loading…
x
Reference in New Issue
Block a user