From 9c3b958ff46920380897824a3713b8532d4e86da Mon Sep 17 00:00:00 2001 From: ShaoboFeng Date: Sun, 18 Jun 2023 18:25:27 +0800 Subject: [PATCH 01/12] add sync_fence buffer_handle render_service_base surface --- build/gn/BUILD.gn | 3 + .../frameworks/surface/ft_build/BUILD.gn | 80 ++ .../ft_build/mock/display_gralloc_client.cpp | 14 + .../surface/ft_build/mock/idisplay_gralloc.h | 156 +++ .../surface/include/surface_buffer_impl.h | 1 + .../frameworks/surface/src/native_window.cpp | 2 +- display_server/ft_configs/ds_config.gni | 18 + .../inner_api/surface/external_window.h | 8 +- .../interfaces/inner_api/surface/window.h | 4 +- .../rosen/modules/composer/ft_build/BUILD.gn | 80 ++ .../modules/render_service/ft_build/BUILD.gn | 87 ++ .../modules/render_service_base/BUILD.gn | 1 + .../render_service_base/ft_build/BUILD.gn | 205 ++++ .../ft_build/mock/BUILD.gn | 28 + .../platform/common/rs_event_detector.h | 6 +- .../platform/common/rs_event_manager.h | 3 +- .../include/render/rs_mask.h | 8 +- .../src/command/rs_surface_node_command.cpp | 2 +- .../src/pipeline/rs_surface_render_node.cpp | 2 +- .../src/platform/fangtian/BUILD.gn | 123 ++ .../backend/rs_surface_frame_ohos_gl.cpp | 77 ++ .../backend/rs_surface_frame_ohos_gl.h | 51 + .../backend/rs_surface_frame_ohos_raster.cpp | 101 ++ .../backend/rs_surface_frame_ohos_raster.h | 71 ++ .../fangtian/backend/rs_surface_ohos_gl.cpp | 142 +++ .../fangtian/backend/rs_surface_ohos_gl.h | 57 + .../backend/rs_surface_ohos_raster.cpp | 117 ++ .../fangtian/backend/rs_surface_ohos_raster.h | 48 + .../platform/fangtian/include/hisysevent.h | 129 +++ .../src/platform/fangtian/include/parameter.h | 182 +++ .../platform/fangtian/include/parameters.h | 23 + .../rs_cpu_overdraw_canvas_listener.cpp | 215 ++++ .../rs_gpu_overdraw_canvas_listener.cpp | 145 +++ .../fangtian/overdraw/rs_listened_canvas.cpp | 174 +++ .../overdraw/rs_overdraw_controller.cpp | 144 +++ .../platform/fangtian/rs_accessibility.cpp | 79 ++ .../platform/fangtian/rs_ashmem_helper.cpp | 283 +++++ .../platform/fangtian/rs_event_detector.cpp | 106 ++ .../platform/fangtian/rs_event_manager.cpp | 214 ++++ .../src/platform/fangtian/rs_frame_report.cpp | 150 +++ .../src/platform/fangtian/rs_innovation.cpp | 143 +++ .../src/platform/fangtian/rs_log.cpp | 73 ++ .../fangtian/rs_marshalling_helper.cpp | 916 +++++++++++++++ .../src/platform/fangtian/rs_param.cpp | 34 + .../fangtian/rs_render_service_client.cpp | 616 ++++++++++ .../rs_render_service_connect_hub.cpp | 180 +++ .../fangtian/rs_render_service_connect_hub.h | 77 ++ .../rs_render_service_connection_proxy.cpp | 1014 +++++++++++++++++ .../rs_render_service_connection_proxy.h | 128 +++ .../fangtian/rs_render_service_proxy.cpp | 59 + .../fangtian/rs_render_service_proxy.h | 39 + .../fangtian/rs_surface_frame_ohos.cpp | 27 + .../platform/fangtian/rs_surface_frame_ohos.h | 36 + .../src/platform/fangtian/rs_surface_ohos.cpp | 52 + .../src/platform/fangtian/rs_surface_ohos.h | 55 + .../fangtian/rs_surface_ohos_converter.cpp | 38 + .../fangtian/rs_system_properties.cpp | 184 +++ .../src/platform/fangtian/rs_vsync_client.cpp | 82 ++ .../src/platform/fangtian/rs_vsync_client.h | 51 + .../src/render/rs_mask.cpp | 4 +- .../utils/buffer_handle/ft_build/BUILD.gn | 33 + .../utils/sync_fence/ft_build/BUILD.gn | 55 + .../sync_fence/src/sync_fence_tracker.cpp | 3 +- 63 files changed, 7219 insertions(+), 19 deletions(-) create mode 100644 display_server/frameworks/surface/ft_build/BUILD.gn create mode 100644 display_server/frameworks/surface/ft_build/mock/display_gralloc_client.cpp create mode 100644 display_server/frameworks/surface/ft_build/mock/idisplay_gralloc.h create mode 100644 display_server/ft_configs/ds_config.gni create mode 100644 display_server/rosen/modules/composer/ft_build/BUILD.gn create mode 100644 display_server/rosen/modules/render_service/ft_build/BUILD.gn create mode 100644 display_server/rosen/modules/render_service_base/ft_build/BUILD.gn create mode 100644 display_server/rosen/modules/render_service_base/ft_build/mock/BUILD.gn create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/BUILD.gn create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_frame_ohos_gl.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_frame_ohos_gl.h create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_frame_ohos_raster.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_frame_ohos_raster.h create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_ohos_gl.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_ohos_gl.h create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_ohos_raster.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_ohos_raster.h create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/include/hisysevent.h create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/include/parameter.h create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/include/parameters.h create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/overdraw/rs_cpu_overdraw_canvas_listener.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/overdraw/rs_gpu_overdraw_canvas_listener.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/overdraw/rs_listened_canvas.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/overdraw/rs_overdraw_controller.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_accessibility.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_ashmem_helper.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_event_detector.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_event_manager.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_frame_report.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_innovation.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_log.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_marshalling_helper.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_param.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_render_service_client.cpp create mode 100755 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_render_service_connect_hub.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_render_service_connect_hub.h create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_render_service_connection_proxy.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_render_service_connection_proxy.h create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_render_service_proxy.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_render_service_proxy.h create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_surface_frame_ohos.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_surface_frame_ohos.h create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_surface_ohos.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_surface_ohos.h create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_surface_ohos_converter.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_system_properties.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_vsync_client.cpp create mode 100644 display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_vsync_client.h create mode 100644 display_server/utils/buffer_handle/ft_build/BUILD.gn create mode 100644 display_server/utils/sync_fence/ft_build/BUILD.gn diff --git a/build/gn/BUILD.gn b/build/gn/BUILD.gn index cc6bf28..5c2c9e9 100644 --- a/build/gn/BUILD.gn +++ b/build/gn/BUILD.gn @@ -15,5 +15,8 @@ group("ft_engine") { deps = [ "//display_server/utils/socketpair/ft_build:socketpair", "//display_server/rosen/modules/composer/vsync/ft_build:libvsync", + "//display_server/utils/sync_fence/ft_build:sync_fence", + "//display_server/frameworks/surface/ft_build:surface", + "//display_server/rosen/modules/render_service_base/ft_build:librender_service_base", ] } diff --git a/display_server/frameworks/surface/ft_build/BUILD.gn b/display_server/frameworks/surface/ft_build/BUILD.gn new file mode 100644 index 0000000..a210c51 --- /dev/null +++ b/display_server/frameworks/surface/ft_build/BUILD.gn @@ -0,0 +1,80 @@ +# Copyright (c) 2021 Huawei Technologies Co., Ltd. +# 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. + +import("//build/gn/fangtian.gni") +import("//display_server/ft_configs/ds_config.gni") + +config("surface_config") { + visibility = [ ":*" ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + "-Wno-error=deprecated-declarations", + "-Wno-c++11-narrowing", + ] + + include_dirs = [ + "${sys_inc}/c_utils", + "${sys_inc}/ipc_core", + "${sys_inc}/hilog", + "${sys_inc}/hitrace_meter", + "../include", + "$display_server_root/interfaces/inner_api/surface", + "$display_server_root/interfaces/inner_api/common", + "$display_server_root/utils/sandbox", + "$display_server_root/utils/buffer_handle/export", + "mock", + ] + + defines = [] + if (ace_enable_gpu) { + defines = [ "ACE_ENABLE_GPU" ] + } + defines += gpu_defines + +} + +ft_shared_library("surface") { + sources = [ + "../src/buffer_client_producer.cpp", + "../src/buffer_extra_data_impl.cpp", + "../src/buffer_manager.cpp", + "../src/buffer_queue.cpp", + "../src/buffer_queue_consumer.cpp", + "../src/buffer_queue_producer.cpp", + "../src/buffer_utils.cpp", + "../src/consumer_surface.cpp", + "../src/native_buffer.cpp", + "../src/native_window.cpp", + "../src/producer_surface.cpp", + "../src/surface.cpp", + "../src/surface_buffer_impl.cpp", + "../src/surface_delegate.cpp", + "../src/surface_tunnel_handle.cpp", + "../src/surface_utils.cpp", + "mock/display_gralloc_client.cpp", + ] + + configs = [ ":surface_config" ] + + + deps = [ + "$display_server_root/utils/sync_fence/ft_build:sync_fence", + "$display_server_root/utils/buffer_handle/ft_build:buffer_handle", + "$display_server_root/utils/sandbox/ft_build:sandbox_utils", + "$display_server_root/utils/scoped_bytrace/ft_build:scoped_bytrace", + ] +} + diff --git a/display_server/frameworks/surface/ft_build/mock/display_gralloc_client.cpp b/display_server/frameworks/surface/ft_build/mock/display_gralloc_client.cpp new file mode 100644 index 0000000..82236b1 --- /dev/null +++ b/display_server/frameworks/surface/ft_build/mock/display_gralloc_client.cpp @@ -0,0 +1,14 @@ +#include +#include "idisplay_gralloc.h" + +namespace OHOS { +namespace HDI { +namespace Display { +namespace V1_0 { +IDisplayGralloc *IDisplayGralloc::Get(){ + return nullptr; +} +} +} +} +} diff --git a/display_server/frameworks/surface/ft_build/mock/idisplay_gralloc.h b/display_server/frameworks/surface/ft_build/mock/idisplay_gralloc.h new file mode 100644 index 0000000..7eb3965 --- /dev/null +++ b/display_server/frameworks/surface/ft_build/mock/idisplay_gralloc.h @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef HDI_IDISPLAY_GRALLOC_V1_0_H +#define HDI_IDISPLAY_GRALLOC_V1_0_H + +#include +#include "display_type.h" +#include "buffer_handle.h" + +namespace OHOS { +namespace HDI { +namespace Display { +namespace V1_0 { +using AllocatorDeathCallback = void (*)(void *); +class IDisplayGralloc { +public: + virtual ~IDisplayGralloc() = default; + + virtual int32_t RegAllocatorDeathCallback(AllocatorDeathCallback func, void* data) = 0; + + /** + * @brief Obtains all interfaces of IDisplayGralloc. + * + * @return Returns IDisplayGralloc* if the operation is successful; returns an null point otherwise. + * @since 1.0 + * @version 1.0 + */ + static IDisplayGralloc* Get(); + + /** + * @brief Allocates memory based on the parameters passed by the GUI. + * + * @param info Indicates the description of the memory to allocate. + * + * @param handle Indicates the pointer to the buffer of the memory to allocate. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t AllocMem(const AllocInfo &info, BufferHandle *&handle) const = 0; + + /** + * @brief Releases memory. + * + * @param handle Indicates the reference to the buffer of the memory to release. + * + * @since 1.0 + * @version 1.0 + */ + virtual void FreeMem(const BufferHandle &handle) const = 0; + + /** + * @brief Maps memory to memory without cache in the process's address space. + * + * @param handle Indicates the reference to the buffer of the memory to map. + * + * @return Returns the pointer to a valid address if the operation is successful; returns NULL otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual void *Mmap(const BufferHandle &handle) const = 0; + + /** + * @brief Maps memory to memory with cache in the process's address space. + * + * @param handle Indicates the reference to the buffer of the memory to map. + * + * @return Returns the pointer to a valid address if the operation is successful; returns NULL otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual void *MmapCache(const BufferHandle &buffer) const = 0; + + /** + * @brief Unmaps memory, that is, removes mappings from the process's address space. + * + * @param handle Indicates the reference to the buffer of the memory to unmap. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t Unmap(const BufferHandle &handle) const = 0; + + /** + * @brief Flushes data from the cache to memory and invalidates the data in the cache. + * + * @param handle Indicates the reference to the buffer of the cache to flush. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t FlushCache(const BufferHandle &handle) const = 0; + + /** + * @brief Flushes data from the cache mapped via {@link Mmap} to memory and invalidates the data in the cache. + * + * @param handle Indicates the reference to the buffer of the cache to flush. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t FlushMCache(const BufferHandle &buffer) const = 0; + + /** + * @brief Invalidates the cache to update it from memory. + * + * @param handle Indicates the reference to the buffer of the cache, which will be invalidated. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t InvalidateCache(const BufferHandle &handle) const = 0; + + /** + * @brief Checks whether the given VerifyAllocInfo array is allocatable. + * + * @param infos Indicates the VerifyAllocInfo array. + * @param supporteds Indicates whether the array is allocatable. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t IsSupportedAlloc(const std::vector &infos, + std::vector &supporteds) const = 0; +}; +} // namespace V1_0 +} // namespace Display +} // namespace HDI +} // namespace OHOS + +#endif // HDI_IDISPLAY_GRALLOC_V1_0_H diff --git a/display_server/frameworks/surface/include/surface_buffer_impl.h b/display_server/frameworks/surface/include/surface_buffer_impl.h index ea68eb3..456ca7f 100644 --- a/display_server/frameworks/surface/include/surface_buffer_impl.h +++ b/display_server/frameworks/surface/include/surface_buffer_impl.h @@ -23,6 +23,7 @@ #include #include "egl_data.h" #include "stdint.h" +#include struct BufferWrapper {}; diff --git a/display_server/frameworks/surface/src/native_window.cpp b/display_server/frameworks/surface/src/native_window.cpp index 43b5496..38edc57 100644 --- a/display_server/frameworks/surface/src/native_window.cpp +++ b/display_server/frameworks/surface/src/native_window.cpp @@ -104,7 +104,7 @@ int32_t NativeWindowRequestBuffer(OHNativeWindow *window, } int32_t NativeWindowFlushBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer, - int fenceFd, struct Region region) + int fenceFd, struct DirtyRegion region) { if (window == nullptr || buffer == nullptr || window->surface == nullptr) { BLOGE("parameter error, please check input parameter"); diff --git a/display_server/ft_configs/ds_config.gni b/display_server/ft_configs/ds_config.gni new file mode 100644 index 0000000..1f7e7da --- /dev/null +++ b/display_server/ft_configs/ds_config.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2021-2022 Huawei Technologies Co., Ltd. +# 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. + +display_server_root = "//display_server" +rosen_root = "//display_server/rosen" +rs_enable_gpu = false +ace_enable_gpu = false +gpu_defines = [] diff --git a/display_server/interfaces/inner_api/surface/external_window.h b/display_server/interfaces/inner_api/surface/external_window.h index 8871c0d..2878133 100644 --- a/display_server/interfaces/inner_api/surface/external_window.h +++ b/display_server/interfaces/inner_api/surface/external_window.h @@ -66,7 +66,7 @@ typedef struct NativeWindowBuffer OHNativeWindowBuffer; /** * @brief indicates a dirty region where content is updated. */ -typedef struct Region { +typedef struct DirtyRegion { /** if rects is nullptr, fill the Buffer dirty size by default */ struct Rect { int32_t x; @@ -76,7 +76,7 @@ typedef struct Region { } *rects; /** if rectNumber is 0, fill the Buffer dirty size by default */ int32_t rectNumber; -}Region; +}DirtyRegion; /** @@ -321,7 +321,7 @@ int32_t OH_NativeWindow_NativeWindowRequestBuffer(OHNativeWindow *window, * @version 1.0 */ int32_t OH_NativeWindow_NativeWindowFlushBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer, - int fenceFd, Region region); + int fenceFd, DirtyRegion region); /** * @brief Returns the NativeWindowBuffer to the buffer queue through a NativeWindow instance, without filling in any content. The NativeWindowBuffer can be used for another request. @@ -454,4 +454,4 @@ int32_t OH_NativeWindow_NativeWindowSetTunnelHandle(OHNativeWindow *window, cons #endif /** @} */ -#endif \ No newline at end of file +#endif diff --git a/display_server/interfaces/inner_api/surface/window.h b/display_server/interfaces/inner_api/surface/window.h index bd3f4fa..2d06982 100644 --- a/display_server/interfaces/inner_api/surface/window.h +++ b/display_server/interfaces/inner_api/surface/window.h @@ -41,7 +41,7 @@ void DestroyNativeWindowBuffer(OHNativeWindowBuffer* buffer); int32_t NativeWindowRequestBuffer(OHNativeWindow *window, /* [out] */ OHNativeWindowBuffer **buffer, /* [out] get release fence */ int *fenceFd); int32_t NativeWindowFlushBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer, - int fenceFd, Region region); + int fenceFd, DirtyRegion region); int32_t NativeWindowCancelBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer); // The meaning and quantity of parameters vary according to the code type. @@ -65,4 +65,4 @@ int32_t NativeWindowSetTunnelHandle(OHNativeWindow *window, const OHExtDataHandl } #endif -#endif \ No newline at end of file +#endif diff --git a/display_server/rosen/modules/composer/ft_build/BUILD.gn b/display_server/rosen/modules/composer/ft_build/BUILD.gn new file mode 100644 index 0000000..ad12ac8 --- /dev/null +++ b/display_server/rosen/modules/composer/ft_build/BUILD.gn @@ -0,0 +1,80 @@ +# Copyright (c) 2021 Huawei Technologies Co., Ltd. +# 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. + +import("//build/gn/fangtian.gni") +import("//display_server/ft_configs/ds_config.gni") + +## Build libcomposer.so +config("composer_config") { + visibility = [ ":*" ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +config("composer_public_config") { + include_dirs = [ + "//foundation/graphic/graphic_2d/rosen/include/common", + "//drivers/peripheral/display/interfaces/include", + "//foundation/graphic/graphic_2d/interfaces/inner_api/common", + "//foundation/graphic/graphic_2d/rosen/modules/composer/hdi_backend/include", + "//foundation/graphic/graphic_2d/rosen/modules/composer/vsync/include", + "//foundation/graphic/graphic_2d/interfaces/inner_api/composer", + ] +} + +ft_shared_library("libcomposer") { + sources = [ + "hdi_backend/src/hdi_backend.cpp", + "hdi_backend/src/hdi_device.cpp", + "hdi_backend/src/hdi_framebuffer_surface.cpp", + "hdi_backend/src/hdi_layer.cpp", + "hdi_backend/src/hdi_output.cpp", + "hdi_backend/src/hdi_screen.cpp", + ] + + include_dirs = [ + "$graphic_2d_root/rosen/modules/render_frame_trace/include", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_base/src", + "//foundation/graphic/graphic_2d/utils/log", + ] + + configs = [ ":composer_config" ] + + defines = [] + + public_configs = [ + ":composer_public_config", + "//commonlibrary/c_utils/base:utils_config", + ] + + deps = [ + "//foundation/graphic/graphic_2d/frameworks/surface:surface", + "$graphic_2d_root/rosen/modules/render_frame_trace:render_frame_trace", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base", + ] + + public_deps = [ + "vsync:libvsync", + "//commonlibrary/c_utils/base:utils", + "//foundation/graphic/graphic_2d/utils:buffer_handle", + "//foundation/graphic/graphic_2d/utils:scoped_bytrace", + "//foundation/graphic/graphic_2d/utils:sync_fence", + "//drivers/peripheral/display/hal/openeuler/core/drm_backend/display_device:display_device", + "//drivers/peripheral/display/hal/openeuler/core/drm_backend/display_gralloc:display_gralloc", + ] +} + diff --git a/display_server/rosen/modules/render_service/ft_build/BUILD.gn b/display_server/rosen/modules/render_service/ft_build/BUILD.gn new file mode 100644 index 0000000..64b2d2e --- /dev/null +++ b/display_server/rosen/modules/render_service/ft_build/BUILD.gn @@ -0,0 +1,87 @@ +# Copyright (c) 2021-2022 Huawei Technologies Co., Ltd. +# 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. + +import("//build/gn/fangtian.gni") +import("//display_server/ft_configs/ds_config.gni") + +ft_shared_library("librender_service") { + defines = [] + + sources = [ + "core/pipeline/rs_base_render_engine.cpp", + "core/pipeline/rs_base_render_util.cpp", + "core/pipeline/rs_cold_start_thread.cpp", + "core/pipeline/rs_composer_adapter.cpp", + "core/pipeline/rs_divided_render_util.cpp", + "core/pipeline/rs_main_thread.cpp", + "core/pipeline/rs_physical_screen_processor.cpp", + "core/pipeline/rs_processor.cpp", + "core/pipeline/rs_processor_factory.cpp", + "core/pipeline/rs_qos_thread.cpp", + "core/pipeline/rs_render_engine.cpp", + "core/pipeline/rs_render_service.cpp", + "core/pipeline/rs_render_service_connection.cpp", + "core/pipeline/rs_render_service_listener.cpp", + "core/pipeline/rs_render_service_visitor.cpp", + "core/pipeline/rs_surface_capture_task.cpp", + "core/pipeline/rs_uni_render_engine.cpp", + "core/pipeline/rs_uni_render_judgement.cpp", + "core/pipeline/rs_uni_render_listener.cpp", + "core/pipeline/rs_uni_render_mirror_processor.cpp", + "core/pipeline/rs_uni_render_processor.cpp", + "core/pipeline/rs_uni_render_util.cpp", + "core/pipeline/rs_uni_render_visitor.cpp", + "core/pipeline/rs_unmarshal_thread.cpp", + "core/pipeline/rs_virtual_screen_processor.cpp", + "core/screen_manager/rs_screen.cpp", + "core/screen_manager/rs_screen_manager.cpp", + "core/transaction/rs_render_service_connection_stub.cpp", + "core/transaction/rs_render_service_stub.cpp", + ] + + include_dirs = [ + "core", + "$display_server_root/frameworks/surface/include", + "$display_server_root/rosen/include", + "$display_server_root/rosen/modules/composer/vsync/include", + "$display_server_root/rosen/modules/render_frame_trace/include", + "$display_server_root/rosen/modules/render_service_base/src", + "$display_server_root/rosen/modules/utils", + "$display_server_root/utils/log", + ] + + deps = [ + "$display_server_root/frameworks/surface/ft_build:surface", + "$display_server_root/rosen/modules/composer/ft_build:libcomposer", + "$display_server_root/rosen/modules/render_frame_trace:render_frame_trace", + "$display_server_root/rosen/modules/render_service_base/ft_build:librender_service_base", + ] + + libs = ["png"] +} + +## Build render_service.bin +ft_executable("render_service") { + sources = [ "core/main.cpp" ] + + include_dirs = [ + "core", + "//commonlibrary/c_utils/base/include", + ] + + deps = [ + ":librender_service", + "$display_server_root/rosen/modules/composer/ft_build:libcomposer", + "$display_server_root/rosen/modules/render_service_base/ft_build:librender_service_base", + ] +} diff --git a/display_server/rosen/modules/render_service_base/BUILD.gn b/display_server/rosen/modules/render_service_base/BUILD.gn index f6223b8..168d041 100644 --- a/display_server/rosen/modules/render_service_base/BUILD.gn +++ b/display_server/rosen/modules/render_service_base/BUILD.gn @@ -199,6 +199,7 @@ ohos_source_set("render_service_base_src") { sources -= graphic_2d_ext_configs.librender_service_base_ext_sources_del sources += graphic_2d_ext_configs.librender_service_base_ext_sources } + libs = ["ace_skia_fangtian"] } config("render_service_base_all_deps_config") { diff --git a/display_server/rosen/modules/render_service_base/ft_build/BUILD.gn b/display_server/rosen/modules/render_service_base/ft_build/BUILD.gn new file mode 100644 index 0000000..bcb84d9 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/ft_build/BUILD.gn @@ -0,0 +1,205 @@ +# Copyright (c) 2021-2023 Huawei Technologies Co., Ltd. +# 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. + +import("//build/gn/fangtian.gni") +import("//display_server/ft_configs/ds_config.gni") + +rs_common_define = [ "ROSEN_OHOS" ] +enable_export_macro = true + +config("export_config") { + cflags_cc = [ "-std=c++17" ] + include_dirs = [ "include" ] + + defines = rs_common_define +} + +ft_source_set("render_service_base_src") { + defines = ["__FANGTIAN__"] + defines += [ "MODULE_RSB" ] + + sources = [ + #animation + "../src/animation/rs_animation_fraction.cpp", + "../src/animation/rs_animation_manager.cpp", + "../src/animation/rs_interpolator.cpp", + "../src/animation/rs_render_animation.cpp", + "../src/animation/rs_render_curve_animation.cpp", + "../src/animation/rs_render_keyframe_animation.cpp", + "../src/animation/rs_render_path_animation.cpp", + "../src/animation/rs_render_property_animation.cpp", + "../src/animation/rs_render_spring_animation.cpp", + "../src/animation/rs_render_transition.cpp", + "../src/animation/rs_render_transition_effect.cpp", + "../src/animation/rs_spring_interpolator.cpp", + "../src/animation/rs_spring_model.cpp", + "../src/animation/rs_steps_interpolator.cpp", + "../src/animation/rs_transition_effect.cpp", + "../src/animation/rs_value_estimator.cpp", + + # message(depracated) + "../src/command/rs_message_processor.cpp", + + # modifier + "../src/modifier/rs_render_modifier.cpp", + "../src/modifier/rs_render_property.cpp", + + #command + "../src/command/rs_animation_command.cpp", + "../src/command/rs_base_node_command.cpp", + "../src/command/rs_canvas_node_command.cpp", + "../src/command/rs_command_factory.cpp", + "../src/command/rs_display_node_command.cpp", + "../src/command/rs_node_command.cpp", + "../src/command/rs_proxy_node_command.cpp", + "../src/command/rs_root_node_command.cpp", + "../src/command/rs_surface_node_command.cpp", + + #common + "../src/common/rs_color.cpp", + "../src/common/rs_common_def.cpp", + "../src/common/rs_obj_abs_geometry.cpp", + "../src/common/rs_occlusion_region.cpp", + "../src/common/rs_thread_handler_generic.cpp", + "../src/common/rs_thread_looper_generic.cpp", + "../src/common/rs_thread_looper_impl.cpp", + + #delegate + "../src/delegate/rs_functional_delegate.cpp", + + #ipc_callbacks + "../src/ipc_callbacks/buffer_available_callback_proxy.cpp", + "../src/ipc_callbacks/buffer_available_callback_stub.cpp", + "../src/ipc_callbacks/rs_application_agent_proxy.cpp", + "../src/ipc_callbacks/rs_application_agent_stub.cpp", + "../src/ipc_callbacks/rs_occlusion_change_callback_proxy.cpp", + "../src/ipc_callbacks/rs_occlusion_change_callback_stub.cpp", + "../src/ipc_callbacks/rs_render_mode_change_callback_proxy.cpp", + "../src/ipc_callbacks/rs_render_mode_change_callback_stub.cpp", + "../src/ipc_callbacks/screen_change_callback_proxy.cpp", + "../src/ipc_callbacks/screen_change_callback_stub.cpp", + "../src/ipc_callbacks/surface_capture_callback_proxy.cpp", + "../src/ipc_callbacks/surface_capture_callback_stub.cpp", + + #pipeline + "../src/pipeline/rs_base_render_node.cpp", + "../src/pipeline/rs_canvas_render_node.cpp", + "../src/pipeline/rs_context.cpp", + "../src/pipeline/rs_dirty_region_manager.cpp", + "../src/pipeline/rs_display_render_node.cpp", + "../src/pipeline/rs_draw_cmd.cpp", + "../src/pipeline/rs_draw_cmd_list.cpp", + "../src/pipeline/rs_occlusion_config.cpp", + "../src/pipeline/rs_paint_filter_canvas.cpp", + "../src/pipeline/rs_proxy_render_node.cpp", + "../src/pipeline/rs_recording_canvas.cpp", + "../src/pipeline/rs_render_node.cpp", + "../src/pipeline/rs_render_node_map.cpp", + "../src/pipeline/rs_root_render_node.cpp", + "../src/pipeline/rs_surface_handler.cpp", + "../src/pipeline/rs_surface_render_node.cpp", + + #property + "../src/property/rs_properties.cpp", + "../src/property/rs_properties_painter.cpp", + "../src/property/rs_property_trace.cpp", + + #render + "../src/render/rs_blur_filter.cpp", + "../src/render/rs_border.cpp", + "../src/render/rs_filter.cpp", + "../src/render/rs_image.cpp", + "../src/render/rs_image_cache.cpp", + "../src/render/rs_mask.cpp", + "../src/render/rs_material_filter.cpp", + "../src/render/rs_path.cpp", + "../src/render/rs_shader.cpp", + "../src/render/rs_shadow.cpp", + "../src/render/rs_skia_filter.cpp", + + #transaction + "../src/transaction/rs_occlusion_data.cpp", + "../src/transaction/rs_transaction_data.cpp", + "../src/transaction/rs_transaction_proxy.cpp", + + #screen_manager + "../src/screen_manager/rs_screen_capability.cpp", + "../src/screen_manager/rs_screen_data.cpp", + "../src/screen_manager/rs_screen_hdr_capability.cpp", + "../src/screen_manager/rs_screen_mode_info.cpp", + "../src/screen_manager/rs_screen_props.cpp", + "../src/screen_manager/rs_virtual_screen_resolution.cpp", + ] + + cflags = [ + "-Wall", + "-Wno-pointer-arith", + "-Wno-non-virtual-dtor", + "-Wno-missing-field-initializers", + "-Wno-c++11-narrowing", + "-fvisibility=hidden", + ] + + cflags_cc = [ + "-std=c++17", + "-fvisibility-inlines-hidden", + ] + + public_configs = [ + ":export_config", + ] + deps = [ + "../src/platform/fangtian:rosen_fangtian_sources", + "mock:mock_image_native", + ] + + if (enable_export_macro) { + defines += [ "ENABLE_EXPORT_MACRO" ] + } + + if (rs_enable_gpu) { + sources += [ "src/common/rs_shared_context.cpp" ] + defines += [ + "GR_TEST_UTILS=1", + ] + } + + include_dirs = [ + "${sys_inc}/c_utils", + "${sys_inc}/skia", + "${sys_inc}/ipc_core", + "${sys_inc}/hitrace_meter", + "${sys_inc}/eventhandler", + "$rosen_root/modules/render_service_base/src", + "$rosen_root/modules/platform/image_native", + "$rosen_root/modules/composer/vsync/include", + "$display_server_root/utils/log", + "$display_server_root/interfaces/inner_api/surface", + "$display_server_root/interfaces/inner_api/composer", + "../include", + ] + + deps += [ + "$display_server_root/utils/buffer_handle/ft_build:buffer_handle", + "$display_server_root/utils/sandbox/ft_build:sandbox_utils", + "$display_server_root/utils/sync_fence/ft_build:sync_fence", + ] + +} + +ft_shared_library("librender_service_base") { + deps = [ + ":render_service_base_src", + "../src/platform/fangtian:rosen_fangtian_sources", + ] +} diff --git a/display_server/rosen/modules/render_service_base/ft_build/mock/BUILD.gn b/display_server/rosen/modules/render_service_base/ft_build/mock/BUILD.gn new file mode 100644 index 0000000..2fb7f2c --- /dev/null +++ b/display_server/rosen/modules/render_service_base/ft_build/mock/BUILD.gn @@ -0,0 +1,28 @@ +# Copyright (c) 2021-2023 Huawei Technologies Co., Ltd. +# 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. + +import("//build/gn/fangtian.gni") +import("//display_server/ft_configs/ds_config.gni") + +ft_source_set("mock_image_native") { + + include_dirs = [ + "${sys_inc}/c_utils", + "${sys_inc}/skia", + ] + + sources = [ + "../../../platform/image_native/pixel_map.cpp", + "../../../platform/image_native/pixel_map_rosen_utils.cpp", + ] +} diff --git a/display_server/rosen/modules/render_service_base/include/platform/common/rs_event_detector.h b/display_server/rosen/modules/render_service_base/include/platform/common/rs_event_detector.h index a88c81d..e2090dd 100644 --- a/display_server/rosen/modules/render_service_base/include/platform/common/rs_event_detector.h +++ b/display_server/rosen/modules/render_service_base/include/platform/common/rs_event_detector.h @@ -19,8 +19,10 @@ #include #include #include +#include +#include #include "rs_log.h" -#include "base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include/hisysevent.h" +#include "hisysevent.h" namespace OHOS { namespace Rosen { @@ -116,4 +118,4 @@ private: } } -#endif // RENDER_SERVICE_BASE_COMMON_RS_DETECTOR_H \ No newline at end of file +#endif // RENDER_SERVICE_BASE_COMMON_RS_DETECTOR_H diff --git a/display_server/rosen/modules/render_service_base/include/platform/common/rs_event_manager.h b/display_server/rosen/modules/render_service_base/include/platform/common/rs_event_manager.h index 4472e78..993a3de 100644 --- a/display_server/rosen/modules/render_service_base/include/platform/common/rs_event_manager.h +++ b/display_server/rosen/modules/render_service_base/include/platform/common/rs_event_manager.h @@ -17,6 +17,7 @@ #define RENDER_SERVICE_BASE_COMMON_RS_EVENT_MANAGER_H #include +#include #include "rs_event_detector.h" namespace OHOS { @@ -54,4 +55,4 @@ private: }; } } -#endif // RENDER_SERVICE_BASE_COMMON_RS_EVENT_MANAGER_H \ No newline at end of file +#endif // RENDER_SERVICE_BASE_COMMON_RS_EVENT_MANAGER_H diff --git a/display_server/rosen/modules/render_service_base/include/render/rs_mask.h b/display_server/rosen/modules/render_service_base/include/render/rs_mask.h index 4142f6c..0cd4803 100644 --- a/display_server/rosen/modules/render_service_base/include/render/rs_mask.h +++ b/display_server/rosen/modules/render_service_base/include/render/rs_mask.h @@ -18,9 +18,9 @@ #include #include "experimental/svg/model/SkSVGDOM.h" -#include "third_party/skia/include/core/SkPaint.h" -#include "third_party/skia/include/core/SkPath.h" -#include "third_party/skia/include/core/SkPicture.h" +#include "include/core/SkPaint.h" +#include "include/core/SkPath.h" +#include "include/core/SkPicture.h" #include "common/rs_macros.h" #include "transaction/rs_marshalling_helper.h" @@ -89,4 +89,4 @@ private: } // namespace Rosen } // namespace OHOS -#endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_MASK_H \ No newline at end of file +#endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_MASK_H diff --git a/display_server/rosen/modules/render_service_base/src/command/rs_surface_node_command.cpp b/display_server/rosen/modules/render_service_base/src/command/rs_surface_node_command.cpp index 71eb0a4..2a02f1c 100644 --- a/display_server/rosen/modules/render_service_base/src/command/rs_surface_node_command.cpp +++ b/display_server/rosen/modules/render_service_base/src/command/rs_surface_node_command.cpp @@ -56,7 +56,7 @@ void SurfaceNodeCommandHelper::SetSecurityLayer(RSContext& context, NodeId id, b } } -#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__gnu_linux__) +#if (!defined(_WIN32) && !defined(__APPLE__) && !defined(__gnu_linux__)) || defined(__FANGTIAN__) void SurfaceNodeCommandHelper::SetColorSpace(RSContext& context, NodeId id, ColorGamut colorSpace) { if (auto node = context.GetNodeMap().GetRenderNode(id)) { diff --git a/display_server/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp b/display_server/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp index 9647ec9..5fa9f57 100644 --- a/display_server/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp +++ b/display_server/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp @@ -299,7 +299,7 @@ bool RSSurfaceRenderNode::GetSecurityLayer() const return isSecurityLayer_; } -#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__gnu_linux__) +#if (!defined(_WIN32) && !defined(__APPLE__) && !defined(__gnu_linux__)) || defined(__FANGTIAN__) void RSSurfaceRenderNode::SetColorSpace(ColorGamut colorSpace) { colorSpace_ = colorSpace; diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/BUILD.gn b/display_server/rosen/modules/render_service_base/src/platform/fangtian/BUILD.gn new file mode 100644 index 0000000..7eb87a6 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/BUILD.gn @@ -0,0 +1,123 @@ +# Copyright (c) 2021-2023 Huawei Device Co., Ltd. +# 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. + +import("//build/gn/fangtian.gni") +import("//display_server/ft_configs/ds_config.gni") +#import("../../../config.gni") +# TODO enable hisysevent +#hisysevent_enable = false + +config("export_config") { + include_dirs = [ + "$rosen_root/include", + "//foundation/graphic/graphic_2d/rosen/modules/composer/vsync/include", + "//foundation/graphic/graphic_2d/frameworks/surface/src", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/src", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/include", + "//foundation/multimedia/image_framework/interfaces/innerkits/include", + "$display_server_root/interfaces/inner_api/surface", + "$display_server_root/interfaces/inner_api/common", + ] +} + +ft_source_set("rosen_fangtian_sources") { + public_configs = [ ":export_config" ] + + cflags_cc = [ + "-std=c++17", + "-Wno-c++11-narrowing", + ] + + defines = [ "ROSEN_OHOS" ] + defines += gpu_defines + + sources = [ + #backend + "backend/rs_surface_frame_ohos_raster.cpp", + "backend/rs_surface_ohos_raster.cpp", + "rs_ashmem_helper.cpp", + + #overdraw + "overdraw/rs_cpu_overdraw_canvas_listener.cpp", + "overdraw/rs_gpu_overdraw_canvas_listener.cpp", + "overdraw/rs_listened_canvas.cpp", + "overdraw/rs_overdraw_controller.cpp", + "rs_event_manager.cpp", + "rs_frame_report.cpp", + "rs_innovation.cpp", + "rs_log.cpp", + "rs_param.cpp", + "rs_marshalling_helper.cpp", + "rs_render_service_client.cpp", + "rs_render_service_connect_hub.cpp", + "rs_render_service_connection_proxy.cpp", + "rs_render_service_proxy.cpp", + "rs_surface_frame_ohos.cpp", + "rs_surface_ohos.cpp", + "rs_surface_ohos_converter.cpp", + "rs_system_properties.cpp", + "rs_vsync_client.cpp", + ] + sources += ["rs_event_detector.cpp",] + if (ace_enable_gpu) { + defines += [ + "GR_TEST_UTILS=1", + ] + + sources += [ + "backend/rs_surface_frame_ohos_gl.cpp", + "backend/rs_surface_ohos_gl.cpp", + ] + + sources += [ + "//display_server/rosen/modules/2d_graphics/src/render_context/cache_data.cpp", + "//display_server/rosen/modules/2d_graphics/src/render_context/memory_handler.cpp", + "//display_server/rosen/modules/2d_graphics/src/render_context/render_context.cpp", + "//display_server/rosen/modules/2d_graphics/src/render_context/shader_cache.cpp", + ] + } + + include_dirs = [ + "${sys_inc}/c_utils", + "${sys_inc}/ipc_core", + "${sys_inc}/hitrace_meter", + "${sys_inc}/hilog", + "${sys_inc}/skia", + "${sys_inc}/samgr", + "${sys_inc}/eventhandler", + "$rosen_root/modules/render_service_base/include", + "$rosen_root/modules/render_service_base/src/platform/fangtian/include", + "$rosen_root/modules/platform/image_native", + "$rosen_root/modules/render_service_base/src", + "//utils/system/safwk/native/include", + "//drivers/peripheral/display/interfaces/include/", + "$display_server_root/utils/log", + ] + + deps = [ + "$display_server_root/frameworks/surface/ft_build:surface", + "$rosen_root/modules/composer/vsync/ft_build:libvsync", + "$display_server_root/utils/sync_fence/ft_build:sync_fence", + "$display_server_root/utils/buffer_handle/ft_build:buffer_handle", + ] + + if (rs_enable_gpu) { + public_deps += [ + "//third_party/EGL:libEGL", + "//third_party/openGLES:libGLES", + ] + libs = ["crypto"] + } + + libs = ["ace_skia_fangtian", "ipc_core", "eventhandler", "hilog", "utils", "samgr_proxy", "hitrace_meter"] +} diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_frame_ohos_gl.cpp b/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_frame_ohos_gl.cpp new file mode 100644 index 0000000..beb2273 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_frame_ohos_gl.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 "rs_surface_frame_ohos_gl.h" +#include "platform/common/rs_log.h" +#include "render_context/render_context.h" + +#include +#include "pipeline/rs_render_thread.h" + +namespace OHOS { +namespace Rosen { + +RSSurfaceFrameOhosGl::RSSurfaceFrameOhosGl(int32_t width, int32_t height) + : width_(width), height_(height) +{ +} + +void RSSurfaceFrameOhosGl::SetDamageRegion(int32_t left, int32_t top, int32_t width, int32_t height) +{ + renderContext_->DamageFrame(left, top, width, height); +} + +void RSSurfaceFrameOhosGl::SetDamageRegion(const std::vector &rects) +{ + renderContext_->DamageFrame(rects); +} + +int32_t RSSurfaceFrameOhosGl::GetBufferAge() const +{ + return static_cast(renderContext_->QueryEglBufferAge()); +} + +SkCanvas* RSSurfaceFrameOhosGl::GetCanvas() +{ + if (skSurface_ == nullptr) { + CreateSurface(); + } + return skSurface_->getCanvas(); +} + +sk_sp RSSurfaceFrameOhosGl::GetSurface() +{ + if (skSurface_ == nullptr) { + CreateSurface(); + } + return skSurface_; +} + +int32_t RSSurfaceFrameOhosGl::GetReleaseFence() const +{ + return releaseFence_; +} + +void RSSurfaceFrameOhosGl::SetReleaseFence(const int32_t& fence) +{ + releaseFence_ = fence; +} + +void RSSurfaceFrameOhosGl::CreateSurface() +{ + skSurface_ = renderContext_->AcquireSurface(width_, height_); +} +} // namespace Rosen +} // namespace OHOS diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_frame_ohos_gl.h b/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_frame_ohos_gl.h new file mode 100644 index 0000000..0c61823 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_frame_ohos_gl.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef RS_SURFACE_FRAME_OHOS_GL_H +#define RS_SURFACE_FRAME_OHOS_GL_H + +#include + +#include "include/gpu/GrContext.h" + +#include "platform/drawing/rs_surface_frame.h" +#include "platform/ohos/rs_surface_frame_ohos.h" + +namespace OHOS { +namespace Rosen { + +class RSSurfaceFrameOhosGl : public RSSurfaceFrameOhos { +public: + RSSurfaceFrameOhosGl(int32_t width, int32_t height); + ~RSSurfaceFrameOhosGl() = default; + + SkCanvas* GetCanvas() override; + sk_sp GetSurface() override; + void SetDamageRegion(int32_t left, int32_t top, int32_t width, int32_t height) override; + void SetDamageRegion(const std::vector &rects) override; + int32_t GetBufferAge() const override; + int32_t GetReleaseFence() const; + void SetReleaseFence(const int32_t& fence); + +private: + int32_t releaseFence_ = 0; + int width_ = 0; + int height_ = 0; + void CreateSurface(); +}; +} // namespace Rosen +} // namespace OHOS + +#endif // RENDER_SERVICE_BASE_PLATFORM_RS_SURFACE_FRAME_OHOS_H diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_frame_ohos_raster.cpp b/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_frame_ohos_raster.cpp new file mode 100644 index 0000000..9963284 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_frame_ohos_raster.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 "rs_surface_frame_ohos_raster.h" +#include + +#include "platform/common/rs_log.h" + +namespace OHOS { +namespace Rosen { + +RSSurfaceFrameOhosRaster::RSSurfaceFrameOhosRaster(int32_t width, int32_t height) +{ + requestConfig_.width = width; + requestConfig_.height = height; + flushConfig_.damage.w = width; + flushConfig_.damage.h = height; +} + +void RSSurfaceFrameOhosRaster::SetDamageRegion(int32_t left, int32_t top, int32_t width, int32_t height) +{ + flushConfig_.damage.x = left; + flushConfig_.damage.y = top; + flushConfig_.damage.w = width; + flushConfig_.damage.h = height; +} + +void RSSurfaceFrameOhosRaster::SetDamageRegion(const std::vector &rects) +{ + // currently not support SetDamageRegion + ROSEN_LOGE("currently not support SetDamageRegion %d", rects.size()); +} + +int32_t RSSurfaceFrameOhosRaster::GetBufferAge() const +{ + // currently could not get real buffer age, so return invalid age + // should be supported by surface + ROSEN_LOGD("RSSurfaceFrameOhosRaster::GetBufferAge return -1"); + return -1; +} + +SkCanvas* RSSurfaceFrameOhosRaster::GetCanvas() +{ + if (buffer_ == nullptr || buffer_->GetWidth() <= 0 || buffer_->GetHeight() <= 0) { + ROSEN_LOGW("buffer is invalid"); + return nullptr; + } + if (skSurface_ == nullptr) { + CreateSurface(); + } + return skSurface_->getCanvas(); +} + +sk_sp RSSurfaceFrameOhosRaster::GetSurface() +{ + if (buffer_ == nullptr || buffer_->GetWidth() <= 0 || buffer_->GetHeight() <= 0) { + ROSEN_LOGW("buffer is invalid"); + return nullptr; + } + if (skSurface_ == nullptr) { + CreateSurface(); + } + return skSurface_; +} + +void RSSurfaceFrameOhosRaster::CreateSurface() +{ + auto addr = static_cast(buffer_->GetVirAddr()); + if (addr == nullptr) { + ROSEN_LOGW("buffer addr is invalid"); + return; + } + SkImageInfo info = + SkImageInfo::Make(buffer_->GetWidth(), buffer_->GetHeight(), kRGBA_8888_SkColorType, kPremul_SkAlphaType); + skSurface_ = SkSurface::MakeRasterDirect(info, addr, buffer_->GetStride()); +} + +int32_t RSSurfaceFrameOhosRaster::GetReleaseFence() const +{ + return releaseFence_; +} + +void RSSurfaceFrameOhosRaster::SetReleaseFence(const int32_t& fence) +{ + releaseFence_ = fence; +} + +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_frame_ohos_raster.h b/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_frame_ohos_raster.h new file mode 100644 index 0000000..0abbbfd --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_frame_ohos_raster.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef RS_SURFACE_FRAME_OHOS_RASTER_H +#define RS_SURFACE_FRAME_OHOS_RASTER_H + +#include + +#include "platform/drawing/rs_surface_frame.h" +#include "platform/ohos/rs_surface_frame_ohos.h" + +namespace OHOS { +namespace Rosen { + +class RSSurfaceFrameOhosRaster : public RSSurfaceFrameOhos { +public: + RSSurfaceFrameOhosRaster(int32_t width, int32_t height); + ~RSSurfaceFrameOhosRaster() = default; + + SkCanvas* GetCanvas() override; + sk_sp GetSurface() override; + + sptr GetBuffer() const + { + return buffer_; + } + void SetDamageRegion(int32_t left, int32_t top, int32_t width, int32_t height) override; + void SetDamageRegion(const std::vector &rects) override; + int32_t GetBufferAge() const override; + int32_t GetReleaseFence() const; + void SetReleaseFence(const int32_t& fence); + friend class RSSurfaceOhosRaster; +private: + sptr buffer_; + int32_t releaseFence_ = -1; + BufferRequestConfig requestConfig_ = { + .width = 0x100, + .height = 0x100, + .strideAlignment = 0x8, + .format = PIXEL_FMT_RGBA_8888, + .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA, + .timeout = 0, + }; + BufferFlushConfig flushConfig_ = { + .damage = { + .x = 0, + .y = 0, + .w = 0x100, + .h = 0x100, + }, + }; + + void CreateSurface(); +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // RENDER_SERVICE_BASE_PLATFORM_RS_SURFACE_FRAME_OHOS_H \ No newline at end of file diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_ohos_gl.cpp b/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_ohos_gl.cpp new file mode 100644 index 0000000..26d5337 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_ohos_gl.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 "rs_surface_ohos_gl.h" +#include "platform/common/rs_log.h" +#include "window.h" +#include +#include "pipeline/rs_render_thread.h" + +namespace OHOS { +namespace Rosen { + +RSSurfaceOhosGl::RSSurfaceOhosGl(const sptr& producer) : RSSurfaceOhos(producer) +{ + bufferUsage_ = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_MEM_DMA; +} + +void RSSurfaceOhosGl::SetSurfaceBufferUsage(uint64_t usage) +{ + bufferUsage_ = usage; +} + +RSSurfaceOhosGl::~RSSurfaceOhosGl() +{ + DestoryNativeWindow(mWindow); + if (context_ != nullptr) { + context_->DestroyEGLSurface(mEglSurface); + } + mWindow = nullptr; + mEglSurface = EGL_NO_SURFACE; +} + +std::unique_ptr RSSurfaceOhosGl::RequestFrame(int32_t width, int32_t height, + uint64_t uiTimestamp, bool useAFBC) +{ + RenderContext* context = GetRenderContext(); + if (context == nullptr) { + ROSEN_LOGE("RSSurfaceOhosGl::RequestFrame, GetRenderContext failed!"); + return nullptr; + } + context->SetColorSpace(colorSpace_); + if (mWindow == nullptr) { + mWindow = CreateNativeWindowFromSurface(&producer_); + mEglSurface = context->CreateEGLSurface((EGLNativeWindowType)mWindow); + ROSEN_LOGD("RSSurfaceOhosGl: create and Init EglSurface"); + } + + if (mEglSurface == EGL_NO_SURFACE) { + ROSEN_LOGE("RSSurfaceOhosGl: Invalid eglSurface, return"); + return nullptr; + } + + std::unique_ptr frame = std::make_unique(width, height); + +#ifdef RS_ENABLE_AFBC + int32_t format = 0; + NativeWindowHandleOpt(mWindow, GET_FORMAT, &format); + if (format == PIXEL_FMT_RGBA_8888 && useAFBC) { + bufferUsage_ = + (BUFFER_USAGE_HW_RENDER | BUFFER_USAGE_HW_TEXTURE | BUFFER_USAGE_HW_COMPOSER | BUFFER_USAGE_MEM_DMA); + } +#endif + NativeWindowHandleOpt(mWindow, SET_USAGE, bufferUsage_); + NativeWindowHandleOpt(mWindow, SET_BUFFER_GEOMETRY, width, height); + NativeWindowHandleOpt(mWindow, GET_BUFFER_GEOMETRY, &mHeight, &mWidth); + NativeWindowHandleOpt(mWindow, SET_COLOR_GAMUT, colorSpace_); + NativeWindowHandleOpt(mWindow, SET_UI_TIMESTAMP, uiTimestamp); + + context->MakeCurrent(mEglSurface); + + ROSEN_LOGD("RSSurfaceOhosGl:RequestFrame, eglsurface is %p, width is %d, height is %d", + mEglSurface, mWidth, mHeight); + + frame->SetRenderContext(context); + + std::unique_ptr ret(std::move(frame)); + + return ret; +} + +void RSSurfaceOhosGl::SetUiTimeStamp(const std::unique_ptr& frame, uint64_t uiTimestamp) +{ + struct timespec curTime = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, &curTime); + // 1000000000 is used for transfer second to nsec + uint64_t duration = static_cast(curTime.tv_sec) * 1000000000 + static_cast(curTime.tv_nsec); + NativeWindowHandleOpt(mWindow, SET_UI_TIMESTAMP, duration); +} + +bool RSSurfaceOhosGl::FlushFrame(std::unique_ptr& frame, uint64_t uiTimestamp) +{ + RenderContext* context = GetRenderContext(); + if (context == nullptr) { + ROSEN_LOGE("RSSurfaceOhosGl::FlushFrame, GetRenderContext failed!"); + return false; + } + + // gpu render flush + context->RenderFrame(); + context->SwapBuffers(mEglSurface); + ROSEN_LOGD("RSSurfaceOhosGl: FlushFrame, SwapBuffers eglsurface is %p", mEglSurface); + return true; +} + +void RSSurfaceOhosGl::ClearBuffer() +{ + if (context_ != nullptr && mEglSurface != EGL_NO_SURFACE && producer_ != nullptr) { + ROSEN_LOGD("RSSurfaceOhosGl: Clear surface buffer!"); + DestoryNativeWindow(mWindow); + context_->MakeCurrent(EGL_NO_SURFACE); + context_->DestroyEGLSurface(mEglSurface); + mEglSurface = EGL_NO_SURFACE; + mWindow = nullptr; + producer_->GoBackground(); + } +} + +void RSSurfaceOhosGl::ResetBufferAge() +{ + if (context_ != nullptr && mEglSurface != EGL_NO_SURFACE && producer_ != nullptr) { + ROSEN_LOGD("RSSurfaceOhosGl: Reset Buffer Age!"); + DestoryNativeWindow(mWindow); + context_->MakeCurrent(EGL_NO_SURFACE, context_->GetEGLContext()); + context_->DestroyEGLSurface(mEglSurface); + mEglSurface = EGL_NO_SURFACE; + mWindow = nullptr; + } +} +} // namespace Rosen +} // namespace OHOS diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_ohos_gl.h b/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_ohos_gl.h new file mode 100644 index 0000000..22d7d6c --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_ohos_gl.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef RS_SURFACE_OHOS_GL_H +#define RS_SURFACE_OHOS_GL_H + +#include + +#include "platform/drawing/rs_surface.h" +#include "platform/ohos/rs_surface_ohos.h" +#include "EGL/egl.h" +#include "rs_surface_frame_ohos_gl.h" +#include "window.h" + +namespace OHOS { +namespace Rosen { +class RSSurfaceOhosGl : public RSSurfaceOhos { +public: + explicit RSSurfaceOhosGl(const sptr& producer); + ~RSSurfaceOhosGl(); + + bool IsValid() const override + { + return producer_ != nullptr; + } + + std::unique_ptr RequestFrame( + int32_t width, int32_t height, uint64_t uiTimestamp, bool useAFBC = true) override; + bool FlushFrame(std::unique_ptr& frame, uint64_t uiTimestamp) override; + + void SetSurfaceBufferUsage(uint64_t usage) override; + void ClearBuffer() override; + void ResetBufferAge() override; + void SetUiTimeStamp(const std::unique_ptr& frame, uint64_t uiTimestamp) override; +private: + EGLSurface mEglSurface = EGL_NO_SURFACE; + struct NativeWindow* mWindow = nullptr; + int mWidth = -1; + int mHeight = -1; +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // RENDER_SERVICE_BASE_PLATFORM_RS_SURFACE_OHOS_H diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_ohos_raster.cpp b/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_ohos_raster.cpp new file mode 100644 index 0000000..9a8943d --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_ohos_raster.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 "rs_surface_ohos_raster.h" + +#include + +#include "platform/common/rs_log.h" +#include "rs_surface_frame_ohos_raster.h" + +namespace OHOS { +namespace Rosen { + +RSSurfaceOhosRaster::RSSurfaceOhosRaster(const sptr& producer) : RSSurfaceOhos(producer) {} + + +void RSSurfaceOhosRaster::SetSurfaceBufferUsage(uint64_t usage) +{ + bufferUsage_ = usage; +} + +std::unique_ptr RSSurfaceOhosRaster::RequestFrame(int32_t width, int32_t height, + uint64_t uiTimestamp, bool useAFBC) +{ + if (producer_ == nullptr) { + ROSEN_LOGE("RSSurfaceOhosRaster::RequestFrame, producer is nullptr"); + return nullptr; + } + + std::unique_ptr frame = std::make_unique(width, height); + frame->requestConfig_.usage = bufferUsage_; + SurfaceError err = producer_->RequestBuffer(frame->buffer_, frame->releaseFence_, frame->requestConfig_); + if (err != SURFACE_ERROR_OK) { + ROSEN_LOGE("RSSurfaceOhosRaster::Requestframe Failed, error is : %s", SurfaceErrorStr(err).c_str()); + return nullptr; + } + + err = frame->buffer_->Map(); + if (err != SURFACE_ERROR_OK) { + ROSEN_LOGE("RSSurfaceOhosRaster::Map Failed, error is : %s", SurfaceErrorStr(err).c_str()); + return nullptr; + } + + + sptr tempFence = new SyncFence(frame->releaseFence_); + int res = tempFence->Wait(3000); + if (res < 0) { + ROSEN_LOGE("RsDebug RSProcessor::RequestFrame this buffer is not available"); + } + std::unique_ptr ret(std::move(frame)); + return ret; +} + +void RSSurfaceOhosRaster::SetUiTimeStamp(const std::unique_ptr& frame, uint64_t uiTimestamp) +{ + auto frameOhosRaster = static_cast(frame.get()); + if (frameOhosRaster == nullptr || frameOhosRaster->GetBuffer() == nullptr) { + RS_LOGE("RSSurfaceOhosRaster::SetUiTimeStamp: buffer is nullptr"); + return; + } + + struct timespec curTime = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, &curTime); + // 1000000000 is used for transfer second to nsec + uint64_t duration = static_cast(curTime.tv_sec) * 1000000000 + static_cast(curTime.tv_nsec); + GSError ret = frameOhosRaster->GetBuffer()->GetExtraData()->ExtraSet("timeStamp", static_cast(duration)); + if (ret != GSERROR_OK) { + RS_LOGE("RSSurfaceOhosRaster::SetUiTimeStamp buffer ExtraSet failed"); + } +} + +bool RSSurfaceOhosRaster::FlushFrame(std::unique_ptr& frame, uint64_t uiTimestamp) +{ + // RSSurfaceOhosRaster is the class for platform OHOS, the input pointer should be the pointer to the class + // RSSurfaceFrameOhos. + // We use static_cast instead of RTTI and dynamic_cast which are not permitted + if (!frame) { + ROSEN_LOGE("RSSurfaceOhosRaster::Flushframe Failed, frame is nullptr"); + return false; + } + RSSurfaceFrameOhosRaster* oriFramePtr = static_cast(frame.get()); + oriFramePtr->flushConfig_.timestamp = static_cast(uiTimestamp); + SurfaceError err = producer_->FlushBuffer(oriFramePtr->buffer_, -1, oriFramePtr->flushConfig_); + if (err != SURFACE_ERROR_OK) { + ROSEN_LOGE("RSSurfaceOhosRaster::Flushframe Failed, error is : %s", SurfaceErrorStr(err).c_str()); + return false; + } + ROSEN_LOGD("RsDebug RSSurfaceOhosRaster::FlushFrame fence:%d", oriFramePtr->releaseFence_); + return true; +} + +void RSSurfaceOhosRaster::ClearBuffer() +{ + if (producer_ != nullptr) { + ROSEN_LOGD("RSSurfaceOhosRaster: Clear surface buffer!"); + producer_->GoBackground(); + } +} + +void RSSurfaceOhosRaster::ResetBufferAge() +{ + ROSEN_LOGD("RSSurfaceOhosRaster: Reset Buffer Age!"); +} +} // namespace Rosen +} // namespace OHOS diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_ohos_raster.h b/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_ohos_raster.h new file mode 100644 index 0000000..46e1157 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/backend/rs_surface_ohos_raster.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef RS_SURFACE_OHOS_RASTER_H +#define RS_SURFACE_OHOS_RASTER_H + +#include + +#include "platform/drawing/rs_surface.h" +#include "platform/ohos/rs_surface_ohos.h" + +namespace OHOS { +namespace Rosen { +class RSSurfaceOhosRaster : public RSSurfaceOhos { +public: + explicit RSSurfaceOhosRaster(const sptr& producer); + ~RSSurfaceOhosRaster() = default; + + bool IsValid() const override + { + return producer_ != nullptr; + } + + std::unique_ptr RequestFrame( + int32_t width, int32_t height, uint64_t uiTimestamp, bool useAFBC = true) override; + bool FlushFrame(std::unique_ptr& frame, uint64_t uiTimestamp) override; + + void SetSurfaceBufferUsage(uint64_t usage) override; + void ClearBuffer() override; + void ResetBufferAge() override; + void SetUiTimeStamp(const std::unique_ptr& frame, uint64_t uiTimestamp) override; +}; +} // namespace Rosen +} // namespace OHOS + +#endif // RENDER_SERVICE_BASE_PLATFORM_RS_SURFACE_OHOS_H diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/include/hisysevent.h b/display_server/rosen/modules/render_service_base/src/platform/fangtian/include/hisysevent.h new file mode 100644 index 0000000..8fa5c7c --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/include/hisysevent.h @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * 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. + */ +#ifndef HI_SYS_EVENT_H +#define HI_SYS_EVENT_H + +namespace OHOS { +namespace HiviewDFX { +class HiSysEvent { +public: + class Domain { + public: + static constexpr char AAFWK[] = "AAFWK"; + static constexpr char ACCESS_TOKEN[] = "ACCESS_TOKEN"; + static constexpr char ACCESSIBILITY[] = "ACCESSIBILITY"; + static constexpr char ACCOUNT[] = "ACCOUNT"; + static constexpr char ACE[] = "ACE"; + static constexpr char AI[] = "AI"; + static constexpr char APPEXECFWK[] = "APPEXECFWK"; + static constexpr char AUDIO[] = "AUDIO"; + static constexpr char AV_SESSION[] = "AV_SESSION"; + static constexpr char BACKGROUND_TASK[] = "BACKGROUND_TASK"; + static constexpr char BARRIER_FREE[] = "BARRIERFREE"; + static constexpr char BATTERY[] = "BATTERY"; + static constexpr char BIOMETRICS[] = "BIOMETRICS"; + static constexpr char BLUETOOTH[] = "BLUETOOTH"; + static constexpr char BUNDLE_MANAGER[] = "BUNDLE_MANAGER"; + static constexpr char CAMERA[] = "CAMERA"; + static constexpr char CAST_ENGINE[] = "CASTENGINE"; + static constexpr char CCRUNTIME[] = "CCRUNTIME"; + static constexpr char CERT_MANAGER[] = "CERT_MANAGER"; + static constexpr char COMMONEVENT[] = "COMMONEVENT"; + static constexpr char COMMUNICATION[] = "COMMUNICATION"; + static constexpr char CUSTOMIZATION_CONFIG[] = "CUST_CONFIG"; + static constexpr char CUSTOMIZATION_EDM[] = "CUST_EDM"; + static constexpr char DEVELOPTOOLS[] = "DEVELOPTOOLS"; + static constexpr char DEVICE_AUTH[] = "DEVICE_AUTH"; + static constexpr char DEVICE_PROFILE[] = "DEVICE_PROFILE"; + static constexpr char DISPLAY[] = "DISPLAY"; + static constexpr char DISTRIBUTED_AUDIO[] = "DISTAUDIO"; + static constexpr char DISTRIBUTED_CAMERA[] = "DISTCAMERA"; + static constexpr char DISTRIBUTED_DATAMGR[] = "DISTDATAMGR"; + static constexpr char DISTRIBUTED_DEVICE_MANAGER[] = "DISTDM"; + static constexpr char DISTRIBUTED_HARDWARE_FWK[] = "DISTHWFWK"; + static constexpr char DISTRIBUTED_INPUT[] = "DISTINPUT"; + static constexpr char DISTRIBUTED_SCHEDULE[] = "DISTSCHEDULE"; + static constexpr char DISTRIBUTED_SCREEN[] = "DISTSCREEN"; + static constexpr char DLP_CRE_SERVICE[] = "DLP_CRE_SERVICE"; + static constexpr char DLP[] = "DLP"; + static constexpr char DSLM[] = "DSLM"; + static constexpr char DSOFTBUS[] = "DSOFTBUS"; + static constexpr char FRAMEWORK[] = "FRAMEWORK"; + static constexpr char GLOBAL_I18N[] = "GLOBAL_I18N"; + static constexpr char GLOBAL_RESMGR[] = "GLOBAL_RESMGR"; + static constexpr char GLOBAL[] = "GLOBAL"; + static constexpr char GRAPHIC[] = "GRAPHIC"; + static constexpr char HDF_USB[] = "HDF_USB"; + static constexpr char HIVIEWDFX[] = "HIVIEWDFX"; + static constexpr char HUKS[] = "HUKS"; + static constexpr char IAWARE[] = "IAWARE"; + static constexpr char IMS_UT[] = "IMS_UT"; + static constexpr char INPUTMETHOD[] = "INPUTMETHOD"; + static constexpr char INTELLI_ACCESSORIES[] = "INTELLIACC"; + static constexpr char INTELLI_TV[] = "INTELLITV"; + static constexpr char ISHARE[] = "ISHARE"; + static constexpr char IVI_HARDWARE[] = "IVIHARDWARE"; + static constexpr char LOCATION[] = "LOCATION"; + static constexpr char MEDICAL_SENSOR[] = "MEDICAL_SENSOR"; + static constexpr char MEMMGR[] = "MEMMGR"; + static constexpr char MISCDEVICE[] = "MISCDEVICE"; + static constexpr char MSDP[] = "MSDP"; + static constexpr char MULTI_MEDIA[] = "MULTIMEDIA"; + static constexpr char MULTI_MODAL_INPUT[] = "MULTIMODALINPUT"; + static constexpr char NETMANAGER_STANDARD[] = "NETMANAGER"; + static constexpr char NOTIFICATION[] = "NOTIFICATION"; + static constexpr char PASTEBOARD[] = "PASTEBOARD"; + static constexpr char POWER[] = "POWER"; + static constexpr char POWERMGR[] = "POWERMGR"; + static constexpr char PUSH_MANAGER[] = "PUSH_MANAGER"; + static constexpr char RELIABILITY[] = "RELIABILITY"; + static constexpr char REQUEST[] = "REQUEST"; + static constexpr char ROUTER[] = "ROUTER"; + static constexpr char RSS[] = "RSS"; + static constexpr char SAMGR[] = "SAMGR"; + static constexpr char SECURITY_GUARD[] = "SECURITY_GUARD"; + static constexpr char SENSOR[] = "SENSOR"; + static constexpr char SOURCE_CODE_TRANSFORMER[] = "SRCTRANSFORMER"; + static constexpr char STARTUP[] = "STARTUP"; + static constexpr char TELEPHONY[] = "TELEPHONY"; + static constexpr char THEME[] = "THEME"; + static constexpr char THERMAL[] = "THERMAL"; + static constexpr char TIME[] = "TIME"; + static constexpr char UPDATE[] = "UPDATE"; + static constexpr char USB[] = "USB"; + static constexpr char USERIAM_FWK[] = "USERIAM_FWK"; + static constexpr char USERIAM_PIN[] = "USERIAM_PIN"; + static constexpr char WEARABLE_HARDWARE[] = "WEARABLEHW"; + static constexpr char WEARABLE[] = "WEARABLE"; + static constexpr char WEBVIEW[] = "WEBVIEW"; + static constexpr char WINDOW_MANAGER[] = "WINDOWMANAGER"; + static constexpr char WORK_SCHEDULER[] = "WORKSCHEDULER"; + static constexpr char OTHERS[] = "OTHERS"; + }; + + enum EventType { + FAULT = 1, // system fault event + STATISTIC = 2, // system statistic event + SECURITY = 3, // system security event + BEHAVIOR = 4 // system behavior event + }; + template + static int Write(const std::string &domain, const std::string &eventName, + EventType type, Types... keyValues){return 0;} +}; +} // namespace HiviewDFX +} // namespace OHOS + +#endif // HI_SYS_EVENT_H diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/include/parameter.h b/display_server/rosen/modules/render_service_base/src/platform/fangtian/include/parameter.h new file mode 100644 index 0000000..5a9b4a9 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/include/parameter.h @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef STARTUP_SYSPARAM_PARAMETER_API_H +#define STARTUP_SYSPARAM_PARAMETER_API_H +#include +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +#define PARAM_CONST_VALUE_LEN_MAX 4096 +#define PARAM_VALUE_LEN_MAX 96 +#define PARAM_NAME_LEN_MAX 96 +#define OS_FULL_NAME_LEN 128 +#define VERSION_ID_MAX_LEN 256 +#define PARAM_BUFFER_MAX (0x01 << 16) + +static const char EMPTY_STR[] = { "" }; + +/** + * @brief Obtains a system parameter matching the specified key. + * + * If no system parameter is found, the def parameter will be returned.\n + * + * @param key Indicates the key for the system parameter to query. + * The value can contain lowercase letters, digits, underscores (_), and dots (.). + * Its length cannot exceed 32 bytes (including the end-of-text character in the string). + * @param def Indicates the default value to return when no query result is found. + * This parameter is specified by the caller. + * @param value Indicates the data buffer that stores the query result. + * This parameter is applied for and released by the caller and can be used as an output parameter. + * @param len Indicates the length of the data in the buffer. + * @return Returns the number of bytes of the system parameter if the operation is successful; + * returns -9 if a parameter is incorrect; returns -1 in other scenarios. + * @since 1 + * @version 1 + */ +int GetParameter(const char *key, const char *def, char *value, uint32_t len); + +/** + * @brief Sets or updates a system parameter. + * + * You can use this function to set a system parameter that matches key as value.\n + * + * @param key Indicates the key for the parameter to set or update. + * The value can contain lowercase letters, digits, underscores (_), and dots (.). + * Its length cannot exceed 32 bytes (including the end-of-text character in the string). + * @param value Indicates the system parameter value. + * Its length cannot exceed 128 bytes (including the end-of-text character in the string). + * @return Returns 0 if the operation is successful; + * returns -9 if a parameter is incorrect; returns -1 in other scenarios. + * @since 1 + * @version 1 + */ +int SetParameter(const char *key, const char *value); + +/** + * @brief Wait for a system parameter with specified value. + * + * You can use this function to wait a system parameter that matches key as value.\n + * + * @param key Indicates the key for the parameter to wait. + * The value can contain lowercase letters, digits, underscores (_), and dots (.). + * Its length cannot exceed 96 bytes (including the end-of-text character in the string). + * @param value Indicates the system parameter value. + * Its length cannot exceed 96 bytes (including the end-of-text character in the string). + * value can use "*" to do arbitrary match. + * @param timeout Indicates the timeout value, in seconds. + * <=0 means wait for ever. + * >0 means wait for specified seconds + * @return Returns 0 if the operation is successful; + * returns -10 if timeout; returns -1 in other scenarios. + * @since 1.1 + * @version 1.1 + */ +int WaitParameter(const char *key, const char *value, int timeout); + +/** + * @brief Watch for system parameter values. + * + * You can use this function to watch system parameter values.\n + * + * @param keyPrefix Indicates the key prefix for the parameter to be watched. + * If keyPrefix is not a full name, "A.B." for example, it means to watch for all parameter started with "A.B.". + * @param callback Indicates value change callback. + * If callback is NULL, it means to cancel the watch. + * @return Returns 0 if the operation is successful; + * returns -1 in other scenarios. + * @since 1.1 + * @version 1.1 + */ +typedef void (*ParameterChgPtr)(const char *key, const char *value, void *context); +int WatchParameter(const char *keyPrefix, ParameterChgPtr callback, void *context); + +/** + * @brief Remove parameter watcher. + * + * You can use this function to remove system parameter watcher.\n + * + * @param keyPrefix Indicates the key prefix for the parameter to be watched. + * If keyPrefix is not a full name, "A.B." for example, it means to watch for all parameter started with "A.B.". + * @param callback Indicates value change callback. + * If callback is NULL, it means to cancel the watch. + * @return Returns 0 if the operation is successful; + * returns -1 in other scenarios. + * @since 1.1 + * @version 1.1 + */ +int RemoveParameterWatcher(const char *keyPrefix, ParameterChgPtr callback, void *context); + +const char *GetSecurityPatchTag(void); +const char *GetOSFullName(void); +const char *GetVersionId(void); +const char *GetBuildRootHash(void); +const char *GetOsReleaseType(void); +int GetSdkApiVersion(void); + +const char *GetDeviceType(void); +const char *GetProductModel(void); +const char *GetManufacture(void); +const char *GetBrand(void); +const char *GetMarketName(void); +const char *GetProductSeries(void); +const char *GetSoftwareModel(void); +const char *GetHardwareModel(void); +const char *GetHardwareProfile(void); +const char *GetSerial(void); +const char *GetAbiList(void); +const char *GetDisplayVersion(void); +const char *GetIncrementalVersion(void); +const char *GetBootloaderVersion(void); +const char *GetBuildType(void); +const char *GetBuildUser(void); +const char *GetBuildHost(void); +const char *GetBuildTime(void); +int GetFirstApiVersion(void); +int GetDevUdid(char *udid, int size); + +const char *AclGetSerial(void); +int AclGetDevUdid(char *udid, int size); + +/** + * @brief Obtains a system parameter matching the specified key. + * + * If no system parameter is found, return -1.\n + * + * @param key Indicates the key for the system parameter to find. + * @return Returns the index for parameter; + * returns handle if a parameter is correct; returns -1 in other scenarios. + * @since 1 + * @version 1 + */ +uint32_t FindParameter(const char *key); +uint32_t GetParameterCommitId(uint32_t handle); +int GetParameterName(uint32_t handle, char *key, uint32_t len); +int GetParameterValue(uint32_t handle, char *value, uint32_t len); +long long GetSystemCommitId(void); + +int32_t GetIntParameter(const char *key, int32_t def); +uint32_t GetUintParameter(const char *key, uint32_t def); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif // STARTUP_SYSPARAM_PARAMETER_API_H diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/include/parameters.h b/display_server/rosen/modules/render_service_base/src/platform/fangtian/include/parameters.h new file mode 100644 index 0000000..0db7c52 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/include/parameters.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * 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 +namespace OHOS { +namespace system { +std::string GetParameter(const std::string& key, const std::string& def); +} +} + + diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/overdraw/rs_cpu_overdraw_canvas_listener.cpp b/display_server/rosen/modules/render_service_base/src/platform/fangtian/overdraw/rs_cpu_overdraw_canvas_listener.cpp new file mode 100644 index 0000000..77c8929 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/overdraw/rs_cpu_overdraw_canvas_listener.cpp @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 "platform/ohos/overdraw/rs_cpu_overdraw_canvas_listener.h" + +#include +#include +#include +#include +#include + +#include "platform/ohos/overdraw/rs_overdraw_controller.h" + +namespace OHOS { +namespace Rosen { +RSCPUOverdrawCanvasListener::RSCPUOverdrawCanvasListener(SkCanvas &canvas) + : RSCanvasListener(canvas) +{ +} + +void RSCPUOverdrawCanvasListener::Draw() +{ + auto overdrawColorMap = RSOverdrawController::GetInstance().GetColorMap(); + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(paint.kFill_Style); + + SkRegion drawed; + for (size_t i = regions.size(); i > 0; i--) { + if (overdrawColorMap.find(i) != overdrawColorMap.end()) { + paint.setColor(overdrawColorMap.at(i)); + } else { + paint.setColor(overdrawColorMap.at(0)); + } + + auto todraw = regions[i]; + todraw.op(drawed, SkRegion::kDifference_Op); + canvas_.drawRegion(todraw, paint); + drawed.op(todraw, SkRegion::kUnion_Op); + } +} + +void RSCPUOverdrawCanvasListener::onDrawRect(const SkRect& rect, const SkPaint& paint) +{ + SkPath path; + path.addRect(rect); + AppendRegion(path); +} + +void RSCPUOverdrawCanvasListener::onDrawRRect(const SkRRect& rect, const SkPaint& paint) +{ + SkPath path; + path.addRRect(rect); + AppendRegion(path); +} + +void RSCPUOverdrawCanvasListener::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, + const SkPaint& paint) +{ + SkPath path; + path.addRRect(outer); + path.addRRect(inner); + AppendRegion(path); +} + +void RSCPUOverdrawCanvasListener::onDrawOval(const SkRect& rect, const SkPaint& paint) +{ + SkPath path; + path.addOval(rect); + AppendRegion(path); +} + +void RSCPUOverdrawCanvasListener::onDrawArc(const SkRect& rect, SkScalar startAngle, + SkScalar sweepAngle, bool useCenter, + const SkPaint& paint) +{ + SkPath path; + path.addArc(rect, startAngle, sweepAngle); + AppendRegion(path); +} + +void RSCPUOverdrawCanvasListener::onDrawPath(const SkPath& path, const SkPaint& paint) +{ + SkPath tpath = path; + AppendRegion(tpath); +} + +void RSCPUOverdrawCanvasListener::onDrawRegion(const SkRegion& region, const SkPaint& paint) +{ + SkPath path; + region.getBoundaryPath(&path); + AppendRegion(path); +} + +void RSCPUOverdrawCanvasListener::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, + const SkPaint& paint) +{ + if (blob == nullptr) { + return; + } + + auto rect = blob->bounds(); + rect.offset(x, y); + onDrawRect(rect, paint); +} + +void RSCPUOverdrawCanvasListener::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], + const SkPoint texCoords[4], SkBlendMode mode, + const SkPaint& paint) +{ + // need know patch region +} + +void RSCPUOverdrawCanvasListener::onDrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], + const SkPaint& paint) +{ + for (size_t i = 0; i < count; i++) { + onDrawRect(SkRect::MakeXYWH(pts[i].x(), pts[i].y(), 1, 1), paint); + } +} + +void RSCPUOverdrawCanvasListener::onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4], + SkCanvas::QuadAAFlags aaFlags, + const SkColor4f& color, SkBlendMode mode) +{ + SkPaint paint(color); + paint.setBlendMode(mode); + if (clip) { + SkPath clipPath; + clipPath.addPoly(clip, 0x4, true); // 4 from clip[4] + onDrawPath(clipPath, paint); + } else { + onDrawRect(rect, paint); + } +} + +void RSCPUOverdrawCanvasListener::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) +{ + // need know annotation region +} + +void RSCPUOverdrawCanvasListener::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rect) +{ + // need know shadow rect region +} + +void RSCPUOverdrawCanvasListener::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) +{ + if (drawable == nullptr) { + return; + } + + canvas_.save(); + if (matrix) { + auto nowMatrix = canvas_.getTotalMatrix(); + nowMatrix.postConcat(*matrix); + canvas_.setMatrix(nowMatrix); + } + + onDrawRect(drawable->getBounds(), {}); + canvas_.restore(); +} + +void RSCPUOverdrawCanvasListener::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, + const SkPaint* paint) +{ + if (picture == nullptr) { + return; + } + + canvas_.save(); + if (matrix) { + auto nowMatrix = canvas_.getTotalMatrix(); + nowMatrix.postConcat(*matrix); + canvas_.setMatrix(nowMatrix); + } + + SkPaint p; + if (paint) { + p = *paint; + } + + onDrawRect(picture->cullRect(), p); + canvas_.restore(); +} + +void RSCPUOverdrawCanvasListener::AppendRegion(SkPath &path) +{ + SkRegion target; + path.transform(canvas_.getTotalMatrix()); + target.setPath(path, SkRegion(SkIRect::MakeLTRB(-1e9, -1e9, 1e9, 1e9))); + + for (size_t i = regions.size(); i > 0; i--) { + if (regions[i].intersects(target)) { + auto regi = regions[i]; + regi.op(target, SkRegion::kIntersect_Op); + regions[i + 1].op(regi, SkRegion::kUnion_Op); + } + } + regions[1].op(target, SkRegion::kUnion_Op); +} +} // namespace Rosen +} // namespace OHOS diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/overdraw/rs_gpu_overdraw_canvas_listener.cpp b/display_server/rosen/modules/render_service_base/src/platform/fangtian/overdraw/rs_gpu_overdraw_canvas_listener.cpp new file mode 100644 index 0000000..b044238 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/overdraw/rs_gpu_overdraw_canvas_listener.cpp @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 "platform/ohos/overdraw/rs_gpu_overdraw_canvas_listener.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "platform/ohos/overdraw/rs_overdraw_controller.h" + +namespace OHOS { +namespace Rosen { +RSGPUOverdrawCanvasListener::RSGPUOverdrawCanvasListener(SkCanvas &canvas) + : RSCanvasListener(canvas) +{ + auto listenedSurface_ = canvas.makeSurface(canvas.imageInfo()); + if (listenedSurface_ != nullptr) { + overdrawCanvas_ = new SkOverdrawCanvas(listenedSurface_->getCanvas()); + } +} + +RSGPUOverdrawCanvasListener::~RSGPUOverdrawCanvasListener() +{ + if (overdrawCanvas_ != nullptr) { + delete overdrawCanvas_; + } +} + +void RSGPUOverdrawCanvasListener::Draw() +{ + auto image = listenedSurface_->makeImageSnapshot(); + SkPaint paint; + auto overdrawColors = RSOverdrawController::GetInstance().GetColorArray(); + paint.setColorFilter(SkOverdrawColorFilter::Make(overdrawColors.data())); + canvas_.drawImage(image, 0, 0, &paint); +} + +bool RSGPUOverdrawCanvasListener::IsValid() const +{ + return listenedSurface_ != nullptr; +} + +void RSGPUOverdrawCanvasListener::onDrawRect(const SkRect& rect, const SkPaint& paint) +{ + overdrawCanvas_->drawRect(rect, paint); +} + +void RSGPUOverdrawCanvasListener::onDrawRRect(const SkRRect& rect, const SkPaint& paint) +{ + overdrawCanvas_->drawRRect(rect, paint); +} + +void RSGPUOverdrawCanvasListener::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, + const SkPaint& paint) +{ + overdrawCanvas_->drawDRRect(outer, inner, paint); +} + +void RSGPUOverdrawCanvasListener::onDrawOval(const SkRect& rect, const SkPaint& paint) +{ + overdrawCanvas_->drawOval(rect, paint); +} + +void RSGPUOverdrawCanvasListener::onDrawArc(const SkRect& rect, SkScalar startAngle, + SkScalar sweepAngle, bool useCenter, + const SkPaint& paint) +{ + overdrawCanvas_->drawArc(rect, startAngle, sweepAngle, useCenter, paint); +} + +void RSGPUOverdrawCanvasListener::onDrawPath(const SkPath& path, const SkPaint& paint) +{ + overdrawCanvas_->drawPath(path, paint); +} + +void RSGPUOverdrawCanvasListener::onDrawRegion(const SkRegion& region, const SkPaint& paint) +{ + overdrawCanvas_->drawRegion(region, paint); +} + +void RSGPUOverdrawCanvasListener::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, + const SkPaint& paint) +{ + overdrawCanvas_->drawTextBlob(blob, x, y, paint); +} + +void RSGPUOverdrawCanvasListener::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], + const SkPoint texCoords[4], SkBlendMode mode, + const SkPaint& paint) +{ + overdrawCanvas_->drawPatch(cubics, colors, texCoords, mode, paint); +} + +void RSGPUOverdrawCanvasListener::onDrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], + const SkPaint& paint) +{ + overdrawCanvas_->drawPoints(mode, count, pts, paint); +} + +void RSGPUOverdrawCanvasListener::onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4], + SkCanvas::QuadAAFlags aaFlags, + const SkColor4f& color, SkBlendMode mode) +{ + overdrawCanvas_->experimental_DrawEdgeAAQuad(rect, clip, aaFlags, color.toSkColor(), mode); +} + +void RSGPUOverdrawCanvasListener::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) +{ + overdrawCanvas_->drawAnnotation(rect, key, value); +} + +void RSGPUOverdrawCanvasListener::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rect) +{ + overdrawCanvas_->private_draw_shadow_rec(path, rect); +} + +void RSGPUOverdrawCanvasListener::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) +{ + overdrawCanvas_->drawDrawable(drawable, matrix); +} + +void RSGPUOverdrawCanvasListener::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, + const SkPaint* paint) +{ + overdrawCanvas_->drawPicture(picture, matrix, paint); +} +} // namespace Rosen +} // namespace OHOS diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/overdraw/rs_listened_canvas.cpp b/display_server/rosen/modules/render_service_base/src/platform/fangtian/overdraw/rs_listened_canvas.cpp new file mode 100644 index 0000000..d68143d --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/overdraw/rs_listened_canvas.cpp @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 "platform/ohos/overdraw/rs_listened_canvas.h" + +#include "platform/common/rs_log.h" +#include "platform/ohos/overdraw/rs_canvas_listener.h" + +namespace OHOS { +namespace Rosen { +RSListenedCanvas::RSListenedCanvas(SkCanvas* canvas, float alpha) + : RSPaintFilterCanvas(canvas, alpha) +{ +} + +RSListenedCanvas::RSListenedCanvas(SkSurface* skSurface, float alpha) + : RSPaintFilterCanvas(skSurface, alpha) +{ +} + +void RSListenedCanvas::SetListener(const std::shared_ptr &listener) +{ + listener_ = listener; +} + +void RSListenedCanvas::onDrawPaint(const SkPaint& paint) +{ + RSPaintFilterCanvas::onDrawPaint(paint); + if (listener_ != nullptr) { + listener_->onDrawPaint(paint); + } +} + +void RSListenedCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) +{ + RSPaintFilterCanvas::onDrawRect(rect, paint); + if (listener_ != nullptr) { + listener_->onDrawRect(rect, paint); + } +} + +void RSListenedCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) +{ + RSPaintFilterCanvas::onDrawRRect(rrect, paint); + if (listener_ != nullptr) { + listener_->onDrawRRect(rrect, paint); + } +} + +void RSListenedCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, + const SkPaint& paint) +{ + RSPaintFilterCanvas::onDrawDRRect(outer, inner, paint); + if (listener_ != nullptr) { + listener_->onDrawDRRect(outer, inner, paint); + } +} + +void RSListenedCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) +{ + RSPaintFilterCanvas::onDrawOval(rect, paint); + if (listener_ != nullptr) { + listener_->onDrawOval(rect, paint); + } +} + +void RSListenedCanvas::onDrawArc(const SkRect& rect, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, + const SkPaint& paint) +{ + RSPaintFilterCanvas::onDrawArc(rect, startAngle, sweepAngle, useCenter, paint); + if (listener_ != nullptr) { + listener_->onDrawArc(rect, startAngle, sweepAngle, useCenter, paint); + } +} + +void RSListenedCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) +{ + RSPaintFilterCanvas::onDrawPath(path, paint); + if (listener_ != nullptr) { + listener_->onDrawPath(path, paint); + } +} + +void RSListenedCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) +{ + RSPaintFilterCanvas::onDrawRegion(region, paint); + if (listener_ != nullptr) { + listener_->onDrawRegion(region, paint); + } +} + +void RSListenedCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, + const SkPaint& paint) +{ + RSPaintFilterCanvas::onDrawTextBlob(blob, x, y, paint); + if (listener_ != nullptr) { + listener_->onDrawTextBlob(blob, x, y, paint); + } +} + +void RSListenedCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], + const SkPoint texCoords[4], SkBlendMode mode, + const SkPaint& paint) +{ + RSPaintFilterCanvas::onDrawPatch(cubics, colors, texCoords, mode, paint); + if (listener_ != nullptr) { + listener_->onDrawPatch(cubics, colors, texCoords, mode, paint); + } +} + +void RSListenedCanvas::onDrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], + const SkPaint& paint) +{ + RSPaintFilterCanvas::onDrawPoints(mode, count, pts, paint); + if (listener_ != nullptr) { + listener_->onDrawPoints(mode, count, pts, paint); + } +} + +void RSListenedCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) +{ + RSPaintFilterCanvas::onDrawAnnotation(rect, key, value); + if (listener_ != nullptr) { + listener_->onDrawAnnotation(rect, key, value); + } +} + +void RSListenedCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rect) +{ + RSPaintFilterCanvas::onDrawShadowRec(path, rect); + if (listener_ != nullptr) { + listener_->onDrawShadowRec(path, rect); + } +} + +void RSListenedCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) +{ + RSPaintFilterCanvas::onDrawDrawable(drawable, matrix); + if (listener_ != nullptr) { + listener_->onDrawDrawable(drawable, matrix); + } +} + +void RSListenedCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, + const SkPaint* paint) +{ + RSPaintFilterCanvas::onDrawPicture(picture, matrix, paint); + if (listener_ != nullptr) { + listener_->onDrawPicture(picture, matrix, paint); + } +} + +void RSListenedCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, + const SkPaint* paint, SrcRectConstraint constraint) +{ + RSPaintFilterCanvas::onDrawImageRect(image, src, dst, paint, constraint); + if (listener_ != nullptr) { + listener_->onDrawRect(dst, {}); + } +} +} // namespace Rosen +} // namespace OHOS diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/overdraw/rs_overdraw_controller.cpp b/display_server/rosen/modules/render_service_base/src/platform/fangtian/overdraw/rs_overdraw_controller.cpp new file mode 100644 index 0000000..ff2e3f0 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/overdraw/rs_overdraw_controller.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 "platform/ohos/overdraw/rs_overdraw_controller.h" + +#include +#include + +#include "hilog/log.h" +#include "parameter.h" + +#include "platform/common/rs_log.h" + +namespace OHOS { +namespace Rosen { +namespace { +// param set debug.graphic.overdraw true/false +constexpr const char *SWITCH_TEXT = "debug.graphic.overdraw"; +constexpr const char *SWITCH_ENABLE_TEXT = "true"; +/* param set debug.graphic.colors_overdraw [color...] + * For Example: + * param set debug.graphic.colors_overdraw "0 0x220000ff 0x2200ff00 0x22ff0000 0x44ff0000" + * means: + * - Drawn Once Region: 0x00000000 (transparent) + * - Drawn Twice Region: 0x220000ff (alpha: 13% blue) + * - Drawn 3 Times Region: 0x2200ff00 (alpha: 13% green) + * - Drawn 4 Times Region: 0x22ff0000 (alpha: 13% red) + * - Drawn >= 5 Times Region: 0x44ff0000 (alpha: 26% red) + */ +constexpr const char *COLOR_TEXT = "debug.graphic.colors_overdraw"; +} // namespace + +RSOverdrawController &RSOverdrawController::GetInstance() +{ + static RSOverdrawController instance; + return instance; +} + +void RSOverdrawController::SetDelegate(const std::shared_ptr &delegate) +{ + delegate_ = delegate; +} + +bool RSOverdrawController::IsEnabled() const +{ + return enabled_; +} + +void RSOverdrawController::SetEnable(bool enable) +{ + enabled_ = enable; +} + +OverdrawColorArray RSOverdrawController::GetColorArray() const +{ + std::lock_guard lock(colorMutex_); + return colorArray_; +} + +std::map RSOverdrawController::GetColorMap() const +{ + std::lock_guard lock(colorMutex_); + return colorMap_; +} + +RSOverdrawController::RSOverdrawController() +{ + char value[0x20]; + GetParameter(SWITCH_TEXT, "false", value, sizeof(value)); + SwitchFunction(SWITCH_TEXT, value, this); + WatchParameter(SWITCH_TEXT, SwitchFunction, this); + WatchParameter(COLOR_TEXT, OnColorChange, this); +} + +void RSOverdrawController::SwitchFunction(const char *key, const char *value, void *context) +{ + auto &that = *reinterpret_cast(context); + auto oldEnable = that.enabled_; + if (strncmp(value, SWITCH_ENABLE_TEXT, strlen(SWITCH_ENABLE_TEXT)) == 0) { + that.enabled_ = true; + ROSEN_LOGI("%{public}s enable", key); + } else { + that.enabled_ = false; + ROSEN_LOGI("%{public}s disable", key); + } + + if (oldEnable != that.enabled_ && that.delegate_ != nullptr) { + that.delegate_->Repaint(); + } +} + +void RSOverdrawController::OnColorChange(const char *key, const char *value, void *context) +{ + auto &that = *reinterpret_cast(context); + std::stringstream ss(value); + std::vector colors; + uint32_t color; + while (ss >> std::hex >> color) { + colors.push_back(color); + } + + if (ss.eof() && colors != that.colors_ && colors.size() > 0) { + // array + OverdrawColorArray colorArray = that.colorArray_; + auto colorNumber = colorArray.size(); + for (size_t i = 0; i < colors.size() && i + 1 < colorNumber; i++) { + colorArray[i + 1] = colors[i]; + } + for (size_t i = colors.size(); i + 1 < colorNumber; i++) { + colorArray[i + 1] = colors.back(); + } + + // map + std::map colorMap; + for (size_t i = 0; i < colors.size(); i++) { + colorMap[i + 1] = colors[i]; + } + colorMap[0] = colors.back(); + + { + std::lock_guard lock(that.colorMutex_); + that.colorArray_ = colorArray; + that.colorMap_ = colorMap; + } + + if (that.delegate_ != nullptr) { + that.delegate_->Repaint(); + } + } +} +} // namespace Rosen +} // namespace OHOS diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_accessibility.cpp b/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_accessibility.cpp new file mode 100644 index 0000000..4d3b912 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_accessibility.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 "platform/common/rs_accessibility.h" + +#include "accessibility_config.h" +#include "platform/common/rs_log.h" + +using namespace OHOS::AccessibilityConfig; + +namespace OHOS { +namespace Rosen { +class RSAccessibilityOHOS : public RSAccessibility { +public: + static RSAccessibilityOHOS &GetInstance(); + void ListenHighContrastChange(OnHighContrastChange callback) override; + +private: + class Observer : public AccessibilityConfigObserver { + public: + virtual void OnConfigChanged(const CONFIG_ID id, const ConfigValue &value) override; + }; + + void ListenHighContrast(); + + std::shared_ptr observer_ = std::make_shared(); + bool listeningHighContrast_ = false; + OnHighContrastChange onHighContrastChange_ = nullptr; +}; + +RSAccessibilityOHOS &RSAccessibilityOHOS::GetInstance() +{ + static RSAccessibilityOHOS instance; + return instance; +} + +RSAccessibility &RSAccessibility::GetInstance() +{ + return RSAccessibilityOHOS::GetInstance(); +} + +void RSAccessibilityOHOS::ListenHighContrastChange(OnHighContrastChange callback) +{ + onHighContrastChange_ = callback; + ListenHighContrast(); +} + +void RSAccessibilityOHOS::ListenHighContrast() +{ + if (!listeningHighContrast_) { + auto &config = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); + config.InitializeContext(); + config.SubscribeConfigObserver(CONFIG_ID::CONFIG_HIGH_CONTRAST_TEXT, observer_); + listeningHighContrast_ = true; + } +} + +void RSAccessibilityOHOS::Observer::OnConfigChanged(const CONFIG_ID id, const ConfigValue &value) +{ + ROSEN_LOGD("OnConfigChanged %d", static_cast(id)); + auto &accessbility = RSAccessibilityOHOS::GetInstance(); + if (id == CONFIG_ID::CONFIG_HIGH_CONTRAST_TEXT && accessbility.onHighContrastChange_) { + accessbility.onHighContrastChange_(value.highContrastText); + } +} +} // namespace Rosen +} // namespace OHOS diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_ashmem_helper.cpp b/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_ashmem_helper.cpp new file mode 100644 index 0000000..1a06a29 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_ashmem_helper.cpp @@ -0,0 +1,283 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 "sys_binder.h" +#include "transaction/rs_ashmem_helper.h" + +#include +#include +#include + +#include "ashmem.h" +#include "platform/common/rs_log.h" +#include "rs_trace.h" +#include "securec.h" +#include "sandbox_utils.h" + +namespace OHOS { +namespace Rosen { +std::unique_ptr AshmemAllocator::CreateAshmemAllocator(size_t size, int mapType) +{ + static pid_t pid_ = GetRealPid(); + static std::atomic shmemCount = 0; + uint64_t id = ((uint64_t)pid_ << 32) | shmemCount++; + std::string name = "RSAshmem" + std::to_string(id); + + int fd = AshmemCreate(name.c_str(), size); + if (fd < 0) { + ROSEN_LOGE("CreateAshmemAllocator: AshmemCreate failed, fd:%d", fd); + return nullptr; + } + auto allocator = std::make_unique(fd, size); + + int result = AshmemSetProt(fd, PROT_READ | PROT_WRITE); + if (result < 0) { + ROSEN_LOGE("CreateAshmemAllocator: AshmemSetProt failed, result:%d", result); + return nullptr; + } + + if (!allocator->MapAshmem(mapType)) { + ROSEN_LOGE("CreateAshmemAllocator: MapAshmem failed"); + return nullptr; + } + + return allocator; +} + +std::unique_ptr AshmemAllocator::CreateAshmemAllocatorWithFd(int fd, size_t size, int mapType) +{ + if (fd < 0) { + ROSEN_LOGE("CreateAshmemAllocatorWithFd: fd < 0"); + return nullptr; + } + auto allocator = std::make_unique(fd, size); + + int ashmemSize = AshmemGetSize(fd); + if (ashmemSize < 0 || size_t(ashmemSize) < size) { + ROSEN_LOGE("CreateAshmemAllocatorWithFd: ashmemSize < size"); + return nullptr; + } + + if (!allocator->MapAshmem(mapType)) { + ROSEN_LOGE("CreateAshmemAllocatorWithFd: MapAshmem failed"); + return nullptr; + } + + return allocator; +} + +AshmemAllocator::AshmemAllocator(int fd, size_t size) : fd_(fd), size_(size) {} + +AshmemAllocator::~AshmemAllocator() +{ + Dealloc(data_); +} + +bool AshmemAllocator::MapAshmem(int mapType) +{ + void *startAddr = ::mmap(nullptr, size_, mapType, MAP_SHARED, fd_, 0); + if (startAddr == MAP_FAILED) { + ROSEN_LOGE("AshmemAllocator::MapAshmem MAP_FAILED"); + return false; + } + data_ = startAddr; + return true; +} + +bool AshmemAllocator::WriteToAshmem(const void *data, size_t size) +{ + if (data == nullptr || size_ < size) { + return false; + } + errno_t err = memcpy_s(data_, size, data, size); + if (err != EOK) { + ROSEN_LOGE("AshmemAllocator::WriteToAshmem memcpy_s failed, err:%d", err); + return false; + } + return true; +} + +void* AshmemAllocator::CopyFromAshmem(size_t size) +{ + if (size_ < size) { + return nullptr; + } + void* base = malloc(size); + if (base == nullptr) { + ROSEN_LOGE("AshmemAllocator::CopyFromAshmem malloc failed, size:%zu", size); + return nullptr; + } + + errno_t err = memcpy_s(base, size, data_, size); + if (err != EOK) { + free(base); + base = nullptr; + ROSEN_LOGE("AshmemAllocator::CopyFromAshmem memcpy_s failed, err:%d", err); + return nullptr; + } + return base; +} + +// the fd is only valid during the object lifetime +int AshmemAllocator::GetFd() const +{ + return fd_; +} + +size_t AshmemAllocator::GetSize() const +{ + return size_; +} + +void* AshmemAllocator::GetData() const +{ + return data_; +} + +void AshmemAllocator::Dealloc(void* data) +{ + if (data != data_) { + ROSEN_LOGW("AshmemAllocator::Dealloc data addr not match!"); + } + if (data_ != nullptr) { + ::munmap(data_, size_); + data_ = nullptr; + } + if (fd_ > 0) { + ::close(fd_); + fd_ = -1; + } +} + +void* AshmemAllocator::Alloc(size_t size) +{ + ROSEN_LOGW("AshmemAllocator::Alloc"); + return nullptr; +} + +void* AshmemAllocator::Realloc(void* data, size_t newSize) +{ + ROSEN_LOGW("AshmemAllocator::Realloc"); + return nullptr; +} + +void RSAshmemHelper::CopyFileDescriptor( + std::shared_ptr& ashmemParcel, std::shared_ptr& dataParcel) +{ + binder_size_t* object = reinterpret_cast(dataParcel->GetObjectOffsets()); + size_t objectNum = dataParcel->GetOffsetsSize(); + uintptr_t data = dataParcel->GetData(); + for (size_t i = 0; i < objectNum; i++) { + const flat_binder_object* flat = reinterpret_cast(data + object[i]); + if (flat->hdr.type == BINDER_TYPE_FD) { + if (!ashmemParcel->WriteFileDescriptor(flat->handle)) { + ROSEN_LOGE("RSAshmemHelper::CopyFileDescriptor failed, fd:%d", flat->handle); + } + } + } +} + +void RSAshmemHelper::InjectFileDescriptor(std::shared_ptr& dataParcel, MessageParcel* ashmemParcel) +{ + binder_size_t* object = reinterpret_cast(dataParcel->GetObjectOffsets()); + size_t objectNum = dataParcel->GetOffsetsSize(); + uintptr_t data = dataParcel->GetData(); + for (size_t i = 0; i < objectNum; i++) { + flat_binder_object* flat = reinterpret_cast(data + object[i]); + if (flat->hdr.type == BINDER_TYPE_FD) { + int32_t val = ashmemParcel->ReadFileDescriptor(); + if (val < 0) { + ROSEN_LOGW("RSAshmemHelper::InjectFileDescriptor failed, fd:%d", val); + } + flat->handle = static_cast(val); + } + } +} + +std::shared_ptr RSAshmemHelper::CreateAshmemParcel(std::shared_ptr& dataParcel) +{ + size_t dataSize = dataParcel->GetDataSize(); + RS_TRACE_NAME("CreateAshmemParcel data size:" + std::to_string(dataSize)); + + // if want a full copy of parcel, need to save its data and fds both: + // 1. save origin parcel data to ashmeme and record the fd to new parcel + // 2. save all fds and their offsets in new parcel + auto ashmemAllocator = AshmemAllocator::CreateAshmemAllocator(dataSize, PROT_READ | PROT_WRITE); + if (!ashmemAllocator) { + ROSEN_LOGE("CreateAshmemParcel failed, ashmemAllocator is nullptr"); + return nullptr; + } + if (!ashmemAllocator->WriteToAshmem(reinterpret_cast(dataParcel->GetData()), dataSize)) { + ROSEN_LOGE("CreateAshmemParcel: WriteToAshmem failed"); + return nullptr; + } + // 1. save data + int fd = ashmemAllocator->GetFd(); + std::shared_ptr ashmemParcel = std::make_shared(); + ashmemParcel->WriteInt32(1); // 1: indicate ashmem parcel + ashmemParcel->WriteInt32(dataSize); + ashmemParcel->WriteFileDescriptor(fd); + + // 2. save fds and their offsets + size_t offsetSize = dataParcel->GetOffsetsSize(); + ashmemParcel->WriteInt32(offsetSize); + if (offsetSize > 0) { + // save array that record the offsets of all fds + ashmemParcel->WriteBuffer( + reinterpret_cast(dataParcel->GetObjectOffsets()), sizeof(binder_size_t) * offsetSize); + // save all fds of origin parcel + CopyFileDescriptor(ashmemParcel, dataParcel); + } + + return ashmemParcel; +} + +std::shared_ptr RSAshmemHelper::ParseFromAshmemParcel(MessageParcel* ashmemParcel) +{ + int32_t dataSize = ashmemParcel->ReadInt32(); + RS_TRACE_NAME("ParseFromAshmemParcel data size:" + std::to_string(dataSize)); + + int fd = ashmemParcel->ReadFileDescriptor(); + auto ashmemAllocator = AshmemAllocator::CreateAshmemAllocatorWithFd(fd, dataSize, PROT_READ | PROT_WRITE); + if (!ashmemAllocator) { + ROSEN_LOGE("ParseFromAshmemParcel failed, ashmemAllocator is nullptr"); + return nullptr; + } + void* data = ashmemAllocator->GetData(); + auto dataParcel = std::make_shared(ashmemAllocator.release()); + dataParcel->ParseFrom(reinterpret_cast(data), dataSize); + + int32_t offsetSize = ashmemParcel->ReadInt32(); + if (offsetSize > 0) { + auto* offsets = ashmemParcel->ReadBuffer(sizeof(binder_size_t) * offsetSize); + if (offsets == nullptr) { + ROSEN_LOGE("ParseFromAshmemParcel: read object offsets failed"); + return nullptr; + } + // restore array that record the offsets of all fds + dataParcel->InjectOffsets(reinterpret_cast(offsets), offsetSize); + // restore all fds + InjectFileDescriptor(dataParcel, ashmemParcel); + } + + if (dataParcel->ReadInt32() != 0) { // identify normal parcel + ROSEN_LOGE("RSAshmemHelper::ParseFromAshmemParcel failed"); + return nullptr; + } + + return dataParcel; +} +} // namespace Rosen +} // namespace OHOS diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_event_detector.cpp b/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_event_detector.cpp new file mode 100644 index 0000000..fc1e0b9 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_event_detector.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 "platform/common/rs_event_manager.h" + +namespace OHOS { +namespace Rosen { +uint64_t RSEventTimer::GetSysTimeMs() +{ + auto now = std::chrono::steady_clock::now().time_since_epoch(); + return std::chrono::duration_cast(now).count(); +} + +std::shared_ptr RSBaseEventDetector::CreateRSTimeOutDetector(int timeOutThresholdMs, + std::string detectorStringId) +{ + std::shared_ptr eventPtr = std::make_shared(timeOutThresholdMs, + detectorStringId); + return eventPtr; +} + +RSTimeOutDetector::RSTimeOutDetector(int timeOutThresholdMs, + std::string detectorStringId) :RSBaseEventDetector(detectorStringId) +{ + RS_LOGD("RSTimeOutDetector ::RSTimeOutDetector timeOutThresholdMs is %d ", timeOutThresholdMs); + timeOutThresholdMs_ = timeOutThresholdMs; + paramList_["timeOutThresholdMs"] = std::to_string(timeOutThresholdMs_); +} + + +void RSTimeOutDetector::SetParam(const std::string& key, const std::string& value) +{ + if (paramList_.count(key) == 0) { + RS_LOGD("RSTimeOutDetector :: SetParam Invaild Key "); + return; + } + int valueInt = atoi(value.c_str()); + if (valueInt <= 0 || valueInt > 1000000) { // 1000000Ms->1000s + RS_LOGD("RSTimeOutDetector :: SetParam Invaild Value "); + return; + } + timeOutThresholdMs_ = valueInt; + paramList_[key] = value; +} + + +void RSTimeOutDetector::SetLoopStartTag() +{ + startTimeStampMs_ = RSEventTimer::GetSysTimeMs(); +} + +void RSTimeOutDetector::SetLoopFinishTag( + int32_t focusAppPid, int32_t focusAppUid, std::string& focusAppBundleName, std::string& focusAppAbilityName) +{ + uint64_t finishTimeStampMs = RSEventTimer::GetSysTimeMs(); + RS_LOGD("RSTimeOutDetector :: One loop cost Time: %" PRIu64 " ", finishTimeStampMs - startTimeStampMs_); + if (finishTimeStampMs > startTimeStampMs_) { + auto durationStampMs = finishTimeStampMs - startTimeStampMs_; + if (durationStampMs > static_cast(timeOutThresholdMs_)) { + focusAppPid_ = focusAppPid; + focusAppUid_ = focusAppUid; + focusAppBundleName_ = focusAppBundleName; + focusAppAbilityName_ = focusAppAbilityName; + EventReport(durationStampMs); + } + } +} + +void RSTimeOutDetector::EventReport(uint64_t costTimeMs) +{ + std::string msg = "RS TimeOut: one loop cost " + std::to_string(costTimeMs) + "ms"; + RSSysEventMsg eventMsg = { + stringId_, + msg, + OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, + focusAppPid_, + focusAppUid_, + focusAppBundleName_, + focusAppAbilityName_ + }; + if (focusAppPid_ != -1) { + eventMsg.pid = focusAppPid_; + eventMsg.uid = focusAppUid_; + eventMsg.bundleName = focusAppBundleName_; + eventMsg.abilityName = focusAppAbilityName_; + RS_LOGD("RSTimeOutDetector::EventReport focusApp: %d, %d, %s, %s", + eventMsg.pid, eventMsg.uid, eventMsg.bundleName.c_str(), eventMsg.abilityName.c_str()); + } + if (eventCallback_ != nullptr) { + eventCallback_(eventMsg); + } +} +} +} \ No newline at end of file diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_event_manager.cpp b/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_event_manager.cpp new file mode 100644 index 0000000..53bbba1 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_event_manager.cpp @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 "platform/common/rs_event_manager.h" +#include "platform/common/rs_system_properties.h" + +namespace OHOS { +namespace Rosen { +RSEventManager::~RSEventManager() +{ + Clear(); +} + +void RSEventManager::Clear() +{ + eventDetectorList_.clear(); + eventStateList_.clear(); + std::map> tempDetectorList; + std::map tempStateList; + eventDetectorList_.swap(tempDetectorList); + eventStateList_.swap(tempStateList); + RS_LOGD("RSEventManager::Clear finish"); +} + +void RSEventManager::DumpDetectorParam(std::shared_ptr detectorPtr, std::string& dumpString) +{ + if (detectorPtr == nullptr) { + RS_LOGD("RSEventManager::DumpDetectorParam detectorPtr nullptr"); + return; + } + const auto& paramList = detectorPtr->GetParamList(); + for (const auto& item : paramList) { + std::string paraName = "rosen.RsDFXEvent." + detectorPtr->GetStringId() + + "." + item.first + ": "; + dumpString.append(paraName + item.second + "\n"); + } +} + +void RSEventManager::DumpEventIntervalMs(std::shared_ptr detectorPtr, std::string& dumpString) +{ + if (detectorPtr == nullptr) { + RS_LOGD("RSEventManager::DumpEventIntervalMs detectorPtr nullptr"); + return; + } + if (eventStateList_.count(detectorPtr->GetStringId()) == 0) { + RS_LOGD("RSEventManager::DumpEventIntervalMs detector:%s is not in list", + detectorPtr->GetStringId().c_str()); + return; + } + std::string paraName = "rosen.RsDFXEvent." + detectorPtr->GetStringId() + + ".eventIntervalMs" + ": "; + dumpString.append(paraName + std::to_string(eventStateList_[detectorPtr->GetStringId()].eventIntervalMs) + "\n"); +} + +void RSEventManager::DumpAllEventParam(std::string& dumpString) +{ + std::unique_lock listLock(listMutex_); + for (auto& item : eventDetectorList_) { + auto detectorPtr = item.second.lock(); + if (detectorPtr == nullptr) { + RS_LOGD("RSEventManager::DumpAllEventParam failed: nullptr"); + continue; + } + DumpDetectorParam(detectorPtr, dumpString); + DumpEventIntervalMs(detectorPtr, dumpString); + } +} + +void RSEventManager::UpdateDetectorParam(std::shared_ptr detectorPtr) +{ + if (detectorPtr == nullptr) { + RS_LOGD("RSEventManager::UpdateDetectorParam detectorPtr nullptr"); + return; + } + const auto& paramList = detectorPtr->GetParamList(); + for (const auto& item : paramList) { + std::string paraName = "rosen.RsDFXEvent." + detectorPtr->GetStringId() + + "." + item.first; + RS_LOGD("RSEventManager::UpdateDetectorParam paraName: %s", paraName.c_str()); + detectorPtr->SetParam(item.first, RSSystemProperties::GetRSEventProperty(paraName)); + } +} + +void RSEventManager::UpdateEventIntervalMs(std::shared_ptr detectorPtr) +{ + if (detectorPtr == nullptr) { + RS_LOGD("RSEventManager::UpdateEventIntervalMs detectorPtr nullptr"); + return; + } + if (eventStateList_.count(detectorPtr->GetStringId()) == 0) { + RS_LOGD("RSEventManager::UpdateEventIntervalMs detector:%s is not in list", + detectorPtr->GetStringId().c_str()); + return; + } + std::string paraName = "rosen.RsDFXEvent." + detectorPtr->GetStringId() + + ".eventIntervalMs"; + RS_LOGD("RSEventManager::UpdateEventIntervalMs paraName: %s", paraName.c_str()); + int valueInt = atoi(RSSystemProperties::GetRSEventProperty(paraName).c_str()); + if (valueInt <= 0 || valueInt > 1000000) { // 1000000 ms ->1000s + RS_LOGD("RSEventManager::UpdateEventIntervalMs detector:%s Invaild Value:%d", + detectorPtr->GetStringId().c_str(), valueInt); + return; + } + eventStateList_[detectorPtr->GetStringId()].eventIntervalMs = valueInt; + RS_LOGD("RSEventManager::UpdateEventIntervalMs detector:%s eventIntervalMs:%d suceess", + detectorPtr->GetStringId().c_str(), valueInt); +} + +void RSEventManager::UpdateParam() +{ + updateCount_++; + if (updateCount_ < updateThreshold_) { + return; + } + updateCount_ = 0; + std::unique_lock listLock(listMutex_); + for (auto& item : eventDetectorList_) { + auto detectorPtr = item.second.lock(); + if (detectorPtr == nullptr) { + RS_LOGD("RSEventManager::UpdateParam failed: nullptr"); + continue; + } + UpdateDetectorParam(detectorPtr); + UpdateEventIntervalMs(detectorPtr); + } +} + +void RSEventManager::AddEvent(const std::shared_ptr& detectorPtr, int eventIntervalMs) +{ + if (detectorPtr == nullptr || eventIntervalMs <= 0) { + RS_LOGD("RSEventManager::AddEvent detectorPtr nullptr"); + return; + } + std::weak_ptr detectorWeakPtr(detectorPtr); + { + std::unique_lock listLock(listMutex_); + if (eventDetectorList_.count(detectorPtr->GetStringId()) != 0) { + RS_LOGD("RSEventManager::AddEvent %s failed ", detectorPtr->GetStringId().c_str()); + return; + } + detectorPtr->AddEventReportCallback([this](const RSSysEventMsg& eventMsg) { + this->EventReport(eventMsg); + }); + eventDetectorList_[detectorPtr->GetStringId()] = detectorWeakPtr; + RSEventState state = { + eventIntervalMs, + 0 + }; + eventStateList_[detectorPtr->GetStringId()] = state; + RS_LOGD("RSEventManager::AddEvent %s success ", detectorPtr->GetStringId().c_str()); + } +} + +void RSEventManager::RemoveEvent(std::string stringId) +{ + std::unique_lock listLock(listMutex_); + if (eventDetectorList_.count(stringId) != 0) { + RS_LOGD("RSEventManager::RemoveEvent %s failed ", stringId.c_str()); + return; + } + eventDetectorList_.erase(stringId); + eventStateList_.erase(stringId); + RS_LOGD("RSEventManager::RemoveEvent %s success ", stringId.c_str()); +} + +void RSEventManager::EventReport(const RSSysEventMsg& eventMsg) +{ + std::unique_lock listLock(listMutex_); + if (eventStateList_.count(eventMsg.stringId) == 0) { + RS_LOGD("RSEventManager::EventReport %s failed ", eventMsg.stringId.c_str()); + return; + } + RSEventState& state = eventStateList_[eventMsg.stringId]; + uint64_t currentTimeMs = RSEventTimer::GetSysTimeMs(); + if (currentTimeMs > state.prevEventTimeStampMs&& + currentTimeMs - state.prevEventTimeStampMs > static_cast(state.eventIntervalMs)) { +#ifndef HISYSEVENT_MOCK + std::string domain = "GRAPHIC"; + if (eventMsg.pid != -1) { + OHOS::HiviewDFX::HiSysEvent::Write( + domain, + eventMsg.stringId, + eventMsg.eventType, + "PID", eventMsg.pid, + "UID", eventMsg.uid, + "BUNDLE_NAME", eventMsg.bundleName, + "ABILITY_NAME", eventMsg.abilityName, + "MSG", eventMsg.msg); + } else { + OHOS::HiviewDFX::HiSysEvent::Write( + domain, + eventMsg.stringId, + eventMsg.eventType, + "MSG", eventMsg.msg); + } + state.prevEventTimeStampMs = currentTimeMs; + RS_LOGD("RSEventManager::EventReport %s success ", eventMsg.stringId.c_str()); +#endif + } +} +} +} \ No newline at end of file diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_frame_report.cpp b/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_frame_report.cpp new file mode 100644 index 0000000..a525826 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_frame_report.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 "pipeline/rs_frame_report.h" + +#include +#include +#include + +#include "platform/common/rs_log.h" + +namespace OHOS { +namespace Rosen { +namespace { +#ifdef __aarch64__ + const std::string FRAME_AWARE_SO_PATH = "/system/lib64/libframe_ui_intf.z.so"; +#else + const std::string FRAME_AWARE_SO_PATH = "/system/lib/libframe_ui_intf.z.so"; +#endif +} +RsFrameReport& RsFrameReport::GetInstance() +{ + static RsFrameReport instance; + return instance; +} + +RsFrameReport::RsFrameReport() {} + +RsFrameReport::~RsFrameReport() +{ + CloseLibrary(); +} + +void RsFrameReport::Init() +{ + int ret = LoadLibrary(); + if (!ret) { + ROSEN_LOGE("RsFrameReport:[Init] dlopen libframe_ui_intf.so failed!"); + return; + } + ROSEN_LOGD("RsFrameReport:[Init] dlopen libframe_ui_intf.so success!"); +} + +bool RsFrameReport::LoadLibrary() +{ + if (!frameSchedSoLoaded_) { + frameSchedHandle_ = dlopen(FRAME_AWARE_SO_PATH.c_str(), RTLD_LAZY); + if (frameSchedHandle_ == nullptr) { + ROSEN_LOGE("RsFrameReport:[LoadLibrary]dlopen libframe_ui_intf.so failed! error = %s\n", dlerror()); + return false; + } + frameSchedSoLoaded_ = true; + } + return true; +} + +void RsFrameReport::CloseLibrary() +{ + if (dlclose(frameSchedHandle_) != 0) { + ROSEN_LOGE("RsFrameReport:[CloseLibrary]libframe_ui_intf.so failed!\n"); + return; + } + frameSchedHandle_ = nullptr; + frameSchedSoLoaded_ = false; + ROSEN_LOGD("RsFrameReport:[CloseLibrary]libframe_ui_intf.so close success!\n"); +} + +void *RsFrameReport::LoadSymbol(const char *symName) +{ + if (!frameSchedSoLoaded_) { + ROSEN_LOGE("RsFrameReport:[loadSymbol]libframe_ui_intf.so not loaded.\n"); + return nullptr; + } + + void *funcSym = dlsym(frameSchedHandle_, symName); + if (funcSym == nullptr) { + ROSEN_LOGE("RsFrameReport:[loadSymbol]Get %{public}s symbol failed: %{public}s\n", symName, dlerror()); + return nullptr; + } + return funcSym; +} + +int RsFrameReport::GetEnable() +{ + if (!frameSchedSoLoaded_) { + return 0; + } + frameGetEnableFunc_ = (FrameGetEnableFunc)LoadSymbol("GetSenseSchedEnable"); + if (frameGetEnableFunc_ != nullptr) { + return frameGetEnableFunc_(); + } else { + ROSEN_LOGE("RsFrameReport:[GetEnable]load GetSenseSchedEnable function failed!"); + return 0; + } +} + +void RsFrameReport::ProcessCommandsStart() +{ + processCommandsStartFun_ = (ProcessCommandsStartFunc)LoadSymbol("ProcessCommandsStart"); + if (processCommandsStartFun_ != nullptr) { + processCommandsStartFun_(); + } else { + ROSEN_LOGE("RsFrameReport:[ProcessCommandsStart]load ProcessCommandsStart function failed!"); + } +} + +void RsFrameReport::AnimateStart() +{ + animateStartFunc_ = (AnimateStartFunc)LoadSymbol("AnimateStart"); + if (animateStartFunc_ != nullptr) { + animateStartFunc_(); + } else { + ROSEN_LOGE("RsFrameReport:[AnimateStart]load AnimateStart function failed!"); + } +} + +void RsFrameReport::RenderStart() +{ + renderStartFunc_ = (RenderStartFunc)LoadSymbol("RenderStart"); + if (renderStartFunc_ != nullptr) { + renderStartFunc_(); + } else { + ROSEN_LOGE("RsFrameReport:[RenderStart]load RenderStart function failed!"); + } +} + +void RsFrameReport::SendCommandsStart() +{ + sendCommandsStartFunc_ = (SendCommandsStartFunc)LoadSymbol("SendCommandsStart"); + if (sendCommandsStartFunc_ != nullptr) { + sendCommandsStartFunc_(); + } else { + ROSEN_LOGE("RsFrameReport:[SendCommandsStart]load SendCommandsStart function failed!"); + } +} +} // namespace Rosen +} // namespace OHOS diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_innovation.cpp b/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_innovation.cpp new file mode 100644 index 0000000..9ed3564 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_innovation.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 "platform/common/rs_innovation.h" + +#include +#include +#include "parameters.h" + +namespace OHOS { +namespace Rosen { +void RSInnovation::OpenInnovationSo() +{ + innovationHandle = dlopen("libgraphic_innovation.z.so", RTLD_NOW); + GetParallelCompositionFunc(); + GetOcclusionCullingFunc(); + GetQosVSyncFunc(); +} + +void RSInnovation::CloseInnovationSo() +{ + if (innovationHandle) { + ResetParallelCompositionFunc(); + ResetOcclusionCullingFunc(); + ResetQosVsyncFunc(); + dlclose(innovationHandle); + } +} + +// parallel composition +bool RSInnovation::GetParallelCompositionEnabled() +{ + return _s_parallelCompositionLoaded && + std::atoi((system::GetParameter("rosen.parallelcomposition.enabled", "0")).c_str()) != 0; +} + +// occlusion culling +void RSInnovation::UpdateOcclusionCullingSoEnabled() +{ + _s_occlusionCullingSoEnabled = + std::atoi((system::GetParameter("rosen.occlusion.so.enabled", "0")).c_str()) != 0; +} + +bool RSInnovation::UpdateQosVsyncEnabled() +{ + return _s_qosVsyncFuncLoaded && + (std::atoi((system::GetParameter("rosen.qos_vsync.enabled", "0")).c_str()) != 0); +} + +void RSInnovation::GetParallelCompositionFunc() +{ + if (innovationHandle) { + _s_createParallelSyncSignal = dlsym(innovationHandle, "CreateParallelSyncSignal"); + _s_signalCountDown = dlsym(innovationHandle, "SignalCountDown"); + _s_signalAwait = dlsym(innovationHandle, "SignalAwait"); + _s_assignTask = dlsym(innovationHandle, "AssignTask"); + _s_removeStoppedThreads = dlsym(innovationHandle, "RemoveStoppedThreads"); + _s_checkForSerialForced = dlsym(innovationHandle, "CheckForSerialForced"); + _s_parallelCompositionLoaded = + (_s_createParallelSyncSignal != nullptr) && + (_s_signalCountDown != nullptr) && + (_s_signalAwait != nullptr) && + (_s_assignTask != nullptr) && + (_s_removeStoppedThreads != nullptr) && + (_s_checkForSerialForced != nullptr); + } +} + +void RSInnovation::ResetParallelCompositionFunc() +{ + if (_s_parallelCompositionLoaded) { + _s_parallelCompositionLoaded = false; + _s_createParallelSyncSignal = nullptr; + _s_signalCountDown = nullptr; + _s_signalAwait = nullptr; + _s_assignTask = nullptr; + _s_removeStoppedThreads = nullptr; + _s_checkForSerialForced = nullptr; + } +} + +void RSInnovation::GetOcclusionCullingFunc() +{ + if (innovationHandle) { + _s_regionOpFromSo = dlsym(innovationHandle, "RegionOpFromSO"); + _s_occlusionCullingFuncLoaded = (_s_regionOpFromSo != nullptr); + } +} + +void RSInnovation::ResetOcclusionCullingFunc() +{ + if (_s_occlusionCullingFuncLoaded) { + _s_regionOpFromSo = nullptr; + } +} + +void RSInnovation::GetQosVSyncFunc() +{ + if (innovationHandle) { + _s_createRSQosService = dlsym(innovationHandle, "CreateRSQosService"); + _s_qosThreadStart = dlsym(innovationHandle, "QosThreadStart"); + _s_qosThreadStop = dlsym(innovationHandle, "QosThreadStop"); + _s_qosSetBoundaryRate = dlsym(innovationHandle, "QosSetBoundaryRate"); + _s_qosOnRSVisibilityChangeCB = dlsym(innovationHandle, "QosOnRSVisibilityChangeCB"); + _s_qosRegisteFuncCB = dlsym(innovationHandle, "QosRegisteFuncCB"); + _s_qosOnRSResetPid = dlsym(innovationHandle, "QosOnRSResetPid"); + _s_qosVsyncFuncLoaded = (_s_createRSQosService != nullptr) && + (_s_qosThreadStart != nullptr) && + (_s_qosThreadStop != nullptr) && + (_s_qosSetBoundaryRate != nullptr) && + (_s_qosOnRSVisibilityChangeCB != nullptr) && + (_s_qosRegisteFuncCB != nullptr) && + (_s_qosOnRSResetPid != nullptr); + } +} + +void RSInnovation::ResetQosVsyncFunc() +{ + if (_s_qosVsyncFuncLoaded) { + _s_qosVsyncFuncLoaded = false; + _s_createRSQosService = nullptr; + _s_qosThreadStart = nullptr; + _s_qosThreadStop = nullptr; + _s_qosSetBoundaryRate = nullptr; + _s_qosOnRSVisibilityChangeCB = nullptr; + _s_qosRegisteFuncCB = nullptr; + _s_qosOnRSResetPid = nullptr; + } +} +} // namespace Rosen +} // namespace OHOS diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_log.cpp b/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_log.cpp new file mode 100644 index 0000000..5ddff78 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_log.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 "platform/common/rs_log.h" + +#include +#include +#include + +#include + +namespace OHOS { +namespace Rosen { +namespace { +constexpr int MAX_LOG_LENGTH = 2048; + +// The "0xD001400" is the domain ID for graphic module that alloted by the OS. +constexpr OHOS::HiviewDFX::HiLogLabel LABEL_RS = { LOG_CORE, 0xD001400, "OHOS::RS" }; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL_ROSEN = { LOG_CORE, 0xD001400, "OHOS::ROSEN" }; + +inline const OHOS::HiviewDFX::HiLogLabel& GenerateLabel(RSLog::Tag tag) +{ + return (tag == RSLog::Tag::RS) ? LABEL_RS : LABEL_ROSEN; +} +} + + +void RSLogOutput(RSLog::Tag tag, RSLog::Level level, const char* format, ...) +{ + char logStr[MAX_LOG_LENGTH] = {0}; + va_list args; + va_start(args, format); + int ret = vsprintf_s(logStr, MAX_LOG_LENGTH, format, args); + if (ret == -1) { // vsprintf_s failed + OHOS::HiviewDFX::HiLog::Error(GenerateLabel(tag), "print log error in vsprintf_s"); + va_end(args); + return; + } + va_end(args); + switch (level) { + case RSLog::LEVEL_INFO: + OHOS::HiviewDFX::HiLog::Info(GenerateLabel(tag), "%{public}s", logStr); + break; + case RSLog::LEVEL_DEBUG: + OHOS::HiviewDFX::HiLog::Debug(GenerateLabel(tag), "%{public}s", logStr); + break; + case RSLog::LEVEL_WARN: + OHOS::HiviewDFX::HiLog::Warn(GenerateLabel(tag), "%{public}s", logStr); + break; + case RSLog::LEVEL_ERROR: + OHOS::HiviewDFX::HiLog::Error(GenerateLabel(tag), "%{public}s", logStr); + break; + case RSLog::LEVEL_FATAL: + OHOS::HiviewDFX::HiLog::Fatal(GenerateLabel(tag), "%{public}s", logStr); + break; + default: + break; + } +} +} // namespace Rosen +} // namespace OHOS diff --git a/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_marshalling_helper.cpp b/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_marshalling_helper.cpp new file mode 100644 index 0000000..21aa9d8 --- /dev/null +++ b/display_server/rosen/modules/render_service_base/src/platform/fangtian/rs_marshalling_helper.cpp @@ -0,0 +1,916 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * 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 "transaction/rs_marshalling_helper.h" + +#include +#include +#include +#include + +#include "ashmem.h" +#include "include/core/SkDrawable.h" +#include "include/core/SkImage.h" +#include "include/core/SkPaint.h" +#include "include/core/SkPicture.h" +#include "include/core/SkSerialProcs.h" +#include "include/core/SkStream.h" +#include "include/core/SkTextBlob.h" +#include "include/core/SkTypeface.h" +#include "include/core/SkVertices.h" +#include "pixel_map.h" +#include "securec.h" +#include "src/core/SkAutoMalloc.h" +#include "src/core/SkPaintPriv.h" +#include "src/core/SkReadBuffer.h" +#include "src/core/SkWriteBuffer.h" +#include "src/image/SkImage_Base.h" + +#include "animation/rs_render_curve_animation.h" +#include "animation/rs_render_keyframe_animation.h" +#include "animation/rs_render_path_animation.h" +#include "animation/rs_render_spring_animation.h" +#include "animation/rs_render_transition.h" +#include "common/rs_color.h" +#include "common/rs_common_def.h" +#include "common/rs_matrix3.h" +#include "common/rs_vector4.h" +#include "modifier/rs_render_modifier.h" +#include "pipeline/rs_draw_cmd_list.h" +#include "platform/common/rs_log.h" +#include "render/rs_blur_filter.h" +#include "render/rs_filter.h" +#include "render/rs_image.h" +#include "render/rs_material_filter.h" +#include "render/rs_path.h" +#include "render/rs_shader.h" +#include "transaction/rs_ashmem_helper.h" + +namespace OHOS { +namespace Rosen { + +#define MARSHALLING_AND_UNMARSHALLING(TYPE, TYPENAME) \ + bool RSMarshallingHelper::Marshalling(Parcel& parcel, const TYPE& val) \ + { \ + return parcel.Write##TYPENAME(val); \ + } \ + bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, TYPE& val) \ + { \ + return parcel.Read##TYPENAME(val); \ + } + +// basic types +MARSHALLING_AND_UNMARSHALLING(bool, Bool) +MARSHALLING_AND_UNMARSHALLING(int8_t, Int8) +MARSHALLING_AND_UNMARSHALLING(uint8_t, Uint8) +MARSHALLING_AND_UNMARSHALLING(int16_t, Int16) +MARSHALLING_AND_UNMARSHALLING(uint16_t, Uint16) +MARSHALLING_AND_UNMARSHALLING(int32_t, Int32) +MARSHALLING_AND_UNMARSHALLING(uint32_t, Uint32) +MARSHALLING_AND_UNMARSHALLING(int64_t, Int64) +MARSHALLING_AND_UNMARSHALLING(uint64_t, Uint64) +MARSHALLING_AND_UNMARSHALLING(float, Float) +MARSHALLING_AND_UNMARSHALLING(double, Double) + +#undef MARSHALLING_AND_UNMARSHALLING + +namespace { +template +static inline sk_sp sk_reinterpret_cast(sk_sp

ptr) +{ + return sk_sp(static_cast(SkSafeRef(ptr.get()))); +} +} // namespace + +// SkData +bool RSMarshallingHelper::Marshalling(Parcel& parcel, sk_sp val) +{ + if (!val) { + return parcel.WriteInt32(-1); + } + + bool ret = parcel.WriteInt32(val->size()); + if (val->size() == 0) { + ROSEN_LOGW("unirender: RSMarshallingHelper::Marshalling SkData size is 0"); + return ret; + } + + ret = ret && RSMarshallingHelper::WriteToParcel(parcel, val->data(), val->size()); + if (!ret) { + ROSEN_LOGE("unirender: failed RSMarshallingHelper::Marshalling SkData"); + } + return ret; +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, sk_sp& val) +{ + int32_t size = parcel.ReadInt32(); + if (size == -1) { + val = nullptr; + return true; + } + if (size == 0) { + ROSEN_LOGW("unirender: RSMarshallingHelper::Unmarshalling SkData size is 0"); + val = SkData::MakeEmpty(); + return true; + } + + const void* data = RSMarshallingHelper::ReadFromParcel(parcel, size); + if (data == nullptr) { + ROSEN_LOGE("unirender: failed RSMarshallingHelper::Unmarshalling SkData"); + return false; + } + + if (static_cast(size) < MIN_DATA_SIZE) { + val = SkData::MakeWithoutCopy(data, size); + } else { + val = SkData::MakeFromMalloc(data, size); + } + return val != nullptr; +} +bool RSMarshallingHelper::SkipSkData(Parcel& parcel) +{ + int32_t size = parcel.ReadInt32(); + if (size <= 0) { + return true; + } + return SkipFromParcel(parcel, size); +} + +bool RSMarshallingHelper::UnmarshallingWithCopy(Parcel& parcel, sk_sp& val) +{ + bool success = Unmarshalling(parcel, val); + if (success) { + if (val && val->size() < MIN_DATA_SIZE) { + val = SkData::MakeWithCopy(val->data(), val->size()); + } + } + return success; +} + +// SkTypeface serial proc +sk_sp RSMarshallingHelper::SerializeTypeface(SkTypeface* tf, void* ctx) +{ + if (tf == nullptr) { + ROSEN_LOGD("unirender: RSMarshallingHelper::SerializeTypeface SkTypeface is nullptr"); + return nullptr; + } + return tf->serialize(); +} + +// SkTypeface deserial proc +sk_sp RSMarshallingHelper::DeserializeTypeface(const void* data, size_t length, void* ctx) +{ + SkMemoryStream stream(data, length); + return SkTypeface::MakeDeserialize(&stream); +} + +// SkTextBlob +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const sk_sp& val) +{ + sk_sp data; + if (!val) { + ROSEN_LOGD("unirender: RSMarshallingHelper::Marshalling SkTextBlob is nullptr"); + return Marshalling(parcel, data); + } + SkSerialProcs serialProcs; + serialProcs.fTypefaceProc = &RSMarshallingHelper::SerializeTypeface; + data = val->serialize(serialProcs); + return Marshalling(parcel, data); +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, sk_sp& val) +{ + sk_sp data; + if (!Unmarshalling(parcel, data)) { + ROSEN_LOGE("unirender: failed RSMarshallingHelper::Unmarshalling SkTextBlob"); + return false; + } + if (data == nullptr) { + val = nullptr; + return true; + } + SkDeserialProcs deserialProcs; + deserialProcs.fTypefaceProc = &RSMarshallingHelper::DeserializeTypeface; + val = SkTextBlob::Deserialize(data->data(), data->size(), deserialProcs); + return val != nullptr; +} + +// SkPaint +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const SkPaint& val) +{ + SkBinaryWriteBuffer writer; + writer.writePaint(val); + size_t length = writer.bytesWritten(); + sk_sp data = SkData::MakeUninitialized(length); + writer.writeToMemory(data->writable_data()); + return Marshalling(parcel, data); +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, SkPaint& val) +{ + sk_sp data; + if (!Unmarshalling(parcel, data)) { + ROSEN_LOGE("unirender: failed RSMarshallingHelper::Unmarshalling SkPaint"); + return false; + } + SkReadBuffer reader(data->data(), data->size()); + reader.readPaint(&val, nullptr); + return true; +} + +// SkImage +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const sk_sp& val) +{ + if (!val) { + return parcel.WriteInt32(-1); + } + int32_t type = val->isLazyGenerated(); + parcel.WriteInt32(type); + if (type == 1) { + ROSEN_LOGD("RSMarshallingHelper::Marshalling SkImage isLazyGenerated"); + SkBinaryWriteBuffer writer; + writer.writeImage(val.get()); + size_t length = writer.bytesWritten(); + sk_sp data = SkData::MakeUninitialized(length); + writer.writeToMemory(data->writable_data()); + return Marshalling(parcel, data); + } else { + SkBitmap bitmap; + if (!as_IB(val.get())->getROPixels(&bitmap)) { + ROSEN_LOGE("RSMarshallingHelper::Marshalling SkImage getROPixels failed"); + return false; + } + SkPixmap pixmap; + if (!bitmap.peekPixels(&pixmap)) { + ROSEN_LOGE("RSMarshallingHelper::Marshalling SkImage peekPixels failed"); + return false; + } + size_t rb = pixmap.rowBytes(); + int width = pixmap.width(); + int height = pixmap.height(); + const void* addr = pixmap.addr(); + size_t size = rb * static_cast(height); + + parcel.WriteUint32(size); + if (!WriteToParcel(parcel, addr, size)) { + ROSEN_LOGE("RSMarshallingHelper::Marshalling SkImage WriteToParcel failed"); + return false; + } + + parcel.WriteUint32(rb); + parcel.WriteInt32(width); + parcel.WriteInt32(height); + + parcel.WriteUint32(pixmap.colorType()); + parcel.WriteUint32(pixmap.alphaType()); + + if (pixmap.colorSpace() == nullptr) { + parcel.WriteUint32(0); + return true; + } else { + auto data = pixmap.colorSpace()->serialize(); + parcel.WriteUint32(data->size()); + if (!WriteToParcel(parcel, data->data(), data->size())) { + ROSEN_LOGE("RSMarshallingHelper::Marshalling SkImage WriteToParcel colorSpace failed"); + return false; + } + } + return true; + } +} + +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, sk_sp& val) +{ + int32_t type = parcel.ReadInt32(); + if (type == -1) { + val = nullptr; + return true; + } + if (type == 1) { + sk_sp data; + ROSEN_LOGD("RSMarshallingHelper::Unmarshalling lazy"); + if (!Unmarshalling(parcel, data)) { + ROSEN_LOGE("failed RSMarshallingHelper::Unmarshalling SkImage"); + return false; + } + SkReadBuffer reader(data->data(), data->size()); + val = reader.readImage(); + return val != nullptr; + } else { + size_t pixmapSize = parcel.ReadUint32(); + const void* addr = RSMarshallingHelper::ReadFromParcel(parcel, pixmapSize); + if (addr == nullptr) { + ROSEN_LOGE("failed RSMarshallingHelper::Unmarshalling SkData addr"); + return false; + } + + size_t rb = parcel.ReadUint32(); + int width = parcel.ReadInt32(); + int height = parcel.ReadInt32(); + + SkColorType colorType = static_cast(parcel.ReadUint32()); + SkAlphaType alphaType = static_cast(parcel.ReadUint32()); + sk_sp colorSpace; + + size_t size = parcel.ReadUint32(); + if (size == 0) { + colorSpace = nullptr; + } else { + const void* data = RSMarshallingHelper::ReadFromParcel(parcel, size); + if (data == nullptr) { + ROSEN_LOGE("failed RSMarshallingHelper::Unmarshalling SkData data"); + return false; + } + colorSpace = SkColorSpace::Deserialize(data, size); + if (size >= MIN_DATA_SIZE) { + free(const_cast(data)); + } + } + + SkImageInfo imageInfo = SkImageInfo::Make(width, height, colorType, alphaType, colorSpace); + auto skData = pixmapSize < MIN_DATA_SIZE ? SkData::MakeWithCopy(addr, pixmapSize) + : SkData::MakeFromMalloc(addr, pixmapSize); + val = SkImage::MakeRasterData(imageInfo, skData, rb); + return val != nullptr; + } +} + +bool RSMarshallingHelper::SkipSkImage(Parcel& parcel) +{ + int32_t type = parcel.ReadInt32(); + if (type == -1) { + return true; + } + sk_sp data; + if (type == 1) { + ROSEN_LOGD("RSMarshallingHelper::SkipSkImage lazy"); + return SkipSkData(parcel); + } else { + size_t pixmapSize = parcel.ReadUint32(); + if (!SkipFromParcel(parcel, pixmapSize)) { + ROSEN_LOGE("failed RSMarshallingHelper::SkipSkImage SkData addr"); + return false; + } + + parcel.ReadUint32(); + parcel.ReadInt32(); + parcel.ReadInt32(); + parcel.ReadUint32(); + parcel.ReadUint32(); + size_t size = parcel.ReadUint32(); + return size == 0 ? true : SkipFromParcel(parcel, size); + } +} + +// SkPicture +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const sk_sp& val) +{ + sk_sp data; + if (!val) { + ROSEN_LOGD("unirender: RSMarshallingHelper::Marshalling SkPicture is nullptr"); + return Marshalling(parcel, data); + } + data = val->serialize(); + return Marshalling(parcel, data); +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, sk_sp& val) +{ + sk_sp data; + if (!Unmarshalling(parcel, data)) { + ROSEN_LOGE("unirender: failed RSMarshallingHelper::Unmarshalling SkPicture"); + return false; + } + if (data == nullptr) { + val = nullptr; + return true; + } + val = SkPicture::MakeFromData(data->data(), data->size()); + return val != nullptr; +} + +// SkVertices +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const sk_sp& val) +{ + sk_sp data; + if (!val) { + ROSEN_LOGD("unirender: RSMarshallingHelper::Marshalling SkVertices is nullptr"); + return Marshalling(parcel, data); + } + data = val->encode(); + return Marshalling(parcel, data); +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, sk_sp& val) +{ + sk_sp data; + if (!Unmarshalling(parcel, data)) { + ROSEN_LOGE("unirender: failed RSMarshallingHelper::Unmarshalling SkVertices"); + return false; + } + if (data == nullptr) { + val = nullptr; + return true; + } + val = SkVertices::Decode(data->data(), data->size()); + return val != nullptr; +} + +// SkRect +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const SkRect& rect) +{ + SkBinaryWriteBuffer writer; + writer.writeRect(rect); + size_t length = writer.bytesWritten(); + sk_sp data = SkData::MakeUninitialized(length); + writer.writeToMemory(data->writable_data()); + return Marshalling(parcel, data); +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, SkRect& rect) +{ + sk_sp data; + if (!Unmarshalling(parcel, data)) { + ROSEN_LOGE("unirender: failed RSMarshallingHelper::Unmarshalling SkRect"); + return false; + } + SkReadBuffer reader(data->data(), data->size()); + reader.readRect(&rect); + return true; +} + +// SkRegion +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const SkRegion& region) +{ + SkBinaryWriteBuffer writer; + writer.writeRegion(region); + size_t length = writer.bytesWritten(); + sk_sp data = SkData::MakeUninitialized(length); + writer.writeToMemory(data->writable_data()); + return Marshalling(parcel, data); +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, SkRegion& region) +{ + sk_sp data; + if (!Unmarshalling(parcel, data)) { + ROSEN_LOGE("unirender: failed RSMarshallingHelper::Unmarshalling SkRegion"); + return false; + } + SkReadBuffer reader(data->data(), data->size()); + reader.readRegion(®ion); + return true; +} + +// SKPath +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const SkPath& val) +{ + SkBinaryWriteBuffer writer; + writer.writePath(val); + size_t length = writer.bytesWritten(); + sk_sp data = SkData::MakeUninitialized(length); + writer.writeToMemory(data->writable_data()); + return Marshalling(parcel, data); +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, SkPath& val) +{ + sk_sp data; + if (!Unmarshalling(parcel, data)) { + ROSEN_LOGE("unirender: failed RSMarshallingHelper::Unmarshalling SKPath"); + return false; + } + SkReadBuffer reader(data->data(), data->size()); + reader.readPath(&val); + return true; +} + +// SkFlattenable +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const sk_sp& val) +{ + if (!val) { + ROSEN_LOGD("unirender: RSMarshallingHelper::Marshalling SkFlattenable is nullptr"); + return parcel.WriteInt32(-1); + } + sk_sp data = val->serialize(); + return parcel.WriteInt32(val->getFlattenableType()) && Marshalling(parcel, data); +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, sk_sp& val) +{ + int32_t type = parcel.ReadInt32(); + if (type == -1) { + val = nullptr; + return true; + } + sk_sp data; + if (!Unmarshalling(parcel, data)) { + ROSEN_LOGE("unirender: failed RSMarshallingHelper::Unmarshalling SkFlattenable"); + return false; + } + val = SkFlattenable::Deserialize(static_cast(type), data->data(), data->size()); + return val != nullptr; +} + +// SkDrawable +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const sk_sp& val) +{ + if (!val) { + ROSEN_LOGD("unirender: RSMarshallingHelper::Marshalling SkDrawable is nullptr"); + } + return Marshalling(parcel, sk_sp(val)); +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, sk_sp& val) +{ + sk_sp flattenablePtr; + if (!Unmarshalling(parcel, flattenablePtr)) { + ROSEN_LOGE("unirender: failed RSMarshallingHelper::Unmarshalling SkDrawable"); + return false; + } + val = sk_reinterpret_cast(flattenablePtr); + return true; +} + +// SkImageFilter +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const sk_sp& val) +{ + if (!val) { + ROSEN_LOGD("unirender: RSMarshallingHelper::Marshalling SkImageFilter is nullptr"); + } + return Marshalling(parcel, sk_sp(val)); +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, sk_sp& val) +{ + sk_sp flattenablePtr; + if (!Unmarshalling(parcel, flattenablePtr)) { + ROSEN_LOGE("unirender: failed RSMarshallingHelper::Unmarshalling SkImageFilter"); + return false; + } + val = sk_reinterpret_cast(flattenablePtr); + return true; +} + +// RSShader +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const std::shared_ptr& val) +{ + if (!val) { + ROSEN_LOGD("unirender: RSMarshallingHelper::Marshalling RSShader is nullptr"); + return parcel.WriteInt32(-1); + } + return parcel.WriteInt32(1) && Marshalling(parcel, sk_sp(val->GetSkShader())); +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, std::shared_ptr& val) +{ + if (parcel.ReadInt32() == -1) { + val = nullptr; + return true; + } + sk_sp flattenablePtr; + if (!Unmarshalling(parcel, flattenablePtr)) { + ROSEN_LOGE("unirender: failed RSMarshallingHelper::Unmarshalling RSShader"); + return false; + } + auto shaderPtr = sk_reinterpret_cast(flattenablePtr); + val = RSShader::CreateRSShader(shaderPtr); + return val != nullptr; +} + +// RSPath +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const std::shared_ptr& val) +{ + if (!val) { + ROSEN_LOGD("unirender: RSMarshallingHelper::Marshalling RSPath is nullptr"); + return parcel.WriteInt32(-1); + } + return parcel.WriteInt32(1) && Marshalling(parcel, val->GetSkiaPath()); +} + +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, std::shared_ptr& val) +{ + if (parcel.ReadInt32() == -1) { + val = nullptr; + return true; + } + SkPath path; + if (!Unmarshalling(parcel, path)) { + ROSEN_LOGE("unirender: failed RSMarshallingHelper::Unmarshalling RSPath"); + return false; + } + val = RSPath::CreateRSPath(path); + return val != nullptr; +} + +// RSMask +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const std::shared_ptr& val) +{ + if (!val) { + ROSEN_LOGD("unirender: RSMarshallingHelper::Marshalling RSMask is nullptr"); + return parcel.WriteInt32(-1); + } + return parcel.WriteInt32(1) && val->Marshalling(parcel); +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, std::shared_ptr& val) +{ + if (parcel.ReadInt32() == -1) { + val = nullptr; + return true; + } + val.reset(RSMask::Unmarshalling(parcel)); + return val != nullptr; +} + +// RSFilter +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const std::shared_ptr& val) +{ + if (!val) { + return parcel.WriteInt32(RSFilter::NONE); + } + bool success = parcel.WriteInt32(static_cast(val->GetFilterType())); + switch (val->GetFilterType()) { + case RSFilter::BLUR: { + auto blur = std::static_pointer_cast(val); + success = success && parcel.WriteFloat(blur->GetBlurRadiusX()) && parcel.WriteFloat(blur->GetBlurRadiusY()); + break; + } + case RSFilter::MATERIAL: { + auto material = std::static_pointer_cast(val); + success = success && parcel.WriteInt32(material->style_) && parcel.WriteFloat(material->dipScale_) && + parcel.WriteInt32(material->colorMode_); + break; + } + default: + break; + } + return success; +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, std::shared_ptr& val) +{ + int type = 0; + bool success = parcel.ReadInt32(type); + switch (static_cast(type)) { + case RSFilter::BLUR: { + float blurRadiusX; + float blurRadiusY; + success = success && parcel.ReadFloat(blurRadiusX) && parcel.ReadFloat(blurRadiusY); + if (success) { + val = RSFilter::CreateBlurFilter(blurRadiusX, blurRadiusY); + } + break; + } + case RSFilter::MATERIAL: { + int style; + float dipScale; + int colorMode; + success = success && parcel.ReadInt32(style) && parcel.ReadFloat(dipScale) && parcel.ReadInt32(colorMode); + if (success) { + val = RSFilter::CreateMaterialFilter(style, dipScale, static_cast(colorMode)); + } + break; + } + default: { + val = nullptr; + break; + } + } + return success; +} + +// RSImage +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const std::shared_ptr& val) +{ + if (!val) { + ROSEN_LOGD("unirender: RSMarshallingHelper::Marshalling RSImage is nullptr"); + return parcel.WriteInt32(-1); + } + return parcel.WriteInt32(1) && val->Marshalling(parcel); +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, std::shared_ptr& val) +{ + if (parcel.ReadInt32() == -1) { + val = nullptr; + return true; + } + val.reset(RSImage::Unmarshalling(parcel)); + return val != nullptr; +} + +// Media::PixelMap +bool RSMarshallingHelper::Marshalling(Parcel& parcel, const std::shared_ptr& val) +{ + if (!val) { + return parcel.WriteInt32(-1); + } + if (!(parcel.WriteInt32(1) && val->Marshalling(parcel))) { + ROSEN_LOGE("failed RSMarshallingHelper::Marshalling Media::PixelMap"); + return false; + } + return true; +} +bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, std::shared_ptr& val) +{ + if (parcel.ReadInt32() == -1) { + val = nullptr; + return true; + } + val.reset(Media::PixelMap::Unmarshalling(parcel)); + if (val == nullptr) { + ROSEN_LOGE("failed RSMarshallingHelper::Unmarshalling Media::PixelMap"); + return false; + } + return true; +} + +#define MARSHALLING_AND_UNMARSHALLING(TYPE) \ + bool RSMarshallingHelper::Marshalling(Parcel& parcel, const std::shared_ptr& val) \ + { \ + return parcel.WriteParcelable(val.get()); \ + } \ + bool RSMarshallingHelper::Unmarshalling(Parcel& parcel, std::shared_ptr& val) \ + { \ + val.reset(parcel.ReadParcelable()); \ + return val != nullptr; \ + } +MARSHALLING_AND_UNMARSHALLING(RSRenderTransition) +MARSHALLING_AND_UNMARSHALLING(RSRenderTransitionEffect) +MARSHALLING_AND_UNMARSHALLING(DrawCmdList) +#undef MARSHALLING_AND_UNMARSHALLING + +#define MARSHALLING_AND_UNMARSHALLING(TEMPLATE) \ + bool RSMarshallingHelper::Marshalling(Parcel& parcel, const std::shared_ptr