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