Skip to content

Commit

Permalink
Remove Surface::flush() and use Context::flush() instead. (#2525)
Browse files Browse the repository at this point in the history
  • Loading branch information
domchen authored Oct 11, 2024
1 parent 9995b21 commit c77c593
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
{
"url": "${PAG_GROUP}/tgfx.git",
"commit": "6bf0581bd6c2b9794a52abffa35e782ee82bfcd0",
"commit": "9d6b7464dd22e3a0aa9aa22e0a789cbfed1fed73",
"dir": "third_party/tgfx"
},
{
Expand Down
3 changes: 1 addition & 2 deletions src/platform/ohos/JPAGImageView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,7 @@ bool JPAGImageView::present(std::shared_ptr<tgfx::Image> image) {
tgfx::Matrix imageMatrix = tgfx::Matrix::MakeScale(1.0 / _renderScale);
imageMatrix.postConcat(_matrix);
canvas->drawImage(image, imageMatrix);
surface->flush();
context->submit();
context->flushAndSubmit();
targetWindow->present(context);
context->purgeResourcesNotUsedSince(std::chrono::steady_clock::now());
device->unlock();
Expand Down
6 changes: 3 additions & 3 deletions src/rendering/PAGSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ bool PAGSurface::clearAll() {
contentVersion = 0; // 清空画布后 contentVersion 还原为初始值 0.
auto canvas = surface->getCanvas();
canvas->clear();
surface->flush();
context->flush();
drawable->setTimeStamp(0);
drawable->present(context);
unlockContext();
Expand Down Expand Up @@ -218,10 +218,10 @@ bool PAGSurface::draw(RenderCache* cache, std::shared_ptr<Graphic> graphic,
}
onDraw(graphic, surface, cache);
if (signalSemaphore == nullptr) {
surface->flush();
context->flush();
} else {
tgfx::BackendSemaphore semaphore = {};
surface->flush(&semaphore);
context->flush(&semaphore);
signalSemaphore->initGL(semaphore.glSync());
}
cache->detachFromContext();
Expand Down
2 changes: 1 addition & 1 deletion src/rendering/filters/DisplacementMapFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void DisplacementMapFilter::updateMapTexture(RenderCache* cache, const Graphic*
if (displacementMapBehavior == DisplacementMapBehavior::TileMap) {
canvas.restore();
}
mapSurface->flush();
cache->getContext()->flush();
}

struct SelectorCoeffs {
Expand Down
2 changes: 1 addition & 1 deletion src/rendering/filters/GradientOverlayFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ void GradientOverlayFilter::draw(tgfx::Context* context, const FilterSource* sou
auto rect = tgfx::Rect::MakeWH(width, height);
targetCanvas->drawRect(rect, paint);
targetCanvas->restore();
targetSurface->flush();
context->flush();
}
} // namespace pag
2 changes: 1 addition & 1 deletion src/rendering/filters/gaussianblur/GaussianBlurFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ void GaussianBlurFilter::draw(tgfx::Context* context, const FilterSource* source
targetCanvas->setMatrix(ToMatrix(target));
targetCanvas->drawImage(std::move(image), offset.x, offset.y);
targetCanvas->restore();
targetSurface->flush();
context->flush();
}
} // namespace pag
4 changes: 2 additions & 2 deletions src/rendering/filters/layerstyle/DropShadowFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void DropShadowFilter::onDrawModeNotSpread(tgfx::Context* context, const FilterS
blurYSize * source->scale.y, color));
paint.setAlpha(opacity);
targetCanvas->drawImage(std::move(image), &paint);
targetSurface->flush();
context->flush();
}

void DropShadowFilter::onDrawModeNotFullSpread(tgfx::Context* context, const FilterSource* source,
Expand Down Expand Up @@ -175,7 +175,7 @@ void DropShadowFilter::onDrawModeNotFullSpread(tgfx::Context* context, const Fil
blurYSize * source->scale.y, color));
paint.setAlpha(opacity);
targetCanvas->drawImage(std::move(image), &paint);
targetSurface->flush();
context->flush();
}

void DropShadowFilter::onDrawModeFullSpread(tgfx::Context* context, const FilterSource* source,
Expand Down
4 changes: 2 additions & 2 deletions src/rendering/filters/layerstyle/OuterGlowFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void OuterGlowFilter::onDrawModeNotSpread(tgfx::Context* context, const FilterSo
blurYSize * source->scale.y, color));
paint.setAlpha(opacity);
targetCanvas->drawImage(std::move(image), &paint);
targetSurface->flush();
context->flush();
}

void OuterGlowFilter::onDrawModeNotFullSpread(tgfx::Context* context, const FilterSource* source,
Expand Down Expand Up @@ -169,7 +169,7 @@ void OuterGlowFilter::onDrawModeNotFullSpread(tgfx::Context* context, const Filt
blurYSize * source->scale.y, color));
paint.setAlpha(opacity);
targetCanvas->drawImage(std::move(image), &paint);
targetSurface->flush();
context->flush();
}

void OuterGlowFilter::onDrawModeFullSpread(tgfx::Context* context, const FilterSource* source,
Expand Down
5 changes: 2 additions & 3 deletions src/rendering/renderers/FilterRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,9 @@ void FilterRenderer::DrawWithFilter(Canvas* parentCanvas, const FilterModifier*
filterSource->scale);
}

// 必须要flush,要不然framebuffer还没真正画到canvas,就被其他图层的filter串改了该framebuffer
auto parentSurface = parentCanvas->getSurface();
parentSurface->flush();
auto context = parentCanvas->getContext();
// 必须要flush,要不然framebuffer还没真正画到canvas,就被其他图层的filter串改了该framebuffer
context->flush();
ApplyFilters(context, filterNodes, contentBounds, filterSource.get(), filterTarget.get());
// Reset the GL states stored in the context, they may be modified during the filter being applied.
context->resetState();
Expand Down

0 comments on commit c77c593

Please sign in to comment.