简体   繁体   中英

What is the use of calling SurfaceHolder.setFixedSize()?

I have similar code to many examples floating around the net:

mSurfaceHolder = mVideoSurface.getHolder();
mSurfaceHolder.addCallback(this);
mSurfaceHolder.setFormat(PixelFormat.TRANSPARENT);
mSurfaceHolder.setFixedSize(20, 10);

Then in the callbacks I have:

@Override public void surfaceCreated(SurfaceHolder holder)
{
    Log.d(TAG, "SurfaceCreated");
    mSurfaceHolder.setFixedSize(20, 10);
}

@Override public void surfaceChanged(
    SurfaceHolder holder, int format, int width, int height
)
{
    Log.d(TAG, "SurfaceChanged to " +
        format + " width " + width + " height " + height);
}

From this code I would expect the video surface to be set to the tiny size of 20x10 pixels , then scaled back up to whatever layout size I'm using it, showing a pixelated/blurred version. However, the video being played back looks right in its full native resolution, it doesn't scale down to 20x10. But I get logs like these:

SurfaceChanged to -2 width 20 height 10

So if the video surface is set to this tiny size, but graphically the video still looks high definition, what is the use of setting the surface size?

Full source code available at https://github.com/gradha/Stackoverflow38118219 .

The size matters for things like OpenGL ES, where you draw on the Surface at whatever size it happens to be. When you're sending buffers of data from the camera or a video decoder, the buffers arrive at whatever size they were given by the camera or video. It's scaled to match the size of the SurfaceView's View, but it's not scaled to match the size of the SurfaceView's Surface.

The one place the two concepts cross is with the Camera2 preview API, which will apparently resize its capture to match the Surface in some cases.

You can read more about a primary use case in this blog post (demo here ), and more about the graphics architecture as a whole in this doc .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM