rsThreadIO.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #ifndef ANDROID_RS_THREAD_IO_H
  17. #define ANDROID_RS_THREAD_IO_H
  18. #include "rsUtils.h"
  19. #include "rsFifoSocket.h"
  20. // ---------------------------------------------------------------------------
  21. namespace android {
  22. namespace renderscript {
  23. class Context;
  24. class ThreadIO {
  25. public:
  26. ThreadIO();
  27. ~ThreadIO();
  28. bool init();
  29. void shutdown();
  30. size_t getMaxInlineSize() {
  31. return mMaxInlineSize;
  32. }
  33. // Plays back commands from the client.
  34. // Returns true if any commands were processed.
  35. bool playCoreCommands(Context *con, int waitFd);
  36. void setTimeoutCallback(void (*)(void *), void *, uint64_t timeout);
  37. void * coreHeader(uint32_t, size_t dataLen);
  38. void coreCommit();
  39. void coreSetReturn(const void *data, size_t dataLen);
  40. void coreGetReturn(void *data, size_t dataLen);
  41. void coreWrite(const void *data, size_t len);
  42. void coreRead(void *data, size_t len);
  43. void asyncSetReturn(const void *data, size_t dataLen);
  44. void asyncGetReturn(void *data, size_t dataLen);
  45. void asyncWrite(const void *data, size_t len);
  46. void asyncRead(void *data, size_t len);
  47. RsMessageToClientType getClientHeader(size_t *receiveLen, uint32_t *usrID);
  48. RsMessageToClientType getClientPayload(void *data, size_t *receiveLen, uint32_t *subID, size_t bufferLen);
  49. bool sendToClient(RsMessageToClientType cmdID, uint32_t usrID, const void *data, size_t dataLen, bool waitForSpace);
  50. void clientShutdown();
  51. protected:
  52. typedef struct CoreCmdHeaderRec {
  53. uint32_t cmdID;
  54. uint32_t bytes;
  55. } CoreCmdHeader;
  56. typedef struct ClientCmdHeaderRec {
  57. uint32_t cmdID;
  58. uint32_t bytes;
  59. uint32_t userID;
  60. } ClientCmdHeader;
  61. ClientCmdHeader mLastClientHeader;
  62. bool mRunning;
  63. size_t mMaxInlineSize;
  64. FifoSocket mToClient;
  65. FifoSocket mToCore;
  66. intptr_t mToCoreRet;
  67. size_t mSendLen;
  68. uint8_t mSendBuffer[2 * 1024] __attribute__((aligned(sizeof(double))));
  69. };
  70. } // namespace renderscript
  71. } // namespace android
  72. #endif