blob: 6de65002f31dc2e72a8c4dceb3ee6f24603a202f [file] [log] [blame]
Sean Paul80b1a5d2016-03-10 15:35:13 -05001/*
2 * Copyright (C) 2016 The Android Open Source Project
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#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18#define LOG_TAG "hwc-drm-utils"
19
John Stultz9057a6f2018-04-26 12:05:55 -070020#include <log/log.h>
Roman Stratiienkoadd24cb2020-10-23 22:28:38 +030021#include <ui/Gralloc.h>
Andrii Chepurnyidc1278c2018-03-20 19:41:18 +020022#include <ui/GraphicBufferMapper.h>
Sean Paul80b1a5d2016-03-10 15:35:13 -050023
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030024#include "bufferinfo/BufferInfoGetter.h"
Roman Stratiienko8666dc92021-02-09 17:49:55 +020025#include "drm/DrmFbImporter.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030026#include "drmhwcomposer.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030027
John Stultzfb3599c2018-08-21 11:21:56 -070028#define UNUSED(x) (void)(x)
29
Sean Paul80b1a5d2016-03-10 15:35:13 -050030namespace android {
31
Roman Stratiienko51287152021-02-10 14:59:52 +020032int DrmHwcLayer::ImportBuffer(DrmDevice *drmDevice) {
33 buffer_info = hwc_drm_bo_t{};
Sean Paul80b1a5d2016-03-10 15:35:13 -050034
Roman Stratiienko51287152021-02-10 14:59:52 +020035 int ret = BufferInfoGetter::GetInstance()->ConvertBoInfo(sf_handle,
36 &buffer_info);
Jason Macnakf2e03b72020-11-02 07:04:11 -080037 if (ret) {
38 ALOGE("Failed to convert buffer info %d", ret);
Sean Paul80b1a5d2016-03-10 15:35:13 -050039 return ret;
Jason Macnakf2e03b72020-11-02 07:04:11 -080040 }
41
Roman Stratiienko51287152021-02-10 14:59:52 +020042 FbIdHandle = drmDevice->GetDrmFbImporter().GetOrCreateFbId(&buffer_info);
Roman Stratiienko8666dc92021-02-09 17:49:55 +020043 if (!FbIdHandle) {
44 ALOGE("Failed to import buffer");
45 return -EINVAL;
Jason Macnakf2e03b72020-11-02 07:04:11 -080046 }
Sean Paul80b1a5d2016-03-10 15:35:13 -050047
Sean Paul80b1a5d2016-03-10 15:35:13 -050048 return 0;
49}
50
Sean Paul80b1a5d2016-03-10 15:35:13 -050051void DrmHwcLayer::SetTransform(int32_t sf_transform) {
52 transform = 0;
53 // 270* and 180* cannot be combined with flips. More specifically, they
54 // already contain both horizontal and vertical flips, so those fields are
55 // redundant in this case. 90* rotation can be combined with either horizontal
56 // flip or vertical flip, so treat it differently
57 if (sf_transform == HWC_TRANSFORM_ROT_270) {
58 transform = DrmHwcTransform::kRotate270;
59 } else if (sf_transform == HWC_TRANSFORM_ROT_180) {
60 transform = DrmHwcTransform::kRotate180;
61 } else {
62 if (sf_transform & HWC_TRANSFORM_FLIP_H)
63 transform |= DrmHwcTransform::kFlipH;
64 if (sf_transform & HWC_TRANSFORM_FLIP_V)
65 transform |= DrmHwcTransform::kFlipV;
66 if (sf_transform & HWC_TRANSFORM_ROT_90)
67 transform |= DrmHwcTransform::kRotate90;
68 }
69}
Sean Paulf72cccd2018-08-27 13:59:08 -040070} // namespace android