diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-01-24 00:01:07 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-01-24 00:01:07 +0000 |
commit | 88cf16ad88f5c0883bb406e698fb342aa2c120d1 (patch) | |
tree | 0ad4eb92941a77d32f72109aaa24e4fcf5ea50f1 | |
parent | 1b1d764259014174a6c45e3f905cfa686247c35c (diff) | |
parent | 998bbe04244331287fa5c3e22c174d75185bc622 (diff) | |
download | goldfish-opengl-88cf16ad88f5c0883bb406e698fb342aa2c120d1.tar.gz |
Snap for 11349503 from 998bbe04244331287fa5c3e22c174d75185bc622 to sdk-release
Change-Id: Iec7263ae47f714d3cd0eff8ebec6a06fc98181a3
-rw-r--r-- | system/hwc3/Android.bp | 5 | ||||
-rw-r--r-- | system/hwc3/ClientFrameComposer.cpp | 2 | ||||
-rw-r--r-- | system/hwc3/ComposerClient.cpp | 8 | ||||
-rw-r--r-- | system/hwc3/ComposerResources.cpp | 14 | ||||
-rw-r--r-- | system/hwc3/Display.cpp | 17 | ||||
-rw-r--r-- | system/hwc3/DisplayFinder.cpp | 48 | ||||
-rw-r--r-- | system/hwc3/Drm.cpp | 4 | ||||
-rw-r--r-- | system/hwc3/Drm.h | 4 | ||||
-rw-r--r-- | system/hwc3/DrmBuffer.h | 2 | ||||
-rw-r--r-- | system/hwc3/DrmClient.cpp | 2 | ||||
-rw-r--r-- | system/hwc3/DrmClient.h | 4 | ||||
-rw-r--r-- | system/hwc3/DrmConnector.cpp | 34 | ||||
-rw-r--r-- | system/hwc3/DrmConnector.h | 9 | ||||
-rw-r--r-- | system/hwc3/DrmCrtc.h | 4 | ||||
-rw-r--r-- | system/hwc3/DrmDisplay.cpp | 5 | ||||
-rw-r--r-- | system/hwc3/DrmEventListener.cpp | 4 | ||||
-rw-r--r-- | system/hwc3/DrmProperty.h | 5 | ||||
-rw-r--r-- | system/hwc3/DrmSwapchain.h | 2 | ||||
-rw-r--r-- | system/hwc3/Gralloc.cpp | 14 | ||||
-rw-r--r-- | system/hwc3/GuestFrameComposer.cpp | 287 | ||||
-rw-r--r-- | system/hwc3/HostFrameComposer.cpp | 55 | ||||
-rw-r--r-- | system/hwc3/Time.h | 8 | ||||
-rw-r--r-- | system/hwc3/VsyncThread.cpp | 3 |
23 files changed, 268 insertions, 272 deletions
diff --git a/system/hwc3/Android.bp b/system/hwc3/Android.bp index 45e122c2..a58e1257 100644 --- a/system/hwc3/Android.bp +++ b/system/hwc3/Android.bp @@ -86,6 +86,11 @@ cc_binary { "VsyncThread.cpp", ], + cflags: [ + "-Wall", + "-Werror=conversion", + ], + vintf_fragments: ["hwc3.xml"], init_rc: ["hwc3.rc"], diff --git a/system/hwc3/ClientFrameComposer.cpp b/system/hwc3/ClientFrameComposer.cpp index af0b3278..bccfa69d 100644 --- a/system/hwc3/ClientFrameComposer.cpp +++ b/system/hwc3/ClientFrameComposer.cpp @@ -154,7 +154,7 @@ HWC3::Error ClientFrameComposer::presentDisplay( ::android::base::unique_fd fence = display->getClientTarget().getFence(); auto [flushError, flushCompleteFence] = mDrmClient.flushToDisplay( - displayId, displayInfo.clientTargetDrmBuffer, fence); + static_cast<uint32_t>(displayId), displayInfo.clientTargetDrmBuffer, fence); if (flushError != HWC3::Error::None) { ALOGE("%s: display:%" PRIu64 " failed to flush drm buffer" PRIu64, __FUNCTION__, displayId); diff --git a/system/hwc3/ComposerClient.cpp b/system/hwc3/ComposerClient.cpp index 2cadedeb..16d8eb1a 100644 --- a/system/hwc3/ComposerClient.cpp +++ b/system/hwc3/ComposerClient.cpp @@ -141,13 +141,13 @@ HWC3::Error ComposerClient::init() { } const auto HotplugCallback = [this](bool connected, // - int32_t id, // + uint32_t id, // uint32_t width, // uint32_t height, // uint32_t dpiX, // uint32_t dpiY, // uint32_t refreshRate) { - handleHotplug(connected, id, width, height, dpiX, dpiY, refreshRate); + handleHotplug(connected, id, width, height, dpiX, dpiY, refreshRate); }; error = mComposer->registerOnHotplugCallback(HotplugCallback); if (error != HWC3::Error::None) { @@ -181,7 +181,7 @@ ndk::ScopedAStatus ComposerClient::createLayer(int64_t displayId, return ToBinderStatus(error); } - error = mResources->addLayer(displayId, *layerId, bufferSlotCount); + error = mResources->addLayer(displayId, *layerId, static_cast<uint32_t>(bufferSlotCount)); if (error != HWC3::Error::None) { ALOGE("%s: display:%" PRIu64 " resources failed to create layer", __FUNCTION__, displayId); @@ -641,7 +641,7 @@ ndk::ScopedAStatus ComposerClient::setClientTargetSlotCount(int64_t displayId, GET_DISPLAY_OR_RETURN_ERROR(); return ToBinderStatus( - mResources->setDisplayClientTargetCacheSize(displayId, count)); + mResources->setDisplayClientTargetCacheSize(displayId, static_cast<uint32_t>(count))); } ndk::ScopedAStatus ComposerClient::setColorMode(int64_t displayId, diff --git a/system/hwc3/ComposerResources.cpp b/system/hwc3/ComposerResources.cpp index 2e17c2c6..35990889 100644 --- a/system/hwc3/ComposerResources.cpp +++ b/system/hwc3/ComposerResources.cpp @@ -189,9 +189,9 @@ HWC3::Error ComposerResources::getDisplayClientTarget( bufferHandle = ::android::makeFromAidl(*buffer.handle); } - return toHwc3Error(mImpl->getDisplayClientTarget( - display, buffer.slot, useCache, bufferHandle, outHandle, - releaser->getReplacedHandle())); + return toHwc3Error(mImpl->getDisplayClientTarget(display, static_cast<uint32_t>(buffer.slot), + useCache, bufferHandle, outHandle, + releaser->getReplacedHandle())); } HWC3::Error ComposerResources::getDisplayOutputBuffer( @@ -207,9 +207,9 @@ HWC3::Error ComposerResources::getDisplayOutputBuffer( bufferHandle = ::android::makeFromAidl(*buffer.handle); } - return toHwc3Error(mImpl->getDisplayOutputBuffer( - display, buffer.slot, useCache, bufferHandle, outHandle, - releaser->getReplacedHandle())); + return toHwc3Error(mImpl->getDisplayOutputBuffer(display, static_cast<uint32_t>(buffer.slot), + useCache, bufferHandle, outHandle, + releaser->getReplacedHandle())); } HWC3::Error ComposerResources::getLayerBuffer( @@ -231,7 +231,7 @@ HWC3::Error ComposerResources::getLayerBuffer( } DEBUG_LOG("%s fromCache:%s", __FUNCTION__, (useCache ? "yes" : "no")); - return toHwc3Error(mImpl->getLayerBuffer(display, layer, buffer.slot, + return toHwc3Error(mImpl->getLayerBuffer(display, layer, static_cast<uint32_t>(buffer.slot), useCache, bufferHandle, outHandle, releaser->getReplacedHandle())); } diff --git a/system/hwc3/Display.cpp b/system/hwc3/Display.cpp index 14f02e21..8e6cfc85 100644 --- a/system/hwc3/Display.cpp +++ b/system/hwc3/Display.cpp @@ -31,6 +31,7 @@ #include "Common.h" #include "Device.h" +#include "Time.h" namespace aidl::android::hardware::graphics::composer3::impl { namespace { @@ -142,12 +143,12 @@ HWC3::Error Display::updateParameters( ALOGE("%s: failed to find config %" PRId32, __func__, *mActiveConfigId); return HWC3::Error::NoResources; } - it->second.setAttribute(DisplayAttribute::VSYNC_PERIOD, - 1000 * 1000 * 1000 / refreshRateHz); - it->second.setAttribute(DisplayAttribute::WIDTH, width); - it->second.setAttribute(DisplayAttribute::HEIGHT, height); - it->second.setAttribute(DisplayAttribute::DPI_X, dpiX); - it->second.setAttribute(DisplayAttribute::DPI_Y, dpiY); + DisplayConfig& config = it->second; + config.setAttribute(DisplayAttribute::VSYNC_PERIOD, HertzToPeriodNanos(refreshRateHz)); + config.setAttribute(DisplayAttribute::WIDTH, static_cast<int32_t>(width)); + config.setAttribute(DisplayAttribute::HEIGHT, static_cast<int32_t>(height)); + config.setAttribute(DisplayAttribute::DPI_X, static_cast<int32_t>(dpiX)); + config.setAttribute(DisplayAttribute::DPI_Y, static_cast<int32_t>(dpiY)); if (edid.has_value()) { mEdid = *edid; @@ -293,7 +294,7 @@ HWC3::Error Display::getDisplayIdentificationData( return HWC3::Error::BadParameter; } - outIdentification->port = mId; + outIdentification->port = static_cast<int8_t>(mId); outIdentification->data = mEdid; return HWC3::Error::None; @@ -1012,7 +1013,7 @@ void Display::setLegacyEdid() { } default: { mEdid.insert(mEdid.end(), kEdid2.begin(), kEdid2.end()); - const uint32_t size = mEdid.size(); + const size_t size = mEdid.size(); // Update the name to EMU_display_<mID> mEdid[size - 3] = '0' + (uint8_t)mId; // Update the checksum byte diff --git a/system/hwc3/DisplayFinder.cpp b/system/hwc3/DisplayFinder.cpp index edb3089b..9ee68374 100644 --- a/system/hwc3/DisplayFinder.cpp +++ b/system/hwc3/DisplayFinder.cpp @@ -22,28 +22,25 @@ #include "Common.h" #include "HostUtils.h" +#include "Time.h" namespace aidl::android::hardware::graphics::composer3::impl { namespace { -constexpr int32_t HertzToPeriodNanos(uint32_t hertz) { - return 1000 * 1000 * 1000 / hertz; -} - -static int getVsyncHzFromProperty() { - static constexpr const auto kVsyncProp = "ro.boot.qemu.vsync"; +static uint32_t getVsyncHzFromProperty() { + static constexpr const auto kVsyncProp = "ro.boot.qemu.vsync"; - const auto vsyncProp = ::android::base::GetProperty(kVsyncProp, ""); - DEBUG_LOG("%s: prop value is: %s", __FUNCTION__, vsyncProp.c_str()); + const auto vsyncProp = ::android::base::GetProperty(kVsyncProp, ""); + DEBUG_LOG("%s: prop value is: %s", __FUNCTION__, vsyncProp.c_str()); - uint64_t vsyncPeriod; - if (!::android::base::ParseUint(vsyncProp, &vsyncPeriod)) { - ALOGE("%s: failed to parse vsync period '%s', returning default 60", - __FUNCTION__, vsyncProp.c_str()); - return 60; - } + uint64_t vsyncPeriod; + if (!::android::base::ParseUint(vsyncProp, &vsyncPeriod)) { + ALOGE("%s: failed to parse vsync period '%s', returning default 60", __FUNCTION__, + vsyncProp.c_str()); + return 60; + } - return static_cast<int>(vsyncPeriod); + return static_cast<uint32_t>(vsyncPeriod); } HWC3::Error findGoldfishPrimaryDisplay( @@ -210,16 +207,17 @@ HWC3::Error findDrmDisplays(const DrmClient& drm, for (const DrmClient::DisplayConfig drmDisplayConfig : drmDisplayConfigs) { outDisplays->push_back(DisplayMultiConfigs{ - .displayId = drmDisplayConfig.id, - .activeConfigId = static_cast<int32_t>(drmDisplayConfig.id), - .configs = { - DisplayConfig(static_cast<int32_t>(drmDisplayConfig.id), - drmDisplayConfig.width, - drmDisplayConfig.height, - drmDisplayConfig.dpiX, - drmDisplayConfig.dpiY, - HertzToPeriodNanos(drmDisplayConfig.refreshRateHz)), - }, + .displayId = drmDisplayConfig.id, + .activeConfigId = static_cast<int32_t>(drmDisplayConfig.id), + .configs = + { + DisplayConfig(static_cast<int32_t>(drmDisplayConfig.id), + static_cast<int32_t>(drmDisplayConfig.width), + static_cast<int32_t>(drmDisplayConfig.height), + static_cast<int32_t>(drmDisplayConfig.dpiX), + static_cast<int32_t>(drmDisplayConfig.dpiY), + HertzToPeriodNanos(drmDisplayConfig.refreshRateHz)), + }, }); } diff --git a/system/hwc3/Drm.cpp b/system/hwc3/Drm.cpp index d5cf1d7c..1ac9051a 100644 --- a/system/hwc3/Drm.cpp +++ b/system/hwc3/Drm.cpp @@ -128,7 +128,7 @@ const char* GetDrmFormatString(uint32_t drm_format) { return "Unknown"; } -int GetDrmFormatBytesPerPixel(uint32_t drm_format) { +uint32_t GetDrmFormatBytesPerPixel(uint32_t drm_format) { switch (drm_format) { case DRM_FORMAT_ABGR8888: case DRM_FORMAT_ARGB8888: @@ -150,7 +150,7 @@ int GetDrmFormatBytesPerPixel(uint32_t drm_format) { return 8; } -int GetDrmFormatFromHalFormat(int hal_format) { +uint32_t GetDrmFormatFromHalFormat(int hal_format) { switch (hal_format) { case HAL_PIXEL_FORMAT_RGBA_FP16: return DRM_FORMAT_ABGR16161616F; diff --git a/system/hwc3/Drm.h b/system/hwc3/Drm.h index 1d25033e..7b822552 100644 --- a/system/hwc3/Drm.h +++ b/system/hwc3/Drm.h @@ -22,9 +22,9 @@ namespace aidl::android::hardware::graphics::composer3::impl { const char* GetDrmFormatString(uint32_t drm_format); -int GetDrmFormatBytesPerPixel(uint32_t drm_format); +uint32_t GetDrmFormatBytesPerPixel(uint32_t drm_format); -int GetDrmFormatFromHalFormat(int hal_format); +uint32_t GetDrmFormatFromHalFormat(int hal_format); } // namespace aidl::android::hardware::graphics::composer3::impl diff --git a/system/hwc3/DrmBuffer.h b/system/hwc3/DrmBuffer.h index 1d5e30af..5107250e 100644 --- a/system/hwc3/DrmBuffer.h +++ b/system/hwc3/DrmBuffer.h @@ -52,7 +52,7 @@ class DrmBuffer { uint32_t mWidth = 0; uint32_t mHeight = 0; uint32_t mDrmFormat = 0; - uint32_t mPlaneFds[4] = {0, 0, 0, 0}; + int32_t mPlaneFds[4] = {0, 0, 0, 0}; uint32_t mPlaneHandles[4] = {0, 0, 0, 0}; uint32_t mPlanePitches[4] = {0, 0, 0, 0}; uint32_t mPlaneOffsets[4] = {0, 0, 0, 0}; diff --git a/system/hwc3/DrmClient.cpp b/system/hwc3/DrmClient.cpp index 1a3e25ec..2f0fb732 100644 --- a/system/hwc3/DrmClient.cpp +++ b/system/hwc3/DrmClient.cpp @@ -343,7 +343,7 @@ bool DrmClient::handleHotplug() { } std::tuple<HWC3::Error, ::android::base::unique_fd> DrmClient::flushToDisplay( - int displayId, const std::shared_ptr<DrmBuffer>& buffer, + uint32_t displayId, const std::shared_ptr<DrmBuffer>& buffer, ::android::base::borrowed_fd inSyncFd) { ATRACE_CALL(); diff --git a/system/hwc3/DrmClient.h b/system/hwc3/DrmClient.h index 91dddb0b..3c8fd41b 100644 --- a/system/hwc3/DrmClient.h +++ b/system/hwc3/DrmClient.h @@ -80,10 +80,10 @@ class DrmClient { std::tuple<HWC3::Error, std::shared_ptr<DrmBuffer>> create(const native_handle_t* handle); std::tuple<HWC3::Error, ::android::base::unique_fd> flushToDisplay( - int display, const std::shared_ptr<DrmBuffer>& buffer, + uint32_t displayId, const std::shared_ptr<DrmBuffer>& buffer, ::android::base::borrowed_fd inWaitSyncFd); - std::optional<std::vector<uint8_t>> getEdid(uint32_t id); + std::optional<std::vector<uint8_t>> getEdid(uint32_t displayId); private: using DrmPrimeBufferHandle = uint32_t; diff --git a/system/hwc3/DrmConnector.cpp b/system/hwc3/DrmConnector.cpp index 0924af52..0c8f6584 100644 --- a/system/hwc3/DrmConnector.cpp +++ b/system/hwc3/DrmConnector.cpp @@ -19,7 +19,7 @@ namespace aidl::android::hardware::graphics::composer3::impl { namespace { -static constexpr const float kMillimetersPerInch = 25.4; +static constexpr const float kMillimetersPerInch = 25.4f; } // namespace @@ -71,7 +71,8 @@ bool DrmConnector::update(::android::base::borrowed_fd drmFd) { } DEBUG_LOG("%s: connector:%" PRIu32 " widthMillimeters:%" PRIu32 " heightMillimeters:%" PRIu32, - __FUNCTION__, mId, mWidthMillimeters, mHeightMillimeters); + __FUNCTION__, mId, (mWidthMillimeters ? *mWidthMillimeters : 0), + (mHeightMillimeters ? *mHeightMillimeters : 0)); return true; } @@ -79,16 +80,13 @@ bool DrmConnector::update(::android::base::borrowed_fd drmFd) { bool DrmConnector::loadEdid(::android::base::borrowed_fd drmFd) { DEBUG_LOG("%s: display:%" PRIu32, __FUNCTION__, mId); - mWidthMillimeters = 0; - mHeightMillimeters = 0; - const uint64_t edidBlobId = mEdidProp.getValue(); if (edidBlobId == -1) { ALOGW("%s: display:%" PRIu32 " does not have EDID.", __FUNCTION__, mId); return true; } - auto blob = drmModeGetPropertyBlob(drmFd.get(), edidBlobId); + auto blob = drmModeGetPropertyBlob(drmFd.get(), static_cast<uint32_t>(edidBlobId)); if (!blob) { ALOGE("%s: display:%" PRIu32 " failed to read EDID blob (%" PRIu64 "): %s", __FUNCTION__, mId, edidBlobId, strerror(errno)); @@ -143,42 +141,42 @@ uint32_t DrmConnector::getHeight() const { return mModes[0]->vdisplay; } -int32_t DrmConnector::getDpiX() const { +uint32_t DrmConnector::getDpiX() const { DEBUG_LOG("%s: connector:%" PRIu32, __FUNCTION__, mId); if (mModes.empty()) { - return -1; + return 0; } const auto& mode = mModes[0]; if (mWidthMillimeters) { - const int32_t dpi = static_cast<int32_t>( - (static_cast<float>(mode->hdisplay) / static_cast<float>(mWidthMillimeters)) * + const uint32_t dpi = static_cast<uint32_t>( + (static_cast<float>(mode->hdisplay) / static_cast<float>(*mWidthMillimeters)) * kMillimetersPerInch); - DEBUG_LOG("%s: connector:%" PRIu32 " has dpi-x:%" PRId32, __FUNCTION__, mId, dpi); + DEBUG_LOG("%s: connector:%" PRIu32 " has dpi-x:%" PRIu32, __FUNCTION__, mId, dpi); return dpi; } - return -1; + return 0; } -int32_t DrmConnector::getDpiY() const { +uint32_t DrmConnector::getDpiY() const { DEBUG_LOG("%s: connector:%" PRIu32, __FUNCTION__, mId); if (mModes.empty()) { - return -1; + return 0; } const auto& mode = mModes[0]; if (mHeightMillimeters) { - const int32_t dpi = static_cast<int32_t>( - (static_cast<float>(mode->vdisplay) / static_cast<float>(mHeightMillimeters)) * + const uint32_t dpi = static_cast<uint32_t>( + (static_cast<float>(mode->vdisplay) / static_cast<float>(*mHeightMillimeters)) * kMillimetersPerInch); - DEBUG_LOG("%s: connector:%" PRIu32 " has dpi-x:%" PRId32, __FUNCTION__, mId, dpi); + DEBUG_LOG("%s: connector:%" PRIu32 " has dpi-x:%" PRIu32, __FUNCTION__, mId, dpi); return dpi; } - return -1; + return 0; } float DrmConnector::getRefreshRate() const { diff --git a/system/hwc3/DrmConnector.h b/system/hwc3/DrmConnector.h index 624d38c1..1cc46c5c 100644 --- a/system/hwc3/DrmConnector.h +++ b/system/hwc3/DrmConnector.h @@ -23,6 +23,7 @@ #include <cstdint> #include <memory> +#include <optional> #include <string> #include <unordered_map> @@ -44,8 +45,8 @@ class DrmConnector { uint32_t getWidth() const; uint32_t getHeight() const; - int32_t getDpiX() const; - int32_t getDpiY() const; + uint32_t getDpiX() const; + uint32_t getDpiY() const; float getRefreshRate() const; uint32_t getRefreshRateUint() const { return (uint32_t)(getRefreshRate() + 0.5f); } @@ -67,8 +68,8 @@ class DrmConnector { const uint32_t mId; drmModeConnection mStatus = DRM_MODE_UNKNOWNCONNECTION; - uint32_t mWidthMillimeters = -1; - uint32_t mHeightMillimeters = -1; + std::optional<uint32_t> mWidthMillimeters; + std::optional<uint32_t> mHeightMillimeters; std::vector<std::unique_ptr<DrmMode>> mModes; DrmProperty mCrtc; diff --git a/system/hwc3/DrmCrtc.h b/system/hwc3/DrmCrtc.h index 947ff517..6dcd93bd 100644 --- a/system/hwc3/DrmCrtc.h +++ b/system/hwc3/DrmCrtc.h @@ -48,8 +48,8 @@ class DrmCrtc { friend class DrmPlane; - const uint32_t mId = -1; - const uint32_t mIndexInResourcesArray = -1; + const uint32_t mId; + const uint32_t mIndexInResourcesArray; DrmProperty mActive; DrmProperty mMode; diff --git a/system/hwc3/DrmDisplay.cpp b/system/hwc3/DrmDisplay.cpp index a1edb10f..182fce5e 100644 --- a/system/hwc3/DrmDisplay.cpp +++ b/system/hwc3/DrmDisplay.cpp @@ -83,7 +83,10 @@ std::tuple<HWC3::Error, ::android::base::unique_fd> DrmDisplay::flush( okay &= request->Set(mCrtc->getId(), mCrtc->getOutFenceProperty(), addressAsUint(&flushFenceFd)); okay &= request->Set(mPlane->getId(), mPlane->getCrtcProperty(), mCrtc->getId()); - okay &= request->Set(mPlane->getId(), mPlane->getInFenceProperty(), inSyncFd.get()); + if (inSyncFd != -1) { + okay &= request->Set(mPlane->getId(), mPlane->getInFenceProperty(), + static_cast<uint64_t>(inSyncFd.get())); + } okay &= request->Set(mPlane->getId(), mPlane->getFbProperty(), *buffer->mDrmFramebuffer); okay &= request->Set(mPlane->getId(), mPlane->getCrtcXProperty(), 0); okay &= request->Set(mPlane->getId(), mPlane->getCrtcYProperty(), 0); diff --git a/system/hwc3/DrmEventListener.cpp b/system/hwc3/DrmEventListener.cpp index 208824bc..aa95eaba 100644 --- a/system/hwc3/DrmEventListener.cpp +++ b/system/hwc3/DrmEventListener.cpp @@ -73,11 +73,11 @@ void DrmEventListener::threadLoop() { char buffer[1024]; while (true) { - ret = read(mEventFd.get(), &buffer, sizeof(buffer)); + ssize_t ret = read(mEventFd.get(), &buffer, sizeof(buffer)); if (ret == 0) { return; } else if (ret < 0) { - ALOGE("Got error reading uevent %d", ret); + ALOGE("Got error reading uevent %zd", ret); return; } diff --git a/system/hwc3/DrmProperty.h b/system/hwc3/DrmProperty.h index 9e7b7984..d52cd9de 100644 --- a/system/hwc3/DrmProperty.h +++ b/system/hwc3/DrmProperty.h @@ -22,6 +22,7 @@ #include <xf86drmMode.h> #include <cstdint> +#include <limits> #include <string> #include <unordered_map> @@ -44,8 +45,8 @@ class DrmProperty { const std::string& getName() const { return mName; } private: - uint32_t mId = -1; - uint64_t mValue = -1; + uint32_t mId = std::numeric_limits<uint32_t>::max(); + uint64_t mValue = std::numeric_limits<uint64_t>::max(); std::string mName; }; diff --git a/system/hwc3/DrmSwapchain.h b/system/hwc3/DrmSwapchain.h index 428763e5..a26031c2 100644 --- a/system/hwc3/DrmSwapchain.h +++ b/system/hwc3/DrmSwapchain.h @@ -51,7 +51,7 @@ class DrmSwapchain { private: DrmSwapchain(std::vector<Image> images); std::vector<Image> mImages; - uint32_t mLastUsedIndex = 0; + std::size_t mLastUsedIndex = 0; }; } // namespace aidl::android::hardware::graphics::composer3::impl diff --git a/system/hwc3/Gralloc.cpp b/system/hwc3/Gralloc.cpp index e3c5e982..e609da79 100644 --- a/system/hwc3/Gralloc.cpp +++ b/system/hwc3/Gralloc.cpp @@ -147,9 +147,9 @@ std::optional<void*> Gralloc::Lock(buffer_handle_t buffer) { buffer_region.left = 0; buffer_region.top = 0; // width = right - left - buffer_region.right = *width_opt; + buffer_region.right = static_cast<int32_t>(*width_opt); // height = bottom - top - buffer_region.bottom = *height_opt; + buffer_region.bottom = static_cast<int32_t>(*height_opt); void* data = nullptr; @@ -212,17 +212,17 @@ std::optional<android_ycbcr> Gralloc::LockYCbCr(buffer_handle_t buffer) { switch (static_cast<PlaneLayoutComponentType>(type.value)) { case PlaneLayoutComponentType::Y: buffer_ycbcr.y = component_data; - buffer_ycbcr.ystride = plane_layout.strideInBytes; + buffer_ycbcr.ystride = static_cast<size_t>(plane_layout.strideInBytes); break; case PlaneLayoutComponentType::CB: buffer_ycbcr.cb = component_data; - buffer_ycbcr.cstride = plane_layout.strideInBytes; - buffer_ycbcr.chroma_step = plane_layout.sampleIncrementInBits / 8; + buffer_ycbcr.cstride = static_cast<size_t>(plane_layout.strideInBytes); + buffer_ycbcr.chroma_step = static_cast<size_t>(plane_layout.sampleIncrementInBits / 8); break; case PlaneLayoutComponentType::CR: buffer_ycbcr.cr = component_data; - buffer_ycbcr.cstride = plane_layout.strideInBytes; - buffer_ycbcr.chroma_step = plane_layout.sampleIncrementInBits / 8; + buffer_ycbcr.cstride = static_cast<size_t>(plane_layout.strideInBytes); + buffer_ycbcr.chroma_step = static_cast<size_t>(plane_layout.sampleIncrementInBits / 8); break; default: break; diff --git a/system/hwc3/GuestFrameComposer.cpp b/system/hwc3/GuestFrameComposer.cpp index 8bb753c2..bc51050d 100644 --- a/system/hwc3/GuestFrameComposer.cpp +++ b/system/hwc3/GuestFrameComposer.cpp @@ -37,9 +37,9 @@ namespace { using ::android::hardware::graphics::common::V1_0::ColorTransform; -uint64_t AlignToPower2(uint64_t val, uint8_t align_log) { - uint64_t align = 1ULL << align_log; - return ((val + (align - 1)) / align) * align; +uint32_t AlignToPower2(uint32_t val, uint8_t align_log) { + uint32_t align = 1 << align_log; + return ((val + (align - 1)) / align) * align; } bool LayerNeedsScaling(const Layer& layer) { @@ -126,22 +126,21 @@ bool GetVFlipFromTransform(common::Transform transform) { struct BufferSpec { uint8_t* buffer; std::optional<android_ycbcr> buffer_ycbcr; - int width; - int height; - int cropX; - int cropY; - int cropWidth; - int cropHeight; + uint32_t width; + uint32_t height; + uint32_t cropX; + uint32_t cropY; + uint32_t cropWidth; + uint32_t cropHeight; uint32_t drmFormat; - int strideBytes; - int sampleBytes; + uint32_t strideBytes; + uint32_t sampleBytes; BufferSpec() = default; - BufferSpec(uint8_t* buffer, std::optional<android_ycbcr> buffer_ycbcr, - int width, int height, int cropX, int cropY, int cropWidth, - int cropHeight, uint32_t drmFormat, int strideBytes, - int sampleBytes) + BufferSpec(uint8_t* buffer, std::optional<android_ycbcr> buffer_ycbcr, uint32_t width, + uint32_t height, uint32_t cropX, uint32_t cropY, uint32_t cropWidth, + uint32_t cropHeight, uint32_t drmFormat, uint32_t strideBytes, uint32_t sampleBytes) : buffer(buffer), buffer_ycbcr(buffer_ycbcr), width(width), @@ -154,7 +153,7 @@ struct BufferSpec { strideBytes(strideBytes), sampleBytes(sampleBytes) {} - BufferSpec(uint8_t* buffer, int width, int height, int strideBytes) + BufferSpec(uint8_t* buffer, uint32_t width, uint32_t height, uint32_t strideBytes) : BufferSpec(buffer, /*buffer_ycbcr=*/std::nullopt, width, height, /*cropX=*/0, @@ -173,17 +172,15 @@ int DoFill(const BufferSpec& dst, const Color& color) { const uint8_t b = static_cast<uint8_t>(color.b * 255.0f); const uint8_t a = static_cast<uint8_t>(color.a * 255.0f); - const uint32_t rgba = r | g << 8 | b << 16 | a << 24; + const uint32_t rgba = static_cast<uint32_t>(r) | static_cast<uint32_t>(g) << 8 | + static_cast<uint32_t>(b) << 16 | static_cast<uint32_t>(a) << 24; // Point to the upper left corner of the crop rectangle. uint8_t* dstBuffer = dst.buffer + dst.cropY * dst.strideBytes + dst.cropX * dst.sampleBytes; - libyuv::SetPlane(dstBuffer, - dst.strideBytes, - dst.cropWidth, - dst.cropHeight, - rgba); + libyuv::SetPlane(dstBuffer, static_cast<int>(dst.strideBytes), static_cast<int>(dst.cropWidth), + static_cast<int>(dst.cropHeight), rgba); return 0; } @@ -194,17 +191,19 @@ int ConvertFromRGB565(const BufferSpec& src, const BufferSpec& dst, // Point to the upper left corner of the crop rectangle uint8_t* srcBuffer = src.buffer + src.cropY * src.strideBytes + src.cropX * src.sampleBytes; + const int srcStrideBytes = static_cast<int>(src.strideBytes); uint8_t* dstBuffer = dst.buffer + dst.cropY * dst.strideBytes + dst.cropX * dst.sampleBytes; + const int dstStrideBytes = static_cast<int>(dst.strideBytes); - int width = src.cropWidth; - int height = src.cropHeight; + int width = static_cast<int>(src.cropWidth); + int height = static_cast<int>(src.cropHeight); if (vFlip) { height = -height; } - return libyuv::RGB565ToARGB(srcBuffer, src.strideBytes, // - dstBuffer, dst.strideBytes, // + return libyuv::RGB565ToARGB(srcBuffer, srcStrideBytes, // + dstBuffer, dstStrideBytes, // width, height); } @@ -229,29 +228,32 @@ int ConvertFromYV12(const BufferSpec& src, const BufferSpec& dst, bool vFlip) { } uint8_t* srcY = reinterpret_cast<uint8_t*>(srcBufferYCbCr.y); - int strideY = srcBufferYCbCr.ystride; + const int strideYBytes = static_cast<int>(srcBufferYCbCr.ystride); uint8_t* srcU = reinterpret_cast<uint8_t*>(srcBufferYCbCr.cb); - int strideU = srcBufferYCbCr.cstride; + const int strideUBytes = static_cast<int>(srcBufferYCbCr.cstride); uint8_t* srcV = reinterpret_cast<uint8_t*>(srcBufferYCbCr.cr); - int strideV = srcBufferYCbCr.cstride; + const int strideVBytes = static_cast<int>(srcBufferYCbCr.cstride); // Adjust for crop - srcY += src.cropY * strideY + src.cropX; - srcV += (src.cropY / 2) * strideV + (src.cropX / 2); - srcU += (src.cropY / 2) * strideU + (src.cropX / 2); + srcY += src.cropY * srcBufferYCbCr.ystride + src.cropX; + srcV += (src.cropY / 2) * srcBufferYCbCr.cstride + (src.cropX / 2); + srcU += (src.cropY / 2) * srcBufferYCbCr.cstride + (src.cropX / 2); uint8_t* dstBuffer = dst.buffer + dst.cropY * dst.strideBytes + dst.cropX * dst.sampleBytes; + const int dstStrideBytes = static_cast<int>(dst.strideBytes); - int width = dst.cropWidth; - int height = dst.cropHeight; + int width = static_cast<int>(dst.cropWidth); + int height = static_cast<int>(dst.cropHeight); if (vFlip) { height = -height; } // YV12 is the same as I420, with the U and V planes swapped - return libyuv::I420ToARGB(srcY, strideY, srcV, strideV, srcU, strideU, - dstBuffer, dst.strideBytes, width, height); + return libyuv::I420ToARGB(srcY, strideYBytes, // + srcV, strideVBytes, // + srcU, strideUBytes, // + dstBuffer, dstStrideBytes, width, height); } int DoConversion(const BufferSpec& src, const BufferSpec& dst, bool v_flip) { @@ -269,10 +271,12 @@ int DoCopy(const BufferSpec& src, const BufferSpec& dst, bool v_flip) { // Point to the upper left corner of the crop rectangle uint8_t* srcBuffer = src.buffer + src.cropY * src.strideBytes + src.cropX * src.sampleBytes; + const int srcStrideBytes = static_cast<int>(src.strideBytes); uint8_t* dstBuffer = dst.buffer + dst.cropY * dst.strideBytes + dst.cropX * dst.sampleBytes; - int width = src.cropWidth; - int height = src.cropHeight; + const int dstStrideBytes = static_cast<int>(dst.strideBytes); + int width = static_cast<int>(src.cropWidth); + int height = static_cast<int>(src.cropHeight); if (v_flip) { height = -height; @@ -282,8 +286,9 @@ int DoCopy(const BufferSpec& src, const BufferSpec& dst, bool v_flip) { // byte stream, while libyuv formats are named based on the order of those // pixel components in an integer written from left to right. So // libyuv::FOURCC_ARGB is equivalent to HAL_PIXEL_FORMAT_BGRA_8888. - auto ret = libyuv::ARGBCopy(srcBuffer, src.strideBytes, dstBuffer, - dst.strideBytes, width, height); + auto ret = libyuv::ARGBCopy(srcBuffer, srcStrideBytes, // + dstBuffer, dstStrideBytes, // + width, height); return ret; } @@ -294,17 +299,20 @@ int DoRotation(const BufferSpec& src, const BufferSpec& dst, // Point to the upper left corner of the crop rectangles uint8_t* srcBuffer = src.buffer + src.cropY * src.strideBytes + src.cropX * src.sampleBytes; + const int srcStrideBytes = static_cast<int>(src.strideBytes); uint8_t* dstBuffer = dst.buffer + dst.cropY * dst.strideBytes + dst.cropX * dst.sampleBytes; - int width = src.cropWidth; - int height = src.cropHeight; + const int dstStrideBytes = static_cast<int>(dst.strideBytes); + int width = static_cast<int>(src.cropWidth); + int height = static_cast<int>(src.cropHeight); if (v_flip) { height = -height; } - return libyuv::ARGBRotate(srcBuffer, src.strideBytes, dstBuffer, - dst.strideBytes, width, height, rotation); + return libyuv::ARGBRotate(srcBuffer, srcStrideBytes, // + dstBuffer, dstStrideBytes, // + width, height, rotation); } int DoScaling(const BufferSpec& src, const BufferSpec& dst, bool v_flip) { @@ -315,18 +323,19 @@ int DoScaling(const BufferSpec& src, const BufferSpec& dst, bool v_flip) { src.buffer + src.cropY * src.strideBytes + src.cropX * src.sampleBytes; uint8_t* dstBuffer = dst.buffer + dst.cropY * dst.strideBytes + dst.cropX * dst.sampleBytes; - int srcWidth = src.cropWidth; - int srcHeight = src.cropHeight; - int dstWidth = dst.cropWidth; - int dstHeight = dst.cropHeight; + const int srcStrideBytes = static_cast<int>(src.strideBytes); + const int dstStrideBytes = static_cast<int>(dst.strideBytes); + const int srcWidth = static_cast<int>(src.cropWidth); + int srcHeight = static_cast<int>(src.cropHeight); + const int dstWidth = static_cast<int>(dst.cropWidth); + const int dstHeight = static_cast<int>(dst.cropHeight); if (v_flip) { srcHeight = -srcHeight; } - return libyuv::ARGBScale(srcBuffer, src.strideBytes, srcWidth, srcHeight, - dstBuffer, dst.strideBytes, dstWidth, dstHeight, - libyuv::kFilterBilinear); + return libyuv::ARGBScale(srcBuffer, srcStrideBytes, srcWidth, srcHeight, dstBuffer, + dstStrideBytes, dstWidth, dstHeight, libyuv::kFilterBilinear); } int DoAttenuation(const BufferSpec& src, const BufferSpec& dst, bool v_flip) { @@ -337,15 +346,17 @@ int DoAttenuation(const BufferSpec& src, const BufferSpec& dst, bool v_flip) { src.buffer + src.cropY * src.strideBytes + src.cropX * src.sampleBytes; uint8_t* dstBuffer = dst.buffer + dst.cropY * dst.strideBytes + dst.cropX * dst.sampleBytes; - int width = dst.cropWidth; - int height = dst.cropHeight; - + const int srcStrideBytes = static_cast<int>(src.strideBytes); + const int dstStrideBytes = static_cast<int>(dst.strideBytes); + const int width = static_cast<int>(dst.cropWidth); + int height = static_cast<int>(dst.cropHeight); if (v_flip) { height = -height; } - return libyuv::ARGBAttenuate(srcBuffer, src.strideBytes, dstBuffer, - dst.strideBytes, width, height); + return libyuv::ARGBAttenuate(srcBuffer, srcStrideBytes, // + dstBuffer, dstStrideBytes, // + width, height); } int DoBlending(const BufferSpec& src, const BufferSpec& dst, bool v_flip) { @@ -356,9 +367,10 @@ int DoBlending(const BufferSpec& src, const BufferSpec& dst, bool v_flip) { src.buffer + src.cropY * src.strideBytes + src.cropX * src.sampleBytes; uint8_t* dstBuffer = dst.buffer + dst.cropY * dst.strideBytes + dst.cropX * dst.sampleBytes; - int width = dst.cropWidth; - int height = dst.cropHeight; - + const int srcStrideBytes = static_cast<int>(src.strideBytes); + const int dstStrideBytes = static_cast<int>(dst.strideBytes); + const int width = static_cast<int>(dst.cropWidth); + int height = static_cast<int>(dst.cropHeight); if (v_flip) { height = -height; } @@ -366,9 +378,10 @@ int DoBlending(const BufferSpec& src, const BufferSpec& dst, bool v_flip) { // libyuv's ARGB format is hwcomposer's BGRA format, since blending only cares // for the position of alpha in the pixel and not the position of the colors // this function is perfectly usable. - return libyuv::ARGBBlend(srcBuffer, src.strideBytes, dstBuffer, - dst.strideBytes, dstBuffer, dst.strideBytes, width, - height); + return libyuv::ARGBBlend(srcBuffer, srcStrideBytes, // + dstBuffer, dstStrideBytes, // + dstBuffer, dstStrideBytes, // + width, height); } std::optional<BufferSpec> GetBufferSpec(GrallocBuffer& buffer, @@ -422,11 +435,14 @@ std::optional<BufferSpec> GetBufferSpec(GrallocBuffer& buffer, bufferStrideBytes = *bufferStrideBytesOpt; } - return BufferSpec(bufferData, bufferYCbCrData, bufferWidth, bufferHeight, - bufferCrop.left, bufferCrop.top, - bufferCrop.right - bufferCrop.left, - bufferCrop.bottom - bufferCrop.top, bufferFormat, - bufferStrideBytes, GetDrmFormatBytesPerPixel(bufferFormat)); + uint32_t bufferCropX = static_cast<uint32_t>(bufferCrop.left); + uint32_t bufferCropY = static_cast<uint32_t>(bufferCrop.top); + uint32_t bufferCropWidth = static_cast<uint32_t>(bufferCrop.right - bufferCrop.left); + uint32_t bufferCropHeight = static_cast<uint32_t>(bufferCrop.bottom - bufferCrop.top); + + return BufferSpec(bufferData, bufferYCbCrData, bufferWidth, bufferHeight, bufferCropX, + bufferCropY, bufferCropWidth, bufferCropHeight, bufferFormat, bufferStrideBytes, + GetDrmFormatBytesPerPixel(bufferFormat)); } } // namespace @@ -454,37 +470,34 @@ HWC3::Error GuestFrameComposer::unregisterOnHotplugCallback() { } HWC3::Error GuestFrameComposer::onDisplayCreate(Display* display) { - int64_t displayId = display->getId(); + const uint32_t displayId = static_cast<uint32_t>(display->getId()); int32_t displayConfigId; int32_t displayWidth; int32_t displayHeight; HWC3::Error error = display->getActiveConfig(&displayConfigId); if (error != HWC3::Error::None) { - ALOGE("%s: display:%" PRIu64 " has no active config", __FUNCTION__, - displayId); + ALOGE("%s: display:%" PRIu32 " has no active config", __FUNCTION__, displayId); return error; } error = display->getDisplayAttribute(displayConfigId, DisplayAttribute::WIDTH, &displayWidth); if (error != HWC3::Error::None) { - ALOGE("%s: display:%" PRIu64 " failed to get width", __FUNCTION__, - displayId); + ALOGE("%s: display:%" PRIu32 " failed to get width", __FUNCTION__, displayId); return error; } error = display->getDisplayAttribute( displayConfigId, DisplayAttribute::HEIGHT, &displayHeight); if (error != HWC3::Error::None) { - ALOGE("%s: display:%" PRIu64 " failed to get height", __FUNCTION__, - displayId); + ALOGE("%s: display:%" PRIu32 " failed to get height", __FUNCTION__, displayId); return error; } auto it = mDisplayInfos.find(displayId); if (it != mDisplayInfos.end()) { - ALOGE("%s: display:%" PRIu64 " already created?", __FUNCTION__, displayId); + ALOGE("%s: display:%" PRIu32 " already created?", __FUNCTION__, displayId); } DisplayInfo& displayInfo = mDisplayInfos[displayId]; @@ -493,19 +506,18 @@ HWC3::Error GuestFrameComposer::onDisplayCreate(Display* display) { buffer_handle_t bufferHandle; auto status = ::android::GraphicBufferAllocator::get().allocate( - displayWidth, // - displayHeight, // - ::android::PIXEL_FORMAT_RGBA_8888, // - /*layerCount=*/1, // - ::android::GraphicBuffer::USAGE_HW_COMPOSER | - ::android::GraphicBuffer::USAGE_SW_READ_OFTEN | + static_cast<uint32_t>(displayWidth), // + static_cast<uint32_t>(displayHeight), // + ::android::PIXEL_FORMAT_RGBA_8888, // + /*layerCount=*/1, // + ::android::GraphicBuffer::USAGE_HW_COMPOSER | ::android::GraphicBuffer::USAGE_SW_READ_OFTEN | ::android::GraphicBuffer::USAGE_SW_WRITE_OFTEN, // &bufferHandle, // &bufferStride, // "RanchuHwc"); if (status != ::android::OK) { - ALOGE("%s: failed to allocate composition buffer for display:%" PRIu64, - __FUNCTION__, displayId); + ALOGE("%s: failed to allocate composition buffer for display:%" PRIu32, __FUNCTION__, + displayId); return HWC3::Error::NoResources; } @@ -513,8 +525,7 @@ HWC3::Error GuestFrameComposer::onDisplayCreate(Display* display) { auto [drmBufferCreateError, drmBuffer] = mDrmClient.create(bufferHandle); if (drmBufferCreateError != HWC3::Error::None) { - ALOGE("%s: failed to create drm buffer for display:%" PRIu64, __FUNCTION__, - displayId); + ALOGE("%s: failed to create drm buffer for display:%" PRIu32, __FUNCTION__, displayId); return drmBufferCreateError; } displayInfo.compositionResultDrmBuffer = std::move(drmBuffer); @@ -692,8 +703,8 @@ HWC3::Error GuestFrameComposer::presentDisplay( Display* display, ::android::base::unique_fd* outDisplayFence, std::unordered_map<int64_t, ::android::base::unique_fd>* /*outLayerFences*/) { - const auto displayId = display->getId(); - DEBUG_LOG("%s display:%" PRIu64, __FUNCTION__, displayId); + const uint32_t displayId = static_cast<uint32_t>(display->getId()); + DEBUG_LOG("%s display:%" PRIu32, __FUNCTION__, displayId); if (mPresentDisabled) { return HWC3::Error::None; @@ -701,69 +712,61 @@ HWC3::Error GuestFrameComposer::presentDisplay( auto it = mDisplayInfos.find(displayId); if (it == mDisplayInfos.end()) { - ALOGE("%s: display:%" PRIu64 " not found", __FUNCTION__, displayId); + ALOGE("%s: display:%" PRIu32 " not found", __FUNCTION__, displayId); return HWC3::Error::NoResources; } DisplayInfo& displayInfo = it->second; if (displayInfo.compositionResultBuffer == nullptr) { - ALOGE("%s: display:%" PRIu64 " missing composition result buffer", - __FUNCTION__, displayId); + ALOGE("%s: display:%" PRIu32 " missing composition result buffer", __FUNCTION__, displayId); return HWC3::Error::NoResources; } if (displayInfo.compositionResultDrmBuffer == nullptr) { - ALOGE("%s: display:%" PRIu64 " missing composition result drm buffer", - __FUNCTION__, displayId); + ALOGE("%s: display:%" PRIu32 " missing composition result drm buffer", __FUNCTION__, displayId); return HWC3::Error::NoResources; } std::optional<GrallocBuffer> compositionResultBufferOpt = mGralloc.Import(displayInfo.compositionResultBuffer); if (!compositionResultBufferOpt) { - ALOGE("%s: display:%" PRIu64 " failed to import buffer", __FUNCTION__, - displayId); + ALOGE("%s: display:%" PRIu32 " failed to import buffer", __FUNCTION__, displayId); return HWC3::Error::NoResources; } std::optional<uint32_t> compositionResultBufferWidthOpt = compositionResultBufferOpt->GetWidth(); if (!compositionResultBufferWidthOpt) { - ALOGE("%s: display:%" PRIu64 " failed to query buffer width", __FUNCTION__, - displayId); + ALOGE("%s: display:%" PRIu32 " failed to query buffer width", __FUNCTION__, displayId); return HWC3::Error::NoResources; } std::optional<uint32_t> compositionResultBufferHeightOpt = compositionResultBufferOpt->GetHeight(); if (!compositionResultBufferHeightOpt) { - ALOGE("%s: display:%" PRIu64 " failed to query buffer height", __FUNCTION__, - displayId); + ALOGE("%s: display:%" PRIu32 " failed to query buffer height", __FUNCTION__, displayId); return HWC3::Error::NoResources; } std::optional<uint32_t> compositionResultBufferStrideOpt = compositionResultBufferOpt->GetMonoPlanarStrideBytes(); if (!compositionResultBufferStrideOpt) { - ALOGE("%s: display:%" PRIu64 " failed to query buffer stride", __FUNCTION__, - displayId); + ALOGE("%s: display:%" PRIu32 " failed to query buffer stride", __FUNCTION__, displayId); return HWC3::Error::NoResources; } std::optional<GrallocBufferView> compositionResultBufferViewOpt = compositionResultBufferOpt->Lock(); if (!compositionResultBufferViewOpt) { - ALOGE("%s: display:%" PRIu64 " failed to get buffer view", __FUNCTION__, - displayId); + ALOGE("%s: display:%" PRIu32 " failed to get buffer view", __FUNCTION__, displayId); return HWC3::Error::NoResources; } const std::optional<void*> compositionResultBufferDataOpt = compositionResultBufferViewOpt->Get(); if (!compositionResultBufferDataOpt) { - ALOGE("%s: display:%" PRIu64 " failed to get buffer data", __FUNCTION__, - displayId); + ALOGE("%s: display:%" PRIu32 " failed to get buffer data", __FUNCTION__, displayId); return HWC3::Error::NoResources; } @@ -784,7 +787,7 @@ HWC3::Error GuestFrameComposer::presentDisplay( }); if (noOpComposition) { - ALOGW("%s: display:%" PRIu64 " empty composition", __FUNCTION__, displayId); + ALOGW("%s: display:%" PRIu32 " empty composition", __FUNCTION__, displayId); } else if (allLayersClientComposed) { auto clientTargetBufferOpt = mGralloc.Import(display->waitAndGetClientTargetBuffer()); @@ -814,7 +817,7 @@ HWC3::Error GuestFrameComposer::presentDisplay( } std::size_t clientTargetPlaneSize = - clientTargetPlaneLayouts[0].totalSizeInBytes; + static_cast<std::size_t>(clientTargetPlaneLayouts[0].totalSizeInBytes); auto clientTargetDataOpt = clientTargetBufferView.Get(); if (!clientTargetDataOpt) { @@ -841,8 +844,8 @@ HWC3::Error GuestFrameComposer::presentDisplay( compositionResultBufferStride, // 4); if (error != HWC3::Error::None) { - ALOGE("%s: display:%" PRIu64 " failed to compose layer:%" PRIu64, - __FUNCTION__, displayId, layerId); + ALOGE("%s: display:%" PRIu32 " failed to compose layer:%" PRIu64, __FUNCTION__, displayId, + layerId); return error; } } @@ -856,20 +859,17 @@ HWC3::Error GuestFrameComposer::presentDisplay( compositionResultBufferHeight, // compositionResultBufferStride); if (error != HWC3::Error::None) { - ALOGE("%s: display:%" PRIu64 " failed to apply color transform", - __FUNCTION__, displayId); + ALOGE("%s: display:%" PRIu32 " failed to apply color transform", __FUNCTION__, displayId); return error; } } - DEBUG_LOG("%s display:%" PRIu64 " flushing drm buffer", __FUNCTION__, - displayId); + DEBUG_LOG("%s display:%" PRIu32 " flushing drm buffer", __FUNCTION__, displayId); auto [error, fence] = mDrmClient.flushToDisplay( displayId, displayInfo.compositionResultDrmBuffer, -1); if (error != HWC3::Error::None) { - ALOGE("%s: display:%" PRIu64 " failed to flush drm buffer" PRIu64, - __FUNCTION__, displayId); + ALOGE("%s: display:%" PRIu32 " failed to flush drm buffer" PRIu64, __FUNCTION__, displayId); } *outDisplayFence = std::move(fence); @@ -976,9 +976,10 @@ HWC3::Error GuestFrameComposer::composeLayerInto( BufferSpec dstLayerSpec( dstBuffer, /*buffer_ycbcr=*/std::nullopt, dstBufferWidth, dstBufferHeight, - srcLayerDisplayFrame.left, srcLayerDisplayFrame.top, - srcLayerDisplayFrame.right - srcLayerDisplayFrame.left, - srcLayerDisplayFrame.bottom - srcLayerDisplayFrame.top, + static_cast<uint32_t>(srcLayerDisplayFrame.left), + static_cast<uint32_t>(srcLayerDisplayFrame.top), + static_cast<uint32_t>(srcLayerDisplayFrame.right - srcLayerDisplayFrame.left), + static_cast<uint32_t>(srcLayerDisplayFrame.bottom - srcLayerDisplayFrame.top), DRM_FORMAT_XBGR8888, dstBufferStrideBytes, dstBufferBytesPerPixel); // Add the destination layer to the bottom of the buffer stack @@ -997,19 +998,18 @@ HWC3::Error GuestFrameComposer::composeLayerInto( (needsAttenuation ? 1 : 0) + (needsBlending ? 1 : 0) + (needsCopy ? 1 : 0) - 1; - int mScratchBufferWidth = - srcLayerDisplayFrame.right - srcLayerDisplayFrame.left; - int mScratchBufferHeight = - srcLayerDisplayFrame.bottom - srcLayerDisplayFrame.top; - int mScratchBufferStrideBytes = + uint32_t mScratchBufferWidth = + static_cast<uint32_t>(srcLayerDisplayFrame.right - srcLayerDisplayFrame.left); + uint32_t mScratchBufferHeight = + static_cast<uint32_t>(srcLayerDisplayFrame.bottom - srcLayerDisplayFrame.top); + uint32_t mScratchBufferStrideBytes = AlignToPower2(mScratchBufferWidth * dstBufferBytesPerPixel, 4); - int mScratchBufferSizeBytes = - mScratchBufferHeight * mScratchBufferStrideBytes; + uint32_t mScratchBufferSizeBytes = mScratchBufferHeight * mScratchBufferStrideBytes; - for (int i = 0; i < neededScratchBuffers; i++) { - BufferSpec mScratchBufferspec( - getRotatingScratchBuffer(mScratchBufferSizeBytes, i), - mScratchBufferWidth, mScratchBufferHeight, mScratchBufferStrideBytes); + for (uint32_t i = 0; i < neededScratchBuffers; i++) { + BufferSpec mScratchBufferspec(getRotatingScratchBuffer(mScratchBufferSizeBytes, i), + mScratchBufferWidth, mScratchBufferHeight, + mScratchBufferStrideBytes); dstBufferStack.push_back(mScratchBufferspec); } @@ -1039,11 +1039,10 @@ HWC3::Error GuestFrameComposer::composeLayerInto( // top of the buffer stack are wrong (wrong sizes for scaling, swapped // width and height for 90 and 270 rotations). // Make width and height match the crop sizes on the source - int srcWidth = srcLayerSpec.cropWidth; - int srcHeight = srcLayerSpec.cropHeight; - int dst_stride_bytes = - AlignToPower2(srcWidth * dstBufferBytesPerPixel, 4); - size_t needed_size = dst_stride_bytes * srcHeight; + uint32_t srcWidth = srcLayerSpec.cropWidth; + uint32_t srcHeight = srcLayerSpec.cropHeight; + uint32_t dst_stride_bytes = AlignToPower2(srcWidth * dstBufferBytesPerPixel, 4); + uint32_t needed_size = dst_stride_bytes * srcHeight; dstBufferSpec.width = srcWidth; dstBufferSpec.height = srcHeight; // Adjust the stride accordingly @@ -1144,13 +1143,13 @@ std::array<std::int8_t, 16> ToLibyuvColorMatrix( const std::array<float, 16>& in) { std::array<std::int8_t, 16> out; - for (int r = 0; r < 4; r++) { - for (int c = 0; c < 4; c++) { - int indexIn = (4 * r) + c; - int indexOut = (4 * c) + r; + for (size_t r = 0; r < 4; r++) { + for (size_t c = 0; c < 4; c++) { + size_t indexIn = (4 * r) + c; + size_t indexOut = (4 * c) + r; - out[indexOut] = std::max( - -128, std::min(127, static_cast<int>(in[indexIn] * 64.0f + 0.5f))); + out[indexOut] = static_cast<std::int8_t>( + std::max(-128, std::min(127, static_cast<int>(in[indexIn] * 64.0f + 0.5f)))); } } @@ -1168,11 +1167,11 @@ HWC3::Error GuestFrameComposer::applyColorTransformToRGBA( ATRACE_CALL(); const auto transformMatrixLibyuv = ToLibyuvColorMatrix(transfromMatrix); - libyuv::ARGBColorMatrix(buffer, bufferStrideBytes, // in buffer params - buffer, bufferStrideBytes, // out buffer params - transformMatrixLibyuv.data(), // - bufferWidth, // - bufferHeight); + libyuv::ARGBColorMatrix(buffer, static_cast<int>(bufferStrideBytes), // + buffer, static_cast<int>(bufferStrideBytes), // + transformMatrixLibyuv.data(), // + static_cast<int>(bufferWidth), // + static_cast<int>(bufferHeight)); return HWC3::Error::None; } diff --git a/system/hwc3/HostFrameComposer.cpp b/system/hwc3/HostFrameComposer.cpp index 5826d235..6f146487 100644 --- a/system/hwc3/HostFrameComposer.cpp +++ b/system/hwc3/HostFrameComposer.cpp @@ -26,8 +26,6 @@ #include <poll.h> #include <sync/sync.h> #include <ui/GraphicBuffer.h> -#include <ui/GraphicBufferAllocator.h> -#include <ui/GraphicBufferMapper.h> #include <optional> #include <tuple> @@ -161,10 +159,6 @@ class ComposeMsg_v2 { ComposeDevice_v2* mComposeDevice; }; -void FreeDisplayColorBuffer(const native_handle_t* h) { - ::android::GraphicBufferAllocator::get().free(h); -} - } // namespace HWC3::Error HostFrameComposer::init() { @@ -236,7 +230,7 @@ HWC3::Error HostFrameComposer::createHostComposerDisplayInfo( displayInfo.hostDisplayId = hostDisplayId; displayInfo.swapchain = DrmSwapchain::create( - displayWidth, displayHeight, + static_cast<uint32_t>(displayWidth), static_cast<uint32_t>(displayHeight), ::android::GraphicBuffer::USAGE_HW_COMPOSER | ::android::GraphicBuffer::USAGE_HW_RENDER, mDrmClient ? &mDrmClient.value() : nullptr); if (!displayInfo.swapchain) { @@ -249,7 +243,7 @@ HWC3::Error HostFrameComposer::createHostComposerDisplayInfo( HWC3::Error HostFrameComposer::onDisplayCreate(Display* display) { HWC3::Error error = HWC3::Error::None; - int64_t displayId = display->getId(); + const uint32_t displayId = static_cast<uint32_t>(display->getId()); int32_t displayConfigId; int32_t displayWidth; int32_t displayHeight; @@ -257,32 +251,28 @@ HWC3::Error HostFrameComposer::onDisplayCreate(Display* display) { error = display->getActiveConfig(&displayConfigId); if (error != HWC3::Error::None) { - ALOGE("%s: display:%" PRIu64 " has no active config", __FUNCTION__, - displayId); + ALOGE("%s: display:%" PRIu32 " has no active config", __FUNCTION__, displayId); return error; } error = display->getDisplayAttribute(displayConfigId, DisplayAttribute::WIDTH, &displayWidth); if (error != HWC3::Error::None) { - ALOGE("%s: display:%" PRIu64 " failed to get width", __FUNCTION__, - displayId); + ALOGE("%s: display:%" PRIu32 " failed to get width", __FUNCTION__, displayId); return error; } error = display->getDisplayAttribute( displayConfigId, DisplayAttribute::HEIGHT, &displayHeight); if (error != HWC3::Error::None) { - ALOGE("%s: display:%" PRIu64 " failed to get height", __FUNCTION__, - displayId); + ALOGE("%s: display:%" PRIu32 " failed to get height", __FUNCTION__, displayId); return error; } error = display->getDisplayAttribute(displayConfigId, DisplayAttribute::DPI_X, &displayDpiX); if (error != HWC3::Error::None) { - ALOGE("%s: display:%" PRIu64 " failed to get height", __FUNCTION__, - displayId); + ALOGE("%s: display:%" PRIu32 " failed to get height", __FUNCTION__, displayId); return error; } @@ -293,13 +283,14 @@ HWC3::Error HostFrameComposer::onDisplayCreate(Display* display) { // Primary display: hostCon->lock(); if (rcEnc->rcCreateDisplayById(rcEnc, displayId)) { - ALOGE("%s host failed to create display %" PRIu64, __func__, displayId); + ALOGE("%s host failed to create display %" PRIu32, __func__, displayId); hostCon->unlock(); return HWC3::Error::NoResources; } - if (rcEnc->rcSetDisplayPoseDpi(rcEnc, displayId, -1, -1, displayWidth, - displayHeight, displayDpiX / 1000)) { - ALOGE("%s host failed to set display %" PRIu64, __func__, displayId); + if (rcEnc->rcSetDisplayPoseDpi(rcEnc, displayId, -1, -1, static_cast<uint32_t>(displayWidth), + static_cast<uint32_t>(displayHeight), + static_cast<uint32_t>(displayDpiX / 1000))) { + ALOGE("%s host failed to set display %" PRIu32, __func__, displayId); hostCon->unlock(); return HWC3::Error::NoResources; } @@ -314,8 +305,8 @@ HWC3::Error HostFrameComposer::onDisplayCreate(Display* display) { hostCon->lock(); rcEnc->rcDestroyDisplay(rcEnc, expectedHostDisplayId); rcEnc->rcCreateDisplay(rcEnc, &actualHostDisplayId); - rcEnc->rcSetDisplayPose(rcEnc, actualHostDisplayId, -1, -1, displayWidth, - displayHeight); + rcEnc->rcSetDisplayPose(rcEnc, actualHostDisplayId, -1, -1, static_cast<uint32_t>(displayWidth), + static_cast<uint32_t>(displayHeight)); hostCon->unlock(); if (actualHostDisplayId != expectedHostDisplayId) { @@ -330,8 +321,7 @@ HWC3::Error HostFrameComposer::onDisplayCreate(Display* display) { error = createHostComposerDisplayInfo(display, hostDisplayId); if (error != HWC3::Error::None) { - ALOGE("%s failed to initialize host info for display:%" PRIu64, - __FUNCTION__, displayId); + ALOGE("%s failed to initialize host info for display:%" PRIu32, __FUNCTION__, displayId); return error; } @@ -492,11 +482,10 @@ HWC3::Error HostFrameComposer::validateDisplay(Display* display, HWC3::Error HostFrameComposer::presentDisplay( Display* display, ::android::base::unique_fd* outDisplayFence, std::unordered_map<int64_t, ::android::base::unique_fd>* outLayerFences) { - auto displayId = display->getId(); + const uint32_t displayId = static_cast<uint32_t>(display->getId()); auto displayInfoIt = mDisplayInfos.find(displayId); if (displayInfoIt == mDisplayInfos.end()) { - ALOGE("%s: failed to find display buffers for display:%" PRIu64, - __FUNCTION__, displayId); + ALOGE("%s: failed to find display buffers for display:%" PRIu32, __FUNCTION__, displayId); return HWC3::Error::BadDisplay; } @@ -532,8 +521,8 @@ HWC3::Error HostFrameComposer::presentDisplay( } } - DEBUG_LOG("%s: presenting display:%" PRIu64 " with %d layers", __FUNCTION__, - displayId, static_cast<int>(layers.size())); + DEBUG_LOG("%s: presenting display:%" PRIu32 " with %d layers", __FUNCTION__, displayId, + static_cast<int>(layers.size())); if (numLayer == 0) { ALOGV( @@ -749,11 +738,11 @@ void HostFrameComposer::post(HostConnection* hostCon, } HWC3::Error HostFrameComposer::onActiveConfigChange(Display* display) { - DEBUG_LOG("%s: display:%" PRIu64, __FUNCTION__, display->getId()); - HWC3::Error error = createHostComposerDisplayInfo(display, display->getId()); + const uint32_t displayId = static_cast<uint32_t>(display->getId()); + DEBUG_LOG("%s: display:%" PRIu32, __FUNCTION__, displayId); + HWC3::Error error = createHostComposerDisplayInfo(display, displayId); if (error != HWC3::Error::None) { - ALOGE("%s failed to update host info for display:%" PRIu64, __FUNCTION__, - display->getId()); + ALOGE("%s failed to update host info for display:%" PRIu32, __FUNCTION__, displayId); return error; } return HWC3::Error::None; diff --git a/system/hwc3/Time.h b/system/hwc3/Time.h index 79473a50..f83e400a 100644 --- a/system/hwc3/Time.h +++ b/system/hwc3/Time.h @@ -37,15 +37,15 @@ inline TimePoint now() { return asTimePoint(systemTime(SYSTEM_TIME_MONOTONIC)); } -inline int32_t asNanosDuration(Nanoseconds duration) { - return duration.count(); -} +inline int64_t asNanosDuration(Nanoseconds duration) { return duration.count(); } inline int64_t asNanosTimePoint(TimePoint time) { TimePoint zero(Nanoseconds(0)); - return std::chrono::duration_cast<Nanoseconds>(time - zero).count(); + return static_cast<int64_t>(std::chrono::duration_cast<Nanoseconds>(time - zero).count()); } +constexpr int32_t HertzToPeriodNanos(uint32_t hertz) { return 1000 * 1000 * 1000 / hertz; } + } // namespace aidl::android::hardware::graphics::composer3::impl #endif diff --git a/system/hwc3/VsyncThread.cpp b/system/hwc3/VsyncThread.cpp index 350a9065..ce695639 100644 --- a/system/hwc3/VsyncThread.cpp +++ b/system/hwc3/VsyncThread.cpp @@ -163,7 +163,7 @@ void VsyncThread::threadLoop() { DEBUG_LOG("%s: for display:%" PRIu64 " calling vsync", __FUNCTION__, mDisplayId); mCallbacks->onVsync(mDisplayId, asNanosTimePoint(nextVsync), - asNanosDuration(vsyncPeriod)); + static_cast<int32_t>(asNanosDuration(vsyncPeriod))); } } @@ -172,6 +172,7 @@ void VsyncThread::threadLoop() { DEBUG_LOG("%s: for display:%" PRIu64 " send %" PRIu32 " in last %d seconds", __FUNCTION__, mDisplayId, vsyncs, kLogIntervalSeconds); + (void)vsyncs; previousLog = now; vsyncs = 0; } |