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 #ifndef FRAMEBUFFER_ALLOCATOR_H 19 #define FRAMEBUFFER_ALLOCATOR_H 20 #include <queue> 21 #include <linux/fb.h> 22 #include "allocator.h" 23 namespace OHOS { 24 namespace HDI { 25 namespace DISPLAY { 26 class FramebufferAllocator : public Allocator { 27 public: 28 int32_t Init() override; 29 int32_t Allocate(const BufferInfo &bufferInfo, BufferHandle &handle) override; 30 void* Mmap(BufferHandle &handle) override; 31 int32_t Unmap(BufferHandle &handle) override; 32 int32_t FreeMem(BufferHandle *handle) override; 33 ~FramebufferAllocator() override; 34 private: 35 static constexpr uint32_t FB_BUFFERS_NUM = 3; 36 static constexpr const char *FBDEV_PATH = "/dev/graphics/fb0"; 37 38 int32_t SetFdFormatAndVirtualRes(struct fb_var_screeninfo varInfo); 39 int32_t InitFb(); 40 int32_t GetDmaBuffer(); 41 42 struct fb_fix_screeninfo fixInfo_; 43 struct fb_var_screeninfo varInfo_; 44 // framebuffer information 45 uint32_t bufferSize_ = 0; 46 uint32_t buffersNum_ = 0; 47 uint32_t frameBufferSize_ = 0; 48 unsigned long smemStart_ = 0; 49 int32_t dmaBufferFb_ = -1; 50 int32_t deviceFd_ = -1; 51 std::queue<unsigned long> freeBuffers_; 52 }; 53 } 54 } 55 } 56 #endif // FRAMEBUFFER_ALLOCATOR_H