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 #include "cairo-boilerplate.h"
42 #include <cairo-beos.h>
44 // Part of this code was originally part of
45 // xpfe/bootstrap/nsNativeAppSupportBeOS.cpp in the Mozilla source code.
47 #include <Application.h>
52 class CairoTestWindow : public BWindow
55 CairoTestWindow(BRect frame, const char* title);
56 virtual ~CairoTestWindow();
57 BView* View() const { return mView; }
62 CairoTestWindow::CairoTestWindow(BRect frame, const char* title)
63 : BWindow(frame, title, B_TITLED_WINDOW,
64 B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
66 mView = new BView(frame, "CairoWindowTestView", B_FOLLOW_ALL_SIDES, 0);
70 // Make sure the window is actually on screen
73 mView->SetViewColor(B_TRANSPARENT_COLOR);
78 CairoTestWindow::~CairoTestWindow()
85 class nsBeOSApp : public BApplication
88 nsBeOSApp(sem_id sem) : BApplication(GetAppSig()), init(sem)
96 static int32 Main(void *args)
98 nsBeOSApp *app = new nsBeOSApp( (sem_id)args );
106 const char *GetAppSig()
108 return "application/x-vnd.cairo-test-app";
121 AppRunner::AppRunner()
126 sem_id initsem = create_sem(0, "Cairo BApplication init");
127 if (initsem < B_OK) {
128 fprintf (stderr, "Error creating BeOS initialization semaphore\n");
132 thread_id tid = spawn_thread(nsBeOSApp::Main, "Cairo/BeOS test", B_NORMAL_PRIORITY, (void *)initsem);
133 if (tid < B_OK || B_OK != resume_thread(tid)) {
134 fprintf (stderr, "Error spawning thread\n");
138 if (B_OK != acquire_sem(initsem)) {
139 fprintf (stderr, "Error acquiring semaphore\n");
147 AppRunner::~AppRunner()
157 // Make sure that the BApplication is initialized
158 static AppRunner sAppRunner;
160 struct beos_boilerplate_closure {
166 // Test a real window
167 static cairo_surface_t *
168 _cairo_boilerplate_beos_create_surface (const char *name,
169 cairo_content_t content,
172 cairo_boilerplate_mode_t mode,
175 float right = width ? width - 1 : 0;
176 float bottom = height ? height - 1 : 0;
177 BRect rect(0.0, 0.0, right, bottom);
178 CairoTestWindow* wnd = new CairoTestWindow(rect, name);
180 beos_boilerplate_closure* bclosure = new beos_boilerplate_closure;
181 bclosure->view = wnd->View();
182 bclosure->bitmap = NULL;
183 bclosure->window = wnd;
187 return cairo_beos_surface_create(wnd->View());
191 _cairo_boilerplate_beos_cleanup (void *closure)
193 beos_boilerplate_closure* bclosure = reinterpret_cast<beos_boilerplate_closure*>(closure);
195 bclosure->window->Lock();
196 bclosure->window->Quit();
202 static cairo_surface_t *
203 _cairo_boilerplate_beos_create_surface_for_bitmap (const char *name,
204 cairo_content_t content,
207 cairo_boilerplate_mode_t mode,
210 BRect rect(0.0, 0.0, width - 1, height - 1);
211 color_space beosformat = (content == CAIRO_CONTENT_COLOR_ALPHA) ? B_RGBA32
213 BBitmap* bmp = new BBitmap(rect, beosformat, true);
214 BView* view = new BView(rect, "Cairo test view", B_FOLLOW_ALL_SIDES, 0);
217 beos_boilerplate_closure* bclosure = new beos_boilerplate_closure;
218 bclosure->view = view;
219 bclosure->bitmap = bmp;
220 bclosure->window = NULL;
223 return cairo_beos_surface_create_for_bitmap(view, bmp);
227 _cairo_boilerplate_beos_cleanup_bitmap (void *closure)
229 beos_boilerplate_closure* bclosure = reinterpret_cast<beos_boilerplate_closure*>(closure);
231 bclosure->bitmap->RemoveChild(bclosure->view);
234 delete bclosure->view;
235 delete bclosure->bitmap;
240 static const cairo_boilerplate_target_t targets[] = {
241 /* BeOS sometimes produces a slightly different image. Perhaps this
242 * is related to the fact that it doesn't use premultiplied alpha...
243 * Just ignore the small difference. */
245 "beos", "beos", NULL, NULL,
246 CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR, 1,
247 _cairo_boilerplate_beos_create_surface,
249 _cairo_boilerplate_get_image_surface,
250 cairo_surface_write_to_png,
251 _cairo_boilerplate_beos_cleanup
254 "beos-bitmap", "beos", NULL, NULL,
255 CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR, 1,
256 _cairo_boilerplate_beos_create_surface_for_bitmap,
258 _cairo_boilerplate_get_image_surface,
259 cairo_surface_write_to_png,
260 _cairo_boilerplate_beos_cleanup_bitmap
263 "beos-bitmap", "beos", NULL, NULL,
264 CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR_ALPHA, 1,
265 _cairo_boilerplate_beos_create_surface_for_bitmap,
267 _cairo_boilerplate_get_image_surface,
268 cairo_surface_write_to_png,
269 _cairo_boilerplate_beos_cleanup_bitmap
272 CAIRO_BOILERPLATE (beos, targets)