<table><tr><td style="">fredrik added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D4366" rel="noreferrer">View Revision</a></tr></table><br /><div><div><p>I know this revision has been abandoned, but I wanted to comment on a few things for future reference.</p></div></div><br /><div><strong>INLINE COMMENTS</strong><div><div style="margin: 6px 0 12px 0;"><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D4366#inline-17913" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">screencast.cpp:105</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">    <span class="n">QRect</span> <span class="n">geometry</span> <span style="color: #aa2211">=</span> <span class="n">effects</span><span style="color: #aa2211">-></span><span class="n">virtualScreenGeometry</span><span class="p">();</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">I strongly suggest that you use the damage information from kwin and only download the parts of the framebuffer that have actually changed. This can make a massive difference in performance.</p>

<p style="padding: 0; margin: 8px;">You can keep a screen sized QImage around and keep it in sync by updating areas as they change.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D4366#inline-17908" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">screencast.cpp:107</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">    <span class="n">GLTexture</span> <span style="color: #004012">tex</span><span class="p">(</span><span class="n">GL_RGBA8</span><span class="p">,</span> <span class="n">geometry</span><span class="p">.</span><span class="n">width</span><span class="p">(),</span> <span class="n">geometry</span><span class="p">.</span><span class="n">height</span><span class="p">());</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">    <span class="n">GLRenderTarget</span> <span style="color: #004012">target</span><span class="p">(</span><span class="n">tex</span><span class="p">);</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Why do you use an intermediate texture instead of reading directly from the framebuffer in the desktop GL case?</p>

<p style="padding: 0; margin: 8px;">You create the texture and blit the framebuffer into it in the GLES case, even though you don't use it.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D4366#inline-17909" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">screencast.cpp:109</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">    <span class="n">GLRenderTarget</span> <span style="color: #004012">target</span><span class="p">(</span><span class="n">tex</span><span class="p">);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">    <span class="n">target</span><span class="p">.</span><span class="n">blitFromFramebuffer</span><span class="p">(</span><span class="n">geometry</span><span class="p">);</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">There is no need to use a RenderTarget here. Use glCopyTexSubImage2D() instead, which copies from the framebuffer to the currently bound texture.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D4366#inline-17907" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">screencast.cpp:114</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">    <span style="color: #aa4000">auto</span> <span class="n">img</span> <span style="color: #aa2211">=</span> <span class="n">QImage</span><span class="p">(</span><span class="n">geometry</span><span class="p">.</span><span class="n">size</span><span class="p">(),</span> <span class="n">QImage</span><span style="color: #aa2211">::</span><span class="n">Format_RGB888</span><span class="p">);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">    <span style="color: #aa4000">if</span> <span class="p">(</span><span class="n">GLPlatform</span><span style="color: #aa2211">::</span><span class="n">instance</span><span class="p">()</span><span style="color: #aa2211">-></span><span class="n">isGLES</span><span class="p">())</span> <span class="p">{</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Don't read back data directly to client memory. Instead create a GL_PIXEL_PACK_BUFFER and download the image into it. That way glReadPixels()/glGetTexImage() schedules the copy, but doesn't block and wait for it to finish. Wait at least one frame before you access the contents of the buffer.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D4366#inline-17905" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">screencast.cpp:116</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">    <span style="color: #aa4000">if</span> <span class="p">(</span><span class="n">GLPlatform</span><span style="color: #aa2211">::</span><span class="n">instance</span><span class="p">()</span><span style="color: #aa2211">-></span><span class="n">isGLES</span><span class="p">())</span> <span class="p">{</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">        <span class="n">glReadPixels</span><span class="p">(</span><span style="color: #601200">0</span><span class="p">,</span> <span style="color: #601200">0</span><span class="p">,</span> <span class="n">img</span><span class="p">.</span><span class="n">width</span><span class="p">(),</span> <span class="n">img</span><span class="p">.</span><span class="n">height</span><span class="p">(),</span> <span class="n">GL_RGB</span><span class="p">,</span> <span class="n">GL_UNSIGNED_BYTE</span><span class="p">,</span> <span class="p">(</span><span class="n">GLvoid</span><span style="color: #aa2211">*</span><span class="p">)</span><span class="n">img</span><span class="p">.</span><span class="n">bits</span><span class="p">());</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">    <span class="p">}</span> <span style="color: #aa4000">else</span> <span class="p">{</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Never read back data as GL_RGB. Three component formats are not supported in hardware, so this involves at least a partial software fallback.</p>

<p style="padding: 0; margin: 8px;">The only format/type combination a GLES implementation is required to support is also GL_RGBA/GL_UNSIGNED_BYTE.</p>

<p style="padding: 0; margin: 8px;">I also note that you immediately convert the image to a four-component format below.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D4366#inline-17910" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">screencast.cpp:118</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">    <span class="p">}</span> <span style="color: #aa4000">else</span> <span class="p">{</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">        <span class="n">glGetTexImage</span><span class="p">(</span><span class="n">GL_TEXTURE_2D</span><span class="p">,</span> <span style="color: #601200">0</span><span class="p">,</span> <span class="n">GL_RGB</span><span class="p">,</span> <span class="n">GL_UNSIGNED_BYTE</span><span class="p">,</span> <span class="p">(</span><span class="n">GLvoid</span><span style="color: #aa2211">*</span><span class="p">)</span><span class="n">img</span><span class="p">.</span><span class="n">bits</span><span class="p">());</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">    <span class="p">}</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">If you need the image to be in QImage::Format_ARGB32, you should read back the data as GL_BGRA/GL_UNSIGNED_INT_8_8_8_8_REV. This is the GL equivalent of QImage::Format_ARGB32.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D4366#inline-17906" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">screencast.cpp:121</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">    <span class="n">img</span> <span style="color: #aa2211">=</span> <span class="n">img</span><span class="p">.</span><span class="n">convertToFormat</span><span class="p">(</span><span class="n">QImage</span><span style="color: #aa2211">::</span><span class="n">Format_ARGB32</span><span class="p">);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">    <span class="n">img</span> <span style="color: #aa2211">=</span> <span class="n">img</span><span class="p">.</span><span class="n">mirrored</span><span class="p">();</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">    <span class="n">tex</span><span class="p">.</span><span class="n">unbind</span><span class="p">();</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Use GL_MESA_pack_invert and GL_ANGLE_pack_reverse_row_order so the image is downloaded in the correct orientation.</p></div></div></div></div></div><br /><div><strong>REPOSITORY</strong><div><div>R108 KWin</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D4366" rel="noreferrer">https://phabricator.kde.org/D4366</a></div></div><br /><div><strong>EMAIL PREFERENCES</strong><div><a href="https://phabricator.kde.org/settings/panel/emailpreferences/" rel="noreferrer">https://phabricator.kde.org/settings/panel/emailpreferences/</a></div></div><br /><div><strong>To: </strong>davidedmundson, Plasma<br /><strong>Cc: </strong>fredrik, graesslin, subdiff, plasma-devel, kwin, KWin, lesliezhai, ali-mohamed, hardening, jensreuterberg, abetts, sebas, apol<br /></div>