cid#1607171 Data race condition
[LibreOffice.git] / canvas / source / opengl / ogl_texturecache.hxx
blob8d0a425ced17745926ef9b62f9b48742676fa7c9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #pragma once
12 #include <sal/types.h>
13 #include <unordered_map>
15 namespace com::sun::star::geometry { struct IntegerSize2D; }
18 namespace oglcanvas
20 class TextureCache
22 public:
23 TextureCache();
24 ~TextureCache();
26 /// clear whole cache, reset statistic counters
27 void flush();
29 /** prune old entries from cache
31 Every time this method is called, all cache entries are set
32 to "old". If subsequently not used by getTexture(),
33 they'll be entitled for expunge on the next prune()
34 call. Resets statistic counters.
36 void prune();
38 /// Statistics
39 size_t getCacheSize() const { return maCache.size(); };
40 sal_uInt32 getCacheMissCount() const { return mnMissCount; }
41 sal_uInt32 getCacheHitCount() const { return mnHitCount; }
43 unsigned int getTexture( const css::geometry::IntegerSize2D& rPixelSize,
44 const sal_Int8* pPixel,
45 sal_uInt32 nPixelCrc32) const;
46 private:
47 struct CacheEntry
49 CacheEntry() : nTexture(0), bOld(false) {}
50 unsigned int nTexture;
51 bool bOld;
53 typedef std::unordered_map<sal_uInt32,CacheEntry> TextureCacheMapT;
54 mutable TextureCacheMapT maCache;
55 mutable sal_uInt32 mnMissCount;
56 mutable sal_uInt32 mnHitCount;
60 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */