Modified: trunk/Source/WebCore/ChangeLog (98170 => 98171)
--- trunk/Source/WebCore/ChangeLog 2011-10-21 23:54:04 UTC (rev 98170)
+++ trunk/Source/WebCore/ChangeLog 2011-10-22 00:01:58 UTC (rev 98171)
@@ -1,3 +1,23 @@
+2011-10-21 Matthew Delaney <mdela...@apple.com>
+
+ Ensure periodic flushing of canvas drawing context
+ https://bugs.webkit.org/show_bug.cgi?id=70646
+
+ Reviewed by Simon Fraser.
+
+ No new tests. No current way to track tests that cause hangs or
+ non-deterministic drops in performance.
+
+ * platform/graphics/cg/ImageBufferDataCG.h: Adds a timestamp of last tracked flush.
+ * platform/graphics/cg/ImageBufferCG.cpp: Ensures periodic flushes on the drawing context.
+ (WebCore::ImageBuffer::ImageBuffer):
+ (WebCore::ImageBuffer::context): Flushes context if we're beyond flush interval.
+ (WebCore::ImageBuffer::copyNativeImage): Updates last flush timestamp.
+ (WebCore::ImageBuffer::getUnmultipliedImageData): Updates last flush timestamp.
+ (WebCore::ImageBuffer::getPremultipliedImageData): Updates last flush timestamp.
+ (WebCore::ImageBuffer::putUnmultipliedImageData): Updates last flush timestamp.
+ (WebCore::ImageBuffer::putPremultipliedImageData): Updates last flush timestamp.
+
2011-10-21 Adam Barth <aba...@webkit.org>
Introduce Event::hasInterface to make uses of interfaceName more readable
Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp (98170 => 98171)
--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp 2011-10-21 23:54:04 UTC (rev 98170)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp 2011-10-22 00:01:58 UTC (rev 98171)
@@ -38,6 +38,7 @@
#include <math.h>
#include <wtf/Assertions.h>
#include <wtf/CheckedArithmetic.h>
+#include <wtf/CurrentTime.h>
#include <wtf/MainThread.h>
#include <wtf/OwnArrayPtr.h>
#include <wtf/RetainPtr.h>
@@ -164,10 +165,11 @@
if (!cgContext)
return;
- m_context= adoptPtr(new GraphicsContext(cgContext.get()));
+ m_context = adoptPtr(new GraphicsContext(cgContext.get()));
m_context->scale(FloatSize(1, -1));
m_context->translate(0, -height.unsafeGet());
m_context->setIsAcceleratedContext(accelerateRendering);
+ m_data.m_lastFlushTime = currentTimeMS();
success = true;
}
@@ -182,6 +184,18 @@
GraphicsContext* ImageBuffer::context() const
{
+ // Force a flush if last flush was more than 20ms ago
+ if (m_context->isAcceleratedContext()) {
+ double elapsedTime = currentTimeMS() - m_data.m_lastFlushTime;
+ double maxFlushInterval = 20; // in ms
+
+ if (elapsedTime > maxFlushInterval) {
+ CGContextRef context = m_context->platformContext();
+ CGContextFlush(context);
+ m_data.m_lastFlushTime = currentTimeMS();
+ }
+ }
+
return m_context.get();
}
@@ -212,8 +226,10 @@
}
}
#if USE(IOSURFACE_CANVAS_BACKING_STORE)
- else
+ else {
image = wkIOSurfaceContextCreateImage(context()->platformContext());
+ m_data.m_lastFlushTime = currentTimeMS();
+ }
#endif
return image;
@@ -262,29 +278,37 @@
PassRefPtr<ByteArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect) const
{
- if (m_context->isAcceleratedContext())
+ if (m_context->isAcceleratedContext()) {
CGContextFlush(context()->platformContext());
+ m_data.m_lastFlushTime = currentTimeMS();
+ }
return m_data.getData(rect, m_size, m_context->isAcceleratedContext(), true);
}
PassRefPtr<ByteArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect) const
{
- if (m_context->isAcceleratedContext())
+ if (m_context->isAcceleratedContext()) {
CGContextFlush(context()->platformContext());
+ m_data.m_lastFlushTime = currentTimeMS();
+ }
return m_data.getData(rect, m_size, m_context->isAcceleratedContext(), false);
}
void ImageBuffer::putUnmultipliedImageData(ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint)
{
- if (m_context->isAcceleratedContext())
+ if (m_context->isAcceleratedContext()) {
CGContextFlush(context()->platformContext());
+ m_data.m_lastFlushTime = currentTimeMS();
+ }
m_data.putData(source, sourceSize, sourceRect, destPoint, m_size, m_context->isAcceleratedContext(), true);
}
void ImageBuffer::putPremultipliedImageData(ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint)
{
- if (m_context->isAcceleratedContext())
+ if (m_context->isAcceleratedContext()) {
CGContextFlush(context()->platformContext());
+ m_data.m_lastFlushTime = currentTimeMS();
+ }
m_data.putData(source, sourceSize, sourceRect, destPoint, m_size, m_context->isAcceleratedContext(), false);
}
Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferDataCG.h (98170 => 98171)
--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferDataCG.h 2011-10-21 23:54:04 UTC (rev 98170)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferDataCG.h 2011-10-22 00:01:58 UTC (rev 98171)
@@ -54,6 +54,7 @@
Checked<unsigned, RecordOverflow> m_bytesPerRow;
CGColorSpaceRef m_colorSpace;
RetainPtr<IOSurfaceRef> m_surface;
+ mutable double m_lastFlushTime;
PassRefPtr<ByteArray> getData(const IntRect& rect, const IntSize& size, bool accelerateRendering, bool unmultiplied) const;
void putData(ByteArray*& source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, const IntSize& size, bool accelerateRendering, bool unmultiplied);