Title: [100021] trunk/Source/WebCore
Revision
100021
Author
commit-qu...@webkit.org
Date
2011-11-11 14:18:29 -0800 (Fri, 11 Nov 2011)

Log Message

Added TileCairo and TiledBackingStoreBackendCairo files
https://bugs.webkit.org/show_bug.cgi?id=71350

Patch by Julien Chaffraix  <jchaffr...@codeaurora.org>, Zaheer Ahmad  <zahi...@codeaurora.org>, Joone Hur  <joone....@collabora.co.uk>, Tomasz Morawski <t.moraw...@samsung.com> on 2011-11-11
Reviewed by Martin Robinson.

Added TileCairo and TiledBackingStoreBackend files needed by Tiled Backing Store implementation that uses cairo
library eg. EFL and Gtk WebKit port.

This patch contains some parts of rebased and updated code from 45423 bug. Originals authors of the code are:
- Julien Chaffraix  <jchaffr...@codeaurora.org>
- Zaheer Ahmad  <zah...@codeaurora.org>
- Joone Hur  <joone....@collabora.co.uk>

* platform/graphics/cairo/RefPtrCairo.cpp: Added support of RefPtr for cairo_region object.
(WTF::refIfNotNull): New refIfNotNull function for cairo_region object.
(WTF::derefIfNotNull): New derefIfNotNull function for cairo_region object.
* platform/graphics/cairo/RefPtrCairo.h: Added support of RefPtr for cairo_region object.
* platform/graphics/cairo/TileCairo.cpp: Added a new file. Implementation of TileCairo class.
(WebCore::TileCairo::TileCairo):
(WebCore::TileCairo::~TileCairo):
(WebCore::TileCairo::isDirty):
(WebCore::TileCairo::isReadyToPaint):
(WebCore::TileCairo::invalidate):
(WebCore::TileCairo::updateBackBuffer):
(WebCore::TileCairo::swapBackBufferToFront):
(WebCore::TileCairo::paint):
(WebCore::TileCairo::resize):
* platform/graphics/cairo/TileCairo.h: Added a new file. Implementation of TileCairo class.
(WebCore::TileCairo::create):
(WebCore::TileCairo::coordinate):
(WebCore::TileCairo::rect):
* platform/graphics/cairo/TiledBackingStoreBackendCairo.cpp: Added a new file. Implementation of
TiledBackingStoreBackend methods.
(WebCore::TiledBackingStoreBackend::createTile):
(WebCore::checkeredSurface): Helper function that creates checkered surface (see below function)
(WebCore::TiledBackingStoreBackend::paintCheckerPattern): Function is used to draw a place holder when tile no
exist or it is not ready to paint yet. The checkered surface is used here.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (100020 => 100021)


--- trunk/Source/WebCore/ChangeLog	2011-11-11 22:15:57 UTC (rev 100020)
+++ trunk/Source/WebCore/ChangeLog	2011-11-11 22:18:29 UTC (rev 100021)
@@ -1,3 +1,43 @@
+2011-11-11  Julien Chaffraix  <jchaffr...@codeaurora.org>, Zaheer Ahmad  <zahi...@codeaurora.org>, Joone Hur  <joone....@collabora.co.uk>, Tomasz Morawski  <t.moraw...@samsung.com>
+
+        Added TileCairo and TiledBackingStoreBackendCairo files
+        https://bugs.webkit.org/show_bug.cgi?id=71350
+
+        Reviewed by Martin Robinson.
+
+        Added TileCairo and TiledBackingStoreBackend files needed by Tiled Backing Store implementation that uses cairo
+        library eg. EFL and Gtk WebKit port.
+
+        This patch contains some parts of rebased and updated code from 45423 bug. Originals authors of the code are:
+        - Julien Chaffraix  <jchaffr...@codeaurora.org>
+        - Zaheer Ahmad  <zah...@codeaurora.org>
+        - Joone Hur  <joone....@collabora.co.uk>
+
+        * platform/graphics/cairo/RefPtrCairo.cpp: Added support of RefPtr for cairo_region object.
+        (WTF::refIfNotNull): New refIfNotNull function for cairo_region object.
+        (WTF::derefIfNotNull): New derefIfNotNull function for cairo_region object.
+        * platform/graphics/cairo/RefPtrCairo.h: Added support of RefPtr for cairo_region object.
+        * platform/graphics/cairo/TileCairo.cpp: Added a new file. Implementation of TileCairo class.
+        (WebCore::TileCairo::TileCairo):
+        (WebCore::TileCairo::~TileCairo):
+        (WebCore::TileCairo::isDirty):
+        (WebCore::TileCairo::isReadyToPaint):
+        (WebCore::TileCairo::invalidate):
+        (WebCore::TileCairo::updateBackBuffer):
+        (WebCore::TileCairo::swapBackBufferToFront):
+        (WebCore::TileCairo::paint):
+        (WebCore::TileCairo::resize):
+        * platform/graphics/cairo/TileCairo.h: Added a new file. Implementation of TileCairo class.
+        (WebCore::TileCairo::create):
+        (WebCore::TileCairo::coordinate):
+        (WebCore::TileCairo::rect):
+        * platform/graphics/cairo/TiledBackingStoreBackendCairo.cpp: Added a new file. Implementation of
+        TiledBackingStoreBackend methods.
+        (WebCore::TiledBackingStoreBackend::createTile):
+        (WebCore::checkeredSurface): Helper function that creates checkered surface (see below function)
+        (WebCore::TiledBackingStoreBackend::paintCheckerPattern): Function is used to draw a place holder when tile no
+        exist or it is not ready to paint yet. The checkered surface is used here.
+
 2011-11-11  Julien Chaffraix  <jchaffr...@webkit.org>
 
         Remove unneeded frame check in FrameView::detachCustomScrollbars

Modified: trunk/Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp (100020 => 100021)


--- trunk/Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp	2011-11-11 22:15:57 UTC (rev 100020)
+++ trunk/Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp	2011-11-11 22:18:29 UTC (rev 100021)
@@ -88,6 +88,18 @@
         cairo_pattern_destroy(ptr);
 }
 
+template<> void refIfNotNull(cairo_region_t* ptr)
+{
+    if (LIKELY(ptr != 0))
+        cairo_region_reference(ptr);
+}
+
+template<> void derefIfNotNull(cairo_region_t* ptr)
+{
+    if (LIKELY(ptr != 0))
+        cairo_region_destroy(ptr);
+}
+
 #if USE(FREETYPE)
 template<> void refIfNotNull(FcPattern* ptr)
 {

Modified: trunk/Source/WebCore/platform/graphics/cairo/RefPtrCairo.h (100020 => 100021)


--- trunk/Source/WebCore/platform/graphics/cairo/RefPtrCairo.h	2011-11-11 22:15:57 UTC (rev 100020)
+++ trunk/Source/WebCore/platform/graphics/cairo/RefPtrCairo.h	2011-11-11 22:18:29 UTC (rev 100021)
@@ -27,6 +27,7 @@
 typedef struct _cairo_font_face cairo_font_face_t;
 typedef struct _cairo_scaled_font cairo_scaled_font_t;
 typedef struct _cairo_pattern cairo_pattern_t;
+typedef struct _cairo_region cairo_region_t;
 
 #if USE(FREETYPE)
 typedef struct _FcPattern FcPattern;
@@ -49,6 +50,9 @@
 template<> void refIfNotNull(cairo_pattern_t*);
 template<> void derefIfNotNull(cairo_pattern_t*);
 
+template<> void refIfNotNull(cairo_region_t*);
+template<> void derefIfNotNull(cairo_region_t*);
+
 #if USE(FREETYPE)
 template<> void refIfNotNull(FcPattern* ptr);
 template<> void derefIfNotNull(FcPattern* ptr);

Added: trunk/Source/WebCore/platform/graphics/cairo/TileCairo.cpp (0 => 100021)


--- trunk/Source/WebCore/platform/graphics/cairo/TileCairo.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cairo/TileCairo.cpp	2011-11-11 22:18:29 UTC (rev 100021)
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2010 codeaurora.org All rights reserved.
+ * Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2011 Samsung Electronics
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "TileCairo.h"
+
+#if USE(TILED_BACKING_STORE) && USE(CAIRO)
+#include "CairoUtilities.h"
+#include "GraphicsContext.h"
+#include "PlatformContextCairo.h"
+#include "TiledBackingStore.h"
+#include "TiledBackingStoreClient.h"
+#include <RefPtrCairo.h>
+
+namespace WebCore {
+
+TileCairo::TileCairo(TiledBackingStore* backingStore, const Coordinate& tileCoordinate)
+    : m_backingStore(backingStore)
+    , m_coordinate(tileCoordinate)
+    , m_rect(m_backingStore->tileRectForCoordinate(tileCoordinate))
+{
+    cairo_rectangle_int_t rect = m_rect;
+    m_dirtyRegion = adoptRef(cairo_region_create_rectangle(&rect));
+}
+
+TileCairo::~TileCairo()
+{
+}
+
+bool TileCairo::isDirty() const
+{
+    return !cairo_region_is_empty(m_dirtyRegion.get());
+}
+
+bool TileCairo::isReadyToPaint() const
+{
+    return m_buffer;
+}
+
+void TileCairo::invalidate(const IntRect& dirtyRect)
+{
+    IntRect tileDirtyRect = intersection(dirtyRect, m_rect);
+    if (tileDirtyRect.isEmpty())
+        return;
+
+    cairo_rectangle_int_t rect = tileDirtyRect;
+    cairo_region_union_rectangle(m_dirtyRegion.get(), &rect);
+}
+
+Vector<IntRect> TileCairo::updateBackBuffer()
+{
+    if (m_buffer && !isDirty())
+        return Vector<IntRect>();
+
+    if (!m_buffer)
+        m_buffer = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
+                                                       m_backingStore->tileSize().width(),
+                                                       m_backingStore->tileSize().height()));
+
+    RefPtr<cairo_t> cr = adoptRef(cairo_create(m_buffer.get()));
+    GraphicsContext context(cr.get());
+    context.translate(-m_rect.x(), -m_rect.y());
+
+    Vector<IntRect> updateRects;
+    cairo_rectangle_int_t rect;
+
+    int rectCount = cairo_region_num_rectangles(m_dirtyRegion.get());
+    for (int i = 0; i < rectCount; ++i) {
+        cairo_region_get_rectangle(m_dirtyRegion.get(), i, &rect);
+        updateRects.append(IntRect(rect));
+
+        context.save();
+        context.clip(FloatRect(rect));
+        context.scale(FloatSize(m_backingStore->contentsScale(), m_backingStore->contentsScale()));
+        m_backingStore->client()->tiledBackingStorePaint(&context, m_backingStore->mapToContents(rect));
+        context.restore();
+    }
+
+    m_dirtyRegion.clear();
+    m_dirtyRegion = adoptRef(cairo_region_create());
+
+    return updateRects;
+}
+
+void TileCairo::swapBackBufferToFront()
+{
+}
+
+void TileCairo::paint(GraphicsContext* context, const IntRect& rect)
+{
+    if (!m_buffer)
+        return;
+
+    IntRect target = intersection(rect, m_rect);
+
+    cairo_t* cr = context->platformContext()->cr();
+    cairo_set_source_surface(cr, m_buffer.get(), m_rect.x(), m_rect.y());
+    cairo_rectangle(cr, target.x(), target.y(), target.width(), target.height());
+    cairo_fill(cr);
+}
+
+void TileCairo::resize(const WebCore::IntSize& newSize)
+{
+    IntRect oldRect = m_rect;
+    m_rect = IntRect(m_rect.location(), newSize);
+    if (m_rect.maxX() > oldRect.maxX())
+        invalidate(IntRect(oldRect.maxX(), oldRect.y(), m_rect.maxX() - oldRect.maxX(), m_rect.height()));
+    if (m_rect.maxY() > oldRect.maxY())
+        invalidate(IntRect(oldRect.x(), oldRect.maxY(), m_rect.width(), m_rect.maxY() - oldRect.maxY()));
+}
+
+}
+
+#endif

Added: trunk/Source/WebCore/platform/graphics/cairo/TileCairo.h (0 => 100021)


--- trunk/Source/WebCore/platform/graphics/cairo/TileCairo.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cairo/TileCairo.h	2011-11-11 22:18:29 UTC (rev 100021)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TileCairo_h
+#define TileCairo_h
+
+#if USE(TILED_BACKING_STORE) && USE(CAIRO)
+
+#include "IntPoint.h"
+#include "IntRect.h"
+#include "RefPtrCairo.h"
+#include "Tile.h"
+#include <cairo.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class TiledBackingStore;
+
+class TileCairo : public Tile {
+public:
+    static PassRefPtr<Tile> create(TiledBackingStore* backingStore, const Coordinate& tileCoordinate)
+    {
+        return adoptRef(new TileCairo(backingStore, tileCoordinate));
+    }
+    virtual ~TileCairo();
+
+    virtual bool isDirty() const;
+    virtual void invalidate(const IntRect&);
+    virtual Vector<IntRect> updateBackBuffer();
+    virtual void swapBackBufferToFront();
+    virtual bool isReadyToPaint() const;
+    virtual void paint(GraphicsContext*, const IntRect&);
+
+    virtual const Tile::Coordinate& coordinate() const { return m_coordinate; }
+    virtual const IntRect& rect() const { return m_rect; }
+    virtual void resize(const WebCore::IntSize&);
+
+protected:
+    TileCairo(TiledBackingStore*, const Coordinate&);
+
+    TiledBackingStore* m_backingStore;
+    Coordinate m_coordinate;
+    IntRect m_rect;
+
+    RefPtr<cairo_surface_t> m_buffer;
+    RefPtr<cairo_region_t> m_dirtyRegion;
+};
+
+}
+#endif
+#endif
+

Added: trunk/Source/WebCore/platform/graphics/cairo/TiledBackingStoreBackendCairo.cpp (0 => 100021)


--- trunk/Source/WebCore/platform/graphics/cairo/TiledBackingStoreBackendCairo.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cairo/TiledBackingStoreBackendCairo.cpp	2011-11-11 22:18:29 UTC (rev 100021)
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2010 codeaurora.org All rights reserved.
+ * Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2011 Samsung Electronics
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "TiledBackingStoreBackend.h"
+
+#if USE(TILED_BACKING_STORE) && USE(CAIRO)
+#include "CairoUtilities.h"
+#include "PlatformContextCairo.h"
+#include "TileCairo.h"
+#include <cairo.h>
+
+namespace WebCore {
+
+PassRefPtr<Tile> TiledBackingStoreBackend::createTile(TiledBackingStore* backingStore, const Tile::Coordinate& tileCoordinate)
+{
+    return TileCairo::create(backingStore, tileCoordinate);
+}
+
+static const unsigned checkerSize = 16;
+static const unsigned checkerColorDarkGrey = 0xff555555;
+static const unsigned checkerColorLightGrey = 0xffaaaaaa;
+
+static cairo_surface_t* checkeredSurface()
+{
+    static cairo_surface_t* surface = 0;
+    if (surface)
+        return surface;
+
+    surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, checkerSize, checkerSize);
+    RefPtr<cairo_t> cr = adoptRef(cairo_create(surface));
+
+    unsigned halfCheckerSize = checkerSize / 2;
+    setSourceRGBAFromColor(cr.get(), checkerColorLightGrey);
+    cairo_rectangle(cr.get(), 0, 0, halfCheckerSize, halfCheckerSize);
+    cairo_rectangle(cr.get(), halfCheckerSize, halfCheckerSize, halfCheckerSize, halfCheckerSize);
+    cairo_fill(cr.get());
+
+    setSourceRGBAFromColor(cr.get(), checkerColorDarkGrey);
+    cairo_rectangle(cr.get(), halfCheckerSize, 0, halfCheckerSize, halfCheckerSize);
+    cairo_rectangle(cr.get(), 0, halfCheckerSize, halfCheckerSize, halfCheckerSize);
+    cairo_fill(cr.get());
+
+    return surface;
+}
+
+void TiledBackingStoreBackend::paintCheckerPattern(GraphicsContext* context, const FloatRect& target)
+{
+    PlatformContextCairo* platformContext = context->platformContext();
+    cairo_t* cr = platformContext->cr();
+    cairo_set_source_surface(cr, checkeredSurface(), 0, 0);
+    cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
+    cairo_rectangle(cr, target.x(), target.y(), target.width(), target.height());
+    cairo_fill(cr);
+}
+
+}
+
+#endif
+
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to