Jason Sams | 326e0dd | 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 | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 20 | #include "rsUtils.h" |
Jason Sams | 1a4efa3 | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 21 | #include "rsFifoSocket.h" |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 22 | |
| 23 | // --------------------------------------------------------------------------- |
| 24 | namespace android { |
| 25 | namespace renderscript { |
| 26 | |
| 27 | class Context; |
| 28 | |
| 29 | class ThreadIO { |
| 30 | public: |
| 31 | ThreadIO(); |
| 32 | ~ThreadIO(); |
| 33 | |
Yang Ni | 9ed983b | 2017-04-18 12:19:01 -0700 | [diff] [blame] | 34 | bool init(); |
Jason Sams | 8c0ee65 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 35 | void shutdown(); |
| 36 | |
Jason Sams | bda75a9 | 2012-02-16 17:21:32 -0800 | [diff] [blame] | 37 | size_t getMaxInlineSize() { |
| 38 | return mMaxInlineSize; |
| 39 | } |
Jason Sams | bda75a9 | 2012-02-16 17:21:32 -0800 | [diff] [blame] | 40 | |
Jason Sams | a44cb29 | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 41 | // Plays back commands from the client. |
| 42 | // Returns true if any commands were processed. |
Jason Sams | 963a2fb | 2012-02-09 14:36:14 -0800 | [diff] [blame] | 43 | bool playCoreCommands(Context *con, int waitFd); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 44 | |
Jason Sams | 5f27d6f | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 45 | void setTimeoutCallback(void (*)(void *), void *, uint64_t timeout); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 46 | |
Jason Sams | 1a4efa3 | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 47 | void * coreHeader(uint32_t, size_t dataLen); |
Jason Sams | 1a4efa3 | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 48 | void coreCommit(); |
Jason Sams | bda75a9 | 2012-02-16 17:21:32 -0800 | [diff] [blame] | 49 | |
Jason Sams | 1a4efa3 | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 50 | void coreSetReturn(const void *data, size_t dataLen); |
| 51 | void coreGetReturn(void *data, size_t dataLen); |
Jason Sams | bda75a9 | 2012-02-16 17:21:32 -0800 | [diff] [blame] | 52 | void coreWrite(const void *data, size_t len); |
| 53 | void coreRead(void *data, size_t len); |
| 54 | |
| 55 | void asyncSetReturn(const void *data, size_t dataLen); |
| 56 | void asyncGetReturn(void *data, size_t dataLen); |
| 57 | void asyncWrite(const void *data, size_t len); |
| 58 | void asyncRead(void *data, size_t len); |
Jason Sams | 1a4efa3 | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 59 | |
| 60 | |
| 61 | RsMessageToClientType getClientHeader(size_t *receiveLen, uint32_t *usrID); |
| 62 | RsMessageToClientType getClientPayload(void *data, size_t *receiveLen, uint32_t *subID, size_t bufferLen); |
| 63 | bool sendToClient(RsMessageToClientType cmdID, uint32_t usrID, const void *data, size_t dataLen, bool waitForSpace); |
| 64 | void clientShutdown(); |
| 65 | |
| 66 | |
| 67 | protected: |
| 68 | typedef struct CoreCmdHeaderRec { |
| 69 | uint32_t cmdID; |
| 70 | uint32_t bytes; |
| 71 | } CoreCmdHeader; |
| 72 | typedef struct ClientCmdHeaderRec { |
| 73 | uint32_t cmdID; |
| 74 | uint32_t bytes; |
| 75 | uint32_t userID; |
| 76 | } ClientCmdHeader; |
| 77 | ClientCmdHeader mLastClientHeader; |
| 78 | |
Jason Sams | 5f27d6f | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 79 | bool mRunning; |
Jason Sams | bda75a9 | 2012-02-16 17:21:32 -0800 | [diff] [blame] | 80 | size_t mMaxInlineSize; |
Jason Sams | 1a4efa3 | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 81 | |
Jason Sams | 5f27d6f | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 82 | FifoSocket mToClient; |
| 83 | FifoSocket mToCore; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 84 | |
| 85 | intptr_t mToCoreRet; |
Jason Sams | 1a4efa3 | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 86 | |
Jason Sams | 5f27d6f | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 87 | size_t mSendLen; |
Vladimir Stefanovic | a05e8dd | 2012-09-05 19:46:02 +0200 | [diff] [blame] | 88 | uint8_t mSendBuffer[2 * 1024] __attribute__((aligned(sizeof(double)))); |
Jason Sams | 5f27d6f | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 89 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 92 | |
Rahul Chaudhry | 7974fc0 | 2017-02-09 12:33:28 -0800 | [diff] [blame] | 93 | } // namespace renderscript |
| 94 | } // namespace android |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 95 | #endif |
| 96 | |