How does GLSurfaceView connect with surfaceflinger? - android

Recently I am confused with GLSurfaceView. In java level, it use glsurfaceview and how it connect with surfaceflinger?
thanks
james.

Using GLSurfaceView , you will draw into a EGLSurface which is created from A Surface. The surface ,inside of surfaceFlinger, is called SurfaceTexture with a BufferQueue . Therefore, SurfacFlinger still own that piece of memory the GLSurfaceView will be drawing to and thus could composite it.

Have a look here. In brief:
The surface flinger is the compositor and handles drawing Surface instances.
A GLSurfaceView contains a Surface that can be drawn to using OpenGL ES.

Related

Draw Here MapsView into a GLSurfaceView

I got a problem with drawing a mapView from the here-api into a glSurfaceView (it should be a glSurfaceView as some external devices requeres it to ensure good performance).
The map draws into a normal SurfaceView just perfectly.
I do the following steps to create the map-view in the GLSurfaceView:
Extend my view from GLSurfaceView:
public class MapView extends GLSurfaceView
Setting the Renderer uppon initialisation in the ctors:
setRenderer(...)
Start rendering after the map has been initialized:
Renderer renderer = new MapOffScreenRenderer(getContext());
renderer.setMap(map); //mapView, not null
updateRendererSize(); //update the render size to the screen size
renderer.start(getHolder(), surfaceUpdatedListener); // HERE COMES THE CRASH
It seems like the MapOffscreenRenderer crashes if i try to tell him to draw the map into the glSurfaceView.
The crash is a generic error: "12291 EGL_BAD_ALLOC during rendering".
If i try to call the renderer.start() func (without the holder param), then everything is fine (the only bad thing is that the map is not being drawn).
The GlSurceView initialisation itself is fine as i am able to draw my own geometries into it.
Thank you very much for you help.
MapOffScreenRenderer internally uses a PBuffer backed surface and its own rendering thread and EGL context. It is not intended to be used to push into another GLSurfaceView surface. If you really want to do this then maybe create an independent OpenGL surface and share it between the GLSurfaceView and the MapOffScreenRenderer.
What use case are you try to accomplish using this type of design?

Need to draw to surface used by MediaRecorder

I need to record a video that just contains one single frame: an image specified by the user (it can be of any length, but it will only have the same static image). So, I figured I could use the new MediaRecorder.VideoSource.SURFACE and just draw to the Surface being used by the recorder. I initialize the recorder properly, and I can even call MediaRecorder.getSurface() without an exception (something that is apparently tricky).
My problem is somewhat embarrassing: I don't know what to do with the surface returned. I need to draw to it somehow, but all examples I can find involve drawing to a SurfaceView. Is this surface the same surface used by MediaRecorder.setPreviewDisplay()? How do I draw something to it?
In theory you can use Surface#lockCanvas() to get a Canvas to draw on if you want to render in software. There used to be problems with this on some platforms; not sure if that has been fixed.
The other option is to create an EGLSurface from the Surface and render onto it with OpenGL ES. You can find examples of this, with some code to manage all of the EGL setup, in Grafika.
The GLES recording examples uses MediaCodec rather than MediaRecorder, but the idea is the same, and it should be much simpler with MediaRecorder.

3D transformation for SurfaceView in Android?

I tried to apply some 3D transformation (such as setRotationX) on a surfaceview which is used for camera previewing, but only the frame changes and the content don't.
A SurfaceView has two parts, the Surface and the View. The Surface is a separate layer that is rendered and composited independently. The View part is, by default, a transparent rectangle that creates a "hole" in the View layer, so that you can see through the Views to the Surface behind it.
The transformation you mention (setRotationX()) is a View method, but the camera preview is sent to the Surface. That's why the frame changed but the preview itself didn't.
You can send your preview to a TextureView, which can take an arbitrary transformation matrix (setTransform()), by using the Camera.setPreviewTexture() method. Or you can send it through a SurfaceTexture to an OpenGL ES texture, which can be rendered on the SurfaceView's Surface, using whatever GLES transformations you want. For an example of the latter, see Grafika's "texture from Camera" Activity.

Create cameraview (mask) on surfaceview in android

I want to create a mask on camera surface view. see image below. mask is resizable. image will be clicked only by unblurred area. can anybody give idea how to create suh mask? thanks in advance.
You can't draw on the Surface of the SurfaceView that is receiving the camera preview.
You have two basic options: draw on the View part of the SurfaceView, treating it as a custom view, or create a second SurfaceView and layer it on top of the camera surface.
For the latter, you would use setZOrderMediaOverlay() to position the Surface above the camera Surface layer but below the View UI layer. You can use Canvas or GLES to draw on it. You can find an example of an activity with three SurfaceViews in Grafika's "multi-surface test".
You can draw on a surfaceview with camera preview. You need to set the
setWillNotDraw(false);
in surfaceCreated override.
See: Extended SurfaceView's onDraw() method never called
So from there on, do all your drawing in onDraw as normal.

How to add a OpenGl object into a surfaceView camera?

I'm not certain how to implement the object made from OpenGl into the surfaceView of the Camera. Is it possible to set the OpenGl objectinto a custom android camera that uses surfaceView. ?
No.
The SurfaceView's Surface has a producer-consumer relationship. In this case, the producer is the Camera, and the consumer is the system compositor (surfaceflinger). To draw on the Surface with OpenGL ES, you would need to attach OpenGL as the producer, and a Surface cannot have two producers at the same time.
What you can do instead is create a second SurfaceView, and call setZOrderMediaOverlay() to put it above the Camera-driven Surface but below the UI, then render on that with GLES. See Grafika's "multi-surface test" for a demonstration of overlapping SurfaceViews.

Categories

Resources