Skip to content

Commit ee006a2

Browse files
committed
[GTK][WPE] Random incorrect image displayed as the background of a div
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
1 parent da591c3 commit ee006a2

4 files changed

Lines changed: 22 additions & 2 deletions

File tree

Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "RefPtrCairo.h"
4040
#include "Region.h"
4141
#include <wtf/Assertions.h>
42+
#include <wtf/Atomics.h>
4243
#include <wtf/NeverDestroyed.h>
4344
#include <wtf/UniqueArray.h>
4445
#include <wtf/Vector.h>
@@ -53,6 +54,9 @@
5354

5455
namespace WebCore {
5556

57+
static cairo_user_data_key_t s_surfaceUniqueIDKey;
58+
static Atomic<uintptr_t> s_surfaceUniqueID = 1;
59+
5660
#if USE(FREETYPE)
5761
RecursiveLock& cairoFontLock()
5862
{
@@ -381,6 +385,16 @@ cairo_matrix_t toCairoMatrix(const AffineTransform& transform)
381385
return cairo_matrix_t { transform.a(), transform.b(), transform.c(), transform.d(), transform.e(), transform.f() };
382386
}
383387

388+
void attachSurfaceUniqueID(cairo_surface_t* surface)
389+
{
390+
cairo_surface_set_user_data(surface, &s_surfaceUniqueIDKey, reinterpret_cast<void*>(s_surfaceUniqueID.exchangeAdd(1)), nullptr);
391+
}
392+
393+
uintptr_t getSurfaceUniqueID(cairo_surface_t* surface)
394+
{
395+
return reinterpret_cast<uintptr_t>(cairo_surface_get_user_data(surface, &s_surfaceUniqueIDKey));
396+
}
397+
384398
} // namespace WebCore
385399

386400
#endif // USE(CAIRO)

Source/WebCore/platform/graphics/cairo/CairoUtilities.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ RefPtr<cairo_region_t> toCairoRegion(const Region&);
9999

100100
cairo_matrix_t toCairoMatrix(const AffineTransform&);
101101

102+
void attachSurfaceUniqueID(cairo_surface_t*);
103+
uintptr_t getSurfaceUniqueID(cairo_surface_t*);
104+
102105
} // namespace WebCore
103106

104107
#endif // USE(CAIRO)

Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#if USE(COORDINATED_GRAPHICS)
2828

29+
#include "CairoUtilities.h"
2930
#include "FloatQuad.h"
3031
#include "GraphicsContext.h"
3132
#include "GraphicsLayer.h"
@@ -908,7 +909,7 @@ void CoordinatedGraphicsLayer::flushCompositingStateForThisLayerOnly()
908909
ASSERT(m_compositedImage);
909910
auto& image = *m_compositedImage;
910911
uintptr_t imageID = reinterpret_cast<uintptr_t>(&image);
911-
uintptr_t nativeImageID = reinterpret_cast<uintptr_t>(m_compositedNativeImage->platformImage().get());
912+
uintptr_t nativeImageID = getSurfaceUniqueID(m_compositedNativeImage->platformImage().get());
912913

913914
// Respawn the ImageBacking object if the underlying image changed.
914915
if (m_nicosia.imageBacking) {
@@ -928,7 +929,7 @@ void CoordinatedGraphicsLayer::flushCompositingStateForThisLayerOnly()
928929
auto& layerState = impl.layerState();
929930
layerState.imageID = imageID;
930931
layerState.update.isVisible = transformedVisibleRect().intersects(IntRect(contentsRect()));
931-
if (layerState.update.isVisible && layerState.update.nativeImageID != nativeImageID) {
932+
if (layerState.update.isVisible && (!nativeImageID || layerState.update.nativeImageID != nativeImageID)) {
932933
layerState.update.nativeImageID = nativeImageID;
933934
layerState.update.imageBackingStore = m_coordinator->imageBackingStore(nativeImageID,
934935
[&] {

Source/WebCore/platform/image-decoders/cairo/ImageBackingStoreCairo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525

2626
#include "config.h"
27+
#include "CairoUtilities.h"
2728
#include "ImageBackingStore.h"
2829

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

45+
attachSurfaceUniqueID(surface.get());
4446
return surface;
4547
}
4648

0 commit comments

Comments
 (0)