<rdar://problem/5974306> CanvasRenderingContext2D becomes invalid when source canvas...
[WebKit-https.git] / WebCore / html / CanvasRenderingContext2D.cpp
index 62b6805..fd17e19 100644 (file)
@@ -74,6 +74,16 @@ CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas)
 {
 }
 
+void CanvasRenderingContext2D::ref()
+{
+m_canvas->ref();
+}
+
+void CanvasRenderingContext2D::deref()
+{
+    m_canvas->deref(); 
+}
+
 void CanvasRenderingContext2D::reset()
 {
     m_stateStack.resize(1);
@@ -520,10 +530,9 @@ void CanvasRenderingContext2D::rect(float x, float y, float width, float height)
 #if ENABLE(DASHBOARD_SUPPORT)
 void CanvasRenderingContext2D::clearPathForDashboardBackwardCompatibilityMode()
 {
-    if (m_canvas)
-        if (Settings* settings = m_canvas->document()->settings())
-            if (settings->usesDashboardBackwardCompatibilityMode())
-                m_path.clear();
+    if (Settings* settings = m_canvas->document()->settings())
+        if (settings->usesDashboardBackwardCompatibilityMode())
+            m_path.clear();
 }
 #endif
 
@@ -1151,8 +1160,6 @@ PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLCanvasElem
 
 void CanvasRenderingContext2D::willDraw(const FloatRect& r)
 {
-    if (!m_canvas)
-        return;
     GraphicsContext* c = drawingContext();
     if (!c)
         return;
@@ -1162,8 +1169,6 @@ void CanvasRenderingContext2D::willDraw(const FloatRect& r)
 
 GraphicsContext* CanvasRenderingContext2D::drawingContext() const
 {
-    if (!m_canvas)
-        return 0;
     return m_canvas->drawingContext();
 }
 
@@ -1279,11 +1284,7 @@ static PassRefPtr<ImageData> createEmptyImageData(const IntSize& size)
 PassRefPtr<ImageData> CanvasRenderingContext2D::createImageData(float sw, float sh) const
 {
     FloatSize unscaledSize(sw, sh);
-    IntSize scaledSize;
-    if (m_canvas)
-        scaledSize = m_canvas->convertLogicalToDevice(unscaledSize);
-    else
-        scaledSize = IntSize(ceilf(sw), ceilf(sh));
+    IntSize scaledSize = m_canvas->convertLogicalToDevice(unscaledSize);
     if (scaledSize.width() < 1)
         scaledSize.setWidth(1);
     if (scaledSize.height() < 1)
@@ -1300,7 +1301,7 @@ PassRefPtr<ImageData> CanvasRenderingContext2D::getImageData(float sx, float sy,
     }
     
     FloatRect unscaledRect(sx, sy, sw, sh);
-    IntRect scaledRect = m_canvas ? m_canvas->convertLogicalToDevice(unscaledRect) : enclosingIntRect(unscaledRect);
+    IntRect scaledRect = m_canvas->convertLogicalToDevice(unscaledRect);
     if (scaledRect.width() < 1)
         scaledRect.setWidth(1);
     if (scaledRect.height() < 1)
@@ -1333,7 +1334,7 @@ void CanvasRenderingContext2D::putImageData(ImageData* data, float dx, float dy,
         return;
     }
 
-    ImageBuffer* buffer = m_canvas ? m_canvas->buffer() : 0;
+    ImageBuffer* buffer = m_canvas->buffer();
     if (!buffer)
         return;