1
/* vim:set ts=8 sw=4 noet cin: */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Mozilla Public License Version
6
* 1.1 (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/MPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is Mozilla Communicator client code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
23
* Takashi Toyoshima <toyoshim@be-in.org>
24
* Fredrik Holmqvist <thesuckiestemail@yahoo.se>
25
* Christian Biesinger <cbiesinger@web.de>
27
* Alternatively, the contents of this file may be used under the terms of
28
* either of the GNU General Public License Version 2 or later (the "GPL"),
29
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30
* in which case the provisions of the GPL or the LGPL are applicable instead
31
* of those above. If you wish to allow use of your version of this file only
32
* under the terms of either the GPL or the LGPL, and not to allow others to
33
* use your version of this file under the terms of the MPL, indicate your
34
* decision by deleting the provisions above and replace them with the notice
35
* and other provisions required by the GPL or the LGPL. If you do not delete
36
* the provisions above, a recipient may use your version of this file under
37
* the terms of any one of the MPL, the GPL or the LGPL.
39
* ***** END LICENSE BLOCK ***** */
41
// BeOS's C++ compiler does not support varargs in macros
42
// So, define CAIRO_BOILERPLATE_LOG here
43
#define CAIRO_BOILERPLATE_LOG cairo_beos_boilerplate_log
46
#include "cairo-boilerplate.h"
48
#include "cairo-boilerplate-beos-private.h"
50
#include <cairo-beos.h>
52
// Part of this code was originally part of
53
// xpfe/bootstrap/nsNativeAppSupportBeOS.cpp in the Mozilla source code.
55
#include <Application.h>
60
static int cairo_beos_boilerplate_log(const char* format, ...) {
63
va_start(args, format);
64
rv = vfprintf(stderr, format, args);
69
class CairoTestWindow : public BWindow
72
CairoTestWindow(BRect frame, const char* title);
73
virtual ~CairoTestWindow();
74
BView* View() const { return mView; }
79
CairoTestWindow::CairoTestWindow(BRect frame, const char* title)
80
: BWindow(frame, title, B_TITLED_WINDOW,
81
B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
83
mView = new BView(frame, "CairoWindowTestView", B_FOLLOW_ALL_SIDES, 0);
87
// Make sure the window is actually on screen
90
mView->SetViewColor(B_TRANSPARENT_COLOR);
95
CairoTestWindow::~CairoTestWindow()
102
class nsBeOSApp : public BApplication
105
nsBeOSApp(sem_id sem) : BApplication(GetAppSig()), init(sem)
113
static int32 Main(void *args)
115
nsBeOSApp *app = new nsBeOSApp( (sem_id)args );
123
const char *GetAppSig()
125
return "application/x-vnd.cairo-test-app";
138
AppRunner::AppRunner()
143
sem_id initsem = create_sem(0, "Cairo BApplication init");
144
if (initsem < B_OK) {
145
CAIRO_BOILERPLATE_LOG("Error creating BeOS initialization semaphore\n");
149
thread_id tid = spawn_thread(nsBeOSApp::Main, "Cairo/BeOS test", B_NORMAL_PRIORITY, (void *)initsem);
150
if (tid < B_OK || B_OK != resume_thread(tid)) {
151
CAIRO_BOILERPLATE_LOG("Error spawning thread\n");
155
if (B_OK != acquire_sem(initsem)) {
156
CAIRO_BOILERPLATE_LOG("Error acquiring semaphore\n");
164
AppRunner::~AppRunner()
174
// Make sure that the BApplication is initialized
175
static AppRunner sAppRunner;
177
struct beos_boilerplate_closure
184
// Test a real window
186
_cairo_boilerplate_beos_create_surface (const char *name,
187
cairo_content_t content,
190
cairo_boilerplate_mode_t mode,
193
float right = width ? width - 1 : 0;
194
float bottom = height ? height - 1 : 0;
195
BRect rect(0.0, 0.0, right, bottom);
196
CairoTestWindow* wnd = new CairoTestWindow(rect, name);
198
beos_boilerplate_closure* bclosure = new beos_boilerplate_closure;
199
bclosure->view = wnd->View();
200
bclosure->bitmap = NULL;
201
bclosure->window = wnd;
205
return cairo_beos_surface_create(wnd->View());
209
_cairo_boilerplate_beos_cleanup (void* closure)
211
beos_boilerplate_closure* bclosure = reinterpret_cast<beos_boilerplate_closure*>(closure);
213
bclosure->window->Lock();
214
bclosure->window->Quit();
221
_cairo_boilerplate_beos_create_surface_for_bitmap (const char *name,
222
cairo_content_t content,
225
cairo_boilerplate_mode_t mode,
228
BRect rect(0.0, 0.0, width - 1, height - 1);
229
color_space beosformat = (content == CAIRO_CONTENT_COLOR_ALPHA) ? B_RGBA32
231
BBitmap* bmp = new BBitmap(rect, beosformat, true);
232
BView* view = new BView(rect, "Cairo test view", B_FOLLOW_ALL_SIDES, 0);
235
beos_boilerplate_closure* bclosure = new beos_boilerplate_closure;
236
bclosure->view = view;
237
bclosure->bitmap = bmp;
238
bclosure->window = NULL;
241
return cairo_beos_surface_create_for_bitmap(view, bmp);
245
_cairo_boilerplate_beos_cleanup_bitmap (void* closure)
247
beos_boilerplate_closure* bclosure = reinterpret_cast<beos_boilerplate_closure*>(closure);
249
bclosure->bitmap->RemoveChild(bclosure->view);
252
delete bclosure->view;
253
delete bclosure->bitmap;