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