BufferQueueLayer.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (C) 2018 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. #pragma once
  17. #include "BufferLayer.h"
  18. #include <utils/String8.h>
  19. namespace android {
  20. /*
  21. * A new BufferQueue and a new BufferLayerConsumer are created when the
  22. * BufferLayer is first referenced.
  23. *
  24. * This also implements onFrameAvailable(), which notifies SurfaceFlinger
  25. * that new data has arrived.
  26. */
  27. class BufferQueueLayer : public BufferLayer, public BufferLayerConsumer::ContentsChangedListener {
  28. public:
  29. explicit BufferQueueLayer(const LayerCreationArgs&);
  30. ~BufferQueueLayer() override;
  31. // -----------------------------------------------------------------------
  32. // Interface implementation for Layer
  33. // -----------------------------------------------------------------------
  34. public:
  35. void onLayerDisplayed(const sp<Fence>& releaseFence) override;
  36. void setTransformHint(uint32_t orientation) const override;
  37. std::vector<OccupancyTracker::Segment> getOccupancyHistory(bool forceFlush) override;
  38. bool getTransformToDisplayInverse() const override;
  39. // If a buffer was replaced this frame, release the former buffer
  40. void releasePendingBuffer(nsecs_t dequeueReadyTime) override;
  41. void setDefaultBufferSize(uint32_t w, uint32_t h) override;
  42. int32_t getQueuedFrameCount() const override;
  43. bool shouldPresentNow(nsecs_t expectedPresentTime) const override;
  44. // -----------------------------------------------------------------------
  45. // -----------------------------------------------------------------------
  46. // Interface implementation for BufferLayer
  47. // -----------------------------------------------------------------------
  48. public:
  49. bool fenceHasSignaled() const override;
  50. bool framePresentTimeIsCurrent() const override;
  51. private:
  52. nsecs_t getDesiredPresentTime() override;
  53. std::shared_ptr<FenceTime> getCurrentFenceTime() const override;
  54. void getDrawingTransformMatrix(float *matrix) override;
  55. uint32_t getDrawingTransform() const override;
  56. ui::Dataspace getDrawingDataSpace() const override;
  57. Rect getDrawingCrop() const override;
  58. uint32_t getDrawingScalingMode() const override;
  59. Region getDrawingSurfaceDamage() const override;
  60. const HdrMetadata& getDrawingHdrMetadata() const override;
  61. int getDrawingApi() const override;
  62. PixelFormat getPixelFormat() const override;
  63. uint64_t getFrameNumber() const override;
  64. bool getAutoRefresh() const override;
  65. bool getSidebandStreamChanged() const override;
  66. bool latchSidebandStream(bool& recomputeVisibleRegions) override;
  67. bool hasFrameUpdate() const override;
  68. void setFilteringEnabled(bool enabled) override;
  69. status_t bindTextureImage() override;
  70. status_t updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime) override;
  71. status_t updateActiveBuffer() override;
  72. status_t updateFrameNumber(nsecs_t latchTime) override;
  73. void setHwcLayerBuffer(const sp<const DisplayDevice>& displayDevice) override;
  74. // -----------------------------------------------------------------------
  75. // Interface implementation for BufferLayerConsumer::ContentsChangedListener
  76. // -----------------------------------------------------------------------
  77. protected:
  78. void onFrameAvailable(const BufferItem& item) override;
  79. void onFrameReplaced(const BufferItem& item) override;
  80. void onSidebandStreamChanged() override;
  81. // -----------------------------------------------------------------------
  82. public:
  83. status_t setDefaultBufferProperties(uint32_t w, uint32_t h, PixelFormat format);
  84. sp<IGraphicBufferProducer> getProducer() const;
  85. private:
  86. // Temporary - Used only for LEGACY camera mode.
  87. uint32_t getProducerStickyTransform() const;
  88. void onFirstRef() override;
  89. sp<BufferLayerConsumer> mConsumer;
  90. sp<IGraphicBufferProducer> mProducer;
  91. PixelFormat mFormat{PIXEL_FORMAT_NONE};
  92. // Only accessed on the main thread.
  93. uint64_t mPreviousFrameNumber{0};
  94. bool mUpdateTexImageFailed{false};
  95. // Local copy of the queued contents of the incoming BufferQueue
  96. mutable Mutex mQueueItemLock;
  97. Condition mQueueItemCondition;
  98. Vector<BufferItem> mQueueItems;
  99. std::atomic<uint64_t> mLastFrameNumberReceived{0};
  100. bool mAutoRefresh{false};
  101. int mActiveBufferSlot{BufferQueue::INVALID_BUFFER_SLOT};
  102. // thread-safe
  103. std::atomic<int32_t> mQueuedFrames{0};
  104. std::atomic<bool> mSidebandStreamChanged{false};
  105. void fakeVsync();
  106. };
  107. } // namespace android