Skip to content

Commit

Permalink
libgui|Font: Thread-safety when accessing fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jan 21, 2017
1 parent 1190e25 commit dceff8e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions doomsday/sdk/libgui/src/text/font.cpp
Expand Up @@ -13,7 +13,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#include "de/Font"
Expand All @@ -34,7 +34,7 @@ namespace de { typedef QtNativeFont PlatformFont; }

namespace de {

namespace internal
namespace internal
{
struct FontParams
{
Expand Down Expand Up @@ -62,14 +62,14 @@ namespace internal

static uint qHash(FontParams const &params)
{
return ::qHash(params.family)
return ::qHash(params.family)
^ ::qHash(int(100 * params.size))
^ ::qHash(params.spec.weight)
^ ::qHash(int(params.spec.style));
}
}

DENG2_PIMPL(Font)
DENG2_PIMPL(Font), public Lockable
{
PlatformFont font;
QHash<internal::FontParams, PlatformFont *> fontMods;
Expand Down Expand Up @@ -138,12 +138,14 @@ DENG2_PIMPL(Font)

PlatformFont &getFontMod(internal::FontParams const &params)
{
DENG2_GUARD(this);

auto found = fontMods.constFind(params);
if (found != fontMods.constEnd())
{
return *found.value();
}

auto *mod = new PlatformFont;
mod->setFamily(params.family);
mod->setSize(params.size);
Expand Down

0 comments on commit dceff8e

Please sign in to comment.