drm_hwcomposer: Use shared pointer type for the pipeline_ variable
The change will help with resource management in further patches.
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
diff --git a/hwc2_device/DrmHwcTwo.cpp b/hwc2_device/DrmHwcTwo.cpp
index 64755c3..99756eb 100644
--- a/hwc2_device/DrmHwcTwo.cpp
+++ b/hwc2_device/DrmHwcTwo.cpp
@@ -35,13 +35,13 @@
displays_[kPrimaryDisplay] = std::make_unique<
HwcDisplay>(kPrimaryDisplay, HWC2::DisplayType::Physical, this);
/* Initializes null-display */
- displays_[kPrimaryDisplay]->SetPipeline(nullptr);
+ displays_[kPrimaryDisplay]->SetPipeline({});
}
if (displays_[kPrimaryDisplay]->IsInHeadlessMode() &&
!display_handles_.empty()) {
/* Reattach first secondary display to take place of the primary */
- auto *pipe = display_handles_.begin()->first;
+ auto pipe = display_handles_.begin()->first;
ALOGI("Primary display was disconnected, reattaching '%s' as new primary",
pipe->connector->Get()->GetName().c_str());
UnbindDisplay(pipe);
@@ -66,10 +66,10 @@
}
}
-bool DrmHwcTwo::BindDisplay(DrmDisplayPipeline *pipeline) {
+bool DrmHwcTwo::BindDisplay(std::shared_ptr<DrmDisplayPipeline> pipeline) {
if (display_handles_.count(pipeline) != 0) {
ALOGE("%s, pipeline is already used by another display, FIXME!!!: %p",
- __func__, pipeline);
+ __func__, pipeline.get());
return false;
}
@@ -96,9 +96,9 @@
return true;
}
-bool DrmHwcTwo::UnbindDisplay(DrmDisplayPipeline *pipeline) {
+bool DrmHwcTwo::UnbindDisplay(std::shared_ptr<DrmDisplayPipeline> pipeline) {
if (display_handles_.count(pipeline) == 0) {
- ALOGE("%s, can't find the display, pipeline: %p", __func__, pipeline);
+ ALOGE("%s, can't find the display, pipeline: %p", __func__, pipeline.get());
return false;
}
auto handle = display_handles_[pipeline];
@@ -112,7 +112,7 @@
ALOGE("%s, can't find the display, handle: %" PRIu64, __func__, handle);
return false;
}
- displays_[handle]->SetPipeline(nullptr);
+ displays_[handle]->SetPipeline({});
/* We must defer display disposal and removal, since it may still have pending
* HWC_API calls scheduled and waiting until ueventlistener thread releases
diff --git a/hwc2_device/DrmHwcTwo.h b/hwc2_device/DrmHwcTwo.h
index 81c5155..8701feb 100644
--- a/hwc2_device/DrmHwcTwo.h
+++ b/hwc2_device/DrmHwcTwo.h
@@ -61,8 +61,8 @@
}
// PipelineToFrontendBindingInterface
- bool BindDisplay(DrmDisplayPipeline *pipeline) override;
- bool UnbindDisplay(DrmDisplayPipeline *pipeline) override;
+ bool BindDisplay(std::shared_ptr<DrmDisplayPipeline> pipeline) override;
+ bool UnbindDisplay(std::shared_ptr<DrmDisplayPipeline> pipeline) override;
void FinalizeDisplayBinding() override;
void SendVsyncEventToClient(hwc2_display_t displayid, int64_t timestamp,
@@ -75,7 +75,8 @@
ResourceManager resource_manager_;
std::map<hwc2_display_t, std::unique_ptr<HwcDisplay>> displays_;
- std::map<DrmDisplayPipeline *, hwc2_display_t> display_handles_;
+ std::map<std::shared_ptr<DrmDisplayPipeline>, hwc2_display_t>
+ display_handles_;
std::string mDumpString;
diff --git a/hwc2_device/HwcDisplay.cpp b/hwc2_device/HwcDisplay.cpp
index efd8c14..4ef98c3 100644
--- a/hwc2_device/HwcDisplay.cpp
+++ b/hwc2_device/HwcDisplay.cpp
@@ -83,12 +83,12 @@
HwcDisplay::~HwcDisplay() = default;
-void HwcDisplay::SetPipeline(DrmDisplayPipeline *pipeline) {
+void HwcDisplay::SetPipeline(std::shared_ptr<DrmDisplayPipeline> pipeline) {
Deinit();
- pipeline_ = pipeline;
+ pipeline_ = std::move(pipeline);
- if (pipeline != nullptr || handle_ == kPrimaryDisplay) {
+ if (pipeline_ != nullptr || handle_ == kPrimaryDisplay) {
Init();
hwc2_->ScheduleHotplugEvent(handle_, /*connected = */ true);
} else {
diff --git a/hwc2_device/HwcDisplay.h b/hwc2_device/HwcDisplay.h
index bf95c3e..d9dc4eb 100644
--- a/hwc2_device/HwcDisplay.h
+++ b/hwc2_device/HwcDisplay.h
@@ -44,7 +44,7 @@
~HwcDisplay();
/* SetPipeline should be carefully used only by DrmHwcTwo hotplug handlers */
- void SetPipeline(DrmDisplayPipeline *pipeline);
+ void SetPipeline(std::shared_ptr<DrmDisplayPipeline> pipeline);
HWC2::Error CreateComposition(AtomicCommitArgs &a_args);
std::vector<HwcLayer *> GetOrderLayersByZPos();
@@ -193,7 +193,7 @@
int64_t staged_mode_change_time_{};
uint32_t staged_mode_config_id_{};
- DrmDisplayPipeline *pipeline_{};
+ std::shared_ptr<DrmDisplayPipeline> pipeline_;
std::unique_ptr<Backend> backend_;
std::shared_ptr<FlatteningController> flatcon_;