1 /* 2 * Copyright 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 17 #ifndef ANDROID_GUI_BUFFERHUBCONSUMER_H_ 18 #define ANDROID_GUI_BUFFERHUBCONSUMER_H_ 19 20 #include <gui/IGraphicBufferConsumer.h> 21 #include <private/dvr/buffer_hub_queue_client.h> 22 #include <private/dvr/buffer_hub_queue_parcelable.h> 23 24 namespace android { 25 26 class BufferHubConsumer : public IGraphicBufferConsumer { 27 public: 28 // Creates a BufferHubConsumer instance by importing an existing producer queue. 29 static sp<BufferHubConsumer> Create(const std::shared_ptr<dvr::ConsumerQueue>& queue); 30 31 // Creates a BufferHubConsumer instance by importing an existing producer 32 // parcelable. Note that this call takes the ownership of the parcelable 33 // object and is guaranteed to succeed if parcelable object is valid. 34 static sp<BufferHubConsumer> Create(dvr::ConsumerQueueParcelable parcelable); 35 36 // See |IGraphicBufferConsumer::acquireBuffer| 37 status_t acquireBuffer(BufferItem* buffer, nsecs_t presentWhen, 38 uint64_t maxFrameNumber = 0) override; 39 40 // See |IGraphicBufferConsumer::detachBuffer| 41 status_t detachBuffer(int slot) override; 42 43 // See |IGraphicBufferConsumer::attachBuffer| 44 status_t attachBuffer(int* outSlot, const sp<GraphicBuffer>& buffer) override; 45 46 // See |IGraphicBufferConsumer::releaseBuffer| 47 status_t releaseBuffer(int buf, uint64_t frameNumber, EGLDisplay display, EGLSyncKHR fence, 48 const sp<Fence>& releaseFence) override; 49 50 // See |IGraphicBufferConsumer::consumerConnect| 51 status_t consumerConnect(const sp<IConsumerListener>& consumer, bool controlledByApp) override; 52 53 // See |IGraphicBufferConsumer::consumerDisconnect| 54 status_t consumerDisconnect() override; 55 56 // See |IGraphicBufferConsumer::getReleasedBuffers| 57 status_t getReleasedBuffers(uint64_t* slotMask) override; 58 59 // See |IGraphicBufferConsumer::setDefaultBufferSize| 60 status_t setDefaultBufferSize(uint32_t w, uint32_t h) override; 61 62 // See |IGraphicBufferConsumer::setMaxBufferCount| 63 status_t setMaxBufferCount(int bufferCount) override; 64 65 // See |IGraphicBufferConsumer::setMaxAcquiredBufferCount| 66 status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) override; 67 68 // See |IGraphicBufferConsumer::setConsumerName| 69 status_t setConsumerName(const String8& name) override; 70 71 // See |IGraphicBufferConsumer::setDefaultBufferFormat| 72 status_t setDefaultBufferFormat(PixelFormat defaultFormat) override; 73 74 // See |IGraphicBufferConsumer::setDefaultBufferDataSpace| 75 status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace) override; 76 77 // See |IGraphicBufferConsumer::setConsumerUsageBits| 78 status_t setConsumerUsageBits(uint64_t usage) override; 79 80 // See |IGraphicBufferConsumer::setConsumerIsProtected| 81 status_t setConsumerIsProtected(bool isProtected) override; 82 83 // See |IGraphicBufferConsumer::setTransformHint| 84 status_t setTransformHint(uint32_t hint) override; 85 86 // See |IGraphicBufferConsumer::getSidebandStream| 87 status_t getSidebandStream(sp<NativeHandle>* outStream) const override; 88 89 // See |IGraphicBufferConsumer::getOccupancyHistory| 90 status_t getOccupancyHistory(bool forceFlush, 91 std::vector<OccupancyTracker::Segment>* outHistory) override; 92 93 // See |IGraphicBufferConsumer::discardFreeBuffers| 94 status_t discardFreeBuffers() override; 95 96 // See |IGraphicBufferConsumer::dumpState| 97 status_t dumpState(const String8& prefix, String8* outResult) const override; 98 99 // BufferHubConsumer provides its own logic to cast to a binder object. 100 IBinder* onAsBinder() override; 101 102 private: 103 // Private constructor to force use of |Create|. 104 BufferHubConsumer() = default; 105 106 // Concrete implementation backed by BufferHubBuffer. 107 std::shared_ptr<dvr::ConsumerQueue> mQueue; 108 }; 109 110 } // namespace android 111 112 #endif // ANDROID_GUI_BUFFERHUBCONSUMER_H_ 113