Skip to content

Commit

Permalink
Remove ImageBufferBackend specific isOriginAtBottomLeftCorner
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=273676
rdar://127480089

Reviewed by Simon Fraser.

GraphicsContext has its origin at the top left corner. Currently Cocoa
CG is the only one using
ImageBufferBackendSubclass::originAtBottomLeftCorner == true. Currently
Cocoa does not have any other GraphicsContexts than CG. Hardcode the
logic into ImageBufferBackend. This way the base transform can be
computed without knowing which type backend is. This is needed for
RemoteImageBufferProxy construction, where the backend, currently, is
obtained only after GPUP has decided which backend worked.

This is work towards removeing the
RemoteImageBufferProxy::create<Backend> template parameter. That is work
towards being able to fix deadlocks wrt. cross-thread ImageBuffer use in
GPUP.

* Source/WebCore/platform/graphics/ImageBuffer.h:
(WebCore::ImageBuffer::populateBackendInfo):
* Source/WebCore/platform/graphics/ImageBufferBackend.cpp:
(WebCore::ImageBufferBackend::calculateBaseTransform):
* Source/WebCore/platform/graphics/ImageBufferBackend.h:
(WebCore::ImageBufferBackend::originAtBottomLeftCorner const): Deleted.
* Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp:
(WebCore::ImageBufferCGBackend::applyBaseTransform const):
(WebCore::ImageBufferCGBackend::originAtBottomLeftCorner const): Deleted.
* Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.h:
* Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:
(WebKit::RemoteRenderingBackendProxy::createDisplayListRecorder):
* Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferRemoteIOSurfaceBackend.h:
* Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBitmapBackend.h:

Canonical link: https://commits.webkit.org/278505@main
  • Loading branch information
kkinnunen-apple committed May 8, 2024
1 parent 87a9d5d commit af6077a
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Source/WebCore/platform/graphics/ImageBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class ImageBuffer : public ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr<Image
{
return {
BackendType::renderingMode,
BackendType::calculateBaseTransform(parameters, BackendType::isOriginAtBottomLeftCorner),
ImageBufferBackend::calculateBaseTransform(parameters),
BackendType::calculateMemoryCost(parameters),
BackendType::calculateExternalMemoryCost(parameters)
};
Expand Down
15 changes: 7 additions & 8 deletions Source/WebCore/platform/graphics/ImageBufferBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,16 @@ void ImageBufferBackend::putPixelBuffer(const PixelBuffer& sourcePixelBuffer, co
convertImagePixels(source, destination, destinationRect.size());
}

AffineTransform ImageBufferBackend::calculateBaseTransform(const Parameters& parameters, bool originAtBottomLeftCorner)
AffineTransform ImageBufferBackend::calculateBaseTransform(const Parameters& parameters)
{
AffineTransform baseTransform;

if (originAtBottomLeftCorner) {
baseTransform.scale(1, -1);
baseTransform.translate(0, -parameters.backendSize.height());
}

#if USE(CG)
// CoreGraphics origin is at bottom left corner. GraphicsContext origin is at top left corner. Flip the drawing with GraphicsContext base
// transform.
baseTransform.scale(1, -1);
baseTransform.translate(0, -parameters.backendSize.height());
#endif
baseTransform.scale(parameters.resolutionScale);

return baseTransform;
}

Expand Down
5 changes: 1 addition & 4 deletions Source/WebCore/platform/graphics/ImageBufferBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class ImageBufferBackend {

WEBCORE_EXPORT static size_t calculateMemoryCost(const IntSize& backendSize, unsigned bytesPerRow);
static size_t calculateExternalMemoryCost(const Parameters&) { return 0; }
WEBCORE_EXPORT static AffineTransform calculateBaseTransform(const Parameters&, bool originAtBottomLeftCorner);
WEBCORE_EXPORT static AffineTransform calculateBaseTransform(const Parameters&);

virtual GraphicsContext& context() = 0;
virtual void flushContext() { }
Expand Down Expand Up @@ -146,9 +146,6 @@ class ImageBufferBackend {

virtual std::unique_ptr<ThreadSafeImageBufferFlusher> createFlusher() { return nullptr; }

static constexpr bool isOriginAtBottomLeftCorner = false;
virtual bool originAtBottomLeftCorner() const { return isOriginAtBottomLeftCorner; }

static constexpr RenderingMode renderingMode = RenderingMode::Unaccelerated;

virtual bool canMapBackingStore() const = 0;
Expand Down
7 changes: 1 addition & 6 deletions Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,10 @@ std::unique_ptr<ThreadSafeImageBufferFlusher> ImageBufferCGBackend::createFlushe

ImageBufferCGBackend::~ImageBufferCGBackend() = default;

bool ImageBufferCGBackend::originAtBottomLeftCorner() const
{
return isOriginAtBottomLeftCorner;
}

void ImageBufferCGBackend::applyBaseTransform(GraphicsContextCG& context) const
{
context.applyDeviceScaleFactor(m_parameters.resolutionScale);
context.setCTM(calculateBaseTransform(m_parameters, originAtBottomLeftCorner()));
context.setCTM(calculateBaseTransform(m_parameters));
}

String ImageBufferCGBackend::debugDescription() const
Expand Down
2 changes: 0 additions & 2 deletions Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class WEBCORE_EXPORT ImageBufferCGBackend : public ImageBufferBackend {
public:
~ImageBufferCGBackend() override;
static unsigned calculateBytesPerRow(const IntSize& backendSize);
static constexpr bool isOriginAtBottomLeftCorner = true;

protected:
using ImageBufferBackend::ImageBufferBackend;
Expand All @@ -49,7 +48,6 @@ class WEBCORE_EXPORT ImageBufferCGBackend : public ImageBufferBackend {

String debugDescription() const override;

bool originAtBottomLeftCorner() const override;
mutable std::unique_ptr<GraphicsContextCG> m_context;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,9 @@ std::unique_ptr<RemoteDisplayListRecorderProxy> RemoteRenderingBackendProxy::cre
ASSERT(WebProcess::singleton().shouldUseRemoteRenderingFor(RenderingPurpose::DOM));
ImageBufferParameters parameters { size, resolutionScale, colorSpace, pixelFormat, purpose };
auto renderingMode = RenderingMode::Unaccelerated;
auto transform = ImageBufferBackend::calculateBaseTransform(ImageBuffer::backendParameters(parameters), ImageBufferShareableBitmapBackend::isOriginAtBottomLeftCorner);

#if HAVE(IOSURFACE)
if (options.contains(ImageBufferOptions::Accelerated)) {
auto transform = ImageBufferBackend::calculateBaseTransform(ImageBuffer::backendParameters(parameters));
if (options.contains(ImageBufferOptions::Accelerated))
renderingMode = RenderingMode::Accelerated;
transform = ImageBufferBackend::calculateBaseTransform(ImageBuffer::backendParameters(parameters), ImageBufferRemoteIOSurfaceBackend::isOriginAtBottomLeftCorner);
}
#endif

return makeUnique<RemoteDisplayListRecorderProxy>(*this, renderingResourceIdentifier, colorSpace, renderingMode, FloatRect { { }, size }, transform);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class ImageBufferRemoteIOSurfaceBackend final : public WebCore::ImageBufferBacke
{
}

static constexpr bool isOriginAtBottomLeftCorner = true;
static constexpr WebCore::RenderingMode renderingMode = WebCore::RenderingMode::Accelerated;
bool canMapBackingStore() const final;

Expand All @@ -65,8 +64,6 @@ class ImageBufferRemoteIOSurfaceBackend final : public WebCore::ImageBufferBacke
void getPixelBuffer(const WebCore::IntRect&, WebCore::PixelBuffer&) final;
void putPixelBuffer(const WebCore::PixelBuffer&, const WebCore::IntRect& srcRect, const WebCore::IntPoint& destPoint, WebCore::AlphaPremultiplication destFormat) final;

bool originAtBottomLeftCorner() const final { return isOriginAtBottomLeftCorner; }

unsigned bytesPerRow() const final;

WebCore::VolatilityState volatilityState() const final { return m_volatilityState; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ class ImageBufferShareableMappedIOSurfaceBitmapBackend final : public WebCore::I
~ImageBufferShareableMappedIOSurfaceBitmapBackend();

static constexpr WebCore::RenderingMode renderingMode = WebCore::RenderingMode::Accelerated;
static constexpr bool isOriginAtBottomLeftCorner = true;
bool canMapBackingStore() const final;

std::optional<ImageBufferBackendHandle> createBackendHandle(WebCore::SharedMemory::Protection = WebCore::SharedMemory::Protection::ReadWrite) const final;
WebCore::GraphicsContext& context() final;
bool originAtBottomLeftCorner() const override { return isOriginAtBottomLeftCorner; }
private:
// ImageBufferBackendSharing
ImageBufferBackendSharing* toBackendSharing() final { return this; }
Expand Down

0 comments on commit af6077a

Please sign in to comment.