• 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 #include <iremote_proxy.h>
19 #include "display_layer.h"
20 #include "idisplay_layer.h"
21 #include "display_common.h"
22 using namespace OHOS::HDI::Display::V1_0;
23 static OHOS::sptr<IDisplayLayer> g_layerService = nullptr;
24 constexpr const char *DISPLAY_LAYER_SERVICE_NAME = "hdi_video_layer_service";
25 
InitDisplayIfNeed(void)26 static int32_t InitDisplayIfNeed(void)
27 {
28     DISPLAY_LOGD();
29     if (g_layerService == nullptr) {
30         g_layerService = IDisplayLayer::Get(DISPLAY_LAYER_SERVICE_NAME);
31         if (g_layerService == nullptr) {
32             DISPLAY_LOGE("get layer service failed");
33             return DISPLAY_FAILURE;
34         }
35         int32_t ret = g_layerService->InitDisplay(0);
36         if (ret != DISPLAY_SUCCESS) {
37             DISPLAY_LOGE("init display fail, ret=%{public}d",  ret);
38             return DISPLAY_FAILURE;
39         }
40     }
41     return DISPLAY_SUCCESS;
42 }
43 
DeInitDisplay(void)44 static int32_t DeInitDisplay(void)
45 {
46     if (g_layerService != nullptr) {
47         return g_layerService->DeinitDisplay(0);
48     }
49     return DISPLAY_SUCCESS;
50 }
51 
52 
CreateLayer(uint32_t devId,const LayerInfo * layerInfo,uint32_t * layerId)53 static int32_t CreateLayer(uint32_t devId, const LayerInfo *layerInfo, uint32_t *layerId)
54 {
55     DISPLAY_LOGD();
56     DISPLAY_CHK_RETURN((layerInfo == nullptr), DISPLAY_NULL_PTR, DISPLAY_LOGE("layerInfo is nullptr"));
57     DISPLAY_CHK_RETURN((layerId == nullptr), DISPLAY_NULL_PTR, DISPLAY_LOGE("layerId is nullptr"));
58     LayerInfo info = *layerInfo;
59     int32_t ret = InitDisplayIfNeed();
60     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("display init failed"));
61     return g_layerService->CreateLayer(devId, info, *layerId);
62 }
63 
CloseLayer(uint32_t devId,uint32_t layerId)64 static int32_t CloseLayer(uint32_t devId, uint32_t layerId)
65 {
66     DISPLAY_LOGD();
67     g_layerService->CloseLayer(devId, layerId);
68     return DISPLAY_SUCCESS;
69 }
70 
SetLayerSize(uint32_t devId,uint32_t layerId,IRect * rect)71 static int32_t SetLayerSize(uint32_t devId, uint32_t layerId, IRect *rect)
72 {
73     DISPLAY_LOGD();
74     DISPLAY_CHK_RETURN((rect == nullptr), DISPLAY_NULL_PTR, DISPLAY_LOGE("rect is nullptr"));
75     g_layerService->SetLayerRect(devId, layerId, *rect);
76     return DISPLAY_SUCCESS;
77 }
78 
SetLayerCrop(uint32_t devId,uint32_t layerId,IRect * rect)79 static int32_t SetLayerCrop(uint32_t devId, uint32_t layerId, IRect *rect)
80 {
81     DISPLAY_LOGD();
82     return DISPLAY_SUCCESS;
83 }
84 
SetLayerZorder(uint32_t devId,uint32_t layerId,uint32_t zorder)85 static int32_t SetLayerZorder(uint32_t devId, uint32_t layerId, uint32_t zorder)
86 {
87     DISPLAY_LOGD();
88     g_layerService->SetLayerZorder(devId, layerId, zorder);
89     return DISPLAY_SUCCESS;
90 }
91 
SetTransformMode(uint32_t devId,uint32_t layerId,TransformType type)92 static int32_t SetTransformMode(uint32_t devId, uint32_t layerId, TransformType type)
93 {
94     DISPLAY_LOGD();
95     g_layerService->SetTransformMode(devId, layerId, type);
96     return DISPLAY_SUCCESS;
97 }
98 
SetLayerBuffer(uint32_t devId,uint32_t layerId,const BufferHandle * buffer,int32_t fence)99 static int32_t SetLayerBuffer(uint32_t devId, uint32_t layerId, const BufferHandle *buffer, int32_t fence)
100 {
101     DISPLAY_LOGD();
102     DISPLAY_CHK_RETURN((buffer == nullptr), DISPLAY_NULL_PTR, DISPLAY_LOGE("buffer is nullptr"));
103     g_layerService->SetLayerBuffer(devId, layerId, *buffer, fence);
104     return DISPLAY_SUCCESS;
105 }
106 extern "C" {
LayerInitialize(LayerFuncs ** funcs)107 int32_t LayerInitialize(LayerFuncs **funcs)
108 {
109     DISPLAY_LOGD();
110     DISPLAY_CHK_RETURN((funcs == nullptr), DISPLAY_FAILURE, DISPLAY_LOGE("funcs is nullptr"));
111     LayerFuncs *lFunc = (LayerFuncs *)calloc(1, sizeof(LayerFuncs));
112     if (lFunc == nullptr) {
113         DISPLAY_LOGE("can not calloc LayerFuncs");
114         return DISPLAY_FAILURE;
115     }
116     lFunc->CreateLayer = CreateLayer;
117     lFunc->CloseLayer = CloseLayer;
118     lFunc->SetLayerSize = SetLayerSize;
119     lFunc->SetLayerCrop = SetLayerCrop;
120     lFunc->SetLayerZorder = SetLayerZorder;
121     lFunc->SetTransformMode = SetTransformMode;
122     lFunc->SetLayerBuffer = SetLayerBuffer;
123     *funcs = lFunc;
124     DISPLAY_LOGD("LayerInitialize success");
125     return DISPLAY_SUCCESS;
126 }
127 
LayerUninitialize(LayerFuncs * funcs)128 int32_t LayerUninitialize(LayerFuncs *funcs)
129 {
130     DISPLAY_CHK_RETURN((funcs == nullptr), DISPLAY_NULL_PTR, DISPLAY_LOGE("funcs is nullptr"));
131     DISPLAY_LOGD();
132     free(funcs);
133     int32_t ret = DeInitDisplay();
134     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), ret, DISPLAY_LOGE("uninitialize failed"));
135     return DISPLAY_SUCCESS;
136 }
137 }
138