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