Retire hwc2/MiniFence
sp<MiniFence> is replaced by shared_ptr<unique_fd>.
Bug: 154346346
Test: boot
Signed-off-by: Roman Kiryanov <rkir@google.com>
Merged-In: Id02e959b897e6e667e092705815d1082da15a2b4
Change-Id: Ic2ba6df78bdc3138e0c617feece75fccb250200f
diff --git a/system/hwc2/Android.mk b/system/hwc2/Android.mk
index 698de73..ac74218 100644
--- a/system/hwc2/Android.mk
+++ b/system/hwc2/Android.mk
@@ -32,6 +32,7 @@
emulator_hwcomposer_cflags += \
-DLOG_TAG=\"hwc2\" \
-DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION) \
+ -DANDROID_BASE_UNIQUE_FD_DISABLE_IMPLICIT_CONVERSION
emulator_hwcomposer_c_includes += \
system/core/libsync \
@@ -45,8 +46,7 @@
emulator_hwcomposer_relative_path := hw
emulator_hwcomposer2_src_files := \
- EmuHWC2.cpp \
- MiniFence.cpp
+ EmuHWC2.cpp
include $(CLEAR_VARS)
diff --git a/system/hwc2/EmuHWC2.h b/system/hwc2/EmuHWC2.h
index 8cb71c1..1a8f275 100644
--- a/system/hwc2/EmuHWC2.h
+++ b/system/hwc2/EmuHWC2.h
@@ -24,8 +24,10 @@
#undef HWC2_USE_CPP11
#include <utils/Thread.h>
+#include <android-base/unique_fd.h>
#include <atomic>
#include <map>
+#include <memory>
#include <mutex>
#include <numeric>
#include <sstream>
@@ -37,7 +39,6 @@
#include <cutils/native_handle.h>
#include "cbmanager.h"
-#include "MiniFence.h"
#include "HostConnection.h"
namespace android {
@@ -126,17 +127,19 @@
// layer. This class is a container for these two.
class FencedBuffer {
public:
- FencedBuffer() : mBuffer(nullptr), mFence(MiniFence::NO_FENCE) {}
+ FencedBuffer() : mBuffer(nullptr) {}
void setBuffer(buffer_handle_t buffer) { mBuffer = buffer; }
- void setFence(int fenceFd) { mFence = new MiniFence(fenceFd); }
+ void setFence(int fenceFd) {
+ mFence = std::make_shared<base::unique_fd>(fenceFd);
+ }
buffer_handle_t getBuffer() const { return mBuffer; }
- int getFence() const { return mFence->dup(); }
+ int getFence() const { return mFence ? dup(mFence->get()) : -1; }
private:
buffer_handle_t mBuffer;
- sp<MiniFence> mFence;
+ std::shared_ptr<base::unique_fd> mFence;
};
typedef struct compose_layer {
diff --git a/system/hwc2/MiniFence.cpp b/system/hwc2/MiniFence.cpp
deleted file mode 100644
index ecfb063..0000000
--- a/system/hwc2/MiniFence.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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/system/hwc2/MiniFence.h b/system/hwc2/MiniFence.h
deleted file mode 100644
index 31c9536..0000000
--- a/system/hwc2/MiniFence.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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 EMU_HWC2_MINIFENCE_H
-#define EMU_HWC2_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 //EMU_HWC2_MINIFENCE_H