SDL  2.0
SDL_BeApp.cc
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 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 #if defined(__HAIKU__)
24 
25 /* Handle the BeApp specific portions of the application */
26 
27 #include <AppKit.h>
28 #include <storage/AppFileInfo.h>
29 #include <storage/Path.h>
30 #include <storage/Entry.h>
31 #include <storage/File.h>
32 #include <unistd.h>
33 
34 #include "SDL_BApp.h" /* SDL_BApp class definition */
35 #include "SDL_BeApp.h"
36 #include "SDL_timer.h"
37 #include "SDL_error.h"
38 
39 #include "../../video/haiku/SDL_BWin.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 #include "../../thread/SDL_systhread.h"
46 
47 /* Flag to tell whether or not the Be application is active or not */
48 static int SDL_BeAppActive = 0;
49 static SDL_Thread *SDL_AppThread = NULL;
50 
51 /* Default application signature */
52 const char *signature = "application/x-SDL-executable";
53 
54 static int
55 StartBeApp(void *unused)
56 {
57  BApplication *App;
58 
59  // dig resources for correct signature
60  image_info info;
61  int32 cookie = 0;
62  if (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) {
63  BFile f(info.name, O_RDONLY);
64  if (f.InitCheck() == B_OK) {
65  BAppFileInfo app_info(&f);
66  if (app_info.InitCheck() == B_OK) {
67  char sig[B_MIME_TYPE_LENGTH];
68  if (app_info.GetSignature(sig) == B_OK)
69  signature = strndup(sig, B_MIME_TYPE_LENGTH);
70  }
71  }
72  }
73 
74  App = new SDL_BApp(signature);
75 
76  App->Run();
77  delete App;
78  return (0);
79 }
80 
81 /* Initialize the Be Application, if it's not already started */
82 int
83 SDL_InitBeApp(void)
84 {
85  /* Create the BApplication that handles appserver interaction */
86  if (SDL_BeAppActive <= 0) {
87  SDL_AppThread = SDL_CreateThreadInternal(StartBeApp, "SDLApplication", 0, NULL);
88  if (SDL_AppThread == NULL) {
89  return SDL_SetError("Couldn't create BApplication thread");
90  }
91 
92  /* Change working directory to that of executable */
93  app_info info;
94  if (B_OK == be_app->GetAppInfo(&info)) {
95  entry_ref ref = info.ref;
96  BEntry entry;
97  if (B_OK == entry.SetTo(&ref)) {
98  BPath path;
99  if (B_OK == path.SetTo(&entry)) {
100  if (B_OK == path.GetParent(&path)) {
101  chdir(path.Path());
102  }
103  }
104  }
105  }
106 
107  do {
108  SDL_Delay(10);
109  } while ((be_app == NULL) || be_app->IsLaunching());
110 
111  /* Mark the application active */
112  SDL_BeAppActive = 0;
113  }
114 
115  /* Increment the application reference count */
116  ++SDL_BeAppActive;
117 
118  /* The app is running, and we're ready to go */
119  return (0);
120 }
121 
122 /* Quit the Be Application, if there's nothing left to do */
123 void
124 SDL_QuitBeApp(void)
125 {
126  /* Decrement the application reference count */
127  --SDL_BeAppActive;
128 
129  /* If the reference count reached zero, clean up the app */
130  if (SDL_BeAppActive == 0) {
131  if (SDL_AppThread != NULL) {
132  if (be_app != NULL) { /* Not tested */
133  be_app->PostMessage(B_QUIT_REQUESTED);
134  }
135  SDL_WaitThread(SDL_AppThread, NULL);
136  SDL_AppThread = NULL;
137  }
138  /* be_app should now be NULL since be_app has quit */
139  }
140 }
141 
142 #ifdef __cplusplus
143 }
144 #endif
145 
146 /* SDL_BApp functions */
147 void SDL_BApp::ClearID(SDL_BWin *bwin) {
148  _SetSDLWindow(NULL, bwin->GetID());
149  int32 i = _GetNumWindowSlots() - 1;
150  while(i >= 0 && GetSDLWindow(i) == NULL) {
151  _PopBackWindow();
152  --i;
153  }
154 }
155 
156 #endif /* __HAIKU__ */
157 
158 /* vi: set ts=4 sw=4 expandtab: */
SDL_InitBeApp
int SDL_InitBeApp(void)
SDL_BApp::_GetNumWindowSlots
int32 _GetNumWindowSlots()
Definition: SDL_BApp.h:393
SDL_BApp::_PopBackWindow
void _PopBackWindow()
Definition: SDL_BApp.h:398
NULL
#define NULL
Definition: begin_code.h:167
SDL_timer.h
SDL_error.h
SDL_BWin
Definition: SDL_BWin.h:64
SDL_BApp::_SetSDLWindow
void _SetSDLWindow(SDL_Window *win, int32 winID)
Definition: SDL_BApp.h:389
unused
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF base if bpp PF set rept prefetch_distance PF set OFFSET endr endif endm macro preload_leading_step2 base if bpp ifc DST PF PF else if bpp lsl PF PF lsl PF PF lsl PF PF PF else PF lsl PF lsl PF lsl PF endif SIZE macro preload_middle scratch_holds_offset if bpp if else PF PF endif endif endif endm macro preload_trailing base if bpp if bpp *pix_per_block PF PF lsl PF PF PF PF PF else PF lsl PF lsl PF PF PF PF PF base if bpp if narrow_case &&bpp<=dst_w_bpp) PF bic, WK0, base, #31 PF pld,[WK0] PF add, WK1, base, X, LSL #bpp_shift PF sub, WK1, WK1, #1 PF bic, WK1, WK1, #31 PF cmp, WK1, WK0 PF beq, 90f PF pld,[WK1]90:.else PF bic, WK0, base, #31 PF pld,[WK0] PF add, WK1, base, X, lsl #bpp_shift PF sub, WK1, WK1, #1 PF bic, WK1, WK1, #31 PF cmp, WK1, WK0 PF beq, 92f91:PF add, WK0, WK0, #32 PF cmp, WK0, WK1 PF pld,[WK0] PF bne, 91b92:.endif .endif.endm.macro conditional_process1_helper cond, process_head, process_tail, numbytes, firstreg, unaligned_src, unaligned_mask, decrementx process_head cond, numbytes, firstreg, unaligned_src, unaligned_mask, 0 .if decrementx sub &cond X, X, #8 *numbytes/dst_w_bpp .endif process_tail cond, numbytes, firstreg .if !((flags) &FLAG_PROCESS_DOES_STORE) pixst cond, numbytes, firstreg, DST .endif.endm.macro conditional_process1 cond, process_head, process_tail, numbytes, firstreg, unaligned_src, unaligned_mask, decrementx .if(flags) &FLAG_BRANCH_OVER .ifc cond, mi bpl 100f .endif .ifc cond, cs bcc 100f .endif .ifc cond, ne beq 100f .endif conditional_process1_helper, process_head, process_tail, numbytes, firstreg, unaligned_src, unaligned_mask, decrementx100:.else conditional_process1_helper cond, process_head, process_tail, numbytes, firstreg, unaligned_src, unaligned_mask, decrementx .endif.endm.macro conditional_process2 test, cond1, cond2, process_head, process_tail, numbytes1, numbytes2, firstreg1, firstreg2, unaligned_src, unaligned_mask, decrementx .if(flags) &(FLAG_DST_READWRITE|FLAG_BRANCH_OVER|FLAG_PROCESS_CORRUPTS_PSR|FLAG_PROCESS_DOES_STORE) test conditional_process1 cond1, process_head, process_tail, numbytes1, firstreg1, unaligned_src, unaligned_mask, decrementx .if(flags) &FLAG_PROCESS_CORRUPTS_PSR test .endif conditional_process1 cond2, process_head, process_tail, numbytes2, firstreg2, unaligned_src, unaligned_mask, decrementx .else test process_head cond1, numbytes1, firstreg1, unaligned_src, unaligned_mask, 0 process_head cond2, numbytes2, firstreg2, unaligned_src, unaligned_mask, 0 .if decrementx sub &cond1 X, X, #8 *numbytes1/dst_w_bpp sub &cond2 X, X, #8 *numbytes2/dst_w_bpp .endif process_tail cond1, numbytes1, firstreg1 process_tail cond2, numbytes2, firstreg2 pixst cond1, numbytes1, firstreg1, DST pixst cond2, numbytes2, firstreg2, DST .endif.endm.macro test_bits_1_0_ptr .if(flags) &FLAG_PROCESS_CORRUPTS_WK0 movs SCRATCH, X, lsl #32-1 .else movs SCRATCH, WK0, lsl #32-1 .endif.endm.macro test_bits_3_2_ptr .if(flags) &FLAG_PROCESS_CORRUPTS_WK0 movs SCRATCH, X, lsl #32-3 .else movs SCRATCH, WK0, lsl #32-3 .endif.endm.macro leading_15bytes process_head, process_tail .set DECREMENT_X, 1 .if(flags) &FLAG_PROCESS_CORRUPTS_WK0 .set DECREMENT_X, 0 sub X, X, WK0, lsr #dst_bpp_shift str X,[sp, #LINE_SAVED_REG_COUNT *4] mov X, WK0 .endif .if dst_w_bpp==8 conditional_process2 test_bits_1_0_ptr, mi, cs, process_head, process_tail, 1, 2, 1, 2, 1, 1, DECREMENT_X .elseif dst_w_bpp==16 test_bits_1_0_ptr conditional_process1 cs, process_head, process_tail, 2, 2, 1, 1, DECREMENT_X .endif conditional_process2 test_bits_3_2_ptr, mi, cs, process_head, process_tail, 4, 8, 1, 2, 1, 1, DECREMENT_X .if(flags) &FLAG_PROCESS_CORRUPTS_WK0 ldr X,[sp, #LINE_SAVED_REG_COUNT *4] .endif.endm.macro test_bits_3_2_pix movs SCRATCH, X, lsl #dst_bpp_shift+32-3.endm.macro test_bits_1_0_pix .if dst_w_bpp==8 movs SCRATCH, X, lsl #dst_bpp_shift+32-1 .else movs SCRATCH, X, lsr #1 .endif.endm.macro trailing_15bytes process_head, process_tail, unaligned_src, unaligned_mask conditional_process2 test_bits_3_2_pix, cs, mi, process_head, process_tail, 8, 4, 0, 2, unaligned_src, unaligned_mask, 0 .if dst_w_bpp==16 test_bits_1_0_pix conditional_process1 cs, process_head, process_tail, 2, 0, unaligned_src, unaligned_mask, 0 .elseif dst_w_bpp==8 conditional_process2 test_bits_1_0_pix, cs, mi, process_head, process_tail, 2, 1, 0, 1, unaligned_src, unaligned_mask, 0 .endif.endm.macro wide_case_inner_loop process_head, process_tail, unaligned_src, unaligned_mask, dst_alignment110:.set SUBBLOCK, 0 .rept pix_per_block *dst_w_bpp/128 process_head, 16, 0, unaligned_src, unaligned_mask, 1 .if(src_bpp > 0) &&(mask_bpp==0) &&((flags) &FLAG_PROCESS_PRESERVES_SCRATCH) preload_middle src_bpp, SRC, 1 .elseif(src_bpp==0) &&(mask_bpp > 0) &&((flags) &FLAG_PROCESS_PRESERVES_SCRATCH) preload_middle mask_bpp, MASK, 1 .else preload_middle src_bpp, SRC, 0 preload_middle mask_bpp, MASK, 0 .endif .if(dst_r_bpp > 0) &&((SUBBLOCK % 2)==0) &&(((flags) &FLAG_NO_PRELOAD_DST)==0) PF pld,[DST, #32 *prefetch_distance - dst_alignment] .endif process_tail, 16, 0 .if !((flags) &FLAG_PROCESS_DOES_STORE) pixst, 16, 0, DST .endif .set SUBBLOCK, SUBBLOCK+1 .endr subs X, X, #pix_per_block bhs 110b.endm.macro wide_case_inner_loop_and_trailing_pixels process_head, process_tail, process_inner_loop, exit_label, unaligned_src, unaligned_mask .if dst_r_bpp > tst bne process_inner_loop DST_PRELOAD_BIAS endif preload_trailing SRC preload_trailing MASK DST endif add medium_case_inner_loop_and_trailing_pixels unaligned_mask endm macro medium_case_inner_loop_and_trailing_pixels unused
Definition: pixman-arm-simd-asm.h:487
path
GLsizei const GLchar *const * path
Definition: SDL_opengl_glext.h:3733
SDL_Thread
Definition: SDL_thread_c.h:54
SDL_BApp.h
SDL_BWin::GetID
int32 GetID()
Definition: SDL_BWin.h:435
SDL_BApp::ClearID
void ClearID(SDL_BWin *bwin)
SDL_CreateThreadInternal
SDL_Thread * SDL_CreateThreadInternal(int(*fn)(void *), const char *name, const size_t stacksize, void *data)
Definition: SDL_thread.c:435
ref
GLenum GLint ref
Definition: SDL_opengl_glext.h:660
SDL_QuitBeApp
void SDL_QuitBeApp(void)
f
GLfloat f
Definition: SDL_opengl_glext.h:1873
SDL_BeApp.h
SDL_Delay
#define SDL_Delay
Definition: SDL_dynapi_overrides.h:486
SDL_BApp::GetSDLWindow
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:191
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_BApp
Definition: SDL_BApp.h:81
SDL_WaitThread
#define SDL_WaitThread
Definition: SDL_dynapi_overrides.h:478
signature
const char * signature
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50