[Qt][WK2] Manage graphics buffers in the web process
authornoam.rosenthal@nokia.com <noam.rosenthal@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Apr 2012 21:52:39 +0000 (21:52 +0000)
committernoam.rosenthal@nokia.com <noam.rosenthal@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Apr 2012 21:52:39 +0000 (21:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78675

Source/WebCore:

Added WebCore::GraphicsSurface, a wrapper class to a platform-dependant
surface that can be accessed efficiently by both the CPU and the GPU.
This will allow fast texture uploads for WebKit2, and in the future
fast copies for 2D canvas and WebGL.
The first implementation is for Mac using IOSurfaces.

TextureMapperGL had to be modified to use GL_UNSIGNED_INT_8_8_8_8_REV
for textures on Mac, since that's the native pixel format of BGRA
IOSurfaces.

Though this feature is not written in a Qt-specific way, it's currently
only enabled for Qt and is protected by USE(GRAPHICS_SURFACE).

Reviewed by Kenneth Rohde Christiansen.

Covered by existing API tests.

* Target.pri:
* WebCore.pri:
* platform/graphics/surfaces/GraphicsSurface.cpp: Added.
* platform/graphics/surfaces/GraphicsSurface.h: Added.
* platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp: Added.
* platform/graphics/surfaces/qt/GraphicsSurfaceQt.cpp: Added.
(WebCore::GraphicsSurface::didReleaseImage):
(WebCore):
(WebCore::GraphicsSurface::platformBeginPaint):
(WebCore::GraphicsSurface::createReadOnlyImage):
* platform/graphics/texmap/TextureMapper.h:
(WebCore::BitmapTexture::isOpenGLBacked):
* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::toBitmapTextureGL):
(WebCore):
(WebCore::BitmapTextureGL::didReset):
(WebCore::BitmapTextureGL::updateContents):
* platform/graphics/texmap/TextureMapperGL.h:
(WebCore::BitmapTextureGL::isOpenGLBacked):
(WebCore):

Source/WebKit2:

Added ShareableSurface, a class allowing the use of GPU-enabled
surfaces for bitmap transfer between the web and UI processes.
Since GraphicsSurfaces may not always be available, ShareableSurface
uses a standard ShareableBitmap as a fallback backend.

The necessary plumbing was added in WebKit2 for passing updates via
ShareableSurfaces instead of ShareableBitmaps. SurfaceUpdateInfo was
added, as to not make UpdateInfo more complicated.

Reviewed by Kenneth Rohde Christiansen.

* Shared/ShareableSurface.cpp: Added.
* Shared/ShareableSurface.h: Added.
* Shared/SurfaceUpdateInfo.cpp: Added.
* Shared/SurfaceUpdateInfo.h: Added.
* Target.pri:
* UIProcess/LayerTreeHostProxy.cpp:
(WebKit::LayerTreeHostProxy::createTileForLayer):
(WebKit::LayerTreeHostProxy::updateTileForLayer):
* UIProcess/LayerTreeHostProxy.h:
(LayerTreeHostProxy):
* UIProcess/LayerTreeHostProxy.messages.in:
* UIProcess/WebLayerTreeRenderer.cpp:
(WebKit::WebLayerTreeRenderer::updateTile):
* UIProcess/WebLayerTreeRenderer.h:
(TileUpdate):
(WebKit::WebLayerTreeRenderer::TileUpdate::TileUpdate):
* UIProcess/qt/LayerBackingStore.cpp:
(WebKit::LayerBackingStoreTile::swapBuffers):
(WebKit::LayerBackingStoreTile::setBackBuffer):
(WebKit::LayerBackingStore::updateTile):
* UIProcess/qt/LayerBackingStore.h:
(LayerBackingStoreTile):
(LayerBackingStore):
* WebProcess/WebCoreSupport/WebGraphicsLayer.cpp:
(WebCore::WebGraphicsLayer::beginContentUpdate):
(WebCore::WebGraphicsLayer::createTile):
(WebCore::WebGraphicsLayer::updateTile):
* WebProcess/WebCoreSupport/WebGraphicsLayer.h:
(WebGraphicsLayerClient):
(WebGraphicsLayer):
* WebProcess/WebPage/TiledBackingStoreRemoteTile.cpp:
(WebKit::TiledBackingStoreRemoteTile::updateBackBuffer):
* WebProcess/WebPage/TiledBackingStoreRemoteTile.h:
(WebKit):
(TiledBackingStoreRemoteTileClient):
* WebProcess/WebPage/UpdateAtlas.cpp:
(WebKit::UpdateAtlas::UpdateAtlas):
(WebKit::UpdateAtlas::beginPaintingOnAvailableBuffer):
* WebProcess/WebPage/UpdateAtlas.h:
(WebKit::UpdateAtlas::surface):
(WebKit::UpdateAtlas::size):
* WebProcess/WebPage/qt/LayerTreeHostQt.cpp:
(WebKit::LayerTreeHostQt::createTile):
(WebKit::LayerTreeHostQt::updateTile):
(WebKit::LayerTreeHostQt::beginContentUpdate):
* WebProcess/WebPage/qt/LayerTreeHostQt.h:
(LayerTreeHostQt):

Tools:

Enable graphics surfaces on Mac for Qt.

Reviewed by Kenneth Rohde Christiansen.

* qmake/mkspecs/features/features.prf:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@113773 268f45cc-cd09-0410-ab3c-d52691b4dbfc

33 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Target.pri
Source/WebCore/WebCore.pri
Source/WebCore/platform/graphics/surfaces/GraphicsSurface.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/surfaces/GraphicsSurface.h [new file with mode: 0644]
Source/WebCore/platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/surfaces/qt/GraphicsSurfaceQt.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/texmap/TextureMapper.h
Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp
Source/WebCore/platform/graphics/texmap/TextureMapperGL.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/ShareableSurface.cpp [new file with mode: 0644]
Source/WebKit2/Shared/ShareableSurface.h [new file with mode: 0644]
Source/WebKit2/Shared/SurfaceUpdateInfo.cpp [new file with mode: 0644]
Source/WebKit2/Shared/SurfaceUpdateInfo.h [new file with mode: 0644]
Source/WebKit2/Target.pri
Source/WebKit2/UIProcess/LayerTreeHostProxy.cpp
Source/WebKit2/UIProcess/LayerTreeHostProxy.h
Source/WebKit2/UIProcess/LayerTreeHostProxy.messages.in
Source/WebKit2/UIProcess/WebLayerTreeRenderer.cpp
Source/WebKit2/UIProcess/WebLayerTreeRenderer.h
Source/WebKit2/UIProcess/qt/LayerBackingStore.cpp
Source/WebKit2/UIProcess/qt/LayerBackingStore.h
Source/WebKit2/WebProcess/WebCoreSupport/WebGraphicsLayer.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebGraphicsLayer.h
Source/WebKit2/WebProcess/WebPage/TiledBackingStoreRemoteTile.cpp
Source/WebKit2/WebProcess/WebPage/TiledBackingStoreRemoteTile.h
Source/WebKit2/WebProcess/WebPage/UpdateAtlas.cpp
Source/WebKit2/WebProcess/WebPage/UpdateAtlas.h
Source/WebKit2/WebProcess/WebPage/qt/LayerTreeHostQt.cpp
Source/WebKit2/WebProcess/WebPage/qt/LayerTreeHostQt.h
Tools/ChangeLog
Tools/qmake/mkspecs/features/features.prf

index cc77093..56dfe72 100644 (file)
@@ -1,3 +1,46 @@
+2012-04-10  No'am Rosenthal  <noam.rosenthal@nokia.com>
+
+        [Qt][WK2] Manage graphics buffers in the web process
+        https://bugs.webkit.org/show_bug.cgi?id=78675
+
+        Added WebCore::GraphicsSurface, a wrapper class to a platform-dependant
+        surface that can be accessed efficiently by both the CPU and the GPU.
+        This will allow fast texture uploads for WebKit2, and in the future
+        fast copies for 2D canvas and WebGL.
+        The first implementation is for Mac using IOSurfaces.
+
+        TextureMapperGL had to be modified to use GL_UNSIGNED_INT_8_8_8_8_REV
+        for textures on Mac, since that's the native pixel format of BGRA
+        IOSurfaces.
+
+        Though this feature is not written in a Qt-specific way, it's currently
+        only enabled for Qt and is protected by USE(GRAPHICS_SURFACE).
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Covered by existing API tests.
+
+        * Target.pri:
+        * WebCore.pri:
+        * platform/graphics/surfaces/GraphicsSurface.cpp: Added.
+        * platform/graphics/surfaces/GraphicsSurface.h: Added.
+        * platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp: Added.
+        * platform/graphics/surfaces/qt/GraphicsSurfaceQt.cpp: Added.
+        (WebCore::GraphicsSurface::didReleaseImage):
+        (WebCore):
+        (WebCore::GraphicsSurface::platformBeginPaint):
+        (WebCore::GraphicsSurface::createReadOnlyImage):
+        * platform/graphics/texmap/TextureMapper.h:
+        (WebCore::BitmapTexture::isOpenGLBacked):
+        * platform/graphics/texmap/TextureMapperGL.cpp:
+        (WebCore::toBitmapTextureGL):
+        (WebCore):
+        (WebCore::BitmapTextureGL::didReset):
+        (WebCore::BitmapTextureGL::updateContents):
+        * platform/graphics/texmap/TextureMapperGL.h:
+        (WebCore::BitmapTextureGL::isOpenGLBacked):
+        (WebCore):
+
 2012-04-10  Alexei Filippov  <alexeif@chromium.org>
 
         Web Inspector: split nodes and edges array in heap profiler serialization.
index d44a00a..7819521 100644 (file)
@@ -1107,6 +1107,8 @@ SOURCES += \
     platform/graphics/SVGGlyph.cpp \
     platform/graphics/SimpleFontData.cpp \
     platform/graphics/StringTruncator.cpp \
+    platform/graphics/surfaces/GraphicsSurface.cpp \
+    platform/graphics/surfaces/qt/GraphicsSurfaceQt.cpp \
     platform/graphics/TextRun.cpp \
     platform/graphics/TiledBackingStore.cpp \
     platform/graphics/transforms/AffineTransform.cpp \
@@ -2244,6 +2246,7 @@ HEADERS += \
     platform/graphics/SegmentedFontData.h \
     platform/graphics/ShadowBlur.h \
     platform/graphics/SimpleFontData.h \
+    platform/graphics/surfaces/GraphicsSurface.h \
     platform/graphics/Tile.h \
     platform/graphics/TiledBackingStore.h \
     platform/graphics/TiledBackingStoreClient.h \
@@ -4080,6 +4083,13 @@ contains(CONFIG, opengl-shims) {
     DEFINES += QT_OPENGL_SHIMS=1
 }
 
+contains(CONFIG, graphics_surfaces) {
+    mac {
+        SOURCES += platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp
+        INCLUDEPATH += /System/Library/Frameworks/CoreFoundation.framework/Headers
+    }
+}
+
 # Make sure the derived sources are built
 include(DerivedSources.pri)
 
index f761ce9..cdaeb73 100644 (file)
@@ -60,6 +60,7 @@ INCLUDEPATH += \
     $$SOURCE_DIR/platform/graphics/filters/arm \
     $$SOURCE_DIR/platform/graphics/opengl \
     $$SOURCE_DIR/platform/graphics/qt \
+    $$SOURCE_DIR/platform/graphics/surfaces \
     $$SOURCE_DIR/platform/graphics/texmap \
     $$SOURCE_DIR/platform/graphics/transforms \
     $$SOURCE_DIR/platform/image-decoders \
@@ -194,6 +195,7 @@ contains(CONFIG, texmap) {
         DEFINES += WTF_USE_TEXTURE_MAPPER_GL=1
         contains(QT_CONFIG, opengles2): LIBS += -lEGL
     }
+    mac: LIBS += -framework IOSurface -framework CoreFoundation
 }
 
 contains(DEFINES, WTF_USE_TEXTURE_MAPPER_GL=1)|contains(DEFINES, ENABLE_WEBGL=1) {
diff --git a/Source/WebCore/platform/graphics/surfaces/GraphicsSurface.cpp b/Source/WebCore/platform/graphics/surfaces/GraphicsSurface.cpp
new file mode 100644 (file)
index 0000000..b43a101
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB.  If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "GraphicsSurface.h"
+
+#include "NotImplemented.h"
+
+#if USE(GRAPHICS_SURFACE)
+namespace WebCore {
+
+PassRefPtr<GraphicsSurface> GraphicsSurface::create(const IntSize& size, Flags flags, uint32_t token)
+{
+    RefPtr<GraphicsSurface> surface = adoptRef(new GraphicsSurface(size, flags));
+    if (!surface->platformImport(token))
+        return PassRefPtr<GraphicsSurface>();
+    return surface;
+}
+
+PassRefPtr<GraphicsSurface> GraphicsSurface::create(const IntSize& size, GraphicsSurface::Flags flags)
+{
+    RefPtr<GraphicsSurface> surface = adoptRef(new GraphicsSurface(size, flags));
+    if (!surface->platformCreate(size, flags))
+        return PassRefPtr<GraphicsSurface>();
+    return surface;
+}
+
+uint32_t GraphicsSurface::exportToken()
+{
+    return platformExport();
+}
+
+PassOwnPtr<GraphicsContext> GraphicsSurface::beginPaint(const IntRect& rect, LockOptions lockOptions)
+{
+    int stride = 0;
+    char* bits = platformLock(rect, &stride, lockOptions);
+    OwnPtr<GraphicsContext> graphicsContext = platformBeginPaint(rect.size(), bits, stride);
+    return graphicsContext.release();
+}
+
+void GraphicsSurface::copyToGLTexture(uint32_t target, uint32_t texture, const IntRect& targetRect, const IntPoint& offset)
+{
+    platformCopyToGLTexture(target, texture, targetRect, offset);
+}
+
+GraphicsSurface::GraphicsSurface(const IntSize& size, Flags flags)
+    : m_size(size)
+    , m_flags(flags)
+    , m_platformSurface(0)
+    , m_texture(0)
+    , m_fbo(0)
+{
+}
+
+}
+#endif
diff --git a/Source/WebCore/platform/graphics/surfaces/GraphicsSurface.h b/Source/WebCore/platform/graphics/surfaces/GraphicsSurface.h
new file mode 100644 (file)
index 0000000..da941d4
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB.  If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef GraphicsSurface_h
+#define GraphicsSurface_h
+
+#include "GraphicsContext.h"
+#include "IntRect.h"
+#include "OwnPtr.h"
+#include "PassOwnPtr.h"
+#include "RefCounted.h"
+#include "RefPtr.h"
+
+#if USE(GRAPHICS_SURFACE)
+
+#if OS(DARWIN)
+typedef struct __IOSurface* IOSurfaceRef;
+typedef IOSurfaceRef PlatformGraphicsSurface;
+#endif
+
+namespace WebCore {
+
+class GraphicsSurface : public RefCounted<GraphicsSurface> {
+public:
+    enum Flag {
+        SupportsAlpha = 0x01,
+        SupportsSoftwareWrite = 0x02,
+        SupportsSoftwareRead = 0x04,
+        SupportsTextureTarget = 0x08,
+        SupportsTextureSource = 0x10,
+        SupportsCopyToTexture = 0x20,
+        SupportsCopyFromTexture = 0x40,
+        SupportsSharing = 0x80
+    };
+
+    enum LockOption {
+        RetainPixels = 0x01,
+        ReadOnly = 0x02
+    };
+
+    typedef int Flags;
+    typedef int LockOptions;
+
+    Flags flags() const { return m_flags; }
+    PlatformGraphicsSurface platformSurface() const { return m_platformSurface; }
+    IntSize size() const { return m_size; }
+
+    static PassRefPtr<GraphicsSurface> create(const IntSize&, Flags);
+    static PassRefPtr<GraphicsSurface> create(const IntSize&, Flags, uint32_t token);
+    void copyToGLTexture(uint32_t target, uint32_t texture, const IntRect& targetRect, const IntPoint& sourceOffset);
+    uint32_t exportToken();
+    PassOwnPtr<GraphicsContext> beginPaint(const IntRect&, LockOptions);
+    PassRefPtr<Image> createReadOnlyImage(const IntRect&);
+
+protected:
+    bool platformCreate(const IntSize&, Flags);
+    bool platformImport(uint32_t);
+    uint32_t platformExport();
+    void platformDestroy();
+
+    char* platformLock(const IntRect&, int* stride, LockOptions);
+    void platformUnlock();
+    void platformCopyToGLTexture(uint32_t target, uint32_t texture, const IntRect&, const IntPoint&);
+
+    PassOwnPtr<GraphicsContext> platformBeginPaint(const IntSize&, char* bits, int stride);
+
+protected:
+    LockOptions m_lockOptions;
+    Flags m_flags;
+
+private:
+    GraphicsSurface(const IntSize&, Flags);
+
+#if PLATFORM(QT)
+    static void didReleaseImage(void*);
+#endif
+
+private:
+    IntSize m_size;
+    PlatformGraphicsSurface m_platformSurface;
+    uint32_t m_texture;
+    uint32_t m_fbo;
+};
+
+}
+#endif // USE(GRAPHICS_SURFACE)
+
+#endif // GraphicsSurface_h
diff --git a/Source/WebCore/platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp b/Source/WebCore/platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp
new file mode 100644 (file)
index 0000000..b6a1a02
--- /dev/null
@@ -0,0 +1,178 @@
+/*
+ Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB.  If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "GraphicsSurface.h"
+
+#if USE(GRAPHICS_SURFACE) && OS(DARWIN)
+#include <CFNumber.h>
+#include <CGLContext.h>
+#include <CGLCurrent.h>
+#include <CGLIOSurface.h>
+#include <IOSurface/IOSurface.h>
+
+
+namespace WebCore {
+
+uint32_t GraphicsSurface::platformExport()
+{
+    return IOSurfaceGetID(m_platformSurface);
+}
+
+static uint32_t createTexture(IOSurfaceRef handle)
+{
+    GLuint texture = 0;
+    GLuint format = GL_BGRA;
+    GLuint type = GL_UNSIGNED_INT_8_8_8_8_REV;
+    GLuint internalFormat = GL_RGBA;
+    CGLContextObj context = CGLGetCurrentContext();
+    if (!context)
+        return 0;
+
+    GLint prevTexture;
+    GLboolean wasEnabled = glIsEnabled(GL_TEXTURE_RECTANGLE_ARB);
+    glGetIntegerv(GL_TEXTURE_RECTANGLE_ARB, &prevTexture);
+    if (!wasEnabled)
+        glEnable(GL_TEXTURE_RECTANGLE_ARB);
+    glGenTextures(1, &texture);
+    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture);
+    CGLError error = CGLTexImageIOSurface2D(context, GL_TEXTURE_RECTANGLE_ARB, internalFormat, IOSurfaceGetWidth(handle), IOSurfaceGetHeight(handle), format, type, handle, 0);
+    if (error) {
+        glDeleteTextures(1, &texture);
+        texture = 0;
+    }
+
+    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, prevTexture);
+    if (!wasEnabled)
+        glDisable(GL_TEXTURE_RECTANGLE_ARB);
+    return texture;
+}
+
+void GraphicsSurface::platformCopyToGLTexture(uint32_t target, uint32_t id, const IntRect& targetRect, const IntPoint& offset)
+{
+    glPushAttrib(GL_ALL_ATTRIB_BITS);
+    if (!m_texture)
+        m_texture = createTexture(m_platformSurface);
+    if (!m_fbo)
+        glGenFramebuffers(1, &m_fbo);
+    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
+    glEnable(GL_TEXTURE_RECTANGLE_ARB);
+    glEnable(target);
+    glBindTexture(target, id);
+    glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo);
+    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, m_texture, 0);
+    glCopyTexSubImage2D(target, 0, targetRect.x(), targetRect.y(), offset.x(), offset.y(), targetRect.width(), targetRect.height());
+    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, 0, 0);
+    glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
+    glPopAttrib();
+}
+
+bool GraphicsSurface::platformCreate(const IntSize& size, Flags flags)
+{
+    unsigned pixelFormat = 'BGRA';
+    unsigned bytesPerElement = 4;
+    int width = size.width();
+    int height = size.height();
+
+    unsigned long bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, width * bytesPerElement);
+    if (!bytesPerRow)
+        return false;
+
+    unsigned long allocSize = IOSurfaceAlignProperty(kIOSurfaceAllocSize, height * bytesPerRow);
+    if (!allocSize)
+        return false;
+
+    const void *keys[7];
+    const void *values[7];
+    keys[0] = kIOSurfaceWidth;
+    values[0] = CFNumberCreate(0, kCFNumberIntType, &width);
+    keys[1] = kIOSurfaceHeight;
+    values[1] = CFNumberCreate(0, kCFNumberIntType, &height);
+    keys[2] = kIOSurfacePixelFormat;
+    values[2] = CFNumberCreate(0, kCFNumberIntType, &pixelFormat);
+    keys[3] = kIOSurfaceBytesPerElement;
+    values[3] = CFNumberCreate(0, kCFNumberIntType, &bytesPerElement);
+    keys[4] = kIOSurfaceBytesPerRow;
+    values[4] = CFNumberCreate(0, kCFNumberLongType, &bytesPerRow);
+    keys[5] = kIOSurfaceAllocSize;
+    values[5] = CFNumberCreate(0, kCFNumberLongType, &allocSize);
+    keys[6] = kIOSurfaceIsGlobal;
+    values[6] = (flags & GraphicsSurface::SupportsSharing) ? kCFBooleanTrue : kCFBooleanFalse;
+
+    CFDictionaryRef dict = CFDictionaryCreate(0, keys, values, 7, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+    for (unsigned i = 0; i < 7; i++)
+        CFRelease(values[i]);
+
+    m_platformSurface = IOSurfaceCreate(dict);
+    return !!m_platformSurface;
+}
+
+bool GraphicsSurface::platformImport(uint32_t token)
+{
+    m_platformSurface = IOSurfaceLookup(token);
+    return !!m_platformSurface;
+}
+
+static int ioSurfaceLockOptions(int lockOptions)
+{
+    int options = 0;
+    if (lockOptions & GraphicsSurface::ReadOnly)
+        options |= kIOSurfaceLockReadOnly;
+    if (!(lockOptions & GraphicsSurface::RetainPixels))
+        options |= kIOSurfaceLockAvoidSync;
+    return options;
+}
+
+static int ioSurfaceUnlockOptions(int lockOptions)
+{
+    int options = 0;
+    if (lockOptions & GraphicsSurface::ReadOnly)
+        options |= (kIOSurfaceLockAvoidSync | kIOSurfaceLockReadOnly);
+    return options;
+}
+
+char* GraphicsSurface::platformLock(const IntRect& rect, int* outputStride, LockOptions lockOptions)
+{
+    m_lockOptions = lockOptions;
+    IOSurfaceLock(m_platformSurface, ioSurfaceLockOptions(m_lockOptions), 0);
+
+    int stride = IOSurfaceGetBytesPerRow(m_platformSurface);
+    if (outputStride)
+        *outputStride = stride;
+
+    char* base = static_cast<char*>(IOSurfaceGetBaseAddress(m_platformSurface));
+    return base + stride * rect.y() + rect.x() * 4;
+}
+
+void GraphicsSurface::platformUnlock()
+{
+    IOSurfaceUnlock(m_platformSurface, ioSurfaceUnlockOptions(m_lockOptions) & (~kIOSurfaceLockAvoidSync), 0);
+}
+
+void GraphicsSurface::platformDestroy()
+{
+    if (m_fbo)
+        glDeleteFramebuffers(1, &m_fbo);
+    if (m_texture)
+        glDeleteTextures(1, &m_texture);
+    CFRelease(IOSurfaceRef(m_platformSurface));
+}
+
+}
+#endif
diff --git a/Source/WebCore/platform/graphics/surfaces/qt/GraphicsSurfaceQt.cpp b/Source/WebCore/platform/graphics/surfaces/qt/GraphicsSurfaceQt.cpp
new file mode 100644 (file)
index 0000000..1aab6c8
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB.  If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "GraphicsSurface.h"
+
+#if USE(GRAPHICS_SURFACE) && PLATFORM(QT)
+
+#include "BitmapImage.h"
+#include <QImage>
+#include <QPainter>
+#include <QPixmap>
+
+namespace WebCore {
+void GraphicsSurface::didReleaseImage(void* data)
+{
+    GraphicsSurface* surface = static_cast<GraphicsSurface*>(data);
+    surface->platformUnlock();
+}
+
+PassOwnPtr<GraphicsContext> GraphicsSurface::platformBeginPaint(const IntSize& size, char* bits, int stride)
+{
+    QImage::Format format = (flags() & SupportsAlpha) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
+
+    // The image and painter will be released when the returned GraphicsContext is released.
+    QImage* image = new QImage(reinterpret_cast<uchar*>(bits), size.width(), size.height(), stride, format, didReleaseImage, this);
+    QPainter* painter = new QPainter(image);
+    OwnPtr<GraphicsContext> graphicsContext = adoptPtr(new GraphicsContext(painter));
+    graphicsContext->takeOwnershipOfPlatformContext();
+    return graphicsContext.release();
+}
+
+PassRefPtr<Image> GraphicsSurface::createReadOnlyImage(const IntRect& rect)
+{
+    int stride;
+    QImage::Format format = (flags() & SupportsAlpha) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
+    char* data = platformLock(rect, &stride, RetainPixels | ReadOnly);
+    QImage image(reinterpret_cast<uchar*>(data), rect.width(), rect.height(), stride, format, didReleaseImage, this);
+    return BitmapImage::create(new QPixmap(QPixmap::fromImage(image)));
+}
+
+}
+#endif
index a287dbd..0f2cea1 100644 (file)
@@ -64,6 +64,7 @@ public:
     }
 
     virtual ~BitmapTexture() { }
+    virtual bool isBackedByOpenGL() const { return false; }
 
     virtual IntSize size() const = 0;
     virtual void updateContents(Image*, const IntRect&, const IntPoint& offset) = 0;
index c3316e8..c34f2c4 100644 (file)
@@ -220,6 +220,14 @@ void TextureMapperGLData::initializeStencil()
     didModifyStencil = true;
 }
 
+BitmapTextureGL* toBitmapTextureGL(BitmapTexture* texture)
+{
+    if (!texture || !texture->isBackedByOpenGL())
+        return 0;
+
+    return static_cast<BitmapTextureGL*>(texture);
+}
+
 TextureMapperGL::TextureMapperGL()
     : m_data(new TextureMapperGLData)
     , m_context(0)
@@ -375,6 +383,12 @@ bool BitmapTextureGL::canReuseWith(const IntSize& contentsSize, Flags)
     return contentsSize == m_textureSize;
 }
 
+#if OS(DARWIN)
+#define DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
+#else
+#define DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE GL_UNSIGNED_BYTE
+#endif
+
 void BitmapTextureGL::didReset()
 {
     if (!m_id)
@@ -390,7 +404,7 @@ void BitmapTextureGL::didReset()
     GL_CMD(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
     GL_CMD(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
     GL_CMD(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
-    GL_CMD(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_textureSize.width(), m_textureSize.height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, 0));
+    GL_CMD(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_textureSize.width(), m_textureSize.height(), 0, GL_BGRA, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, 0));
 }
 
 static void swizzleBGRAToRGBA(uint32_t* data, const IntSize& size, int stride = 0)
@@ -436,7 +450,7 @@ void BitmapTextureGL::updateContents(const void* data, const IntRect& targetRect
         swizzleBGRAToRGBA(static_cast<uint32_t*>(const_cast<void*>(data)), targetRect.size(), bytesPerLine / 4);
 
     if (bytesPerLine == targetRect.width() / 4 && sourceOffset == IntPoint::zero()) {
-        GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, GL_UNSIGNED_BYTE, (const char*)data));
+        GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, (const char*)data));
         return;
     }
 
@@ -445,7 +459,7 @@ void BitmapTextureGL::updateContents(const void* data, const IntRect& targetRect
         const char* bits = static_cast<const char*>(data);
         for (int y = 0; y < targetRect.height(); ++y) {
             const char *row = bits + ((sourceOffset.y() + y) * bytesPerLine + sourceOffset.x() * 4);
-            GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y() + y, targetRect.width(), 1, glFormat, GL_UNSIGNED_BYTE, row));
+            GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y() + y, targetRect.width(), 1, glFormat, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, row));
         }
         return;
     }
@@ -454,7 +468,7 @@ void BitmapTextureGL::updateContents(const void* data, const IntRect& targetRect
     GL_CMD(glPixelStorei(GL_UNPACK_ROW_LENGTH, bytesPerLine / 4));
     GL_CMD(glPixelStorei(GL_UNPACK_SKIP_ROWS, sourceOffset.y()));
     GL_CMD(glPixelStorei(GL_UNPACK_SKIP_PIXELS, sourceOffset.x()));
-    GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, GL_UNSIGNED_BYTE, (const char*)data));
+    GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, DEFAULT_TEXTURE_PIXEL_TRANSFER_TYPE, (const char*)data));
     GL_CMD(glPixelStorei(GL_UNPACK_ROW_LENGTH, 0));
     GL_CMD(glPixelStorei(GL_UNPACK_SKIP_ROWS, 0));
     GL_CMD(glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0));
index b6c6e42..f2ea83b 100644 (file)
@@ -88,6 +88,7 @@ public:
     void setTextureMapper(TextureMapperGL* texmap) { m_textureMapper = texmap; }
     void updateContents(Image*, const IntRect&, const IntPoint&);
     virtual void updateContents(const void*, const IntRect& target, const IntPoint& sourceOffset, int bytesPerLine);
+    virtual bool isBackedByOpenGL() const { return true; }
 
 private:
     GLuint m_id;
@@ -111,9 +112,9 @@ private:
 
 typedef uint64_t ImageUID;
 ImageUID uidForImage(Image*);
+BitmapTextureGL* toBitmapTextureGL(BitmapTexture*);
 
-};
-
+}
 #endif
 
 #endif
index 47605d8..04690f1 100644 (file)
@@ -1,3 +1,67 @@
+2012-04-10  No'am Rosenthal  <noam.rosenthal@nokia.com>
+
+        [Qt][WK2] Manage graphics buffers in the web process
+        https://bugs.webkit.org/show_bug.cgi?id=78675
+
+        Added ShareableSurface, a class allowing the use of GPU-enabled
+        surfaces for bitmap transfer between the web and UI processes.
+        Since GraphicsSurfaces may not always be available, ShareableSurface
+        uses a standard ShareableBitmap as a fallback backend.
+
+        The necessary plumbing was added in WebKit2 for passing updates via
+        ShareableSurfaces instead of ShareableBitmaps. SurfaceUpdateInfo was
+        added, as to not make UpdateInfo more complicated.
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        * Shared/ShareableSurface.cpp: Added.
+        * Shared/ShareableSurface.h: Added.
+        * Shared/SurfaceUpdateInfo.cpp: Added.
+        * Shared/SurfaceUpdateInfo.h: Added.
+        * Target.pri:
+        * UIProcess/LayerTreeHostProxy.cpp:
+        (WebKit::LayerTreeHostProxy::createTileForLayer):
+        (WebKit::LayerTreeHostProxy::updateTileForLayer):
+        * UIProcess/LayerTreeHostProxy.h:
+        (LayerTreeHostProxy):
+        * UIProcess/LayerTreeHostProxy.messages.in:
+        * UIProcess/WebLayerTreeRenderer.cpp:
+        (WebKit::WebLayerTreeRenderer::updateTile):
+        * UIProcess/WebLayerTreeRenderer.h:
+        (TileUpdate):
+        (WebKit::WebLayerTreeRenderer::TileUpdate::TileUpdate):
+        * UIProcess/qt/LayerBackingStore.cpp:
+        (WebKit::LayerBackingStoreTile::swapBuffers):
+        (WebKit::LayerBackingStoreTile::setBackBuffer):
+        (WebKit::LayerBackingStore::updateTile):
+        * UIProcess/qt/LayerBackingStore.h:
+        (LayerBackingStoreTile):
+        (LayerBackingStore):
+        * WebProcess/WebCoreSupport/WebGraphicsLayer.cpp:
+        (WebCore::WebGraphicsLayer::beginContentUpdate):
+        (WebCore::WebGraphicsLayer::createTile):
+        (WebCore::WebGraphicsLayer::updateTile):
+        * WebProcess/WebCoreSupport/WebGraphicsLayer.h:
+        (WebGraphicsLayerClient):
+        (WebGraphicsLayer):
+        * WebProcess/WebPage/TiledBackingStoreRemoteTile.cpp:
+        (WebKit::TiledBackingStoreRemoteTile::updateBackBuffer):
+        * WebProcess/WebPage/TiledBackingStoreRemoteTile.h:
+        (WebKit):
+        (TiledBackingStoreRemoteTileClient):
+        * WebProcess/WebPage/UpdateAtlas.cpp:
+        (WebKit::UpdateAtlas::UpdateAtlas):
+        (WebKit::UpdateAtlas::beginPaintingOnAvailableBuffer):
+        * WebProcess/WebPage/UpdateAtlas.h:
+        (WebKit::UpdateAtlas::surface):
+        (WebKit::UpdateAtlas::size):
+        * WebProcess/WebPage/qt/LayerTreeHostQt.cpp:
+        (WebKit::LayerTreeHostQt::createTile):
+        (WebKit::LayerTreeHostQt::updateTile):
+        (WebKit::LayerTreeHostQt::beginContentUpdate):
+        * WebProcess/WebPage/qt/LayerTreeHostQt.h:
+        (LayerTreeHostQt):
+
 2012-04-10  Patrick Gansterer  <paroga@webkit.org>
 
         [CMake] Enable USE_FOLDERS property
diff --git a/Source/WebKit2/Shared/ShareableSurface.cpp b/Source/WebKit2/Shared/ShareableSurface.cpp
new file mode 100644 (file)
index 0000000..cf10e16
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+ Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB.  If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "ShareableSurface.h"
+
+#include "WebCoreArgumentCoders.h"
+
+#if USE(TEXTURE_MAPPER)
+#include "TextureMapperGL.h"
+#endif
+
+using namespace WebCore;
+
+namespace WebKit {
+
+ShareableSurface::Handle::Handle()
+#if USE(GRAPHICS_SURFACE)
+    : m_graphicsSurfaceToken(0)
+#endif
+{
+}
+
+void ShareableSurface::Handle::encode(CoreIPC::ArgumentEncoder* encoder) const
+{
+    encoder->encode(m_size);
+    encoder->encode(m_flags);
+#if USE(GRAPHICS_SURFACE)
+    encoder->encode(m_graphicsSurfaceToken);
+    if (m_graphicsSurfaceToken)
+        return;
+#endif
+    encoder->encode(m_bitmapHandle);
+}
+
+bool ShareableSurface::Handle::decode(CoreIPC::ArgumentDecoder* decoder, Handle& handle)
+{
+    if (!decoder->decode(handle.m_size))
+        return false;
+    if (!decoder->decode(handle.m_flags))
+        return false;
+#if USE(GRAPHICS_SURFACE)
+    if (!decoder->decode(handle.m_graphicsSurfaceToken))
+        return false;
+    if (handle.m_graphicsSurfaceToken)
+        return true;
+#endif
+    if (!decoder->decode(handle.m_bitmapHandle))
+        return false;
+
+    return true;
+}
+
+PassRefPtr<ShareableSurface> ShareableSurface::create(const IntSize& size, ShareableBitmap::Flags flags, Hints hints)
+{
+#if USE(GRAPHICS_SURFACE)
+    if (hints & SupportsGraphicsSurface) {
+        RefPtr<ShareableSurface> surface = createWithSurface(size, flags);
+        if (surface)
+            return surface.release();
+    }
+#endif
+
+    return create(size, flags, ShareableBitmap::createShareable(size, flags));
+}
+
+#if USE(GRAPHICS_SURFACE)
+PassRefPtr<ShareableSurface> ShareableSurface::createWithSurface(const IntSize& size, ShareableBitmap::Flags flags)
+{
+    GraphicsSurface::Flags surfaceFlags =
+            GraphicsSurface::SupportsSoftwareWrite
+            | GraphicsSurface::SupportsCopyToTexture
+            | GraphicsSurface::SupportsSharing;
+
+    if (flags & ShareableBitmap::SupportsAlpha)
+        surfaceFlags |= GraphicsSurface::SupportsAlpha;
+
+    // This might return null, if the system is unable to provide a new graphics surface.
+    // In that case, this function would return null and allow falling back to ShareableBitmap.
+    RefPtr<GraphicsSurface> surface = GraphicsSurface::create(size, surfaceFlags);
+    if (!surface)
+        return 0;
+
+    ASSERT(surface);
+    return adoptRef(new ShareableSurface(size, flags, surface.release()));
+}
+#endif
+
+PassOwnPtr<WebCore::GraphicsContext> ShareableSurface::createGraphicsContext(const IntRect& rect)
+{    
+#if USE(GRAPHICS_SURFACE)
+    if (isBackedByGraphicsSurface())
+        return m_graphicsSurface->beginPaint(rect, 0 /* Write without retaining pixels*/);
+#endif
+
+    ASSERT(m_bitmap);
+    OwnPtr<GraphicsContext> graphicsContext = m_bitmap->createGraphicsContext();
+    graphicsContext->clip(rect);
+    graphicsContext->translate(rect.x(), rect.y());
+    return graphicsContext.release();
+}
+
+PassRefPtr<ShareableSurface> ShareableSurface::create(const IntSize& size, ShareableBitmap::Flags flags, PassRefPtr<ShareableBitmap> bitmap)
+{
+    return adoptRef(new ShareableSurface(size, flags, bitmap));
+}
+
+ShareableSurface::ShareableSurface(const IntSize& size, ShareableBitmap::Flags flags, PassRefPtr<ShareableBitmap> bitmap)
+    : m_size(size)
+    , m_flags(flags)
+    , m_bitmap(bitmap)
+{
+}
+
+#if USE(GRAPHICS_SURFACE)
+ShareableSurface::ShareableSurface(const WebCore::IntSize& size, ShareableBitmap::Flags flags, PassRefPtr<WebCore::GraphicsSurface> surface)
+    : m_size(size)
+    , m_flags(flags)
+    , m_graphicsSurface(surface)
+{
+}
+
+PassRefPtr<ShareableSurface> ShareableSurface::create(const IntSize& size, ShareableBitmap::Flags flags, PassRefPtr<GraphicsSurface> surface)
+{
+    return adoptRef(new ShareableSurface(size, flags, surface));
+}
+#endif
+
+ShareableSurface::~ShareableSurface()
+{
+}
+
+PassRefPtr<ShareableSurface> ShareableSurface::create(const Handle& handle)
+{
+#if USE(GRAPHICS_SURFACE)
+        RefPtr<GraphicsSurface> surface = GraphicsSurface::create(handle.m_size, handle.m_flags, handle.m_graphicsSurfaceToken);
+        if (surface)
+            return adoptRef(new ShareableSurface(handle.m_size, handle.m_flags, PassRefPtr<GraphicsSurface>(surface)));
+#endif
+
+    RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(handle.m_bitmapHandle);
+    if (!bitmap)
+        return 0;
+
+    return create(handle.m_size, handle.m_flags, bitmap.release());
+}
+
+bool ShareableSurface::createHandle(Handle& handle)
+{
+    handle.m_size = m_size;
+    handle.m_flags = m_flags;
+
+#if USE(GRAPHICS_SURFACE)
+    handle.m_graphicsSurfaceToken = m_graphicsSurface ? m_graphicsSurface->exportToken() : 0;
+    if (handle.m_graphicsSurfaceToken)
+        return true;
+#endif
+    if (!m_bitmap->createHandle(handle.m_bitmapHandle))
+        return false;
+
+    return true;
+}
+
+#if USE(TEXTURE_MAPPER)
+void ShareableSurface::copyToTexture(PassRefPtr<WebCore::BitmapTexture> passTexture, const IntRect& target, const IntPoint& sourceOffset)
+{
+    RefPtr<BitmapTexture> texture(passTexture);
+
+#if USE(GRAPHICS_SURFACE)
+    if (isBackedByGraphicsSurface()) {
+        RefPtr<BitmapTextureGL> textureGL = toBitmapTextureGL(texture.get());
+        if (textureGL) {
+            uint32_t textureID = textureGL->id();
+            uint32_t textureTarget = textureGL->textureTarget();
+            m_graphicsSurface->copyToGLTexture(textureTarget, textureID, target, sourceOffset);
+            return;
+        }
+
+        RefPtr<Image> image = m_graphicsSurface->createReadOnlyImage(IntRect(sourceOffset, target.size()));
+        texture->updateContents(image.get(), target, IntPoint::zero());
+    }
+#endif
+
+    ASSERT(m_bitmap);
+    RefPtr<Image> image = m_bitmap->createImage();
+    texture->updateContents(image.get(), target, sourceOffset);
+    return;
+}
+#endif // USE(TEXTURE_MAPPER)
+
+} // namespace WebKit
diff --git a/Source/WebKit2/Shared/ShareableSurface.h b/Source/WebKit2/Shared/ShareableSurface.h
new file mode 100644 (file)
index 0000000..1d2e098
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB.  If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef ShareableSurface_h
+#define ShareableSurface_h
+
+#include "ShareableBitmap.h"
+
+#if USE(GRAPHICS_SURFACE)
+#include "GraphicsSurface.h"
+#endif
+
+namespace WebCore {
+class BitmapTexture;
+class Image;
+class GraphicsContext;
+}
+
+namespace WebKit {
+
+class ShareableSurface : public RefCounted<ShareableSurface> {
+public:
+    enum Hint {
+        SupportsGraphicsSurface = 0x01
+    };
+
+    typedef unsigned Hints;
+
+    class Handle {
+        WTF_MAKE_NONCOPYABLE(Handle);
+    public:
+        Handle();
+
+        bool isNull() const;
+
+        void encode(CoreIPC::ArgumentEncoder*) const;
+        static bool decode(CoreIPC::ArgumentDecoder*, Handle&);
+
+    private:
+        friend class ShareableSurface;
+        mutable ShareableBitmap::Handle m_bitmapHandle;
+#if USE(GRAPHICS_SURFACE)
+        uint32_t m_graphicsSurfaceToken;
+#endif
+        WebCore::IntSize m_size;
+        ShareableBitmap::Flags m_flags;
+    };
+
+    // Create a new ShareableSurface, and allocate either a GraphicsSurface or a ShareableBitmap as backing.
+    static PassRefPtr<ShareableSurface> create(const WebCore::IntSize&, ShareableBitmap::Flags, Hints);
+
+    // Create a shareable surface from a handle.
+    static PassRefPtr<ShareableSurface> create(const Handle&);
+
+    ShareableBitmap::Flags flags() const { return m_flags; }
+
+    // Create a handle.
+    bool createHandle(Handle&);
+
+    ~ShareableSurface();
+
+    const WebCore::IntSize& size() const { return m_size; }
+    WebCore::IntRect bounds() const { return WebCore::IntRect(WebCore::IntPoint(), size()); }
+
+    // Create a graphics context that can be used to paint into the backing store.
+    PassOwnPtr<WebCore::GraphicsContext> createGraphicsContext(const WebCore::IntRect&);
+
+#if USE(TEXTURE_MAPPER)
+    void copyToTexture(PassRefPtr<WebCore::BitmapTexture>, const WebCore::IntRect& target, const WebCore::IntPoint& sourceOffset);
+#endif
+
+private:
+    ShareableSurface(const WebCore::IntSize&, ShareableBitmap::Flags, PassRefPtr<ShareableBitmap>);
+
+    // Create a ShareableSurface referencing an existing ShareableBitmap.
+    static PassRefPtr<ShareableSurface> create(const WebCore::IntSize&, ShareableBitmap::Flags, PassRefPtr<ShareableBitmap>);
+
+#if USE(GRAPHICS_SURFACE)
+    ShareableSurface(const WebCore::IntSize&, ShareableBitmap::Flags, PassRefPtr<WebCore::GraphicsSurface>);
+    // Create a shareable bitmap backed by a graphics surface.
+    static PassRefPtr<ShareableSurface> createWithSurface(const WebCore::IntSize&, ShareableBitmap::Flags);
+    // Create a ShareableSurface referencing an existing GraphicsSurface.
+    static PassRefPtr<ShareableSurface> create(const WebCore::IntSize&, ShareableBitmap::Flags, PassRefPtr<WebCore::GraphicsSurface>);
+
+    bool isBackedByGraphicsSurface() const { return !!m_graphicsSurface; }
+#endif
+
+    WebCore::IntSize m_size;
+    ShareableBitmap::Flags m_flags;
+    RefPtr<ShareableBitmap> m_bitmap;
+
+#if USE(GRAPHICS_SURFACE)
+    RefPtr<WebCore::GraphicsSurface> m_graphicsSurface;
+#endif
+};
+
+} // namespace WebKit
+
+#endif // ShareableSurface_h
diff --git a/Source/WebKit2/Shared/SurfaceUpdateInfo.cpp b/Source/WebKit2/Shared/SurfaceUpdateInfo.cpp
new file mode 100644 (file)
index 0000000..1533379
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB.  If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "SurfaceUpdateInfo.h"
+
+#include "WebCoreArgumentCoders.h"
+
+namespace WebKit {
+
+void SurfaceUpdateInfo::encode(CoreIPC::ArgumentEncoder* encoder) const
+{
+    encoder->encode(updateRect);
+    encoder->encode(scaleFactor);
+    encoder->encode(surfaceHandle);
+    encoder->encode(surfaceOffset);
+}
+
+bool SurfaceUpdateInfo::decode(CoreIPC::ArgumentDecoder* decoder, SurfaceUpdateInfo& result)
+{
+    if (!decoder->decode(result.updateRect))
+        return false;
+    if (!decoder->decode(result.scaleFactor))
+        return false;
+    if (!decoder->decode(result.surfaceHandle))
+        return false;
+    if (!decoder->decode(result.surfaceOffset))
+        return false;
+
+    return true;
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit2/Shared/SurfaceUpdateInfo.h b/Source/WebKit2/Shared/SurfaceUpdateInfo.h
new file mode 100644 (file)
index 0000000..01d60d2
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB.  If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SurfaceUpdateInfo_h
+#define SurfaceUpdateInfo_h
+
+#include "ShareableSurface.h"
+#include <WebCore/IntRect.h>
+#include <wtf/Noncopyable.h>
+
+namespace CoreIPC {
+class ArgumentDecoder;
+class ArgumentEncoder;
+}
+
+namespace WebKit {
+
+class SurfaceUpdateInfo {
+    WTF_MAKE_NONCOPYABLE(SurfaceUpdateInfo);
+
+public:
+    SurfaceUpdateInfo() { }
+
+    void encode(CoreIPC::ArgumentEncoder*) const;
+    static bool decode(CoreIPC::ArgumentDecoder*, SurfaceUpdateInfo&);
+
+    // The rect to be updated.
+    WebCore::IntRect updateRect;
+
+    // The page scale factor used to render this update.
+    float scaleFactor;
+
+    // The handle of the shareable bitmap containing the updates. Will be null if there are no updates.
+    ShareableSurface::Handle surfaceHandle;
+
+    // The offset in the bitmap where the rendered contents are.
+    WebCore::IntPoint surfaceOffset;
+};
+
+} // namespace WebKit
+
+#endif // UpdateInfo_h
index 50bc150..d8609d0 100644 (file)
@@ -67,6 +67,7 @@ HEADERS += \
     Shared/API/c/qt/WKImageQt.h \
     Shared/APIClientTraits.h \
     Shared/ShareableBitmap.h \
+    Shared/ShareableSurface.h \
     Shared/CacheModel.h \
     Shared/ChildProcess.h \
     Shared/DictionaryPopupInfo.h \
@@ -90,6 +91,7 @@ HEADERS += \
     Shared/SessionState.h \
     Shared/StatisticsData.h \
     Shared/StringPairVector.h \
+    Shared/SurfaceUpdateInfo.h \
     Shared/UpdateInfo.h \
     Shared/UserMessageCoders.h \
     Shared/VisitedLinkTable.h \
@@ -426,6 +428,7 @@ SOURCES += \
     Shared/Plugins/Netscape/NetscapePluginModuleNone.cpp \
     Shared/Plugins/Netscape/x11/NetscapePluginModuleX11.cpp \
     Shared/ShareableBitmap.cpp \
+    Shared/ShareableSurface.cpp \
     Shared/Plugins/NPRemoteObjectMap.cpp \
     Shared/Plugins/NPIdentifierData.cpp \
     Shared/Plugins/NPObjectMessageReceiver.cpp \
@@ -447,6 +450,7 @@ SOURCES += \
     Shared/SecurityOriginData.cpp \
     Shared/SessionState.cpp \
     Shared/StatisticsData.cpp \
+    Shared/SurfaceUpdateInfo.cpp \
     Shared/UpdateInfo.cpp \
     Shared/VisitedLinkTable.cpp \
     Shared/WebBackForwardListItem.cpp \
index f790627..31b60e5 100644 (file)
@@ -66,19 +66,16 @@ void LayerTreeHostProxy::dispatchUpdate(const Function<void()>& function)
     m_renderer->appendUpdate(function);
 }
 
-void LayerTreeHostProxy::createTileForLayer(int layerID, int tileID, const WebKit::UpdateInfo& updateInfo)
+void LayerTreeHostProxy::createTileForLayer(int layerID, int tileID, const IntRect& targetRect, const WebKit::SurfaceUpdateInfo& updateInfo)
 {
-    dispatchUpdate(bind(&WebLayerTreeRenderer::createTile, m_renderer.get(), layerID, tileID, updateInfo.updateScaleFactor));
-    updateTileForLayer(layerID, tileID, updateInfo);
+    dispatchUpdate(bind(&WebLayerTreeRenderer::createTile, m_renderer.get(), layerID, tileID, updateInfo.scaleFactor));
+    updateTileForLayer(layerID, tileID, targetRect, updateInfo);
 }
 
-void LayerTreeHostProxy::updateTileForLayer(int layerID, int tileID, const WebKit::UpdateInfo& updateInfo)
+void LayerTreeHostProxy::updateTileForLayer(int layerID, int tileID, const IntRect& targetRect, const WebKit::SurfaceUpdateInfo& updateInfo)
 {
-    ASSERT(updateInfo.updateRects.size() == 1);
-    IntRect sourceRect = updateInfo.updateRects.first();
-    IntRect targetRect = updateInfo.updateRectBounds;
-    RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(updateInfo.bitmapHandle);
-    dispatchUpdate(bind(&WebLayerTreeRenderer::updateTile, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(sourceRect, targetRect, bitmap, updateInfo.bitmapOffset)));
+    RefPtr<ShareableSurface> surface = ShareableSurface::create(updateInfo.surfaceHandle);
+    dispatchUpdate(bind(&WebLayerTreeRenderer::updateTile, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(updateInfo.updateRect, targetRect, surface, updateInfo.surfaceOffset)));
 }
 
 void LayerTreeHostProxy::removeTileForLayer(int layerID, int tileID)
index a90ce40..6c163c8 100644 (file)
@@ -25,6 +25,7 @@
 #include "BackingStore.h"
 #include "DrawingAreaProxy.h"
 #include "Region.h"
+#include "SurfaceUpdateInfo.h"
 #include "WebLayerTreeInfo.h"
 #include <WebCore/GraphicsContext.h>
 #include <WebCore/GraphicsLayer.h>
@@ -57,8 +58,8 @@ public:
     void purgeGLResources();
     void setVisibleContentsRect(const WebCore::IntRect&, float scale, const WebCore::FloatPoint& trajectory);
     void didRenderFrame();
-    void createTileForLayer(int layerID, int tileID, const WebKit::UpdateInfo&);
-    void updateTileForLayer(int layerID, int tileID, const WebKit::UpdateInfo&);
+    void createTileForLayer(int layerID, int tileID, const WebCore::IntRect&, const SurfaceUpdateInfo&);
+    void updateTileForLayer(int layerID, int tileID, const WebCore::IntRect&, const SurfaceUpdateInfo&);
     void removeTileForLayer(int layerID, int tileID);
     void createDirectlyCompositedImage(int64_t, const WebKit::ShareableBitmap::Handle&);
     void destroyDirectlyCompositedImage(int64_t);
index 30103e3..28bbad1 100644 (file)
@@ -23,8 +23,8 @@ messages -> LayerTreeHostProxy {
     SetCompositingLayerChildren(uint32_t id, Vector<uint32_t> children)
     SetRootCompositingLayer(uint32_t id)
     DeleteCompositingLayer(uint32_t id)
-    CreateTileForLayer(uint32_t layerID, int tileID, WebKit::UpdateInfo updateInfo)
-    UpdateTileForLayer(uint32_t layerID, int tileID, WebKit::UpdateInfo updateInfo)
+    CreateTileForLayer(uint32_t layerID, int tileID, WebCore::IntRect targetRect, WebKit::SurfaceUpdateInfo updateInfo)
+    UpdateTileForLayer(uint32_t layerID, int tileID, WebCore::IntRect targetRect, WebKit::SurfaceUpdateInfo updateInfo)
     RemoveTileForLayer(uint32_t layerID, int tileID)
     CreateDirectlyCompositedImage(int64_t key, WebKit::ShareableBitmap::Handle handle)
     DestroyDirectlyCompositedImage(int64_t key)
index d6e72e6..abbd3aa 100644 (file)
@@ -270,7 +270,7 @@ void WebLayerTreeRenderer::removeTile(WebLayerID layerID, int tileID)
 void WebLayerTreeRenderer::updateTile(WebLayerID layerID, int tileID, const TileUpdate& update)
 {
     RefPtr<LayerBackingStore> backingStore = getBackingStore(layerID);
-    backingStore->updateTile(tileID, update.sourceRect, update.targetRect, update.bitmap, update.offset);
+    backingStore->updateTile(tileID, update.sourceRect, update.targetRect, update.surface, update.offset);
     m_backingStoresWithPendingBuffers.add(backingStore);
 }
 
index 181be0c..357b087 100644 (file)
@@ -21,8 +21,8 @@
 #define WebLayerTreeRenderer_h
 
 #if USE(UI_SIDE_COMPOSITING)
-
 #include "BackingStore.h"
+#include "ShareableSurface.h"
 #include "TextureMapper.h"
 #include "TextureMapperBackingStore.h"
 #include "WebLayerTreeInfo.h"
@@ -48,12 +48,12 @@ public:
     struct TileUpdate {
         WebCore::IntRect sourceRect;
         WebCore::IntRect targetRect;
-        RefPtr<ShareableBitmap> bitmap;
+        RefPtr<ShareableSurface> surface;
         WebCore::IntPoint offset;
-        TileUpdate(const WebCore::IntRect& source, const WebCore::IntRect& target, PassRefPtr<ShareableBitmap> newBitmap, const WebCore::IntPoint& newOffset)
+        TileUpdate(const WebCore::IntRect& source, const WebCore::IntRect& target, PassRefPtr<ShareableSurface> newSurface, const WebCore::IntPoint& newOffset)
             : sourceRect(source)
             , targetRect(target)
-            , bitmap(newBitmap)
+            , surface(newSurface)
             , offset(newOffset)
         {
         }
index fee0c90..799c953 100644 (file)
@@ -31,7 +31,7 @@ namespace WebKit {
 
 void LayerBackingStoreTile::swapBuffers(WebCore::TextureMapper* textureMapper)
 {
-    if (!m_backBuffer)
+    if (!m_surface)
         return;
 
     FloatRect targetRect(m_targetRect);
@@ -48,19 +48,19 @@ void LayerBackingStoreTile::swapBuffers(WebCore::TextureMapper* textureMapper)
         shouldReset = true;
     }
 
-    QImage qImage = m_backBuffer->createQImage();
     if (shouldReset)
-        texture->reset(m_sourceRect.size(), qImage.hasAlphaChannel() ? BitmapTexture::SupportsAlpha : 0);
-    texture->updateContents(qImage.constBits(), m_sourceRect, m_bitmapOffset, qImage.bytesPerLine());
-    m_backBuffer.clear();
+        texture->reset(m_targetRect.size(), m_surface->flags() & ShareableBitmap::SupportsAlpha ? BitmapTexture::SupportsAlpha : 0);
+
+    m_surface->copyToTexture(texture, m_sourceRect, m_surfaceOffset);
+    m_surface.clear();
 }
 
-void LayerBackingStoreTile::setBackBuffer(const IntRect& targetRect, const IntRect& sourceRect, PassRefPtr<ShareableBitmap> buffer, const IntPoint& offset)
+void LayerBackingStoreTile::setBackBuffer(const IntRect& targetRect, const IntRect& sourceRect, PassRefPtr<ShareableSurface> buffer, const IntPoint& offset)
 {
     m_sourceRect = sourceRect;
     m_targetRect = targetRect;
-    m_bitmapOffset = offset;
-    m_backBuffer = buffer;
+    m_surfaceOffset = offset;
+    m_surface = buffer;
 }
 
 void LayerBackingStore::createTile(int id, float scale)
@@ -75,7 +75,7 @@ void LayerBackingStore::removeTile(int id)
 }
 
 
-void LayerBackingStore::updateTile(int id, const IntRect& sourceRect, const IntRect& targetRect, PassRefPtr<ShareableBitmap> backBuffer, const IntPoint& offset)
+void LayerBackingStore::updateTile(int id, const IntRect& sourceRect, const IntRect& targetRect, PassRefPtr<ShareableSurface> backBuffer, const IntPoint& offset)
 {
     HashMap<int, LayerBackingStoreTile>::iterator it = m_tiles.find(id);
     ASSERT(it != m_tiles.end());
index a241e4c..2852bca 100644 (file)
@@ -22,7 +22,7 @@
 
 #if USE(UI_SIDE_COMPOSITING)
 
-#include "ShareableBitmap.h"
+#include "ShareableSurface.h"
 #include "TextureMapper.h"
 #include "TextureMapperBackingStore.h"
 #include <wtf/HashMap.h>
@@ -39,13 +39,13 @@ public:
 
     inline float scale() const { return m_scale; }
     void swapBuffers(WebCore::TextureMapper*);
-    void setBackBuffer(const WebCore::IntRect&, const WebCore::IntRect&, PassRefPtr<ShareableBitmap> buffer, const WebCore::IntPoint&);
+    void setBackBuffer(const WebCore::IntRect&, const WebCore::IntRect&, PassRefPtr<ShareableSurface> buffer, const WebCore::IntPoint&);
 
 private:
-    RefPtr<ShareableBitmap> m_backBuffer;
+    RefPtr<ShareableSurface> m_surface;
     WebCore::IntRect m_sourceRect;
     WebCore::IntRect m_targetRect;
-    WebCore::IntPoint m_bitmapOffset;
+    WebCore::IntPoint m_surfaceOffset;
     float m_scale;
 };
 
@@ -53,7 +53,7 @@ class LayerBackingStore : public WebCore::TextureMapperBackingStore {
 public:
     void createTile(int, float);
     void removeTile(int);
-    void updateTile(int, const WebCore::IntRect&, const WebCore::IntRect&, PassRefPtr<ShareableBitmap>, const WebCore::IntPoint&);
+    void updateTile(int, const WebCore::IntRect&, const WebCore::IntRect&, PassRefPtr<ShareableSurface>, const WebCore::IntPoint&);
     static PassRefPtr<LayerBackingStore> create() { return adoptRef(new LayerBackingStore); }
     void commitTileOperations(WebCore::TextureMapper*);
     PassRefPtr<WebCore::BitmapTexture> texture() const;
index 3af6257..bae9a0f 100644 (file)
@@ -553,19 +553,19 @@ Color WebGraphicsLayer::tiledBackingStoreBackgroundColor() const
     return contentsOpaque() ? Color::white : Color::transparent;
 }
 
-PassOwnPtr<WebCore::GraphicsContext> WebGraphicsLayer::beginContentUpdate(const WebCore::IntSize& size, ShareableBitmap::Handle& handle, WebCore::IntPoint& offset)
+PassOwnPtr<WebCore::GraphicsContext> WebGraphicsLayer::beginContentUpdate(const WebCore::IntSize& size, ShareableSurface::Handle& handle, WebCore::IntPoint& offset)
 {
     return m_webGraphicsLayerClient->beginContentUpdate(size, contentsOpaque() ? 0 : ShareableBitmap::SupportsAlpha, handle, offset);
 }
 
-void WebGraphicsLayer::createTile(int tileID, const UpdateInfo& updateInfo)
+void WebGraphicsLayer::createTile(int tileID, const SurfaceUpdateInfo& updateInfo, const IntRect& targetRect)
 {
-    m_webGraphicsLayerClient->createTile(id(), tileID, updateInfo);
+    m_webGraphicsLayerClient->createTile(id(), tileID, updateInfo, targetRect);
 }
 
-void WebGraphicsLayer::updateTile(int tileID, const UpdateInfo& updateInfo)
+void WebGraphicsLayer::updateTile(int tileID, const SurfaceUpdateInfo& updateInfo, const IntRect& targetRect)
 {
-    m_webGraphicsLayerClient->updateTile(id(), tileID, updateInfo);
+    m_webGraphicsLayerClient->updateTile(id(), tileID, updateInfo, targetRect);
 }
 
 void WebGraphicsLayer::removeTile(int tileID)
index 27fec55..5329cdc 100644 (file)
@@ -47,8 +47,8 @@ namespace WebKit {
 class WebGraphicsLayerClient {
 public:
     // TiledBackingStoreRemoteTileClient
-    virtual void createTile(WebLayerID, int tileID, const UpdateInfo&) = 0;
-    virtual void updateTile(WebLayerID, int tileID, const UpdateInfo&) = 0;
+    virtual void createTile(WebLayerID, int tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&) = 0;
+    virtual void updateTile(WebLayerID, int tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&) = 0;
     virtual void removeTile(WebLayerID, int tileID) = 0;
 
     virtual WebCore::IntRect visibleContentsRect() const = 0;
@@ -59,7 +59,7 @@ public:
     virtual void syncLayerChildren(WebLayerID, const Vector<WebLayerID>&) = 0;
     virtual void attachLayer(WebCore::WebGraphicsLayer*) = 0;
     virtual void detachLayer(WebCore::WebGraphicsLayer*) = 0;
-    virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, ShareableBitmap::Flags, ShareableBitmap::Handle&, WebCore::IntPoint&) = 0;
+    virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, ShareableBitmap::Flags, ShareableSurface::Handle&, WebCore::IntPoint&) = 0;
 };
 }
 
@@ -126,10 +126,10 @@ public:
     virtual Color tiledBackingStoreBackgroundColor() const;
 
     // TiledBackingStoreRemoteTileClient
-    virtual void createTile(int tileID, const WebKit::UpdateInfo&);
-    virtual void updateTile(int tileID, const WebKit::UpdateInfo&);
+    virtual void createTile(int tileID, const WebKit::SurfaceUpdateInfo&, const WebCore::IntRect&);
+    virtual void updateTile(int tileID, const WebKit::SurfaceUpdateInfo&, const WebCore::IntRect&);
     virtual void removeTile(int tileID);
-    virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, WebKit::ShareableBitmap::Handle&, WebCore::IntPoint&);
+    virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, WebKit::ShareableSurface::Handle&, WebCore::IntPoint&);
 
     void setWebGraphicsLayerClient(WebKit::WebGraphicsLayerClient*);
     void syncChildren();
index aeb6ebc..2125600 100644 (file)
@@ -30,8 +30,8 @@
 
 #include "GraphicsContext.h"
 #include "ImageBuffer.h"
+#include "SurfaceUpdateInfo.h"
 #include "TiledBackingStoreClient.h"
-#include "UpdateInfo.h"
 
 using namespace WebCore;
 
@@ -72,27 +72,25 @@ Vector<IntRect> TiledBackingStoreRemoteTile::updateBackBuffer()
     if (!isDirty())
         return Vector<IntRect>();
 
-    UpdateInfo updateInfo;
-    OwnPtr<GraphicsContext> graphicsContext = m_client->beginContentUpdate(m_dirtyRect.size(), updateInfo.bitmapHandle, updateInfo.bitmapOffset);
+    SurfaceUpdateInfo updateInfo;
+    OwnPtr<GraphicsContext> graphicsContext = m_client->beginContentUpdate(m_dirtyRect.size(), updateInfo.surfaceHandle, updateInfo.surfaceOffset);
     if (!graphicsContext)
         return Vector<IntRect>();
     graphicsContext->translate(-m_dirtyRect.x(), -m_dirtyRect.y());
     graphicsContext->scale(FloatSize(m_tiledBackingStore->contentsScale(), m_tiledBackingStore->contentsScale()));
     m_tiledBackingStore->client()->tiledBackingStorePaint(graphicsContext.get(), m_tiledBackingStore->mapToContents(m_dirtyRect));
 
-    updateInfo.updateRectBounds = m_rect;
-    IntRect updateRect = m_dirtyRect;
-    updateRect.move(-m_rect.x(), -m_rect.y());
-    updateInfo.updateRects.append(updateRect);
-    updateInfo.updateScaleFactor = m_tiledBackingStore->contentsScale();
+    updateInfo.updateRect = m_dirtyRect;
+    updateInfo.updateRect.move(-m_rect.x(), -m_rect.y());
+    updateInfo.scaleFactor = m_tiledBackingStore->contentsScale();
     graphicsContext.release();
 
     static int id = 0;
     if (!m_ID) {
         m_ID = ++id;
-        m_client->createTile(m_ID, updateInfo);
+        m_client->createTile(m_ID, updateInfo, m_rect);
     } else
-        m_client->updateTile(m_ID, updateInfo);
+        m_client->updateTile(m_ID, updateInfo, m_rect);
 
     m_dirtyRect = IntRect();
     return Vector<IntRect>();
index dfc252e..cae11e9 100644 (file)
@@ -28,7 +28,7 @@
 
 #if USE(TILED_BACKING_STORE)
 
-#include "ShareableBitmap.h"
+#include "ShareableSurface.h"
 #include "Tile.h"
 #include "TiledBackingStore.h"
 #include "WebCore/IntRect.h"
@@ -41,7 +41,7 @@ class TiledBackingStore;
 namespace WebKit {
 
 class TiledBackingStoreRemoteTileClient;
-class UpdateInfo;
+class SurfaceUpdateInfo;
 
 class TiledBackingStoreRemoteTile : public WebCore::Tile {
 public:
@@ -76,10 +76,10 @@ private:
 class TiledBackingStoreRemoteTileClient {
 public:
     virtual ~TiledBackingStoreRemoteTileClient() { }
-    virtual void createTile(int tileID, const UpdateInfo&) = 0;
-    virtual void updateTile(int tileID, const UpdateInfo&) = 0;
+    virtual void createTile(int tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&) = 0;
+    virtual void updateTile(int tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&) = 0;
     virtual void removeTile(int tileID) = 0;
-    virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, ShareableBitmap::Handle&, WebCore::IntPoint&) = 0;
+    virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, ShareableSurface::Handle&, WebCore::IntPoint&) = 0;
 };
 
 class TiledBackingStoreRemoteTileBackend : public WebCore::TiledBackingStoreBackend {
index 9e46413..9383bc5 100644 (file)
@@ -32,7 +32,7 @@ namespace WebKit {
 UpdateAtlas::UpdateAtlas(int dimension, ShareableBitmap::Flags flags)
     : m_flags(flags)
 {
-    m_bitmap = ShareableBitmap::createShareable(IntSize(dimension, dimension), flags);
+    m_surface = ShareableSurface::create(IntSize(dimension, dimension), flags, ShareableSurface::SupportsGraphicsSurface);
 }
 
 static int nextPowerOfTwo(int number)
@@ -112,12 +112,14 @@ PassOwnPtr<GraphicsContext> UpdateAtlas::beginPaintingOnAvailableBuffer(const We
     m_bufferStates[index] = Taken;
     offset = offsetForIndex(index);
     IntRect rect(IntPoint::zero(), size);
-    OwnPtr<GraphicsContext> graphicsContext = m_bitmap->createGraphicsContext();
-    graphicsContext->translate(offset.x(), offset.y());
-    graphicsContext->clip(rect);
-    graphicsContext->setCompositeOperation(CompositeCopy);
-    graphicsContext->fillRect(rect, (flags() & ShareableBitmap::SupportsAlpha) ? Color::transparent : Color::white, ColorSpaceDeviceRGB);
-    graphicsContext->setCompositeOperation(CompositeSourceOver);
+    OwnPtr<GraphicsContext> graphicsContext = m_surface->createGraphicsContext(IntRect(offset, size));
+
+    if (flags() & ShareableBitmap::SupportsAlpha) {
+        graphicsContext->setCompositeOperation(CompositeCopy);
+        graphicsContext->fillRect(rect, Color::transparent, ColorSpaceDeviceRGB);
+        graphicsContext->setCompositeOperation(CompositeSourceOver);
+    }
+
     return graphicsContext.release();
 }
 
index cef3e9c..9d10962 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef UpdateAtlas_h
 #define UpdateAtlas_h
 
-#include "ShareableBitmap.h"
+#include "ShareableSurface.h"
 
 #if USE(UI_SIDE_COMPOSITING)
 namespace WebCore {
@@ -34,8 +34,8 @@ class UpdateAtlas {
 public:
     UpdateAtlas(int dimension, ShareableBitmap::Flags);
 
-    PassRefPtr<ShareableBitmap> bitmap() { return m_bitmap; }
-    inline WebCore::IntSize size() const { return m_bitmap->size(); }
+    PassRefPtr<ShareableSurface> surface() { return m_surface; }
+    inline WebCore::IntSize size() const { return m_surface->size(); }
 
     // Returns a null pointer of there is no available buffer.
     PassOwnPtr<WebCore::GraphicsContext> beginPaintingOnAvailableBuffer(const WebCore::IntSize&, WebCore::IntPoint& offset);
@@ -56,7 +56,7 @@ private:
     Vector<State> m_bufferStates;
     Vector<int> m_layout;
     ShareableBitmap::Flags m_flags;
-    RefPtr<ShareableBitmap> m_bitmap;
+    RefPtr<ShareableSurface> m_surface;
 };
 
 }
index 13ea96a..14e7c86 100644 (file)
@@ -32,6 +32,7 @@
 #include "GraphicsContext.h"
 #include "LayerTreeHostProxyMessages.h"
 #include "MessageID.h"
+#include "SurfaceUpdateInfo.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebGraphicsLayer.h"
 #include "WebPage.h"
@@ -399,16 +400,16 @@ bool LayerTreeHost::supportsAcceleratedCompositing()
     return true;
 }
 
-void LayerTreeHostQt::createTile(WebLayerID layerID, int tileID, const UpdateInfo& updateInfo)
+void LayerTreeHostQt::createTile(WebLayerID layerID, int tileID, const SurfaceUpdateInfo& updateInfo, const WebCore::IntRect& targetRect)
 {
     m_shouldSyncFrame = true;
-    m_webPage->send(Messages::LayerTreeHostProxy::CreateTileForLayer(layerID, tileID, updateInfo));
+    m_webPage->send(Messages::LayerTreeHostProxy::CreateTileForLayer(layerID, tileID, targetRect, updateInfo));
 }
 
-void LayerTreeHostQt::updateTile(WebLayerID layerID, int tileID, const UpdateInfo& updateInfo)
+void LayerTreeHostQt::updateTile(WebLayerID layerID, int tileID, const SurfaceUpdateInfo& updateInfo, const WebCore::IntRect& targetRect)
 {
     m_shouldSyncFrame = true;
-    m_webPage->send(Messages::LayerTreeHostProxy::UpdateTileForLayer(layerID, tileID, updateInfo));
+    m_webPage->send(Messages::LayerTreeHostProxy::UpdateTileForLayer(layerID, tileID, targetRect, updateInfo));
 }
 
 void LayerTreeHostQt::removeTile(WebLayerID layerID, int tileID)
@@ -482,10 +483,10 @@ UpdateAtlas& LayerTreeHostQt::getAtlas(ShareableBitmap::Flags flags)
     return m_updateAtlases.last();
 }
 
-PassOwnPtr<WebCore::GraphicsContext> LayerTreeHostQt::beginContentUpdate(const WebCore::IntSize& size, ShareableBitmap::Flags flags, ShareableBitmap::Handle& handle, WebCore::IntPoint& offset)
+PassOwnPtr<WebCore::GraphicsContext> LayerTreeHostQt::beginContentUpdate(const WebCore::IntSize& size, ShareableBitmap::Flags flags, ShareableSurface::Handle& handle, WebCore::IntPoint& offset)
 {
     UpdateAtlas& atlas = getAtlas(flags);
-    if (!atlas.bitmap()->createHandle(handle))
+    if (!atlas.surface()->createHandle(handle))
         return PassOwnPtr<WebCore::GraphicsContext>();
 
     // This will return null if there is no available buffer.
index 7912842..c293b18 100644 (file)
@@ -64,8 +64,8 @@ public:
     virtual int64_t adoptImageBackingStore(WebCore::Image*);
     virtual void releaseImageBackingStore(int64_t);
 
-    virtual void createTile(WebLayerID, int tileID, const UpdateInfo&);
-    virtual void updateTile(WebLayerID, int tileID, const UpdateInfo&);
+    virtual void createTile(WebLayerID, int tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&);
+    virtual void updateTile(WebLayerID, int tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&);
     virtual void removeTile(WebLayerID, int tileID);
     virtual WebCore::IntRect visibleContentsRect() const;
     virtual void renderNextFrame();
@@ -77,7 +77,7 @@ public:
     virtual void attachLayer(WebCore::WebGraphicsLayer*);
     virtual void detachLayer(WebCore::WebGraphicsLayer*);
 
-    virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, ShareableBitmap::Flags, ShareableBitmap::Handle&, WebCore::IntPoint&);
+    virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, ShareableBitmap::Flags, ShareableSurface::Handle&, WebCore::IntPoint&);
 
 protected:
     explicit LayerTreeHostQt(WebPage*);
index 609595e..bffe9c2 100644 (file)
@@ -1,3 +1,14 @@
+2012-04-10  No'am Rosenthal  <noam.rosenthal@nokia.com>
+
+        [Qt][WK2] Manage graphics buffers in the web process
+        https://bugs.webkit.org/show_bug.cgi?id=78675
+
+        Enable graphics surfaces on Mac for Qt.
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        * qmake/mkspecs/features/features.prf:
+
 2012-04-10  Patrick Gansterer  <paroga@webkit.org>
 
         [CMake] Enable USE_FOLDERS property
index a744147..6e15f3d 100644 (file)
@@ -18,6 +18,11 @@ meegotouch {
     DEFINES += WTF_USE_MEEGOTOUCH=1
 }
 
+mac: CONFIG += graphics_surfaces
+contains(CONFIG, graphics_surfaces) {
+    DEFINES += WTF_USE_GRAPHICS_SURFACE=1
+}
+
 ## load mobilityconfig if mobility is available
 load(mobilityconfig, true)