blob: cb7d4abca5c5bf6652c208053eaca66a956dd3bb [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 Samsedbfabd2011-05-17 15:01:29 -070021#include "rsFifoSocket.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070022
23// ---------------------------------------------------------------------------
24namespace android {
25namespace renderscript {
26
27class Context;
28
29class ThreadIO {
30public:
31 ThreadIO();
32 ~ThreadIO();
33
Jason Sams4c2e4c82012-02-07 15:32:08 -080034 void init();
Jason Samsf5b45962009-08-25 14:49:07 -070035 void shutdown();
36
Jason Sams548cc0e2012-02-16 17:21:32 -080037 size_t getMaxInlineSize() {
38 return mMaxInlineSize;
39 }
40 bool isPureFifo() {
41 return mPureFifo;
42 }
43
Jason Samsa09f11d2009-06-04 17:58:03 -070044 // Plays back commands from the client.
45 // Returns true if any commands were processed.
Jason Sams87e27212012-02-09 14:36:14 -080046 bool playCoreCommands(Context *con, int waitFd);
Jason Samsd19f10d2009-05-22 14:03:28 -070047
Jason Sams4c2e4c82012-02-07 15:32:08 -080048 void setTimeoutCallback(void (*)(void *), void *, uint64_t timeout);
Jason Samsd19f10d2009-05-22 14:03:28 -070049
Jason Samsedbfabd2011-05-17 15:01:29 -070050 void * coreHeader(uint32_t, size_t dataLen);
Jason Samsedbfabd2011-05-17 15:01:29 -070051 void coreCommit();
Jason Sams548cc0e2012-02-16 17:21:32 -080052
Jason Samsedbfabd2011-05-17 15:01:29 -070053 void coreSetReturn(const void *data, size_t dataLen);
54 void coreGetReturn(void *data, size_t dataLen);
Jason Sams548cc0e2012-02-16 17:21:32 -080055 void coreWrite(const void *data, size_t len);
56 void coreRead(void *data, size_t len);
57
58 void asyncSetReturn(const void *data, size_t dataLen);
59 void asyncGetReturn(void *data, size_t dataLen);
60 void asyncWrite(const void *data, size_t len);
61 void asyncRead(void *data, size_t len);
Jason Samsedbfabd2011-05-17 15:01:29 -070062
63
64 RsMessageToClientType getClientHeader(size_t *receiveLen, uint32_t *usrID);
65 RsMessageToClientType getClientPayload(void *data, size_t *receiveLen, uint32_t *subID, size_t bufferLen);
66 bool sendToClient(RsMessageToClientType cmdID, uint32_t usrID, const void *data, size_t dataLen, bool waitForSpace);
67 void clientShutdown();
68
69
70protected:
71 typedef struct CoreCmdHeaderRec {
72 uint32_t cmdID;
73 uint32_t bytes;
74 } CoreCmdHeader;
75 typedef struct ClientCmdHeaderRec {
76 uint32_t cmdID;
77 uint32_t bytes;
78 uint32_t userID;
79 } ClientCmdHeader;
80 ClientCmdHeader mLastClientHeader;
81
Jason Sams4c2e4c82012-02-07 15:32:08 -080082 bool mRunning;
Jason Sams548cc0e2012-02-16 17:21:32 -080083 bool mPureFifo;
84 size_t mMaxInlineSize;
Jason Samsedbfabd2011-05-17 15:01:29 -070085
Jason Sams4c2e4c82012-02-07 15:32:08 -080086 FifoSocket mToClient;
87 FifoSocket mToCore;
Jason Samsd19f10d2009-05-22 14:03:28 -070088
89 intptr_t mToCoreRet;
Jason Samsedbfabd2011-05-17 15:01:29 -070090
Jason Sams4c2e4c82012-02-07 15:32:08 -080091 size_t mSendLen;
92 uint8_t mSendBuffer[2 * 1024];
93
Jason Samsd19f10d2009-05-22 14:03:28 -070094};
95
Jason Samsd19f10d2009-05-22 14:03:28 -070096
97}
98}
99#endif
100