188 lines
8.7 KiB
C++
188 lines
8.7 KiB
C++
/*
|
|
* 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.
|
|
* 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.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
#include "aidl/android/hardware/graphics/composer3/BnComposerClient.h"
|
|
#include "aidl/android/hardware/graphics/composer3/LayerCommand.h"
|
|
#include "hwc/HwcLayer.h"
|
|
#include "hwc3/CommandResultWriter.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::drm_hwcomposer {
|
|
class CompositionStatsPoller;
|
|
class HwcDisplay;
|
|
} // namespace android::drm_hwcomposer
|
|
|
|
namespace aidl::android::hardware::graphics::composer3::impl {
|
|
using AidlColorMode = ColorMode;
|
|
|
|
class DrmHwcThree;
|
|
|
|
class ComposerClient : public BnComposerClient {
|
|
public:
|
|
ComposerClient();
|
|
~ComposerClient() override;
|
|
|
|
void Init();
|
|
std::string Dump();
|
|
|
|
// composer3 interface
|
|
ndk::ScopedAStatus createLayer(int64_t display, int32_t buffer_slot_count,
|
|
int64_t* layer) override;
|
|
ndk::ScopedAStatus createVirtualDisplay(int32_t width, int32_t height,
|
|
AidlPixelFormat format_hint,
|
|
int32_t output_buffer_slot_count,
|
|
VirtualDisplay* display) override;
|
|
ndk::ScopedAStatus destroyLayer(int64_t display, int64_t layer) override;
|
|
ndk::ScopedAStatus destroyVirtualDisplay(int64_t display) override;
|
|
ndk::ScopedAStatus executeCommands(
|
|
const std::vector<DisplayCommand>& commands,
|
|
std::vector<CommandResultPayload>* results) override;
|
|
ndk::ScopedAStatus getActiveConfig(int64_t display, int32_t* config) override;
|
|
ndk::ScopedAStatus getColorModes(
|
|
int64_t display, std::vector<ColorMode>* color_modes) override;
|
|
ndk::ScopedAStatus getDataspaceSaturationMatrix(
|
|
common::Dataspace dataspace, std::vector<float>* matrix) override;
|
|
ndk::ScopedAStatus getDisplayAttribute(int64_t display, int32_t config,
|
|
DisplayAttribute attribute,
|
|
int32_t* value) override;
|
|
ndk::ScopedAStatus getDisplayCapabilities(
|
|
int64_t display, std::vector<DisplayCapability>* caps) override;
|
|
ndk::ScopedAStatus getDisplayConfigs(int64_t display,
|
|
std::vector<int32_t>* configs) override;
|
|
ndk::ScopedAStatus getDisplayConnectionType(
|
|
int64_t display, DisplayConnectionType* type) override;
|
|
ndk::ScopedAStatus getDisplayIdentificationData(
|
|
int64_t display, DisplayIdentification* id) override;
|
|
ndk::ScopedAStatus getDisplayName(int64_t display,
|
|
std::string* name) override;
|
|
ndk::ScopedAStatus getDisplayVsyncPeriod(int64_t display,
|
|
int32_t* vsync_period) override;
|
|
ndk::ScopedAStatus getDisplayedContentSample(
|
|
int64_t display, int64_t max_frames, int64_t timestamp,
|
|
DisplayContentSample* samples) override;
|
|
ndk::ScopedAStatus getDisplayedContentSamplingAttributes(
|
|
int64_t display, DisplayContentSamplingAttributes* attrs) override;
|
|
ndk::ScopedAStatus getDisplayPhysicalOrientation(
|
|
int64_t display, common::Transform* orientation) override;
|
|
ndk::ScopedAStatus getHdrCapabilities(int64_t display,
|
|
HdrCapabilities* caps) override;
|
|
ndk::ScopedAStatus getMaxVirtualDisplayCount(int32_t* count) override;
|
|
ndk::ScopedAStatus getPerFrameMetadataKeys(
|
|
int64_t display, std::vector<PerFrameMetadataKey>* keys) override;
|
|
ndk::ScopedAStatus getReadbackBufferAttributes(
|
|
int64_t display, ReadbackBufferAttributes* attrs) override;
|
|
ndk::ScopedAStatus getReadbackBufferFence(
|
|
int64_t display, ndk::ScopedFileDescriptor* acquire_fence) override;
|
|
ndk::ScopedAStatus getRenderIntents(
|
|
int64_t display, AidlColorMode mode,
|
|
std::vector<RenderIntent>* intents) override;
|
|
ndk::ScopedAStatus getSupportedContentTypes(
|
|
int64_t display, std::vector<ContentType>* types) override;
|
|
ndk::ScopedAStatus getDisplayDecorationSupport(
|
|
int64_t display,
|
|
std::optional<common::DisplayDecorationSupport>* support) override;
|
|
ndk::ScopedAStatus registerCallback(
|
|
const std::shared_ptr<IComposerCallback>& callback) override;
|
|
ndk::ScopedAStatus setActiveConfig(int64_t display, int32_t config) override;
|
|
ndk::ScopedAStatus setActiveConfigWithConstraints(
|
|
int64_t display, int32_t config,
|
|
const VsyncPeriodChangeConstraints& constraints,
|
|
VsyncPeriodChangeTimeline* timeline) override;
|
|
ndk::ScopedAStatus setBootDisplayConfig(int64_t display,
|
|
int32_t config) override;
|
|
ndk::ScopedAStatus clearBootDisplayConfig(int64_t display) override;
|
|
ndk::ScopedAStatus getPreferredBootDisplayConfig(int64_t display,
|
|
int32_t* config) override;
|
|
ndk::ScopedAStatus setAutoLowLatencyMode(int64_t display, bool on) override;
|
|
ndk::ScopedAStatus setClientTargetSlotCount(int64_t display,
|
|
int32_t count) override;
|
|
ndk::ScopedAStatus setColorMode(int64_t display, AidlColorMode mode,
|
|
RenderIntent intent) override;
|
|
ndk::ScopedAStatus setContentType(int64_t display, ContentType type) override;
|
|
ndk::ScopedAStatus setDisplayedContentSamplingEnabled(
|
|
int64_t display, bool enable, FormatColorComponent component_mask,
|
|
int64_t max_frames) override;
|
|
ndk::ScopedAStatus setPowerMode(int64_t display, PowerMode mode) override;
|
|
ndk::ScopedAStatus setReadbackBuffer(
|
|
int64_t display, const AidlNativeHandle& buffer,
|
|
const ndk::ScopedFileDescriptor& release_fence) override;
|
|
ndk::ScopedAStatus setVsyncEnabled(int64_t display, bool enabled) override;
|
|
ndk::ScopedAStatus setIdleTimerEnabled(int64_t display,
|
|
int32_t timeout) override;
|
|
ndk::ScopedAStatus getOverlaySupport(
|
|
OverlayProperties* out_overlay_properties) override;
|
|
ndk::ScopedAStatus getHdrConversionCapabilities(
|
|
std::vector<common::HdrConversionCapability>* out_capabilities) override;
|
|
ndk::ScopedAStatus setHdrConversionStrategy(
|
|
const common::HdrConversionStrategy& conversion_strategy,
|
|
common::Hdr* out_hdr) override;
|
|
ndk::ScopedAStatus setRefreshRateChangedCallbackDebugEnabled(
|
|
int64_t display, bool enabled) override;
|
|
ndk::ScopedAStatus getDisplayConfigurations(
|
|
int64_t display, int32_t max_frame_interval_ns,
|
|
std::vector<DisplayConfiguration>* configurations) override;
|
|
ndk::ScopedAStatus notifyExpectedPresent(
|
|
int64_t display, const ClockMonotonicTimestamp& expected_present_time,
|
|
int32_t frame_interval_ns) override;
|
|
|
|
#if __ANDROID_API__ >= 36
|
|
ndk::ScopedAStatus startHdcpNegotiation(
|
|
int64_t display, const drm::HdcpLevels& levels) override;
|
|
ndk::ScopedAStatus getMaxLayerPictureProfiles(int64_t display,
|
|
int32_t* max_profiles) override;
|
|
ndk::ScopedAStatus getLuts(int64_t display,
|
|
const std::vector<Buffer>& buffers,
|
|
std::vector<Luts>* out_luts) override;
|
|
#endif
|
|
|
|
protected:
|
|
::ndk::SpAIBinder createBinder() override;
|
|
|
|
private:
|
|
hwc3::Error ImportLayerBuffer(
|
|
int64_t display_handle, int64_t layer_id, const Buffer& buffer,
|
|
::android::drm_hwcomposer::HwcLayer::Buffer* out_buffer);
|
|
|
|
// Layer commands
|
|
void DispatchLayerCommand(int64_t display_handle,
|
|
const LayerCommand& command);
|
|
|
|
// Display commands
|
|
void ExecuteDisplayCommand(const DisplayCommand& command);
|
|
void ExecuteSetDisplayClientTarget(int64_t display_handle,
|
|
const ClientTarget& command);
|
|
void ExecuteSetDisplayOutputBuffer(int64_t display_handle,
|
|
const Buffer& buffer);
|
|
|
|
::android::drm_hwcomposer::HwcDisplay* GetDisplay(int64_t display_handle);
|
|
|
|
std::unique_ptr<CommandResultWriter> cmd_result_writer_;
|
|
|
|
std::unique_ptr<DrmHwcThree> hwc_;
|
|
|
|
std::unique_ptr<::android::drm_hwcomposer::CompositionStatsPoller>
|
|
stats_poller_;
|
|
};
|
|
|
|
} // namespace aidl::android::hardware::graphics::composer3::impl
|