From c859147db5e9d5aa8a5043c0111e2799e1db042b Mon Sep 17 00:00:00 2001 From: Fabien Sanglard Date: Tue, 7 Mar 2017 10:10:03 -0800 Subject: Add MiniFence to drop HWC2on1Adapter libui dep This class will soon become a library used by devices with no support for HWC2. They will link against libhwc2on1adapter. Drivers should have no depedencies on libui. Test:Manual Change-Id: Iabd2aa89fc3b737a999632a16c4f6c30464787c4 --- services/surfaceflinger/Android.mk | 1 + .../DisplayHardware/HWC2On1Adapter.cpp | 4 +- .../DisplayHardware/HWC2On1Adapter.h | 18 +++---- .../surfaceflinger/DisplayHardware/MiniFence.cpp | 42 +++++++++++++++ .../surfaceflinger/DisplayHardware/MiniFence.h | 59 ++++++++++++++++++++++ 5 files changed, 113 insertions(+), 11 deletions(-) create mode 100644 services/surfaceflinger/DisplayHardware/MiniFence.cpp create mode 100644 services/surfaceflinger/DisplayHardware/MiniFence.h diff --git a/services/surfaceflinger/Android.mk b/services/surfaceflinger/Android.mk index afaccd2b5c..a317ea2def 100644 --- a/services/surfaceflinger/Android.mk +++ b/services/surfaceflinger/Android.mk @@ -26,6 +26,7 @@ LOCAL_SRC_FILES := \ DisplayHardware/FramebufferSurface.cpp \ DisplayHardware/HWC2.cpp \ DisplayHardware/HWC2On1Adapter.cpp \ + DisplayHardware/MiniFence.cpp \ DisplayHardware/PowerHAL.cpp \ DisplayHardware/VirtualDisplaySurface.cpp \ Effects/Daltonizer.cpp \ diff --git a/services/surfaceflinger/DisplayHardware/HWC2On1Adapter.cpp b/services/surfaceflinger/DisplayHardware/HWC2On1Adapter.cpp index 418789004a..13bf0b5ae9 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2On1Adapter.cpp +++ b/services/surfaceflinger/DisplayHardware/HWC2On1Adapter.cpp @@ -724,7 +724,7 @@ Error HWC2On1Adapter::Display::getReleaseFences(uint32_t* outNumElements, } auto releaseFence = layer->getReleaseFence(); - if (releaseFence != Fence::NO_FENCE) { + if (releaseFence != MiniFence::NO_FENCE) { if (outputsNonNull) { outLayers[numWritten] = layer->getId(); outFences[numWritten] = releaseFence->dup(); @@ -2003,7 +2003,7 @@ void HWC2On1Adapter::Layer::addReleaseFence(int fenceFd) { mReleaseFence.add(fenceFd); } -const sp& HWC2On1Adapter::Layer::getReleaseFence() const { +const sp& HWC2On1Adapter::Layer::getReleaseFence() const { return mReleaseFence.get(); } diff --git a/services/surfaceflinger/DisplayHardware/HWC2On1Adapter.h b/services/surfaceflinger/DisplayHardware/HWC2On1Adapter.h index 408bc41649..a1d2c884cb 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2On1Adapter.h +++ b/services/surfaceflinger/DisplayHardware/HWC2On1Adapter.h @@ -23,7 +23,7 @@ #undef HWC2_INCLUDE_STRINGIFICATION #undef HWC2_USE_CPP11 -#include +#include "MiniFence.h" #include #include @@ -155,35 +155,35 @@ private: class DeferredFence { public: DeferredFence() - : mFences({Fence::NO_FENCE, Fence::NO_FENCE}) {} + : mFences({MiniFence::NO_FENCE, MiniFence::NO_FENCE}) {} void add(int32_t fenceFd) { - mFences.emplace(new Fence(fenceFd)); + mFences.emplace(new MiniFence(fenceFd)); mFences.pop(); } - const sp& get() const { + const sp& get() const { return mFences.front(); } private: // There are always two fences in this queue. - std::queue> mFences; + std::queue> mFences; }; class FencedBuffer { public: - FencedBuffer() : mBuffer(nullptr), mFence(Fence::NO_FENCE) {} + FencedBuffer() : mBuffer(nullptr), mFence(MiniFence::NO_FENCE) {} void setBuffer(buffer_handle_t buffer) { mBuffer = buffer; } - void setFence(int fenceFd) { mFence = new Fence(fenceFd); } + void setFence(int fenceFd) { mFence = new MiniFence(fenceFd); } buffer_handle_t getBuffer() const { return mBuffer; } int getFence() const { return mFence->dup(); } private: buffer_handle_t mBuffer; - sp mFence; + sp mFence; }; class Display { @@ -552,7 +552,7 @@ private: uint32_t getZ() const { return mZ; } void addReleaseFence(int fenceFd); - const sp& getReleaseFence() const; + const sp& getReleaseFence() const; void setHwc1Id(size_t id) { mHwc1Id = id; } size_t getHwc1Id() const { return mHwc1Id; } diff --git a/services/surfaceflinger/DisplayHardware/MiniFence.cpp b/services/surfaceflinger/DisplayHardware/MiniFence.cpp new file mode 100644 index 0000000000..ecfb0635cb --- /dev/null +++ b/services/surfaceflinger/DisplayHardware/MiniFence.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2017 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 "MiniFence.h" + +#include + +namespace android { + +const sp MiniFence::NO_FENCE = sp(new MiniFence); + +MiniFence::MiniFence() : + mFenceFd(-1) { +} + +MiniFence::MiniFence(int fenceFd) : + mFenceFd(fenceFd) { +} + +MiniFence::~MiniFence() { + if (mFenceFd != -1) { + close(mFenceFd); + } +} + +int MiniFence::dup() const { + return ::dup(mFenceFd); +} +} diff --git a/services/surfaceflinger/DisplayHardware/MiniFence.h b/services/surfaceflinger/DisplayHardware/MiniFence.h new file mode 100644 index 0000000000..75de764d2c --- /dev/null +++ b/services/surfaceflinger/DisplayHardware/MiniFence.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2017 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 MINIFENCE_H +#define MINIFENCE_H + +#include + +namespace android { + +/* MiniFence is a minimal re-implementation of Fence from libui. It exists to + * avoid linking the HWC2on1Adapter to libui and satisfy Treble requirements. + */ +class MiniFence : public LightRefBase { +public: + static const sp NO_FENCE; + + // Construct a new MiniFence object with an invalid file descriptor. + MiniFence(); + + // Construct a new MiniFence object to manage a given fence file descriptor. + // When the new MiniFence object is destructed the file descriptor will be + // closed. + explicit MiniFence(int fenceFd); + + // Not copyable or movable. + MiniFence(const MiniFence& rhs) = delete; + MiniFence& operator=(const MiniFence& rhs) = delete; + MiniFence(MiniFence&& rhs) = delete; + MiniFence& operator=(MiniFence&& rhs) = delete; + + // Return a duplicate of the fence file descriptor. The caller is + // responsible for closing the returned file descriptor. On error, -1 will + // be returned and errno will indicate the problem. + int dup() const; + +private: + // Only allow instantiation using ref counting. + friend class LightRefBase; + ~MiniFence(); + + int mFenceFd; + +}; +} +#endif //MINIFENCE_H -- cgit v1.2.3-59-g8ed1b