Merge lp:~bregma/compiz/lp-1227449 into lp:compiz/0.9.12

Proposed by Stephen M. Webb
Status: Merged
Approved by: Brandon Schaefer
Approved revision: 3890
Merged at revision: 3898
Proposed branch: lp:~bregma/compiz/lp-1227449
Merge into: lp:compiz/0.9.12
Diff against target: 123 lines (+43/-10)
5 files modified
plugins/opengl/include/opengl/shadercache.h (+5/-0)
plugins/opengl/src/paint.cpp (+9/-0)
plugins/opengl/src/shadercache.cpp (+14/-5)
plugins/opengl/src/vertexbuffer.cpp (+12/-0)
plugins/opengl/src/window.cpp (+3/-5)
To merge this branch: bzr merge lp:~bregma/compiz/lp-1227449
Reviewer Review Type Date Requested Status
Brandon Schaefer (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+240112@code.launchpad.net

Commit message

opengl plugin: free shaders and uniforms

Description of the change

Frees shaders and uniforms (which were previously always just leaked). Since these are mostly cached there won't be much effect at runtime (unless a third-party plugin is doing something wacky, which is allowed) but will definitely reduce the noise from valgrind.

The only real way to test this change is to run valgrind on Compiz before and after applying the patch.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/opengl/include/opengl/shadercache.h'
2--- plugins/opengl/include/opengl/shadercache.h 2013-01-09 10:45:16 +0000
3+++ plugins/opengl/include/opengl/shadercache.h 2014-10-30 12:51:30 +0000
4@@ -69,9 +69,14 @@
5 */
6 struct GLShaderData
7 {
8+ GLShaderData(const std::string &name,
9+ const std::string &vertexShader,
10+ const std::string &fragmentShader);
11+
12 std::string name;
13 std::string vertexShader;
14 std::string fragmentShader;
15+ bool isCached;
16 };
17
18 class PrivateShaderCache;
19
20=== modified file 'plugins/opengl/src/paint.cpp'
21--- plugins/opengl/src/paint.cpp 2013-07-22 17:19:59 +0000
22+++ plugins/opengl/src/paint.cpp 2014-10-30 12:51:30 +0000
23@@ -1298,6 +1298,15 @@
24 priv->vertexBuffer->render (transform, attrib);
25 #endif
26
27+ for (std::list<const GLShaderData*>::const_iterator it = priv->shaders.begin();
28+ it != priv->shaders.end();
29+ ++it)
30+ {
31+ if ((*it)->isCached != true)
32+ {
33+ delete *it;
34+ }
35+ }
36 priv->shaders.clear ();
37 texture->disable ();
38
39
40=== modified file 'plugins/opengl/src/shadercache.cpp'
41--- plugins/opengl/src/shadercache.cpp 2013-12-04 01:31:52 +0000
42+++ plugins/opengl/src/shadercache.cpp 2014-10-30 12:51:30 +0000
43@@ -40,6 +40,16 @@
44
45 };
46
47+GLShaderData::GLShaderData(const std::string &name,
48+ const std::string &vertexShader,
49+ const std::string &fragmentShader) :
50+ name(name),
51+ vertexShader(vertexShader),
52+ fragmentShader(fragmentShader),
53+ isCached(false)
54+{
55+}
56+
57 typedef std::map<GLShaderParameters, GLShaderData, GLShaderParametersComparer> ShaderMapType;
58
59 /**
60@@ -125,11 +135,10 @@
61 ShaderMapType::const_iterator
62 PrivateShaderCache::addShaderData (const GLShaderParameters &params)
63 {
64- GLShaderData shaderData;
65-
66- shaderData.name = params.id ();
67- shaderData.fragmentShader = createFragmentShader (params);
68- shaderData.vertexShader = createVertexShader (params);
69+ GLShaderData shaderData (params.id (),
70+ createVertexShader (params),
71+ createFragmentShader (params));
72+ shaderData.isCached = true;
73
74 std::pair<ShaderMapType::iterator, bool> ret =
75 shaderMap.insert(std::pair<GLShaderParameters, GLShaderData>(params,shaderData));
76
77=== modified file 'plugins/opengl/src/vertexbuffer.cpp'
78--- plugins/opengl/src/vertexbuffer.cpp 2013-03-31 19:27:26 +0000
79+++ plugins/opengl/src/vertexbuffer.cpp 2014-10-30 12:51:30 +0000
80@@ -88,6 +88,12 @@
81 priv->maxVertices = -1;
82 priv->normalData.clear ();
83 priv->colorData.clear ();
84+ for (std::vector<AbstractUniform*>::iterator it = priv->uniforms.begin();
85+ it != priv->uniforms.end();
86+ ++it)
87+ {
88+ delete *it;
89+ }
90 priv->uniforms.clear ();
91
92 priv->nTextures = 0;
93@@ -412,6 +418,12 @@
94 GL::deleteBuffers (1, &colorBuffer);
95 if (textureBuffers[0])
96 GL::deleteBuffers (4, &textureBuffers[0]);
97+ for (std::vector<AbstractUniform*>::iterator it = uniforms.begin();
98+ it != uniforms.end();
99+ ++it)
100+ {
101+ delete *it;
102+ }
103 }
104
105 int PrivateVertexBuffer::render (const GLMatrix *projection,
106
107=== modified file 'plugins/opengl/src/window.cpp'
108--- plugins/opengl/src/window.cpp 2013-06-20 09:22:02 +0000
109+++ plugins/opengl/src/window.cpp 2014-10-30 12:51:30 +0000
110@@ -362,11 +362,9 @@
111 std::string vertex_shader,
112 std::string fragment_shader)
113 {
114- GLShaderData *data = new GLShaderData;
115- data->name = name;
116- data->vertexShader = vertex_shader;
117- data->fragmentShader = fragment_shader;
118-
119+ GLShaderData *data = new GLShaderData (name,
120+ vertex_shader,
121+ fragment_shader);
122 priv->shaders.push_back(data);
123 }
124

Subscribers

People subscribed via source and target branches