• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
20 #include "rsUtils.h"
21 #include "rsLocklessFifo.h"
22 #include "rsFifoSocket.h"
23 
24 // ---------------------------------------------------------------------------
25 namespace android {
26 namespace renderscript {
27 
28 class Context;
29 
30 class ThreadIO {
31 public:
32     ThreadIO();
33     ~ThreadIO();
34 
35     void init(bool useSocket = false);
36     void shutdown();
37 
38     // Plays back commands from the client.
39     // Returns true if any commands were processed.
40     bool playCoreCommands(Context *con, bool waitForCommand, uint64_t timeToWait);
41 
42     void setTimoutCallback(void (*)(void *), void *, uint64_t timeout);
43     //LocklessCommandFifo mToCore;
44 
45 
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 
62 protected:
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;
80     LocklessCommandFifo mToClient;
81     LocklessCommandFifo mToCore;
82 
83     FifoSocket mToClientSocket;
84     FifoSocket mToCoreSocket;
85 
86     intptr_t mToCoreRet;
87 
88 };
89 
90 
91 }
92 }
93 #endif
94 
95