<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Filipe Abrantes on Medium]]></title>
        <description><![CDATA[Stories by Filipe Abrantes on Medium]]></description>
        <link>https://medium.com/@fabrantes?source=rss-2b80f21cc532------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*mc2nOlNx3Q3oSR-N.png</url>
            <title>Stories by Filipe Abrantes on Medium</title>
            <link>https://medium.com/@fabrantes?source=rss-2b80f21cc532------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 21:53:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fabrantes/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Rounded video corners on Android — (Part II)]]></title>
            <link>https://medium.com/@fabrantes/rounded-video-corners-on-android-part-ii-a8971b7773dd?source=rss-2b80f21cc532------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8971b7773dd</guid>
            <dc:creator><![CDATA[Filipe Abrantes]]></dc:creator>
            <pubDate>Tue, 28 Apr 2015 15:08:18 GMT</pubDate>
            <atom:updated>2015-05-04T21:02:42.340Z</atom:updated>
            <content:encoded><![CDATA[<h3>Rounded video corners on Android — (Part II)</h3><p><a href="https://medium.com/@fabrantes/68eca391f39b">We were able to map video textures on to some rounded cornered geometry on the screen</a> but there are still a few rough edges. On this post we’ll focus on getting those corners properly anti-aliased and optimizing the GL performance a bit.</p><h4>Anti-Alias</h4><p>Back in the day — when I was still developing the infamous <a href="http://lifehacker.com/5507281/cubed-is-a-much-better-music-app-for-android"><em>cubed music player</em></a>, in early 2010<em> —</em> I remember trying to <strong>use </strong><a href="https://www.opengl.org/sdk/docs/man2/xhtml/glHint.xml"><strong>glHint</strong></a><strong> and not having much luck with it</strong>. It turns out that not much has changed in that front and most Android devices still simply ignore those calls nowadays.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*e7BUMdvahDmxDekMFZBMSw.png" /></figure><p>Fortunately, <a href="http://en.wikipedia.org/wiki/Multisample_anti-aliasing"><strong><em>Multi Sampling Anti-Alias</em></strong></a><strong><em> (MSSA)</em> has now been widely adopted</strong> in the Android world and that’s currently your best chance of getting anti-aliased GL geometry borders (there is even a developer option to force it). The way it works is by sampling pixels at the geometry border several times and making the <strong>output value an average of the values in the vicinity</strong>. Awesome! There is a great example app that has <a href="https://code.google.com/p/gdc2011-android-opengl/source/browse/trunk/src/com/example/gdc11/MultisampleConfigChooser.java">code</a> of how to enable it so I just imported it with some minor modifications.</p><p><em>MSAA</em> is a high level configuration of the GL context, so the core piece in that example code is the block where the <em>EGLConfig</em> is generated. Before, we were simply calling:</p><pre>setEGLConfigChooser(8, 8, 8, 8, 16, 0);</pre><p>which meant that we wanted our GL context to use colors with 8 bits per channel and include alpha as well as providing 16 bits for the depth buffer and 0 for the stencil buffer. That was a convenience method that would internally provide an <a href="http://developer.android.com/reference/android/opengl/GLSurfaceView.EGLConfigChooser.html">EGLConfigChooser</a> implementation. Moving away from the basic configuration options means that we need to create our own though. <strong>The key aspects of the configuration are stored in an int array like this:</strong></p><pre>// Try to find a normal multisample configuration first.<br>int[] configSpec = {<br>        EGL10.<em>EGL_RED_SIZE</em>, 8,<br>        EGL10.<em>EGL_GREEN_SIZE</em>, 8,<br>        EGL10.<em>EGL_BLUE_SIZE</em>, 8,<br>        EGL10.<em>EGL_ALPHA_SIZE</em>, 8,<br>        EGL10.<em>EGL_DEPTH_SIZE</em>, 16,<br>        // Requires that setEGLContextClientVersion(2) is called on the view.<br>        EGL10.<em>EGL_RENDERABLE_TYPE</em>, 4 /* EGL_OPENGL_ES2_BIT */,<br>        EGL10.<em>EGL_SAMPLE_BUFFERS</em>, 1 /* true */,<br>        EGL10.<em>EGL_SAMPLES</em>, 4,<br>        EGL10.<em>EGL_NONE<br></em>};</pre><p>where the presence of the <em>EGL_SAMPLE_BUFFERS</em> field turns on <em>MSAA</em>. I think the value of <em>EGL_SAMPLE_BUFFERS </em>is actually ignored, but I recommend you leave it alone<em>. MSAA </em>has variants of 2x, 4x, 8x and 16x, however my Nexus 5 will crash if the value passed is not between 1 and 4. Any value within that range will yield the same results though (or at least I couldn’t notice the difference).</p><p>There is also some <strong>config weirdness specific of the nVidia Tegra chipsets</strong> which have their own sampling extensions. The config in that case looks like this:</p><pre>final int EGL_COVERAGE_BUFFERS_NV = 0x30E0;<br>final int EGL_COVERAGE_SAMPLES_NV = 0x30E1;<br><br>configSpec = new int[]{<br>        EGL10.<em>EGL_RED_SIZE</em>, 8,<br>        EGL10.<em>EGL_GREEN_SIZE</em>, 8,<br>        EGL10.<em>EGL_BLUE_SIZE</em>, 8,<br>        EGL10.<em>EGL_ALPHA_SIZE</em>, 8,<br>        EGL10.<em>EGL_DEPTH_SIZE</em>, 16,<br>        EGL10.<em>EGL_RENDERABLE_TYPE</em>, 4 /* EGL_OPENGL_ES2_BIT */,<br>        EGL_COVERAGE_BUFFERS_NV, 1 /* true */,<br>        EGL_COVERAGE_SAMPLES_NV, 2,  // always 5 in practice on tegra 2<br>        EGL10.<em>EGL_NONE<br></em>};</pre><p>All good, the sample code had us covered ☺.</p><p>So yeah, that’s it, some GL boilerplate and good looking anti-aliased rounded corners here we go. Below you can <strong>check the actual difference </strong>on a Nexus 5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nircK5GNc99JRqqNwqmKoA.png" /><figcaption>Left has MSAA enabled. Used 6 triangles for this corner.</figcaption></figure><h4>Geometry optimization</h4><p>At this point we were using triangle strips to draw the geometry:</p><pre>GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mTriangleVerticesData.length / 5);</pre><p>which basically means that we go through all of the defined vertices and draw the triangles sequentially (i.e. using vertices 0, 1, 2, then 1, 2, 3, then 2, 3, 4, etc). If you aren’t careful with the order in which you create those vertices, this generates a lot of <a href="http://en.wikipedia.org/wiki/Triangle_strip"><em>degenerate triangles/strips</em></a><em>.</em> And we weren’t being careful, for instance if we would use 10 triangles per corner we would end up <strong>drawing close to 140 triangles when only 50 were necessary</strong>. <strong>Worse, some of those <em>degenerate</em> triangles would cover a decent area of the geometry</strong> and that’s a bit heavy on the fragment shaders.</p><p>To optimize this, there are two options, either creating those vertices in the right order, or draw the triangles indexed instead of using the <em>GL_TRIANGLE_STRIP</em> method. Creating the vertices in the right order, while maintaining some degree of readability in the code is a bit of a pain so I decided to go with the indexed approach. That implies changing the draw call to:</p><pre>GLES20.<em>glDrawElements</em>(GLES20.<em>GL_TRIANGLES</em>, mTriangleIndicesData.length,<br>        GL10.<em>GL_UNSIGNED_SHORT</em>, mTriangleIndices);</pre><p>where <em>mTriangleIndices</em> is an array which contains the indexes of the vertices for each triangle. It involves transferring some more data to the GPU, but we’re still talking about relatively small buffers. The rough drawing below illustrates the difference of what we were doing before with <em>glDrawArrays</em> and what is happening now with <em>glDrawElements</em>. Admittedly, the previous approach with <em>glDrawArrays</em> was very wasteful (it is possible to do better with arrays), but <em>glDrawElements</em> is still better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OFIWI3u91vhj0ALDPjOmkA.jpeg" /><figcaption>Admittedly, the previous approach with glDrawArrays was very wasteful (it is possible to do better with arrays), but glDrawElements is still better.</figcaption></figure><p>The source code is available <a href="https://github.com/fabrantes/videoroundedcorners">here</a>.</p><h4>Next</h4><p>It’s all working a little better now with these two fixes and we’re ready to progress further. In the next post, chances are we’ll focus on dealing with the video <em>vs</em> view aspect ratio, tidying this up in a nice library or achieving the same rounded corner effect with custom fragment shaders. I haven’t decided yet, until then ✌.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8971b7773dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rounded video corners on Android  —  Part I]]></title>
            <link>https://medium.com/@fabrantes/rounded-video-corners-on-android-part-i-68eca391f39b?source=rss-2b80f21cc532------2</link>
            <guid isPermaLink="false">https://medium.com/p/68eca391f39b</guid>
            <dc:creator><![CDATA[Filipe Abrantes]]></dc:creator>
            <pubDate>Sun, 12 Apr 2015 23:28:17 GMT</pubDate>
            <atom:updated>2015-06-25T18:28:00.290Z</atom:updated>
            <content:encoded><![CDATA[<h3>Rounded video corners on Android — (Part I)</h3><p><a href="https://medium.com/@fabrantes/rounded-video-corners-on-android-3467841cc1b">We have seen</a> that we want to be in control of where the video frames are stored and how they’re mapped on the screen in order to round the video corners. We’re going to 1) add a <em>GLSurfaceView</em> to our layout, 2) create a texture on the GPU, 3) create a <em>Surface</em> with a <em>SurfaceTexture</em> from that texture, 4) attach that <em>Surface</em> to the <em>MediaPlayer</em> so it draws the frames to the texture and finally 5) draw that texture mapped to a rounded rectangle geometry whenever a new frame is available.</p><h4>Adding a GLSurfaceView to our layout</h4><p>The Android open source repo actually contains a class called <a href="https://code.google.com/p/android-source-browsing/source/browse/tests/tests/media/src/android/media/cts/VideoSurfaceView.java?repo=platform--cts"><em>VideoSurfaceView</em></a> which covers the steps 1 to 4 mentioned above. We will take it as a starting point as it handles most of the GL boilerplate + weirdness which is great. It loads flat vertex and fragment shaders (i.e. ones that draw the original texture color at the coordinates specified by the uv mapping), creates the geometry for a basic rectangle and generates the GL texture. It then uses that texture to create a <em>SurfaceTexture</em> and corresponding <em>Surface</em> which it attaches to a given <em>MediaPlayer</em>.</p><h4>The GLSurfaceView</h4><p>The <em>GLSurfaceView</em> extends from <em>SurfaceView</em> so it draws whatever pixels are stored in a given (special) block of memory. The difference lies in that <strong>the <em>GLSurfaceView</em> allows a GL context to write to that block of memory</strong> (meaning that you use the GPU to calculate the pixel values that will be stored in there).</p><p>There are a few things worth noting when using a <em>GLSurfaceView</em>, the most important one being that <strong>the actual rendering occurs on a separate thread</strong>. Keep that in mind and use <a href="http://developer.android.com/reference/android/opengl/GLSurfaceView.html#queueEvent(java.lang.Runnable)"><em>queueEvent(Runnable)</em></a> if you need something to be run on the rendering thread. The core of a <em>GLSurfaceView</em> is a <a href="http://developer.android.com/reference/android/opengl/GLSurfaceView.html#setRenderer(android.opengl.GLSurfaceView.Renderer)"><em>Renderer</em></a><em>,</em> it is responsible for implementing the actual rendering logic. <a href="http://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer.html#onDrawFrame(javax.microedition.khronos.opengles.GL10)"><em>Renderer.onDrawFrame()</em></a> will be invoked every time a new frame needs to be rendered on the screen.</p><h4>Timing video decoding and rendering</h4><p>Now that we have our pipeline in place we want to synchronize video decoding and rendering to make sure we are not wasting resources. First thing is to <strong>set the render mode to be on demand</strong> instead of continuous.</p><pre>GLSurfaceView.setRenderMode(RENDERMODE_WHEN_DIRTY);</pre><p>This means that a frame will only be rendered when we explicitly call</p><pre>mGLSurfaceView.requestRender();</pre><p>Nice! Just need to hook it up with the video decoding side of things. Our SurfaceTexture exposes a listener for that:</p><pre>mSurfaceTexture.setOnFrameAvailableListener(this);<br>...<br>synchronized public void onFrameAvailable(SurfaceTexture surface) {<br>    mUpdateSurface = true;<br>    mGLSurfaceView.requestRender();<br>}</pre><p>And then finally when our <em>Renderer.onDrawFrame()</em> is invoked we need to tell the SurfaceTexture to update to the latest decoded video frame</p><pre>public void onDrawFrame(GL10 glUnused) {<br>    synchronized(this) {<br>        if (mUpdateSurface) {<br>            <strong>mSurfaceTexture.updateTexImage();</strong><br>            mSurfaceTexture.getTransformMatrix(mSTMatrix);<br>            mUpdateSurface = false;<br>        }<br>    }<br>    ...<br>    // do your GL drawing<br>}</pre><p>All set.</p><h4>Corner rounding prep</h4><p>We’re almost ready to start actually rounding these corners but there is just one small thing missing. There is <strong>no real point in rounding the corners if we can’t view what’s below</strong> so the <em>GLSurfaceView</em> needs to be <strong>translucent</strong>. This can be achieved by enabling alpha on the pixel format used by the <em>SurfaceHolder</em> and making the <em>GLSurfaceView</em> stay above the other views. This little block of code will do it.</p><pre>private void setTranslucent(boolean translucent) {<br>    if (translucent) {<br>        setZOrderOnTop(true);<br>        setEGLConfigChooser(8, 8, 8, 8, 16, 0);<br>        this.getHolder().setFormat(PixelFormat.RGBA_8888);<br>    } else {<br>        this.getHolder().setFormat(PixelFormat.RGB_565);<br>    }<br>}</pre><p>This has some performance implications though. Making the view translucent will make the screen compositor to re-compose the overlapping views whenever the surface is updated.</p><h4>Actually rounding those corners</h4><p>We came all this way just to round some corners so let’s get to it. Looking at the <a href="https://code.google.com/p/android-source-browsing/source/browse/tests/tests/media/src/android/media/cts/VideoSurfaceView.java?repo=platform--cts"><em>VideoSurfaceView</em> source</a> you’ll find code like this.</p><pre>private final float[] mTriangleVerticesData = {<br>    // X, Y, Z, U, V<br>    -1.0f, -1.0f, 0, 0.f, 0.f,<br>    1.0f, -1.0f, 0, 1.f, 0.f,<br>    -1.0f, 1.0f, 0, 0.f, 1.f,<br>    1.0f, 1.0f, 0, 1.f, 1.f,<br>};<br>...<br>// Copy our mTriangleVerticesData to some special mem buffer<br>...<br>// Tell the shaders they can find the vertex positions <br>// and uv mappings in our special memory buffer<br>...<br>// Render it<br>GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);</pre><p>So basically we’re defining our geometry in <em>mTriangleVerticesData</em> and then drawing it. That float array contains every vertex of the geometry in the form of X, Y, Z, U, V, where XYZ are the coordinates in 3D space and UV are the horizontal and vertical coordinates of the texture at that vertex — for example UV(0, 0) refers to the left-bottom corner of the texture. Drawing happens one triangle at the time and in this case, since we’re not specifying the vertex indices for our triangles, it will just go through them sequentially. <strong>It will first draw the triangle composed by vertices 0, 1 and 2 and then 1, 2, 3.</strong> Here’s a drawing so you get a better idea.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l6anve8s6zYzS1vXMfp4uw.jpeg" /></figure><p>To create a rounded cornered geometry we need to split this into a lot more vertices though. Unfortunately GPUs are not really good at round shapes. We’ll create an inner rectangle plus 4 more for each edge and then <strong>create each corner as a set of triangles</strong>. Something like this (and forgive for my unsteady hand).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Yx1qFr3rKhu-rYVNA424Q.jpeg" /></figure><p>Of course this only shows two triangles per corner which doesn’t look very round, in practice we’ll want to have a lot more so it gives us something that looks a bit more like a hand fan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qEfu3B5dddSDjJyP9hEHRA.jpeg" /></figure><p>And there you go, rounded corners for your video. The tricky part about creating this geometry is making sure to account for any transformations and that we map actual pixel dimensions right to the GL scalar space.</p><p>Watch the code in action below. Source code can be found <a href="https://github.com/fabrantes/videoroundedcorners">here</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FDgPw6rQU8h4%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DDgPw6rQU8h4&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FDgPw6rQU8h4%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3220f22d3693626c35e6267828d58039/href">https://medium.com/media/3220f22d3693626c35e6267828d58039/href</a></iframe><h4>Next steps</h4><p>The current implementation is still quite wasteful and has some rough edges (literally). For example, not specifying the <strong>triangle indexes</strong> is making us draw a lot more triangles than we need to and we haven’t talked about <strong>anti-aliasing</strong> at all yet. We’ll go through those in the next post.</p><p><a href="https://medium.com/@fabrantes/rounded-video-corners-on-android-part-ii-a8971b7773dd">Keep reading.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68eca391f39b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rounded video corners on Android]]></title>
            <link>https://medium.com/@fabrantes/rounded-video-corners-on-android-3467841cc1b?source=rss-2b80f21cc532------2</link>
            <guid isPermaLink="false">https://medium.com/p/3467841cc1b</guid>
            <dc:creator><![CDATA[Filipe Abrantes]]></dc:creator>
            <pubDate>Sun, 12 Apr 2015 23:26:07 GMT</pubDate>
            <atom:updated>2018-04-20T17:19:08.526Z</atom:updated>
            <content:encoded><![CDATA[<h3>Rounded video corners on Android — (Intro)</h3><p><strong>A very late update and before you read any of this post: as of Lollipop the most practical way of handling this is to use </strong><a href="https://developer.android.com/reference/android/view/View.html#setClipToOutline(boolean)"><strong>View#setClipToOutline()</strong></a><strong> (and set the desired outline). It doesn’t support individual corner rounding or KitKat and below, but the setup is really minimal. The docs say this is a relatively expensive operation, but CardView uses this and it is used widely by Google apps on scrollable lists so it’s probably good enough for most use cases.</strong></p><p>(…)</p><p><em>Quick note: I’m writing this mostly to structure what I have learnt while trying to implement video rounded corners on Android for the last couple of days. While I’m happy to share the findings, the article will contain imprecisions and errors throughout so take what’s written here with caution and don’t hesitate to contact me directly or leave a comment when you find something wrong.</em></p><p>The Android UI framework has quite a few things that I’m thankful for as a developer — I love being able to tint an <em>ImageView</em> (or any asset really) with <a href="http://developer.android.com/reference/android/widget/ImageView.html#setColorFilter(int,%20android.graphics.PorterDuff.Mode)"><em>setColorFilter</em></a> or tweening any object property with <a href="http://developer.android.com/reference/android/animation/ObjectAnimator.html"><em>ObjectAnimator</em></a>— however there are also some significant missing features. The ones I miss the most are probably the ability to set rounded corners or drop shadows at the View level. Every Android dev must have looked at how to round the corners of an <em>ImageView</em> at least once in their dev life and they know how tricky it can be to implement right. And it shouldn’t be that hard, at least not corner rounding. Views are ultimately translated to a texture that is mapped to some geometry on the GPU so the framework would just need to create the right geometry to enable rounded corners (at the expense of drawing a few more triangles).</p><h4>Approaches to video corner rounding</h4><p>I have though about how to implement rounded corners on video views on and off for the last few months now and came up with three ways to go about it: <strong>1) drawing some <em>corner overlays</em></strong> that give you the impression that the view is rounding its corners, <strong>2) apply some kind of <em>mask</em> to the content </strong>(e.g. through a GLSL shader that takes a <em>vignette-like</em> <em>image </em>as input or uses the <a href="https://open.gl/depthstencils"><em>stencil buffer</em></a>) or <strong>3) control the GPU <em>geometry</em> </strong>on which the video content is being mapped. While 1) sounds easy and fast, it is only convenient to implement if the background is static and you don’t plan to translate, scale, rotate or animate in any way the video container or any of the overlapping views. If that’s the case, 1) is perfectly reasonable, but still it’s not a generic approach. 2) looks promising, but dealing with the mask in a separate image might be tricky and I’m not sure how well the stencil buffer would be able to handle this (assumedly because I don’t know enough about it). So yeah, we’re left with 3) which to me sounds like it’s worth a try. We’ll simply change the geometry that ultimately is used to show pixels on the screen and all we need to do is create that geometry correctly. Clean and easy, right? Well, maybe… let’s give it a try.</p><h4>Displaying video on Android</h4><p>Assuming that you are going to use the <a href="http://developer.android.com/reference/android/media/MediaPlayer.html"><em>MediaPlayer</em></a><em> </em>to handle video decoding for you — there is also <a href="https://developer.android.com/guide/topics/media/exoplayer.html"><em>ExoPlayer</em></a>, <a href="https://developer.android.com/reference/android/media/MediaCodec.html"><em>MediaCodec</em></a> and <a href="https://developer.android.com/reference/android/media/MediaExtractor.html"><em>MediaExtractor</em></a> if you need lower level access, but I don’t think it makes sense to tie you to these just for the sake of rounding corners — <strong>you basically need to have a </strong><a href="http://developer.android.com/reference/android/view/Surface.html"><strong><em>Surface</em></strong></a> (or a <em>SurfaceHolder </em>which is someone who holds a <em>Surface</em>) where you can show the video frames as they are decoded by the MediaPlayer. The docs describe <strong>a <em>Surface</em> as</strong>:</p><pre>Handle onto a raw buffer that is being managed by the screen compositor.</pre><p>Which sounds a bit generic, but gives you an idea. Something that lets you access some block of memory somewhere on the system where some pixels that can be shown on the screen are stored. Actually, as <a href="http://s.android.com/devices/graphics/architecture.html#surface">these other docs</a> state, it isn’t so simple. There is a <em>BufferQueue</em> entity in the middle managing what and when the produced pixels are allocated and consumed.</p><p><strong>So we need a <em>Surface</em>.</strong> <strong>There are two ways of obtaining one</strong>: 1) add a <em>SurfaceView</em> or any of its extensions (<em>GLSurfaceView</em>, <em>VideoView</em>) to your layout and take the <em>Surface</em> these views create or 2) create one yourself. To obtain a reference to the <em>Surface</em> created by a <em>SurfaceView</em> you can call <em>SurfaceView.getHolder().getSurface(),</em> while to create one ourselves we need a <em>SurfaceTexture</em> (see the public <a href="http://developer.android.com/reference/android/view/Surface.html#Surface(android.graphics.SurfaceTexture)"><em>Surface</em> constructor</a>), which is basically a handle to some texture on the GPU.</p><pre>SurfaceTexture(int texName)</pre><pre>Construct a new SurfaceTexture to stream images to a given OpenGL texture.</pre><p>Thus, in order to create a <em>SurfaceTexture</em> you need the id of a texture on the GPU. Or simply add a <em>TextureView</em> to your layout and it will create one for you. <strong>Summing it all up we’re left with 3 different options to show video on the screen </strong>(assuming the <em>MediaPlayer</em> is used):</p><p>1) add a <em>SurfaceView</em>/<em>VideoView</em> to the layout and attach its <em>Surface</em> to the <em>MediaPlayer,</em></p><p>2) add a <em>TextureView</em> to the layout, create a <em>Surface</em> with its <em>SurfaceTexture</em> and attach it to the <em>MediaPlayer,</em></p><p>3) add a <em>GLSurfaceView</em> to the layout, generate a texture on the GPU, create a <em>SurfaceTexture</em> with it and then a <em>Surface</em>. Finally attach that <em>Surface</em> to the <em>MediaPlayer</em> so it draws the decoded frames to that texture and finally draw the texture on the <em>GLSurfaceView</em>.</p><p><strong>The first two are of course the most convenient, but we don’t really get any control over how the video is mapped to the screen</strong> (would be great if the <em>TextureView</em> would allow you to define your own geometry + shaders) nor do we get access to where the frames are stored so we can modify them. <strong>The third approach gives you both, we know the texture id where the frames are being stored and we’re also mapping that texture to the screen ourselves so we have full control over what we’re drawing.</strong> It is a little bit more code but let’s see how we can do it.</p><p><a href="https://medium.com/@fabrantes/rounded-video-corners-on-android-part-i-68eca391f39b"><em>Contnue reading — Part I</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3467841cc1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>