Commit 61fc3bb1 authored by levin@chromium.org's avatar levin@chromium.org
Browse files

(non-generated) code should only use CanvasRenderingContext::canvas as a CanvasSurface.

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

Reviewed by Darin Adler.

WebCore:

* dom/CanvasSurface.cpp: Added methods for items that depended on
CanvasRenderingContext::canvas() being an HTMLElement(), so that this usage
can be dealt with in one place.
(WebCore::CanvasSurface::securityOrigin): Only used by methods that are
only run in the document context.
(WebCore::CanvasSurface::renderBox): Will likely return 0 in a worker context.
(WebCore::CanvasSurface::computedStyle): Used by setFont. Return value is TBD for
the worker context.
(WebCore::CanvasSurface::styleSelector): Ditto.
* dom/CanvasSurface.h:
* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::getContext): Passing in information into
the CanvasRenderingContext2D constructor to eliminate some uses of document
inside of the CanvasRenderingContext2D class.
* html/HTMLCanvasElement.h:
(WebCore::HTMLCanvasElement::renderBox): Added to disambiguate between the
two parent class versions of the method.
(WebCore::HTMLCanvasElement::computedStyle): Ditto.
* html/canvas/CanvasRenderingContext2D.cpp: All of these changes are about
removing document usage either by using a bool that is set in the constructor or
by calling one of the new methods added to CanvasSurface.
(WebCore::CanvasRenderingContext2D::CanvasRenderingContext2D):
(WebCore::CanvasRenderingContext2D::clearPathForDashboardBackwardCompatibilityMode):
(WebCore::CanvasRenderingContext2D::checkOrigin):
(WebCore::CanvasRenderingContext2D::prepareGradientForDashboard):
(WebCore::CanvasRenderingContext2D::createPattern):
(WebCore::CanvasRenderingContext2D::setFont):
(WebCore::CanvasRenderingContext2D::drawTextInternal):
* html/canvas/CanvasRenderingContext2D.h:
* html/canvas/WebGLRenderingContext.cpp: Removed some duplicate includes.
(WebCore::WebGLRenderingContext::markContextChanged): Reduced calls to renderBox
 as it may become slightly more expensive in the future.
(WebCore::WebGLRenderingContext::reshape): Ditto.

LayoutTests:

* fast/canvas/script-tests/canvas-gradient-addStop-error.js: Changed the test
to create a new canvas after switching to dashboard compatiblity mode, which is
needed now that the compatibility mode is cached in the canvas.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@57020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f2645846
2010-04-02 David Levin <levin@chromium.org>
Reviewed by Darin Adler.
(non-generated) code should only use CanvasRenderingContext::canvas as a CanvasSurface.
https://bugs.webkit.org/show_bug.cgi?id=36906
* fast/canvas/script-tests/canvas-gradient-addStop-error.js: Changed the test
to create a new canvas after switching to dashboard compatiblity mode, which is
needed now that the compatibility mode is cached in the canvas.
2010-04-02 Zhenyao Mo <zmo@google.com>
 
Reviewed by Eric Seidel.
......
......@@ -12,7 +12,8 @@ if (this.layoutTestController) {
} else {
debug("The following tests will fail in the browser as we can only enable dashboard compatibility mode in DRT.")
}
// Create a new context so that will be created using dashboard compatibility mode.
ctx = document.createElement('canvas').getContext('2d');
var gradient = ctx.createLinearGradient(0, 0, 0, 100);
shouldBeUndefined("gradient.addColorStop(1, 'rgb(NaN%, NaN%, NaN%)')");
var gradient = ctx.createRadialGradient(0, 0, 0, 100, 0, 0);
......
2010-04-02 David Levin <levin@chromium.org>
Reviewed by Darin Adler.
(non-generated) code should only use CanvasRenderingContext::canvas as a CanvasSurface.
https://bugs.webkit.org/show_bug.cgi?id=36906
* dom/CanvasSurface.cpp: Added methods for items that depended on
CanvasRenderingContext::canvas() being an HTMLElement(), so that this usage
can be dealt with in one place.
(WebCore::CanvasSurface::securityOrigin): Only used by methods that are
only run in the document context.
(WebCore::CanvasSurface::renderBox): Will likely return 0 in a worker context.
(WebCore::CanvasSurface::computedStyle): Used by setFont. Return value is TBD for
the worker context.
(WebCore::CanvasSurface::styleSelector): Ditto.
* dom/CanvasSurface.h:
* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::getContext): Passing in information into
the CanvasRenderingContext2D constructor to eliminate some uses of document
inside of the CanvasRenderingContext2D class.
* html/HTMLCanvasElement.h:
(WebCore::HTMLCanvasElement::renderBox): Added to disambiguate between the
two parent class versions of the method.
(WebCore::HTMLCanvasElement::computedStyle): Ditto.
* html/canvas/CanvasRenderingContext2D.cpp: All of these changes are about
removing document usage either by using a bool that is set in the constructor or
by calling one of the new methods added to CanvasSurface.
(WebCore::CanvasRenderingContext2D::CanvasRenderingContext2D):
(WebCore::CanvasRenderingContext2D::clearPathForDashboardBackwardCompatibilityMode):
(WebCore::CanvasRenderingContext2D::checkOrigin):
(WebCore::CanvasRenderingContext2D::prepareGradientForDashboard):
(WebCore::CanvasRenderingContext2D::createPattern):
(WebCore::CanvasRenderingContext2D::setFont):
(WebCore::CanvasRenderingContext2D::drawTextInternal):
* html/canvas/CanvasRenderingContext2D.h:
* html/canvas/WebGLRenderingContext.cpp: Removed some duplicate includes.
(WebCore::WebGLRenderingContext::markContextChanged): Reduced calls to renderBox
as it may become slightly more expensive in the future.
(WebCore::WebGLRenderingContext::reshape): Ditto.
2010-04-02 Zhenyao Mo <zmo@google.com>
 
Reviewed by Eric Seidel.
......@@ -30,6 +30,7 @@
#include "ExceptionCode.h"
#include "FloatRect.h"
#include "GraphicsContext.h"
#include "HTMLCanvasElement.h"
#include "ImageBuffer.h"
#include "MIMETypeRegistry.h"
......@@ -154,4 +155,26 @@ AffineTransform CanvasSurface::baseTransform() const
return transform;
}
// FIXME: Everything below here relies on CanvasSurface really being
// a HTMLCanvasElement.
const SecurityOrigin& CanvasSurface::securityOrigin() const
{
return *(static_cast<const HTMLCanvasElement*>(this)->document()->securityOrigin());
}
RenderBox* CanvasSurface::renderBox() const
{
return static_cast<const HTMLCanvasElement*>(this)->renderBox();
}
RenderStyle* CanvasSurface::computedStyle()
{
return static_cast<HTMLCanvasElement*>(this)->computedStyle();
}
CSSStyleSelector* CanvasSurface::styleSelector()
{
return static_cast<HTMLCanvasElement*>(this)->document()->styleSelector();
}
} // namespace WebCore
......@@ -43,6 +43,11 @@ class ImageBuffer;
class IntPoint;
class String;
class CSSStyleSelector;
class RenderBox;
class RenderStyle;
class SecurityOrigin;
typedef int ExceptionCode;
class CanvasSurface : public Noncopyable {
......@@ -72,6 +77,11 @@ public:
AffineTransform baseTransform() const;
const SecurityOrigin& securityOrigin() const;
RenderBox* renderBox() const;
RenderStyle* computedStyle();
CSSStyleSelector* styleSelector();
protected:
void setSurfaceSize(const IntSize&);
bool hasCreatedImageBuffer() const { return m_hasCreatedImageBuffer; }
......
......@@ -133,8 +133,14 @@ CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type, Canvas
if (type == "2d") {
if (m_context && !m_context->is2d())
return 0;
if (!m_context)
m_context = new CanvasRenderingContext2D(this);
if (!m_context) {
bool usesDashbardCompatibilityMode = false;
#if ENABLE(DASHBOARD_SUPPORT)
if (Settings* settings = document()->settings())
usesDashbardCompatibilityMode = settings->usesDashboardBackwardCompatibilityMode();
#endif
m_context = new CanvasRenderingContext2D(this, document()->inCompatMode(), usesDashbardCompatibilityMode);
}
return m_context.get();
}
#if ENABLE(3D_CANVAS)
......
......@@ -81,6 +81,9 @@ public:
CanvasRenderingContext* renderingContext() const { return m_context.get(); }
RenderBox* renderBox() const { return HTMLElement::renderBox(); }
RenderStyle* computedStyle() { return HTMLElement::computedStyle(); }
#if ENABLE(3D_CANVAS)
bool is3D() const;
#endif
......
......@@ -39,7 +39,6 @@
#include "CSSMutableStyleDeclaration.h"
#include "CSSPropertyNames.h"
#include "CSSStyleSelector.h"
#include "Document.h"
#include "ExceptionCode.h"
#include "FloatConversion.h"
#include "GraphicsContext.h"
......@@ -90,12 +89,18 @@ private:
CanvasRenderingContext2D* m_canvasContext;
};
CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas)
CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, bool usesCSSCompatibilityParseMode, bool usesDashbardCompatibilityMode)
: CanvasRenderingContext(canvas)
, m_stateStack(1)
, m_usesCSSCompatibilityParseMode(usesCSSCompatibilityParseMode)
#if ENABLE(DASHBOARD_SUPPORT)
, m_usesDashbardCompatibilityMode(usesDashbardCompatibilityMode)
#endif
{
#if !ENABLE(DASHBOARD_SUPPORT)
ASSERT_UNUSED(usesDashboardCompatibilityMode, !usesDashboardCompatibilityMode);
#endif
// Make sure that even if the drawingContext() has a different default
// thickness, it is in sync with the canvas thickness.
setLineWidth(lineWidth());
......@@ -636,9 +641,8 @@ void CanvasRenderingContext2D::rect(float x, float y, float width, float height)
#if ENABLE(DASHBOARD_SUPPORT)
void CanvasRenderingContext2D::clearPathForDashboardBackwardCompatibilityMode()
{
if (Settings* settings = canvas()->document()->settings())
if (settings->usesDashboardBackwardCompatibilityMode())
m_path.clear();
if (m_usesDashbardCompatibilityMode)
m_path.clear();
}
#endif
......@@ -941,7 +945,7 @@ static inline FloatRect normalizeRect(const FloatRect& rect)
void CanvasRenderingContext2D::checkOrigin(const KURL& url)
{
if (canvas()->document()->securityOrigin()->taintsCanvas(url))
if (canvas()->securityOrigin().taintsCanvas(url))
canvas()->setOriginTainted();
}
......@@ -1161,9 +1165,8 @@ void CanvasRenderingContext2D::setCompositeOperation(const String& operation)
void CanvasRenderingContext2D::prepareGradientForDashboard(CanvasGradient* gradient) const
{
#if ENABLE(DASHBOARD_SUPPORT)
if (Settings* settings = canvas()->document()->settings())
if (settings->usesDashboardBackwardCompatibilityMode())
gradient->setDashboardCompatibilityMode();
if (m_usesDashbardCompatibilityMode)
gradient->setDashboardCompatibilityMode();
#else
UNUSED_PARAM(gradient);
#endif
......@@ -1211,7 +1214,7 @@ PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLImageEleme
if (!cachedImage || !image->cachedImage()->image())
return CanvasPattern::create(Image::nullImage(), repeatX, repeatY, true);
bool originClean = !canvas()->document()->securityOrigin()->taintsCanvas(KURL(KURL(), cachedImage->url())) && cachedImage->image()->hasSingleSecurityOrigin();
bool originClean = !canvas()->securityOrigin().taintsCanvas(KURL(KURL(), cachedImage->url())) && cachedImage->image()->hasSingleSecurityOrigin();
return CanvasPattern::create(cachedImage->image(), repeatX, repeatY, originClean);
}
......@@ -1369,7 +1372,7 @@ String CanvasRenderingContext2D::font() const
void CanvasRenderingContext2D::setFont(const String& newFont)
{
RefPtr<CSSMutableStyleDeclaration> tempDecl = CSSMutableStyleDeclaration::create();
CSSParser parser(!canvas()->document()->inCompatMode()); // Use the parse mode of the canvas' document when parsing CSS.
CSSParser parser(!m_usesCSSCompatibilityParseMode);
String declarationText("font: ");
declarationText += newFont;
......@@ -1383,11 +1386,11 @@ void CanvasRenderingContext2D::setFont(const String& newFont)
// Map the <canvas> font into the text style. If the font uses keywords like larger/smaller, these will work
// relative to the canvas.
RefPtr<RenderStyle> newStyle = RenderStyle::create();
if (canvas()->computedStyle())
newStyle->setFontDescription(canvas()->computedStyle()->fontDescription());
if (RenderStyle* computedStyle = canvas()->computedStyle())
newStyle->setFontDescription(computedStyle->fontDescription());
// Now map the font property into the style.
CSSStyleSelector* styleSelector = canvas()->document()->styleSelector();
CSSStyleSelector* styleSelector = canvas()->styleSelector();
styleSelector->applyPropertyToStyle(CSSPropertyFont, tempDecl->getPropertyCSSValue(CSSPropertyFont).get(), newStyle.get());
state().m_font = newStyle->font();
......@@ -1461,8 +1464,9 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo
// FIXME: Handle maxWidth.
// FIXME: Need to turn off font smoothing.
bool rtl = canvas()->computedStyle() ? canvas()->computedStyle()->direction() == RTL : false;
bool override = canvas()->computedStyle() ? canvas()->computedStyle()->unicodeBidi() == Override : false;
RenderStyle* computedStyle = canvas()->computedStyle();
bool rtl = computedStyle ? computedStyle->direction() == RTL : false;
bool override = computedStyle ? computedStyle->unicodeBidi() == Override : false;
unsigned length = text.length();
const UChar* string = text.characters();
......
......@@ -57,7 +57,7 @@ namespace WebCore {
class CanvasRenderingContext2D : public CanvasRenderingContext {
public:
CanvasRenderingContext2D(HTMLCanvasElement*);
CanvasRenderingContext2D(HTMLCanvasElement*, bool usesCSSCompatibilityParseMode, bool usesDashbardCompatibilityMode);
virtual ~CanvasRenderingContext2D();
......@@ -263,6 +263,10 @@ namespace WebCore {
void checkOrigin(const String&);
Vector<State, 1> m_stateStack;
bool m_usesCSSCompatibilityParseMode;
#if ENABLE(DASHBOARD_SUPPORT)
bool m_usesDashbardCompatibilityMode;
#endif
};
} // namespace WebCore
......
......@@ -46,12 +46,6 @@
#include "WebGLTexture.h"
#include "WebGLShader.h"
#include "WebGLUniformLocation.h"
#include "HTMLCanvasElement.h"
#include "HTMLImageElement.h"
#include "ImageBuffer.h"
#include "NotImplemented.h"
#include "RenderBox.h"
#include "RenderLayer.h"
#include <wtf/ByteArray.h>
......@@ -108,9 +102,10 @@ WebGLRenderingContext::~WebGLRenderingContext()
void WebGLRenderingContext::markContextChanged()
{
#if USE(ACCELERATED_COMPOSITING)
if (canvas()->renderBox() && canvas()->renderBox()->hasLayer() && canvas()->renderBox()->layer()->hasAcceleratedCompositing()) {
canvas()->renderBox()->layer()->rendererContentChanged();
} else {
RenderBox* renderBox = canvas()->renderBox();
if (renderBox && renderBox->hasLayer() && renderBox->layer()->hasAcceleratedCompositing())
renderBox->layer()->rendererContentChanged();
else {
#endif
if (!m_markedCanvasDirty) {
// Make sure the canvas's image buffer is allocated.
......@@ -142,8 +137,9 @@ void WebGLRenderingContext::reshape(int width, int height)
{
if (m_needsUpdate) {
#if USE(ACCELERATED_COMPOSITING)
if (canvas()->renderBox() && canvas()->renderBox()->hasLayer())
canvas()->renderBox()->layer()->rendererContentChanged();
RenderBox* renderBox = canvas()->renderBox();
if (renderBox && renderBox->hasLayer())
renderBox->layer()->rendererContentChanged();
#endif
m_needsUpdate = false;
}
......
Supports Markdown
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