Changeset 98171 in webkit


Ignore:
Timestamp:
Oct 21, 2011 5:01:58 PM (13 years ago)
Author:
mdelaney@apple.com
Message:

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.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r98164 r98171  
     12011-10-21  Matthew Delaney  <mdelaney@apple.com>
     2
     3        Ensure periodic flushing of canvas drawing context
     4        https://bugs.webkit.org/show_bug.cgi?id=70646
     5
     6        Reviewed by Simon Fraser.
     7
     8        No new tests. No current way to track tests that cause hangs or
     9        non-deterministic drops in performance.
     10
     11        * platform/graphics/cg/ImageBufferDataCG.h: Adds a timestamp of last tracked flush.
     12        * platform/graphics/cg/ImageBufferCG.cpp: Ensures periodic flushes on the drawing context.
     13        (WebCore::ImageBuffer::ImageBuffer):
     14        (WebCore::ImageBuffer::context): Flushes context if we're beyond flush interval.
     15        (WebCore::ImageBuffer::copyNativeImage): Updates last flush timestamp.
     16        (WebCore::ImageBuffer::getUnmultipliedImageData): Updates last flush timestamp.
     17        (WebCore::ImageBuffer::getPremultipliedImageData): Updates last flush timestamp.
     18        (WebCore::ImageBuffer::putUnmultipliedImageData): Updates last flush timestamp.
     19        (WebCore::ImageBuffer::putPremultipliedImageData): Updates last flush timestamp.
     20
    1212011-10-21  Adam Barth  <abarth@webkit.org>
    222
  • trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp

    r97946 r98171  
    3939#include <wtf/Assertions.h>
    4040#include <wtf/CheckedArithmetic.h>
     41#include <wtf/CurrentTime.h>
    4142#include <wtf/MainThread.h>
    4243#include <wtf/OwnArrayPtr.h>
     
    165166        return;
    166167
    167     m_context= adoptPtr(new GraphicsContext(cgContext.get()));
     168    m_context = adoptPtr(new GraphicsContext(cgContext.get()));
    168169    m_context->scale(FloatSize(1, -1));
    169170    m_context->translate(0, -height.unsafeGet());
    170171    m_context->setIsAcceleratedContext(accelerateRendering);
     172    m_data.m_lastFlushTime = currentTimeMS();
    171173    success = true;
    172174}
     
    183185GraphicsContext* ImageBuffer::context() const
    184186{
     187    // Force a flush if last flush was more than 20ms ago
     188    if (m_context->isAcceleratedContext()) {
     189        double elapsedTime = currentTimeMS() - m_data.m_lastFlushTime;
     190        double maxFlushInterval = 20; // in ms
     191
     192        if (elapsedTime > maxFlushInterval) {
     193            CGContextRef context = m_context->platformContext();
     194            CGContextFlush(context);
     195            m_data.m_lastFlushTime = currentTimeMS();
     196        }
     197    }
     198
    185199    return m_context.get();
    186200}
     
    213227    }
    214228#if USE(IOSURFACE_CANVAS_BACKING_STORE)
    215     else
     229    else {
    216230        image = wkIOSurfaceContextCreateImage(context()->platformContext());
     231        m_data.m_lastFlushTime = currentTimeMS();
     232    }
    217233#endif
    218234
     
    263279PassRefPtr<ByteArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect) const
    264280{
    265     if (m_context->isAcceleratedContext())
     281    if (m_context->isAcceleratedContext()) {
    266282        CGContextFlush(context()->platformContext());
     283        m_data.m_lastFlushTime = currentTimeMS();
     284    }
    267285    return m_data.getData(rect, m_size, m_context->isAcceleratedContext(), true);
    268286}
     
    270288PassRefPtr<ByteArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect) const
    271289{
    272     if (m_context->isAcceleratedContext())
     290    if (m_context->isAcceleratedContext()) {
    273291        CGContextFlush(context()->platformContext());
     292        m_data.m_lastFlushTime = currentTimeMS();
     293    }
    274294    return m_data.getData(rect, m_size, m_context->isAcceleratedContext(), false);
    275295}
     
    277297void ImageBuffer::putUnmultipliedImageData(ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint)
    278298{
    279     if (m_context->isAcceleratedContext())
     299    if (m_context->isAcceleratedContext()) {
    280300        CGContextFlush(context()->platformContext());
     301        m_data.m_lastFlushTime = currentTimeMS();
     302    }
    281303    m_data.putData(source, sourceSize, sourceRect, destPoint, m_size, m_context->isAcceleratedContext(), true);
    282304}
     
    284306void ImageBuffer::putPremultipliedImageData(ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint)
    285307{
    286     if (m_context->isAcceleratedContext())
     308    if (m_context->isAcceleratedContext()) {
    287309        CGContextFlush(context()->platformContext());
     310        m_data.m_lastFlushTime = currentTimeMS();
     311    }
    288312    m_data.putData(source, sourceSize, sourceRect, destPoint, m_size, m_context->isAcceleratedContext(), false);
    289313}
  • trunk/Source/WebCore/platform/graphics/cg/ImageBufferDataCG.h

    r95901 r98171  
    5555    CGColorSpaceRef m_colorSpace;
    5656    RetainPtr<IOSurfaceRef> m_surface;
     57    mutable double m_lastFlushTime;
    5758
    5859    PassRefPtr<ByteArray> getData(const IntRect& rect, const IntSize& size, bool accelerateRendering, bool unmultiplied) const;
Note: See TracChangeset for help on using the changeset viewer.