diff options
| author | 2017-03-07 23:16:12 +0000 | |
|---|---|---|
| committer | 2017-03-07 23:16:13 +0000 | |
| commit | 077f132c19e731d25973bbab1c6dc319beb3f460 (patch) | |
| tree | d885e7614623502f3431d1fe726acb16473a1d7e | |
| parent | 10012f0ce0c06ad56459a41aabef682d0b1b06d0 (diff) | |
| parent | c859147db5e9d5aa8a5043c0111e2799e1db042b (diff) | |
Merge "Add MiniFence to drop HWC2on1Adapter libui dep"
5 files changed, 113 insertions, 11 deletions
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<Fence>& HWC2On1Adapter::Layer::getReleaseFence() const { +const sp<MiniFence>& 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 <ui/Fence.h> +#include "MiniFence.h" #include <atomic> #include <map> @@ -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<Fence>& get() const { + const sp<MiniFence>& get() const { return mFences.front(); } private: // There are always two fences in this queue. - std::queue<sp<Fence>> mFences; + std::queue<sp<MiniFence>> 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<Fence> mFence; + sp<MiniFence> mFence; }; class Display { @@ -552,7 +552,7 @@ private: uint32_t getZ() const { return mZ; } void addReleaseFence(int fenceFd); - const sp<Fence>& getReleaseFence() const; + const sp<MiniFence>& 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 <unistd.h> + +namespace android { + +const sp<MiniFence> MiniFence::NO_FENCE = sp<MiniFence>(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 <utils/RefBase.h> + +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<MiniFence> { +public: + static const sp<MiniFence> 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>; + ~MiniFence(); + + int mFenceFd; + +}; +} +#endif //MINIFENCE_H |