1. mPreviewWindow 在hardware/intel/libcamera/CameraHardware.h 中定义
preview_stream_ops_t* mPreviewWindow;
preview_stream_ops_t 定义:
1. typedef struct preview_stream_ops {
2. int (*dequeue_buffer)(struct preview_stream_ops* w,
3. buffer_handle_t** buffer, int *stride);
4. int (*enqueue_buffer)(struct preview_stream_ops* w,
5. buffer_handle_t* buffer);
6. int (*cancel_buffer)(struct preview_stream_ops* w,
7. buffer_handle_t* buffer);
8. int (*set_buffer_count)(struct preview_stream_ops* w, int count);
9. int (*set_buffers_geometry)(struct preview_stream_ops* pw,
10. int w, int h, int format);
11. int (*set_crop)(struct preview_stream_ops *w,
12. int left, int top, int right, int bottom);
13. int (*set_usage)(struct preview_stream_ops* w, int usage);
14. int (*set_swap_interval)(struct preview_stream_ops *w, int interval);
15. int (*get_min_undequeued_buffer_count)(const struct preview_stream_ops *w,
16. int *count);
17. int (*lock_buffer)(struct preview_stream_ops* w,
18. buffer_handle_t* buffer);
19. } preview_stream_ops_t;
2. 初始化:
# if (mPreviewWindow != 0) {
# int preview_width, preview_height;
# mParameters.getPreviewSize(&preview_width, &preview_height);
# mPreviewWindow->set_buffers_geometry(
# mPreviewWindow,
# preview_width,
# preview_height,
# HAL_PIXEL_FORMAT_RGB_565);
# }
mPreviewWindow->set_buffers_geometry() 在/frameworks/base/services/camera/libcameraservice/CameraHardwareInterface.h 中定义
1. void initHalPreviewWindow()
2. {
3. mHalPreviewWindow.nw.cancel_buffer = __cancel_buffer;
4. mHalPreviewWindow.nw.lock_buffer = __lock_buffer;
5. mHalPreviewWindow.nw.dequeue_buffer = __dequeue_buffer;
6. mHalPreviewWindow.nw.enqueue_buffer = __enqueue_buffer;
7. mHalPreviewWindow.nw.set_buffer_count = __set_buffer_count;
8. mHalPreviewWindow.nw.set_buffers_geometry = __set_buffers_geometry;
9. mHalPreviewWindow.nw.set_crop = __set_crop;
10. mHalPreviewWindow.nw.set_usage = __set_usage;
11. mHalPreviewWindow.nw.set_swap_interval = __set_swap_interval;
12.
13. mHalPreviewWindow.nw.get_min_undequeued_buffer_count =
14. __get_min_undequeued_buffer_count;
15. }
16.
17. sp<ANativeWindow> mPreviewWindow;
18.
19. struct camera_preview_window {
20. struct preview_stream_ops nw;
21. void *user;
22. };
23.
24. struct camera_preview_window mHalPreviewWindow;
__set_buffers_geometry 封装了 native_window_set_buffers_geometry().
1. static int __set_buffers_geometry(struct preview_stream_ops* w,
2. int width, int height, int format)
3. {
4. ANativeWindow *a = anw(w);
5. return native_window_set_buffers_geometry(a,
6. width, height, format);
7. }
native_window_set_buffers_geometry(). 在system/core/include/system/window.h 中定义:
1. /*
2. * native_window_set_buffers_geometry(..., int w, int h, int format)
3. * All buffers dequeued after this call will have the dimensions and format
4. * specified. A successful call to this function has the same effect as calling
5. * native_window_set_buffers_size and native_window_set_buffers_format.
6. *
7. * XXX: This function is deprecated. The native_window_set_buffers_dimensions
8. * and native_window_set_buffers_format functions should be used instead.
9. */
10. static inline int native_window_set_buffers_geometry(
11. struct ANativeWindow* window,
12. int w, int h, int format)
13. {
14. return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
15. w, h, format);
16. }
其他的函数也是类似的调用情况。