on xenial help sign in
Optimize Card by not creating an invisible ShaderEffect when unneeded
6b42ddaAlbert Astals
qml/Dash/Card.qml+35−31
@@ -123,44 +123,48 @@ AbstractButton {
123 }
123 }
124 }
124 }
125
125
126− ShaderEffect {
126+ Loader {
127− id: overlay
127+ id: overlayLoader
128 anchors {
128 anchors {
129 left: artShape.left
129 left: artShape.left
130 right: artShape.right
130 right: artShape.right
131 bottom: artShape.bottom
131 bottom: artShape.bottom
132 }
132 }
133+ active: template && template["overlay"] && artShape.visible && artShape.image.status === Image.Ready || false
133
134
134− height: header.height
135+ sourceComponent: ShaderEffect {
135− opacity: header.opacity * 0.6
136+ id: overlay
136− visible: template && template["overlay"] && artShape.visible && artShape.image.status === Image.Ready || false
137
137
138− property var source: ShaderEffectSource {
138+ height: header.height
139− id: shaderSource
139+ opacity: header.opacity * 0.6
140− sourceItem: artShape
141− onVisibleChanged: if (visible) scheduleUpdate()
142− live: false
143− sourceRect: Qt.rect(0, artShape.height - overlay.height, artShape.width, overlay.height)
144− }
145
140
141+ property var source: ShaderEffectSource {
142+ id: shaderSource
143+ sourceItem: artShape
144+ onVisibleChanged: if (visible) scheduleUpdate()
145+ live: false
146+ sourceRect: Qt.rect(0, artShape.height - overlay.height, artShape.width, overlay.height)
147+ }
148+
146− vertexShader: "
149+ vertexShader: "
147− uniform highp mat4 qt_Matrix;
150+ uniform highp mat4 qt_Matrix;
148− attribute highp vec4 qt_Vertex;
151+ attribute highp vec4 qt_Vertex;
149− attribute highp vec2 qt_MultiTexCoord0;
152+ attribute highp vec2 qt_MultiTexCoord0;
150− varying highp vec2 coord;
153+ varying highp vec2 coord;
151− void main() {
154+ void main() {
152− coord = qt_MultiTexCoord0;
155+ coord = qt_MultiTexCoord0;
153− gl_Position = qt_Matrix * qt_Vertex;
156+ gl_Position = qt_Matrix * qt_Vertex;
154− }"
157+ }"
155−
158+
156− fragmentShader: "
159+ fragmentShader: "
157− varying highp vec2 coord;
160+ varying highp vec2 coord;
158− uniform sampler2D source;
161+ uniform sampler2D source;
159− uniform lowp float qt_Opacity;
162+ uniform lowp float qt_Opacity;
160− void main() {
163+ void main() {
161− lowp vec4 tex = texture2D(source, coord);
164+ lowp vec4 tex = texture2D(source, coord);
162− gl_FragColor = vec4(0, 0, 0, tex.a) * qt_Opacity;
165+ gl_FragColor = vec4(0, 0, 0, tex.a) * qt_Opacity;
163− }"
166+ }"
167+ }
164 }
168 }
165
169
166 CardHeader {
170 CardHeader {
@@ -169,7 +173,7 @@ AbstractButton {
169 anchors {
173 anchors {
170 top: {
174 top: {
171 if (template) {
175 if (template) {
172− if (template["overlay"]) return overlay.top;
176+ if (template["overlay"]) return overlayLoader.top;
173 if (template["card-layout"] === "horizontal") return artShape.top;
177 if (template["card-layout"] === "horizontal") return artShape.top;
174 }
178 }
175 return artShape.bottom;
179 return artShape.bottom;