1a56bc488SPhilippe Houdoin/*
2a56bc488SPhilippe Houdoin	Copyright 1999, Be Incorporated.   All Rights Reserved.
3a56bc488SPhilippe Houdoin	This file may be used under the terms of the Be Sample Code License.
4a56bc488SPhilippe Houdoin
5a56bc488SPhilippe Houdoin	Other authors:
6a56bc488SPhilippe Houdoin	Gerald Zajac 2007-2010
7a56bc488SPhilippe Houdoin*/
8a56bc488SPhilippe Houdoin
9a56bc488SPhilippe Houdoin#include "accelerant.h"
10a56bc488SPhilippe Houdoin
11a56bc488SPhilippe Houdoin
12a56bc488SPhilippe Houdoinstatic engine_token engineToken = { 1, B_2D_ACCELERATION, NULL };
13a56bc488SPhilippe Houdoin
14a56bc488SPhilippe Houdoin
15a56bc488SPhilippe Houdoinuint32
16a56bc488SPhilippe HoudoinAccelerantEngineCount(void)
17a56bc488SPhilippe Houdoin{
18a56bc488SPhilippe Houdoin	return 1;
19a56bc488SPhilippe Houdoin}
20a56bc488SPhilippe Houdoin
21a56bc488SPhilippe Houdoin
22a56bc488SPhilippe Houdoinstatus_t
23a56bc488SPhilippe HoudoinAcquireEngine(uint32 capabilities, uint32 max_wait,
24a56bc488SPhilippe Houdoin						sync_token* st, engine_token** et)
25a56bc488SPhilippe Houdoin{
26a56bc488SPhilippe Houdoin	(void)capabilities;	// avoid compiler warning for unused arg
27a56bc488SPhilippe Houdoin	(void)max_wait;		// avoid compiler warning for unused arg
28a56bc488SPhilippe Houdoin
29a56bc488SPhilippe Houdoin	if (gInfo.sharedInfo->engineLock.Acquire() != B_OK)
30a56bc488SPhilippe Houdoin		return B_ERROR;
31a56bc488SPhilippe Houdoin
32a56bc488SPhilippe Houdoin	// Sync if required.
33a56bc488SPhilippe Houdoin	if (st)
34a56bc488SPhilippe Houdoin		SyncToToken(st);
35a56bc488SPhilippe Houdoin
36a56bc488SPhilippe Houdoin	// Return an engine token.
37a56bc488SPhilippe Houdoin	*et = &engineToken;
38a56bc488SPhilippe Houdoin	return B_OK;
39a56bc488SPhilippe Houdoin}
40a56bc488SPhilippe Houdoin
41a56bc488SPhilippe Houdoin
42a56bc488SPhilippe Houdoinstatus_t
43a56bc488SPhilippe HoudoinReleaseEngine(engine_token* et, sync_token* st)
44a56bc488SPhilippe Houdoin{
45a56bc488SPhilippe Houdoin	// Update the sync token, if any.
46a56bc488SPhilippe Houdoin	if (st)
47a56bc488SPhilippe Houdoin		GetSyncToken(et, st);
48a56bc488SPhilippe Houdoin
49a56bc488SPhilippe Houdoin	gInfo.sharedInfo->engineLock.Release();
50a56bc488SPhilippe Houdoin	return B_OK;
51a56bc488SPhilippe Houdoin}
52a56bc488SPhilippe Houdoin
53a56bc488SPhilippe Houdoin
54a56bc488SPhilippe Houdoinvoid
55a56bc488SPhilippe HoudoinWaitEngineIdle(void)
56a56bc488SPhilippe Houdoin{
57a56bc488SPhilippe Houdoin	TDFX_WaitForIdle();	// wait until engine is completely idle
58a56bc488SPhilippe Houdoin}
59a56bc488SPhilippe Houdoin
60a56bc488SPhilippe Houdoin
61a56bc488SPhilippe Houdoinstatus_t
62a56bc488SPhilippe HoudoinGetSyncToken(engine_token* et, sync_token* st)
63a56bc488SPhilippe Houdoin{
64a56bc488SPhilippe Houdoin	st->engine_id = et->engine_id;
65a56bc488SPhilippe Houdoin	st->counter = 0;
66a56bc488SPhilippe Houdoin	return B_OK;
67a56bc488SPhilippe Houdoin}
68a56bc488SPhilippe Houdoin
69a56bc488SPhilippe Houdoin
70a56bc488SPhilippe Houdoinstatus_t
71a56bc488SPhilippe HoudoinSyncToToken(sync_token* st)
72a56bc488SPhilippe Houdoin{
73a56bc488SPhilippe Houdoin	(void)st;		// avoid compiler warning for unused arg
74a56bc488SPhilippe Houdoin
75a56bc488SPhilippe Houdoin	WaitEngineIdle();
76a56bc488SPhilippe Houdoin	return B_OK;
77a56bc488SPhilippe Houdoin}
78a56bc488SPhilippe Houdoin
79