Changeset 128755 in webkit


Ignore:
Timestamp:
Sep 17, 2012 7:57:36 AM (12 years ago)
Author:
jpetsovits@rim.com
Message:

[BlackBerry] Support copying image data in WebOverlay.
https://bugs.webkit.org/show_bug.cgi?id=96684
RIM PR 195444

Reviewed by Rob Buis.
Internally reviewed by Arvid Nilsson.

The publicly exposed WebOverlay class provides a method
setContentsToImage() to assign a pointer to pixel data,
which is later used to provide texture data for the
underlying compositing layer. This works well for static
images that stay in memory and never change, but not
so well for images with changing contents or where the
image data is being reassigned from different image
sources that are not constantly kept around in memory.

Due to the delayed upload and delayed fetching of
EGLImage data by the GPU, we shouldn't assume the caller
to know how long the image should be retained. Instead,
we should offer another method of setting image data
that takes ownership of the pixel data.

This patch adds an option to setContentsToImage() that
copies the passed pixel data and doesn't destroy it
until both the texture is destroyed and the image
contents are changed. Using this method, the caller can
withdraw the passed pixel array right after the
setContentsToImage() call without consequences.

  • Api/WebOverlay.cpp:

(BlackBerry::WebKit::WebOverlay::setContentsToImage):
(BlackBerry::WebKit::WebOverlayPrivateWebKitThread::setContentsToImage):
(BlackBerry::WebKit::WebOverlayLayerCompositingThreadClient::WebOverlayLayerCompositingThreadClient):
(BlackBerry::WebKit::WebOverlayLayerCompositingThreadClient::invalidate):
(BlackBerry::WebKit::WebOverlayLayerCompositingThreadClient::setContents):
(WebKit):
(BlackBerry::WebKit::WebOverlayLayerCompositingThreadClient::clearUploadedContents):
(BlackBerry::WebKit::WebOverlayLayerCompositingThreadClient::setContentsToColor):
(BlackBerry::WebKit::WebOverlayLayerCompositingThreadClient::uploadTexturesIfNeeded):
(BlackBerry::WebKit::WebOverlayLayerCompositingThreadClient::deleteTextures):
(BlackBerry::WebKit::WebOverlayPrivateCompositingThread::setContentsToImage):

  • Api/WebOverlay.h:
  • Api/WebOverlay_p.h:

(WebOverlayPrivate):
(WebOverlayPrivateWebKitThread):
(WebOverlayLayerCompositingThreadClient):
(WebOverlayPrivateCompositingThread):

Location:
trunk/Source/WebKit/blackberry
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/blackberry/Api/WebOverlay.cpp

    r125381 r128755  
    164164}
    165165
    166 void WebOverlay::setContentsToImage(const unsigned char* data, const Platform::IntSize& imageSize)
    167 {
    168     d->setContentsToImage(data, imageSize);
     166void WebOverlay::setContentsToImage(const unsigned char* data, const Platform::IntSize& imageSize, ImageDataAdoptionType adoptionType)
     167{
     168    d->setContentsToImage(data, imageSize, adoptionType);
    169169}
    170170
     
    330330}
    331331
    332 void WebOverlayPrivateWebKitThread::setContentsToImage(const unsigned char* data, const WebCore::IntSize& imageSize)
     332void WebOverlayPrivateWebKitThread::setContentsToImage(const unsigned char* data, const WebCore::IntSize& imageSize, WebOverlay::ImageDataAdoptionType adoptionType)
    333333{
    334334    notImplemented();
     
    391391{
    392392    m_texture.clear();
     393    clearUploadedContents();
    393394}
    394395
     
    398399    m_color = Color();
    399400    m_texture.clear();
     401    clearUploadedContents();
     402}
     403
     404void WebOverlayLayerCompositingThreadClient::clearUploadedContents()
     405{
     406    m_uploadedContents = SkBitmap();
    400407}
    401408
     
    405412    m_color = color;
    406413    m_texture.clear();
     414    clearUploadedContents();
    407415}
    408416
     
    447455    m_texture->protect(IntSize(m_contents.width(), m_contents.height()));
    448456    IntRect bitmapRect(0, 0, m_contents.width(), m_contents.height());
    449     m_texture->updateContents(m_contents, bitmapRect, bitmapRect, false);
     457    m_uploadedContents = m_contents;
     458    m_texture->updateContents(m_uploadedContents, bitmapRect, bitmapRect, false);
    450459}
    451460
     
    465474{
    466475    m_texture.clear();
     476    clearUploadedContents();
    467477}
    468478
     
    595605}
    596606
    597 void WebOverlayPrivateCompositingThread::setContentsToImage(const unsigned char* data, const IntSize& imageSize)
     607void WebOverlayPrivateCompositingThread::setContentsToImage(const unsigned char* data, const IntSize& imageSize, WebOverlay::ImageDataAdoptionType adoptionType)
    598608{
    599609    if (!m_layerCompositingThreadClient)
     
    609619    SkBitmap contents;
    610620    contents.setConfig(SkBitmap::kARGB_8888_Config, imageSize.width(), imageSize.height());
    611     contents.setPixels(const_cast<unsigned char*>(data));
     621
     622    switch (adoptionType) {
     623    case WebOverlay::ReferenceImageData:
     624        contents.setPixels(const_cast<unsigned char*>(data));
     625        break;
     626    case WebOverlay::CopyImageData:
     627        if (contents.allocPixels()) {
     628            contents.lockPixels();
     629            size_t bytes = SkBitmap::ComputeSize(SkBitmap::kARGB_8888_Config, imageSize.width(), imageSize.height());
     630            memcpy(contents.getPixels(), data, bytes);
     631            contents.unlockPixels();
     632        }
     633        break;
     634    default:
     635        ASSERT_NOT_REACHED();
     636    }
    612637
    613638    m_layerCompositingThreadClient->setContents(contents);
     
    734759}
    735760
    736 void WebOverlay::setContentsToImage(const unsigned char*, const Platform::IntSize&)
     761void WebOverlay::setContentsToImage(const unsigned char*, const Platform::IntSize&, ImageDataAdoptionType)
    737762{
    738763}
  • trunk/Source/WebKit/blackberry/Api/WebOverlay.h

    r118750 r128755  
    5656class BLACKBERRY_EXPORT WebOverlay {
    5757public:
     58    enum ImageDataAdoptionType {
     59        ReferenceImageData,
     60        CopyImageData
     61    };
     62
    5863    WebOverlay();
    5964    WebOverlay(WebCore::GraphicsLayerClient*);
     
    95100    void removeFromParent();
    96101
    97     void setContentsToImage(const unsigned char* data, const Platform::IntSize& imageSize);
     102    void setContentsToImage(const unsigned char* data, const Platform::IntSize& imageSize, ImageDataAdoptionType = ReferenceImageData);
    98103    void setContentsToColor(int r, int g, int b, int a);
    99104    void setDrawsContent(bool);
  • trunk/Source/WebKit/blackberry/Api/WebOverlay_p.h

    r125381 r128755  
    2525#include "LayerCompositingThread.h"
    2626#include "Texture.h"
     27#include "WebOverlay.h"
    2728#include "WebOverlayOverride.h"
    2829
     
    4647namespace WebKit {
    4748
    48 class WebOverlay;
    4949class WebOverlayClient;
    5050class WebPagePrivate;
     
    9696    virtual void removeFromParent() = 0;
    9797
    98     virtual void setContentsToImage(const unsigned char* data, const WebCore::IntSize& imageSize) = 0;
     98    virtual void setContentsToImage(const unsigned char* data, const WebCore::IntSize& imageSize, WebOverlay::ImageDataAdoptionType) = 0;
    9999    virtual void setContentsToColor(const WebCore::Color&) = 0;
    100100    virtual void setDrawsContent(bool) = 0;
     
    153153    virtual void removeFromParent();
    154154
    155     virtual void setContentsToImage(const unsigned char* data, const WebCore::IntSize& imageSize);
     155    virtual void setContentsToImage(const unsigned char* data, const WebCore::IntSize& imageSize, WebOverlay::ImageDataAdoptionType);
    156156    virtual void setContentsToColor(const WebCore::Color&);
    157157    virtual void setDrawsContent(bool);
     
    203203
    204204private:
     205    void clearUploadedContents();
     206
     207private:
    205208    RefPtr<WebCore::Texture> m_texture;
    206209    bool m_drawsContent;
    207210    SkBitmap m_contents;
     211    SkBitmap m_uploadedContents;
    208212    WebCore::Color m_color;
    209213    WebCore::LayerCompositingThread* m_layerCompositingThread;
     
    244248    virtual void removeFromParent();
    245249
    246     virtual void setContentsToImage(const unsigned char* data, const WebCore::IntSize& imageSize);
     250    virtual void setContentsToImage(const unsigned char* data, const WebCore::IntSize& imageSize, WebOverlay::ImageDataAdoptionType);
    247251    virtual void setContentsToColor(const WebCore::Color&);
    248252    virtual void setDrawsContent(bool);
  • trunk/Source/WebKit/blackberry/ChangeLog

    r128650 r128755  
     12012-09-17  Jakob Petsovits  <jpetsovits@rim.com>
     2
     3        [BlackBerry] Support copying image data in WebOverlay.
     4        https://bugs.webkit.org/show_bug.cgi?id=96684
     5        RIM PR 195444
     6
     7        Reviewed by Rob Buis.
     8        Internally reviewed by Arvid Nilsson.
     9
     10        The publicly exposed WebOverlay class provides a method
     11        setContentsToImage() to assign a pointer to pixel data,
     12        which is later used to provide texture data for the
     13        underlying compositing layer. This works well for static
     14        images that stay in memory and never change, but not
     15        so well for images with changing contents or where the
     16        image data is being reassigned from different image
     17        sources that are not constantly kept around in memory.
     18
     19        Due to the delayed upload and delayed fetching of
     20        EGLImage data by the GPU, we shouldn't assume the caller
     21        to know how long the image should be retained. Instead,
     22        we should offer another method of setting image data
     23        that takes ownership of the pixel data.
     24
     25        This patch adds an option to setContentsToImage() that
     26        copies the passed pixel data and doesn't destroy it
     27        until both the texture is destroyed and the image
     28        contents are changed. Using this method, the caller can
     29        withdraw the passed pixel array right after the
     30        setContentsToImage() call without consequences.
     31
     32        * Api/WebOverlay.cpp:
     33        (BlackBerry::WebKit::WebOverlay::setContentsToImage):
     34        (BlackBerry::WebKit::WebOverlayPrivateWebKitThread::setContentsToImage):
     35        (BlackBerry::WebKit::WebOverlayLayerCompositingThreadClient::WebOverlayLayerCompositingThreadClient):
     36        (BlackBerry::WebKit::WebOverlayLayerCompositingThreadClient::invalidate):
     37        (BlackBerry::WebKit::WebOverlayLayerCompositingThreadClient::setContents):
     38        (WebKit):
     39        (BlackBerry::WebKit::WebOverlayLayerCompositingThreadClient::clearUploadedContents):
     40        (BlackBerry::WebKit::WebOverlayLayerCompositingThreadClient::setContentsToColor):
     41        (BlackBerry::WebKit::WebOverlayLayerCompositingThreadClient::uploadTexturesIfNeeded):
     42        (BlackBerry::WebKit::WebOverlayLayerCompositingThreadClient::deleteTextures):
     43        (BlackBerry::WebKit::WebOverlayPrivateCompositingThread::setContentsToImage):
     44        * Api/WebOverlay.h:
     45        * Api/WebOverlay_p.h:
     46        (WebOverlayPrivate):
     47        (WebOverlayPrivateWebKitThread):
     48        (WebOverlayLayerCompositingThreadClient):
     49        (WebOverlayPrivateCompositingThread):
     50
    1512012-09-14  Dana Jansens  <danakj@chromium.org>
    252
Note: See TracChangeset for help on using the changeset viewer.