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

自闭症网瘾萝莉.ら 提交于 2019-12-11 00:39:51

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/38118219/what-is-the-use-of-calling-surfaceholder-setfixedsize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!