Changeset 106620 in webkit


Ignore:
Timestamp:
Feb 2, 2012 8:00:29 PM (12 years ago)
Author:
noam.rosenthal@nokia.com
Message:

[Qt][Texmap] Refactor TextureMapper API to use ImageBuffers when possible.
https://bugs.webkit.org/show_bug.cgi?id=77148

Reviewed by Martin Robinson.

Source/WebCore:

Removed TextureMapperQt, and instead created a TextureMapperImageBuffer class,
which responds to an "Software" mode of TextureMapper, instead of creating subclasses
of TextureMapper directly. This allows using the software fallback of TextureMapper by any
sort.

To make the ImageBuffer backend easier, content updates to BitmapTexture can now use either
an image, or a raw data pointer. The raw data pointer is provided for performance reasons,
as converting data to/from Image references in Qt generates unnecessary deep copies of the
image data.

Also, functions that use TransformationMatrix were added to GraphicsContext, to allow for
3D transforms in cross platform code.
After this patch everything renders the same. An additional bug report was created to allow
ImageBuffer shallow image copies: https://bugs.webkit.org/show_bug.cgi?id=77689

Covered extensively by existing tests, no behavioral changes.

  • Target.pri:
  • platform/graphics/GraphicsContext.cpp:
  • platform/graphics/GraphicsContext.h:

(WebCore):
(GraphicsContext):

  • platform/graphics/cairo/TextureMapperCairo.cpp:
  • platform/graphics/opengl/TextureMapperGL.cpp:

(TextureMapperGLData):
(BitmapTextureGL):
(WebCore::BitmapTextureGL::BitmapTextureGL):
(WebCore::TextureMapperGL::beginPainting):
(WebCore::BitmapTextureGL::reset):
(WebCore):
(WebCore::swizzleBGRAToRGBA):
(WebCore::BitmapTextureGL::updateContents):
(WebCore::BitmapTextureGL::destroy):
(WebCore::TextureMapperGL::bindSurface):
(WebCore::TextureMapper::platformCreateAccelerated):

  • platform/graphics/opengl/TextureMapperGL.h:

(TextureMapperGL):
(WebCore::TextureMapperGL::accelerationMode):
(WebCore):

  • platform/graphics/qt/GraphicsContext3DQt.cpp:

(WebCore::GraphicsContext3DPrivate::paintToTextureMapper):

  • platform/graphics/qt/GraphicsContextQt.cpp:

(WebCore):
(WebCore::GraphicsContext::get3DTransform):
(WebCore::GraphicsContext::concat3DTransform):
(WebCore::GraphicsContext::set3DTransform):

  • platform/graphics/qt/TextureMapperQt.cpp: Removed.
  • platform/graphics/qt/TextureMapperQt.h: Removed.
  • platform/graphics/texmap/TextureMapper.cpp:

(WebCore):
(BitmapTextureImageBuffer):
(TextureMapperImageBuffer):

  • platform/graphics/texmap/TextureMapper.h:

(WebCore::BitmapTexture::BitmapTexture):
(BitmapTexture):
(WebCore::BitmapTexture::bpp):
(WebCore::BitmapTexture::isOpaque):
(WebCore::TextureMapper::setGraphicsContext):
(WebCore::TextureMapper::graphicsContext):
(TextureMapper):
(WebCore::TextureMapper::TextureMapper):
(WebCore::TextureMapper::platformCreateAccelerated):

  • platform/graphics/texmap/TextureMapperNode.cpp:

(WebCore::TextureMapperNode::renderContent):
(WebCore::TextureMapperNode::setContentsTileBackBuffer):

  • platform/graphics/texmap/TextureMapperNode.h:

(TextureMapperNode):

Source/WebKit/qt:

Use TextureMapper::create instead of creating TextureMapperGL/TextureMapperQt directly.

  • Api/qwebframe.cpp:

(QWebFramePrivate::renderCompositedLayers):

  • WebCoreSupport/PageClientQt.cpp:

(WebCore::PageClientQWidget::setRootGraphicsLayer):
(WebCore::PageClientQGraphicsWidget::setRootGraphicsLayer):

Source/WebKit2:

Use TextureMapper::create instead of creating TextureMapperGL/TextureMapperQt directly.
Remove calls to unused API.

  • UIProcess/qt/LayerTreeHostProxyQt.cpp:

(WebKit::LayerTreeHostProxy::paintToCurrentGLContext):
(WebKit::LayerTreeHostProxy::paintToGraphicsContext):
(WebKit::LayerTreeHostProxy::createImage):
(WebKit::LayerTreeHostProxy::ensureRootLayer):

Location:
trunk/Source
Files:
2 added
2 deleted
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r106618 r106620  
     12012-02-02  No'am Rosenthal  <noam.rosenthal@nokia.com>
     2
     3        [Qt][Texmap] Refactor TextureMapper API to use ImageBuffers when possible.
     4        https://bugs.webkit.org/show_bug.cgi?id=77148
     5
     6        Reviewed by Martin Robinson.
     7
     8        Removed TextureMapperQt, and instead created a TextureMapperImageBuffer class,
     9        which responds to an "Software" mode of TextureMapper, instead of creating subclasses
     10        of TextureMapper directly. This allows using the software fallback of TextureMapper by any
     11        sort.
     12
     13        To make the ImageBuffer backend easier, content updates to BitmapTexture can now use either
     14        an image, or a raw data pointer. The raw data pointer is provided for performance reasons,
     15        as converting data to/from Image references in Qt generates unnecessary deep copies of the
     16        image data.
     17
     18        Also, functions that use TransformationMatrix were added to GraphicsContext, to allow for
     19        3D transforms in cross platform code.
     20        After this patch everything renders the same. An additional bug report was created to allow
     21        ImageBuffer shallow image copies: https://bugs.webkit.org/show_bug.cgi?id=77689
     22
     23        Covered extensively by existing tests, no behavioral changes.
     24
     25        * Target.pri:
     26        * platform/graphics/GraphicsContext.cpp:
     27        * platform/graphics/GraphicsContext.h:
     28        (WebCore):
     29        (GraphicsContext):
     30        * platform/graphics/cairo/TextureMapperCairo.cpp:
     31        * platform/graphics/opengl/TextureMapperGL.cpp:
     32        (TextureMapperGLData):
     33        (BitmapTextureGL):
     34        (WebCore::BitmapTextureGL::BitmapTextureGL):
     35        (WebCore::TextureMapperGL::beginPainting):
     36        (WebCore::BitmapTextureGL::reset):
     37        (WebCore):
     38        (WebCore::swizzleBGRAToRGBA):
     39        (WebCore::BitmapTextureGL::updateContents):
     40        (WebCore::BitmapTextureGL::destroy):
     41        (WebCore::TextureMapperGL::bindSurface):
     42        (WebCore::TextureMapper::platformCreateAccelerated):
     43        * platform/graphics/opengl/TextureMapperGL.h:
     44        (TextureMapperGL):
     45        (WebCore::TextureMapperGL::accelerationMode):
     46        (WebCore):
     47        * platform/graphics/qt/GraphicsContext3DQt.cpp:
     48        (WebCore::GraphicsContext3DPrivate::paintToTextureMapper):
     49        * platform/graphics/qt/GraphicsContextQt.cpp:
     50        (WebCore):
     51        (WebCore::GraphicsContext::get3DTransform):
     52        (WebCore::GraphicsContext::concat3DTransform):
     53        (WebCore::GraphicsContext::set3DTransform):
     54        * platform/graphics/qt/TextureMapperQt.cpp: Removed.
     55        * platform/graphics/qt/TextureMapperQt.h: Removed.
     56        * platform/graphics/texmap/TextureMapper.cpp:
     57        (WebCore):
     58        (BitmapTextureImageBuffer):
     59        (TextureMapperImageBuffer):
     60        * platform/graphics/texmap/TextureMapper.h:
     61        (WebCore::BitmapTexture::BitmapTexture):
     62        (BitmapTexture):
     63        (WebCore::BitmapTexture::bpp):
     64        (WebCore::BitmapTexture::isOpaque):
     65        (WebCore::TextureMapper::setGraphicsContext):
     66        (WebCore::TextureMapper::graphicsContext):
     67        (TextureMapper):
     68        (WebCore::TextureMapper::TextureMapper):
     69        (WebCore::TextureMapper::platformCreateAccelerated):
     70        * platform/graphics/texmap/TextureMapperNode.cpp:
     71        (WebCore::TextureMapperNode::renderContent):
     72        (WebCore::TextureMapperNode::setContentsTileBackBuffer):
     73        * platform/graphics/texmap/TextureMapperNode.h:
     74        (TextureMapperNode):
     75
    1762012-02-02  Adam Barth  <abarth@webkit.org>
    277
  • trunk/Source/WebCore/GNUmakefile.list.am

    r106615 r106620  
    57345734        Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp \
    57355735        Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.h \
    5736         Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp \
    5737         Source/WebCore/platform/graphics/texmap/TextureMapperNode.h \
    5738         Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayer.h
     5736        Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.cpp \
     5737        Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.h \
     5738        Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp \
     5739        Source/WebCore/platform/graphics/texmap/TextureMapperNode.h \
     5740        Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayer.h
    57395741webcoregtk_sources += \
    57405742        Source/WebCore/platform/graphics/cairo/TextureMapperCairo.cpp \
     
    57545756        Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp \
    57555757        Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.h \
    5756         Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp \
    5757         Source/WebCore/platform/graphics/texmap/TextureMapperNode.h \
     5758        Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.cpp \
     5759        Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.h \
     5760        Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp \
     5761        Source/WebCore/platform/graphics/texmap/TextureMapperNode.h \
    57585762        Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayer.h
    57595763webcoregtk_sources += \
  • trunk/Source/WebCore/Target.pri

    r106373 r106620  
    39403940contains(CONFIG, texmap) {
    39413941    HEADERS += \
    3942         platform/graphics/qt/TextureMapperQt.h \
    39433942        platform/graphics/texmap/GraphicsLayerTextureMapper.h \
    39443943        platform/graphics/texmap/LayerTransform.h \
    39453944        platform/graphics/texmap/TextureMapper.h \
    39463945        platform/graphics/texmap/TextureMapperAnimation.h \
     3946        platform/graphics/texmap/TextureMapperImageBuffer.h \
    39473947        platform/graphics/texmap/TextureMapperNode.h \
    39483948        platform/graphics/texmap/TextureMapperPlatformLayer.h
    39493949
    39503950    SOURCES += \
    3951         platform/graphics/qt/TextureMapperQt.cpp \
    39523951        platform/graphics/texmap/LayerTransform.cpp \
    39533952        platform/graphics/texmap/TextureMapper.cpp \
    39543953        platform/graphics/texmap/TextureMapperAnimation.cpp \
     3954        platform/graphics/texmap/TextureMapperImageBuffer.cpp \
    39553955        platform/graphics/texmap/TextureMapperNode.cpp \
    39563956        platform/graphics/texmap/GraphicsLayerTextureMapper.cpp
     
    39603960        SOURCES += platform/graphics/opengl/TextureMapperGL.cpp
    39613961        CONFIG += opengl-shims
     3962        DEFINES += WTF_USE_TEXTURE_MAPPER_GL
    39623963    }
    39633964} else {
  • trunk/Source/WebCore/WebCore.gypi

    r106373 r106620  
    35813581            'platform/graphics/texmap/TextureMapperAnimation.cpp',
    35823582            'platform/graphics/texmap/TextureMapperAnimation.h',
     3583            'platform/graphics/texmap/TextureMapperImageBuffer.cpp',
     3584            'platform/graphics/texmap/TextureMapperImageBuffer.h',
    35833585            'platform/graphics/texmap/TextureMapperNode.cpp',
    35843586            'platform/graphics/texmap/TextureMapperNode.h',
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.h

    r98406 r106620  
    125125    class GraphicsContext3D;
    126126    class TextRun;
     127    class TransformationMatrix;
    127128
    128129    enum TextDrawingMode {
     
    410411        AffineTransform getCTM() const;
    411412
     413#if ENABLE(3D_RENDERING) && USE(TEXTURE_MAPPER)
     414        // This is needed when using accelerated-compositing in software mode, like in TextureMapper.
     415        void concat3DTransform(const TransformationMatrix&);
     416        void set3DTransform(const TransformationMatrix&);
     417        TransformationMatrix get3DTransform() const;
     418#endif
    412419        // Create an image buffer compatible with this context, with suitable resolution
    413420        // for drawing into the buffer and then into this context.
  • trunk/Source/WebCore/platform/graphics/cairo/TextureMapperCairo.cpp

    r101548 r106620  
    116116}
    117117
    118 PassOwnPtr<TextureMapper> TextureMapper::create(GraphicsContext* context)
    119 {
    120     return adoptPtr(new TextureMapperCairo);
    121 }
    122 
    123118PassRefPtr<BitmapTexture> TextureMapperCairo::createTexture()
    124119{
  • trunk/Source/WebCore/platform/graphics/opengl/TextureMapperGL.cpp

    r106524 r106620  
    266266    };
    267267
    268     struct DirectlyCompositedImageRepository {
    269         struct Entry {
    270             GLuint texture;
    271             int refCount;
    272         };
    273         typedef HashMap<ImageUID, Entry> ImageTextureMap;
    274         ImageTextureMap imageToTexture;
    275 
    276         GLuint findOrCreate(ImageUID image, bool& found)
    277         {
    278             ImageTextureMap::iterator it = imageToTexture.find(image);
    279             found = false;
    280             if (it != imageToTexture.end()) {
    281                 it->second.refCount++;
    282                 found = true;
    283                 return it->second.texture;
    284             }
    285             Entry entry;
    286             GL_CMD(glGenTextures(1, &entry.texture));
    287             entry.refCount = 1;
    288             imageToTexture.add(image, entry);
    289             return entry.texture;
    290         }
    291 
    292         bool deref(ImageUID image)
    293         {
    294             HashMap<ImageUID, Entry>::iterator it = imageToTexture.find(image);
    295             if (it != imageToTexture.end()) {
    296                 if (it->second.refCount < 2) {
    297                     imageToTexture.remove(it);
    298                     return false;
    299                 }
    300             }
    301             return true;
    302         }
    303 
    304         DirectlyCompositedImageRepository()
    305         {
    306         }
    307 
    308         ~DirectlyCompositedImageRepository()
    309         {
    310             for (ImageTextureMap::iterator it = imageToTexture.begin(); it != imageToTexture.end(); ++it) {
    311                 GLuint texture = it->second.texture;
    312                 if (texture)
    313                     GL_CMD(glDeleteTextures(1, &texture));
    314             }
    315 
    316         }
    317     } directlyCompositedImages;
    318 
    319268    SharedGLData& sharedGLData() const
    320269    {
     
    333282    GLint previousProgram;
    334283    GLint previousScissorState;
     284    GLint viewport[4];
    335285    RefPtr<SharedGLData> m_sharedGLData;
    336286};
     
    343293    virtual void reset(const IntSize&, bool opaque);
    344294    void bind();
    345     virtual PlatformGraphicsContext* beginPaint(const IntRect& dirtyRect);
    346     virtual void endPaint();
    347     virtual void setContentsToImage(Image*);
    348295    ~BitmapTextureGL() { destroy(); }
    349296    virtual uint32_t id() const { return m_id; }
    350     inline bool isOpaque() const { return m_opaque; }
    351297    inline FloatSize relativeSize() const { return m_relativeSize; }
    352298    void setTextureMapper(TextureMapperGL* texmap) { m_textureMapper = texmap; }
    353 
    354     void updateContents(PixelFormat, const IntRect&, void*);
    355     void updateRawContents(const IntRect&, const void*);
    356     void pack()
    357     {
    358         // This is currently a stub.
    359         if (isPacked())
    360             return;
    361         m_isPacked = true;
    362     }
    363 
    364     void unpack()
    365     {
    366         // This is currently a stub.
    367         if (!isPacked())
    368             return;
    369         m_isPacked = false;
    370     }
    371 
    372     bool isPacked() const
    373     {
    374         return m_isPacked;
    375     }
     299    void updateContents(Image*, const IntRect&, const IntRect&, PixelFormat);
     300    void updateContents(const void*, const IntRect&);
    376301
    377302private:
    378303    GLuint m_id;
    379     ImageUID m_imageUID;
    380304    FloatSize m_relativeSize;
    381     bool m_opaque;
    382305    IntSize m_textureSize;
    383     OwnPtr<BGRA32PremultimpliedBuffer> m_buffer;
    384306    IntRect m_dirtyRect;
    385307    GLuint m_fbo;
     
    387309    IntSize m_actualSize;
    388310    bool m_surfaceNeedsReset;
    389     bool m_isPacked;
    390311    TextureMapperGL* m_textureMapper;
    391312    BitmapTextureGL()
    392313        : m_id(0)
    393         , m_imageUID(0)
    394         , m_opaque(false)
    395314        , m_fbo(0)
    396315        , m_rbo(0)
     
    545464    glClearStencil(0);
    546465    glClear(GL_STENCIL_BUFFER_BIT);
     466    glGetIntegerv(GL_VIEWPORT, data().viewport);
    547467    bindSurface(0);
    548468}
     
    664584{
    665585    BitmapTexture::reset(newSize, opaque);
    666     m_imageUID = 0;
    667586    IntSize newTextureSize = nextPowerOfTwo(newSize);
    668587    bool justCreated = false;
     
    683602    m_actualSize = newSize;
    684603    m_relativeSize = FloatSize(float(newSize.width()) / m_textureSize.width(), float(newSize.height()) / m_textureSize.height());
    685     m_opaque = opaque;
    686604    m_surfaceNeedsReset = true;
    687605}
    688606
    689 PlatformGraphicsContext* BitmapTextureGL::beginPaint(const IntRect& dirtyRect)
    690 {
    691     m_buffer = BGRA32PremultimpliedBuffer::create();
    692     m_dirtyRect = dirtyRect;
    693     return m_buffer->beginPaint(dirtyRect, m_opaque);
    694 }
    695 
    696 void BitmapTextureGL::endPaint()
    697 {
    698     if (!m_buffer)
    699         return;
    700     m_buffer->endPaint();
    701     updateContents(BGRAFormat, m_dirtyRect, m_buffer->data());
    702     GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id))
    703     m_buffer.clear();
    704 }
    705 
    706 #ifdef TEXMAP_OPENGL_ES_2
     607
    707608static void swizzleBGRAToRGBA(uint32_t* data, const IntSize& size)
    708609{
     
    715616    }
    716617}
    717 #endif
    718 
    719 void BitmapTextureGL::updateContents(PixelFormat pixelFormat, const IntRect& rect, void* bits)
     618
     619void BitmapTextureGL::updateContents(const void* data, const IntRect& targetRect)
    720620{
    721621    GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id))
    722 #ifdef TEXMAP_OPENGL_ES_2
    723     bool shouldSwizzle = false;
    724 #endif
    725 
    726     GLint glFormat = GL_RGBA;
    727     switch (pixelFormat) {
    728     case RGBAFormat:
    729         glFormat = GL_RGBA;
    730         break;
    731     case RGBFormat:
    732         glFormat = GL_RGB;
    733         break;
    734     case BGRAFormat:
    735 #ifdef TEXMAP_OPENGL_ES_2
    736         shouldSwizzle = true;
    737         glFormat = GL_RGBA;
    738 #else
    739         glFormat = GL_BGRA;
    740 #endif
    741         break;
    742     case BGRFormat:
    743 #ifdef TEXMAP_OPENGL_ES_2
    744         shouldSwizzle = true;
    745         glFormat = GL_RGB;
    746 #else
    747         glFormat = GL_BGR;
    748 #endif
    749          break;
    750     }
    751 
    752 #ifdef TEXMAP_OPENGL_ES_2
    753     if (shouldSwizzle)
    754         swizzleBGRAToRGBA(static_cast<uint32_t*>(bits), rect.size());
    755 #endif
    756     GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), glFormat, GL_UNSIGNED_BYTE, bits))
    757 }
    758 
    759 void BitmapTextureGL::updateRawContents(const IntRect& rect, const void* bits)
    760 {
     622    GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), GL_RGBA, GL_UNSIGNED_BYTE, data))
     623}
     624
     625void BitmapTextureGL::updateContents(Image* image, const IntRect& targetRect, const IntRect& sourceRect, BitmapTexture::PixelFormat format)
     626{
     627    if (!image)
     628        return;
    761629    GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id))
    762630    GLuint glFormat = isOpaque() ? GL_RGB : GL_RGBA;
    763     GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), glFormat, GL_UNSIGNED_BYTE, bits))
    764 }
    765 
    766 void BitmapTextureGL::setContentsToImage(Image* image)
    767 {
    768     ImageUID uid = image ? uidForImage(image) : 0;
    769     if (!image || !uid) {
    770         if (m_imageUID)
    771             destroy();
    772         return;
    773     }
    774 
    775     if (uid == m_imageUID)
    776         return;
    777     bool found = false;
    778     GLuint newTextureID = m_textureMapper->data().directlyCompositedImages.findOrCreate(uid, found);
    779     if (newTextureID != m_id) {
    780         m_imageUID = uid;
    781         destroy();
    782         m_id = newTextureID;
    783         reset(image->size(), false);
    784         if (!found) {
    785             GraphicsContext context(beginPaint(IntRect(0, 0, m_textureSize.width(), m_textureSize.height())));
    786             context.drawImage(image, ColorSpaceDeviceRGB, IntPoint(0, 0), CompositeCopy);
    787             endPaint();
    788         }
    789     }
     631    NativeImagePtr frameImage = image->nativeImageForCurrentFrame();
     632    if (!frameImage)
     633        return;
     634
     635#if PLATFORM(QT)
     636    QImage qtImage = frameImage->toImage();
     637    if (IntSize(qtImage.size()) != sourceRect.size())
     638        qtImage = qtImage.copy(sourceRect);
     639    if (format == BGRAFormat || format == BGRFormat)
     640        swizzleBGRAToRGBA(reinterpret_cast<uint32_t*>(qtImage.bits()), qtImage.size());
     641    GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, GL_UNSIGNED_BYTE, qtImage.constBits()))
     642#endif
    790643}
    791644
     
    838691void BitmapTextureGL::destroy()
    839692{
    840     if (m_id && (!m_imageUID || !m_textureMapper->data().directlyCompositedImages.deref(m_imageUID)))
     693    if (m_id)
    841694        GL_CMD(glDeleteTextures(1, &m_id))
    842695
     
    873726
    874727    if (!surface) {
     728        IntSize viewportSize(data().viewport[2], data().viewport[3]);
    875729        GL_CMD(glBindFramebuffer(GL_FRAMEBUFFER, 0))
    876         data().projectionMatrix = createProjectionMatrix(viewportSize(), true).multiply(transform());
     730        data().projectionMatrix = createProjectionMatrix(viewportSize, true);
    877731        GL_CMD(glStencilFunc(data().sharedGLData().stencilIndex > 1 ? GL_EQUAL : GL_ALWAYS, data().sharedGLData().stencilIndex - 1, data().sharedGLData().stencilIndex - 1))
    878732        GL_CMD(glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP))
    879         GL_CMD(glViewport(0, 0, viewportSize().width(), viewportSize().height()))
    880         data().sharedGLData().clipStack.append(IntRect(IntPoint::zero(), viewportSize()));
     733        GL_CMD(glViewport(0, 0, viewportSize.width(), viewportSize.height()))
     734        data().sharedGLData().clipStack.append(IntRect(data().viewport[0], data().viewport[1], data().viewport[2], data().viewport[3]));
    881735        return;
    882736    }
     
    986840}
    987841
     842PassOwnPtr<TextureMapper> TextureMapper::platformCreateAccelerated()
     843{
     844    return TextureMapperGL::create();
     845}
     846
    988847};
  • trunk/Source/WebCore/platform/graphics/opengl/TextureMapperGL.h

    r106524 r106620  
    4444    virtual void bindSurface(BitmapTexture* surface);
    4545    virtual void beginClip(const TransformationMatrix&, const FloatRect&);
     46    virtual void beginPainting();
     47    virtual void endPainting();
    4648    virtual void endClip();
    47     virtual bool allowSurfaceForRoot() const { return false; }
    4849    virtual PassRefPtr<BitmapTexture> createTexture();
    4950    virtual const char* type() const;
    5051    static PassOwnPtr<TextureMapperGL> create() { return adoptPtr(new TextureMapperGL); }
    51     void beginPainting();
    52     void endPainting();
    5352    void setGraphicsContext(GraphicsContext* context) { m_context = context; }
    5453    GraphicsContext* graphicsContext() { return m_context; }
    5554    virtual bool isOpenGLBacked() const { return true; }
     55    void platformUpdateContents(NativeImagePtr, const IntRect&, const IntRect&, BitmapTexture::PixelFormat);
     56    virtual AccelerationMode accelerationMode() const { return OpenGLMode; }
    5657
    5758private:
     
    6566
    6667// An offscreen buffer to be rendered by software.
    67 class BGRA32PremultimpliedBuffer {
    68     WTF_MAKE_FAST_ALLOCATED;
    69 public:
    70     virtual ~BGRA32PremultimpliedBuffer() { }
    71     virtual PlatformGraphicsContext* beginPaint(const IntRect& dirtyRect, bool opaque) = 0;
    72     virtual void endPaint() = 0;
    73     virtual void* data() = 0;
    74     static PassOwnPtr<BGRA32PremultimpliedBuffer> create();
    75 };
    76 
    7768static inline int nextPowerOfTwo(int num)
    7869{
  • trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp

    r106320 r106620  
    147147    blitMultisampleFramebufferAndRestoreContext();
    148148
    149     if (textureMapper->isOpenGLBacked()) {
     149    if (textureMapper->accelerationMode() == TextureMapper::OpenGLMode) {
    150150        TextureMapperGL* texmapGL = static_cast<TextureMapperGL*>(textureMapper);
    151151        texmapGL->drawTexture(m_context->m_texture, !m_context->m_attrs.alpha, FloatSize(1, 1), targetRect, matrix, opacity, mask, true /* flip */);
  • trunk/Source/WebCore/platform/graphics/qt/GraphicsContextQt.cpp

    r97557 r106620  
    13361336}
    13371337
     1338#if ENABLE(3D_RENDERING) && USE(TEXTURE_MAPPER)
     1339TransformationMatrix GraphicsContext::get3DTransform() const
     1340{
     1341    if (paintingDisabled())
     1342        return TransformationMatrix();
     1343
     1344    return platformContext()->combinedTransform();
     1345}
     1346
     1347void GraphicsContext::concat3DTransform(const TransformationMatrix& transform)
     1348{
     1349    if (paintingDisabled())
     1350        return;
     1351
     1352    m_data->p()->setWorldTransform(transform, true);
     1353}
     1354
     1355void GraphicsContext::set3DTransform(const TransformationMatrix& transform)
     1356{
     1357    if (paintingDisabled())
     1358        return;
     1359
     1360    m_data->p()->setWorldTransform(transform, false);
     1361}
     1362#endif
     1363
    13381364void GraphicsContext::setURLForRect(const KURL&, const IntRect&)
    13391365{
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp

    r105467 r106620  
    2020#include "config.h"
    2121#include "TextureMapper.h"
     22
     23#include "TextureMapperImageBuffer.h"
    2224
    2325#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
     
    7274}
    7375
     76
     77PassOwnPtr<TextureMapper> TextureMapper::create(AccelerationMode mode)
     78{
     79    if (mode == SoftwareMode)
     80        return TextureMapperImageBuffer::create();
     81    return platformCreateAccelerated();
     82}
     83
    7484}
    7585#endif
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.h

    r105737 r106620  
    4848public:
    4949    enum PixelFormat { BGRAFormat, RGBAFormat, BGRFormat, RGBFormat };
    50     BitmapTexture() : m_lockCount(0) {}
     50    BitmapTexture()
     51        : m_isOpaque(true)
     52    {
     53    }
     54
    5155    virtual ~BitmapTexture() { }
    5256    virtual void destroy() { }
    5357
    54     virtual bool allowOfflineTextureUpload() const { return false; }
    5558    virtual IntSize size() const = 0;
     59    virtual void updateContents(Image*, const IntRect&, const IntRect&, BitmapTexture::PixelFormat) = 0;
     60    virtual void updateContents(const void*, const IntRect&) = 0;
     61    virtual bool isValid() const = 0;
     62
    5663    virtual int bpp() const { return 32; }
    57     virtual bool isValid() const = 0;
    5864    virtual void reset(const IntSize& size, bool opaque = false)
    5965    {
     
    6268    }
    6369
    64     virtual void pack() { }
    65     virtual void unpack() { }
    66     virtual bool isPacked() const { return false; }
    67 
    68     virtual PlatformGraphicsContext* beginPaint(const IntRect& dirtyRect) = 0;
    69     virtual void endPaint() = 0;
    70 
    71     // For performance reasons, BitmapTexture might modify the bits directly (swizzle).
    72     // Thus, this method is only recommended for buffer update, such as used by WebKit2.
    73     virtual void updateContents(PixelFormat, const IntRect&, void* bits) = 0;
    74     virtual void updateRawContents(const IntRect&, const void* bits) { }
    75     virtual PlatformGraphicsContext* beginPaintMedia()
    76     {
    77         return beginPaint(IntRect(0, 0, size().width(), size().height()));
    78     }
    79     virtual void setContentsToImage(Image*) = 0;
    80     virtual bool save(const String&) { return false; }
    81 
    82     inline void lock() { ++m_lockCount; }
    83     inline void unlock() { --m_lockCount; }
    84     inline bool isLocked() { return m_lockCount; }
    8570    inline IntSize contentSize() const { return m_contentSize; }
    8671    inline int numberOfBytes() const { return size().width() * size().height() * bpp() >> 3; }
     72    inline bool isOpaque() const { return m_isOpaque; }
    8773
    8874protected:
    89     int m_lockCount;
    9075    IntSize m_contentSize;
    9176    bool m_isOpaque;
     
    9883
    9984public:
    100     static PassOwnPtr<TextureMapper> create(GraphicsContext* graphicsContext = 0);
     85    enum AccelerationMode { SoftwareMode, OpenGLMode };
     86    static PassOwnPtr<TextureMapper> create(AccelerationMode newMode = SoftwareMode);
    10187    virtual ~TextureMapper() { }
    10288
     
    10591    // makes a surface the target for the following drawTexture calls.
    10692    virtual void bindSurface(BitmapTexture* surface) = 0;
    107     virtual void setGraphicsContext(GraphicsContext*) = 0;
    108     virtual GraphicsContext* graphicsContext() = 0;
     93    virtual void setGraphicsContext(GraphicsContext* context) { m_context = context; }
     94    virtual GraphicsContext* graphicsContext() { return m_context; }
    10995    virtual void beginClip(const TransformationMatrix&, const FloatRect&) = 0;
    11096    virtual void endClip() = 0;
    111     virtual bool allowSurfaceForRoot() const = 0;
    11297    virtual PassRefPtr<BitmapTexture> createTexture() = 0;
    113     IntSize viewportSize() const { return m_viewportSize; }
    114     void setViewportSize(const IntSize& s) { m_viewportSize = s; }
    11598
    11699    void setImageInterpolationQuality(InterpolationQuality quality) { m_interpolationQuality = quality; }
     
    119102    InterpolationQuality imageInterpolationQuality() const { return m_interpolationQuality; }
    120103    TextDrawingModeFlags textDrawingMode() const { return m_textDrawingMode; }
    121     virtual bool allowPartialUpdates() const { return false; }
    122     virtual bool isOpenGLBacked() const { return false; }
    123 
    124     void setTransform(const TransformationMatrix& matrix) { m_transform = matrix; }
    125     TransformationMatrix transform() const { return m_transform; }
     104    virtual AccelerationMode accelerationMode() const = 0;
    126105
    127106    virtual void beginPainting() { }
     
    130109    // A surface is released implicitly when dereferenced.
    131110    virtual PassRefPtr<BitmapTexture> acquireTextureFromPool(const IntSize&);
    132 
    133111
    134112protected:
     
    139117
    140118private:
     119#if USE(TEXTURE_MAPPER_GL)
     120    static PassOwnPtr<TextureMapper> platformCreateAccelerated();
     121#else
     122    static PassOwnPtr<TextureMapper> platformCreateAccelerated()
     123    {
     124        return 0;
     125    }
     126#endif
    141127    InterpolationQuality m_interpolationQuality;
    142128    TextDrawingModeFlags m_textDrawingMode;
    143     TransformationMatrix m_transform;
    144     IntSize m_viewportSize;
    145129    Vector<RefPtr<BitmapTexture> > m_texturePool;
     130    GraphicsContext* m_context;
    146131};
    147132
    148 };
     133}
    149134
    150135#endif
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp

    r105925 r106620  
    2424
    2525#include "GraphicsLayerTextureMapper.h"
     26#include "ImageBuffer.h"
    2627#include "MathExtras.h"
    2728
     
    157158        return;
    158159
    159     // FIXME: Add directly composited images.
    160     FloatRect dirtyRect = m_currentContent.needsDisplay ? entireRect() : m_currentContent.needsDisplayRect;
     160    IntRect dirtyRect = enclosingIntRect(m_currentContent.needsDisplay ? entireRect() : m_currentContent.needsDisplayRect);
    161161
    162162    for (size_t tileIndex = 0; tileIndex < m_ownedTiles.size(); ++tileIndex) {
    163163        OwnedTile& tile = m_ownedTiles[tileIndex];
    164         FloatRect rect = dirtyRect;
    165164        if (!tile.texture)
    166165            tile.texture = textureMapper->createTexture();
     
    170169        if (tile.needsReset || texture->contentSize() != tileSize || !texture->isValid()) {
    171170            tile.needsReset = false;
    172             texture->reset(tileSize, m_currentContent.contentType == DirectImageContentType ? false : m_state.contentsOpaque);
    173             rect = tile.rect;
    174         }
    175 
    176         IntRect contentRect = enclosingIntRect(tile.rect);
    177         contentRect.intersect(enclosingIntRect(rect));
    178         if (contentRect.isEmpty())
     171            texture->reset(tileSize, m_state.contentsOpaque);
     172            dirtyRect.unite(enclosingIntRect(tile.rect));
     173        }
     174    }
     175
     176    if (dirtyRect.isEmpty())
     177        return;
     178
     179    // Paint the entire dirty rect into an image buffer. This ensures we only paint once.
     180    OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(dirtyRect.size());
     181    GraphicsContext* context = imageBuffer->context();
     182    context->setImageInterpolationQuality(textureMapper->imageInterpolationQuality());
     183    context->setTextDrawingMode(textureMapper->textDrawingMode());
     184    context->translate(-dirtyRect.x(), -dirtyRect.y());
     185    layer->paintGraphicsLayerContents(*context, dirtyRect);
     186    if (m_currentContent.contentType == DirectImageContentType)
     187        context->drawImage(m_currentContent.image.get(), ColorSpaceDeviceRGB, m_state.contentsRect);
     188
     189    // FIXME: Implement ImageBuffer::DontCopyBackingStore in Qt/GTK ports, and then change this.
     190    // See https://bugs.webkit.org/show_bug.cgi?id=77689
     191    RefPtr<Image> image = imageBuffer->copyImage(CopyBackingStore);
     192
     193    // Divide the image to tiles.
     194    for (size_t tileIndex = 0; tileIndex < m_ownedTiles.size(); ++tileIndex) {
     195        OwnedTile& tile = m_ownedTiles[tileIndex];
     196        IntRect targetRect = enclosingIntRect(tile.rect);
     197        targetRect.intersect(dirtyRect);
     198        if (targetRect.isEmpty())
    179199            continue;
    180 
    181         FloatRect contentRectInTileCoordinates = contentRect;
    182         FloatPoint offset(-tile.rect.x(), -tile.rect.y());
    183         contentRectInTileCoordinates.move(offset.x(), offset.y());
    184 
    185         {
    186             GraphicsContext context(texture->beginPaint(enclosingIntRect(contentRectInTileCoordinates)));
    187             context.setImageInterpolationQuality(textureMapper->imageInterpolationQuality());
    188             context.setTextDrawingMode(textureMapper->textDrawingMode());
    189             context.translate(offset.x(), offset.y());
    190             FloatRect scaledContentRect(contentRect);
    191             if (m_currentContent.contentType == DirectImageContentType)
    192                 context.drawImage(m_currentContent.image.get(), ColorSpaceDeviceRGB, IntPoint(0, 0));
    193             else
    194                 layer->paintGraphicsLayerContents(context, enclosingIntRect(scaledContentRect));
    195             texture->endPaint();
    196         }
     200        IntRect sourceRect = targetRect;
     201
     202        // Normalize sourceRect to the buffer's coordinates.
     203        sourceRect.move(-dirtyRect.x(), -dirtyRect.y());
     204
     205        // Normalize targetRect to the texture's coordinqates.
     206        targetRect.move(-tile.rect.x(), -tile.rect.y());
     207        tile.texture->updateContents(image.get(), targetRect, sourceRect, BitmapTexture::RGBAFormat);
    197208    }
    198209
     
    482493}
    483494
    484 void TextureMapperNode::setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, const void* bits)
     495void TextureMapperNode::setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, const void* data)
    485496{
    486497    ASSERT(m_textureMapper);
     
    499510        tile.backBuffer.texture = m_textureMapper->createTexture();
    500511    tile.backBuffer.texture->reset(sourceRect.size(), false);
    501     tile.backBuffer.texture->updateRawContents(sourceRect, bits);
     512    tile.backBuffer.texture->updateContents(data, sourceRect);
    502513    tile.isBackBufferUpdated = true;
    503514}
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperNode.h

    r105925 r106620  
    149149    int createContentsTile(float scale);
    150150    void removeContentsTile(int id);
    151     void setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, const void* bits);
     151    void setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, const void*);
    152152    void setTileBackBufferTextureForDirectlyCompositedImage(int id, const IntRect& sourceRect, const FloatRect& targetRect, BitmapTexture*);
    153153    void clearAllDirectlyCompositedImageTiles();
  • trunk/Source/WebKit/qt/Api/qwebframe.cpp

    r102763 r106620  
    337337    textureMapper->setImageInterpolationQuality(context->imageInterpolationQuality());
    338338    textureMapper->setTextDrawingMode(context->textDrawingMode());
    339     textureMapper->setViewportSize(frame->view()->frameRect().size());
    340339    QPainter* painter = context->platformContext();
    341340    const QTransform transform = painter->worldTransform();
  • trunk/Source/WebKit/qt/ChangeLog

    r106515 r106620  
     12012-02-02  No'am Rosenthal  <noam.rosenthal@nokia.com>
     2
     3        [Qt][Texmap] Refactor TextureMapper API to use ImageBuffers when possible.
     4        https://bugs.webkit.org/show_bug.cgi?id=77148
     5
     6        Reviewed by Martin Robinson.
     7
     8        Use TextureMapper::create instead of creating TextureMapperGL/TextureMapperQt directly.
     9
     10        * Api/qwebframe.cpp:
     11        (QWebFramePrivate::renderCompositedLayers):
     12        * WebCoreSupport/PageClientQt.cpp:
     13        (WebCore::PageClientQWidget::setRootGraphicsLayer):
     14        (WebCore::PageClientQGraphicsWidget::setRootGraphicsLayer):
     15
    1162012-02-01  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
    217
  • trunk/Source/WebKit/qt/WebCoreSupport/PageClientQt.cpp

    r100410 r106620  
    2929
    3030#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
    31 #include "TextureMapperQt.h"
     31#include "TextureMapper.h"
    3232#include "texmap/TextureMapperNode.h"
    33 
    34 #if USE(TEXTURE_MAPPER_GL)
    35 #include "opengl/TextureMapperGL.h"
    36 #endif
    3733#endif
    3834
     
    7773    if (layer) {
    7874        textureMapperNodeClient = adoptPtr(new TextureMapperNodeClientQt(page->mainFrame(), layer));
    79         textureMapperNodeClient->setTextureMapper(adoptPtr(new TextureMapperQt));
     75        textureMapperNodeClient->setTextureMapper(TextureMapper::create());
    8076        textureMapperNodeClient->syncRootLayer();
    8177        return;
     
    268264        QGraphicsView* graphicsView = view->scene()->views()[0];
    269265        if (graphicsView && graphicsView->viewport() && graphicsView->viewport()->inherits("QGLWidget")) {
    270             textureMapperNodeClient->setTextureMapper(TextureMapperGL::create());
     266            textureMapperNodeClient->setTextureMapper(TextureMapper::create(TextureMapper::OpenGLMode));
    271267            return;
    272268        }
    273269#endif
    274         textureMapperNodeClient->setTextureMapper(TextureMapperQt::create());
     270        textureMapperNodeClient->setTextureMapper(TextureMapper::create());
    275271        return;
    276272    }
  • trunk/Source/WebKit2/ChangeLog

    r106592 r106620  
     12012-02-02  No'am Rosenthal  <noam.rosenthal@nokia.com>
     2
     3        [Qt][Texmap] Refactor TextureMapper API to use ImageBuffers when possible.
     4        https://bugs.webkit.org/show_bug.cgi?id=77148
     5
     6        Reviewed by Martin Robinson.
     7
     8        Use TextureMapper::create instead of creating TextureMapperGL/TextureMapperQt directly.
     9        Remove calls to unused API.
     10
     11        * UIProcess/qt/LayerTreeHostProxyQt.cpp:
     12        (WebKit::LayerTreeHostProxy::paintToCurrentGLContext):
     13        (WebKit::LayerTreeHostProxy::paintToGraphicsContext):
     14        (WebKit::LayerTreeHostProxy::createImage):
     15        (WebKit::LayerTreeHostProxy::ensureRootLayer):
     16
    1172012-02-02  Jon Lee  <jonlee@apple.com>
    218
  • trunk/Source/WebKit2/UIProcess/qt/LayerTreeHostProxyQt.cpp

    r106524 r106620  
    2727#include "MessageID.h"
    2828#include "ShareableBitmap.h"
    29 #include "TextureMapperGL.h"
    30 #include "TextureMapperQt.h"
     29#include "TextureMapper.h"
    3130#include "UpdateInfo.h"
    3231#include "WebCoreArgumentCoders.h"
     
    172171{
    173172    if (!m_textureMapper)
    174         m_textureMapper = TextureMapperGL::create();
    175     ASSERT(dynamic_cast<TextureMapperGL*>(m_textureMapper.get()));
     173        m_textureMapper = TextureMapper::create(TextureMapper::OpenGLMode);
     174    ASSERT(m_textureMapper->accelerationMode() == TextureMapper::OpenGLMode);
    176175
    177176    syncRemoteContent();
     
    185184        return;
    186185
    187     GLint viewport[4];
    188     glGetIntegerv(GL_VIEWPORT, viewport);
    189     m_textureMapper->setViewportSize(IntSize(viewport[2], viewport[3]));
    190186    node->setTextureMapper(m_textureMapper.get());
    191187    m_textureMapper->beginPainting();
     
    212208{
    213209    if (!m_textureMapper)
    214         m_textureMapper = TextureMapperQt::create();
    215     ASSERT(dynamic_cast<TextureMapperQt*>(m_textureMapper.get()));
    216 
     210        m_textureMapper = TextureMapper::create();
     211    ASSERT(m_textureMapper->accelerationMode() == TextureMapper::SoftwareMode);
    217212    syncRemoteContent();
    218213    TextureMapperNode* node = toTextureMapperNode(rootLayer());
     
    411406            RefPtr<BitmapTexture> texture = m_textureMapper->createTexture();
    412407            texture->reset(rect.size(), !imageHasAlpha);
    413             texture->updateRawContents(IntRect(IntPoint::zero(), rect.size()), subImage.constBits());
     408            texture->updateContents(subImage.constBits(), IntRect(IntPoint::zero(), rect.size()));
    414409            tiledImage.add(rect.location(), texture);
    415410        }
     
    474469    m_rootLayer->setSize(FloatSize(1.0, 1.0));
    475470    if (!m_textureMapper)
    476         m_textureMapper = TextureMapperGL::create();
     471        m_textureMapper = TextureMapper::create(TextureMapper::OpenGLMode);
    477472    toTextureMapperNode(m_rootLayer.get())->setTextureMapper(m_textureMapper.get());
    478473}
Note: See TracChangeset for help on using the changeset viewer.