Commit 9347a409 authored by Fernando Serboncini's avatar Fernando Serboncini Committed by Commit Bot

Adds getTransform/setTransform using DOMMatrix

Bug: 742360
Change-Id: I49c21ea926e8c228986dc041108ca7b9449966c5
Reviewed-on: https://chromium-review.googlesource.com/676088Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Reviewed-by: default avatarJustin Novosad <junov@chromium.org>
Commit-Queue: Fernando Serboncini <fserb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558783}
parent 2953d9b0
......@@ -386,6 +386,7 @@ interface CanvasRenderingContext2D
method getContextAttributes
method getImageData
method getLineDash
method getTransform
method isPointInPath
method isPointInStroke
method lineTo
......
This is a testharness.js-based test.
FAIL void methods return undefined Failed to execute 'setTransform' on 'CanvasRenderingContext2D': 6 arguments required, but only 0 present.
Harness: the test ran to completion.
This is a testharness.js-based test.
FAIL Canvas test: 2d.transformation.setTransform.multiple Failed to execute 'setTransform' on 'CanvasRenderingContext2D': 6 arguments required, but only 0 present.
Harness: the test ran to completion.
......@@ -4929,11 +4929,11 @@ PASS CanvasRenderingContext2D interface: operation translate(unrestricted double
PASS Unscopable handled correctly for translate(unrestricted double, unrestricted double) on CanvasRenderingContext2D
PASS CanvasRenderingContext2D interface: operation transform(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double)
PASS Unscopable handled correctly for transform(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double) on CanvasRenderingContext2D
FAIL CanvasRenderingContext2D interface: operation getTransform() assert_own_property: interface prototype object missing non-static operation expected property "getTransform" missing
PASS CanvasRenderingContext2D interface: operation getTransform()
PASS Unscopable handled correctly for getTransform() on CanvasRenderingContext2D
FAIL CanvasRenderingContext2D interface: operation setTransform(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double) assert_equals: property has wrong .length expected 0 but got 6
PASS CanvasRenderingContext2D interface: operation setTransform(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double)
PASS Unscopable handled correctly for setTransform(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double) on CanvasRenderingContext2D
FAIL CanvasRenderingContext2D interface: operation setTransform(DOMMatrix2DInit) assert_equals: property has wrong .length expected 0 but got 6
PASS CanvasRenderingContext2D interface: operation setTransform(DOMMatrix2DInit)
PASS Unscopable handled correctly for setTransform(DOMMatrix2DInit) on CanvasRenderingContext2D
PASS CanvasRenderingContext2D interface: operation resetTransform()
PASS Unscopable handled correctly for resetTransform() on CanvasRenderingContext2D
......@@ -5078,7 +5078,7 @@ PASS CanvasRenderingContext2D interface: document.createElement("canvas").getCon
PASS CanvasRenderingContext2D interface: calling translate(unrestricted double, unrestricted double) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError
PASS CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "transform(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double)" with the proper type
PASS CanvasRenderingContext2D interface: calling transform(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError
FAIL CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "getTransform()" with the proper type assert_inherits: property "getTransform" not found in prototype chain
PASS CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "getTransform()" with the proper type
PASS CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "setTransform(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double)" with the proper type
PASS CanvasRenderingContext2D interface: calling setTransform(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError
PASS CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "setTransform(DOMMatrix2DInit)" with the proper type
......
......@@ -717,6 +717,7 @@ interface CanvasRenderingContext2D
method fillText
method getImageData
method getLineDash
method getTransform
method isPointInPath
method isPointInStroke
method lineTo
......
......@@ -950,6 +950,7 @@ interface CanvasRenderingContext2D
method getContextAttributes
method getImageData
method getLineDash
method getTransform
method isContextLost
method isPointInPath
method isPointInStroke
......
......@@ -575,10 +575,6 @@ void BaseRenderingContext2D::setTransform(double m11,
double m22,
double dx,
double dy) {
PaintCanvas* c = DrawingCanvas();
if (!c)
return;
if (!std::isfinite(m11) || !std::isfinite(m21) || !std::isfinite(dx) ||
!std::isfinite(m12) || !std::isfinite(m22) || !std::isfinite(dy))
return;
......@@ -595,6 +591,29 @@ void BaseRenderingContext2D::setTransform(double m11,
transform(fm11, fm12, fm21, fm22, fdx, fdy);
}
void BaseRenderingContext2D::setTransform(DOMMatrix2DInit& transform,
ExceptionState& exception_state) {
DOMMatrixReadOnly* m =
DOMMatrixReadOnly::fromMatrix2D(transform, exception_state);
if (!m)
return;
setTransform(m->m11(), m->m12(), m->m21(), m->m22(), m->m41(), m->m42());
}
DOMMatrix* BaseRenderingContext2D::getTransform() {
const AffineTransform& t = GetState().Transform();
DOMMatrix* m = DOMMatrix::Create();
m->setA(t.A());
m->setB(t.B());
m->setC(t.C());
m->setD(t.D());
m->setE(t.E());
m->setF(t.F());
return m;
}
void BaseRenderingContext2D::beginPath() {
path_.Clear();
}
......
......@@ -7,6 +7,8 @@
#include "third_party/blink/renderer/bindings/modules/v8/canvas_image_source.h"
#include "third_party/blink/renderer/bindings/modules/v8/string_or_canvas_gradient_or_canvas_pattern.h"
#include "third_party/blink/renderer/core/geometry/dom_matrix.h"
#include "third_party/blink/renderer/core/geometry/dom_matrix_2d_init.h"
#include "third_party/blink/renderer/core/html/canvas/image_data.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_gradient.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_path.h"
......@@ -105,6 +107,8 @@ class MODULES_EXPORT BaseRenderingContext2D : public GarbageCollectedMixin,
double m22,
double dx,
double dy);
void setTransform(DOMMatrix2DInit&, ExceptionState&);
DOMMatrix* getTransform();
void resetTransform();
void beginPath();
......
......@@ -60,6 +60,8 @@ interface CanvasRenderingContext2D {
void translate(unrestricted double x, unrestricted double y);
void transform(unrestricted double a, unrestricted double b, unrestricted double c, unrestricted double d, unrestricted double e, unrestricted double f);
void setTransform(unrestricted double a, unrestricted double b, unrestricted double c, unrestricted double d, unrestricted double e, unrestricted double f);
[RaisesException] void setTransform(optional DOMMatrix2DInit transform);
DOMMatrix getTransform();
void resetTransform();
// compositing
......@@ -128,7 +130,7 @@ interface CanvasRenderingContext2D {
[RaisesException] ImageData getImageData(long sx, long sy, long sw, long sh);
[RaisesException] void putImageData(ImageData imagedata, long dx, long dy);
[RaisesException] void putImageData(ImageData imagedata, long dx, long dy, long dirtyX, long dirtyY, long dirtyWidth, long dirtyHeight);
// https://github.com/WICG/canvas-color-space/blob/master/CanvasColorSpaceProposal.md
[RuntimeEnabled=CanvasColorManagement, RaisesException] ImageData createImageData(unsigned long sw, unsigned long sh, ImageDataColorSettings imageDataColorSettings);
[RuntimeEnabled=CanvasColorManagement, RaisesException] ImageData createImageData(ImageDataArray data, unsigned long sw, unsigned long sh, optional ImageDataColorSettings imageDataColorSettings);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment