BufferQueue.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) 2012 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. #define LOG_TAG "BufferQueue"
  17. #define ATRACE_TAG ATRACE_TAG_GRAPHICS
  18. //#define LOG_NDEBUG 0
  19. #include <gui/BufferQueue.h>
  20. #include <gui/BufferQueueConsumer.h>
  21. #include <gui/BufferQueueCore.h>
  22. #include <gui/BufferQueueProducer.h>
  23. namespace android {
  24. BufferQueue::ProxyConsumerListener::ProxyConsumerListener(
  25. const wp<ConsumerListener>& consumerListener):
  26. mConsumerListener(consumerListener) {}
  27. BufferQueue::ProxyConsumerListener::~ProxyConsumerListener() {}
  28. void BufferQueue::ProxyConsumerListener::onFrameAvailable(
  29. const BufferItem& item) {
  30. sp<ConsumerListener> listener(mConsumerListener.promote());
  31. if (listener != NULL) {
  32. listener->onFrameAvailable(item);
  33. }
  34. }
  35. void BufferQueue::ProxyConsumerListener::onFrameReplaced(
  36. const BufferItem& item) {
  37. sp<ConsumerListener> listener(mConsumerListener.promote());
  38. if (listener != NULL) {
  39. listener->onFrameReplaced(item);
  40. }
  41. }
  42. void BufferQueue::ProxyConsumerListener::onBuffersReleased() {
  43. sp<ConsumerListener> listener(mConsumerListener.promote());
  44. if (listener != NULL) {
  45. listener->onBuffersReleased();
  46. }
  47. }
  48. void BufferQueue::ProxyConsumerListener::onSidebandStreamChanged() {
  49. sp<ConsumerListener> listener(mConsumerListener.promote());
  50. if (listener != NULL) {
  51. listener->onSidebandStreamChanged();
  52. }
  53. }
  54. void BufferQueue::createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
  55. sp<IGraphicBufferConsumer>* outConsumer,
  56. const sp<IGraphicBufferAlloc>& allocator) {
  57. LOG_ALWAYS_FATAL_IF(outProducer == NULL,
  58. "BufferQueue: outProducer must not be NULL");
  59. LOG_ALWAYS_FATAL_IF(outConsumer == NULL,
  60. "BufferQueue: outConsumer must not be NULL");
  61. sp<BufferQueueCore> core(new BufferQueueCore(allocator));
  62. LOG_ALWAYS_FATAL_IF(core == NULL,
  63. "BufferQueue: failed to create BufferQueueCore");
  64. sp<IGraphicBufferProducer> producer(new BufferQueueProducer(core));
  65. LOG_ALWAYS_FATAL_IF(producer == NULL,
  66. "BufferQueue: failed to create BufferQueueProducer");
  67. sp<IGraphicBufferConsumer> consumer(new BufferQueueConsumer(core));
  68. LOG_ALWAYS_FATAL_IF(consumer == NULL,
  69. "BufferQueue: failed to create BufferQueueConsumer");
  70. *outProducer = producer;
  71. *outConsumer = consumer;
  72. }
  73. }; // namespace android