SimpleKernel  0.0.1
Graphics Class Reference

#include <load_elf.h>

Collaboration diagram for Graphics:
Collaboration graph

Public Member Functions

 Graphics ()
 
 ~Graphics ()=default
 
void set_mode (EFI_GRAPHICS_PIXEL_FORMAT _format=PixelBlueGreenRedReserved8BitPerColor, uint32_t _width=DEFAULT_WIDTH, uint32_t _height=DEFAULT_HEIGHT) const
 
void print_info () const
 
不使用的构造函数
 Graphics (const Graphics &)=delete
 
 Graphics (Graphics &&)=delete
 
auto operator= (const Graphics &) -> Graphics &=delete
 
auto operator= (Graphics &&) -> Graphics &=delete
 

Private Attributes

EFI_GRAPHICS_OUTPUT_PROTOCOL * gop = nullptr
 

Static Private Attributes

默认分辨率
static constexpr const uint32_t DEFAULT_WIDTH = 1920
 
static constexpr const uint32_t DEFAULT_HEIGHT = 1080
 

Detailed Description

图形相关

Definition at line 39 of file load_elf.h.

Constructor & Destructor Documentation

◆ Graphics() [1/3]

Graphics::Graphics ( )

构造函数

Definition at line 22 of file graphics.cpp.

22  {
23  auto status = LibLocateProtocol(&GraphicsOutputProtocol,
24  reinterpret_cast<void **>(&gop));
25  if (EFI_ERROR(status)) {
26  debug << L"Could not locate GOP: " << status << ostream::endl;
27  throw std::runtime_error("EFI_ERROR(status)");
28  }
29  if (gop == nullptr) {
30  debug << L"LibLocateProtocol(GraphicsOutputProtocol, &gop) returned "
31  << status << " but gop is nullptr" << ostream::endl;
32 
33  throw std::runtime_error("gop == nullptr");
34  }
35 }
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop
Definition: load_elf.h:81
static auto endl(ostream &_ostream) -> ostream &
Definition: ostream.cpp:42
static ostream debug
全局输出流
Definition: ostream.hpp:194
Here is the call graph for this function:

◆ ~Graphics()

Graphics::~Graphics ( )
default

析构函数

◆ Graphics() [2/3]

Graphics::Graphics ( const Graphics )
delete

◆ Graphics() [3/3]

Graphics::Graphics ( Graphics &&  )
delete

Member Function Documentation

◆ operator=() [1/2]

auto Graphics::operator= ( const Graphics ) -> Graphics &=delete
delete

◆ operator=() [2/2]

auto Graphics::operator= ( Graphics &&  ) -> Graphics &=delete
delete

◆ print_info()

void Graphics::print_info ( ) const

输出图形信息

Definition at line 78 of file graphics.cpp.

78  {
79  debug << L"Current Mode: " << gop->Mode->Mode << L", Version: "
80  << ostream::hex_x << gop->Mode->Info->Version << L", Format: "
81  << gop->Mode->Info->PixelFormat << L", Horizontal: "
82  << gop->Mode->Info->HorizontalResolution << L", Vertical: "
83  << gop->Mode->Info->VerticalResolution << L", ScanLine: "
84  << gop->Mode->Info->PixelsPerScanLine << L", FrameBufferBase: "
85  << ostream::hex_X << gop->Mode->FrameBufferBase
86  << L", FrameBufferSize: " << ostream::hex_X
87  << gop->Mode->FrameBufferSize << ostream::endl;
88 
89  for (uint32_t i = 0; i < gop->Mode->MaxMode; i++) {
90  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info = nullptr;
91  uint64_t mode_info_size = 0;
92  auto status = uefi_call_wrapper(gop->QueryMode, 4, gop, i, &mode_info_size,
93  &mode_info);
94  if (EFI_ERROR(status)) {
95  debug << L"QueryMode failed: " << status << ostream::endl;
96  throw std::runtime_error("EFI_ERROR(status)");
97  }
98 
99  debug << L"Mode: " << i << L", Version: " << ostream::hex_x
100  << gop->Mode->Info->Version << L", Format: "
101  << gop->Mode->Info->PixelFormat << L", Horizontal: "
102  << gop->Mode->Info->HorizontalResolution << L", Vertical: "
103  << gop->Mode->Info->VerticalResolution << L", ScanLine: "
104  << gop->Mode->Info->PixelsPerScanLine << ostream::endl;
105 
106  status = uefi_call_wrapper(gBS->FreePool, 1, mode_info);
107  if (EFI_ERROR(status)) {
108  debug << L"FreePool failed: " << status << ostream::endl;
109  throw std::runtime_error("EFI_ERROR(status)");
110  }
111  }
112 }
static auto hex_x(ostream &_ostream) -> ostream &
Definition: ostream.cpp:32
static auto hex_X(ostream &_ostream) -> ostream &
Definition: ostream.cpp:37
Here is the call graph for this function:

◆ set_mode()

void Graphics::set_mode ( EFI_GRAPHICS_PIXEL_FORMAT  _format = PixelBlueGreenRedReserved8BitPerColor,
uint32_t  _width = DEFAULT_WIDTH,
uint32_t  _height = DEFAULT_HEIGHT 
) const

设置图形模式

Parameters
_format图形像素格式,默认为 PixelBlueGreenRedReserved8BitPerColor
_width宽度,默认为 1920
_height高度,默认为 1080

Definition at line 37 of file graphics.cpp.

38  {
39  EFI_STATUS status = EFI_SUCCESS;
40 
41  for (uint32_t i = 0; i < gop->Mode->MaxMode; i++) {
42  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info = nullptr;
43  uint64_t mode_info_size = 0;
44  status = uefi_call_wrapper(gop->QueryMode, 4, gop, i, &mode_info_size,
45  &mode_info);
46  if (EFI_ERROR(status)) {
47  debug << L"QueryMode failed: " << status << ostream::endl;
48  throw std::runtime_error("EFI_ERROR(status)");
49  }
50 
51  if ((mode_info->PixelFormat == _format) &&
52  (mode_info->HorizontalResolution == _width) &&
53  (mode_info->VerticalResolution == _height)) {
54  status = uefi_call_wrapper(gop->SetMode, 2, gop, i);
55  if (EFI_ERROR(status)) {
56  debug << L"SetMode failed: " << status << ostream::endl;
57  throw std::runtime_error("EFI_ERROR(status)");
58  }
59  }
60  status = uefi_call_wrapper(gBS->FreePool, 1, mode_info);
61  if (EFI_ERROR(status)) {
62  debug << L"FreePool failed: " << status << ostream::endl;
63  throw std::runtime_error("EFI_ERROR(status)");
64  }
65  }
66 
67  debug << L"Current Mode: " << gop->Mode->Mode << L", Version: "
68  << ostream::hex_x << gop->Mode->Info->Version << L", Format: "
69  << gop->Mode->Info->PixelFormat << L", Horizontal: "
70  << gop->Mode->Info->HorizontalResolution << L", Vertical: "
71  << gop->Mode->Info->VerticalResolution << L", ScanLine: "
72  << gop->Mode->Info->PixelsPerScanLine << L", FrameBufferBase: "
73  << ostream::hex_X << gop->Mode->FrameBufferBase
74  << L", FrameBufferSize: " << ostream::hex_X
75  << gop->Mode->FrameBufferSize << ostream::endl;
76 }
Here is the call graph for this function:

Member Data Documentation

◆ DEFAULT_HEIGHT

constexpr const uint32_t Graphics::DEFAULT_HEIGHT = 1080
staticconstexprprivate

Definition at line 78 of file load_elf.h.

◆ DEFAULT_WIDTH

constexpr const uint32_t Graphics::DEFAULT_WIDTH = 1920
staticconstexprprivate

Definition at line 77 of file load_elf.h.

◆ gop

EFI_GRAPHICS_OUTPUT_PROTOCOL* Graphics::gop = nullptr
private

图形输出协议

Definition at line 81 of file load_elf.h.


The documentation for this class was generated from the following files: