Add hostgraphics classes required for ImageReader
Bug: 117921091
Test: all tests should pass
Change-Id: I5d60a1177d43eb8dec08403cf34936007b8a267f
(cherry picked from commit c1409f44f82313902a690fb257ee271dc16385a0)
diff --git a/libs/hostgraphics/gui/BufferItem.h b/libs/hostgraphics/gui/BufferItem.h
new file mode 100644
index 0000000..01409e1
--- /dev/null
+++ b/libs/hostgraphics/gui/BufferItem.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_GUI_BUFFERITEM_H
+#define ANDROID_GUI_BUFFERITEM_H
+
+#include <ui/Fence.h>
+#include <ui/Rect.h>
+
+#include <system/graphics.h>
+
+#include <utils/StrongPointer.h>
+
+namespace android {
+
+class Fence;
+class GraphicBuffer;
+
+// The only thing we need here for layoutlib is mGraphicBuffer. The rest of the fields are added
+// just to satisfy the calls from the android_media_ImageReader.h
+
+class BufferItem {
+public:
+ enum { INVALID_BUFFER_SLOT = -1 };
+
+ BufferItem() : mGraphicBuffer(nullptr), mFence(Fence::NO_FENCE) {}
+ ~BufferItem() {}
+
+ sp<GraphicBuffer> mGraphicBuffer;
+
+ sp<Fence> mFence;
+
+ Rect mCrop;
+
+ uint32_t mTransform;
+
+ uint32_t mScalingMode;
+
+ int64_t mTimestamp;
+
+ android_dataspace mDataSpace;
+
+ uint64_t mFrameNumber;
+
+ int mSlot;
+
+ bool mTransformToDisplayInverse;
+};
+
+}
+
+#endif // ANDROID_GUI_BUFFERITEM_H
diff --git a/libs/hostgraphics/gui/BufferItemConsumer.h b/libs/hostgraphics/gui/BufferItemConsumer.h
new file mode 100644
index 0000000..707b313
--- /dev/null
+++ b/libs/hostgraphics/gui/BufferItemConsumer.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_GUI_BUFFERITEMCONSUMER_H
+#define ANDROID_GUI_BUFFERITEMCONSUMER_H
+
+#include <utils/RefBase.h>
+
+#include <gui/ConsumerBase.h>
+#include <gui/IGraphicBufferConsumer.h>
+
+namespace android {
+
+class BufferItemConsumer : public ConsumerBase {
+public:
+ BufferItemConsumer(
+ const sp<IGraphicBufferConsumer>& consumer,
+ uint64_t consumerUsage,
+ int bufferCount,
+ bool controlledByApp) : mConsumer(consumer) {
+ }
+
+ status_t acquireBuffer(BufferItem *item, nsecs_t presentWhen, bool waitForFence = true) {
+ return mConsumer->acquireBuffer(item, presentWhen, 0);
+ }
+
+ status_t releaseBuffer(
+ const BufferItem &item, const sp<Fence>& releaseFence = Fence::NO_FENCE) { return OK; }
+
+ void setName(const String8& name) { }
+
+ void setFrameAvailableListener(const wp<FrameAvailableListener>& listener) { }
+
+ status_t setDefaultBufferSize(uint32_t width, uint32_t height) {
+ return mConsumer->setDefaultBufferSize(width, height);
+ }
+
+ status_t setDefaultBufferFormat(PixelFormat defaultFormat) {
+ return mConsumer->setDefaultBufferFormat(defaultFormat);
+ }
+
+ status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace) {
+ return mConsumer->setDefaultBufferDataSpace(defaultDataSpace);
+ }
+
+ void abandon() { }
+
+ status_t detachBuffer(int slot) { return OK; }
+
+ status_t discardFreeBuffers() { return OK; }
+
+ void freeBufferLocked(int slotIndex) { }
+
+ status_t addReleaseFenceLocked(
+ int slot, const sp<GraphicBuffer> graphicBuffer, const sp<Fence>& fence) { return OK; }
+private:
+ sp<IGraphicBufferConsumer> mConsumer;
+};
+
+} // namespace android
+
+#endif // ANDROID_GUI_BUFFERITEMCONSUMER_H
diff --git a/libs/hostgraphics/gui/BufferQueue.h b/libs/hostgraphics/gui/BufferQueue.h
new file mode 100644
index 0000000..aa3e726
--- /dev/null
+++ b/libs/hostgraphics/gui/BufferQueue.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_GUI_BUFFERQUEUE_H
+#define ANDROID_GUI_BUFFERQUEUE_H
+
+#include <gui/BufferItem.h>
+#include <gui/IGraphicBufferConsumer.h>
+#include <gui/IGraphicBufferProducer.h>
+
+namespace android {
+
+class BufferQueue {
+public:
+ enum { INVALID_BUFFER_SLOT = BufferItem::INVALID_BUFFER_SLOT };
+ enum { NO_BUFFER_AVAILABLE = IGraphicBufferConsumer::NO_BUFFER_AVAILABLE };
+
+ static void createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
+ sp<IGraphicBufferConsumer>* outConsumer);
+};
+
+} // namespace android
+
+#endif // ANDROID_GUI_BUFFERQUEUE_H
diff --git a/libs/hostgraphics/gui/ConsumerBase.h b/libs/hostgraphics/gui/ConsumerBase.h
new file mode 100644
index 0000000..9002953
--- /dev/null
+++ b/libs/hostgraphics/gui/ConsumerBase.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_GUI_CONSUMERBASE_H
+#define ANDROID_GUI_CONSUMERBASE_H
+
+#include <gui/BufferItem.h>
+
+#include <utils/RefBase.h>
+
+namespace android {
+
+class ConsumerBase : public virtual RefBase {
+public:
+ struct FrameAvailableListener : public virtual RefBase {
+ // See IConsumerListener::onFrame{Available,Replaced}
+ virtual void onFrameAvailable(const BufferItem& item) = 0;
+ virtual void onFrameReplaced(const BufferItem& /* item */) {}
+ };
+};
+
+} // namespace android
+
+#endif // ANDROID_GUI_CONSUMERBASE_H
\ No newline at end of file
diff --git a/libs/hostgraphics/gui/IGraphicBufferConsumer.h b/libs/hostgraphics/gui/IGraphicBufferConsumer.h
new file mode 100644
index 0000000..9eb67b2
--- /dev/null
+++ b/libs/hostgraphics/gui/IGraphicBufferConsumer.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <utils/RefBase.h>
+
+#include <ui/PixelFormat.h>
+
+#include <utils/Errors.h>
+
+namespace android {
+
+class BufferItem;
+class Fence;
+class GraphicBuffer;
+
+class IGraphicBufferConsumer : virtual public RefBase {
+public:
+ enum {
+ // Returned by releaseBuffer, after which the consumer must free any references to the
+ // just-released buffer that it might have.
+ STALE_BUFFER_SLOT = 1,
+ // Returned by dequeueBuffer if there are no pending buffers available.
+ NO_BUFFER_AVAILABLE,
+ // Returned by dequeueBuffer if it's too early for the buffer to be acquired.
+ PRESENT_LATER,
+ };
+
+ virtual status_t acquireBuffer(BufferItem* buffer, nsecs_t presentWhen,
+ uint64_t maxFrameNumber = 0) = 0;
+
+ virtual status_t detachBuffer(int slot) = 0;
+
+ virtual status_t getReleasedBuffers(uint64_t* slotMask) = 0;
+
+ virtual status_t setDefaultBufferSize(uint32_t w, uint32_t h) = 0;
+
+ virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) = 0;
+
+ virtual status_t setDefaultBufferFormat(PixelFormat defaultFormat) = 0;
+
+ virtual status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace) = 0;
+
+ virtual status_t setConsumerUsageBits(uint64_t usage) = 0;
+
+ virtual status_t setConsumerIsProtected(bool isProtected) = 0;
+
+ virtual status_t discardFreeBuffers() = 0;
+};
+
+} // namespace android
\ No newline at end of file
diff --git a/libs/hostgraphics/gui/IGraphicBufferProducer.h b/libs/hostgraphics/gui/IGraphicBufferProducer.h
index 0042213..a1efd0b 100644
--- a/libs/hostgraphics/gui/IGraphicBufferProducer.h
+++ b/libs/hostgraphics/gui/IGraphicBufferProducer.h
@@ -19,6 +19,8 @@
#include <utils/RefBase.h>
+#include <ui/GraphicBuffer.h>
+
namespace android {
class IGraphicBufferProducer : virtual public RefBase {