Changeset 82442 in webkit


Ignore:
Timestamp:
Mar 30, 2011 7:42:13 AM (13 years ago)
Author:
Adam Roben
Message:

Add a way to specify that a ShareableBitmap has no alpha channel

Before this patch, all ShareableBitmaps had an alpha channel. With this patch, all
ShareableBitmaps *still* have an alpha channel. But now there's a way to specify you don't
want one (which will be used in the future)!

Fixes <http://webkit.org/b/57388> Need a way to specify that a ShareableBitmap has no alpha
channel

Reviewed by Anders Carlsson.

  • Shared/ShareableBitmap.cpp:

(WebKit::ShareableBitmap::Handle::Handle): Moved here from the header file, and added
initialization of m_flags.

(WebKit::ShareableBitmap::Handle::encode):
(WebKit::ShareableBitmap::Handle::decode):
Encode/decode m_flags.

(WebKit::ShareableBitmap::create):
(WebKit::ShareableBitmap::createShareable):
Pass along the new Flags argument.

(WebKit::ShareableBitmap::createHandle): Store our Flags on the Handle.
(WebKit::ShareableBitmap::ShareableBitmap): Store the Flags in m_flags.

  • Shared/ShareableBitmap.h: Added Flag, Flags, and m_flags, and added a Flags argument to

some create functions.

  • Shared/WebCoreArgumentCoders.cpp:

(CoreIPC::encodeImage):

  • Shared/WebImage.cpp:

(WebKit::WebImage::create):
Specify that we want a bitmap that supports alpha to maintain current behavior.

  • Shared/cg/ShareableBitmapCG.cpp:

(WebKit::bitmapInfo): New helper function. Includes an alpha channel only if specified in
the flags.

(WebKit::ShareableBitmap::createGraphicsContext):
(WebKit::ShareableBitmap::makeCGImage):
Use the new helper function.

  • WebProcess/Plugins/Netscape/NetscapePlugin.cpp:

(WebKit::NetscapePlugin::snapshot):

  • WebProcess/Plugins/PluginProxy.cpp:

(WebKit::PluginProxy::geometryDidChange):

  • WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:

(WebKit::convertImageToBitmap):

  • WebProcess/WebCoreSupport/win/WebPopupMenuWin.cpp:

(WebKit::WebPopupMenu::setUpPlatformData):

  • WebProcess/WebPage/DrawingAreaImpl.cpp:

(WebKit::DrawingAreaImpl::display):

  • WebProcess/WebPage/FindController.cpp:

(WebKit::FindController::updateFindIndicator):
Specify that we want a bitmap that supports alpha to maintain current behavior.

Location:
trunk/Source/WebKit2
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r82441 r82442  
     12011-03-29  Adam Roben  <aroben@apple.com>
     2
     3        Add a way to specify that a ShareableBitmap has no alpha channel
     4
     5        Before this patch, all ShareableBitmaps had an alpha channel. With this patch, all
     6        ShareableBitmaps *still* have an alpha channel. But now there's a way to specify you don't
     7        want one (which will be used in the future)!
     8
     9        Fixes <http://webkit.org/b/57388> Need a way to specify that a ShareableBitmap has no alpha
     10        channel
     11
     12        Reviewed by Anders Carlsson.
     13
     14        * Shared/ShareableBitmap.cpp:
     15        (WebKit::ShareableBitmap::Handle::Handle): Moved here from the header file, and added
     16        initialization of m_flags.
     17
     18        (WebKit::ShareableBitmap::Handle::encode):
     19        (WebKit::ShareableBitmap::Handle::decode):
     20        Encode/decode m_flags.
     21
     22        (WebKit::ShareableBitmap::create):
     23        (WebKit::ShareableBitmap::createShareable):
     24        Pass along the new Flags argument.
     25
     26        (WebKit::ShareableBitmap::createHandle): Store our Flags on the Handle.
     27        (WebKit::ShareableBitmap::ShareableBitmap): Store the Flags in m_flags.
     28
     29        * Shared/ShareableBitmap.h: Added Flag, Flags, and m_flags, and added a Flags argument to
     30        some create functions.
     31
     32        * Shared/WebCoreArgumentCoders.cpp:
     33        (CoreIPC::encodeImage):
     34        * Shared/WebImage.cpp:
     35        (WebKit::WebImage::create):
     36        Specify that we want a bitmap that supports alpha to maintain current behavior.
     37
     38        * Shared/cg/ShareableBitmapCG.cpp:
     39        (WebKit::bitmapInfo): New helper function. Includes an alpha channel only if specified in
     40        the flags.
     41
     42        (WebKit::ShareableBitmap::createGraphicsContext):
     43        (WebKit::ShareableBitmap::makeCGImage):
     44        Use the new helper function.
     45
     46        * WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
     47        (WebKit::NetscapePlugin::snapshot):
     48        * WebProcess/Plugins/PluginProxy.cpp:
     49        (WebKit::PluginProxy::geometryDidChange):
     50        * WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
     51        (WebKit::convertImageToBitmap):
     52        * WebProcess/WebCoreSupport/win/WebPopupMenuWin.cpp:
     53        (WebKit::WebPopupMenu::setUpPlatformData):
     54        * WebProcess/WebPage/DrawingAreaImpl.cpp:
     55        (WebKit::DrawingAreaImpl::display):
     56        * WebProcess/WebPage/FindController.cpp:
     57        (WebKit::FindController::updateFindIndicator):
     58        Specify that we want a bitmap that supports alpha to maintain current behavior.
     59
    1602011-03-29  Adam Roben  <aroben@apple.com>
    261
  • trunk/Source/WebKit2/Shared/ShareableBitmap.cpp

    r82441 r82442  
    3535namespace WebKit {
    3636
     37ShareableBitmap::Handle::Handle()
     38    : m_flags(0)
     39{
     40}
     41
    3742void ShareableBitmap::Handle::encode(CoreIPC::ArgumentEncoder* encoder) const
    3843{
    3944    encoder->encode(m_handle);
    4045    encoder->encode(m_size);
     46    encoder->encode(m_flags);
    4147}
    4248
     
    4753    if (!decoder->decode(handle.m_size))
    4854        return false;
     55    if (!decoder->decode(handle.m_flags))
     56        return false;
    4957    return true;
    5058}
    5159
    52 PassRefPtr<ShareableBitmap> ShareableBitmap::create(const WebCore::IntSize& size)
     60PassRefPtr<ShareableBitmap> ShareableBitmap::create(const IntSize& size, Flags flags)
    5361{
    5462    size_t numBytes = numBytesForSize(size);
     
    5866        return 0;
    5967
    60     return adoptRef(new ShareableBitmap(size, data));
     68    return adoptRef(new ShareableBitmap(size, flags, data));
    6169}
    6270
    63 PassRefPtr<ShareableBitmap> ShareableBitmap::createShareable(const IntSize& size)
     71PassRefPtr<ShareableBitmap> ShareableBitmap::createShareable(const IntSize& size, Flags flags)
    6472{
    6573    size_t numBytes = numBytesForSize(size);
     
    6977        return 0;
    7078
    71     return adoptRef(new ShareableBitmap(size, sharedMemory));
     79    return adoptRef(new ShareableBitmap(size, flags, sharedMemory));
    7280}
    7381
    74 PassRefPtr<ShareableBitmap> ShareableBitmap::create(const WebCore::IntSize& size, PassRefPtr<SharedMemory> sharedMemory)
     82PassRefPtr<ShareableBitmap> ShareableBitmap::create(const IntSize& size, Flags flags, PassRefPtr<SharedMemory> sharedMemory)
    7583{
    7684    ASSERT(sharedMemory);
     
    7987    ASSERT_UNUSED(numBytes, sharedMemory->size() >= numBytes);
    8088   
    81     return adoptRef(new ShareableBitmap(size, sharedMemory));
     89    return adoptRef(new ShareableBitmap(size, flags, sharedMemory));
    8290}
    8391
     
    8997        return 0;
    9098
    91     return create(handle.m_size, sharedMemory.release());
     99    return create(handle.m_size, handle.m_flags, sharedMemory.release());
    92100}
    93101
     
    99107        return false;
    100108    handle.m_size = m_size;
     109    handle.m_flags = m_flags;
    101110    return true;
    102111}
    103112
    104 ShareableBitmap::ShareableBitmap(const IntSize& size, void* data)
     113ShareableBitmap::ShareableBitmap(const IntSize& size, Flags flags, void* data)
    105114    : m_size(size)
     115    , m_flags(flags)
    106116    , m_data(data)
    107117{
    108118}
    109119
    110 ShareableBitmap::ShareableBitmap(const IntSize& size, PassRefPtr<SharedMemory> sharedMemory)
     120ShareableBitmap::ShareableBitmap(const IntSize& size, Flags flags, PassRefPtr<SharedMemory> sharedMemory)
    111121    : m_size(size)
     122    , m_flags(flags)
    112123    , m_sharedMemory(sharedMemory)
    113124    , m_data(0)
  • trunk/Source/WebKit2/Shared/ShareableBitmap.h

    r82441 r82442  
    4646class ShareableBitmap : public RefCounted<ShareableBitmap> {
    4747public:
     48    enum Flag {
     49        SupportsAlpha = 1 << 0,
     50    };
     51    typedef unsigned Flags;
     52
    4853    class Handle {
    4954        WTF_MAKE_NONCOPYABLE(Handle);
    5055    public:
    51         Handle() { }
     56        Handle();
    5257
    5358        bool isNull() const { return m_handle.isNull(); }
     
    6166        mutable SharedMemory::Handle m_handle;
    6267        WebCore::IntSize m_size;
     68        Flags m_flags;
    6369    };
    6470
    6571    // Create a shareable bitmap that uses malloced memory.
    66     static PassRefPtr<ShareableBitmap> create(const WebCore::IntSize&);
     72    static PassRefPtr<ShareableBitmap> create(const WebCore::IntSize&, Flags);
    6773
    6874    // Create a shareable bitmap whose backing memory can be shared with another process.
    69     static PassRefPtr<ShareableBitmap> createShareable(const WebCore::IntSize&);
     75    static PassRefPtr<ShareableBitmap> createShareable(const WebCore::IntSize&, Flags);
    7076
    7177    // Create a shareable bitmap from an already existing shared memory block.
    72     static PassRefPtr<ShareableBitmap> create(const WebCore::IntSize&, PassRefPtr<SharedMemory>);
     78    static PassRefPtr<ShareableBitmap> create(const WebCore::IntSize&, Flags, PassRefPtr<SharedMemory>);
    7379
    7480    // Create a shareable bitmap from a handle.
     
    103109
    104110private:
    105     ShareableBitmap(const WebCore::IntSize&, void*);
    106     ShareableBitmap(const WebCore::IntSize&, PassRefPtr<SharedMemory>);
     111    ShareableBitmap(const WebCore::IntSize&, Flags, void*);
     112    ShareableBitmap(const WebCore::IntSize&, Flags, PassRefPtr<SharedMemory>);
    107113
    108114    static size_t numBytesForSize(const WebCore::IntSize& size) { return size.width() * size.height() * 4; }
     
    117123
    118124    WebCore::IntSize m_size;
     125    Flags m_flags;
    119126
    120127    // If the shareable bitmap is backed by shared memory, this points to the shared memory object.
  • trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp

    r82441 r82442  
    3838void encodeImage(ArgumentEncoder* encoder, Image* image)
    3939{
    40     RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(image->size());
     40    RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(image->size(), ShareableBitmap::SupportsAlpha);
    4141    bitmap->createGraphicsContext()->drawImage(image, ColorSpaceDeviceRGB, IntPoint());
    4242    ShareableBitmap::Handle handle;
  • trunk/Source/WebKit2/Shared/WebImage.cpp

    r76916 r82442  
    3636{
    3737    if (options & ImageOptionsShareable)
    38         return WebImage::create(ShareableBitmap::createShareable(size));
    39     return WebImage::create(ShareableBitmap::create(size));
     38        return WebImage::create(ShareableBitmap::createShareable(size, ShareableBitmap::SupportsAlpha));
     39    return WebImage::create(ShareableBitmap::create(size, ShareableBitmap::SupportsAlpha));
    4040}
    4141
  • trunk/Source/WebKit2/Shared/cg/ShareableBitmapCG.cpp

    r82151 r82442  
    3535namespace WebKit {
    3636
     37static CGBitmapInfo bitmapInfo(ShareableBitmap::Flags flags)
     38{
     39    CGBitmapInfo info = kCGBitmapByteOrder32Host;
     40    if (flags & ShareableBitmap::SupportsAlpha)
     41        info |= kCGImageAlphaPremultipliedFirst;
     42    else
     43        info |= kCGImageAlphaNoneSkipFirst;
     44
     45    return info;
     46}
     47
    3748PassOwnPtr<GraphicsContext> ShareableBitmap::createGraphicsContext()
    3849{
    3950    RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB());
    4051
     52
    4153    ref(); // Balanced by deref in releaseBitmapContextData.
    4254    RetainPtr<CGContextRef> bitmapContext(AdoptCF, CGBitmapContextCreateWithData(data(),
    4355        m_size.width(), m_size.height(), 8, m_size.width() * 4, colorSpace.get(),
    44         kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, releaseBitmapContextData, this));
     56        bitmapInfo(m_flags), releaseBitmapContextData, this));
    4557
    4658    // We want the origin to be in the top left corner so we flip the backing store context.
     
    6981
    7082    RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB());
    71     RetainPtr<CGImageRef> image(AdoptCF, CGImageCreate(m_size.width(), m_size.height(), 8, 32, m_size.width() * 4, colorSpace.get(), kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, dataProvider.get(), 0, false, kCGRenderingIntentDefault));
     83    RetainPtr<CGImageRef> image(AdoptCF, CGImageCreate(m_size.width(), m_size.height(), 8, 32, m_size.width() * 4, colorSpace.get(), bitmapInfo(m_flags), dataProvider.get(), 0, false, kCGRenderingIntentDefault));
    7284    return image;
    7385}
  • trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp

    r81705 r82442  
    514514    ASSERT(m_isStarted);
    515515   
    516     RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(m_frameRect.size());
     516    RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(m_frameRect.size(), ShareableBitmap::SupportsAlpha);
    517517    OwnPtr<GraphicsContext> context = bitmap->createGraphicsContext();
    518518
  • trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.cpp

    r82441 r82442  
    196196    if (didUpdateBackingStore) {
    197197        // Create a new plug-in backing store.
    198         m_pluginBackingStore = ShareableBitmap::createShareable(frameRect.size());
     198        m_pluginBackingStore = ShareableBitmap::createShareable(frameRect.size(), ShareableBitmap::SupportsAlpha);
    199199        if (!m_pluginBackingStore)
    200200            return;
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm

    r82441 r82442  
    7878static PassRefPtr<ShareableBitmap> convertImageToBitmap(NSImage *image)
    7979{
    80     RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(IntSize([image size]));
     80    RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(IntSize([image size]), ShareableBitmap::SupportsAlpha);
    8181    OwnPtr<GraphicsContext> graphicsContext = bitmap->createGraphicsContext();
    8282
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/win/WebPopupMenuWin.cpp

    r82441 r82442  
    8080
    8181    IntSize backingStoreSize(backingStoreWidth, (itemCount * data.m_itemHeight));
    82     data.m_notSelectedBackingStore = ShareableBitmap::createShareable(backingStoreSize);
    83     data.m_selectedBackingStore = ShareableBitmap::createShareable(backingStoreSize);
     82    data.m_notSelectedBackingStore = ShareableBitmap::createShareable(backingStoreSize, ShareableBitmap::SupportsAlpha);
     83    data.m_selectedBackingStore = ShareableBitmap::createShareable(backingStoreSize, ShareableBitmap::SupportsAlpha);
    8484
    8585    OwnPtr<GraphicsContext> notSelectedBackingStoreContext = data.m_notSelectedBackingStore->createGraphicsContext();
  • trunk/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.cpp

    r80917 r82442  
    516516    ASSERT(m_webPage->bounds().contains(bounds));
    517517
    518     RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(bounds.size());
     518    RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(bounds.size(), ShareableBitmap::SupportsAlpha);
    519519    if (!bitmap->createHandle(updateInfo.bitmapHandle))
    520520        return;
  • trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp

    r82441 r82442  
    166166
    167167    // Create a backing store and paint the find indicator text into it.
    168     RefPtr<ShareableBitmap> findIndicatorTextBackingStore = ShareableBitmap::createShareable(selectionRect.size());
     168    RefPtr<ShareableBitmap> findIndicatorTextBackingStore = ShareableBitmap::createShareable(selectionRect.size(), ShareableBitmap::SupportsAlpha);
    169169    if (!findIndicatorTextBackingStore)
    170170        return false;
Note: See TracChangeset for help on using the changeset viewer.