| Differences between
and this patch
- a/WebCore/ChangeLog +46 lines
Lines 1-3 a/WebCore/ChangeLog_sec1
1
2010-02-26  David Levin  <levin@chromium.org>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        Need to move items that CanvasRenderingContext2D depends on into CanvasSurface.
6
        https://bugs.webkit.org/show_bug.cgi?id=35453
7
8
        Prepartory changes to allow for an OffscreenCanvas which may be used in a worker
9
        or outside of the DOM.
10
11
        No change in functionality, so new tests.
12
13
        * dom/CanvasSurface.cpp: Moved functionality that CanvasRenderingContext2D depends on
14
        into this class (and removed dependencies on document/html element).
15
        (WebCore::CanvasSurface::CanvasSurface):
16
        (WebCore::CanvasSurface::~CanvasSurface): Put the desctructor in the cpp file
17
        to avoid needing access to ~ImageBuffer in the header file.
18
        (WebCore::CanvasSurface::setSurfaceSize): Does basic items needed
19
        when the size changes. It is protected to force outside callers to go
20
        through HTMLCanvasElement::setSize.
21
        (WebCore::CanvasSurface::toDataURL): Just moved from HTMLCanvasElement and
22
        made a note about a method to fix for worker usage.
23
        (WebCore::CanvasSurface::willDraw): Made this virtual to allow an overide
24
        which uses the renderbox and tracks a dirtyRect.
25
        (WebCore::CanvasSurface::convertLogicalToDevice): Moved and changed to
26
        rely on a member variable for page scale (to avoid using the document).
27
        (WebCore::CanvasSurface::createImageBuffer):
28
        (WebCore::CanvasSurface::drawingContext): Simple move from HTMLCanvasElement.
29
        (WebCore::CanvasSurface::buffer): Ditto.
30
        (WebCore::CanvasSurface::baseTransform): Ditto.
31
        * dom/CanvasSurface.h:
32
        (WebCore::CanvasSurface::width): Simple move from HTMLCanvasElement.
33
        (WebCore::CanvasSurface::height): Ditto.
34
        (WebCore::CanvasSurface::size): Ditto.
35
        (WebCore::CanvasSurface::setOriginTainted): Ditto.
36
        (WebCore::CanvasSurface::originClean): Ditto.
37
        (WebCore::CanvasSurface::hasCreatedImageBuffer): Ditto (with small name change).
38
        * html/HTMLCanvasElement.cpp:
39
        (WebCore::HTMLCanvasElement::HTMLCanvasElement): Pass in the scale factor to CanvasSurface
40
        so it doesn't need the document.
41
        (WebCore::HTMLCanvasElement::willDraw): Moved the relevant portion to CanvasSurface.
42
        (WebCore::HTMLCanvasElement::reset): Small changes due to refactoring.
43
        (WebCore::HTMLCanvasElement::paint): Ditto.
44
        * html/HTMLCanvasElement.h:
45
        (WebCore::HTMLCanvasElement::setSize): Ditto.
46
1
2010-02-26  Adam Barth  <abarth@webkit.org>
47
2010-02-26  Adam Barth  <abarth@webkit.org>
2
48
3
        Reviewed by Darin Adler.
49
        Reviewed by Darin Adler.
- a/WebCore/dom/CanvasSurface.cpp +126 lines
Lines 26-31 a/WebCore/dom/CanvasSurface.cpp_sec1
26
#include "config.h"
26
#include "config.h"
27
#include "CanvasSurface.h"
27
#include "CanvasSurface.h"
28
28
29
#include "AffineTransform.h"
30
#include "ExceptionCode.h"
31
#include "FloatRect.h"
32
#include "GraphicsContext.h"
33
#include "ImageBuffer.h"
34
#include "MIMETypeRegistry.h"
35
29
namespace WebCore {
36
namespace WebCore {
30
37
38
// These values come from the WhatWG spec.
39
const int CanvasSurface::DefaultWidth = 300;
40
const int CanvasSurface::DefaultHeight = 150;
41
42
// Firefox limits width/height to 32767 pixels, but slows down dramatically before it
43
// reaches that limit. We limit by area instead, giving us larger maximum dimensions,
44
// in exchange for a smaller maximum canvas size.
45
const float CanvasSurface::MaxCanvasArea = 32768 * 8192; // Maximum canvas area in CSS pixels
46
47
CanvasSurface::CanvasSurface(float pageScaleFactor)
48
    : m_size(DefaultWidth, DefaultHeight)
49
    , m_pageScaleFactor(pageScaleFactor)
50
    , m_originClean(true)
51
    , m_hasCreatedImageBuffer(false)
52
{
53
}
54
55
CanvasSurface::~CanvasSurface()
56
{
57
}
58
59
void CanvasSurface::setSurfaceSize(const IntSize& size)
60
{
61
    m_size = size;
62
    m_hasCreatedImageBuffer = false;
63
    m_imageBuffer.clear();
64
}
65
66
String CanvasSurface::toDataURL(const String& mimeType, ExceptionCode& ec)
67
{
68
    if (!m_originClean) {
69
        ec = SECURITY_ERR;
70
        return String();
71
    }
72
73
    if (m_size.isEmpty() || !buffer())
74
        return String("data:,");
75
76
    // FIXME: Make isSupportedImageMIMETypeForEncoding threadsafe (to allow this method to be used on a worker thread).
77
    if (mimeType.isNull() || !MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType))
78
        return buffer()->toDataURL("image/png");
79
80
    return buffer()->toDataURL(mimeType);
81
}
82
83
void CanvasSurface::willDraw(const FloatRect&)
84
{
85
    if (m_imageBuffer)
86
        m_imageBuffer->clearImage();
87
}
88
89
IntRect CanvasSurface::convertLogicalToDevice(const FloatRect& logicalRect) const
90
{
91
    return IntRect(convertLogicalToDevice(logicalRect.location()), convertLogicalToDevice(logicalRect.size()));
92
}
93
94
IntSize CanvasSurface::convertLogicalToDevice(const FloatSize& logicalSize) const
95
{
96
    float wf = ceilf(logicalSize.width() * m_pageScaleFactor);
97
    float hf = ceilf(logicalSize.height() * m_pageScaleFactor);
98
99
    if (!(wf >= 1 && hf >= 1 && wf * hf <= MaxCanvasArea))
100
        return IntSize();
101
102
    return IntSize(static_cast<unsigned>(wf), static_cast<unsigned>(hf));
103
}
104
105
IntPoint CanvasSurface::convertLogicalToDevice(const FloatPoint& logicalPos) const
106
{
107
    float xf = logicalPos.x() * m_pageScaleFactor;
108
    float yf = logicalPos.y() * m_pageScaleFactor;
109
110
    return IntPoint(static_cast<unsigned>(xf), static_cast<unsigned>(yf));
111
}
112
113
void CanvasSurface::createImageBuffer() const
114
{
115
    ASSERT(!m_imageBuffer);
116
117
    m_hasCreatedImageBuffer = true;
118
119
    FloatSize unscaledSize(width(), height());
120
    IntSize size = convertLogicalToDevice(unscaledSize);
121
    if (!size.width() || !size.height())
122
        return;
123
124
    m_imageBuffer = ImageBuffer::create(size);
125
    // The convertLogicalToDevice MaxCanvasArea check should prevent common cases
126
    // where ImageBuffer::create() returns 0, however we could still be low on memory.
127
    if (!m_imageBuffer)
128
        return;
129
    m_imageBuffer->context()->scale(FloatSize(size.width() / unscaledSize.width(), size.height() / unscaledSize.height()));
130
    m_imageBuffer->context()->setShadowsIgnoreTransforms(true);
131
}
132
133
GraphicsContext* CanvasSurface::drawingContext() const
134
{
135
    return buffer() ? m_imageBuffer->context() : 0;
136
}
137
138
ImageBuffer* CanvasSurface::buffer() const
139
{
140
    if (!m_hasCreatedImageBuffer)
141
        createImageBuffer();
142
    return m_imageBuffer.get();
143
}
144
145
AffineTransform CanvasSurface::baseTransform() const
146
{
147
    ASSERT(m_hasCreatedImageBuffer);
148
    FloatSize unscaledSize(width(), height());
149
    IntSize size = convertLogicalToDevice(unscaledSize);
150
    AffineTransform transform;
151
    if (size.width() && size.height())
152
        transform.scaleNonUniform(size.width() / unscaledSize.width(), size.height() / unscaledSize.height());
153
    transform.multiply(m_imageBuffer->baseTransform());
154
    return transform;
155
}
156
31
} // namespace WebCore
157
} // namespace WebCore
- a/WebCore/dom/CanvasSurface.h +58 lines
Lines 26-39 a/WebCore/dom/CanvasSurface.h_sec1
26
#ifndef CanvasSurface_h
26
#ifndef CanvasSurface_h
27
#define CanvasSurface_h
27
#define CanvasSurface_h
28
28
29
#include "AffineTransform.h"
30
#include "IntSize.h"
31
32
#include <wtf/OwnPtr.h>
29
#include <wtf/Noncopyable.h>
33
#include <wtf/Noncopyable.h>
30
34
31
namespace WebCore {
35
namespace WebCore {
32
36
37
class AffineTransform;
38
class FloatPoint;
39
class FloatRect;
40
class FloatSize;
41
class GraphicsContext;
42
class ImageBuffer;
43
class IntPoint;
44
class String;
45
46
typedef int ExceptionCode;
47
33
class CanvasSurface : public Noncopyable {
48
class CanvasSurface : public Noncopyable {
34
public:
49
public:
50
    CanvasSurface(float pageScaleFactor);
51
    virtual ~CanvasSurface();
52
53
    int width() const { return m_size.width(); }
54
    int height() const { return m_size.height(); }
55
56
    String toDataURL(const String& mimeType, ExceptionCode&);
57
58
    const IntSize& size() const { return m_size; }
59
60
    virtual void willDraw(const FloatRect&);
61
62
    GraphicsContext* drawingContext() const;
63
64
    ImageBuffer* buffer() const;
65
66
    IntRect convertLogicalToDevice(const FloatRect&) const;
67
    IntSize convertLogicalToDevice(const FloatSize&) const;
68
    IntPoint convertLogicalToDevice(const FloatPoint&) const;
69
70
    void setOriginTainted() { m_originClean = false; }
71
    bool originClean() const { return m_originClean; }
72
73
    AffineTransform baseTransform() const;
74
75
protected:
76
    void setSurfaceSize(const IntSize&);
77
    bool hasCreatedImageBuffer() const { return m_hasCreatedImageBuffer; }
78
79
    static const int DefaultWidth;
80
    static const int DefaultHeight;
35
81
36
private:
82
private:
83
    void createImageBuffer() const;
84
85
    static const float MaxCanvasArea;
86
87
    IntSize m_size;
88
89
    float m_pageScaleFactor;
90
    bool m_originClean;
91
92
    // m_createdImageBuffer means we tried to malloc the buffer.  We didn't necessarily get it.
93
    mutable bool m_hasCreatedImageBuffer;
94
    mutable OwnPtr<ImageBuffer> m_imageBuffer;
37
};
95
};
38
96
39
} // namespace WebCore
97
} // namespace WebCore
- a/WebCore/html/HTMLCanvasElement.cpp -118 / +19 lines
Lines 28-49 a/WebCore/html/HTMLCanvasElement.cpp_sec1
28
#include "HTMLCanvasElement.h"
28
#include "HTMLCanvasElement.h"
29
29
30
#include "CanvasContextAttributes.h"
30
#include "CanvasContextAttributes.h"
31
#include "CanvasGradient.h"
32
#include "CanvasPattern.h"
33
#include "CanvasRenderingContext2D.h"
31
#include "CanvasRenderingContext2D.h"
34
#if ENABLE(3D_CANVAS)    
32
#if ENABLE(3D_CANVAS)    
35
#include "WebGLContextAttributes.h"
33
#include "WebGLContextAttributes.h"
36
#include "WebGLRenderingContext.h"
34
#include "WebGLRenderingContext.h"
37
#endif
35
#endif
36
#include "CanvasGradient.h"
37
#include "CanvasPattern.h"
38
#include "CanvasStyle.h"
38
#include "CanvasStyle.h"
39
#include "Chrome.h"
39
#include "Chrome.h"
40
#include "Document.h"
40
#include "Document.h"
41
#include "ExceptionCode.h"
42
#include "Frame.h"
41
#include "Frame.h"
43
#include "GraphicsContext.h"
42
#include "GraphicsContext.h"
44
#include "HTMLNames.h"
43
#include "HTMLNames.h"
45
#include "ImageBuffer.h"
44
#include "ImageBuffer.h"
46
#include "MIMETypeRegistry.h"
47
#include "MappedAttribute.h"
45
#include "MappedAttribute.h"
48
#include "Page.h"
46
#include "Page.h"
49
#include "RenderHTMLCanvas.h"
47
#include "RenderHTMLCanvas.h"
Lines 55-76 namespace WebCore { a/WebCore/html/HTMLCanvasElement.cpp_sec2
55
53
56
using namespace HTMLNames;
54
using namespace HTMLNames;
57
55
58
// These values come from the WhatWG spec.
59
static const int defaultWidth = 300;
60
static const int defaultHeight = 150;
61
62
// Firefox limits width/height to 32767 pixels, but slows down dramatically before it 
63
// reaches that limit. We limit by area instead, giving us larger maximum dimensions,
64
// in exchange for a smaller maximum canvas size.
65
const float HTMLCanvasElement::MaxCanvasArea = 32768 * 8192; // Maximum canvas area in CSS pixels
66
67
HTMLCanvasElement::HTMLCanvasElement(const QualifiedName& tagName, Document* doc)
56
HTMLCanvasElement::HTMLCanvasElement(const QualifiedName& tagName, Document* doc)
68
    : HTMLElement(tagName, doc)
57
    : HTMLElement(tagName, doc)
69
    , m_size(defaultWidth, defaultHeight)
58
    , CanvasSurface(doc->frame() ? doc->frame()->page()->chrome()->scaleFactor() : 1)
70
    , m_observer(0)
59
    , m_observer(0)
71
    , m_originClean(true)
72
    , m_ignoreReset(false)
60
    , m_ignoreReset(false)
73
    , m_createdImageBuffer(false)
74
{
61
{
75
    ASSERT(hasTagName(canvasTag));
62
    ASSERT(hasTagName(canvasTag));
76
}
63
}
Lines 133-154 void HTMLCanvasElement::setWidth(int value) a/WebCore/html/HTMLCanvasElement.cpp_sec3
133
    setAttribute(widthAttr, String::number(value));
120
    setAttribute(widthAttr, String::number(value));
134
}
121
}
135
122
136
String HTMLCanvasElement::toDataURL(const String& mimeType, ExceptionCode& ec)
137
{
138
    if (!m_originClean) {
139
        ec = SECURITY_ERR;
140
        return String();
141
    }
142
143
    if (m_size.isEmpty() || !buffer())
144
        return String("data:,");
145
146
    if (mimeType.isNull() || !MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType))
147
        return buffer()->toDataURL("image/png");
148
149
    return buffer()->toDataURL(mimeType);
150
}
151
152
CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type, CanvasContextAttributes* attrs)
123
CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type, CanvasContextAttributes* attrs)
153
{
124
{
154
    // A Canvas can either be "2D" or "webgl" but never both. If you request a 2D canvas and the existing
125
    // A Canvas can either be "2D" or "webgl" but never both. If you request a 2D canvas and the existing
Lines 193-204 CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type, Canvas a/WebCore/html/HTMLCanvasElement.cpp_sec4
193
164
194
void HTMLCanvasElement::willDraw(const FloatRect& rect)
165
void HTMLCanvasElement::willDraw(const FloatRect& rect)
195
{
166
{
196
    if (m_imageBuffer)
167
    CanvasSurface::willDraw(rect);
197
        m_imageBuffer->clearImage();
168
198
    
199
    if (RenderBox* ro = renderBox()) {
169
    if (RenderBox* ro = renderBox()) {
200
        FloatRect destRect = ro->contentBoxRect();
170
        FloatRect destRect = ro->contentBoxRect();
201
        FloatRect r = mapRect(rect, FloatRect(0, 0, m_size.width(), m_size.height()), destRect);
171
        FloatRect r = mapRect(rect, FloatRect(0, 0, size().width(), size().height()), destRect);
202
        r.intersect(destRect);
172
        r.intersect(destRect);
203
        if (m_dirtyRect.contains(r))
173
        if (m_dirtyRect.contains(r))
204
            return;
174
            return;
Lines 219-246 void HTMLCanvasElement::reset() a/WebCore/html/HTMLCanvasElement.cpp_sec5
219
    bool ok;
189
    bool ok;
220
    int w = getAttribute(widthAttr).toInt(&ok);
190
    int w = getAttribute(widthAttr).toInt(&ok);
221
    if (!ok)
191
    if (!ok)
222
        w = defaultWidth;
192
        w = DefaultWidth;
223
    int h = getAttribute(heightAttr).toInt(&ok);
193
    int h = getAttribute(heightAttr).toInt(&ok);
224
    if (!ok)
194
    if (!ok)
225
        h = defaultHeight;
195
        h = DefaultHeight;
226
196
227
    IntSize oldSize = m_size;
197
    IntSize oldSize = size();
228
    m_size = IntSize(w, h);
198
    setSurfaceSize(IntSize(w, h));
229
199
230
#if ENABLE(3D_CANVAS)
200
#if ENABLE(3D_CANVAS)
231
    if (m_context && m_context->is3d())
201
    if (m_context && m_context->is3d())
232
        static_cast<WebGLRenderingContext*>(m_context.get())->reshape(width(), height());
202
        static_cast<WebGLRenderingContext*>(m_context.get())->reshape(width(), height());
233
#endif
203
#endif
234
204
235
    bool hadImageBuffer = m_createdImageBuffer;
205
    bool hadImageBuffer = hasCreatedImageBuffer();
236
    m_createdImageBuffer = false;
237
    m_imageBuffer.clear();
238
    if (m_context && m_context->is2d())
206
    if (m_context && m_context->is2d())
239
        static_cast<CanvasRenderingContext2D*>(m_context.get())->reset();
207
        static_cast<CanvasRenderingContext2D*>(m_context.get())->reset();
240
208
241
    if (RenderObject* renderer = this->renderer()) {
209
    if (RenderObject* renderer = this->renderer()) {
242
        if (m_rendererIsCanvas) {
210
        if (m_rendererIsCanvas) {
243
            if (oldSize != m_size)
211
            if (oldSize != size())
244
                toRenderHTMLCanvas(renderer)->canvasSizeChanged();
212
                toRenderHTMLCanvas(renderer)->canvasSizeChanged();
245
            if (hadImageBuffer)
213
            if (hadImageBuffer)
246
                renderer->repaint();
214
                renderer->repaint();
Lines 267-276 void HTMLCanvasElement::paint(GraphicsContext* context, const IntRect& r) a/WebCore/html/HTMLCanvasElement.cpp_sec6
267
    }
235
    }
268
#endif
236
#endif
269
237
270
    if (m_imageBuffer) {
238
    if (hasCreatedImageBuffer()) {
271
        Image* image = m_imageBuffer->image();
239
        ImageBuffer* imageBuffer = buffer();
272
        if (image)
240
        if (imageBuffer) {
273
            context->drawImage(image, DeviceColorSpace, r);
241
            Image* image = imageBuffer->image();
242
            if (image)
243
                context->drawImage(image, DeviceColorSpace, r);
244
        }
274
    }
245
    }
275
246
276
#if ENABLE(3D_CANVAS)
247
#if ENABLE(3D_CANVAS)
Lines 279-354 void HTMLCanvasElement::paint(GraphicsContext* context, const IntRect& r) a/WebCore/html/HTMLCanvasElement.cpp_sec7
279
#endif
250
#endif
280
}
251
}
281
252
282
IntRect HTMLCanvasElement::convertLogicalToDevice(const FloatRect& logicalRect) const
283
{
284
    return IntRect(convertLogicalToDevice(logicalRect.location()), convertLogicalToDevice(logicalRect.size()));
285
}
286
287
IntSize HTMLCanvasElement::convertLogicalToDevice(const FloatSize& logicalSize) const
288
{
289
    float pageScaleFactor = document()->frame() ? document()->frame()->page()->chrome()->scaleFactor() : 1.0f;
290
    float wf = ceilf(logicalSize.width() * pageScaleFactor);
291
    float hf = ceilf(logicalSize.height() * pageScaleFactor);
292
    
293
    if (!(wf >= 1 && hf >= 1 && wf * hf <= MaxCanvasArea))
294
        return IntSize();
295
296
    return IntSize(static_cast<unsigned>(wf), static_cast<unsigned>(hf));
297
}
298
299
IntPoint HTMLCanvasElement::convertLogicalToDevice(const FloatPoint& logicalPos) const
300
{
301
    float pageScaleFactor = document()->frame() ? document()->frame()->page()->chrome()->scaleFactor() : 1.0f;
302
    float xf = logicalPos.x() * pageScaleFactor;
303
    float yf = logicalPos.y() * pageScaleFactor;
304
    
305
    return IntPoint(static_cast<unsigned>(xf), static_cast<unsigned>(yf));
306
}
307
308
void HTMLCanvasElement::createImageBuffer() const
309
{
310
    ASSERT(!m_imageBuffer);
311
312
    m_createdImageBuffer = true;
313
    
314
    FloatSize unscaledSize(width(), height());
315
    IntSize size = convertLogicalToDevice(unscaledSize);
316
    if (!size.width() || !size.height())
317
        return;
318
319
    m_imageBuffer = ImageBuffer::create(size);
320
    // The convertLogicalToDevice MaxCanvasArea check should prevent common cases
321
    // where ImageBuffer::create() returns NULL, however we could still be low on memory.
322
    if (!m_imageBuffer)
323
        return;
324
    m_imageBuffer->context()->scale(FloatSize(size.width() / unscaledSize.width(), size.height() / unscaledSize.height()));
325
    m_imageBuffer->context()->setShadowsIgnoreTransforms(true);
326
}
327
328
GraphicsContext* HTMLCanvasElement::drawingContext() const
329
{
330
    return buffer() ? m_imageBuffer->context() : 0;
331
}
332
333
ImageBuffer* HTMLCanvasElement::buffer() const
334
{
335
    if (!m_createdImageBuffer)
336
        createImageBuffer();
337
    return m_imageBuffer.get();
338
}
339
    
340
AffineTransform HTMLCanvasElement::baseTransform() const
341
{
342
    ASSERT(m_createdImageBuffer);
343
    FloatSize unscaledSize(width(), height());
344
    IntSize size = convertLogicalToDevice(unscaledSize);
345
    AffineTransform transform;
346
    if (size.width() && size.height())
347
        transform.scaleNonUniform(size.width() / unscaledSize.width(), size.height() / unscaledSize.height());
348
    transform.multiply(m_imageBuffer->baseTransform());
349
    return transform;
350
}
351
352
#if ENABLE(3D_CANVAS)    
253
#if ENABLE(3D_CANVAS)    
353
bool HTMLCanvasElement::is3D() const
254
bool HTMLCanvasElement::is3D() const
354
{
255
{
- a/WebCore/html/HTMLCanvasElement.h -38 / +5 lines
Lines 27-33 a/WebCore/html/HTMLCanvasElement.h_sec1
27
#ifndef HTMLCanvasElement_h
27
#ifndef HTMLCanvasElement_h
28
#define HTMLCanvasElement_h
28
#define HTMLCanvasElement_h
29
29
30
#include "AffineTransform.h"
31
#include "CanvasSurface.h"
30
#include "CanvasSurface.h"
32
#include "FloatRect.h"
31
#include "FloatRect.h"
33
#include "HTMLElement.h"
32
#include "HTMLElement.h"
Lines 40-52 namespace WebCore { a/WebCore/html/HTMLCanvasElement.h_sec2
40
39
41
class CanvasContextAttributes;
40
class CanvasContextAttributes;
42
class CanvasRenderingContext;
41
class CanvasRenderingContext;
43
class FloatPoint;
44
class FloatRect;
45
class FloatSize;
46
class GraphicsContext;
42
class GraphicsContext;
47
class HTMLCanvasElement;
43
class HTMLCanvasElement;
48
class ImageBuffer;
49
class IntPoint;
50
class IntSize;
44
class IntSize;
51
45
52
class CanvasObserver {
46
class CanvasObserver {
Lines 63-108 public: a/WebCore/html/HTMLCanvasElement.h_sec3
63
    HTMLCanvasElement(const QualifiedName&, Document*);
57
    HTMLCanvasElement(const QualifiedName&, Document*);
64
    virtual ~HTMLCanvasElement();
58
    virtual ~HTMLCanvasElement();
65
59
66
    int width() const { return m_size.width(); }
67
    int height() const { return m_size.height(); }
68
    void setWidth(int);
60
    void setWidth(int);
69
    void setHeight(int);
61
    void setHeight(int);
70
62
71
    String toDataURL(const String& mimeType, ExceptionCode&);
72
73
    CanvasRenderingContext* getContext(const String&, CanvasContextAttributes* attributes = 0);
63
    CanvasRenderingContext* getContext(const String&, CanvasContextAttributes* attributes = 0);
74
64
75
    const IntSize& size() const { return m_size; }
65
    void setSize(const IntSize& newSize)
76
    void setSize(const IntSize& size)
77
    { 
66
    { 
78
        if (size == m_size)
67
        if (newSize == size())
79
            return;
68
            return;
80
        m_ignoreReset = true; 
69
        m_ignoreReset = true; 
81
        setWidth(size.width());
70
        setWidth(newSize.width());
82
        setHeight(size.height());
71
        setHeight(newSize.height());
83
        m_ignoreReset = false;
72
        m_ignoreReset = false;
84
        reset();
73
        reset();
85
    }
74
    }
86
75
87
    void willDraw(const FloatRect&);
76
    virtual void willDraw(const FloatRect&);
88
77
89
    void paint(GraphicsContext*, const IntRect&);
78
    void paint(GraphicsContext*, const IntRect&);
90
79
91
    GraphicsContext* drawingContext() const;
92
93
    ImageBuffer* buffer() const;
94
95
    IntRect convertLogicalToDevice(const FloatRect&) const;
96
    IntSize convertLogicalToDevice(const FloatSize&) const;
97
    IntPoint convertLogicalToDevice(const FloatPoint&) const;
98
99
    void setOriginTainted() { m_originClean = false; } 
100
    bool originClean() const { return m_originClean; }
101
102
    void setObserver(CanvasObserver* observer) { m_observer = observer; }
80
    void setObserver(CanvasObserver* observer) { m_observer = observer; }
103
81
104
    AffineTransform baseTransform() const;
105
106
    CanvasRenderingContext* renderingContext() const { return m_context.get(); }
82
    CanvasRenderingContext* renderingContext() const { return m_context.get(); }
107
83
108
#if ENABLE(3D_CANVAS)    
84
#if ENABLE(3D_CANVAS)    
Lines 118-141 private: a/WebCore/html/HTMLCanvasElement.h_sec4
118
    virtual void parseMappedAttribute(MappedAttribute*);
94
    virtual void parseMappedAttribute(MappedAttribute*);
119
    virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
95
    virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
120
96
121
    void createImageBuffer() const;
122
    void reset();
97
    void reset();
123
98
124
    static const float MaxCanvasArea;
125
126
    bool m_rendererIsCanvas;
99
    bool m_rendererIsCanvas;
127
100
128
    OwnPtr<CanvasRenderingContext> m_context;
101
    OwnPtr<CanvasRenderingContext> m_context;
129
    IntSize m_size;    
130
    CanvasObserver* m_observer;
102
    CanvasObserver* m_observer;
131
103
132
    bool m_originClean;
133
    bool m_ignoreReset;
104
    bool m_ignoreReset;
134
    FloatRect m_dirtyRect;
105
    FloatRect m_dirtyRect;
135
136
    // m_createdImageBuffer means we tried to malloc the buffer.  We didn't necessarily get it.
137
    mutable bool m_createdImageBuffer;
138
    mutable OwnPtr<ImageBuffer> m_imageBuffer;
139
};
106
};
140
107
141
} //namespace
108
} //namespace
- a/WebCore/platform/MIMETypeRegistry.cpp +2 lines
Lines 369-374 bool MIMETypeRegistry::isSupportedImageResourceMIMEType(const String& mimeType) a/WebCore/platform/MIMETypeRegistry.cpp_sec1
369
369
370
bool MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(const String& mimeType)
370
bool MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(const String& mimeType)
371
{
371
{
372
    ASSERT(isMainThread());
373
372
    if (mimeType.isEmpty())
374
    if (mimeType.isEmpty())
373
        return false;
375
        return false;
374
    if (!supportedImageMIMETypesForEncoding)
376
    if (!supportedImageMIMETypesForEncoding)
- a/WebCore/platform/graphics/Image.cpp +1 lines
Lines 53-58 Image::~Image() a/WebCore/platform/graphics/Image.cpp_sec1
53
53
54
Image* Image::nullImage()
54
Image* Image::nullImage()
55
{
55
{
56
    ASSERT(isMainThread());
56
    DEFINE_STATIC_LOCAL(RefPtr<Image>, nullImage, (BitmapImage::create()));;
57
    DEFINE_STATIC_LOCAL(RefPtr<Image>, nullImage, (BitmapImage::create()));;
57
    return nullImage.get();
58
    return nullImage.get();
58
}
59
}
- a/WebCore/platform/graphics/cg/ImageBufferCG.cpp +3 lines
Lines 38-43 a/WebCore/platform/graphics/cg/ImageBufferCG.cpp_sec1
38
#include <wtf/Assertions.h>
38
#include <wtf/Assertions.h>
39
#include <wtf/OwnArrayPtr.h>
39
#include <wtf/OwnArrayPtr.h>
40
#include <wtf/RetainPtr.h>
40
#include <wtf/RetainPtr.h>
41
#include <wtf/Threading.h>
41
#include <math.h>
42
#include <math.h>
42
43
43
using namespace std;
44
using namespace std;
Lines 254-259 static RetainPtr<CFStringRef> utiFromMIMEType(const String& mimeType) a/WebCore/platform/graphics/cg/ImageBufferCG.cpp_sec2
254
    RetainPtr<CFStringRef> mimeTypeCFString(AdoptCF, mimeType.createCFString());
255
    RetainPtr<CFStringRef> mimeTypeCFString(AdoptCF, mimeType.createCFString());
255
    return RetainPtr<CFStringRef>(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mimeTypeCFString.get(), 0));
256
    return RetainPtr<CFStringRef>(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mimeTypeCFString.get(), 0));
256
#else
257
#else
258
    ASSERT(isMainThread()); // It is unclear if CFSTR is threadsafe.
259
257
    // FIXME: Add Windows support for all the supported UTIs when a way to convert from MIMEType to UTI reliably is found.
260
    // FIXME: Add Windows support for all the supported UTIs when a way to convert from MIMEType to UTI reliably is found.
258
    // For now, only support PNG, JPEG, and GIF. See <rdar://problem/6095286>.
261
    // For now, only support PNG, JPEG, and GIF. See <rdar://problem/6095286>.
259
    static const CFStringRef kUTTypePNG = CFSTR("public.png");
262
    static const CFStringRef kUTTypePNG = CFSTR("public.png");

Return to Bug 35453