Changeset 225573 in webkit


Ignore:
Timestamp:
Dec 6, 2017 3:46:50 AM (6 years ago)
Author:
zandobersek@gmail.com
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):

Location:
trunk/Source
Files:
4 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r225567 r225573  
     12017-12-06  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        [CoordGraphics] Introduce Nicosia::PaintingContext, add Cairo implementation
     4        https://bugs.webkit.org/show_bug.cgi?id=180239
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        As the next step in the Nicosia abstraction formation, we introduce
     9        Nicosia::PaintingContext. Implementations of this class will leverage a
     10        chosen 2D graphics library to paint (through GraphicsContext) into the
     11        memory area that's specified by a given Nicosia::Buffer object.
     12
     13        Nicosia::Buffer is slimmed down to only control the memory that's
     14        required for rasterization of an RGBA32 painting output. It mimics the
     15        Cairo ImageBuffer implementation by using FastMalloc to allocate the
     16        necessary memory. In the future this class might become an interface of
     17        which different implementations will be providing memory that's
     18        allocated through different ways. For instance, when GLES3 is available,
     19        it would be possible to map GPU memory into the process memory space and
     20        rasterize into that, effectively eliminating need for GPU uploads.
     21
     22        Since the ImageBuffer use in Nicosia::Buffer is dropped, the context()
     23        and uploadImage() methods are also removed. The functionality of
     24        ImageBuffer that was leveraged for CoordinatedGraphics rasterization
     25        still remains used through the PaintingContextCairo implementation. In
     26        the constructor of that class, with the target Nicosia::Buffer provided,
     27        we construct the cairo_surface_t and cairo_t objects that are necessary
     28        to create a combination of PlatformContextCairo and GraphicsContext
     29        objects that we can then use for rasterization.
     30
     31        Reference of the passed-in Nicosia::Buffer object is increased for the
     32        lifetime of the cairo_surface_t object that will be drawing into that
     33        buffer's memory area. This ensures the memory area doesn't disappear
     34        from a live cairo_surface_t. Still, the expectation is that the
     35        cairo_surface_t object won't outlive the PaintingContextCairo object's
     36        lifetime, since the cairo_t object is also managed here and deleted in
     37        the destructor. To test that, we use a cairo_surface_t user data key
     38        that in its destroy callback dereferences the Nicosia::Buffer object and
     39        also marks the deletion process for the related PaintingContextCairo
     40        object as complete. This m_deletionComplete value is tested in the
     41        destructor of the class, once all the Cairo references are nulled out.
     42
     43        The PaintingContext objects should be limited to a single scope,
     44        enabling the implementation resources to assume that the lifetime of the
     45        implementation object won't extend outside of the scope where it was
     46        created. To ensure that, the PaintingContext::paint() static function is
     47        added that creates the PaintingContext object and then executes the
     48        passed-in functor, passing it the GraphicsContext that should be used
     49        for drawing. Drawing is thus limited to that functor only, and the
     50        PaintingContext's create() function and the virtual graphicsContext()
     51        are not made public in the class.
     52
     53        No new tests -- no change in functionality.
     54
     55        * platform/TextureMapper.cmake:
     56        * platform/graphics/nicosia/NicosiaBuffer.cpp:
     57        (Nicosia::Buffer::Buffer):
     58        (Nicosia::Buffer::context): Deleted.
     59        (Nicosia::Buffer::uploadImage): Deleted.
     60        * platform/graphics/nicosia/NicosiaBuffer.h:
     61        (Nicosia::Buffer::stride const):
     62        (Nicosia::Buffer::data const):
     63        * platform/graphics/nicosia/NicosiaPaintingContext.cpp: Copied from Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.cpp.
     64        (Nicosia::PaintingContext::create):
     65        * platform/graphics/nicosia/NicosiaPaintingContext.h: Copied from Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.cpp.
     66        (Nicosia::PaintingContext::paint):
     67        * platform/graphics/nicosia/NicosiaPaintingContextCairo.cpp: Added.
     68        (Nicosia::PaintingContextCairo::PaintingContextCairo):
     69        (Nicosia::PaintingContextCairo::~PaintingContextCairo):
     70        (Nicosia::PaintingContextCairo::graphicsContext):
     71        * platform/graphics/nicosia/NicosiaPaintingContextCairo.h: Copied from Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.h.
     72        * platform/graphics/nicosia/NicosiaPaintingEngineBasic.cpp:
     73        (Nicosia::PaintingEngineBasic::paint):
     74        * platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp:
     75        (WebCore::CoordinatedImageBacking::update):
     76
    1772017-12-05  Fujii Hironori  <Hironori.Fujii@sony.com>
    278
  • trunk/Source/WebCore/platform/TextureMapper.cmake

    r225328 r225573  
    4848    list(APPEND WebCore_SOURCES
    4949        platform/graphics/nicosia/NicosiaBuffer.cpp
     50        platform/graphics/nicosia/NicosiaPaintingContext.cpp
     51        platform/graphics/nicosia/NicosiaPaintingContextCairo.cpp
    5052        platform/graphics/nicosia/NicosiaPaintingEngine.cpp
    5153        platform/graphics/nicosia/NicosiaPaintingEngineBasic.cpp
  • trunk/Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.cpp

    r225266 r225573  
    3030#include "NicosiaBuffer.h"
    3131
    32 #include "ImageBuffer.h"
     32#include <wtf/FastMalloc.h>
    3333
    3434namespace Nicosia {
     
    4040
    4141Buffer::Buffer(const WebCore::IntSize& size, Flags flags)
    42     : m_imageBuffer(WebCore::ImageBuffer::create(size, WebCore::Unaccelerated))
    43     , m_size(size)
     42    : m_size(size)
    4443    , m_flags(flags)
    4544{
     45    auto checkedArea = size.area() * 4;
     46    unsigned char* bufferData;
     47    if (!tryFastZeroedMalloc(checkedArea.unsafeGet()).getValue(bufferData))
     48        return;
     49
     50    m_data = adoptMallocPtr(bufferData);
    4651}
    4752
    4853Buffer::~Buffer() = default;
    4954
    50 WebCore::GraphicsContext& Buffer::context()
    51 {
    52     return m_imageBuffer->context();
    53 }
    54 
    55 RefPtr<WebCore::Image> Buffer::uploadImage()
    56 {
    57     return m_imageBuffer->copyImage(WebCore::DontCopyBackingStore);
    58 }
    59 
    6055} // namespace Nicosia
  • trunk/Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.h

    r225266 r225573  
    3030
    3131#include "IntSize.h"
    32 #include <wtf/RefPtr.h>
     32#include <wtf/MallocPtr.h>
     33#include <wtf/Ref.h>
    3334#include <wtf/ThreadSafeRefCounted.h>
    34 
    35 namespace WebCore {
    36 class GraphicsContext;
    37 class Image;
    38 class ImageBuffer;
    39 }
    4035
    4136namespace Nicosia {
     
    5449    bool supportsAlpha() const { return m_flags & SupportsAlpha; }
    5550    const WebCore::IntSize& size() const { return m_size; }
    56 
    57     WebCore::GraphicsContext& context();
    58     RefPtr<WebCore::Image> uploadImage();
     51    int stride() const { return m_size.width() * 4; }
     52    unsigned char* data() const { return m_data.get(); }
    5953
    6054private:
    6155    Buffer(const WebCore::IntSize&, Flags);
    6256
    63     std::unique_ptr<WebCore::ImageBuffer> m_imageBuffer;
     57    MallocPtr<unsigned char> m_data;
    6458    WebCore::IntSize m_size;
    6559    Flags m_flags;
  • trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingEngineBasic.cpp

    r225328 r225573  
    3333#include "GraphicsLayer.h"
    3434#include "NicosiaBuffer.h"
     35#include "NicosiaPaintingContext.h"
    3536
    3637namespace Nicosia {
     
    4344bool PaintingEngineBasic::paint(GraphicsLayer& layer, Ref<Buffer>&& buffer, const IntRect& sourceRect, const IntRect& mappedSourceRect, const IntRect& targetRect, float contentsScale)
    4445{
    45     auto& context = buffer->context();
    46     context.save();
    47     context.clip(targetRect);
    48     context.translate(targetRect.x(), targetRect.y());
     46    bool supportsAlpha = buffer->supportsAlpha();
     47    PaintingContext::paint(buffer,
     48        [&layer, sourceRect, mappedSourceRect, targetRect, contentsScale, supportsAlpha]
     49        (GraphicsContext& context)
     50        {
     51            context.save();
     52            context.clip(targetRect);
     53            context.translate(targetRect.x(), targetRect.y());
    4954
    50     if (buffer->supportsAlpha()) {
    51         context.setCompositeOperation(CompositeCopy);
    52         context.fillRect(IntRect(IntPoint::zero(), sourceRect.size()), Color::transparent);
    53         context.setCompositeOperation(CompositeSourceOver);
    54     }
     55            if (supportsAlpha) {
     56                context.setCompositeOperation(CompositeCopy);
     57                context.fillRect(IntRect(IntPoint::zero(), sourceRect.size()), Color::transparent);
     58                context.setCompositeOperation(CompositeSourceOver);
     59            }
    5560
    56     context.translate(-sourceRect.x(), -sourceRect.y());
    57     context.scale(FloatSize(contentsScale, contentsScale));
     61            context.translate(-sourceRect.x(), -sourceRect.y());
     62            context.scale(FloatSize(contentsScale, contentsScale));
    5863
    59     layer.paintGraphicsLayerContents(context, mappedSourceRect);
     64            layer.paintGraphicsLayerContents(context, mappedSourceRect);
    6065
    61     context.restore();
     66            context.restore();
     67        });
    6268    return true;
    6369}
  • trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp

    r225266 r225573  
    3232#include "GraphicsContext.h"
    3333#include "NicosiaBuffer.h"
     34#include "NicosiaPaintingContext.h"
    3435
    3536namespace WebCore {
     
    105106    ASSERT(m_buffer);
    106107
    107     IntRect rect(IntPoint::zero(), IntSize(m_image->size()));
    108 
    109     {
    110         GraphicsContext& context = m_buffer->context();
    111         context.save();
    112         context.clip(rect);
    113         context.drawImage(*m_image, rect, rect);
    114         context.restore();
    115     }
     108    Nicosia::PaintingContext::paint(*m_buffer,
     109        [this](GraphicsContext& context)
     110        {
     111            IntRect rect(IntPoint::zero(), IntSize(m_image->size()));
     112            context.save();
     113            context.clip(rect);
     114            context.drawImage(*m_image, rect, rect);
     115            context.restore();
     116        });
    116117
    117118    m_nativeImagePtr = m_image->nativeImageForCurrentFrame();
  • trunk/Source/WebKit/ChangeLog

    r225562 r225573  
     12017-12-06  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        [CoordGraphics] Introduce Nicosia::PaintingContext, add Cairo implementation
     4        https://bugs.webkit.org/show_bug.cgi?id=180239
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        With Nicosia::Buffer now only providing the memory area into which the
     9        tile content was rasterized, we can simplify the BitmapTexture update
     10        greatly -- we don't have to create a BitmapImage anymore and retrieve
     11        memory pointer from the contained cairo_surface_t object. Instead, we
     12        just copy to GPU the memory that Nicosia::Buffer controls.
     13
     14        * Shared/CoordinatedGraphics/CoordinatedBackingStore.cpp:
     15        (WebKit::CoordinatedBackingStoreTile::swapBuffers):
     16
    1172017-12-05  Brent Fulgham  <bfulgham@apple.com>
    218
  • trunk/Source/WebKit/Shared/CoordinatedGraphics/CoordinatedBackingStore.cpp

    r225266 r225573  
    4949        m_texture->reset(m_tileRect.size(), m_buffer->supportsAlpha());
    5050
    51     auto uploadImage = m_buffer->uploadImage();
    52     m_texture->updateContents(uploadImage.get(), m_sourceRect, m_bufferOffset, BitmapTexture::UpdateCanModifyOriginalImageData);
     51    m_texture->updateContents(m_buffer->data(), m_sourceRect, m_bufferOffset, m_buffer->stride(), BitmapTexture::UpdateCanModifyOriginalImageData);
    5352    m_buffer = nullptr;
    5453}
Note: See TracChangeset for help on using the changeset viewer.