• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #include "surface_dev.h"
16 #include <unistd.h>
17 #include "drm_driver.h"
18 #include "fbdev_driver.h"
19 #include "log/log.h"
20 #include "updater_ui_const.h"
21 
22 namespace Updater {
MakeDevDrv(DevType devType)23 std::unique_ptr<GraphicDrv> SurfaceDev::MakeDevDrv(DevType devType)
24 {
25     std::unique_ptr<GraphicDrv> drv = nullptr;
26     switch (devType) {
27         case DevType::DRM_DEVICE:
28             drv = std::make_unique<DrmDriver>();
29             break;
30         case DevType::FB_DEVICE:
31             drv = std::make_unique<FbdevDriver>();
32             break;
33         default:
34             LOG(ERROR) << " not Support.";
35             break;
36     }
37     return drv;
38 }
39 
Flip(const uint8_t * buf) const40 void SurfaceDev::Flip(const uint8_t *buf) const
41 {
42     if (buf == nullptr) {
43         LOG(ERROR) << "buf is null";
44         return;
45     }
46     if (drv_ != nullptr) {
47         drv_->Flip(buf);
48     }
49 }
50 
GetDevType() const51 DevType SurfaceDev::GetDevType() const
52 {
53     if (access(DRM_DEV_PATH, 0) == 0) {
54         return DevType::DRM_DEVICE;
55     } else if (access(FB_DEV_PATH, 0) == 0) {
56         return DevType::FB_DEVICE;
57     }
58     return DevType::UNKNOW_DEVICE;
59 }
60 
Init()61 bool SurfaceDev::Init()
62 {
63     static bool res = [this] () {
64         drv_ = MakeDevDrv(GetDevType());
65         if (drv_ != nullptr) {
66             return drv_->Init();
67         }
68         return false;
69     } ();
70     return res;
71 }
72 
GetScreenSize(uint16_t & w,uint16_t & h) const73 void SurfaceDev::GetScreenSize(uint16_t &w, uint16_t &h) const
74 {
75     GrSurface surface {0};
76     if (drv_ != nullptr) {
77         drv_->GetGrSurface(surface);
78     }
79     w = surface.width;
80     h = surface.height;
81     LOG(INFO) << "weight=" << w << " " << "height=" << h;
82 }
83 
~SurfaceDev()84 SurfaceDev::~SurfaceDev()
85 {
86     LOG(INFO) << "SurfaceDev end";
87 }
88 } // namespace Updater
89