rsThreadIO.h revision 1a4efa363916977ef9aeab756725b3bdc880a15b
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// --------------------------------------------------------------------------- 25namespace android { 26namespace renderscript { 27 28class Context; 29 30class ThreadIO { 31public: 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); 41 42 //LocklessCommandFifo mToCore; 43 44 45 46 void coreFlush(); 47 void * coreHeader(uint32_t, size_t dataLen); 48 void coreData(const void *data, size_t dataLen); 49 void coreCommit(); 50 void coreCommitSync(); 51 void coreSetReturn(const void *data, size_t dataLen); 52 void coreGetReturn(void *data, size_t dataLen); 53 54 55 RsMessageToClientType getClientHeader(size_t *receiveLen, uint32_t *usrID); 56 RsMessageToClientType getClientPayload(void *data, size_t *receiveLen, uint32_t *subID, size_t bufferLen); 57 bool sendToClient(RsMessageToClientType cmdID, uint32_t usrID, const void *data, size_t dataLen, bool waitForSpace); 58 void clientShutdown(); 59 60 61protected: 62 typedef struct CoreCmdHeaderRec { 63 uint32_t cmdID; 64 uint32_t bytes; 65 } CoreCmdHeader; 66 typedef struct ClientCmdHeaderRec { 67 uint32_t cmdID; 68 uint32_t bytes; 69 uint32_t userID; 70 } ClientCmdHeader; 71 ClientCmdHeader mLastClientHeader; 72 73 size_t mCoreCommandSize; 74 uint32_t mCoreCommandID; 75 uint8_t * mCoreDataPtr; 76 uint8_t * mCoreDataBasePtr; 77 78 bool mUsingSocket; 79 LocklessCommandFifo mToClient; 80 LocklessCommandFifo mToCore; 81 82 FifoSocket mToClientSocket; 83 FifoSocket mToCoreSocket; 84 85 intptr_t mToCoreRet; 86 87}; 88 89 90} 91} 92#endif 93 94