1fb299fa2Sopenharmony_ci/* 2fb299fa2Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3fb299fa2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb299fa2Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb299fa2Sopenharmony_ci * You may obtain a copy of the License at 6fb299fa2Sopenharmony_ci * 7fb299fa2Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb299fa2Sopenharmony_ci * 9fb299fa2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb299fa2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb299fa2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb299fa2Sopenharmony_ci * See the License for the specific language governing permissions and 13fb299fa2Sopenharmony_ci * limitations under the License. 14fb299fa2Sopenharmony_ci */ 15fb299fa2Sopenharmony_ci#include "surface_dev.h" 16fb299fa2Sopenharmony_ci#include <unistd.h> 17fb299fa2Sopenharmony_ci#include "drm_driver.h" 18fb299fa2Sopenharmony_ci#include "fbdev_driver.h" 19fb299fa2Sopenharmony_ci#include "log/log.h" 20fb299fa2Sopenharmony_ci#include "updater_ui_const.h" 21fb299fa2Sopenharmony_ci 22fb299fa2Sopenharmony_cinamespace Updater { 23fb299fa2Sopenharmony_cistd::vector<std::string> SurfaceDev::fbDeviceList_ {FB_DEV_PATH}; 24fb299fa2Sopenharmony_ci 25fb299fa2Sopenharmony_cistd::unique_ptr<GraphicDrv> SurfaceDev::MakeDevDrv(DevType devType) 26fb299fa2Sopenharmony_ci{ 27fb299fa2Sopenharmony_ci std::unique_ptr<GraphicDrv> drv = nullptr; 28fb299fa2Sopenharmony_ci switch (devType) { 29fb299fa2Sopenharmony_ci case DevType::DRM_DEVICE: 30fb299fa2Sopenharmony_ci drv = std::make_unique<DrmDriver>(); 31fb299fa2Sopenharmony_ci break; 32fb299fa2Sopenharmony_ci case DevType::FB_DEVICE: 33fb299fa2Sopenharmony_ci drv = std::make_unique<FbdevDriver>(); 34fb299fa2Sopenharmony_ci break; 35fb299fa2Sopenharmony_ci default: 36fb299fa2Sopenharmony_ci LOG(ERROR) << " not Support."; 37fb299fa2Sopenharmony_ci break; 38fb299fa2Sopenharmony_ci } 39fb299fa2Sopenharmony_ci return drv; 40fb299fa2Sopenharmony_ci} 41fb299fa2Sopenharmony_ci 42fb299fa2Sopenharmony_civoid SurfaceDev::Flip(const uint8_t *buf) const 43fb299fa2Sopenharmony_ci{ 44fb299fa2Sopenharmony_ci if (buf == nullptr) { 45fb299fa2Sopenharmony_ci LOG(ERROR) << "buf is null"; 46fb299fa2Sopenharmony_ci return; 47fb299fa2Sopenharmony_ci } 48fb299fa2Sopenharmony_ci if (drv_ != nullptr) { 49fb299fa2Sopenharmony_ci drv_->Flip(buf); 50fb299fa2Sopenharmony_ci } 51fb299fa2Sopenharmony_ci} 52fb299fa2Sopenharmony_ci 53fb299fa2Sopenharmony_ciDevType SurfaceDev::GetDevType() const 54fb299fa2Sopenharmony_ci{ 55fb299fa2Sopenharmony_ci bool isFbDevice = std::find_if(fbDeviceList_.begin(), fbDeviceList_.end(), [] (auto &devicePath) { 56fb299fa2Sopenharmony_ci if (access(devicePath.c_str(), 0) != 0) { 57fb299fa2Sopenharmony_ci LOG(WARNING) << devicePath << " not existed"; 58fb299fa2Sopenharmony_ci return false; 59fb299fa2Sopenharmony_ci } 60fb299fa2Sopenharmony_ci return true; 61fb299fa2Sopenharmony_ci }) != fbDeviceList_.end(); 62fb299fa2Sopenharmony_ci if (access(DRM_DEV_PATH, 0) == 0) { 63fb299fa2Sopenharmony_ci return DevType::DRM_DEVICE; 64fb299fa2Sopenharmony_ci } else if (isFbDevice) { 65fb299fa2Sopenharmony_ci return DevType::FB_DEVICE; 66fb299fa2Sopenharmony_ci } 67fb299fa2Sopenharmony_ci return DevType::UNKNOW_DEVICE; 68fb299fa2Sopenharmony_ci} 69fb299fa2Sopenharmony_ci 70fb299fa2Sopenharmony_cibool SurfaceDev::Init() 71fb299fa2Sopenharmony_ci{ 72fb299fa2Sopenharmony_ci drv_ = MakeDevDrv(GetDevType()); 73fb299fa2Sopenharmony_ci if (drv_ != nullptr) { 74fb299fa2Sopenharmony_ci return drv_->Init(); 75fb299fa2Sopenharmony_ci } 76fb299fa2Sopenharmony_ci return false; 77fb299fa2Sopenharmony_ci} 78fb299fa2Sopenharmony_ci 79fb299fa2Sopenharmony_civoid SurfaceDev::Blank(bool blank) 80fb299fa2Sopenharmony_ci{ 81fb299fa2Sopenharmony_ci if (drv_ != nullptr) { 82fb299fa2Sopenharmony_ci drv_->Blank(blank); 83fb299fa2Sopenharmony_ci } 84fb299fa2Sopenharmony_ci} 85fb299fa2Sopenharmony_ci 86fb299fa2Sopenharmony_civoid SurfaceDev::Exit(void) 87fb299fa2Sopenharmony_ci{ 88fb299fa2Sopenharmony_ci if (drv_ != nullptr) { 89fb299fa2Sopenharmony_ci drv_->Exit(); 90fb299fa2Sopenharmony_ci } 91fb299fa2Sopenharmony_ci} 92fb299fa2Sopenharmony_ci 93fb299fa2Sopenharmony_civoid SurfaceDev::AddFbDevice(const std::string &devicePath) 94fb299fa2Sopenharmony_ci{ 95fb299fa2Sopenharmony_ci fbDeviceList_.push_back(devicePath); 96fb299fa2Sopenharmony_ci} 97fb299fa2Sopenharmony_ci 98fb299fa2Sopenharmony_civoid SurfaceDev::GetScreenSize(uint16_t &w, uint16_t &h, GrSurface &surface) const 99fb299fa2Sopenharmony_ci{ 100fb299fa2Sopenharmony_ci if (drv_ != nullptr) { 101fb299fa2Sopenharmony_ci drv_->GetGrSurface(surface); 102fb299fa2Sopenharmony_ci } 103fb299fa2Sopenharmony_ci w = surface.width; 104fb299fa2Sopenharmony_ci h = surface.height; 105fb299fa2Sopenharmony_ci LOG(INFO) << "weight=" << w << " " << "height=" << h; 106fb299fa2Sopenharmony_ci} 107fb299fa2Sopenharmony_ci 108fb299fa2Sopenharmony_ciSurfaceDev::~SurfaceDev() 109fb299fa2Sopenharmony_ci{ 110fb299fa2Sopenharmony_ci LOG(INFO) << "SurfaceDev end"; 111fb299fa2Sopenharmony_ci} 112fb299fa2Sopenharmony_ci} // namespace Updater 113