diff options
author | 2019-07-04 17:52:39 +0100 | |
---|---|---|
committer | 2019-08-02 10:00:02 +0000 | |
commit | 15e58b4023dda977836dfcc89bdc657a8b2f4a64 (patch) | |
tree | 5fdb8dcbcbe20fdf481411d57f4fc2344b749a05 | |
parent | c71fb23b4bed7f3d279cd6e4f8b0fd9b22d60e8f (diff) |
Add hostgraphics classes required for ImageReader
Bug: 117921091
Test: all tests should pass
Change-Id: I5d60a1177d43eb8dec08403cf34936007b8a267f
(cherry picked from commit c1409f44f82313902a690fb257ee271dc16385a0)
-rw-r--r-- | libs/hostgraphics/Android.bp | 7 | ||||
-rw-r--r-- | libs/hostgraphics/Fence.cpp | 23 | ||||
-rw-r--r-- | libs/hostgraphics/HostBufferQueue.cpp | 69 | ||||
-rw-r--r-- | libs/hostgraphics/PublicFormat.cpp | 33 | ||||
-rw-r--r-- | libs/hostgraphics/gui/BufferItem.h | 65 | ||||
-rw-r--r-- | libs/hostgraphics/gui/BufferItemConsumer.h | 75 | ||||
-rw-r--r-- | libs/hostgraphics/gui/BufferQueue.h | 37 | ||||
-rw-r--r-- | libs/hostgraphics/gui/ConsumerBase.h | 37 | ||||
-rw-r--r-- | libs/hostgraphics/gui/IGraphicBufferConsumer.h | 65 | ||||
-rw-r--r-- | libs/hostgraphics/gui/IGraphicBufferProducer.h | 2 | ||||
-rw-r--r-- | libs/hostgraphics/ui/Fence.h | 72 | ||||
-rw-r--r-- | libs/hostgraphics/ui/GraphicBuffer.h | 64 |
12 files changed, 549 insertions, 0 deletions
diff --git a/libs/hostgraphics/Android.bp b/libs/hostgraphics/Android.bp index aedb7522ab08..e713b98b867e 100644 --- a/libs/hostgraphics/Android.bp +++ b/libs/hostgraphics/Android.bp @@ -1,8 +1,15 @@ cc_library_host_static { name: "libhostgraphics", + cflags: [ + "-Wno-unused-parameter", + ], + srcs: [ ":libui_host_common", + "Fence.cpp", + "HostBufferQueue.cpp", + "PublicFormat.cpp", ], include_dirs: [ diff --git a/libs/hostgraphics/Fence.cpp b/libs/hostgraphics/Fence.cpp new file mode 100644 index 000000000000..9e54816651c4 --- /dev/null +++ b/libs/hostgraphics/Fence.cpp @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#include <ui/Fence.h> + +namespace android { + +const sp<Fence> Fence::NO_FENCE = sp<Fence>(new Fence); + +} // namespace android
\ No newline at end of file diff --git a/libs/hostgraphics/HostBufferQueue.cpp b/libs/hostgraphics/HostBufferQueue.cpp new file mode 100644 index 000000000000..ec304378c6c4 --- /dev/null +++ b/libs/hostgraphics/HostBufferQueue.cpp @@ -0,0 +1,69 @@ +/* + * 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. + */ + +#include <gui/BufferQueue.h> + +namespace android { + +class HostBufferQueue : public IGraphicBufferProducer, public IGraphicBufferConsumer { +public: + HostBufferQueue() : mWidth(0), mHeight(0) { } + + virtual status_t setConsumerIsProtected(bool isProtected) { return OK; } + + virtual status_t detachBuffer(int slot) { return OK; } + + virtual status_t getReleasedBuffers(uint64_t* slotMask) { return OK; } + + virtual status_t setDefaultBufferSize(uint32_t w, uint32_t h) { + mWidth = w; + mHeight = h; + mBuffer = sp<GraphicBuffer>(new GraphicBuffer(mWidth, mHeight)); + return OK; + } + + virtual status_t setDefaultBufferFormat(PixelFormat defaultFormat) { return OK; } + + virtual status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace) { return OK; } + + virtual status_t discardFreeBuffers() { return OK; } + + virtual status_t acquireBuffer(BufferItem* buffer, nsecs_t presentWhen, + uint64_t maxFrameNumber = 0) { + buffer->mGraphicBuffer = mBuffer; + buffer->mSlot = 0; + return OK; + } + + virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) { return OK; } + + virtual status_t setConsumerUsageBits(uint64_t usage) { return OK; } +private: + sp<GraphicBuffer> mBuffer; + uint32_t mWidth; + uint32_t mHeight; +}; + +void BufferQueue::createBufferQueue(sp<IGraphicBufferProducer>* outProducer, + sp<IGraphicBufferConsumer>* outConsumer) { + + sp<HostBufferQueue> obj(new HostBufferQueue()); + + *outProducer = obj; + *outConsumer = obj; +} + +} // namespace android diff --git a/libs/hostgraphics/PublicFormat.cpp b/libs/hostgraphics/PublicFormat.cpp new file mode 100644 index 000000000000..af6d2738c801 --- /dev/null +++ b/libs/hostgraphics/PublicFormat.cpp @@ -0,0 +1,33 @@ +/* + * 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. + */ + +#include <ui/PublicFormat.h> + +namespace android { + +android_dataspace mapPublicFormatToHalDataspace(PublicFormat f) { + return static_cast<android_dataspace>(0); +} + +int mapPublicFormatToHalFormat(PublicFormat f) { + return static_cast<int>(f); +} + +PublicFormat mapHalFormatDataspaceToPublicFormat(int format, android_dataspace dataSpace) { + return static_cast<PublicFormat>(format); +} + +} // namespace android
\ No newline at end of file diff --git a/libs/hostgraphics/gui/BufferItem.h b/libs/hostgraphics/gui/BufferItem.h new file mode 100644 index 000000000000..01409e19c715 --- /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 000000000000..707b313eb102 --- /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 000000000000..aa3e7268e11c --- /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 000000000000..9002953c0848 --- /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 000000000000..9eb67b218800 --- /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 00422136ff76..a1efd0bcfa4c 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 { diff --git a/libs/hostgraphics/ui/Fence.h b/libs/hostgraphics/ui/Fence.h new file mode 100644 index 000000000000..04d535c3a211 --- /dev/null +++ b/libs/hostgraphics/ui/Fence.h @@ -0,0 +1,72 @@ +/* + * 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_FENCE_H +#define ANDROID_FENCE_H + +#include <utils/String8.h> +#include <utils/RefBase.h> + +typedef int64_t nsecs_t; + +namespace android { + +class Fence : public LightRefBase<Fence> { +public: + Fence() { } + Fence(int) { } + static const sp<Fence> NO_FENCE; + static constexpr nsecs_t SIGNAL_TIME_PENDING = INT64_MAX; + static constexpr nsecs_t SIGNAL_TIME_INVALID = -1; + static sp<Fence> merge(const char* name, const sp<Fence>& f1, const sp<Fence>& f2) { + return NO_FENCE; + } + + static sp<Fence> merge(const String8& name, const sp<Fence>& f1, const sp<Fence>& f2) { + return NO_FENCE; + } + + enum class Status { + Invalid, // Fence is invalid + Unsignaled, // Fence is valid but has not yet signaled + Signaled, // Fence is valid and has signaled + }; + + status_t wait(int timeout) { return OK; } + + status_t waitForever(const char* logname) { return OK; } + + int dup() const { return 0; } + + inline Status getStatus() { + // The sync_wait call underlying wait() has been measured to be + // significantly faster than the sync_fence_info call underlying + // getSignalTime(), which might otherwise appear to be the more obvious + // way to check whether a fence has signaled. + switch (wait(0)) { + case NO_ERROR: + return Status::Signaled; + case -ETIME: + return Status::Unsignaled; + default: + return Status::Invalid; + } + } +}; + +} // namespace android + +#endif // ANDROID_FENCE_H diff --git a/libs/hostgraphics/ui/GraphicBuffer.h b/libs/hostgraphics/ui/GraphicBuffer.h new file mode 100644 index 000000000000..ac88e44dbc65 --- /dev/null +++ b/libs/hostgraphics/ui/GraphicBuffer.h @@ -0,0 +1,64 @@ +/* + * 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_GRAPHIC_BUFFER_H +#define ANDROID_GRAPHIC_BUFFER_H + +#include <stdint.h> +#include <sys/types.h> + +#include <vector> + +#include <ui/PixelFormat.h> +#include <ui/Rect.h> + +#include <utils/RefBase.h> + +namespace android { + +class GraphicBuffer : virtual public RefBase { +public: + GraphicBuffer(uint32_t w, uint32_t h):width(w),height(h) { + data.resize(w*h); + } + uint32_t getWidth() const { return static_cast<uint32_t>(width); } + uint32_t getHeight() const { return static_cast<uint32_t>(height); } + uint32_t getStride() const { return static_cast<uint32_t>(width); } + uint64_t getUsage() const { return 0; } + PixelFormat getPixelFormat() const { return PIXEL_FORMAT_RGBA_8888; } + //uint32_t getLayerCount() const { return static_cast<uint32_t>(layerCount); } + Rect getBounds() const { return Rect(width, height); } + + status_t lockAsyncYCbCr(uint32_t inUsage, const Rect& rect, + android_ycbcr *ycbcr, int fenceFd) { return OK; } + + status_t lockAsync(uint32_t inUsage, const Rect& rect, void** vaddr, int fenceFd, + int32_t* outBytesPerPixel = nullptr, int32_t* outBytesPerStride = nullptr) { + *vaddr = data.data(); + return OK; + } + + status_t unlockAsync(int *fenceFd) { return OK; } + +private: + uint32_t width; + uint32_t height; + std::vector<uint32_t> data; +}; + +}; // namespace android + +#endif // ANDROID_GRAPHIC_BUFFER_H |