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 "video_window.h" 17 18 #include "window_manager_hilog.h" 19 #include "wl_surface_factory.h" 20 21 #define VIDEO_WINDOW_DEBUG 22 23 #ifndef VIDEO_WINDOW_DEBUG 24 #define VIDEO_WINDOW_ENTER() ((void)0) 25 #define VIDEO_WINDOW_EXIT() ((void)0) 26 #else 27 #define VIDEO_WINDOW_ENTER() do { \ 28 WMLOGFD("enter..."); \ 29 } while (0) 30 31 #define VIDEO_WINDOW_EXIT() do { \ 32 WMLOGFD("exit..."); \ 33 } while (0) 34 #endif 35 36 namespace OHOS { 37 namespace { 38 static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "VideoWindow" }; 39 } 40 VideoWindow(InnerWindowInfo & winInfo)41 VideoWindow::VideoWindow(InnerWindowInfo &winInfo) : SubWindow(winInfo.windowid, winInfo.surf), 42 layerId_(winInfo.voLayerId), surface_(winInfo.surf), producer(nullptr) 43 { 44 VIDEO_WINDOW_ENTER(); 45 #ifdef TARGET_CPU_ARM 46 display = new (std::nothrow) VideoDisplayManager(); 47 #else 48 display = nullptr; 49 #endif 50 if (display == nullptr) { 51 WMLOGFE("new video display manager fail"); 52 } 53 Init(); 54 Move(winInfo.pos_x, winInfo.pos_y); 55 VIDEO_WINDOW_EXIT(); 56 } 57 ~VideoWindow()58 VideoWindow::~VideoWindow() 59 { 60 VIDEO_WINDOW_ENTER(); 61 #ifdef TARGET_CPU_ARM 62 if (display != nullptr) { 63 display->DetachLayer(layerId_); 64 } 65 #endif 66 DestroyLayer(layerId_); 67 VIDEO_WINDOW_EXIT(); 68 } 69 CreateLayer(InnerWindowInfo & winInfo,uint32_t & layerId,sptr<Surface> & surf)70 int32_t VideoWindow::CreateLayer(InnerWindowInfo &winInfo, uint32_t &layerId, sptr<Surface> &surf) 71 { 72 VIDEO_WINDOW_ENTER(); 73 LayerInfo layerInfo = {winInfo.width, winInfo.height, LAYER_TYPE_SDIEBAND, 8, PIXEL_FMT_YCRCB_420_SP}; 74 layerInfo.pixFormat = (PixelFormat)winInfo.windowconfig.format; 75 if (winInfo.windowconfig.type == -1) { 76 layerInfo.type = LAYER_TYPE_OVERLAY; 77 } 78 #ifdef TARGET_CPU_ARM 79 int32_t ret = VideoDisplayManager::CreateLayer(layerInfo, layerId, surf); 80 #else 81 int32_t ret = DISPLAY_FAILURE; 82 #endif 83 VIDEO_WINDOW_EXIT(); 84 return ret; 85 } 86 DestroyLayer(uint32_t layerId)87 void VideoWindow::DestroyLayer(uint32_t layerId) 88 { 89 VIDEO_WINDOW_ENTER(); 90 #ifdef TARGET_CPU_ARM 91 VideoDisplayManager::DestroyLayer(layerId); 92 #endif 93 VIDEO_WINDOW_EXIT(); 94 } 95 Init()96 int32_t VideoWindow::Init() 97 { 98 VIDEO_WINDOW_ENTER(); 99 int32_t ret = DISPLAY_SUCCESS; 100 if (display == nullptr) { 101 WMLOGFE("display layer is not create"); 102 return DISPLAY_FAILURE; 103 } 104 #ifdef TARGET_CPU_ARM 105 producer = display->AttachLayer(surface_, layerId_); 106 if (producer == nullptr) { 107 WMLOGFE("attach layer fail"); 108 ret = DISPLAY_FAILURE; 109 } 110 #endif 111 VIDEO_WINDOW_EXIT(); 112 return ret; 113 } 114 GetSurface()115 sptr<Surface> VideoWindow::GetSurface() 116 { 117 VIDEO_WINDOW_ENTER(); 118 sptr<Surface> surf = Surface::CreateSurfaceAsProducer(producer); 119 VIDEO_WINDOW_EXIT(); 120 return surf; 121 } 122 Move(int32_t x,int32_t y)123 void VideoWindow::Move(int32_t x, int32_t y) 124 { 125 VIDEO_WINDOW_ENTER(); 126 if (display == nullptr) { 127 WMLOGFE("display layer is not create"); 128 return; 129 } 130 131 #ifdef TARGET_CPU_ARM 132 IRect rect = {}; 133 int32_t ret = display->GetRect(layerId_, rect); 134 if (ret != DISPLAY_SUCCESS) { 135 WMLOGFW("get rect fail, ret:%{public}d", ret); 136 return; 137 } 138 139 WMLOGFI("get layer: x=%{public}d, y=%{public}d, w=%{public}d, h=%{public}d", rect.x, rect.y, rect.w, rect.h); 140 constexpr float BAR_WIDTH_PERCENT = 0.07; 141 int maxHeight = LayerControllerClient::GetInstance()->GetMaxHeight(); 142 rect.x = x; 143 rect.y = y + maxHeight * BAR_WIDTH_PERCENT; // status bar 144 WMLOGFI("set layer: x=%{public}d, y=%{public}d, w=%{public}d, h=%{public}d", rect.x, rect.y, rect.w, rect.h); 145 ret = display->SetRect(layerId_, rect); 146 if (ret != DISPLAY_SUCCESS) { 147 WMLOGFW("set rect fail, ret:%{public}d", ret); 148 return; 149 } 150 SubWindow::Move(x, y); 151 #endif 152 VIDEO_WINDOW_EXIT(); 153 } 154 SetSubWindowSize(int32_t width,int32_t height)155 void VideoWindow::SetSubWindowSize(int32_t width, int32_t height) 156 { 157 VIDEO_WINDOW_ENTER(); 158 if (display == nullptr) { 159 WMLOGFE("display layer is not create"); 160 return; 161 } 162 163 #ifdef TARGET_CPU_ARM 164 IRect rect = {}; 165 int32_t ret = display->GetRect(layerId_, rect); 166 if (ret != DISPLAY_SUCCESS) { 167 WMLOGFW("get rect fail, ret:%d", ret); 168 return; 169 } 170 WMLOGFI("get layer: x=%{public}d, y=%{public}d, w=%{public}d, h=%{public}d", rect.x, rect.y, rect.w, rect.h); 171 rect.w = width; 172 rect.h = height; 173 WMLOGFI("set layer: x=%{public}d, y=%{public}d, w=%{public}d, h=%{public}d", rect.x, rect.y, rect.w, rect.h); 174 ret = display->SetRect(layerId_, rect); 175 if (ret != DISPLAY_SUCCESS) { 176 WMLOGFW("set rect fail, ret:%{public}d", ret); 177 return; 178 } 179 SubWindow::SetSubWindowSize(width, height); 180 #endif 181 VIDEO_WINDOW_EXIT(); 182 } 183 ZorderChange(uint32_t layerId,uint32_t zorder)184 int32_t VideoWindow::ZorderChange(uint32_t layerId, uint32_t zorder) 185 { 186 VIDEO_WINDOW_ENTER(); 187 if (display == nullptr) { 188 WMLOGFE("display layer is not create"); 189 return DISPLAY_FAILURE; 190 } 191 #ifdef TARGET_CPU_ARM 192 int32_t ret = display->SetZorder(layerId, zorder); 193 if (ret != DISPLAY_SUCCESS) { 194 WMLOGFW("set zorder fail, ret:%{public}d", ret); 195 } 196 #else 197 int32_t ret = DISPLAY_FAILURE; 198 #endif 199 VIDEO_WINDOW_EXIT(); 200 return ret; 201 } 202 TransformChange(uint32_t layerId,TransformType type)203 int32_t VideoWindow::TransformChange(uint32_t layerId, TransformType type) 204 { 205 VIDEO_WINDOW_ENTER(); 206 if (display == nullptr) { 207 WMLOGFE("display layer is not create"); 208 return DISPLAY_FAILURE; 209 } 210 #ifdef TARGET_CPU_ARM 211 int32_t ret = display->SetTransformMode(layerId, type); 212 if (ret != DISPLAY_SUCCESS) { 213 WMLOGFW("set transform mode fail, ret:%{public}d", ret); 214 } 215 #else 216 int32_t ret = DISPLAY_FAILURE; 217 #endif 218 VIDEO_WINDOW_EXIT(); 219 return ret; 220 } 221 } // namespace OHOS 222