Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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 | |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 20 | #include "rsUtils.h" |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 21 | #include "rsLocklessFifo.h" |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 22 | #include "rsFifoSocket.h" |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 23 | |
| 24 | // --------------------------------------------------------------------------- |
| 25 | namespace android { |
| 26 | namespace renderscript { |
| 27 | |
| 28 | class Context; |
| 29 | |
| 30 | class ThreadIO { |
| 31 | public: |
| 32 | ThreadIO(); |
| 33 | ~ThreadIO(); |
| 34 | |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 35 | void init(bool useSocket = false); |
Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 36 | void shutdown(); |
| 37 | |
Jason Sams | a09f11d | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 38 | // Plays back commands from the client. |
| 39 | // Returns true if any commands were processed. |
Jason Sams | bfc7891 | 2011-08-12 15:05:15 -0700 | [diff] [blame] | 40 | bool playCoreCommands(Context *con, bool waitForCommand, uint64_t timeToWait); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 41 | |
Jason Sams | 5316b9e | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 42 | void setTimoutCallback(void (*)(void *), void *, uint64_t timeout); |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 43 | //LocklessCommandFifo mToCore; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 44 | |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 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; |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 80 | LocklessCommandFifo mToClient; |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 81 | LocklessCommandFifo mToCore; |
| 82 | |
| 83 | FifoSocket mToClientSocket; |
| 84 | FifoSocket mToCoreSocket; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 85 | |
| 86 | intptr_t mToCoreRet; |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 87 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 90 | |
| 91 | } |
| 92 | } |
| 93 | #endif |
| 94 | |