summaryrefslogtreecommitdiffhomepage
path: root/src/modules/CoreGfx/CoreGfx.h
blob: 81d3fc62336f6af1161bbc8ec080c011ced3c118 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* ========================================

  Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.

======================================== */

#ifndef COREGFX_COREGFX_H
#define COREGFX_COREGFX_H

#include <NeKit/Config.h>

#define cg_init() Kernel::UInt32 kCGCursor = 0

#define cg_color(R, G, B) RGB(R, G, B)

#define cg_get_clear_clr() RGB(0, 0, 0x80)

#define cg_clear() kCGCursor = 0UL

#ifdef __NE_AMD64__
/// @brief Performs Alpha drawing on the framebuffer.
#define FBDrawBitMapInRegionA(reg_ptr, height, width, base_x, base_y)                   \
  for (Kernel::UInt32 i = base_x; i < (width + base_x); ++i) {                          \
    for (Kernel::UInt32 u = base_y; u < (height + base_y); ++u) {                       \
      *(((Kernel::UInt32*) (kHandoverHeader->f_GOP.f_The +                              \
                            4 * kHandoverHeader->f_GOP.f_PixelPerLine * i + 4 * u))) |= \
          (reg_ptr)[kCGCursor];                                                         \
                                                                                        \
      ++kCGCursor;                                                                      \
    }                                                                                   \
  }

/// @brief Performs drawing on the framebuffer.
#define FBDrawBitMapInRegion(reg_ptr, height, width, base_x, base_y)                   \
  for (Kernel::UInt32 i = base_x; i < (width + base_x); ++i) {                         \
    for (Kernel::UInt32 u = base_y; u < (height + base_y); ++u) {                      \
      *(((Kernel::UInt32*) (kHandoverHeader->f_GOP.f_The +                             \
                            4 * kHandoverHeader->f_GOP.f_PixelPerLine * i + 4 * u))) = \
          (reg_ptr)[kCGCursor];                                                        \
                                                                                       \
      ++kCGCursor;                                                                     \
    }                                                                                  \
  }

#define FBDrawBitMapInRegionToRgn(_Rgn, reg_ptr, height, width, base_x, base_y)               \
  for (Kernel::UInt32 i = base_x; i < (width + base_x); ++i) {                                \
    for (Kernel::UInt32 u = base_y; u < (height + base_y); ++u) {                             \
      *(((Kernel::UInt32*) (_Rgn + 4 * kHandoverHeader->f_GOP.f_PixelPerLine * i + 4 * u))) = \
          (reg_ptr)[kCGCursor];                                                               \
                                                                                              \
      ++kCGCursor;                                                                            \
    }                                                                                         \
  }

/// @brief Cleans a resource.
#define FBClearRegion(height, width, base_x, base_y)                                            \
  for (Kernel::UInt32 i = base_x; i < (width + base_x); ++i) {                                  \
    for (Kernel::UInt32 u = base_y; u < (height + base_y); ++u) {                               \
      *(((volatile Kernel::UInt32*) (kHandoverHeader->f_GOP.f_The +                             \
                                     4 * kHandoverHeader->f_GOP.f_PixelPerLine * i + 4 * u))) = \
          cg_get_clear_clr();                                                                   \
    }                                                                                           \
  }

/// @brief Draws inside a zone.
#define FBDrawInRegion(clr, height, width, base_x, base_y)                                \
  for (Kernel::UInt32 x_base = base_x; x_base < (width + base_x); ++x_base) {             \
    for (Kernel::UInt32 y_base = base_y; y_base < (height + base_y); ++y_base) {          \
      *(((volatile Kernel::UInt32*) (kHandoverHeader->f_GOP.f_The +                       \
                                     4 * kHandoverHeader->f_GOP.f_PixelPerLine * x_base + \
                                     4 * y_base))) = clr;                                 \
    }                                                                                     \
  }

/// @brief Draws inside a zone.
#define FBDrawInRegionToRgn(_Rgn, clr, height, width, base_x, base_y)                            \
  for (Kernel::UInt32 x_base = base_x; x_base < (width + base_x); ++x_base) {                    \
    for (Kernel::UInt32 y_base = base_y; y_base < (height + base_y); ++y_base) {                 \
      *(((volatile Kernel::UInt32*) (_Rgn + 4 * kHandoverHeader->f_GOP.f_PixelPerLine * x_base + \
                                     4 * y_base))) = clr[kCGCursor];                             \
      ++kCGCursor;                                                                               \
    }                                                                                            \
  }

#define FBDrawInRegionA(clr, height, width, base_x, base_y)                               \
  for (Kernel::UInt32 x_base = base_x; x_base < (width + base_x); ++x_base) {             \
    for (Kernel::UInt32 y_base = base_y; y_base < (height + base_y); ++y_base) {          \
      *(((volatile Kernel::UInt32*) (kHandoverHeader->f_GOP.f_The +                       \
                                     4 * kHandoverHeader->f_GOP.f_PixelPerLine * x_base + \
                                     4 * y_base))) |= clr;                                \
    }                                                                                     \
  }
#else
#define FBDrawBitMapInRegionA(reg_ptr, height, width, base_x, base_y)
#define FBDrawBitMapInRegion(reg_ptr, height, width, base_x, base_y)
#define FBDrawBitMapInRegionToRgn(_Rgn, reg_ptr, height, width, base_x, base_y)
#define FBClearRegion(height, width, base_x, base_y)
#define FBDrawInRegion(clr, height, width, base_x, base_y)
#define FBDrawInRegionToRgn(_Rgn, clr, height, width, base_x, base_y)
#define FBDrawInRegionA(clr, height, width, base_x, base_y)
#define FBDrawBitMapInRegionA(reg_ptr, height, width, base_x, base_y)
#define FBDrawBitMapInRegion(reg_ptr, height, width, base_x, base_y)
#define FBDrawBitMapInRegionToRgn(_Rgn, reg_ptr, height, width, base_x, base_y)
#define FBClearRegion(height, width, base_x, base_y)
#define FBDrawInRegion(clr, height, width, base_x, base_y)
#define FBDrawInRegionToRgn(_Rgn, clr, height, width, base_x, base_y)
#define FBDrawInRegionA(clr, height, width, base_x, base_y)
#endif  // __NE_AMD64__

#ifndef CORE_GFX_ACCESSIBILITY_H
#include <modules/CoreGfx/CoreAccess.h>
#endif  // ifndef CORE_GFX_ACCESSIBILITY_H

namespace FB {
inline Void cg_clear_video() {
  FBDrawInRegion(cg_get_clear_clr(), FB::CGAccessibilty::Height(), FB::CGAccessibilty::Width(), 0,
                 0);
}
}  // namespace FB

#endif