Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Antialiasing in TextureView

I tried to play the same video with a SurfaceView and a TextureView and noticed that the image rendered with the TextureView is more aliased (less 'smooth') than with the SurfaceView.

What is the reason for this ? Is there any way to configure rendering of TextureView to look better ?

The TextureView is used like this:

    TextureView textureView = new TextureView(this);
    textureView.setSurfaceTextureListener(new SurfaceTextureListener() {

        @Override
        public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
            Log.i("test", "onSurfaceTextureAvailable()");
            MediaPlayer player = MediaPlayer.create(TestActivity.this, Uri.parse(VIDEO_URL));
            Surface surface = new Surface(surfaceTexture);
            player.setSurface(surface);
            player.start();
        }

        @Override
        public void onSurfaceTextureUpdated(SurfaceTexture surface) { 
            Log.i("test", "onSurfaceTextureUpdated()");
        }

        @Override
        public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { 
            Log.i("test", "onSurfaceTextureSizeChanged()");
        }

        @Override
        public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
            Log.i("test", "onSurfaceTextureDestroyed()");
            return false;
        }
    });
    setContentView(textureView);

And for the SurfaceView:

    SurfaceView surfaceView = new SurfaceView(this);
    surfaceView.getHolder().addCallback(new Callback() {

        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            Log.i("test", "surfaceCreated()");
        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) { 
            Log.i("test", "surfaceDestroyed()");
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { 
            Log.i("test", "surfaceChanged()");
            MediaPlayer player = MediaPlayer.create(TestActivity.this, Uri.parse(VIDEO_URL));
            player.setSurface(holder.getSurface());
            player.start();
        }
    });
    setContentView(surfaceView);
like image 657
sdabet Avatar asked Sep 18 '12 09:09

sdabet


1 Answers

Well, it seems that applying a scaling (other than 1) on the TextureView does the 'smoothing' effect that I'm looking for.

textureView.setScaleX(1.00001f);

That sounds like a strange hack...but it works. Would be interesting to dig out what's done in the scaling that changes the rendering aspect...

like image 192
sdabet Avatar answered Oct 12 '22 23:10

sdabet