blob: ebce0abf1beacca7534aadba767570a5add5c45a [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_RS_THREAD_IO_H
18#define ANDROID_RS_THREAD_IO_H
19
Jason Sams4b962e52009-06-22 17:15:15 -070020#include "rsUtils.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070021#include "rsLocklessFifo.h"
Jason Samsedbfabd2011-05-17 15:01:29 -070022#include "rsFifoSocket.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070023
24// ---------------------------------------------------------------------------
25namespace android {
26namespace renderscript {
27
28class Context;
29
30class ThreadIO {
31public:
32 ThreadIO();
33 ~ThreadIO();
34
Jason Samsedbfabd2011-05-17 15:01:29 -070035 void init(bool useSocket = false);
Jason Samsf5b45962009-08-25 14:49:07 -070036 void shutdown();
37
Jason Samsa09f11d2009-06-04 17:58:03 -070038 // Plays back commands from the client.
39 // Returns true if any commands were processed.
Jason Samsbfc78912011-08-12 15:05:15 -070040 bool playCoreCommands(Context *con, bool waitForCommand, uint64_t timeToWait);
Jason Samsd19f10d2009-05-22 14:03:28 -070041
Jason Sams5316b9e2011-09-13 15:41:01 -070042 void setTimoutCallback(void (*)(void *), void *, uint64_t timeout);
Jason Samsedbfabd2011-05-17 15:01:29 -070043 //LocklessCommandFifo mToCore;
Jason Samsd19f10d2009-05-22 14:03:28 -070044
Jason Samsedbfabd2011-05-17 15:01:29 -070045
46
47 void coreFlush();
48 void * coreHeader(uint32_t, size_t dataLen);
49 void coreData(const void *data, size_t dataLen);
50 void coreCommit();
51 void coreCommitSync();
52 void coreSetReturn(const void *data, size_t dataLen);
53 void coreGetReturn(void *data, size_t dataLen);
54
55
56 RsMessageToClientType getClientHeader(size_t *receiveLen, uint32_t *usrID);
57 RsMessageToClientType getClientPayload(void *data, size_t *receiveLen, uint32_t *subID, size_t bufferLen);
58 bool sendToClient(RsMessageToClientType cmdID, uint32_t usrID, const void *data, size_t dataLen, bool waitForSpace);
59 void clientShutdown();
60
61
62protected:
63 typedef struct CoreCmdHeaderRec {
64 uint32_t cmdID;
65 uint32_t bytes;
66 } CoreCmdHeader;
67 typedef struct ClientCmdHeaderRec {
68 uint32_t cmdID;
69 uint32_t bytes;
70 uint32_t userID;
71 } ClientCmdHeader;
72 ClientCmdHeader mLastClientHeader;
73
74 size_t mCoreCommandSize;
75 uint32_t mCoreCommandID;
76 uint8_t * mCoreDataPtr;
77 uint8_t * mCoreDataBasePtr;
78
79 bool mUsingSocket;
Jason Sams516c3192009-10-06 13:58:47 -070080 LocklessCommandFifo mToClient;
Jason Samsedbfabd2011-05-17 15:01:29 -070081 LocklessCommandFifo mToCore;
82
83 FifoSocket mToClientSocket;
84 FifoSocket mToCoreSocket;
Jason Samsd19f10d2009-05-22 14:03:28 -070085
86 intptr_t mToCoreRet;
Jason Samsedbfabd2011-05-17 15:01:29 -070087
Jason Samsd19f10d2009-05-22 14:03:28 -070088};
89
Jason Samsd19f10d2009-05-22 14:03:28 -070090
91}
92}
93#endif
94