[Android] Get each layer picture from SurfaceFlinger (3) Summary review

 

in

https://blog.csdn.net/aaajj/article/details/93653074

https://blog.csdn.net/aaajj/article/details/102537628

It discusses an experiment of obtaining layer images from SurfaceFlinger. Let’s review it here.

The image of the application is essentially drawn on a memory space, which is created by SurfaceFinger. Through a series of complex operations, the client can obtain the address of this shared area and write data on it to achieve drawing.

[Preliminary Study on Android Display System] First acquaintance with surface

The C++ program inside draws pictures by writing memory data, which can deepen this understanding.

The image storage area created by SurfaceFinger is managed by GraifcBuffer. In our experiment, the GraifcBuffer object is also obtained, and the GraifcBuffer object is transferred to another program A through the binder. After program A obtains the GraphicBuffer object, it calls Its lockAsync method gets the address of the image, then gets the image and saves it in the picture.

                        sp<GraphicBuffer> buf = new GraphicBuffer();;

                        data.read(*buf);

                       

                        Region newDirtyRegion;

                        const Rect bounds(w, h);

                        newDirtyRegion.set(bounds);

                       

                        int fenceFd = -1;

                        void* vaddr;

                        //GRALLOC_USAGE_SW_READ_OFTEN 0x00000003U

                        //GRALLOC_USAGE_SW_WRITE_OFTEN 0x00000030U

        status_t res = buf->lockAsync(0x00000003U | 0x00000030U,

                newDirtyRegion.bounds(), &vaddr, fenceFd);

               

              printf("==== vaddr=%p\n", vaddr);

             

              char pname[32] = {0};

                        sprintf(pname, "%02d.png", icode++);

                       

                        char* base = (char*)vaddr;

                       

                        writePNG(pname, base, w, h, format, s);

 

 

Reference

https://www.jianshu.com/p/993e66015c18

Android drawing mechanism

 

 

Guess you like

Origin blog.csdn.net/aaajj/article/details/105159905