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_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_I420:
48         // for these two formats, chroma stride is calculated as half of luma stride
49         // so luma stride needs to be 128-byte aligned.
50         return 128;
51     default:
52         return 64;
53     }
54 }
55 
queryNV12Format()56 uint32_t DisplayQuery::queryNV12Format()
57 {
58     return HAL_PIXEL_FORMAT_NV12;
59 }
60 
forceFbScaling(int device)61 bool DisplayQuery::forceFbScaling(int device)
62 {
63     // RGB planes don't support scaling. Panel fitter can be used to scale frame buffer to device's resolution
64     // if scaling factor is less than 1.5. Otherwise, GPU scaling is needed on RGB buffer, or hardware overlay
65     // scaling is needed on NV12 buffer
66 
67     // this needs to work together with kernel driver. Panel fitter needs to be disabled if scaling factor is greater
68     // than 1.5
69 
70     uint32_t width, height;
71     if (!Hwcomposer::getInstance().getDrm()->getDisplayResolution(device, width, height)) {
72         return false;
73     }
74 
75     if (DEFAULT_DRM_FB_WIDTH / (float)width > 1.5) {
76         return true;
77     }
78 
79     if (DEFAULT_DRM_FB_HEIGHT / (float)height > 1.5) {
80         return true;
81     }
82 
83     return false;
84 }
85 
86 } // namespace intel
87 } // namespace android
88 
89