1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "drm_encoder.h"
17
18 namespace OHOS {
19 namespace HDI {
20 namespace DISPLAY {
DrmEncoder(drmModeEncoder e)21 DrmEncoder::DrmEncoder(drmModeEncoder e)
22 {
23 mEncoderId = e.encoder_id;
24 mCrtcId = e.crtc_id;
25 mPossibleCrtcs = e.possible_crtcs;
26 }
27
PickIdleCrtcId(IdMapPtr<DrmCrtc> & crtcs,uint32_t & crtcId)28 int32_t DrmEncoder::PickIdleCrtcId(IdMapPtr<DrmCrtc> &crtcs, uint32_t &crtcId)
29 {
30 // find the crtc id;
31 DISPLAY_DEBUGLOG("crtcs szie %{public}zu", crtcs.size());
32 std::shared_ptr<DrmCrtc> crtc;
33 auto crtcIter = crtcs.find(mCrtcId);
34 if (crtcIter == crtcs.end()) {
35 DISPLAY_LOGW("can not find crtc for id %{public}d", mCrtcId);
36 crtcIter = crtcs.begin();
37 return DISPLAY_FAILURE;
38 }
39 DISPLAY_CHK_RETURN((crtcIter == crtcs.end()), DISPLAY_FAILURE,
40 DISPLAY_LOGE("have no crtc %{public}zu ", crtcs.size()));
41 crtc = crtcIter->second;
42 DISPLAY_CHK_RETURN((crtc == nullptr), DISPLAY_FAILURE, DISPLAY_LOGE("crtc is null"));
43
44 if (!crtc->CanBind()) {
45 crtc = nullptr;
46 for (const auto &posCrtcPair : crtcs) {
47 auto &posCrts = posCrtcPair.second;
48 DISPLAY_DEBUGLOG("try crtc id : %{public}d", posCrts->GetId());
49 if (posCrts->CanBind() && ((1 << posCrts->GetPipe()) & mPossibleCrtcs)) {
50 crtc = posCrts;
51 }
52 }
53 }
54 DISPLAY_CHK_RETURN((crtc == nullptr), DISPLAY_FAILURE,
55 DISPLAY_LOGE("encoder %{public}d can not bind to idle crtc", mEncoderId));
56 crtcId = crtc->GetId();
57 return DISPLAY_SUCCESS;
58 }
59 } // namespace OHOS
60 } // namespace HDI
61 } // namespace DISPLAY
62