Skip to content

Commit

Permalink
[GTK][WPE] Random incorrect image displayed as the background of a div
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=265990

Reviewed by Žan Doberšek.

Add an unique ID to cairo surfaces created in ImageBackingStoreCairo. This unique ID allows us
to differentiate when the cairo surface that's backing an image has changed, so we are sure that
we're not using an incorrect value cached inside some ImageBackingStore.

* Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp:
(WebCore::attachSurfaceUniqueID):
(WebCore::getSurfaceUniqueID):
* Source/WebCore/platform/graphics/cairo/CairoUtilities.h:
* Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp:
(WebCore::CoordinatedGraphicsLayer::flushCompositingStateForThisLayerOnly):
* Source/WebCore/platform/image-decoders/cairo/ImageBackingStoreCairo.cpp:
(WebCore::ImageBackingStore::image const):

Canonical link: https://commits.webkit.org/272009@main
  • Loading branch information
magomez committed Dec 13, 2023
1 parent 791a42d commit fcd6924
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
14 changes: 14 additions & 0 deletions Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "RefPtrCairo.h"
#include "Region.h"
#include <wtf/Assertions.h>
#include <wtf/Atomics.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/UniqueArray.h>
#include <wtf/Vector.h>
Expand All @@ -48,6 +49,9 @@

namespace WebCore {

static cairo_user_data_key_t s_surfaceUniqueIDKey;
static Atomic<uintptr_t> s_surfaceUniqueID = 1;

#if USE(FREETYPE)
RecursiveLock& cairoFontLock()
{
Expand Down Expand Up @@ -413,6 +417,16 @@ cairo_matrix_t toCairoMatrix(const AffineTransform& transform)
return cairo_matrix_t { transform.a(), transform.b(), transform.c(), transform.d(), transform.e(), transform.f() };
}

void attachSurfaceUniqueID(cairo_surface_t* surface)
{
cairo_surface_set_user_data(surface, &s_surfaceUniqueIDKey, reinterpret_cast<void*>(s_surfaceUniqueID.exchangeAdd(1)), nullptr);
}

uintptr_t getSurfaceUniqueID(cairo_surface_t* surface)
{
return reinterpret_cast<uintptr_t>(cairo_surface_get_user_data(surface, &s_surfaceUniqueIDKey));
}

} // namespace WebCore

#endif // USE(CAIRO)
3 changes: 3 additions & 0 deletions Source/WebCore/platform/graphics/cairo/CairoUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ RefPtr<cairo_region_t> toCairoRegion(const Region&);

cairo_matrix_t toCairoMatrix(const AffineTransform&);

void attachSurfaceUniqueID(cairo_surface_t*);
uintptr_t getSurfaceUniqueID(cairo_surface_t*);

} // namespace WebCore

#endif // USE(CAIRO)
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#if USE(COORDINATED_GRAPHICS)

#include "CairoUtilities.h"
#include "FloatQuad.h"
#include "GraphicsContext.h"
#include "GraphicsLayer.h"
Expand Down Expand Up @@ -892,7 +893,7 @@ void CoordinatedGraphicsLayer::flushCompositingStateForThisLayerOnly()
ASSERT(m_compositedImage);
auto& image = *m_compositedImage;
uintptr_t imageID = reinterpret_cast<uintptr_t>(&image);
uintptr_t nativeImageID = reinterpret_cast<uintptr_t>(m_compositedNativeImage->platformImage().get());
uintptr_t nativeImageID = getSurfaceUniqueID(m_compositedNativeImage->platformImage().get());

// Respawn the ImageBacking object if the underlying image changed.
if (m_nicosia.imageBacking) {
Expand All @@ -910,7 +911,7 @@ void CoordinatedGraphicsLayer::flushCompositingStateForThisLayerOnly()
auto& layerState = m_nicosia.imageBacking->layerState();
layerState.imageID = imageID;
layerState.update.isVisible = transformedVisibleRect().intersects(IntRect(contentsRect()));
if (layerState.update.isVisible && layerState.update.nativeImageID != nativeImageID) {
if (layerState.update.isVisible && (!nativeImageID || layerState.update.nativeImageID != nativeImageID)) {
layerState.update.nativeImageID = nativeImageID;
layerState.update.imageBackingStore = m_coordinator->imageBackingStore(nativeImageID,
[&] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

#include "config.h"
#include "CairoUtilities.h"
#include "ImageBackingStore.h"

#include <cairo.h>
Expand All @@ -41,6 +42,7 @@ PlatformImagePtr ImageBackingStore::image() const
static_cast<DataSegment*>(data)->deref();
});

attachSurfaceUniqueID(surface.get());
return surface;
}

Expand Down

0 comments on commit fcd6924

Please sign in to comment.