Loading libs/gui/BufferHubProducer.cpp +7 −48 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ #include <log/log.h> #include <system/window.h> #include <ui/BufferHubBuffer.h> #include <ui/DetachedBufferHandle.h> namespace android { Loading Loading @@ -276,14 +275,10 @@ status_t BufferHubProducer::DetachBufferLocked(size_t slot) { status_or_handle.error()); return BAD_VALUE; } std::unique_ptr<DetachedBufferHandle> handle = DetachedBufferHandle::Create(status_or_handle.take()); if (!handle->isValid()) { ALOGE("detachBuffer: Failed to create a DetachedBufferHandle at slot %zu.", slot); return BAD_VALUE; } return graphic_buffer->setDetachedBufferHandle(std::move(handle)); // TODO(b/70912269): Reimplement BufferHubProducer::DetachBufferLocked() once GraphicBuffer can // be directly backed by BufferHub. return INVALID_OPERATION; } status_t BufferHubProducer::detachNextBuffer(sp<GraphicBuffer>* out_buffer, sp<Fence>* out_fence) { Loading Loading @@ -373,7 +368,7 @@ status_t BufferHubProducer::attachBuffer(int* out_slot, const sp<GraphicBuffer>& ALOGE("attachBuffer: out_slot cannot be NULL."); return BAD_VALUE; } if (buffer == nullptr || !buffer->isDetachedBuffer()) { if (buffer == nullptr) { ALOGE("attachBuffer: invalid GraphicBuffer."); return BAD_VALUE; } Loading @@ -394,45 +389,9 @@ status_t BufferHubProducer::attachBuffer(int* out_slot, const sp<GraphicBuffer>& return BAD_VALUE; } // Creates a BufferProducer from the GraphicBuffer. std::unique_ptr<DetachedBufferHandle> detached_handle = buffer->takeDetachedBufferHandle(); if (detached_handle == nullptr) { ALOGE("attachBuffer: DetachedBufferHandle cannot be NULL."); return BAD_VALUE; } std::shared_ptr<BufferProducer> buffer_producer = BufferProducer::Import(std::move(detached_handle->handle())); if (buffer_producer == nullptr) { ALOGE("attachBuffer: Failed to import BufferProducer."); return BAD_VALUE; } // Adds the BufferProducer into the Queue. auto status_or_slot = queue_->InsertBuffer(buffer_producer); if (!status_or_slot.ok()) { ALOGE("attachBuffer: Failed to insert buffer, error=%d.", status_or_slot.error()); return BAD_VALUE; } size_t slot = status_or_slot.get(); ALOGV("attachBuffer: returning slot %zu.", slot); if (slot >= static_cast<size_t>(max_buffer_count_)) { ALOGE("attachBuffer: Invalid slot: %zu.", slot); return BAD_VALUE; } // The just attached buffer should be in dequeued state according to IGraphicBufferProducer // interface. In BufferHub's language the buffer should be in Gained state. buffers_[slot].mGraphicBuffer = buffer; buffers_[slot].mBufferState.attachProducer(); buffers_[slot].mEglFence = EGL_NO_SYNC_KHR; buffers_[slot].mFence = Fence::NO_FENCE; buffers_[slot].mRequestBufferCalled = true; buffers_[slot].mAcquireCalled = false; buffers_[slot].mNeedsReallocation = false; *out_slot = static_cast<int>(slot); return NO_ERROR; // TODO(b/70912269): Reimplement BufferHubProducer::DetachBufferLocked() once GraphicBuffer can // be directly backed by BufferHub. return INVALID_OPERATION; } status_t BufferHubProducer::queueBuffer(int slot, const QueueBufferInput& input, Loading libs/gui/tests/IGraphicBufferProducer_test.cpp +0 −17 Original line number Diff line number Diff line Loading @@ -777,14 +777,6 @@ TEST_P(IGraphicBufferProducerTest, ASSERT_OK(mProducer->detachBuffer(slot)); EXPECT_OK(buffer->initCheck()); if (GetParam() == USE_BUFFER_HUB_PRODUCER) { // For a GraphicBuffer backed by BufferHub, once detached from an IGBP, it should have // isDetachedBuffer() set. Note that this only applies to BufferHub. EXPECT_TRUE(buffer->isDetachedBuffer()); } else { EXPECT_FALSE(buffer->isDetachedBuffer()); } ASSERT_OK(mProducer->disconnect(TEST_API)); ASSERT_EQ(NO_INIT, mProducer->attachBuffer(&slot, buffer)); Loading @@ -801,16 +793,7 @@ TEST_P(IGraphicBufferProducerTest, DetachThenAttach_Succeeds) { ASSERT_OK(mProducer->detachBuffer(slot)); EXPECT_OK(buffer->initCheck()); if (GetParam() == USE_BUFFER_HUB_PRODUCER) { // For a GraphicBuffer backed by BufferHub, once detached from an IGBP, it should have // isDetachedBuffer() set. Note that this only applies to BufferHub. EXPECT_TRUE(buffer->isDetachedBuffer()); } else { EXPECT_FALSE(buffer->isDetachedBuffer()); } EXPECT_OK(mProducer->attachBuffer(&slot, buffer)); EXPECT_FALSE(buffer->isDetachedBuffer()); EXPECT_OK(buffer->initCheck()); } Loading libs/ui/BufferHubBuffer.cpp +0 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ #pragma clang diagnostic pop #include <ui/BufferHubBuffer.h> #include <ui/DetachedBufferHandle.h> #include <poll.h> Loading libs/ui/GraphicBuffer.cpp +0 −19 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ #include <grallocusage/GrallocUsageConversion.h> #include <ui/DetachedBufferHandle.h> #include <ui/Gralloc2.h> #include <ui/GraphicBufferAllocator.h> #include <ui/GraphicBufferMapper.h> Loading Loading @@ -490,24 +489,6 @@ status_t GraphicBuffer::unflatten( return NO_ERROR; } bool GraphicBuffer::isDetachedBuffer() const { return mDetachedBufferHandle && mDetachedBufferHandle->isValid(); } status_t GraphicBuffer::setDetachedBufferHandle(std::unique_ptr<DetachedBufferHandle> channel) { if (isDetachedBuffer()) { ALOGW("setDetachedBuffer: there is already a BufferHub channel associated with this " "GraphicBuffer. Replacing the old one."); } mDetachedBufferHandle = std::move(channel); return NO_ERROR; } std::unique_ptr<DetachedBufferHandle> GraphicBuffer::takeDetachedBufferHandle() { return std::move(mDetachedBufferHandle); } // --------------------------------------------------------------------------- }; // namespace android libs/ui/include/ui/DetachedBufferHandle.hdeleted 100644 → 0 +0 −52 Original line number Diff line number Diff line /* * Copyright (C) 2018 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_DETACHED_BUFFER_HUB_HANDLE_H #define ANDROID_DETACHED_BUFFER_HUB_HANDLE_H #include <pdx/channel_handle.h> #include <memory> namespace android { // A wrapper that holds a pdx::LocalChannelHandle object. From the handle, a BufferHub buffer can be // created. Current implementation assumes that the underlying transport is using libpdx (thus // holding a pdx::LocalChannelHandle object), but future implementation can change it to a Binder // backend if ever needed. class DetachedBufferHandle { public: static std::unique_ptr<DetachedBufferHandle> Create(pdx::LocalChannelHandle handle) { return std::unique_ptr<DetachedBufferHandle>(new DetachedBufferHandle(std::move(handle))); } // Accessors to get or take the internal pdx::LocalChannelHandle. pdx::LocalChannelHandle& handle() { return mHandle; } const pdx::LocalChannelHandle& handle() const { return mHandle; } // Returns whether the DetachedBufferHandle holds a BufferHub channel. bool isValid() const { return mHandle.valid(); } private: // Constructs a DetachedBufferHandle from a pdx::LocalChannelHandle. explicit DetachedBufferHandle(pdx::LocalChannelHandle handle) : mHandle(std::move(handle)) {} pdx::LocalChannelHandle mHandle; }; } // namespace android #endif // ANDROID_DETACHED_BUFFER_HUB_HANDLE_H Loading
libs/gui/BufferHubProducer.cpp +7 −48 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ #include <log/log.h> #include <system/window.h> #include <ui/BufferHubBuffer.h> #include <ui/DetachedBufferHandle.h> namespace android { Loading Loading @@ -276,14 +275,10 @@ status_t BufferHubProducer::DetachBufferLocked(size_t slot) { status_or_handle.error()); return BAD_VALUE; } std::unique_ptr<DetachedBufferHandle> handle = DetachedBufferHandle::Create(status_or_handle.take()); if (!handle->isValid()) { ALOGE("detachBuffer: Failed to create a DetachedBufferHandle at slot %zu.", slot); return BAD_VALUE; } return graphic_buffer->setDetachedBufferHandle(std::move(handle)); // TODO(b/70912269): Reimplement BufferHubProducer::DetachBufferLocked() once GraphicBuffer can // be directly backed by BufferHub. return INVALID_OPERATION; } status_t BufferHubProducer::detachNextBuffer(sp<GraphicBuffer>* out_buffer, sp<Fence>* out_fence) { Loading Loading @@ -373,7 +368,7 @@ status_t BufferHubProducer::attachBuffer(int* out_slot, const sp<GraphicBuffer>& ALOGE("attachBuffer: out_slot cannot be NULL."); return BAD_VALUE; } if (buffer == nullptr || !buffer->isDetachedBuffer()) { if (buffer == nullptr) { ALOGE("attachBuffer: invalid GraphicBuffer."); return BAD_VALUE; } Loading @@ -394,45 +389,9 @@ status_t BufferHubProducer::attachBuffer(int* out_slot, const sp<GraphicBuffer>& return BAD_VALUE; } // Creates a BufferProducer from the GraphicBuffer. std::unique_ptr<DetachedBufferHandle> detached_handle = buffer->takeDetachedBufferHandle(); if (detached_handle == nullptr) { ALOGE("attachBuffer: DetachedBufferHandle cannot be NULL."); return BAD_VALUE; } std::shared_ptr<BufferProducer> buffer_producer = BufferProducer::Import(std::move(detached_handle->handle())); if (buffer_producer == nullptr) { ALOGE("attachBuffer: Failed to import BufferProducer."); return BAD_VALUE; } // Adds the BufferProducer into the Queue. auto status_or_slot = queue_->InsertBuffer(buffer_producer); if (!status_or_slot.ok()) { ALOGE("attachBuffer: Failed to insert buffer, error=%d.", status_or_slot.error()); return BAD_VALUE; } size_t slot = status_or_slot.get(); ALOGV("attachBuffer: returning slot %zu.", slot); if (slot >= static_cast<size_t>(max_buffer_count_)) { ALOGE("attachBuffer: Invalid slot: %zu.", slot); return BAD_VALUE; } // The just attached buffer should be in dequeued state according to IGraphicBufferProducer // interface. In BufferHub's language the buffer should be in Gained state. buffers_[slot].mGraphicBuffer = buffer; buffers_[slot].mBufferState.attachProducer(); buffers_[slot].mEglFence = EGL_NO_SYNC_KHR; buffers_[slot].mFence = Fence::NO_FENCE; buffers_[slot].mRequestBufferCalled = true; buffers_[slot].mAcquireCalled = false; buffers_[slot].mNeedsReallocation = false; *out_slot = static_cast<int>(slot); return NO_ERROR; // TODO(b/70912269): Reimplement BufferHubProducer::DetachBufferLocked() once GraphicBuffer can // be directly backed by BufferHub. return INVALID_OPERATION; } status_t BufferHubProducer::queueBuffer(int slot, const QueueBufferInput& input, Loading
libs/gui/tests/IGraphicBufferProducer_test.cpp +0 −17 Original line number Diff line number Diff line Loading @@ -777,14 +777,6 @@ TEST_P(IGraphicBufferProducerTest, ASSERT_OK(mProducer->detachBuffer(slot)); EXPECT_OK(buffer->initCheck()); if (GetParam() == USE_BUFFER_HUB_PRODUCER) { // For a GraphicBuffer backed by BufferHub, once detached from an IGBP, it should have // isDetachedBuffer() set. Note that this only applies to BufferHub. EXPECT_TRUE(buffer->isDetachedBuffer()); } else { EXPECT_FALSE(buffer->isDetachedBuffer()); } ASSERT_OK(mProducer->disconnect(TEST_API)); ASSERT_EQ(NO_INIT, mProducer->attachBuffer(&slot, buffer)); Loading @@ -801,16 +793,7 @@ TEST_P(IGraphicBufferProducerTest, DetachThenAttach_Succeeds) { ASSERT_OK(mProducer->detachBuffer(slot)); EXPECT_OK(buffer->initCheck()); if (GetParam() == USE_BUFFER_HUB_PRODUCER) { // For a GraphicBuffer backed by BufferHub, once detached from an IGBP, it should have // isDetachedBuffer() set. Note that this only applies to BufferHub. EXPECT_TRUE(buffer->isDetachedBuffer()); } else { EXPECT_FALSE(buffer->isDetachedBuffer()); } EXPECT_OK(mProducer->attachBuffer(&slot, buffer)); EXPECT_FALSE(buffer->isDetachedBuffer()); EXPECT_OK(buffer->initCheck()); } Loading
libs/ui/BufferHubBuffer.cpp +0 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ #pragma clang diagnostic pop #include <ui/BufferHubBuffer.h> #include <ui/DetachedBufferHandle.h> #include <poll.h> Loading
libs/ui/GraphicBuffer.cpp +0 −19 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ #include <grallocusage/GrallocUsageConversion.h> #include <ui/DetachedBufferHandle.h> #include <ui/Gralloc2.h> #include <ui/GraphicBufferAllocator.h> #include <ui/GraphicBufferMapper.h> Loading Loading @@ -490,24 +489,6 @@ status_t GraphicBuffer::unflatten( return NO_ERROR; } bool GraphicBuffer::isDetachedBuffer() const { return mDetachedBufferHandle && mDetachedBufferHandle->isValid(); } status_t GraphicBuffer::setDetachedBufferHandle(std::unique_ptr<DetachedBufferHandle> channel) { if (isDetachedBuffer()) { ALOGW("setDetachedBuffer: there is already a BufferHub channel associated with this " "GraphicBuffer. Replacing the old one."); } mDetachedBufferHandle = std::move(channel); return NO_ERROR; } std::unique_ptr<DetachedBufferHandle> GraphicBuffer::takeDetachedBufferHandle() { return std::move(mDetachedBufferHandle); } // --------------------------------------------------------------------------- }; // namespace android
libs/ui/include/ui/DetachedBufferHandle.hdeleted 100644 → 0 +0 −52 Original line number Diff line number Diff line /* * Copyright (C) 2018 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_DETACHED_BUFFER_HUB_HANDLE_H #define ANDROID_DETACHED_BUFFER_HUB_HANDLE_H #include <pdx/channel_handle.h> #include <memory> namespace android { // A wrapper that holds a pdx::LocalChannelHandle object. From the handle, a BufferHub buffer can be // created. Current implementation assumes that the underlying transport is using libpdx (thus // holding a pdx::LocalChannelHandle object), but future implementation can change it to a Binder // backend if ever needed. class DetachedBufferHandle { public: static std::unique_ptr<DetachedBufferHandle> Create(pdx::LocalChannelHandle handle) { return std::unique_ptr<DetachedBufferHandle>(new DetachedBufferHandle(std::move(handle))); } // Accessors to get or take the internal pdx::LocalChannelHandle. pdx::LocalChannelHandle& handle() { return mHandle; } const pdx::LocalChannelHandle& handle() const { return mHandle; } // Returns whether the DetachedBufferHandle holds a BufferHub channel. bool isValid() const { return mHandle.valid(); } private: // Constructs a DetachedBufferHandle from a pdx::LocalChannelHandle. explicit DetachedBufferHandle(pdx::LocalChannelHandle handle) : mHandle(std::move(handle)) {} pdx::LocalChannelHandle mHandle; }; } // namespace android #endif // ANDROID_DETACHED_BUFFER_HUB_HANDLE_H