1. 首先给自己做个list, 方便查找
camera 用到ANativewindow src code
/frameworks/av/services/camera/libcameraservice/CameraHardwareInterface.h
/system/core/include/system/window.h
/frameworks/native/libs/gui/SurfaceTextureClient.cpp
2 . ANativeWindow API:
在这一过程中使用的API
a 、cancelBuffer
Hook used to cancel a buffer that has been dequeued. No synchronization is performed between dequeue() and cancel(), so either external synchronization is needed, or these functions must be called from the same thread.
b、 queuebuffer ---
Hook called by EGL when modifications to the render buffer are done. This unlocks and post the buffer
The window holds a reference to the buffer between dequeueBuffer and either queueBuffer or cancelBuffer, so clients only need their own reference if they might use the buffer after queueing or canceling it.
c、dequeuebuffer
Hook called by EGL to acquire a buffer. This call may block if no buffers are available.
d、lock_buffer -- do nothing
static int __lock_buffer(struct preview_stream_ops* w,
buffer_handle_t* /*buffer*/)
{
ANativeWindow *a = anw(w);
(void)a;
return 0;
}
3. GraphicBufferMapper
GraphicBufferMapper& mapper(GraphicBufferMapper::get());
mapper.lock(*phandle, CAMHAL_GRALLOC_USAGE, rect, &img);
The (*lock)() method is called before a buffer is accessed for the specified usage.
This call may block, for instance if the h/w needsto finish rendering or if CPU caches need to be synchronized.
The caller promises to modify only pixels in the area specified by (l,t,w,h).
mapper.unlock((buffer_handle_t) *phandle);
The (*unlock)() method must be called after all changes to the buffer are completed.
those function been defined in
hardware/libhardware/include/hardware/gralloc.h
gralloc.cpp
88 registerBuffer: gralloc_register_buffer,
89 unregisterBuffer: gralloc_unregister_buffer,
90 lock: gralloc_lock,
91 unlock: gralloc_unlock, ->gc_gralloc_lock
92 perform: gralloc_perform,
lock: 1. Lock android native buffer and get Vaddress
unlock: ion_flush(hnd);