diff options
author | 2024-02-26 18:56:00 +0000 | |
---|---|---|
committer | 2024-03-04 11:25:45 +0000 | |
commit | 8f6d6e033462c7b74f2bdf87879e26b0f0321212 (patch) | |
tree | 04c789e071e01629aa666fb70b0985a89c5500c4 | |
parent | 358a360cbdbdd0ac9d2f82387cf5bcede112fc17 (diff) |
Add DeviceInfo to host build for libhwui
This requires creating a host version of nativedisplay/ADisplay.cpp and
putting it in libhostgraphics.
Bug: 322360037
Test: host build of libhwui
Change-Id: I75a14ce4dd417ef7ff5983beb0c1397f14c279e5
-rw-r--r-- | core/jni/Android.bp | 1 | ||||
-rw-r--r-- | libs/hostgraphics/ADisplay.cpp | 159 | ||||
-rw-r--r-- | libs/hostgraphics/Android.bp | 12 | ||||
-rw-r--r-- | libs/hwui/Android.bp | 13 | ||||
-rw-r--r-- | libs/hwui/RenderProperties.h | 27 |
5 files changed, 189 insertions, 23 deletions
diff --git a/core/jni/Android.bp b/core/jni/Android.bp index 240028c191bc..76e71380017c 100644 --- a/core/jni/Android.bp +++ b/core/jni/Android.bp @@ -400,6 +400,7 @@ cc_library_shared_for_libandroid_runtime { "libbinary_parse", "libdng_sdk", "libft2", + "libhostgraphics", "libhwui", "libimage_type_recognition", "libjpeg", diff --git a/libs/hostgraphics/ADisplay.cpp b/libs/hostgraphics/ADisplay.cpp new file mode 100644 index 000000000000..9cc1f40184e3 --- /dev/null +++ b/libs/hostgraphics/ADisplay.cpp @@ -0,0 +1,159 @@ +/* + * Copyright 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. + */ + +#include <apex/display.h> +#include <utils/Errors.h> + +namespace android::display::impl { + +/** + * Implementation of ADisplayConfig + */ +struct DisplayConfigImpl { + /** + * The width in pixels of the display configuration. + */ + int32_t width{1080}; + + /** + * The height in pixels of the display configuration. + */ + + int32_t height{1920}; + + /** + * The refresh rate of the display configuration, in frames per second. + */ + float fps{60.0}; + + /** + * The vsync offset at which surfaceflinger runs, in nanoseconds. + */ + int64_t sfOffset{0}; + + /** + * The vsync offset at which applications run, in nanoseconds. + */ + int64_t appOffset{0}; +}; + +// DisplayConfigImpl allocation is not managed through C++ memory apis, so +// preventing calling the destructor here. +static_assert(std::is_trivially_destructible<DisplayConfigImpl>::value); + +/** + * Implementation of ADisplay + */ +struct DisplayImpl { + /** + * The type of the display, i.e. whether it is an internal or external + * display. + */ + ADisplayType type; + + /** + * The preferred WCG dataspace + */ + ADataSpace wcgDataspace; + + /** + * The preferred WCG pixel format + */ + AHardwareBuffer_Format wcgPixelFormat; + + /** + * The config for this display. + */ + DisplayConfigImpl config; +}; + +// DisplayImpl allocation is not managed through C++ memory apis, so +// preventing calling the destructor here. +static_assert(std::is_trivially_destructible<DisplayImpl>::value); + +} // namespace android::display::impl + +using namespace android; +using namespace android::display::impl; + +namespace android { + +int ADisplay_acquirePhysicalDisplays(ADisplay*** outDisplays) { + // This is running on host, so there are no physical displays available. + // Create 1 fake display instead. + DisplayImpl** const impls = reinterpret_cast<DisplayImpl**>( + malloc(sizeof(DisplayImpl*) + sizeof(DisplayImpl))); + DisplayImpl* const displayData = reinterpret_cast<DisplayImpl*>(impls + 1); + + displayData[0] = DisplayImpl{ADisplayType::DISPLAY_TYPE_INTERNAL, + ADataSpace::ADATASPACE_UNKNOWN, + AHardwareBuffer_Format::AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM, + DisplayConfigImpl()}; + impls[0] = displayData; + *outDisplays = reinterpret_cast<ADisplay**>(impls); + return 1; +} + +void ADisplay_release(ADisplay** displays) { + if (displays == nullptr) { + return; + } + free(displays); +} + +float ADisplay_getMaxSupportedFps(ADisplay* display) { + DisplayImpl* impl = reinterpret_cast<DisplayImpl*>(display); + return impl->config.fps; +} + +ADisplayType ADisplay_getDisplayType(ADisplay* display) { + return reinterpret_cast<DisplayImpl*>(display)->type; +} + +void ADisplay_getPreferredWideColorFormat(ADisplay* display, ADataSpace* outDataspace, + AHardwareBuffer_Format* outPixelFormat) { + DisplayImpl* impl = reinterpret_cast<DisplayImpl*>(display); + *outDataspace = impl->wcgDataspace; + *outPixelFormat = impl->wcgPixelFormat; +} + +int ADisplay_getCurrentConfig(ADisplay* display, ADisplayConfig** outConfig) { + DisplayImpl* impl = reinterpret_cast<DisplayImpl*>(display); + *outConfig = reinterpret_cast<ADisplayConfig*>(&impl->config); + return OK; +} + +int32_t ADisplayConfig_getWidth(ADisplayConfig* config) { + return reinterpret_cast<DisplayConfigImpl*>(config)->width; +} + +int32_t ADisplayConfig_getHeight(ADisplayConfig* config) { + return reinterpret_cast<DisplayConfigImpl*>(config)->height; +} + +float ADisplayConfig_getFps(ADisplayConfig* config) { + return reinterpret_cast<DisplayConfigImpl*>(config)->fps; +} + +int64_t ADisplayConfig_getCompositorOffsetNanos(ADisplayConfig* config) { + return reinterpret_cast<DisplayConfigImpl*>(config)->sfOffset; +} + +int64_t ADisplayConfig_getAppVsyncOffsetNanos(ADisplayConfig* config) { + return reinterpret_cast<DisplayConfigImpl*>(config)->appOffset; +} + +} // namespace android diff --git a/libs/hostgraphics/Android.bp b/libs/hostgraphics/Android.bp index f166fdeafa41..4407af68de99 100644 --- a/libs/hostgraphics/Android.bp +++ b/libs/hostgraphics/Android.bp @@ -22,6 +22,7 @@ cc_library_host_static { srcs: [ ":libui_host_common", + "ADisplay.cpp", "Fence.cpp", "HostBufferQueue.cpp", "PublicFormat.cpp", @@ -32,16 +33,21 @@ cc_library_host_static { // When frameworks/native/include will be removed from the list of automatic includes. // We will have to copy necessary headers with a pre-build step (generated headers). ".", - "frameworks/native/libs/nativebase/include", - "frameworks/native/libs/nativewindow/include", "frameworks/native/libs/arect/include", "frameworks/native/libs/ui/include_private", ], + + header_libs: [ + "libnativebase_headers", + "libnativedisplay_headers", + "libnativewindow_headers", + ], + export_include_dirs: ["."], target: { windows: { enabled: true, - } + }, }, } diff --git a/libs/hwui/Android.bp b/libs/hwui/Android.bp index 4e349e681e15..cb7c2ada2ab4 100644 --- a/libs/hwui/Android.bp +++ b/libs/hwui/Android.bp @@ -559,6 +559,7 @@ cc_defaults { "AnimatorManager.cpp", "CanvasTransform.cpp", "DamageAccumulator.cpp", + "DeviceInfo.cpp", "FrameInfo.cpp", "FrameInfoVisualizer.cpp", "FrameMetricsReporter.cpp", @@ -626,7 +627,6 @@ cc_defaults { "utils/NdkUtils.cpp", "AutoBackendTextureRelease.cpp", "DeferredLayerUpdater.cpp", - "DeviceInfo.cpp", "HardwareBitmapUploader.cpp", "HWUIProperties.sysprop", "JankTracker.cpp", @@ -643,7 +643,10 @@ cc_defaults { cflags: ["-Wno-implicit-fallthrough"], }, host: { - header_libs: ["libnativebase_headers"], + header_libs: [ + "libnativebase_headers", + "libnativedisplay_headers", + ], local_include_dirs: ["platform/host"], @@ -655,7 +658,11 @@ cc_defaults { "platform/host/WebViewFunctorManager.cpp", ], - cflags: ["-Wno-unused-private-field"], + cflags: [ + "-DHWUI_NULL_GPU", + "-DNULL_GPU_MAX_TEXTURE_SIZE=4096", + "-Wno-unused-private-field", + ], }, }, } diff --git a/libs/hwui/RenderProperties.h b/libs/hwui/RenderProperties.h index e358b57f6fe1..b1ad8b2eb1b9 100644 --- a/libs/hwui/RenderProperties.h +++ b/libs/hwui/RenderProperties.h @@ -16,32 +16,29 @@ #pragma once -#ifdef __ANDROID__ // Layoutlib does not support device info -#include "DeviceInfo.h" -#endif // __ANDROID__ - -#include "Outline.h" -#include "Rect.h" -#include "RevealClip.h" -#include "effects/StretchEffect.h" -#include "utils/MathUtils.h" -#include "utils/PaintUtils.h" - #include <SkBlendMode.h> -#include <SkImageFilter.h> #include <SkCamera.h> #include <SkColor.h> +#include <SkImageFilter.h> #include <SkMatrix.h> #include <SkRegion.h> - #include <androidfw/ResourceTypes.h> #include <cutils/compiler.h> #include <stddef.h> #include <utils/Log.h> + #include <algorithm> #include <ostream> #include <vector> +#include "DeviceInfo.h" +#include "Outline.h" +#include "Rect.h" +#include "RevealClip.h" +#include "effects/StretchEffect.h" +#include "utils/MathUtils.h" +#include "utils/PaintUtils.h" + class SkBitmap; class SkColorFilter; class SkPaint; @@ -546,13 +543,9 @@ public: } bool fitsOnLayer() const { -#ifdef __ANDROID__ // Layoutlib does not support device info const DeviceInfo* deviceInfo = DeviceInfo::get(); return mPrimitiveFields.mWidth <= deviceInfo->maxTextureSize() && mPrimitiveFields.mHeight <= deviceInfo->maxTextureSize(); -#else - return mPrimitiveFields.mWidth <= 4096 && mPrimitiveFields.mHeight <= 4096; -#endif } bool promotedToLayer() const { |