1 /*
2 // Copyright (c) 2014 Intel Corporation 
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 
17 #include <common/utils/HwcTrace.h>
18 #include <DisplayPlane.h>
19 #include <hal_public.h>
20 #include <DisplayQuery.h>
21 #include <khronos/openmax/OMX_IntelVideoExt.h>
22 #include <Hwcomposer.h>
23 
24 
25 namespace android {
26 namespace intel {
27 
isVideoFormat(uint32_t format)28 bool DisplayQuery::isVideoFormat(uint32_t format)
29 {
30     switch (format) {
31     case OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar:
32     case OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar_Tiled:
33     // Expand format to support the case: Software decoder + HW rendering
34     // Only VP9 use this foramt now
35     case HAL_PIXEL_FORMAT_INTEL_YV12:
36         return true;
37     default:
38         return false;
39     }
40 }
41 
getOverlayLumaStrideAlignment(uint32_t format)42 int DisplayQuery::getOverlayLumaStrideAlignment(uint32_t format)
43 {
44     // both luma and chroma stride need to be 64-byte aligned for overlay
45     switch (format) {
46     case HAL_PIXEL_FORMAT_YV12:
47     case HAL_PIXEL_FORMAT_INTEL_YV12:
48     case HAL_PIXEL_FORMAT_I420:
49         // for these two formats, chroma stride is calculated as half of luma stride
50         // so luma stride needs to be 128-byte aligned.
51         return 128;
52     default:
53         return 64;
54     }
55 }
56 
queryNV12Format()57 uint32_t DisplayQuery::queryNV12Format()
58 {
59     return HAL_PIXEL_FORMAT_NV12;
60 }
61 
forceFbScaling(int device)62 bool DisplayQuery::forceFbScaling(int device)
63 {
64     // RGB planes don't support scaling. Panel fitter can be used to scale frame buffer to device's resolution
65     // if scaling factor is less than 1.5. Otherwise, GPU scaling is needed on RGB buffer, or hardware overlay
66     // scaling is needed on NV12 buffer
67 
68     // this needs to work together with kernel driver. Panel fitter needs to be disabled if scaling factor is greater
69     // than 1.5
70 
71     uint32_t width, height;
72     if (!Hwcomposer::getInstance().getDrm()->getDisplayResolution(device, width, height)) {
73         return false;
74     }
75 
76     if (DEFAULT_DRM_FB_WIDTH / (float)width > 1.5) {
77         return true;
78     }
79 
80     if (DEFAULT_DRM_FB_HEIGHT / (float)height > 1.5) {
81         return true;
82     }
83 
84     return false;
85 }
86 
87 } // namespace intel
88 } // namespace android
89 
90