LibreOffice Module canvas (master)
1
canvas
source
opengl
ogl_texturecache.cxx
Go to the documentation of this file.
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
* This file is part of the LibreOffice project.
4
*
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
*/
9
10
#include <
sal/config.h
>
11
12
#include <epoxy/gl.h>
13
14
#include <com/sun/star/geometry/IntegerSize2D.hpp>
15
16
#include "
ogl_texturecache.hxx
"
17
18
19
using namespace
::
com::sun::star
;
20
21
namespace
oglcanvas
22
{
23
TextureCache::TextureCache
() :
24
maCache
(101),
25
mnMissCount(0),
26
mnHitCount(0)
27
{}
28
29
TextureCache::~TextureCache
()
30
{
31
flush
();
32
}
33
34
void
TextureCache::flush
()
35
{
36
// un-bind any texture
37
glBindTexture(GL_TEXTURE_2D, 0);
38
39
// delete all cached textures
40
for
(
const
auto
& rCache :
maCache
)
41
{
42
glDeleteTextures( 1, &rCache.second.nTexture );
43
}
44
45
maCache
.clear();
46
mnMissCount
= 0;
47
mnHitCount
= 0;
48
}
49
50
void
TextureCache::prune
()
51
{
52
// un-bind any texture
53
glBindTexture(GL_TEXTURE_2D, 0);
54
55
// delete already "old" textures, mark "new" entries "old"
56
const
TextureCacheMapT::const_iterator aEnd =
maCache
.end();
57
for
(
auto
aCurr =
maCache
.begin(); aCurr != aEnd;
/* increment managed in loop */
)
58
{
59
if
( aCurr->second.bOld )
60
{
61
glDeleteTextures( 1, &aCurr->second.nTexture );
62
aCurr =
maCache
.erase( aCurr );
63
}
64
else
65
{
66
aCurr->second.bOld =
true
;
67
++aCurr;
68
}
69
}
70
71
mnMissCount
= 0;
72
mnHitCount
= 0;
73
}
74
75
unsigned
int
TextureCache::getTexture
(
const
geometry::IntegerSize2D& rPixelSize,
76
const
sal_Int8
* pPixel,
77
sal_uInt32 nPixelCrc32)
const
78
{
79
unsigned
int
nTexture(0);
80
81
// texture already cached?
82
TextureCacheMapT::iterator aCacheEntry;
83
if
( (aCacheEntry=
maCache
.find(nPixelCrc32)) ==
maCache
.end() )
84
{
85
// nope, insert new entry
86
glGenTextures(1, &nTexture);
87
glBindTexture(GL_TEXTURE_2D, nTexture);
88
89
// TODO(E3): handle limited texture sizes -
90
// glGetIntegerv(GL_MAX_TEXTURE_SIZE)
91
glTexImage2D(GL_TEXTURE_2D,
92
0,
93
4,
94
rPixelSize.Width,
95
rPixelSize.Height,
96
0,
97
GL_RGBA,
98
GL_UNSIGNED_INT_8_8_8_8_REV,
99
pPixel);
100
101
maCache
[nPixelCrc32].nTexture = nTexture;
102
++
mnMissCount
;
103
104
return
nTexture;
105
}
106
else
107
{
108
nTexture = aCacheEntry->second.nTexture;
109
aCacheEntry->second.bOld =
false
;
110
++
mnHitCount
;
111
}
112
113
return
nTexture;
114
}
115
}
116
117
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
oglcanvas::TextureCache::maCache
TextureCacheMapT maCache
Definition:
ogl_texturecache.hxx:54
oglcanvas::TextureCache::prune
void prune()
prune old entries from cache
Definition:
ogl_texturecache.cxx:50
oglcanvas::TextureCache::~TextureCache
~TextureCache()
Definition:
ogl_texturecache.cxx:29
oglcanvas::TextureCache::getTexture
unsigned int getTexture(const css::geometry::IntegerSize2D &rPixelSize, const sal_Int8 *pPixel, sal_uInt32 nPixelCrc32) const
Definition:
ogl_texturecache.cxx:75
oglcanvas::TextureCache::flush
void flush()
clear whole cache, reset statistic counters
Definition:
ogl_texturecache.cxx:34
oglcanvas::TextureCache::mnHitCount
sal_uInt32 mnHitCount
Definition:
ogl_texturecache.hxx:56
oglcanvas::TextureCache::mnMissCount
sal_uInt32 mnMissCount
Definition:
ogl_texturecache.hxx:55
oglcanvas::TextureCache::TextureCache
TextureCache()
Definition:
ogl_texturecache.cxx:23
config.h
maCache
ColCacheType maCache
com::sun::star
oglcanvas
Definition:
ogl_bitmapcanvashelper.cxx:20
ogl_texturecache.hxx
sal_Int8
signed char sal_Int8
Generated on Sun Jul 30 2023 04:34:08 for LibreOffice Module canvas (master) by
1.9.3