drm_hwcomposer: Connect ComposerClient with HwcDisplay
Implements the HWC3 frontend by calling the HWC2 interfaces already
exposed through DrmHwc, HwcDisplay, HwcLayer, and so on.
Convert between hwc2 types and hwc3 types in ComposerClient.
The following changes from !238 were used as a basis for this change,
and squashed together:
(drm_hwcomposer: Connect ComposerClient with HwcDisplay)
(drm_hwcomposer: Implement HWC3 frontend by calling down to HWC2)
The projects [1, 2] were used as a reference for the implementation.
[1]: https://android.googlesource.com/platform/hardware/google/graphics/common/+/refs/heads/main/hwc3/
[2]: https://android.googlesource.com/device/generic/goldfish-opengl/+/refs/heads/master/system/hwc3/
Co-authored-by: Normunds Rieksts <normunds.rieksts@arm.com>
Co-authored-by: Dennis Tsiang <dennis.tsiang@arm.com>
Change-Id: I98c10175d5c5f01aec1e192863238e16aa1537ec
Signed-off-by: Drew Davenport <ddavenport@chromium.org>
Signed-off-by: Drew Davenport <ddavenport@google.com>
diff --git a/hwc3/ComposerClient.h b/hwc3/ComposerClient.h
index bdf4b0a..616f8aa 100644
--- a/hwc3/ComposerClient.h
+++ b/hwc3/ComposerClient.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2024 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.
@@ -16,22 +16,42 @@
#pragma once
-#include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h>
-#include <aidl/android/hardware/graphics/composer3/BnComposerClient.h>
-#include <utils/Mutex.h>
-
#include <memory>
+#include "aidl/android/hardware/graphics/composer3/BnComposerClient.h"
+#include "aidl/android/hardware/graphics/composer3/LayerCommand.h"
+#include "hwc3/CommandResultWriter.h"
+#include "hwc3/ComposerResources.h"
+#include "hwc3/Utils.h"
+#include "utils/Mutex.h"
+
using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
using AidlNativeHandle = aidl::android::hardware::common::NativeHandle;
+namespace android {
+
+class HwcDisplay;
+class HwcLayer;
+
+} // namespace android
+
namespace aidl::android::hardware::graphics::composer3::impl {
+class DrmHwcThree;
+
+struct HwcLayerWrapper {
+ int64_t layer_id;
+ ::android::HwcLayer* layer;
+};
+
class ComposerClient : public BnComposerClient {
public:
- ComposerClient() = default;
+ ComposerClient();
~ComposerClient() override;
+ bool Init();
+ std::string Dump();
+
// composer3 interface
ndk::ScopedAStatus createLayer(int64_t display, int32_t buffer_slot_count,
int64_t* layer) override;
@@ -119,6 +139,71 @@
protected:
::ndk::SpAIBinder createBinder() override;
+
+ private:
+ // Layer commands
+ void DispatchLayerCommand(int64_t display_id, const LayerCommand& command);
+ void ExecuteSetLayerBuffer(int64_t display_id, HwcLayerWrapper& layer_id,
+ const Buffer& buffer);
+ void ExecuteSetLayerBlendMode(int64_t display_id, HwcLayerWrapper& layer,
+ const ParcelableBlendMode& blend_mode);
+ void ExecuteSetLayerComposition(int64_t display_id, HwcLayerWrapper& layer,
+ const ParcelableComposition& composition);
+ void ExecuteSetLayerDataspace(int64_t display_id, HwcLayerWrapper& layer,
+ const ParcelableDataspace& dataspace);
+ void ExecuteSetLayerDisplayFrame(int64_t display_id, HwcLayerWrapper& layer,
+ const common::Rect& rect);
+ void ExecuteSetLayerPlaneAlpha(int64_t display_id, HwcLayerWrapper& layer,
+ const PlaneAlpha& plane_alpha);
+ void ExecuteSetLayerSourceCrop(int64_t display_id, HwcLayerWrapper& layer,
+ const common::FRect& source_crop);
+ void ExecuteSetLayerTransform(int64_t display_id, HwcLayerWrapper& layer,
+ const ParcelableTransform& transform);
+ void ExecuteSetLayerZOrder(int64_t display_id, HwcLayerWrapper& layer,
+ const ZOrder& z_order);
+ void ExecuteSetLayerBrightness(int64_t display_id, HwcLayerWrapper& layer,
+ const LayerBrightness& brightness);
+
+ // Display commands
+ void ExecuteDisplayCommand(const DisplayCommand& command);
+ void ExecuteSetDisplayBrightness(uint64_t display_id,
+ const DisplayBrightness& command);
+ void ExecuteSetDisplayColorTransform(uint64_t display_id,
+ const std::vector<float>& matrix);
+ void ExecuteSetDisplayClientTarget(uint64_t display_id,
+ const ClientTarget& command);
+ void ExecuteSetDisplayOutputBuffer(uint64_t display_id, const Buffer& buffer);
+ void ExecuteValidateDisplay(
+ int64_t display_id,
+ std::optional<ClockMonotonicTimestamp> expected_present_time);
+ void ExecuteAcceptDisplayChanges(int64_t display_id);
+ void ExecutePresentDisplay(int64_t display_id);
+ void ExecutePresentOrValidateDisplay(
+ int64_t display_id,
+ std::optional<ClockMonotonicTimestamp> expected_present_time);
+
+ static hwc3::Error ValidateDisplayInternal(
+ ::android::HwcDisplay& display, std::vector<int64_t>* out_changed_layers,
+ std::vector<Composition>* out_composition_types,
+ int32_t* out_display_request_mask,
+ std::vector<int64_t>* out_requested_layers,
+ std::vector<int32_t>* out_request_masks,
+ ClientTargetProperty* out_client_target_property,
+ DimmingStage* out_dimming_stage);
+
+ hwc3::Error PresentDisplayInternal(
+ uint64_t display_id, ::android::base::unique_fd& out_display_fence,
+ std::unordered_map<int64_t, ::android::base::unique_fd>&
+ out_release_fences);
+
+ ::android::HwcDisplay* GetDisplay(uint64_t display_id);
+
+ std::unique_ptr<CommandResultWriter> cmd_result_writer_;
+
+ // Manages importing and caching gralloc buffers for displays and layers.
+ std::unique_ptr<ComposerResources> composer_resources_;
+
+ std::unique_ptr<DrmHwcThree> hwc_;
};
} // namespace aidl::android::hardware::graphics::composer3::impl