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 #include <common/utils/HwcTrace.h>
17 #include <ips/common/GrallocBufferBase.h>
18 #include <DisplayQuery.h>
19 #include <khronos/openmax/OMX_IntelVideoExt.h>
20 #include <hal_public.h>
21 
22 namespace android {
23 namespace intel {
24 
GrallocBufferBase(uint32_t handle)25 GrallocBufferBase::GrallocBufferBase(uint32_t handle)
26     : GraphicBuffer(handle)
27 {
28     ALOGTRACE("handle = %#x", handle);
29     initBuffer(handle);
30 }
31 
resetBuffer(uint32_t handle)32 void GrallocBufferBase::resetBuffer(uint32_t handle)
33 {
34     GraphicBuffer::resetBuffer(handle);
35     initBuffer(handle);
36 }
37 
initBuffer(uint32_t)38 void GrallocBufferBase::initBuffer(uint32_t /* handle */)
39 {
40     // nothing to initialize
41 }
42 
initStride()43 void GrallocBufferBase::initStride()
44 {
45     int yStride, uvStride;
46 
47     // setup stride
48     switch (mFormat) {
49     case HAL_PIXEL_FORMAT_YV12:
50     case HAL_PIXEL_FORMAT_I420:
51         uint32_t yStride_align;
52         yStride_align = DisplayQuery::getOverlayLumaStrideAlignment(mFormat);
53         if (yStride_align > 0)
54         {
55             yStride = align_to(align_to(mWidth, 32), yStride_align);
56         }
57         else
58         {
59             yStride = align_to(align_to(mWidth, 32), 64);
60         }
61         uvStride = align_to(yStride >> 1, 64);
62         mStride.yuv.yStride = yStride;
63         mStride.yuv.uvStride = uvStride;
64         break;
65     case HAL_PIXEL_FORMAT_NV12:
66         yStride = align_to(align_to(mWidth, 32), 64);
67         uvStride = yStride;
68         mStride.yuv.yStride = yStride;
69         mStride.yuv.uvStride = uvStride;
70         break;
71     case OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar:
72     case OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar_Tiled:
73         yStride = align_to(align_to(mWidth, 32), 64);
74         uvStride = yStride;
75         mStride.yuv.yStride = yStride;
76         mStride.yuv.uvStride = uvStride;
77         break;
78     case HAL_PIXEL_FORMAT_YUY2:
79     case HAL_PIXEL_FORMAT_UYVY:
80         yStride = align_to((align_to(mWidth, 32) << 1), 64);
81         uvStride = 0;
82         mStride.yuv.yStride = yStride;
83         mStride.yuv.uvStride = uvStride;
84         break;
85     default:
86         mStride.rgb.stride = align_to(((mBpp >> 3) * align_to(mWidth, 32)), 64);
87         break;
88     }
89 }
90 
91 }
92 }
93