blob: 7e730df312712112c65814684ceba6f1910192c4 [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 Sams61e76a72012-01-27 13:27:01 -080040 //
41 // waitForCommand: true, block until a command arrives or
42 // the specified time expires.
43 //
44 // timeToWait: Max time to block in microseconds. A value of zero indicates
45 // an indefinite wait.
Jason Samsbfc78912011-08-12 15:05:15 -070046 bool playCoreCommands(Context *con, bool waitForCommand, uint64_t timeToWait);
Jason Samsd19f10d2009-05-22 14:03:28 -070047
Jason Sams5316b9e2011-09-13 15:41:01 -070048 void setTimoutCallback(void (*)(void *), void *, uint64_t timeout);
Jason Samsedbfabd2011-05-17 15:01:29 -070049 //LocklessCommandFifo mToCore;
Jason Samsd19f10d2009-05-22 14:03:28 -070050
Jason Samsedbfabd2011-05-17 15:01:29 -070051
52
53 void coreFlush();
54 void * coreHeader(uint32_t, size_t dataLen);
55 void coreData(const void *data, size_t dataLen);
56 void coreCommit();
57 void coreCommitSync();
58 void coreSetReturn(const void *data, size_t dataLen);
59 void coreGetReturn(void *data, size_t dataLen);
60
61
62 RsMessageToClientType getClientHeader(size_t *receiveLen, uint32_t *usrID);
63 RsMessageToClientType getClientPayload(void *data, size_t *receiveLen, uint32_t *subID, size_t bufferLen);
64 bool sendToClient(RsMessageToClientType cmdID, uint32_t usrID, const void *data, size_t dataLen, bool waitForSpace);
65 void clientShutdown();
66
67
68protected:
69 typedef struct CoreCmdHeaderRec {
70 uint32_t cmdID;
71 uint32_t bytes;
72 } CoreCmdHeader;
73 typedef struct ClientCmdHeaderRec {
74 uint32_t cmdID;
75 uint32_t bytes;
76 uint32_t userID;
77 } ClientCmdHeader;
78 ClientCmdHeader mLastClientHeader;
79
80 size_t mCoreCommandSize;
81 uint32_t mCoreCommandID;
82 uint8_t * mCoreDataPtr;
83 uint8_t * mCoreDataBasePtr;
84
85 bool mUsingSocket;
Jason Sams516c3192009-10-06 13:58:47 -070086 LocklessCommandFifo mToClient;
Jason Samsedbfabd2011-05-17 15:01:29 -070087 LocklessCommandFifo mToCore;
88
89 FifoSocket mToClientSocket;
90 FifoSocket mToCoreSocket;
Jason Samsd19f10d2009-05-22 14:03:28 -070091
92 intptr_t mToCoreRet;
Jason Samsedbfabd2011-05-17 15:01:29 -070093
Jason Samsd19f10d2009-05-22 14:03:28 -070094};
95
Jason Samsd19f10d2009-05-22 14:03:28 -070096
97}
98}
99#endif
100