summaryrefslogtreecommitdiff
path: root/contrib/SDL-3.2.8/src/video/haiku/SDL_bframebuffer.cc
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-12-27 12:03:39 -0800
committer3gg <3gg@shellblade.net>2025-12-27 12:03:39 -0800
commit5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch)
tree8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/src/video/haiku/SDL_bframebuffer.cc
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/haiku/SDL_bframebuffer.cc')
-rw-r--r--contrib/SDL-3.2.8/src/video/haiku/SDL_bframebuffer.cc128
1 files changed, 128 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/haiku/SDL_bframebuffer.cc b/contrib/SDL-3.2.8/src/video/haiku/SDL_bframebuffer.cc
new file mode 100644
index 0000000..d152255
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/haiku/SDL_bframebuffer.cc
@@ -0,0 +1,128 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21#include "SDL_internal.h"
22
23#ifdef SDL_VIDEO_DRIVER_HAIKU
24
25#include "SDL_bframebuffer.h"
26
27#include <AppKit.h>
28#include <InterfaceKit.h>
29#include "SDL_bmodes.h"
30#include "SDL_BWin.h"
31
32#include "../../core/haiku/SDL_BApp.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window)
39{
40 return (SDL_BWin *)(window->internal);
41}
42
43static SDL_INLINE SDL_BLooper *_GetBeLooper()
44{
45 return SDL_Looper;
46}
47
48bool HAIKU_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window, SDL_PixelFormat * format, void ** pixels, int *pitch)
49{
50 SDL_BWin *bwin = _ToBeWin(window);
51 BScreen bscreen;
52 if (!bscreen.IsValid()) {
53 return false;
54 }
55
56 // Make sure we have exclusive access to frame buffer data
57 bwin->LockBuffer();
58
59 bwin->CreateView();
60
61 // format
62 display_mode bmode;
63 bscreen.GetMode(&bmode);
64 *format = HAIKU_ColorSpaceToSDLPxFormat(bmode.space);
65
66 // Create the new bitmap object
67 BBitmap *bitmap = bwin->GetBitmap();
68
69 if (bitmap) {
70 delete bitmap;
71 }
72 bitmap = new BBitmap(bwin->Bounds(), (color_space)bmode.space,
73 false, // Views not accepted
74 true); // Contiguous memory required
75
76 if (bitmap->InitCheck() != B_OK) {
77 delete bitmap;
78 return SDL_SetError("Could not initialize back buffer!");
79 }
80
81
82 bwin->SetBitmap(bitmap);
83
84 // Set the pixel pointer
85 *pixels = bitmap->Bits();
86
87 // pitch = width of window, in bytes
88 *pitch = bitmap->BytesPerRow();
89
90 bwin->UnlockBuffer();
91 return true;
92}
93
94
95
96bool HAIKU_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window,
97 const SDL_Rect * rects, int numrects) {
98 if (!window) {
99 return true;
100 }
101
102 SDL_BWin *bwin = _ToBeWin(window);
103
104 bwin->PostMessage(BWIN_UPDATE_FRAMEBUFFER);
105
106 return true;
107}
108
109void HAIKU_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window) {
110 SDL_BWin *bwin = _ToBeWin(window);
111
112 bwin->LockBuffer();
113
114 // Free and clear the window buffer
115 BBitmap *bitmap = bwin->GetBitmap();
116 delete bitmap;
117 bwin->SetBitmap(NULL);
118
119 bwin->RemoveView();
120
121 bwin->UnlockBuffer();
122}
123
124#ifdef __cplusplus
125}
126#endif
127
128#endif // SDL_VIDEO_DRIVER_HAIKU