summaryrefslogtreecommitdiff
path: root/libhwc2.1/libresource/ExynosMPPModule.cpp
blob: 9096a1ee4a1affed20be0b506fa26758b0267c28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "ExynosMPPModule.h"
#include "ExynosHWCDebug.h"
#include "ExynosResourceManager.h"

ExynosMPPModule::ExynosMPPModule(ExynosResourceManager* resourceManager,
        uint32_t physicalType, uint32_t logicalType, const char *name,
        uint32_t physicalIndex, uint32_t logicalIndex, uint32_t preAssignInfo)
    : ExynosMPP(resourceManager, physicalType, logicalType, name, physicalIndex, logicalIndex, preAssignInfo),
    mChipId(0x00)
{
}

ExynosMPPModule::~ExynosMPPModule()
{
}

uint32_t ExynosMPPModule::getSrcXOffsetAlign(struct exynos_image &src)
{
    uint32_t idx = getRestrictionClassification(src);
    return mSrcSizeRestrictions[idx].cropXAlign;
}

bool ExynosMPPModule::isSupportedCompression(struct exynos_image &src)
{
    if (src.compressed) {
        if (mPhysicalType == MPP_G2D)
            return true;

        ExynosMPP *sharedMPP = NULL;
        if (mPhysicalType == MPP_DPP_GF) {
            if (mPhysicalIndex == 0) {
                /* GF1 shares memory with VGF0 */
                sharedMPP = mResourceManager->getExynosMPP(MPP_DPP_VGF, 0);
            } else if (mPhysicalIndex == 1) {
                /* GF0 shares memory with VGRFS0 */
                sharedMPP = mResourceManager->getExynosMPP(MPP_DPP_VGRFS, 0);
            } else {
                MPP_LOGE("Invalid MPP_DPP_GF index(%d)", mPhysicalIndex);
                return false;
            }
        } else if (mPhysicalType == MPP_DPP_VGF) {
            /* GF1 shares memory with VGF0 */
            sharedMPP = mResourceManager->getExynosMPP(MPP_DPP_GF, 0);
        } else if (mPhysicalType == MPP_DPP_VGRFS) {
            /* GF0 shares memory with VGRFS0 */
            sharedMPP = mResourceManager->getExynosMPP(MPP_DPP_GF, 1);
        } else {
            /* Other mpp don't support decompression */
            return false;
        }

        if (sharedMPP == NULL) {
            MPP_LOGE("sharedMPP is NULL");
            return false;
        }

        if ((sharedMPP->mAssignedState & MPP_ASSIGN_STATE_ASSIGNED) == 0)
            return true;
        else {
            if (sharedMPP->mAssignedSources.size() == 1) {
                exynos_image checkImg = sharedMPP->mAssignedSources[0]->mSrcImg;
                if ((sharedMPP->mAssignedSources[0]->mSourceType == MPP_SOURCE_COMPOSITION_TARGET) ||
                    (sharedMPP->mAssignedSources[0]->mM2mMPP != NULL)) {
                    checkImg = sharedMPP->mAssignedSources[0]->mMidImg;
                }
                if (checkImg.transform & HAL_TRANSFORM_ROT_90)
                    return false;

                if (checkImg.compressed == 0)
                    return true;

                if (checkImg.w > 2048)
                    return false;
                else {
                    if (src.w < 2048)
                        return true;
                    else
                        return false;
                }
            } else {
                MPP_LOGE("Invalid sharedMPP[%d, %d] mAssignedSources size(%zu)",
                        sharedMPP->mPhysicalType,
                        sharedMPP->mPhysicalIndex,
                        sharedMPP->mAssignedSources.size());
            }
        }
        return false;
    } else {
        return true;
    }
}

bool ExynosMPPModule::isSupportedTransform(struct exynos_image &src)
{
    ExynosMPP *sharedMPP = NULL;
    switch (mPhysicalType)
    {
    case MPP_G2D:
        return true;
    case MPP_DPP_G:
    case MPP_DPP_GF:
    case MPP_DPP_VG:
    case MPP_DPP_VGS:
    case MPP_DPP_VGF:
    case MPP_DPP_VGFS:
        if ((src.transform & HAL_TRANSFORM_ROT_90) == 0)
        {
            if ((src.compressed == 1) && (src.transform != 0))
                return false;
            return true;
        } else {
            return false;
        }
    case MPP_DPP_VGRFS:
        if (isFormatYUV420(src.format)) {
            /* HACK */
            if ((src.transform != 0) && isFormat10BitYUV420(src.format)) return false;

            /* GF0 shares memory with VGRFS0 */
            sharedMPP = mResourceManager->getExynosMPP(MPP_DPP_GF, 1);
            if (sharedMPP == NULL) {
                MPP_LOGE("sharedMPP is NULL");
                return false;
            }

            if ((src.transform & HAL_TRANSFORM_ROT_90) &&
                (sharedMPP->mAssignedState & MPP_ASSIGN_STATE_ASSIGNED)) {
                if (sharedMPP->mAssignedSources.size() != 1) {
                    MPP_LOGE("Invalid sharedMPP[%d, %d] mAssignedSources size(%zu)",
                            sharedMPP->mPhysicalType,
                            sharedMPP->mPhysicalIndex,
                            sharedMPP->mAssignedSources.size());
                    return false;
                }
                exynos_image checkImg = sharedMPP->mAssignedSources[0]->mSrcImg;
                if ((sharedMPP->mAssignedSources[0]->mSourceType == MPP_SOURCE_COMPOSITION_TARGET) ||
                    (sharedMPP->mAssignedSources[0]->mM2mMPP != NULL)) {
                    checkImg = sharedMPP->mAssignedSources[0]->mMidImg;
                }
                if (checkImg.compressed == 1)
                    return false;
                }
            return true;
        }
        /* RGB case */
        if ((src.transform & HAL_TRANSFORM_ROT_90) == 0)
        {
            if ((src.compressed == 1) && (src.transform != 0))
                return false;
            return true;
        } else {
            return false;
        }
    default:
            return true;
    }
}

uint32_t ExynosMPPModule::getSrcMaxCropSize(struct exynos_image &src)
{
    if ((mPhysicalType == MPP_DPP_VGRFS) &&
        (src.transform & HAL_TRANSFORM_ROT_90))
        return MAX_DPP_ROT_SRC_SIZE;
    else
        return ExynosMPP::getSrcMaxCropSize(src);
}