1 /*
2  * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
3 
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *   * Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *   * Redistributions in binary form must reproduce the above
10  *     copyright notice, this list of conditions and the following
11  *     disclaimer in the documentation and/or other materials provided
12  *     with the distribution.
13  *   * Neither the name of The Linux Foundation nor the names of its
14  *     contributors may be used to endorse or promote products derived
15  *     from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <dlfcn.h>
31 #include <log/log.h>
32 #include <mutex>
33 
34 #include "gr_camera_info.h"
35 #include "gralloc_priv.h"
36 
37 using std::lock_guard;
38 using std::mutex;
39 
40 namespace gralloc {
41 
42 CameraInfo *CameraInfo::s_instance = nullptr;
43 
GetInstance()44 CameraInfo *CameraInfo::GetInstance() {
45   static mutex s_lock;
46   lock_guard<mutex> obj(s_lock);
47   if (!s_instance) {
48     s_instance = new CameraInfo();
49   }
50 
51   return s_instance;
52 }
53 
CameraInfo()54 CameraInfo::CameraInfo() {
55   libcamera_utils_ = ::dlopen("libcamxexternalformatutils.so", RTLD_NOW);
56   if (libcamera_utils_) {
57     *reinterpret_cast<void **>(&LINK_camera_get_stride_in_bytes) =
58         ::dlsym(libcamera_utils_, "CamxFormatUtil_GetStrideInBytes");
59     *reinterpret_cast<void **>(&LINK_camera_get_stride_in_pixels) =
60         ::dlsym(libcamera_utils_, "CamxFormatUtil_GetStrideInPixels");
61     *reinterpret_cast<void **>(&LINK_camera_get_scanline) =
62         ::dlsym(libcamera_utils_, "CamxFormatUtil_GetScanline");
63     *reinterpret_cast<void **>(&LINK_camera_get_plane_size) =
64         ::dlsym(libcamera_utils_, "CamxFormatUtil_GetPlaneSize");
65     *reinterpret_cast<void **>(&LINK_camera_get_buffer_size) =
66         ::dlsym(libcamera_utils_, "CamxFormatUtil_GetBufferSize");
67     *reinterpret_cast<void **>(&LINK_camera_get_ubwc_info) =
68         ::dlsym(libcamera_utils_, "CamxFormatUtil_GetUBWCInfo");
69     *reinterpret_cast<void **>(&LINK_camera_get_plane_alignment) =
70         ::dlsym(libcamera_utils_, "CamxFormatUtil_GetPlaneAlignment");
71     *reinterpret_cast<void **>(&LINK_camera_get_plane_offset) =
72         ::dlsym(libcamera_utils_, "CamxFormatUtil_GetPlaneOffset");
73     *reinterpret_cast<void **>(&LINK_camera_is_per_plane_fd_needed) =
74         ::dlsym(libcamera_utils_, "CamxFormatUtil_IsPerPlaneFdNeeded");
75     *reinterpret_cast<void **>(&LINK_camera_get_bpp) =
76         ::dlsym(libcamera_utils_, "CamxFormatUtil_GetBpp");
77     *reinterpret_cast<void **>(&LINK_camera_get_per_plane_bpp) =
78         ::dlsym(libcamera_utils_, "CamxFormatUtil_GetPerPlaneBpp");
79     *reinterpret_cast<void **>(&LINK_camera_get_subsampling_factor) =
80         ::dlsym(libcamera_utils_, "CamxFormatUtil_GetSubsamplingFactor");
81     *reinterpret_cast<void **>(&LINK_camera_get_plane_count) =
82         ::dlsym(libcamera_utils_, "CamxFormatUtil_GetPlaneCount");
83     *reinterpret_cast<void **>(&LINK_camera_get_plane_types) =
84         ::dlsym(libcamera_utils_, "CamxFormatUtil_GetPlaneTypes");
85     *reinterpret_cast<void **>(&LINK_camera_get_pixel_increment) =
86         ::dlsym(libcamera_utils_, "CamxFormatUtil_GetPixelIncrement");
87     *reinterpret_cast<void **>(&LINK_camera_get_plane_start_address_alignment) =
88         ::dlsym(libcamera_utils_, "CamxFormatUtil_GetPlaneStartAddressAlignment");
89   } else {
90     ALOGE("%s: Failed to load libcamxexternalformatutils.so - %s", __FUNCTION__, strerror(errno));
91   }
92 }
93 
~CameraInfo()94 CameraInfo::~CameraInfo() {
95   if (libcamera_utils_) {
96     ::dlclose(libcamera_utils_);
97   }
98 }
99 
GetCameraPixelFormat(int hal_format)100 CamxPixelFormat CameraInfo::GetCameraPixelFormat(int hal_format) {
101   CamxPixelFormat format = (CamxPixelFormat)0;
102   switch (hal_format) {
103     case HAL_PIXEL_FORMAT_NV21_ZSL:
104       format = CAMERA_PIXEL_FORMAT_NV21_ZSL;
105       break;
106     case HAL_PIXEL_FORMAT_NV12_LINEAR_FLEX:
107       format = CAMERA_PIXEL_FORMAT_YUV_FLEX;
108       break;
109     case HAL_PIXEL_FORMAT_NV12_UBWC_FLEX:
110       format = CAMERA_PIXEL_FORMAT_UBWC_FLEX;
111       break;
112     case HAL_PIXEL_FORMAT_NV12_UBWC_FLEX_2_BATCH:
113       format = CAMERA_PIXEL_FORMAT_UBWC_FLEX_2_BATCH;
114       break;
115     case HAL_PIXEL_FORMAT_NV12_UBWC_FLEX_4_BATCH:
116       format = CAMERA_PIXEL_FORMAT_UBWC_FLEX_4_BATCH;
117       break;
118     case HAL_PIXEL_FORMAT_NV12_UBWC_FLEX_8_BATCH:
119       format = CAMERA_PIXEL_FORMAT_UBWC_FLEX_8_BATCH;
120       break;
121     case HAL_PIXEL_FORMAT_MULTIPLANAR_FLEX:
122       format = CAMERA_PIXEL_FORMAT_MULTIPLANAR_FLEX;
123       break;
124     case HAL_PIXEL_FORMAT_RAW_OPAQUE:
125       format = CAMERA_PIXEL_FORMAT_RAW_OPAQUE;
126       break;
127     case HAL_PIXEL_FORMAT_RAW10:
128       format = CAMERA_PIXEL_FORMAT_RAW10;
129       break;
130     case HAL_PIXEL_FORMAT_RAW12:
131       format = CAMERA_PIXEL_FORMAT_RAW12;
132       break;
133     default:
134       ALOGE("%s: No map for format: 0x%x", __FUNCTION__, hal_format);
135       break;
136   }
137 
138   return format;
139 }
140 
GetBufferSize(int format,int width,int height,unsigned int * size)141 int CameraInfo::GetBufferSize(int format, int width, int height, unsigned int *size) {
142   CamxFormatResult result = (CamxFormatResult)-1;
143   if (LINK_camera_get_buffer_size) {
144     result = LINK_camera_get_buffer_size(GetCameraPixelFormat(format), width, height, size);
145     if (result != 0) {
146       ALOGE("%s: Failed to get the buffer size. Error code: %d", __FUNCTION__, result);
147     }
148   } else {
149     ALOGW("%s: Failed to link CamxFormatUtil_GetBufferSize. Error code : %d", __FUNCTION__, result);
150   }
151 
152   return result;
153 }
154 
GetStrideInBytes(int format,int plane_type,int width,int * stride_bytes)155 int CameraInfo::GetStrideInBytes(int format, int plane_type, int width, int *stride_bytes) {
156   CamxFormatResult result = (CamxFormatResult)-1;
157   if (LINK_camera_get_stride_in_bytes) {
158     result = LINK_camera_get_stride_in_bytes(GetCameraPixelFormat(format),
159                                              GetCamxPlaneType(plane_type), width, stride_bytes);
160     if (result != 0) {
161       ALOGE("%s: Failed to get the stride in bytes. Error code: %d", __FUNCTION__, result);
162     }
163   } else {
164     ALOGW("%s: Failed to link CamxFormatUtil_GetStrideInBytes. Error code : %d", __FUNCTION__,
165           result);
166   }
167 
168   return result;
169 }
170 
GetStrideInPixels(int format,int plane_type,int width,float * stride_pixel)171 int CameraInfo::GetStrideInPixels(int format, int plane_type, int width, float *stride_pixel) {
172   CamxFormatResult result = (CamxFormatResult)-1;
173   if (LINK_camera_get_stride_in_pixels) {
174     result = LINK_camera_get_stride_in_pixels(GetCameraPixelFormat(format),
175                                               GetCamxPlaneType(plane_type), width, stride_pixel);
176     if (result != 0) {
177       ALOGE("%s: Failed to get the stride in pixels. Error code: %d", __FUNCTION__, result);
178     }
179   } else {
180     ALOGW("%s: Failed to link CamxFormatUtil_GetStrideInPixels. Error code : %d", __FUNCTION__,
181           result);
182   }
183 
184   return result;
185 }
186 
GetPixelIncrement(int format,int plane_type,int * pixel_increment)187 int CameraInfo::GetPixelIncrement(int format, int plane_type, int *pixel_increment) {
188   CamxFormatResult result = (CamxFormatResult)-1;
189   if (LINK_camera_get_pixel_increment) {
190     result = LINK_camera_get_pixel_increment(GetCameraPixelFormat(format),
191                                              GetCamxPlaneType(plane_type), pixel_increment);
192     if (result != 0) {
193       ALOGE("%s: Failed to get pixel increment. Error code: %d", __FUNCTION__, result);
194     }
195   } else {
196     ALOGW("%s: Failed to link CamxFormatUtil_GetPixelIncrement. Error code : %d", __FUNCTION__,
197           result);
198   }
199 
200   return result;
201 }
202 
GetPlaneOffset(int format,int plane_type,int width,int height,int * offset)203 int CameraInfo::GetPlaneOffset(int format, int plane_type, int width, int height, int *offset) {
204   CamxFormatResult result = (CamxFormatResult)-1;
205   if (LINK_camera_get_plane_offset) {
206     result = LINK_camera_get_plane_offset(GetCameraPixelFormat(format),
207                                           GetCamxPlaneType(plane_type), offset, width, height);
208     if (result != 0) {
209       ALOGE("%s: Failed to get the plane offset. Error code: %d", __FUNCTION__, result);
210     }
211   } else {
212     ALOGW("%s: Failed to link CamxFormatUtil_GetPlaneOffset. Error code : %d", __FUNCTION__,
213           result);
214   }
215 
216   return result;
217 }
218 
GetSubsamplingFactor(int format,int plane_type,bool isHorizontal,int * subsampling_factor)219 int CameraInfo::GetSubsamplingFactor(int format, int plane_type, bool isHorizontal,
220                                      int *subsampling_factor) {
221   CamxFormatResult result = (CamxFormatResult)-1;
222   if (LINK_camera_get_subsampling_factor) {
223     result = LINK_camera_get_subsampling_factor(GetCameraPixelFormat(format),
224                                                 GetCamxPlaneType(plane_type), isHorizontal,
225                                                 subsampling_factor);
226     if (result != 0) {
227       ALOGE("%s: Failed to get the sub-sampling factor. Error code: %d", __FUNCTION__, result);
228     }
229   } else {
230     ALOGW("%s: Failed to link CamxFormatUtil_GetSubsamplingFactor. Error code : %d", __FUNCTION__,
231           result);
232   }
233 
234   return result;
235 }
236 
GetPlaneTypes(int format,PlaneComponent * plane_component_array,int * plane_count)237 int CameraInfo::GetPlaneTypes(int format, PlaneComponent *plane_component_array, int *plane_count) {
238   CamxPlaneType plane_types_array[8] = {};
239   CamxFormatResult result = (CamxFormatResult)-1;
240   if (LINK_camera_get_plane_types) {
241     result =
242         LINK_camera_get_plane_types(GetCameraPixelFormat(format), plane_types_array, plane_count);
243     if (result == 0) {
244       for (int plane = 0; plane < *plane_count; plane++) {
245         plane_component_array[plane] = GetPlaneComponent(plane_types_array[plane]);
246       }
247     } else {
248       ALOGE("%s: Failed to get the plane types. Error code: %d", __FUNCTION__, result);
249     }
250   } else {
251     ALOGW("%s: Failed to link CamxFormatUtil_GetPlaneTypes. Error code : %d", __FUNCTION__, result);
252   }
253 
254   return result;
255 }
256 
GetScanline(int format,int plane_type,int height,int * scanlines)257 int CameraInfo::GetScanline(int format, int plane_type, int height, int *scanlines) {
258   CamxFormatResult result = (CamxFormatResult)-1;
259   if (LINK_camera_get_scanline) {
260     result = LINK_camera_get_scanline(GetCameraPixelFormat(format), GetCamxPlaneType(plane_type),
261                                       height, scanlines);
262     if (result != 0) {
263       ALOGE("%s: Failed to get the scanlines. Error code: %d", __FUNCTION__, result);
264     }
265   } else {
266     ALOGW("%s: Failed to link CamxFormatUtil_GetScanline. Error code : %d", __FUNCTION__, result);
267   }
268 
269   return result;
270 }
271 
GetPlaneSize(int format,int plane_type,int width,int height,unsigned int * size)272 int CameraInfo::GetPlaneSize(int format, int plane_type, int width, int height,
273                              unsigned int *size) {
274   CamxFormatResult result = (CamxFormatResult)-1;
275   if (LINK_camera_get_plane_size) {
276     result = LINK_camera_get_plane_size(GetCameraPixelFormat(format), GetCamxPlaneType(plane_type),
277                                         width, height, size);
278     if (result != 0) {
279       ALOGE("%s: Failed to get the plane size. Error code: %d", __FUNCTION__, result);
280     }
281   } else {
282     ALOGW("%s: Failed to link CamxFormatUtil_GetPlaneSize. Error code : %d", __FUNCTION__, result);
283   }
284 
285   return result;
286 }
287 
GetCameraFormatPlaneInfo(int format,int width,int height,int * plane_count,PlaneLayoutInfo * plane_info)288 int CameraInfo::GetCameraFormatPlaneInfo(int format, int width, int height, int *plane_count,
289                                          PlaneLayoutInfo *plane_info) {
290   int h_subsampling = 0;
291   int v_subsampling = 0;
292   int offset = 0;
293   int pixel_increment = 0;
294   float stride_pixel = 0;
295   int stride_bytes = 0;
296   int scanlines = 0;
297   unsigned int plane_size = 0;
298   PlaneComponent plane_type[8] = {};
299   int result;
300   result = GetPlaneTypes(format, plane_type, plane_count);
301   if (result != 0) {
302     ALOGE("%s: Failed to get the plane types. Error code : %d", __FUNCTION__, result);
303     return result;
304   }
305 
306   for (int i = 0; i < *plane_count; i++) {
307     plane_info[i].component = plane_type[i];
308     result = GetSubsamplingFactor(format, plane_type[i], true, &h_subsampling);
309     if (result != 0) {
310       ALOGE("%s: Failed to get horizontal subsampling factor. plane_type = %d, Error code : %d",
311             __FUNCTION__, plane_type[i], result);
312       break;
313     }
314     plane_info[i].h_subsampling = (uint32_t)h_subsampling;
315 
316     result = GetSubsamplingFactor(format, plane_type[i], false, &v_subsampling);
317     if (result != 0) {
318       ALOGE("%s: Failed to get vertical subsampling factor. plane_type = %d, Error code : %d",
319             __FUNCTION__, plane_type[i], result);
320       break;
321     }
322     plane_info[i].v_subsampling = (uint32_t)v_subsampling;
323 
324     result = GetPlaneOffset(format, plane_type[i], width, height, &offset);
325     if (result != 0) {
326       ALOGE("%s: Failed to get plane offset. plane_type = %d, Error code : %d", __FUNCTION__,
327             plane_type[i], result);
328       break;
329     }
330     plane_info[i].offset = (uint32_t)offset;
331 
332     result = GetPixelIncrement(format, plane_type[i], &pixel_increment);
333     if (result != 0) {
334       ALOGE("%s: Failed to get pixel increment. plane_type = %d, Error code : %d", __FUNCTION__,
335             plane_type[i], result);
336       break;
337     }
338     plane_info[i].step = (int32_t)pixel_increment;
339 
340     result = GetStrideInPixels(format, plane_type[i], width, &stride_pixel);
341     if (result != 0) {
342       ALOGE("%s: Failed to get stride in pixel. plane_type = %d, Error code : %d", __FUNCTION__,
343             plane_type[i], result);
344       break;
345     }
346     plane_info[i].stride = (int32_t)stride_pixel;
347 
348     result = GetStrideInBytes(format, plane_type[i], width, &stride_bytes);
349     if (result != 0) {
350       ALOGE("%s: Failed to get stride in bytes. plane_type = %d, Error code : %d", __FUNCTION__,
351             plane_type[i], result);
352       break;
353     }
354     plane_info[i].stride_bytes = (int32_t)stride_bytes;
355 
356     result = GetScanline(format, plane_type[i], height, &scanlines);
357     if (result != 0) {
358       ALOGE("%s: Failed to get scanlines. plane_type = %d, Error code : %d", __FUNCTION__,
359             plane_type[i], result);
360       break;
361     }
362     plane_info[i].scanlines = (int32_t)scanlines;
363 
364     result = GetPlaneSize(format, plane_type[i], width, height, &plane_size);
365     if (result != 0) {
366       ALOGE("%s: Failed to get plane size. plane_type = %d, Error code : %d", __FUNCTION__,
367             plane_type[i], result);
368       break;
369     }
370     plane_info[i].size = (uint32_t)plane_size;
371   }
372 
373   return result;
374 }
375 
GetUBWCInfo(int format,bool * is_supported,bool * is_pi,int * version)376 int CameraInfo::GetUBWCInfo(int format, bool *is_supported, bool *is_pi, int *version) {
377   CamxFormatResult result = (CamxFormatResult)-1;
378   if (LINK_camera_get_ubwc_info) {
379     result = LINK_camera_get_ubwc_info(GetCameraPixelFormat(format), is_supported, is_pi, version);
380     if (result != 0) {
381       ALOGE("%s: Failed to get the UBWC info. Error code: %d", __FUNCTION__, result);
382     }
383   } else {
384     ALOGW("%s: Failed to link CamxFormatUtil_GetUBWCInfo. Error code : %d", __FUNCTION__, result);
385   }
386 
387   return result;
388 }
389 
GetPlaneAlignment(int format,int plane_type,unsigned int * alignment)390 int CameraInfo::GetPlaneAlignment(int format, int plane_type, unsigned int *alignment) {
391   CamxFormatResult result = (CamxFormatResult)-1;
392   if (LINK_camera_get_plane_alignment) {
393     result = LINK_camera_get_plane_alignment(GetCameraPixelFormat(format),
394                                              GetCamxPlaneType(plane_type), alignment);
395     if (result != 0) {
396       ALOGE("%s: Failed to get the plane alignment. Error code: %d", __FUNCTION__, result);
397     }
398   } else {
399     ALOGW("%s: Failed to link CamxFormatUtil_GetPlaneAlignment. Error code : %d", __FUNCTION__,
400           result);
401   }
402 
403   return result;
404 }
405 
IsPerPlaneFdNeeded(int format,bool * is_per_plane_fd_needed)406 int CameraInfo::IsPerPlaneFdNeeded(int format, bool *is_per_plane_fd_needed) {
407   CamxFormatResult result = (CamxFormatResult)-1;
408   if (LINK_camera_is_per_plane_fd_needed) {
409     result =
410         LINK_camera_is_per_plane_fd_needed(GetCameraPixelFormat(format), is_per_plane_fd_needed);
411     if (result != 0) {
412       ALOGE("%s: Failed to get per_plane_fd flag. Error code: %d", __FUNCTION__, result);
413     }
414   } else {
415     ALOGW("%s: Failed to link CamxFormatUtil_IsPerPlaneFdNeeded. Error code : %d", __FUNCTION__,
416           result);
417   }
418 
419   return result;
420 }
421 
GetBpp(int format,int * bpp)422 int CameraInfo::GetBpp(int format, int *bpp) {
423   CamxFormatResult result = (CamxFormatResult)-1;
424   if (LINK_camera_get_bpp) {
425     result = LINK_camera_get_bpp(GetCameraPixelFormat(format), bpp);
426     if (result != 0) {
427       ALOGE("%s: Failed to get the bpp. Error code: %d", __FUNCTION__, result);
428     }
429   } else {
430     ALOGW("%s: Failed to link CamxFormatUtil_GetBpp. Error code : %d", __FUNCTION__, result);
431   }
432 
433   return result;
434 }
435 
GetPerPlaneBpp(int format,int plane_type,int * bpp)436 int CameraInfo::GetPerPlaneBpp(int format, int plane_type, int *bpp) {
437   CamxFormatResult result = (CamxFormatResult)-1;
438   if (LINK_camera_get_per_plane_bpp) {
439     result = LINK_camera_get_per_plane_bpp(GetCameraPixelFormat(format),
440                                            GetCamxPlaneType(plane_type), bpp);
441     if (result != 0) {
442       ALOGE("%s: Failed to get the per plane bpp. Error code: %d", __FUNCTION__, result);
443     }
444   } else {
445     ALOGW("%s: Failed to link CamxFormatUtil_GetPerPlaneBpp. Error code : %d", __FUNCTION__,
446           result);
447   }
448 
449   return result;
450 }
451 
GetPlaneStartAddressAlignment(int format,int plane_type,int * alignment)452 int CameraInfo::GetPlaneStartAddressAlignment(int format, int plane_type, int *alignment) {
453   CamxFormatResult result = (CamxFormatResult)-1;
454   if (LINK_camera_get_plane_start_address_alignment) {
455     result = LINK_camera_get_plane_start_address_alignment(GetCameraPixelFormat(format),
456                                                            GetCamxPlaneType(plane_type), alignment);
457     if (result != 0) {
458       ALOGE("%s: Failed to get the plane star address alignment. Error code: %d", __FUNCTION__,
459             result);
460     }
461   } else {
462     ALOGW("%s: Failed to link CamxFormatUtil_GetPlaneStartAddressAlignment. Error code : %d",
463           __FUNCTION__, result);
464   }
465 
466   return result;
467 }
468 
GetPlaneComponent(CamxPlaneType plane_type)469 PlaneComponent CameraInfo::GetPlaneComponent(CamxPlaneType plane_type) {
470   PlaneComponent plane_component = (PlaneComponent)0;
471   switch (plane_type) {
472     case CAMERA_PLANE_TYPE_RAW:
473       plane_component = (PlaneComponent)PLANE_COMPONENT_RAW;
474       break;
475     case CAMERA_PLANE_TYPE_Y:
476       plane_component = (PlaneComponent)PLANE_COMPONENT_Y;
477       break;
478     case CAMERA_PLANE_TYPE_UV:
479       plane_component = (PlaneComponent)(PLANE_COMPONENT_Cb | PLANE_COMPONENT_Cr);
480       break;
481     case CAMERA_PLANE_TYPE_U:
482       plane_component = (PlaneComponent)PLANE_COMPONENT_Cb;
483       break;
484     case CAMERA_PLANE_TYPE_V:
485       plane_component = (PlaneComponent)PLANE_COMPONENT_Cr;
486       break;
487     case CAMERA_PLANE_TYPE_META_Y:
488       plane_component = (PlaneComponent)(PLANE_COMPONENT_META | PLANE_COMPONENT_Y);
489       break;
490     case CAMERA_PLANE_TYPE_META_VU:
491       plane_component =
492           (PlaneComponent)(PLANE_COMPONENT_META | PLANE_COMPONENT_Cb | PLANE_COMPONENT_Cr);
493       break;
494     default:
495       ALOGE("%s: No PlaneComponent mapping for plane_type: %d", __FUNCTION__, plane_type);
496       break;
497   }
498 
499   return plane_component;
500 }
501 
GetCamxPlaneType(int plane_type)502 CamxPlaneType CameraInfo::GetCamxPlaneType(int plane_type) {
503   CamxPlaneType camx_plane_type = (CamxPlaneType)0;
504   switch (plane_type) {
505     case PLANE_COMPONENT_RAW:
506       camx_plane_type = CAMERA_PLANE_TYPE_RAW;
507       break;
508     case PLANE_COMPONENT_Y:
509       camx_plane_type = CAMERA_PLANE_TYPE_Y;
510       break;
511     case (PLANE_COMPONENT_Cb | PLANE_COMPONENT_Cr):
512       camx_plane_type = CAMERA_PLANE_TYPE_UV;
513       break;
514     case PLANE_COMPONENT_Cb:
515       camx_plane_type = CAMERA_PLANE_TYPE_U;
516       break;
517     case PLANE_COMPONENT_Cr:
518       camx_plane_type = CAMERA_PLANE_TYPE_V;
519       break;
520     case (PLANE_COMPONENT_META | PLANE_COMPONENT_Y):
521       camx_plane_type = CAMERA_PLANE_TYPE_META_Y;
522       break;
523     case (PLANE_COMPONENT_META | PLANE_COMPONENT_Cr | PLANE_COMPONENT_Cb):
524       camx_plane_type = CAMERA_PLANE_TYPE_META_VU;
525       break;
526     default:
527       ALOGE("%s: No CamxPlane for plane_type: %d", __FUNCTION__, plane_type);
528       break;
529   }
530 
531   return camx_plane_type;
532 }
533 
534 }  // namespace gralloc
535