Title: [225573] trunk/Source
Revision
225573
Author
[email protected]
Date
2017-12-06 03:46:50 -0800 (Wed, 06 Dec 2017)

Log Message

[CoordGraphics] Introduce Nicosia::PaintingContext, add Cairo implementation
https://bugs.webkit.org/show_bug.cgi?id=180239

Reviewed by Michael Catanzaro.

Source/WebCore:

As the next step in the Nicosia abstraction formation, we introduce
Nicosia::PaintingContext. Implementations of this class will leverage a
chosen 2D graphics library to paint (through GraphicsContext) into the
memory area that's specified by a given Nicosia::Buffer object.

Nicosia::Buffer is slimmed down to only control the memory that's
required for rasterization of an RGBA32 painting output. It mimics the
Cairo ImageBuffer implementation by using FastMalloc to allocate the
necessary memory. In the future this class might become an interface of
which different implementations will be providing memory that's
allocated through different ways. For instance, when GLES3 is available,
it would be possible to map GPU memory into the process memory space and
rasterize into that, effectively eliminating need for GPU uploads.

Since the ImageBuffer use in Nicosia::Buffer is dropped, the context()
and uploadImage() methods are also removed. The functionality of
ImageBuffer that was leveraged for CoordinatedGraphics rasterization
still remains used through the PaintingContextCairo implementation. In
the constructor of that class, with the target Nicosia::Buffer provided,
we construct the cairo_surface_t and cairo_t objects that are necessary
to create a combination of PlatformContextCairo and GraphicsContext
objects that we can then use for rasterization.

Reference of the passed-in Nicosia::Buffer object is increased for the
lifetime of the cairo_surface_t object that will be drawing into that
buffer's memory area. This ensures the memory area doesn't disappear
from a live cairo_surface_t. Still, the expectation is that the
cairo_surface_t object won't outlive the PaintingContextCairo object's
lifetime, since the cairo_t object is also managed here and deleted in
the destructor. To test that, we use a cairo_surface_t user data key
that in its destroy callback dereferences the Nicosia::Buffer object and
also marks the deletion process for the related PaintingContextCairo
object as complete. This m_deletionComplete value is tested in the
destructor of the class, once all the Cairo references are nulled out.

The PaintingContext objects should be limited to a single scope,
enabling the implementation resources to assume that the lifetime of the
implementation object won't extend outside of the scope where it was
created. To ensure that, the PaintingContext::paint() static function is
added that creates the PaintingContext object and then executes the
passed-in functor, passing it the GraphicsContext that should be used
for drawing. Drawing is thus limited to that functor only, and the
PaintingContext's create() function and the virtual graphicsContext()
are not made public in the class.

No new tests -- no change in functionality.

* platform/TextureMapper.cmake:
* platform/graphics/nicosia/NicosiaBuffer.cpp:
(Nicosia::Buffer::Buffer):
(Nicosia::Buffer::context): Deleted.
(Nicosia::Buffer::uploadImage): Deleted.
* platform/graphics/nicosia/NicosiaBuffer.h:
(Nicosia::Buffer::stride const):
(Nicosia::Buffer::data const):
* platform/graphics/nicosia/NicosiaPaintingContext.cpp: Copied from Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.cpp.
(Nicosia::PaintingContext::create):
* platform/graphics/nicosia/NicosiaPaintingContext.h: Copied from Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.cpp.
(Nicosia::PaintingContext::paint):
* platform/graphics/nicosia/NicosiaPaintingContextCairo.cpp: Added.
(Nicosia::PaintingContextCairo::PaintingContextCairo):
(Nicosia::PaintingContextCairo::~PaintingContextCairo):
(Nicosia::PaintingContextCairo::graphicsContext):
* platform/graphics/nicosia/NicosiaPaintingContextCairo.h: Copied from Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.h.
* platform/graphics/nicosia/NicosiaPaintingEngineBasic.cpp:
(Nicosia::PaintingEngineBasic::paint):
* platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp:
(WebCore::CoordinatedImageBacking::update):

Source/WebKit:

With Nicosia::Buffer now only providing the memory area into which the
tile content was rasterized, we can simplify the BitmapTexture update
greatly -- we don't have to create a BitmapImage anymore and retrieve
memory pointer from the contained cairo_surface_t object. Instead, we
just copy to GPU the memory that Nicosia::Buffer controls.

* Shared/CoordinatedGraphics/CoordinatedBackingStore.cpp:
(WebKit::CoordinatedBackingStoreTile::swapBuffers):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (225572 => 225573)


--- trunk/Source/WebCore/ChangeLog	2017-12-06 08:51:47 UTC (rev 225572)
+++ trunk/Source/WebCore/ChangeLog	2017-12-06 11:46:50 UTC (rev 225573)
@@ -1,3 +1,79 @@
+2017-12-06  Zan Dobersek  <[email protected]>
+
+        [CoordGraphics] Introduce Nicosia::PaintingContext, add Cairo implementation
+        https://bugs.webkit.org/show_bug.cgi?id=180239
+
+        Reviewed by Michael Catanzaro.
+
+        As the next step in the Nicosia abstraction formation, we introduce
+        Nicosia::PaintingContext. Implementations of this class will leverage a
+        chosen 2D graphics library to paint (through GraphicsContext) into the
+        memory area that's specified by a given Nicosia::Buffer object.
+
+        Nicosia::Buffer is slimmed down to only control the memory that's
+        required for rasterization of an RGBA32 painting output. It mimics the
+        Cairo ImageBuffer implementation by using FastMalloc to allocate the
+        necessary memory. In the future this class might become an interface of
+        which different implementations will be providing memory that's
+        allocated through different ways. For instance, when GLES3 is available,
+        it would be possible to map GPU memory into the process memory space and
+        rasterize into that, effectively eliminating need for GPU uploads.
+
+        Since the ImageBuffer use in Nicosia::Buffer is dropped, the context()
+        and uploadImage() methods are also removed. The functionality of
+        ImageBuffer that was leveraged for CoordinatedGraphics rasterization
+        still remains used through the PaintingContextCairo implementation. In
+        the constructor of that class, with the target Nicosia::Buffer provided,
+        we construct the cairo_surface_t and cairo_t objects that are necessary
+        to create a combination of PlatformContextCairo and GraphicsContext
+        objects that we can then use for rasterization.
+
+        Reference of the passed-in Nicosia::Buffer object is increased for the
+        lifetime of the cairo_surface_t object that will be drawing into that
+        buffer's memory area. This ensures the memory area doesn't disappear
+        from a live cairo_surface_t. Still, the expectation is that the
+        cairo_surface_t object won't outlive the PaintingContextCairo object's
+        lifetime, since the cairo_t object is also managed here and deleted in
+        the destructor. To test that, we use a cairo_surface_t user data key
+        that in its destroy callback dereferences the Nicosia::Buffer object and
+        also marks the deletion process for the related PaintingContextCairo
+        object as complete. This m_deletionComplete value is tested in the
+        destructor of the class, once all the Cairo references are nulled out.
+
+        The PaintingContext objects should be limited to a single scope,
+        enabling the implementation resources to assume that the lifetime of the
+        implementation object won't extend outside of the scope where it was
+        created. To ensure that, the PaintingContext::paint() static function is
+        added that creates the PaintingContext object and then executes the
+        passed-in functor, passing it the GraphicsContext that should be used
+        for drawing. Drawing is thus limited to that functor only, and the
+        PaintingContext's create() function and the virtual graphicsContext()
+        are not made public in the class.
+
+        No new tests -- no change in functionality.
+
+        * platform/TextureMapper.cmake:
+        * platform/graphics/nicosia/NicosiaBuffer.cpp:
+        (Nicosia::Buffer::Buffer):
+        (Nicosia::Buffer::context): Deleted.
+        (Nicosia::Buffer::uploadImage): Deleted.
+        * platform/graphics/nicosia/NicosiaBuffer.h:
+        (Nicosia::Buffer::stride const):
+        (Nicosia::Buffer::data const):
+        * platform/graphics/nicosia/NicosiaPaintingContext.cpp: Copied from Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.cpp.
+        (Nicosia::PaintingContext::create):
+        * platform/graphics/nicosia/NicosiaPaintingContext.h: Copied from Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.cpp.
+        (Nicosia::PaintingContext::paint):
+        * platform/graphics/nicosia/NicosiaPaintingContextCairo.cpp: Added.
+        (Nicosia::PaintingContextCairo::PaintingContextCairo):
+        (Nicosia::PaintingContextCairo::~PaintingContextCairo):
+        (Nicosia::PaintingContextCairo::graphicsContext):
+        * platform/graphics/nicosia/NicosiaPaintingContextCairo.h: Copied from Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.h.
+        * platform/graphics/nicosia/NicosiaPaintingEngineBasic.cpp:
+        (Nicosia::PaintingEngineBasic::paint):
+        * platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp:
+        (WebCore::CoordinatedImageBacking::update):
+
 2017-12-05  Fujii Hironori  <[email protected]>
 
         [GTK] Layout test media/track/track-in-band-duplicate-tracks-when-source-changes.html crashes and times out

Modified: trunk/Source/WebCore/platform/TextureMapper.cmake (225572 => 225573)


--- trunk/Source/WebCore/platform/TextureMapper.cmake	2017-12-06 08:51:47 UTC (rev 225572)
+++ trunk/Source/WebCore/platform/TextureMapper.cmake	2017-12-06 11:46:50 UTC (rev 225573)
@@ -47,6 +47,8 @@
     )
     list(APPEND WebCore_SOURCES
         platform/graphics/nicosia/NicosiaBuffer.cpp
+        platform/graphics/nicosia/NicosiaPaintingContext.cpp
+        platform/graphics/nicosia/NicosiaPaintingContextCairo.cpp
         platform/graphics/nicosia/NicosiaPaintingEngine.cpp
         platform/graphics/nicosia/NicosiaPaintingEngineBasic.cpp
     )

Modified: trunk/Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.cpp (225572 => 225573)


--- trunk/Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.cpp	2017-12-06 08:51:47 UTC (rev 225572)
+++ trunk/Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.cpp	2017-12-06 11:46:50 UTC (rev 225573)
@@ -29,7 +29,7 @@
 #include "config.h"
 #include "NicosiaBuffer.h"
 
-#include "ImageBuffer.h"
+#include <wtf/FastMalloc.h>
 
 namespace Nicosia {
 
@@ -39,22 +39,17 @@
 }
 
 Buffer::Buffer(const WebCore::IntSize& size, Flags flags)
-    : m_imageBuffer(WebCore::ImageBuffer::create(size, WebCore::Unaccelerated))
-    , m_size(size)
+    : m_size(size)
     , m_flags(flags)
 {
+    auto checkedArea = size.area() * 4;
+    unsigned char* bufferData;
+    if (!tryFastZeroedMalloc(checkedArea.unsafeGet()).getValue(bufferData))
+        return;
+
+    m_data = adoptMallocPtr(bufferData);
 }
 
 Buffer::~Buffer() = default;
 
-WebCore::GraphicsContext& Buffer::context()
-{
-    return m_imageBuffer->context();
-}
-
-RefPtr<WebCore::Image> Buffer::uploadImage()
-{
-    return m_imageBuffer->copyImage(WebCore::DontCopyBackingStore);
-}
-
 } // namespace Nicosia

Modified: trunk/Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.h (225572 => 225573)


--- trunk/Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.h	2017-12-06 08:51:47 UTC (rev 225572)
+++ trunk/Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.h	2017-12-06 11:46:50 UTC (rev 225573)
@@ -29,15 +29,10 @@
 #pragma once
 
 #include "IntSize.h"
-#include <wtf/RefPtr.h>
+#include <wtf/MallocPtr.h>
+#include <wtf/Ref.h>
 #include <wtf/ThreadSafeRefCounted.h>
 
-namespace WebCore {
-class GraphicsContext;
-class Image;
-class ImageBuffer;
-}
-
 namespace Nicosia {
 
 class Buffer : public ThreadSafeRefCounted<Buffer> {
@@ -53,14 +48,13 @@
 
     bool supportsAlpha() const { return m_flags & SupportsAlpha; }
     const WebCore::IntSize& size() const { return m_size; }
+    int stride() const { return m_size.width() * 4; }
+    unsigned char* data() const { return m_data.get(); }
 
-    WebCore::GraphicsContext& context();
-    RefPtr<WebCore::Image> uploadImage();
-
 private:
     Buffer(const WebCore::IntSize&, Flags);
 
-    std::unique_ptr<WebCore::ImageBuffer> m_imageBuffer;
+    MallocPtr<unsigned char> m_data;
     WebCore::IntSize m_size;
     Flags m_flags;
 };

Added: trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingContext.cpp (0 => 225573)


--- trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingContext.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingContext.cpp	2017-12-06 11:46:50 UTC (rev 225573)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2017 Metrological Group B.V.
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 AND CONTRIBUTORS
+ * "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
+ * HOLDER 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 "NicosiaPaintingContext.h"
+
+#if USE(CAIRO)
+#include "NicosiaPaintingContextCairo.h"
+#endif
+
+namespace Nicosia {
+
+std::unique_ptr<PaintingContext> PaintingContext::create(Buffer& buffer)
+{
+#if USE(CAIRO)
+    return std::unique_ptr<PaintingContext>(new PaintingContextCairo(buffer));
+#else
+#error A Nicosia::PaintingContext implementation is required.
+#endif
+}
+
+} // namespace Nicosia

Added: trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingContext.h (0 => 225573)


--- trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingContext.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingContext.h	2017-12-06 11:46:50 UTC (rev 225573)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2017 Metrological Group B.V.
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 AND CONTRIBUTORS
+ * "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
+ * HOLDER 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.
+ */
+
+#pragma once
+
+#include <memory>
+
+namespace WebCore {
+class GraphicsContext;
+}
+
+namespace Nicosia {
+
+class Buffer;
+
+class PaintingContext {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    template<typename T>
+    static void paint(Buffer& buffer, const T& paintFunctor)
+    {
+        auto paintingContext = PaintingContext::create(buffer);
+        paintFunctor(paintingContext->graphicsContext());
+    }
+
+    virtual ~PaintingContext() = default;
+
+protected:
+    virtual WebCore::GraphicsContext& graphicsContext() = 0;
+
+private:
+    static std::unique_ptr<PaintingContext> create(Buffer&);
+};
+
+} // namespace Nicosia

Added: trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingContextCairo.cpp (0 => 225573)


--- trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingContextCairo.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingContextCairo.cpp	2017-12-06 11:46:50 UTC (rev 225573)
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2017 Metrological Group B.V.
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 AND CONTRIBUTORS
+ * "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
+ * HOLDER 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 "NicosiaPaintingContextCairo.h"
+
+#if USE(CAIRO)
+
+#include "GraphicsContext.h"
+#include "NicosiaBuffer.h"
+#include "PlatformContextCairo.h"
+#include "RefPtrCairo.h"
+#include <cairo.h>
+#include <utility>
+
+namespace Nicosia {
+
+PaintingContextCairo::PaintingContextCairo(Buffer& buffer)
+{
+    // Balanced by the deref in the s_bufferKey user data destroy callback.
+    buffer.ref();
+
+    m_cairo.surface = adoptRef(cairo_image_surface_create_for_data(buffer.data(),
+        CAIRO_FORMAT_ARGB32, buffer.size().width(), buffer.size().height(), buffer.stride()));
+
+    static cairo_user_data_key_t s_bufferKey;
+    cairo_surface_set_user_data(m_cairo.surface.get(), &s_bufferKey,
+        new std::pair<Buffer*, PaintingContextCairo*> { &buffer, this },
+        [](void* data)
+        {
+            auto* userData = static_cast<std::pair<Buffer*, PaintingContextCairo*>*>(data);
+
+            // Deref the Buffer object.
+            userData->first->deref();
+#if !ASSERT_DISABLED
+            // Mark the deletion of the cairo_surface_t object associated with this
+            // PaintingContextCairo as complete. This way we check that the cairo_surface_t
+            // object doesn't outlive the PaintingContextCairo through which it was used.
+            userData->second->m_deletionComplete = true;
+#endif
+            delete userData;
+        });
+
+    m_cairo.context = adoptRef(cairo_create(m_cairo.surface.get()));
+    m_platformContext = std::make_unique<WebCore::PlatformContextCairo>(m_cairo.context.get());
+    m_graphicsContext = std::make_unique<WebCore::GraphicsContext>(m_platformContext.get());
+}
+
+PaintingContextCairo::~PaintingContextCairo()
+{
+    cairo_surface_flush(m_cairo.surface.get());
+
+    m_graphicsContext = nullptr;
+    m_platformContext = nullptr;
+    m_cairo.context = nullptr;
+    m_cairo.surface = nullptr;
+
+    // With all the Cairo references purged, the cairo_surface_t object should be destroyed
+    // as well. This is checked by asserting that m_deletionComplete is true, which should
+    // be the case if the s_bufferKey user data destroy callback has been invoked upon the
+    // cairo_surface_t destruction.
+    ASSERT(m_deletionComplete);
+}
+
+WebCore::GraphicsContext& PaintingContextCairo::graphicsContext()
+{
+    return *m_graphicsContext;
+}
+
+} // namespace Nicosia
+
+#endif // USE(CAIRO)

Added: trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingContextCairo.h (0 => 225573)


--- trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingContextCairo.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingContextCairo.h	2017-12-06 11:46:50 UTC (rev 225573)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2017 Metrological Group B.V.
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 AND CONTRIBUTORS
+ * "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
+ * HOLDER 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.
+ */
+
+#pragma once
+
+#include "NicosiaPaintingContext.h"
+
+#if USE(CAIRO)
+
+#include <wtf/RefPtr.h>
+
+typedef struct _cairo cairo_t;
+typedef struct _cairo_surface cairo_surface_t;
+
+namespace WebCore {
+class GraphicsContext;
+class PlatformContextCairo;
+}
+
+namespace Nicosia {
+
+class PaintingContextCairo final : public PaintingContext {
+public:
+    explicit PaintingContextCairo(Buffer&);
+    virtual ~PaintingContextCairo();
+
+private:
+    WebCore::GraphicsContext& graphicsContext() override;
+
+    struct {
+        RefPtr<cairo_surface_t> surface;
+        RefPtr<cairo_t> context;
+    } m_cairo;
+    std::unique_ptr<WebCore::PlatformContextCairo> m_platformContext;
+    std::unique_ptr<WebCore::GraphicsContext> m_graphicsContext;
+
+#ifndef NDEBUG
+    bool m_deletionComplete { false };
+#endif
+};
+
+} // namespace Nicosia
+
+#endif // USE(CAIRO)

Modified: trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingEngineBasic.cpp (225572 => 225573)


--- trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingEngineBasic.cpp	2017-12-06 08:51:47 UTC (rev 225572)
+++ trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingEngineBasic.cpp	2017-12-06 11:46:50 UTC (rev 225573)
@@ -32,6 +32,7 @@
 #include "GraphicsContext.h"
 #include "GraphicsLayer.h"
 #include "NicosiaBuffer.h"
+#include "NicosiaPaintingContext.h"
 
 namespace Nicosia {
 
@@ -42,23 +43,28 @@
 
 bool PaintingEngineBasic::paint(GraphicsLayer& layer, Ref<Buffer>&& buffer, const IntRect& sourceRect, const IntRect& mappedSourceRect, const IntRect& targetRect, float contentsScale)
 {
-    auto& context = buffer->context();
-    context.save();
-    context.clip(targetRect);
-    context.translate(targetRect.x(), targetRect.y());
+    bool supportsAlpha = buffer->supportsAlpha();
+    PaintingContext::paint(buffer,
+        [&layer, sourceRect, mappedSourceRect, targetRect, contentsScale, supportsAlpha]
+        (GraphicsContext& context)
+        {
+            context.save();
+            context.clip(targetRect);
+            context.translate(targetRect.x(), targetRect.y());
 
-    if (buffer->supportsAlpha()) {
-        context.setCompositeOperation(CompositeCopy);
-        context.fillRect(IntRect(IntPoint::zero(), sourceRect.size()), Color::transparent);
-        context.setCompositeOperation(CompositeSourceOver);
-    }
+            if (supportsAlpha) {
+                context.setCompositeOperation(CompositeCopy);
+                context.fillRect(IntRect(IntPoint::zero(), sourceRect.size()), Color::transparent);
+                context.setCompositeOperation(CompositeSourceOver);
+            }
 
-    context.translate(-sourceRect.x(), -sourceRect.y());
-    context.scale(FloatSize(contentsScale, contentsScale));
+            context.translate(-sourceRect.x(), -sourceRect.y());
+            context.scale(FloatSize(contentsScale, contentsScale));
 
-    layer.paintGraphicsLayerContents(context, mappedSourceRect);
+            layer.paintGraphicsLayerContents(context, mappedSourceRect);
 
-    context.restore();
+            context.restore();
+        });
     return true;
 }
 

Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp (225572 => 225573)


--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp	2017-12-06 08:51:47 UTC (rev 225572)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp	2017-12-06 11:46:50 UTC (rev 225573)
@@ -31,6 +31,7 @@
 #include "CoordinatedGraphicsState.h"
 #include "GraphicsContext.h"
 #include "NicosiaBuffer.h"
+#include "NicosiaPaintingContext.h"
 
 namespace WebCore {
 
@@ -104,16 +105,16 @@
     m_buffer = Nicosia::Buffer::create(IntSize(m_image->size()), !m_image->currentFrameKnownToBeOpaque() ? Nicosia::Buffer::SupportsAlpha : Nicosia::Buffer::NoFlags);
     ASSERT(m_buffer);
 
-    IntRect rect(IntPoint::zero(), IntSize(m_image->size()));
+    Nicosia::PaintingContext::paint(*m_buffer,
+        [this](GraphicsContext& context)
+        {
+            IntRect rect(IntPoint::zero(), IntSize(m_image->size()));
+            context.save();
+            context.clip(rect);
+            context.drawImage(*m_image, rect, rect);
+            context.restore();
+        });
 
-    {
-        GraphicsContext& context = m_buffer->context();
-        context.save();
-        context.clip(rect);
-        context.drawImage(*m_image, rect, rect);
-        context.restore();
-    }
-
     m_nativeImagePtr = m_image->nativeImageForCurrentFrame();
 
     m_client->updateImageBacking(id(), m_buffer.copyRef());

Modified: trunk/Source/WebKit/ChangeLog (225572 => 225573)


--- trunk/Source/WebKit/ChangeLog	2017-12-06 08:51:47 UTC (rev 225572)
+++ trunk/Source/WebKit/ChangeLog	2017-12-06 11:46:50 UTC (rev 225573)
@@ -1,3 +1,19 @@
+2017-12-06  Zan Dobersek  <[email protected]>
+
+        [CoordGraphics] Introduce Nicosia::PaintingContext, add Cairo implementation
+        https://bugs.webkit.org/show_bug.cgi?id=180239
+
+        Reviewed by Michael Catanzaro.
+
+        With Nicosia::Buffer now only providing the memory area into which the
+        tile content was rasterized, we can simplify the BitmapTexture update
+        greatly -- we don't have to create a BitmapImage anymore and retrieve
+        memory pointer from the contained cairo_surface_t object. Instead, we
+        just copy to GPU the memory that Nicosia::Buffer controls.
+
+        * Shared/CoordinatedGraphics/CoordinatedBackingStore.cpp:
+        (WebKit::CoordinatedBackingStoreTile::swapBuffers):
+
 2017-12-05  Brent Fulgham  <[email protected]>
 
         Limit user agent versioning to an upper bound

Modified: trunk/Source/WebKit/Shared/CoordinatedGraphics/CoordinatedBackingStore.cpp (225572 => 225573)


--- trunk/Source/WebKit/Shared/CoordinatedGraphics/CoordinatedBackingStore.cpp	2017-12-06 08:51:47 UTC (rev 225572)
+++ trunk/Source/WebKit/Shared/CoordinatedGraphics/CoordinatedBackingStore.cpp	2017-12-06 11:46:50 UTC (rev 225573)
@@ -48,8 +48,7 @@
     } else if (m_buffer->supportsAlpha() == m_texture->isOpaque())
         m_texture->reset(m_tileRect.size(), m_buffer->supportsAlpha());
 
-    auto uploadImage = m_buffer->uploadImage();
-    m_texture->updateContents(uploadImage.get(), m_sourceRect, m_bufferOffset, BitmapTexture::UpdateCanModifyOriginalImageData);
+    m_texture->updateContents(m_buffer->data(), m_sourceRect, m_bufferOffset, m_buffer->stride(), BitmapTexture::UpdateCanModifyOriginalImageData);
     m_buffer = nullptr;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to