From f191431e04f70753a78634fa0f73e752526c222a Mon Sep 17 00:00:00 2001 From: Hparty <420024556@qq.com> Date: Wed, 30 Oct 2024 20:42:04 +0800 Subject: [PATCH] fix bug while task does not submit --- src/gpu/OpContext.cpp | 6 +++++- test/src/LayerTest.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/gpu/OpContext.cpp b/src/gpu/OpContext.cpp index d83edf0..91f2338 100644 --- a/src/gpu/OpContext.cpp +++ b/src/gpu/OpContext.cpp @@ -21,6 +21,8 @@ #include "gpu/ops/FillRectOp.h" namespace tgfx { +static constexpr uint32_t InvalidContentVersion = 0; + void OpContext::fillWithFP(std::unique_ptr fp, const Matrix& uvMatrix, bool autoResolve) { fillRectWithFP(Rect::MakeWH(renderTargetProxy->width(), renderTargetProxy->height()), @@ -46,8 +48,10 @@ void OpContext::addOp(std::unique_ptr op) { if (opsTask == nullptr || opsTask->isClosed()) { auto drawingManager = renderTargetProxy->getContext()->drawingManager(); opsTask = drawingManager->addOpsTask(renderTargetProxy); - _contentVersion++; } opsTask->addOp(std::move(op)); + do { + _contentVersion++; + } while (InvalidContentVersion == _contentVersion); } } // namespace tgfx diff --git a/test/src/LayerTest.cpp b/test/src/LayerTest.cpp index 826a050..ff7a9b7 100644 --- a/test/src/LayerTest.cpp +++ b/test/src/LayerTest.cpp @@ -683,18 +683,18 @@ TGFX_TEST(LayerTest, ContentVersion) { displayList.root()->addChild(shapeLayer); auto contentVersion = surface->contentVersion(); displayList.render(surface.get()); - ASSERT_NE(surface->contentVersion(), contentVersion); + EXPECT_NE(surface->contentVersion(), contentVersion); contentVersion = surface->contentVersion(); displayList.render(surface.get()); - ASSERT_EQ(surface->contentVersion(), contentVersion); + EXPECT_EQ(surface->contentVersion(), contentVersion); displayList.render(surface.get(), false); - ASSERT_NE(surface->contentVersion(), contentVersion); + EXPECT_NE(surface->contentVersion(), contentVersion); contentVersion = surface->contentVersion(); surface->getCanvas()->clear(); - ASSERT_NE(surface->contentVersion(), contentVersion); + EXPECT_NE(surface->contentVersion(), contentVersion); contentVersion = surface->contentVersion(); displayList.render(surface.get()); - ASSERT_NE(surface->contentVersion(), contentVersion); + EXPECT_NE(surface->contentVersion(), contentVersion); device->unlock(); }