Reuse buffer allocation if canvas size does not change
[WebKit-https.git] / Source / WebCore / html / canvas / CanvasRenderingContext2D.cpp
index 279b2a1c309275a8499cd2dd8ac29153316b51b2..eca54192b3827e9bcd99b69204a275a9691fc039 100644 (file)
@@ -124,6 +124,8 @@ CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, bo
 #if !ENABLE(DASHBOARD_SUPPORT)
     ASSERT_UNUSED(usesDashboardCompatibilityMode, !usesDashboardCompatibilityMode);
 #endif
+    if (GraphicsContext* context = canvas->drawingContext())
+        context->save();
 }
 
 void CanvasRenderingContext2D::unwindStateStack()
@@ -133,7 +135,7 @@ void CanvasRenderingContext2D::unwindStateStack()
     // GraphicsContext dtor.
     if (size_t stackSize = m_stateStack.size()) {
         if (GraphicsContext* context = canvas()->existingDrawingContext()) {
-            while (--stackSize)
+            while (stackSize--)
                 context->restore();
         }
     }
@@ -161,11 +163,8 @@ void CanvasRenderingContext2D::reset()
     m_stateStack.resize(1);
     m_stateStack.first() = State();
     m_path.clear();
-#if USE(ACCELERATED_COMPOSITING)
-    RenderBox* renderBox = canvas()->renderBox();
-    if (renderBox && renderBox->hasLayer() && renderBox->layer()->hasAcceleratedCompositing())
-        renderBox->layer()->contentChanged(RenderLayer::CanvasChanged);
-#endif
+    if (GraphicsContext* context = canvas()->drawingContext())
+        context->save();
 }
 
 CanvasRenderingContext2D::State::State()