Changeset 57020 in webkit


Ignore:
Timestamp:
Apr 2, 2010 1:31:53 PM (14 years ago)
Author:
levin@chromium.org
Message:

(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.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r57018 r57020  
     12010-04-02  David Levin  <levin@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        (non-generated) code should only use CanvasRenderingContext::canvas as a CanvasSurface.
     6        https://bugs.webkit.org/show_bug.cgi?id=36906
     7
     8        * fast/canvas/script-tests/canvas-gradient-addStop-error.js: Changed the test
     9        to create a new canvas after switching to dashboard compatiblity mode, which is
     10        needed now that the compatibility mode is cached in the canvas.
     11
    1122010-04-02  Zhenyao Mo  <zmo@google.com>
    213
  • trunk/LayoutTests/fast/canvas/script-tests/canvas-gradient-addStop-error.js

    r48550 r57020  
    1313    debug("The following tests will fail in the browser as we can only enable dashboard compatibility mode in DRT.")
    1414}
    15 
     15// Create a new context so that will be created using dashboard compatibility mode.
     16ctx = document.createElement('canvas').getContext('2d');
    1617var gradient = ctx.createLinearGradient(0, 0, 0, 100);
    1718shouldBeUndefined("gradient.addColorStop(1, 'rgb(NaN%, NaN%, NaN%)')");
  • trunk/WebCore/ChangeLog

    r57018 r57020  
     12010-04-02  David Levin  <levin@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        (non-generated) code should only use CanvasRenderingContext::canvas as a CanvasSurface.
     6        https://bugs.webkit.org/show_bug.cgi?id=36906
     7
     8        * dom/CanvasSurface.cpp: Added methods for items that depended on
     9        CanvasRenderingContext::canvas() being an HTMLElement(), so that this usage
     10        can be dealt with in one place.
     11        (WebCore::CanvasSurface::securityOrigin): Only used by methods that are
     12        only run in the document context.
     13        (WebCore::CanvasSurface::renderBox): Will likely return 0 in a worker context.
     14        (WebCore::CanvasSurface::computedStyle): Used by setFont. Return value is TBD for
     15        the worker context.
     16        (WebCore::CanvasSurface::styleSelector): Ditto.
     17        * dom/CanvasSurface.h:
     18        * html/HTMLCanvasElement.cpp:
     19        (WebCore::HTMLCanvasElement::getContext): Passing in information into
     20        the CanvasRenderingContext2D constructor to eliminate some uses of document
     21        inside of the CanvasRenderingContext2D class.
     22        * html/HTMLCanvasElement.h:
     23        (WebCore::HTMLCanvasElement::renderBox): Added to disambiguate between the
     24        two parent class versions of the method.
     25        (WebCore::HTMLCanvasElement::computedStyle): Ditto.
     26        * html/canvas/CanvasRenderingContext2D.cpp: All of these changes are about
     27        removing document usage either by using a bool that is set in the constructor or
     28        by calling one of the new methods added to CanvasSurface.
     29        (WebCore::CanvasRenderingContext2D::CanvasRenderingContext2D):
     30        (WebCore::CanvasRenderingContext2D::clearPathForDashboardBackwardCompatibilityMode):
     31        (WebCore::CanvasRenderingContext2D::checkOrigin):
     32        (WebCore::CanvasRenderingContext2D::prepareGradientForDashboard):
     33        (WebCore::CanvasRenderingContext2D::createPattern):
     34        (WebCore::CanvasRenderingContext2D::setFont):
     35        (WebCore::CanvasRenderingContext2D::drawTextInternal):
     36        * html/canvas/CanvasRenderingContext2D.h:
     37        * html/canvas/WebGLRenderingContext.cpp: Removed some duplicate includes.
     38        (WebCore::WebGLRenderingContext::markContextChanged): Reduced calls to renderBox
     39         as it may become slightly more expensive in the future.
     40        (WebCore::WebGLRenderingContext::reshape): Ditto.
     41
    1422010-04-02  Zhenyao Mo  <zmo@google.com>
    243
  • trunk/WebCore/dom/CanvasSurface.cpp

    r56447 r57020  
    3131#include "FloatRect.h"
    3232#include "GraphicsContext.h"
     33#include "HTMLCanvasElement.h"
    3334#include "ImageBuffer.h"
    3435#include "MIMETypeRegistry.h"
     
    155156}
    156157
     158// FIXME: Everything below here relies on CanvasSurface really being
     159// a HTMLCanvasElement.
     160const SecurityOrigin& CanvasSurface::securityOrigin() const
     161{
     162    return *(static_cast<const HTMLCanvasElement*>(this)->document()->securityOrigin());
     163}
     164
     165RenderBox* CanvasSurface::renderBox() const
     166{
     167    return static_cast<const HTMLCanvasElement*>(this)->renderBox();
     168}
     169
     170RenderStyle* CanvasSurface::computedStyle()
     171{
     172    return static_cast<HTMLCanvasElement*>(this)->computedStyle();
     173}
     174
     175CSSStyleSelector* CanvasSurface::styleSelector()
     176{
     177    return static_cast<HTMLCanvasElement*>(this)->document()->styleSelector();
     178}
     179
    157180} // namespace WebCore
  • trunk/WebCore/dom/CanvasSurface.h

    r56447 r57020  
    4444class String;
    4545
     46class CSSStyleSelector;
     47class RenderBox;
     48class RenderStyle;
     49class SecurityOrigin;
     50
    4651typedef int ExceptionCode;
    4752
     
    7378    AffineTransform baseTransform() const;
    7479
     80    const SecurityOrigin& securityOrigin() const;
     81    RenderBox* renderBox() const;
     82    RenderStyle* computedStyle();
     83    CSSStyleSelector* styleSelector();
     84
    7585protected:
    7686    void setSurfaceSize(const IntSize&);
  • trunk/WebCore/html/HTMLCanvasElement.cpp

    r56447 r57020  
    134134        if (m_context && !m_context->is2d())
    135135            return 0;
    136         if (!m_context)
    137             m_context = new CanvasRenderingContext2D(this);
     136        if (!m_context) {
     137            bool usesDashbardCompatibilityMode = false;
     138#if ENABLE(DASHBOARD_SUPPORT)
     139            if (Settings* settings = document()->settings())
     140                usesDashbardCompatibilityMode = settings->usesDashboardBackwardCompatibilityMode();
     141#endif
     142            m_context = new CanvasRenderingContext2D(this, document()->inCompatMode(), usesDashbardCompatibilityMode);
     143        }
    138144        return m_context.get();
    139145    }
  • trunk/WebCore/html/HTMLCanvasElement.h

    r56447 r57020  
    8282    CanvasRenderingContext* renderingContext() const { return m_context.get(); }
    8383
     84    RenderBox* renderBox() const { return HTMLElement::renderBox(); }
     85    RenderStyle* computedStyle() { return HTMLElement::computedStyle(); }
     86
    8487#if ENABLE(3D_CANVAS)   
    8588    bool is3D() const;
  • trunk/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r56810 r57020  
    4040#include "CSSPropertyNames.h"
    4141#include "CSSStyleSelector.h"
    42 #include "Document.h"
    4342#include "ExceptionCode.h"
    4443#include "FloatConversion.h"
     
    9190};
    9291
    93 
    94 
    95 CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas)
     92CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, bool usesCSSCompatibilityParseMode, bool usesDashbardCompatibilityMode)
    9693    : CanvasRenderingContext(canvas)
    9794    , m_stateStack(1)
    98 {
     95    , m_usesCSSCompatibilityParseMode(usesCSSCompatibilityParseMode)
     96#if ENABLE(DASHBOARD_SUPPORT)
     97    , m_usesDashbardCompatibilityMode(usesDashbardCompatibilityMode)
     98#endif
     99{
     100#if !ENABLE(DASHBOARD_SUPPORT)
     101   ASSERT_UNUSED(usesDashboardCompatibilityMode, !usesDashboardCompatibilityMode);
     102#endif
     103
    99104    // Make sure that even if the drawingContext() has a different default
    100105    // thickness, it is in sync with the canvas thickness.
     
    637642void CanvasRenderingContext2D::clearPathForDashboardBackwardCompatibilityMode()
    638643{
    639     if (Settings* settings = canvas()->document()->settings())
    640         if (settings->usesDashboardBackwardCompatibilityMode())
    641             m_path.clear();
     644    if (m_usesDashbardCompatibilityMode)
     645        m_path.clear();
    642646}
    643647#endif
     
    942946void CanvasRenderingContext2D::checkOrigin(const KURL& url)
    943947{
    944     if (canvas()->document()->securityOrigin()->taintsCanvas(url))
     948    if (canvas()->securityOrigin().taintsCanvas(url))
    945949        canvas()->setOriginTainted();
    946950}
     
    11621166{
    11631167#if ENABLE(DASHBOARD_SUPPORT)
    1164     if (Settings* settings = canvas()->document()->settings())
    1165         if (settings->usesDashboardBackwardCompatibilityMode())
    1166             gradient->setDashboardCompatibilityMode();
     1168    if (m_usesDashbardCompatibilityMode)
     1169        gradient->setDashboardCompatibilityMode();
    11671170#else
    11681171    UNUSED_PARAM(gradient);
     
    12121215        return CanvasPattern::create(Image::nullImage(), repeatX, repeatY, true);
    12131216
    1214     bool originClean = !canvas()->document()->securityOrigin()->taintsCanvas(KURL(KURL(), cachedImage->url())) && cachedImage->image()->hasSingleSecurityOrigin();
     1217    bool originClean = !canvas()->securityOrigin().taintsCanvas(KURL(KURL(), cachedImage->url())) && cachedImage->image()->hasSingleSecurityOrigin();
    12151218    return CanvasPattern::create(cachedImage->image(), repeatX, repeatY, originClean);
    12161219}
     
    13701373{
    13711374    RefPtr<CSSMutableStyleDeclaration> tempDecl = CSSMutableStyleDeclaration::create();
    1372     CSSParser parser(!canvas()->document()->inCompatMode()); // Use the parse mode of the canvas' document when parsing CSS.
     1375    CSSParser parser(!m_usesCSSCompatibilityParseMode);
    13731376       
    13741377    String declarationText("font: ");
     
    13841387    // relative to the canvas.
    13851388    RefPtr<RenderStyle> newStyle = RenderStyle::create();
    1386     if (canvas()->computedStyle())
    1387         newStyle->setFontDescription(canvas()->computedStyle()->fontDescription());
     1389    if (RenderStyle* computedStyle = canvas()->computedStyle())
     1390        newStyle->setFontDescription(computedStyle->fontDescription());
    13881391
    13891392    // Now map the font property into the style.
    1390     CSSStyleSelector* styleSelector = canvas()->document()->styleSelector();
     1393    CSSStyleSelector* styleSelector = canvas()->styleSelector();
    13911394    styleSelector->applyPropertyToStyle(CSSPropertyFont, tempDecl->getPropertyCSSValue(CSSPropertyFont).get(), newStyle.get());
    13921395   
     
    14621465    // FIXME: Need to turn off font smoothing.
    14631466
    1464     bool rtl = canvas()->computedStyle() ? canvas()->computedStyle()->direction() == RTL : false;
    1465     bool override = canvas()->computedStyle() ? canvas()->computedStyle()->unicodeBidi() == Override : false;
     1467    RenderStyle* computedStyle = canvas()->computedStyle();
     1468    bool rtl = computedStyle ? computedStyle->direction() == RTL : false;
     1469    bool override = computedStyle ? computedStyle->unicodeBidi() == Override : false;
    14661470
    14671471    unsigned length = text.length();
  • trunk/WebCore/html/canvas/CanvasRenderingContext2D.h

    r54137 r57020  
    5858    class CanvasRenderingContext2D : public CanvasRenderingContext {
    5959    public:
    60         CanvasRenderingContext2D(HTMLCanvasElement*);
     60        CanvasRenderingContext2D(HTMLCanvasElement*, bool usesCSSCompatibilityParseMode, bool usesDashbardCompatibilityMode);
    6161
    6262        virtual ~CanvasRenderingContext2D();
     
    264264
    265265        Vector<State, 1> m_stateStack;
     266        bool m_usesCSSCompatibilityParseMode;
     267#if ENABLE(DASHBOARD_SUPPORT)
     268        bool m_usesDashbardCompatibilityMode;
     269#endif
    266270    };
    267271
  • trunk/WebCore/html/canvas/WebGLRenderingContext.cpp

    r57018 r57020  
    4747#include "WebGLShader.h"
    4848#include "WebGLUniformLocation.h"
    49 #include "HTMLCanvasElement.h"
    50 #include "HTMLImageElement.h"
    51 #include "ImageBuffer.h"
    52 #include "NotImplemented.h"
    53 #include "RenderBox.h"
    54 #include "RenderLayer.h"
    5549
    5650#include <wtf/ByteArray.h>
     
    109103{
    110104#if USE(ACCELERATED_COMPOSITING)
    111     if (canvas()->renderBox() && canvas()->renderBox()->hasLayer() && canvas()->renderBox()->layer()->hasAcceleratedCompositing()) {
    112         canvas()->renderBox()->layer()->rendererContentChanged();
    113     } else {
     105    RenderBox* renderBox = canvas()->renderBox();
     106    if (renderBox && renderBox->hasLayer() && renderBox->layer()->hasAcceleratedCompositing())
     107        renderBox->layer()->rendererContentChanged();
     108    else {
    114109#endif
    115110        if (!m_markedCanvasDirty) {
     
    143138    if (m_needsUpdate) {
    144139#if USE(ACCELERATED_COMPOSITING)
    145         if (canvas()->renderBox() && canvas()->renderBox()->hasLayer())
    146             canvas()->renderBox()->layer()->rendererContentChanged();
     140        RenderBox* renderBox = canvas()->renderBox();
     141        if (renderBox && renderBox->hasLayer())
     142            renderBox->layer()->rendererContentChanged();
    147143#endif
    148144        m_needsUpdate = false;
Note: See TracChangeset for help on using the changeset viewer.