Changeset 225573 in webkit
- Timestamp:
- Dec 6, 2017 3:46:50 AM (6 years ago)
- Location:
- trunk/Source
- Files:
-
- 4 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r225567 r225573 1 2017-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 1 77 2017-12-05 Fujii Hironori <Hironori.Fujii@sony.com> 2 78 -
trunk/Source/WebCore/platform/TextureMapper.cmake
r225328 r225573 48 48 list(APPEND WebCore_SOURCES 49 49 platform/graphics/nicosia/NicosiaBuffer.cpp 50 platform/graphics/nicosia/NicosiaPaintingContext.cpp 51 platform/graphics/nicosia/NicosiaPaintingContextCairo.cpp 50 52 platform/graphics/nicosia/NicosiaPaintingEngine.cpp 51 53 platform/graphics/nicosia/NicosiaPaintingEngineBasic.cpp -
trunk/Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.cpp
r225266 r225573 30 30 #include "NicosiaBuffer.h" 31 31 32 #include "ImageBuffer.h"32 #include <wtf/FastMalloc.h> 33 33 34 34 namespace Nicosia { … … 40 40 41 41 Buffer::Buffer(const WebCore::IntSize& size, Flags flags) 42 : m_imageBuffer(WebCore::ImageBuffer::create(size, WebCore::Unaccelerated)) 43 , m_size(size) 42 : m_size(size) 44 43 , m_flags(flags) 45 44 { 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); 46 51 } 47 52 48 53 Buffer::~Buffer() = default; 49 54 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 60 55 } // namespace Nicosia -
trunk/Source/WebCore/platform/graphics/nicosia/NicosiaBuffer.h
r225266 r225573 30 30 31 31 #include "IntSize.h" 32 #include <wtf/RefPtr.h> 32 #include <wtf/MallocPtr.h> 33 #include <wtf/Ref.h> 33 34 #include <wtf/ThreadSafeRefCounted.h> 34 35 namespace WebCore {36 class GraphicsContext;37 class Image;38 class ImageBuffer;39 }40 35 41 36 namespace Nicosia { … … 54 49 bool supportsAlpha() const { return m_flags & SupportsAlpha; } 55 50 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(); } 59 53 60 54 private: 61 55 Buffer(const WebCore::IntSize&, Flags); 62 56 63 std::unique_ptr<WebCore::ImageBuffer> m_imageBuffer;57 MallocPtr<unsigned char> m_data; 64 58 WebCore::IntSize m_size; 65 59 Flags m_flags; -
trunk/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingEngineBasic.cpp
r225328 r225573 33 33 #include "GraphicsLayer.h" 34 34 #include "NicosiaBuffer.h" 35 #include "NicosiaPaintingContext.h" 35 36 36 37 namespace Nicosia { … … 43 44 bool PaintingEngineBasic::paint(GraphicsLayer& layer, Ref<Buffer>&& buffer, const IntRect& sourceRect, const IntRect& mappedSourceRect, const IntRect& targetRect, float contentsScale) 44 45 { 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()); 49 54 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 } 55 60 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)); 58 63 59 layer.paintGraphicsLayerContents(context, mappedSourceRect);64 layer.paintGraphicsLayerContents(context, mappedSourceRect); 60 65 61 context.restore(); 66 context.restore(); 67 }); 62 68 return true; 63 69 } -
trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp
r225266 r225573 32 32 #include "GraphicsContext.h" 33 33 #include "NicosiaBuffer.h" 34 #include "NicosiaPaintingContext.h" 34 35 35 36 namespace WebCore { … … 105 106 ASSERT(m_buffer); 106 107 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 }); 116 117 117 118 m_nativeImagePtr = m_image->nativeImageForCurrentFrame(); -
trunk/Source/WebKit/ChangeLog
r225562 r225573 1 2017-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 1 17 2017-12-05 Brent Fulgham <bfulgham@apple.com> 2 18 -
trunk/Source/WebKit/Shared/CoordinatedGraphics/CoordinatedBackingStore.cpp
r225266 r225573 49 49 m_texture->reset(m_tileRect.size(), m_buffer->supportsAlpha()); 50 50 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); 53 52 m_buffer = nullptr; 54 53 }
Note: See TracChangeset
for help on using the changeset viewer.