Assertion fires if canvas is resized while save() active

https://bugs.webkit.org/show_bug.cgi?id=66710

Reviewed by Simon Fraser.

Source/WebCore: 

Test: fast/canvas/resize-while-save-active.html

* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::reset):
Call CanvasRenderingContext2D::reset() before resizing the canvas,
so that the GraphicsContext state stack can be unwound.
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::unwindStateStack):
(WebCore::CanvasRenderingContext2D::~CanvasRenderingContext2D):
Refactor the state stack unwinding code from the destructor to 
unwindStateStack() (new).
(WebCore::CanvasRenderingContext2D::reset):
Unwind the GraphicsContext state stack when the context is reset.
* html/canvas/CanvasRenderingContext2D.h:

LayoutTests: 

* fast/canvas/resize-while-save-active-expected.txt: Added.
* fast/canvas/resize-while-save-active.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@93901 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1b943efc
2011-08-23 Stephen White <senorblanco@chromium.org>
Assertion fires if canvas is resized while save() active
https://bugs.webkit.org/show_bug.cgi?id=66710
Reviewed by Simon Fraser.
* fast/canvas/resize-while-save-active-expected.txt: Added.
* fast/canvas/resize-while-save-active.html: Added.
2011-08-26 Martin Robinson <mrobinson@igalia.com>
Add some new baselines for GTK+ and unskip tests that now have them.
If we got this far without an assertion, this test passed.
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<canvas id="mycanvas" width="512" height="512"></canvas>
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText()
var canvas = document.getElementById('mycanvas');
var ctx = canvas.getContext('2d');
ctx.fillStyle = "rgb(255,165,0)";
ctx.fillRect(0, 0, 512, 512);
ctx.save();
canvas.width = 256;
ctx.fillStyle = "rgb(255,165,0)";
ctx.fillRect(0, 0, 256, 512);
document.body.appendChild(document.createElement("p")).appendChild(document.createTextNode("If we got this far without an assertion, this test passed."));
</script>
</body>
</html>
2011-08-23 Stephen White <senorblanco@chromium.org>
Assertion fires if canvas is resized while save() active
https://bugs.webkit.org/show_bug.cgi?id=66710
Reviewed by Simon Fraser.
Test: fast/canvas/resize-while-save-active.html
* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::reset):
Call CanvasRenderingContext2D::reset() before resizing the canvas,
so that the GraphicsContext state stack can be unwound.
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::unwindStateStack):
(WebCore::CanvasRenderingContext2D::~CanvasRenderingContext2D):
Refactor the state stack unwinding code from the destructor to
unwindStateStack() (new).
(WebCore::CanvasRenderingContext2D::reset):
Unwind the GraphicsContext state stack when the context is reset.
* html/canvas/CanvasRenderingContext2D.h:
2011-08-26 Darin Adler <darin@apple.com>
[Mac] Use the progress cursor instead of the wristwatch for CSS "wait" cursor
......@@ -237,6 +237,11 @@ void HTMLCanvasElement::reset()
if (!ok || h < 0)
h = DefaultHeight;
if (m_context && m_context->is2d()) {
CanvasRenderingContext2D* context2D = static_cast<CanvasRenderingContext2D*>(m_context.get());
context2D->reset();
}
IntSize oldSize = size();
setSurfaceSize(IntSize(w, h)); // The image buffer gets cleared here.
......@@ -245,11 +250,6 @@ void HTMLCanvasElement::reset()
static_cast<WebGLRenderingContext*>(m_context.get())->reshape(width(), height());
#endif
if (m_context && m_context->is2d()) {
CanvasRenderingContext2D* context2D = static_cast<CanvasRenderingContext2D*>(m_context.get());
context2D->reset();
}
if (RenderObject* renderer = this->renderer()) {
if (m_rendererIsCanvas) {
if (oldSize != size())
......
......@@ -127,9 +127,8 @@ CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, bo
setLineWidth(lineWidth());
}
CanvasRenderingContext2D::~CanvasRenderingContext2D()
void CanvasRenderingContext2D::unwindStateStack()
{
#if !ASSERT_DISABLED
// Ensure that the state stack in the ImageBuffer's context
// is cleared before destruction, to avoid assertions in the
// GraphicsContext dtor.
......@@ -139,6 +138,12 @@ CanvasRenderingContext2D::~CanvasRenderingContext2D()
context->restore();
}
}
}
CanvasRenderingContext2D::~CanvasRenderingContext2D()
{
#if !ASSERT_DISABLED
unwindStateStack();
#endif
}
......@@ -170,6 +175,7 @@ bool CanvasRenderingContext2D::paintsIntoCanvasBuffer() const
void CanvasRenderingContext2D::reset()
{
unwindStateStack();
m_stateStack.resize(1);
m_stateStack.first() = State();
m_path.clear();
......
......@@ -273,6 +273,8 @@ private:
GraphicsContext* drawingContext() const;
void unwindStateStack();
void applyStrokePattern();
void applyFillPattern();
......
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