rsGrallocConsumer.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2013 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_GRALLOC_CONSUMER_H
  17. #define ANDROID_RS_GRALLOC_CONSUMER_H
  18. #include <media/NdkImage.h>
  19. #include <media/NdkImageReader.h>
  20. // ---------------------------------------------------------------------------
  21. namespace android {
  22. namespace renderscript {
  23. class Allocation;
  24. class Context;
  25. /**
  26. * CpuConsumer is a BufferQueue consumer endpoint that allows direct CPU
  27. * access to the underlying gralloc buffers provided by BufferQueue. Multiple
  28. * buffers may be acquired by it at once, to be used concurrently by the
  29. * CpuConsumer owner. Sets gralloc usage flags to be software-read-only.
  30. * This queue is synchronous by default.
  31. */
  32. class GrallocConsumer
  33. {
  34. public:
  35. GrallocConsumer(const Context *, Allocation *, uint32_t numAlloc);
  36. virtual ~GrallocConsumer();
  37. ANativeWindow* getNativeWindow();
  38. media_status_t lockNextBuffer(uint32_t idx = 0);
  39. media_status_t unlockBuffer(uint32_t idx = 0);
  40. uint32_t getNextAvailableIdx(Allocation *a);
  41. bool releaseIdx(uint32_t idx);
  42. bool isActive();
  43. uint32_t mNumAlloc;
  44. static void onFrameAvailable(void* obj, AImageReader* reader);
  45. private:
  46. media_status_t releaseAcquiredBufferLocked(uint32_t idx);
  47. // Boolean array to check if a position has been occupied or not.
  48. bool *isIdxUsed;
  49. Allocation **mAlloc;
  50. const Context *mCtx;
  51. AImageReader* mImgReader;
  52. ANativeWindow* mNativeWindow;
  53. AImageReader_ImageListener mReaderCb;
  54. // Tracking for buffers acquired by the user
  55. struct AcquiredBuffer {
  56. AImage *mImg;
  57. uint8_t *mBufferPointer;
  58. AcquiredBuffer() :
  59. mImg(nullptr),
  60. mBufferPointer(nullptr) {
  61. }
  62. };
  63. AcquiredBuffer *mAcquiredBuffer;
  64. };
  65. } // namespace renderscript
  66. } // namespace android
  67. #endif // ANDROID_RS_GRALLOC_CONSUMER_H