opuntiaOS - an operating system targeting x86 and ARMv7
at master 1.5 kB view raw
1/* 2 * Copyright (C) 2020-2022 The opuntiaOS Project Authors. 3 * + Contributed by Nikita Melekhin <nimelehin@gmail.com> 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9#include "Screen.h" 10#include "../Managers/Compositor.h" 11#include <cstring> 12#include <fcntl.h> 13#include <sys/ioctl.h> 14#include <sys/mman.h> 15#include <utility> 16 17namespace WinServer { 18 19Screen* s_WinServer_Screen_the = nullptr; 20 21Screen::Screen() 22 : m_depth(4) 23 , m_write_bitmap() 24 , m_display_bitmap() 25{ 26 s_WinServer_Screen_the = this; 27 m_screen_fd = open("/dev/bga", O_RDWR); 28 m_bounds = LG::Rect(0, 0, ioctl(m_screen_fd, BGA_GET_WIDTH, 0), ioctl(m_screen_fd, BGA_GET_HEIGHT, 0)); 29 30 size_t screen_buffer_size = width() * height() * depth(); 31 auto* first_buffer = reinterpret_cast<LG::Color*>(mmap(NULL, 1, PROT_READ | PROT_WRITE, MAP_SHARED, m_screen_fd, 0)); 32 auto* second_buffer = reinterpret_cast<LG::Color*>(reinterpret_cast<uint8_t*>(first_buffer) + screen_buffer_size); 33 34 m_display_bitmap = LG::PixelBitmap(first_buffer, width(), height()); 35 m_write_bitmap = LG::PixelBitmap(second_buffer, width(), height()); 36 37 m_display_bitmap_ptr = &m_display_bitmap; 38 m_write_bitmap_ptr = &m_write_bitmap; 39 40 m_active_buffer = 0; 41} 42 43void Screen::swap_buffers() 44{ 45 m_write_bitmap_ptr.swap(m_display_bitmap_ptr); 46 m_active_buffer ^= 1; 47 ioctl(m_screen_fd, BGA_SWAP_BUFFERS, m_active_buffer); 48} 49 50} // namespace WinServer