Title: [107401] trunk/Source/WebKit
Revision
107401
Author
rwlb...@webkit.org
Date
2012-02-10 07:41:22 -0800 (Fri, 10 Feb 2012)

Log Message

[BlackBerry] Upstream graphics helper classes in WebKitSupport
https://bugs.webkit.org/show_bug.cgi?id=78278

Reviewed by Antonio Gomes.

Initial upstream, no new tests.

* blackberry/WebKitSupport/SurfacePool.cpp: Added.
* blackberry/WebKitSupport/SurfacePool.h: Added.
* blackberry/WebKitSupport/TileIndex.h: Added.
* blackberry/WebKitSupport/TileIndexHash.h: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (107400 => 107401)


--- trunk/Source/WebKit/ChangeLog	2012-02-10 15:31:10 UTC (rev 107400)
+++ trunk/Source/WebKit/ChangeLog	2012-02-10 15:41:22 UTC (rev 107401)
@@ -1,3 +1,17 @@
+2012-02-10  Rob Buis  <rb...@rim.com>
+
+        [BlackBerry] Upstream graphics helper classes in WebKitSupport
+        https://bugs.webkit.org/show_bug.cgi?id=78278
+
+        Reviewed by Antonio Gomes.
+
+        Initial upstream, no new tests.
+
+        * blackberry/WebKitSupport/SurfacePool.cpp: Added.
+        * blackberry/WebKitSupport/SurfacePool.h: Added.
+        * blackberry/WebKitSupport/TileIndex.h: Added.
+        * blackberry/WebKitSupport/TileIndexHash.h: Added.
+
 2012-02-09  Leo Yang  <leo.y...@torchmobile.com.cn>
 
         [BlackBerry] Upstream _javascript_DebuggerBlackBerry.{h, cpp}

Added: trunk/Source/WebKit/blackberry/WebKitSupport/SurfacePool.cpp (0 => 107401)


--- trunk/Source/WebKit/blackberry/WebKitSupport/SurfacePool.cpp	                        (rev 0)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/SurfacePool.cpp	2012-02-10 15:41:22 UTC (rev 107401)
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "SurfacePool.h"
+
+#include "PlatformContextSkia.h"
+
+#if USE(ACCELERATED_COMPOSITING)
+#include "BackingStoreCompositingSurface.h"
+#endif
+
+#include <BlackBerryPlatformLog.h>
+#include <BlackBerryPlatformMisc.h>
+#include <BlackBerryPlatformScreen.h>
+#include <BlackBerryPlatformSettings.h>
+
+#define SHARED_PIXMAP_GROUP "webkit_backingstore_group"
+
+namespace BlackBerry {
+namespace WebKit {
+
+#if USE(ACCELERATED_COMPOSITING) && ENABLE_COMPOSITING_SURFACE
+static PassRefPtr<BackingStoreCompositingSurface> createCompositingSurface()
+{
+    BlackBerry::Platform::IntSize screenSize = BlackBerry::Platform::Graphics::Screen::size();
+    return BackingStoreCompositingSurface::create(screenSize, false /*doubleBuffered*/);
+}
+#endif
+
+SurfacePool* SurfacePool::globalSurfacePool()
+{
+    static SurfacePool* s_instance = 0;
+    if (!s_instance)
+        s_instance = new SurfacePool;
+    return s_instance;
+}
+
+SurfacePool::SurfacePool()
+    : m_visibleTileBuffer(0)
+#if USE(ACCELERATED_COMPOSITING)
+    , m_compositingSurface(0)
+#endif
+    , m_tileRenderingSurface(0)
+    , m_backBuffer(0)
+    , m_initialized(false)
+    , m_buffersSuspended(false)
+{
+}
+
+void SurfacePool::initialize(const BlackBerry::Platform::IntSize& tileSize)
+{
+    if (m_initialized)
+        return;
+    m_initialized = true;
+
+    const unsigned numberOfTiles = BlackBerry::Platform::Settings::get()->numberOfBackingStoreTiles();
+    const unsigned maxNumberOfTiles = BlackBerry::Platform::Settings::get()->maximumNumberOfBackingStoreTilesAcrossProcesses();
+
+    if (numberOfTiles) { // Only allocate if we actually use a backingstore.
+        unsigned byteLimit = (maxNumberOfTiles /*pool*/ + 2 /*visible tile buffer, backbuffer*/) * tileSize.width() * tileSize.height() * 4;
+        bool success = BlackBerry::Platform::Graphics::createPixmapGroup(SHARED_PIXMAP_GROUP, byteLimit);
+        if (!success) {
+            BlackBerry::Platform::log(BlackBerry::Platform::LogLevelWarn,
+                "Shared buffer pool could not be set up, using regular memory allocation instead.");
+        }
+    }
+
+    m_tileRenderingSurface = BlackBerry::Platform::Graphics::drawingSurface();
+
+#if USE(ACCELERATED_COMPOSITING) && ENABLE_COMPOSITING_SURFACE
+    m_compositingSurface = createCompositingSurface();
+#endif
+
+    if (!numberOfTiles)
+        return; // we only use direct rendering when 0 tiles are specified.
+
+    // Create the shared backbuffer.
+    m_backBuffer = reinterpret_cast<unsigned>(new TileBuffer(tileSize));
+
+    for (size_t i = 0; i < numberOfTiles; ++i)
+        m_tilePool.append(BackingStoreTile::create(tileSize, BackingStoreTile::DoubleBuffered));
+}
+
+PlatformGraphicsContext* SurfacePool::createPlatformGraphicsContext(BlackBerry::Platform::Graphics::Drawable* drawable) const
+{
+    return new WebCore::PlatformContextSkia(drawable);
+}
+
+PlatformGraphicsContext* SurfacePool::lockTileRenderingSurface() const
+{
+    if (!m_tileRenderingSurface)
+        return 0;
+
+    return createPlatformGraphicsContext(BlackBerry::Platform::Graphics::lockBufferDrawable(m_tileRenderingSurface));
+}
+
+void SurfacePool::releaseTileRenderingSurface(PlatformGraphicsContext* context) const
+{
+    if (!m_tileRenderingSurface)
+        return;
+
+    delete context;
+    BlackBerry::Platform::Graphics::releaseBufferDrawable(m_tileRenderingSurface);
+}
+
+void SurfacePool::initializeVisibleTileBuffer(const BlackBerry::Platform::IntSize& visibleSize)
+{
+    if (!m_visibleTileBuffer || m_visibleTileBuffer->size() != visibleSize) {
+        delete m_visibleTileBuffer;
+        m_visibleTileBuffer = BackingStoreTile::create(visibleSize, BackingStoreTile::SingleBuffered);
+    }
+}
+
+TileBuffer* SurfacePool::backBuffer() const
+{
+    ASSERT(m_backBuffer);
+    return reinterpret_cast<TileBuffer*>(m_backBuffer);
+}
+
+#if USE(ACCELERATED_COMPOSITING)
+BackingStoreCompositingSurface* SurfacePool::compositingSurface() const
+{
+    return m_compositingSurface.get();
+}
+#endif
+
+void SurfacePool::notifyScreenRotated()
+{
+#if USE(ACCELERATED_COMPOSITING) && ENABLE_COMPOSITING_SURFACE
+    // Recreate compositing surface at new screen resolution.
+    m_compositingSurface = createCompositingSurface();
+#endif
+}
+
+std::string SurfacePool::sharedPixmapGroup() const
+{
+    return SHARED_PIXMAP_GROUP;
+}
+
+void SurfacePool::createBuffers()
+{
+    if (!m_initialized || m_tilePool.isEmpty())
+        return;
+
+    // Create the tile pool.
+    for (size_t i = 0; i < m_tilePool.size(); ++i)
+        BlackBerry::Platform::Graphics::createPixmapBuffer(m_tilePool[i]->frontBuffer()->nativeBuffer());
+
+    if (m_visibleTileBuffer)
+        BlackBerry::Platform::Graphics::createPixmapBuffer(m_visibleTileBuffer->frontBuffer()->nativeBuffer());
+
+    if (backBuffer())
+        BlackBerry::Platform::Graphics::createPixmapBuffer(backBuffer()->nativeBuffer());
+
+    m_buffersSuspended = false;
+}
+
+void SurfacePool::releaseBuffers()
+{
+    if (!m_initialized || m_tilePool.isEmpty())
+        return;
+
+    m_buffersSuspended = true;
+
+    // Release the tile pool.
+    for (size_t i = 0; i < m_tilePool.size(); ++i) {
+        m_tilePool[i]->frontBuffer()->clearRenderedRegion();
+        BlackBerry::Platform::Graphics::destroyPixmapBuffer(m_tilePool[i]->frontBuffer()->nativeBuffer());
+    }
+
+    if (m_visibleTileBuffer) {
+        m_visibleTileBuffer->frontBuffer()->clearRenderedRegion();
+        BlackBerry::Platform::Graphics::destroyPixmapBuffer(m_visibleTileBuffer->frontBuffer()->nativeBuffer());
+    }
+
+    if (backBuffer()) {
+        backBuffer()->clearRenderedRegion();
+        BlackBerry::Platform::Graphics::destroyPixmapBuffer(backBuffer()->nativeBuffer());
+    }
+}
+
+}
+}

Added: trunk/Source/WebKit/blackberry/WebKitSupport/SurfacePool.h (0 => 107401)


--- trunk/Source/WebKit/blackberry/WebKitSupport/SurfacePool.h	                        (rev 0)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/SurfacePool.h	2012-02-10 15:41:22 UTC (rev 107401)
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef SurfacePool_h
+#define SurfacePool_h
+
+#include "BackingStoreTile.h"
+
+#include "PlatformContextSkia.h"
+
+#include <BlackBerryPlatformGraphics.h>
+#include <BlackBerryPlatformPrimitives.h>
+#include <wtf/Vector.h>
+
+#define ENABLE_COMPOSITING_SURFACE 1
+
+namespace BlackBerry {
+namespace WebKit {
+
+class BackingStoreCompositingSurface;
+
+class SurfacePool {
+public:
+    static SurfacePool* globalSurfacePool();
+
+    void initialize(const BlackBerry::Platform::IntSize&);
+
+    int isActive() const { return !m_tilePool.isEmpty() && !m_buffersSuspended; }
+    int isEmpty() const { return m_tilePool.isEmpty(); }
+    int size() const { return m_tilePool.size(); }
+
+    typedef WTF::Vector<BackingStoreTile*> TileList;
+    const TileList tileList() const { return m_tilePool; }
+
+    PlatformGraphicsContext* createPlatformGraphicsContext(BlackBerry::Platform::Graphics::Drawable*) const;
+    PlatformGraphicsContext* lockTileRenderingSurface() const;
+    void releaseTileRenderingSurface(PlatformGraphicsContext*) const;
+    BackingStoreTile* visibleTileBuffer() const { return m_visibleTileBuffer; }
+
+    void initializeVisibleTileBuffer(const BlackBerry::Platform::IntSize&);
+
+    // This is a shared back buffer that is used by all the tiles since
+    // only one tile will be rendering it at a time and we invalidate
+    // the whole tile every time we render by copying from the front
+    // buffer those portions that we don't render. This allows us to
+    // have N+1 tilebuffers rather than N*2 for our double buffered
+    // backingstore.
+    TileBuffer* backBuffer() const;
+
+    BackingStoreCompositingSurface* compositingSurface() const;
+
+    void notifyScreenRotated();
+
+    std::string sharedPixmapGroup() const;
+
+    void releaseBuffers();
+    void createBuffers();
+
+private:
+    // This is necessary so BackingStoreTile can atomically swap buffers with m_backBuffer.
+    friend class BackingStoreTile;
+
+    SurfacePool();
+
+    TileList m_tilePool;
+    BackingStoreTile* m_visibleTileBuffer;
+#if USE(ACCELERATED_COMPOSITING)
+    RefPtr<BackingStoreCompositingSurface> m_compositingSurface;
+#endif
+    BlackBerry::Platform::Graphics::Buffer* m_tileRenderingSurface;
+    unsigned m_backBuffer;
+    bool m_initialized; // SurfacePool has been set up, with or without buffers.
+    bool m_buffersSuspended; // Buffer objects exist, but pixel memory has been freed.
+};
+}
+}
+
+#endif // SurfacePool_h

Added: trunk/Source/WebKit/blackberry/WebKitSupport/TileIndex.h (0 => 107401)


--- trunk/Source/WebKit/blackberry/WebKitSupport/TileIndex.h	                        (rev 0)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/TileIndex.h	2012-02-10 15:41:22 UTC (rev 107401)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2009, 2010, 2011 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef TileIndex_h
+#define TileIndex_h
+
+#include <limits>
+
+namespace BlackBerry {
+namespace WebKit {
+
+class TileIndex {
+public:
+    TileIndex()
+        : m_i(std::numeric_limits<unsigned int>::max())
+        , m_j(std::numeric_limits<unsigned int>::max()) { }
+    TileIndex(unsigned int i, unsigned int j)
+        : m_i(i)
+        , m_j(j) { }
+    ~TileIndex() { }
+
+    unsigned int i() const { return m_i; }
+    unsigned int j() const { return m_j; }
+    void setIndex(unsigned int i, unsigned int j)
+    {
+        m_i = i;
+        m_j = j;
+    }
+
+private:
+    bool m_isValid;
+    unsigned int m_i;
+    unsigned int m_j;
+};
+
+inline bool operator==(const BlackBerry::WebKit::TileIndex& a, const BlackBerry::WebKit::TileIndex& b)
+{
+    return a.i() == b.i() && a.j() == b.j();
+}
+
+inline bool operator!=(const BlackBerry::WebKit::TileIndex& a, const BlackBerry::WebKit::TileIndex& b)
+{
+    return a.i() != b.i() || a.j() != b.j();
+}
+}
+}
+
+#endif // TileIndex_h

Added: trunk/Source/WebKit/blackberry/WebKitSupport/TileIndexHash.h (0 => 107401)


--- trunk/Source/WebKit/blackberry/WebKitSupport/TileIndexHash.h	                        (rev 0)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/TileIndexHash.h	2012-02-10 15:41:22 UTC (rev 107401)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2009, 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef TileIndexHash_h
+#define TileIndexHash_h
+
+#include "TileIndex.h"
+#include <limits>
+#include <wtf/HashMap.h>
+
+using BlackBerry::WebKit::TileIndex;
+
+namespace WTF {
+
+template<> struct IntHash<TileIndex> {
+    static unsigned hash(const TileIndex& key) { return intHash((static_cast<uint64_t>(key.i()) << 32 | key.j())); }
+    static bool equal(const TileIndex& a, const TileIndex& b) { return a == b; }
+    static const bool safeToCompareToEmptyOrDeleted = true;
+};
+template<> struct DefaultHash<TileIndex> {
+    typedef IntHash<TileIndex> Hash;
+};
+
+template<> struct HashTraits<TileIndex> : GenericHashTraits<TileIndex> {
+    static const bool emptyValueIsZero = false;
+    static const bool needsDestruction = false;
+    static TileIndex emptyValue() { return TileIndex(); }
+    static void constructDeletedValue(TileIndex& slot)
+    {
+        new (&slot) TileIndex(std::numeric_limits<unsigned int>::max() - 1,
+                              std::numeric_limits<unsigned int>::max() - 1);
+    }
+    static bool isDeletedValue(const TileIndex& value)
+    {
+        return value.i() == (std::numeric_limits<unsigned int>::max() - 1)
+               && value.j() == (std::numeric_limits<unsigned int>::max() - 1);
+    }
+};
+} // namespace WTF
+
+#endif // TileIndexHash_h
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to