Changeset 73318 in webkit


Ignore:
Timestamp:
Dec 3, 2010 4:04:49 PM (13 years ago)
Author:
andersca@apple.com
Message:

Clean up the BackingStore implementation
https://bugs.webkit.org/show_bug.cgi?id=50498

Reviewed by Sam Weinig and Dan Bernstein.

  • Shared/BackingStore.cpp:

(WebKit::BackingStore::create):
(WebKit::BackingStore::createSharable):
(WebKit::BackingStore::resize):
Use new numBytesForSize helper function.

(WebKit::BackingStore::createFlippedGraphicsContext):
Make this function platform independent.

  • Shared/BackingStore.h:

(WebKit::BackingStore::numBytesForSize):
Given a size, return the number of bytes needed for it.

(WebKit::BackingStore::sizeInBytes):
Implement.

  • Shared/cg/BackingStoreCG.cpp:

(WebKit::BackingStore::paint):
Don't use CGBitmapContextCreateImage; it creates an extra copy of the image data.

  • Shared/qt/BackingStoreQt.cpp:

Remove createFlippedGraphicsContext.

Location:
trunk/WebKit2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit2/ChangeLog

    r73313 r73318  
     12010-12-03  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Sam Weinig and Dan Bernstein.
     4
     5        Clean up the BackingStore implementation
     6        https://bugs.webkit.org/show_bug.cgi?id=50498
     7
     8        * Shared/BackingStore.cpp:
     9        (WebKit::BackingStore::create):
     10        (WebKit::BackingStore::createSharable):
     11        (WebKit::BackingStore::resize):
     12        Use new numBytesForSize helper function.
     13
     14        (WebKit::BackingStore::createFlippedGraphicsContext):
     15        Make this function platform independent.
     16
     17        * Shared/BackingStore.h:
     18        (WebKit::BackingStore::numBytesForSize):
     19        Given a size, return the number of bytes needed for it.
     20
     21        (WebKit::BackingStore::sizeInBytes):
     22        Implement.
     23
     24        * Shared/cg/BackingStoreCG.cpp:
     25        (WebKit::BackingStore::paint):
     26        Don't use CGBitmapContextCreateImage; it creates an extra copy of the image data.
     27
     28        * Shared/qt/BackingStoreQt.cpp:
     29        Remove createFlippedGraphicsContext.
     30
    1312010-12-03  Siddharth Mathur  <siddharth.mathur@nokia.com>
    232
  • trunk/WebKit2/Shared/BackingStore.cpp

    r68351 r73318  
    2727
    2828#include "SharedMemory.h"
     29#include <WebCore/GraphicsContext.h>
    2930
    3031using namespace WebCore;
     
    3435PassRefPtr<BackingStore> BackingStore::create(const WebCore::IntSize& size)
    3536{
    36     size_t numBytes = size.width() * size.height() * 4;
     37    size_t numBytes = numBytesForSize(size);
    3738   
    3839    void* data = 0;
     
    4546PassRefPtr<BackingStore> BackingStore::createSharable(const IntSize& size)
    4647{
    47     size_t numBytes = size.width() * size.height() * 4;
     48    size_t numBytes = numBytesForSize(size);
    4849   
    4950    RefPtr<SharedMemory> sharedMemory = SharedMemory::create(numBytes);
     
    6162        return 0;
    6263
    63     size_t numBytes = size.width() * size.height() * 4;
     64    size_t numBytes = numBytesForSize(size);
    6465    ASSERT_UNUSED(numBytes, sharedMemory->size() >= numBytes);
    6566
     
    101102        return true;
    102103
    103     size_t newNumBytes = size.width() * size.height() * 4;
     104    size_t newNumBytes = numBytesForSize(size);
    104105   
    105106    // Try to resize.
     
    125126}
    126127
     128PassOwnPtr<GraphicsContext> BackingStore::createFlippedGraphicsContext()
     129{
     130    OwnPtr<GraphicsContext> graphicsContext = createGraphicsContext();
     131
     132    // Flip the coordinate system.
     133    graphicsContext->translate(0, m_size.height());
     134    graphicsContext->scale(FloatSize(1, -1));
     135
     136    return graphicsContext.release();
     137}
     138   
    127139} // namespace WebKit
  • trunk/WebKit2/Shared/BackingStore.h

    r71640 r73318  
    7373
    7474    bool isBackedBySharedMemory() const { return m_sharedMemory; }
     75    static size_t numBytesForSize(const WebCore::IntSize& size) { return size.width() * size.height() * 4; }
     76
    7577    void* data() const;
     78    size_t sizeInBytes() const { return numBytesForSize(m_size); }
    7679
    7780    WebCore::IntSize m_size;
  • trunk/WebKit2/Shared/cg/BackingStoreCG.cpp

    r73310 r73318  
    4646}
    4747
    48 PassOwnPtr<GraphicsContext> BackingStore::createFlippedGraphicsContext()
    49 {
    50     RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB());
    51     RetainPtr<CGContextRef> bitmapContext(AdoptCF, CGBitmapContextCreate(data(), m_size.width(), m_size.height(), 8,  m_size.width() * 4, colorSpace.get(),
    52                                                                          kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
    53 
    54     return adoptPtr(new GraphicsContext(bitmapContext.get()));
    55 }
    56 
    5748void BackingStore::paint(WebCore::GraphicsContext& context, const WebCore::IntPoint& dstPoint, const WebCore::IntRect& srcRect)
    5849{
    5950    OwnPtr<GraphicsContext> sourceContext(createGraphicsContext());
    6051
    61     // FIXME: This creates an extra copy.
    62     RetainPtr<CGImageRef> image(AdoptCF, CGBitmapContextCreateImage(sourceContext->platformContext()));
     52    CGContextRef sourceCGContext = sourceContext->platformContext();
     53
     54    RetainPtr<CGDataProviderRef> dataProvider(AdoptCF, CGDataProviderCreateWithData(0, data(), sizeInBytes(), 0));
     55    RetainPtr<CGImageRef> image(AdoptCF, CGImageCreate(CGBitmapContextGetWidth(sourceCGContext),
     56                                                       CGBitmapContextGetHeight(sourceCGContext),
     57                                                       CGBitmapContextGetBitsPerComponent(sourceCGContext),
     58                                                       CGBitmapContextGetBitsPerPixel(sourceCGContext),
     59                                                       CGBitmapContextGetBytesPerRow(sourceCGContext),
     60                                                       CGBitmapContextGetColorSpace(sourceCGContext),
     61                                                       CGBitmapContextGetBitmapInfo(sourceCGContext),
     62                                                       dataProvider.get(), 0, false, kCGRenderingIntentDefault));
    6363
    6464    CGContextRef cgContext = context.platformContext();
  • trunk/WebKit2/Shared/qt/BackingStoreQt.cpp

    r71821 r73318  
    4747}
    4848
    49 PassOwnPtr<GraphicsContext> BackingStore::createFlippedGraphicsContext()
    50 {
    51     // This is CG specific so we should not use it.
    52     ASSERT_NOT_REACHED();
    53     return 0;
    54 }
    55 
    5649void BackingStore::paint(GraphicsContext& context, const IntPoint& dstPoint, const IntRect& srcRect)
    5750{
Note: See TracChangeset for help on using the changeset viewer.