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_INTEL_YV12:
51 case HAL_PIXEL_FORMAT_I420:
52 uint32_t yStride_align;
53 yStride_align = DisplayQuery::getOverlayLumaStrideAlignment(mFormat);
54 if (yStride_align > 0)
55 {
56 yStride = align_to(align_to(mWidth, 32), yStride_align);
57 }
58 else
59 {
60 yStride = align_to(align_to(mWidth, 32), 64);
61 }
62 uvStride = align_to(yStride >> 1, 64);
63 mStride.yuv.yStride = yStride;
64 mStride.yuv.uvStride = uvStride;
65 break;
66 case HAL_PIXEL_FORMAT_NV12:
67 yStride = align_to(align_to(mWidth, 32), 64);
68 uvStride = yStride;
69 mStride.yuv.yStride = yStride;
70 mStride.yuv.uvStride = uvStride;
71 break;
72 case OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar:
73 case OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar_Tiled:
74 yStride = align_to(align_to(mWidth, 32), 64);
75 uvStride = yStride;
76 mStride.yuv.yStride = yStride;
77 mStride.yuv.uvStride = uvStride;
78 break;
79 case HAL_PIXEL_FORMAT_YUY2:
80 case HAL_PIXEL_FORMAT_UYVY:
81 yStride = align_to((align_to(mWidth, 32) << 1), 64);
82 uvStride = 0;
83 mStride.yuv.yStride = yStride;
84 mStride.yuv.uvStride = uvStride;
85 break;
86 default:
87 mStride.rgb.stride = align_to(((mBpp >> 3) * align_to(mWidth, 32)), 64);
88 break;
89 }
90 }
91
92 }
93 }
94