Diffusion Krita 2617900662ff

Fix thread-safety for rendering of the shapes

Authored by dkazakov on Jan 24 2020, 2:01 PM.

Description

Fix thread-safety for rendering of the shapes

Vector shapes are not thread-safe against concurrent read-writes, so we
need to utilize rather complicated policy on accessing them:

  1. All shape writes happen in GUI thread (right in the tools)
  2. No concurrent reads from the shapes may happen in other threads while the user is modifying them.

That is why our shape rendering code is split into two parts:

  1. First we just fetch a shallow copy of the shapes of the layer (it takes about 1ms for complicated vecotor layers) and pack them into KoShapeManager::PaintJobsList jobs. It happens here, in slotStartAsyncRepaint(), which runs in the GUI thread. It guarantees that noone is accessing the shapes during the copy operation.
  1. The rendering itself happens in the worker thread in repaint(). But repaint() doesn't access original shapes anymore. It accesses only they shallow copies, which means that there is no concurrent access to anything (*).

(*) "no concurrent access to anything" is a rather fragile term :) There

will still be concurrent access to it, on detaching... But(!), when detaching,
the original data is kept unchanged, so "it should be safe enough"(c). Especially
if we guarantee that rendering thread may not cause a detach (?), and the detach
can happen only from a single GUI thread.

CCBUG:411738

Details

Committed
dkazakovJan 24 2020, 2:01 PM
Parents
R37:743355c0a3d9: Remove unused KoPathShape private member
Branches
Unknown
Tags
Unknown
References
refs/keep-around/2617900662ff7046d79249077053edc7d6942621