merge conflict fix Signed-off-by: s30029175 <shiqiwei4@huawei.com>

Signed-off-by: sqwlly <shiqiwei4@huawei.com>
Change-Id: I76f72c467cdd1bd951a0990ff1db31ba51b77322
This commit is contained in:
sqwlly 2024-04-09 01:19:34 +00:00
commit a6253f8d59
118 changed files with 1687 additions and 376 deletions

View File

@ -88,20 +88,19 @@
"vulkan-headers",
"hiview",
"battery_manager",
"cJSON"
"cJSON",
"jsoncpp",
"openssl"
],
"third_party": [
"flutter",
"libuv",
"openssl",
"libxml2",
"bounds_checking_function",
"icu",
"libpng",
"zlib",
"skia",
"cJSON",
"jsoncpp",
"egl",
"opengles",
"vulkan-headers",

View File

@ -2096,17 +2096,6 @@ HWTEST_F(EglWrapperEntryTest, EglGetPlatformDisplayEXTImpl002, Level2)
ASSERT_EQ(EGL_NO_DISPLAY, result);
}
/**
* @tc.name: EglGetPlatformDisplayEXTImpl003
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(EglWrapperEntryTest, EglGetPlatformDisplayEXTImpl003, Level2)
{
auto result = gWrapperHook.wrapper.eglGetPlatformDisplayEXT(EGL_PLATFORM_OHOS_KHR, EGL_DEFAULT_DISPLAY, 0);
ASSERT_NE(EGL_NO_DISPLAY, result);
}
/**
* @tc.name: EglSwapBuffersWithDamageKHRImpl001
* @tc.desc:

View File

@ -30,7 +30,6 @@ config("local_drawing_config") {
include_dirs = [
"../drawing",
"../../../../../../../multimedia/image_framework/interfaces/innerkits/include/",
"../../../../../rosen/modules/2d_graphics/include",
"../../../../../rosen/modules/2d_graphics/src/drawing/engine_adapter",
]
@ -49,8 +48,8 @@ ohos_shared_library("drawing_napi") {
external_deps = [ "napi:ace_napi" ]
if (current_os == "ohos" || current_os == "ohos_ng") {
cflags = [ "-fstack-protector-all" ]
cflags_cc = [ "-fstack-protector-all" ]
cflags = [ "-fstack-protector-strong" ]
cflags_cc = [ "-fstack-protector-strong" ]
}
relative_install_dir = "module/graphics"

View File

@ -17,8 +17,8 @@
#include <cstdint>
#include "../js_drawing_utils.h"
#include "../color_filter_napi/js_color_filter.h"
#include "js_drawing_utils.h"
#include "color_filter_napi/js_color_filter.h"
namespace OHOS::Rosen {
namespace Drawing {

View File

@ -13,26 +13,29 @@
* limitations under the License.
*/
#include <mutex>
#include "js_canvas.h"
#include "../brush_napi/js_brush.h"
#include "../pen_napi/js_pen.h"
#include "../path_napi/js_path.h"
#include "../text_blob_napi/js_text_blob.h"
#include "../js_drawing_utils.h"
#include "native_value.h"
#include <mutex>
#ifdef ROSEN_OHOS
#include "pixel_map.h"
#include "pixel_map_napi.h"
#endif
#include "native_value.h"
#include "draw/canvas.h"
#include "image/image.h"
#include "draw/path.h"
#include "image/image.h"
#include "text/text.h"
#include "text/text_blob.h"
#include "utils/point.h"
#include "utils/sampling_options.h"
#include "utils/rect.h"
#include "utils/sampling_options.h"
#include "brush_napi/js_brush.h"
#include "pen_napi/js_pen.h"
#include "path_napi/js_path.h"
#include "text_blob_napi/js_text_blob.h"
#include "js_drawing_utils.h"
namespace OHOS::Rosen {
#ifdef ROSEN_OHOS

View File

@ -14,10 +14,11 @@
*/
#include "js_color_filter.h"
#include "../js_drawing_utils.h"
#include "native_value.h"
#include "draw/color.h"
#include "js_drawing_utils.h"
namespace OHOS::Rosen {
namespace Drawing {

View File

@ -13,15 +13,16 @@
* limitations under the License.
*/
#include "js_enum.h"
#include <map>
#include <vector>
#include "native_value.h"
#include "draw/blend_mode.h"
#include "text/font_types.h"
#include "js_enum.h"
#include "../js_drawing_utils.h"
#include "native_value.h"
#include "js_drawing_utils.h"
#ifdef WINDOWS_PLATFORM
#ifdef DIFFERENCE

View File

@ -14,10 +14,12 @@
*/
#include "js_font.h"
#include "js_typeface.h"
#include "../js_drawing_utils.h"
#include "native_value.h"
#include "js_drawing_utils.h"
#include "js_typeface.h"
namespace OHOS::Rosen {
namespace Drawing {
thread_local napi_ref JsFont::constructor_ = nullptr;

View File

@ -14,9 +14,11 @@
*/
#include "js_typeface.h"
#include "../js_drawing_utils.h"
#include "native_value.h"
#include "js_drawing_utils.h"
namespace OHOS::Rosen {
namespace Drawing {
thread_local napi_ref JsTypeface::constructor_ = nullptr;

View File

@ -14,9 +14,11 @@
*/
#include "js_path.h"
#include "../js_drawing_utils.h"
#include "native_value.h"
#include "js_drawing_utils.h"
namespace OHOS::Rosen {
namespace Drawing {
thread_local napi_ref JsPath::constructor_ = nullptr;

View File

@ -17,8 +17,8 @@
#include <cstdint>
#include "../js_drawing_utils.h"
#include "../color_filter_napi/js_color_filter.h"
#include "js_drawing_utils.h"
#include "color_filter_napi/js_color_filter.h"
namespace OHOS::Rosen {
namespace Drawing {

View File

@ -14,10 +14,12 @@
*/
#include "js_text_blob.h"
#include "../js_drawing_utils.h"
#include "native_value.h"
#include "../font_napi/js_font.h"
#include "../js_common.h"
#include "js_common.h"
#include "js_drawing_utils.h"
#include "font_napi/js_font.h"
namespace OHOS::Rosen {
namespace Drawing {

View File

@ -84,6 +84,10 @@
"name": "OH_Drawing_CanvasDrawImageRectWithSrc"
},
{ "name": "OH_Drawing_CanvasClipRect" },
{
"first_introduced": "12",
"name": "OH_Drawing_CanvasClipRoundRect"
},
{ "name": "OH_Drawing_CanvasClipPath" },
{ "name": "OH_Drawing_CanvasRotate" },
{ "name": "OH_Drawing_CanvasTranslate" },
@ -230,6 +234,10 @@
"first_introduced": "12",
"name": "OH_Drawing_PathConicTo"
},
{
"first_introduced": "12",
"name": "OH_Drawing_PathAddOval"
},
{ "name": "OH_Drawing_PathContains" },
{
"first_introduced": "12",
@ -370,6 +378,14 @@
"name": "OH_Drawing_RectSetBottom"
},
{ "name": "OH_Drawing_RoundRectCreate" },
{
"first_introduced": "12",
"name": "OH_Drawing_RoundRectGetCorner"
},
{
"first_introduced": "12",
"name": "OH_Drawing_RoundRectSetCorner"
},
{ "name": "OH_Drawing_RoundRectDestroy" },
{ "name": "OH_Drawing_SetTextStyleColor" },
{ "name": "OH_Drawing_SetTextStyleFontSize" },

View File

@ -105,6 +105,7 @@ struct TypographyStyle {
bool customTextStyle = false;
TextHeightBehavior textHeightBehavior = TextHeightBehavior::ALL;
bool hintingIsOn = false;
bool ellipsizedForNDK = false;
};
} // namespace Rosen
} // namespace OHOS

View File

@ -211,7 +211,6 @@ template("graphics2d_source_set") {
"$drawing_core_src_dir/engine_adapter",
"$ace_root/frameworks",
"$rosen_root/modules/render_service_base/include",
"//third_party/bounds_checking_function/include",
"//third_party/skia/include/core",
"//third_party/skia/include/private",
"//third_party/skia/src/core",
@ -221,7 +220,7 @@ template("graphics2d_source_set") {
"$rosen_root/../interfaces/kits/napi/graphic/drawing/common_napi",
]
configs = [ "//third_party/jsoncpp:jsoncpp_public_config" ]
external_deps += [ "jsoncpp:jsoncpp" ]
defines += [ "USE_ACE_SKIA" ]
@ -243,7 +242,6 @@ template("graphics2d_source_set") {
"$rosen_root/modules/2d_engine/rosen_text",
"$rosen_root/modules/2d_engine/rosen_text/adapter",
"$rosen_root/modules/2d_engine/rosen_text/export",
"//third_party/bounds_checking_function/include",
"$platform_dir/image_native",
]
if (defined(use_new_skia) && use_new_skia) {
@ -274,13 +272,11 @@ template("graphics2d_source_set") {
}
if (platform == "ohos" || platform == "ohos_ng") {
external_deps += [
"bounds_checking_function:libsec_static",
"hilog:libhilog",
"hitrace:hitrace_meter",
]
deps = [
"//third_party/bounds_checking_function:libsec_static",
"//third_party/skia:skia_$platform",
]
deps = [ "//third_party/skia:skia_$platform" ]
defines += [ "USE_GRAPHIC_TEXT_GINE" ]
deps += [ "$graphic_2d_root/rosen/build/icu:rosen_libicu_$platform" ]
include_dirs += [ "$flutter_root/engine" ]
@ -312,7 +308,7 @@ template("graphics2d_source_set") {
deps += [ "$rosen_root/modules/platform:hilog" ]
}
deps += [ "//third_party/bounds_checking_function:libsec_static" ]
external_deps += [ "bounds_checking_function:libsec_static" ]
deps += [ "$graphic_2d_root/utils:sandbox_utils" ]
defines += [ "MODULE_DRAWING" ]
@ -400,7 +396,7 @@ if (enable_text_gine) {
"$rosen_root/modules/texgine/texgine_drawing:libtexgine_drawing",
]
external_deps = [ "hilog:libhilog" ]
public_deps = [ "//third_party/bounds_checking_function:libsec_static" ]
public_external_deps = [ "bounds_checking_function:libsec_static" ]
defines += [ "USE_GRAPHIC_TEXT_GINE" ]
public_configs = [ ":2d_graphics_config" ]
innerapi_tags = [ "platformsdk_indirect" ]

View File

@ -102,8 +102,6 @@ template("drawing_ndk_source_set") {
"$drawing_utils_root",
"$graphic_2d_root/rosen/modules/render_service_base/include",
"$rosen_root/modules/texgine/src",
"//foundation/multimedia/image_framework/interfaces/kits/js/common/include/",
"//foundation/multimedia/image_framework/interfaces/kits/native/include/",
"//foundation/multimedia/image_framework/interfaces/innerkits/include/mdkKits/",
]
@ -117,7 +115,6 @@ template("drawing_ndk_source_set") {
"$rosen_root/modules/2d_engine/rosen_text",
"$rosen_root/modules/2d_engine/rosen_text/adapter",
"$rosen_root/modules/2d_engine/rosen_text/export",
"//third_party/bounds_checking_function/include",
]
} else {
include_dirs += [
@ -129,13 +126,13 @@ template("drawing_ndk_source_set") {
if (platform == "ohos" || platform == "ohos_ng") {
defines += [ "OHOS_PLATFORM" ]
external_deps += [
"bounds_checking_function:libsec_static",
"hilog:libhilog",
"image_framework:image_native",
"image_framework:pixelmap_ndk",
]
deps = [ "//third_party/bounds_checking_function:libsec_static" ]
deps += [ "$graphic_2d_root/rosen/build/icu:rosen_libicu_$platform" ]
deps = [ "$graphic_2d_root/rosen/build/icu:rosen_libicu_$platform" ]
include_dirs += [ "$flutter_root/engine" ]
if (enable_text_gine && use_texgine) {
@ -155,7 +152,7 @@ template("drawing_ndk_source_set") {
deps += [ "$rosen_root/modules/platform:hilog" ]
}
deps += [ "//third_party/bounds_checking_function:libsec_static" ]
external_deps += [ "bounds_checking_function:libsec_static" ]
defines += [ "MODULE_DRAWING" ]
defines += [ "USE_GRAPHIC_TEXT_GINE" ]

View File

@ -419,6 +419,20 @@ typedef enum {
void OH_Drawing_CanvasClipRect(OH_Drawing_Canvas*, const OH_Drawing_Rect*,
OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias);
/**
* @brief Clip a round rect.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
* @param OH_Drawing_RoundRect Indicates the pointer to an <b>OH_Drawing_RoundRect</b> object.
* @param clipOp Indicates the operation to apply to clip.
* @param doAntiAlias Indicates whether clip operation requires anti-aliased.
* @since 12
* @version 1.0
*/
void OH_Drawing_CanvasClipRoundRect(OH_Drawing_Canvas*, const OH_Drawing_RoundRect*,
OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias);
/**
* @brief Clip a path.
*

View File

@ -408,6 +408,18 @@ void OH_Drawing_PathAddPathWithMode(OH_Drawing_Path* path, const OH_Drawing_Path
void OH_Drawing_PathAddPathWithOffsetAndMode(OH_Drawing_Path* path, const OH_Drawing_Path* src, float dx, float dy,
OH_Drawing_PathAddMode);
/**
* @brief Adds a oval to the path, defined by the rect, and wound in the specified direction.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
* @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
* @param OH_Drawing_PathDirection Indicates the path direction.
* @since 12
* @version 1.0
*/
void OH_Drawing_PathAddOval(OH_Drawing_Path*, const OH_Drawing_Rect*, OH_Drawing_PathDirection);
/**
* @brief Return the status that point (x, y) is contained by path.
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -43,6 +43,31 @@
extern "C" {
#endif
/**
* @brief Enumerates of corner radii position.
*
* @since 12
* @version 1.0
*/
typedef enum {
/**
* Index of top-left corner radii.
*/
CORNER_POS_TOP_LEFT,
/**
* Index of top-right corner radii.
*/
CORNER_POS_TOP_RIGHT,
/**
* Index of bottom-right corner radii.
*/
CORNER_POS_BOTTOM_RIGHT,
/**
* Index of bottom-left corner radii.
*/
CORNER_POS_BOTTOM_LEFT,
} OH_Drawing_CornerPos;
/**
* @brief Creates an <b>OH_Drawing_RoundRect</b> object.
*
@ -56,6 +81,30 @@ extern "C" {
*/
OH_Drawing_RoundRect* OH_Drawing_RoundRectCreate(const OH_Drawing_Rect*, float xRad, float yRad);
/**
* @brief Sets the radiusX and radiusY for a specific corner position.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_RoundRect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
* @param pos Indicates the corner radii position.
* @param OH_Drawing_Corner_Radii Indicates the corner radii on x-axis and y-axis.
* @since 12
* @version 1.0
*/
void OH_Drawing_RoundRectSetCorner(OH_Drawing_RoundRect*, OH_Drawing_CornerPos pos, OH_Drawing_Corner_Radii radiusXY);
/**
* @brief Gets an <b>OH_Drawing_Corner_Radii</b> struct, the point is round corner radiusX and radiusY.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_RoundRect Indicates the pointer to an <b>OH_Drawing_RoundRect</b> object.
* @param pos Indicates the corner radii position.
* @return Returns the corner radii of <b>OH_Drawing_Corner_Radii</b> struct.
* @since 12
* @version 1.0
*/
OH_Drawing_Corner_Radii OH_Drawing_RoundRectGetCorner(OH_Drawing_RoundRect*, OH_Drawing_CornerPos pos);
/**
* @brief Destroys an <b>OH_Drawing_RoundRect</b> object and reclaims the memory occupied by the object.
*

View File

@ -128,6 +128,14 @@ typedef struct {
float y;
} OH_Drawing_Point2D;
/**
* @brief Defines a corner radii, which is on x-axis and y-axis.
*
* @since 12
* @version 1.0
*/
typedef OH_Drawing_Point2D OH_Drawing_Corner_Radii;
/**
* @brief Defines a point of 3d, which is used to describe the coordinate point.
*

View File

@ -512,6 +512,19 @@ void OH_Drawing_CanvasClipRect(OH_Drawing_Canvas* cCanvas, const OH_Drawing_Rect
canvas->ClipRect(CastToRect(*cRect), CClipOpCastToClipOp(cClipOp), doAntiAlias);
}
void OH_Drawing_CanvasClipRoundRect(OH_Drawing_Canvas* cCanvas, const OH_Drawing_RoundRect* cRoundRect,
OH_Drawing_CanvasClipOp cClipOp, bool doAntiAlias)
{
if (cRoundRect == nullptr) {
return;
}
Canvas* canvas = CastToCanvas(cCanvas);
if (canvas == nullptr) {
return;
}
canvas->ClipRoundRect(CastToRoundRect(*cRoundRect), CClipOpCastToClipOp(cClipOp), doAntiAlias);
}
void OH_Drawing_CanvasClipPath(OH_Drawing_Canvas* cCanvas, const OH_Drawing_Path* cPath,
OH_Drawing_CanvasClipOp cClipOp, bool doAntiAlias)
{

View File

@ -293,6 +293,18 @@ void OH_Drawing_PathAddPathWithOffsetAndMode(OH_Drawing_Path* cPath,
path->AddPath(*srcPath, dx, dy, static_cast<PathAddMode>(mode));
}
void OH_Drawing_PathAddOval(OH_Drawing_Path* cPath, const OH_Drawing_Rect* oval, OH_Drawing_PathDirection dir)
{
if (oval == nullptr) {
return;
}
Path* path = CastToPath(cPath);
if (path == nullptr) {
return;
}
path->AddOval(CastToRect(*oval), static_cast<PathDirection>(dir));
}
bool OH_Drawing_PathContains(OH_Drawing_Path* cPath, float x, float y)
{
Path* path = CastToPath(cPath);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -39,6 +39,48 @@ OH_Drawing_RoundRect* OH_Drawing_RoundRectCreate(const OH_Drawing_Rect* cRect, f
return (OH_Drawing_RoundRect*)new RoundRect(CastToRect(*cRect), xRad, yRad);
}
static RoundRect::CornerPos CCornerPosCastToCornerPos(OH_Drawing_CornerPos pos)
{
RoundRect::CornerPos roundPos = RoundRect::CornerPos::TOP_LEFT_POS;
switch (pos) {
case CORNER_POS_TOP_LEFT:
roundPos = RoundRect::CornerPos::TOP_LEFT_POS;
break;
case CORNER_POS_TOP_RIGHT:
roundPos = RoundRect::CornerPos::TOP_RIGHT_POS;
break;
case CORNER_POS_BOTTOM_RIGHT:
roundPos = RoundRect::CornerPos::BOTTOM_RIGHT_POS;
break;
case CORNER_POS_BOTTOM_LEFT:
roundPos = RoundRect::CornerPos::BOTTOM_LEFT_POS;
break;
default:
break;
}
return roundPos;
}
void OH_Drawing_RoundRectSetCorner(OH_Drawing_RoundRect* cRoundRect, OH_Drawing_CornerPos pos,
OH_Drawing_Corner_Radii radiusXY)
{
RoundRect* rounRect = CastToRoundRect(cRoundRect);
if (rounRect == nullptr) {
return;
}
rounRect->SetCornerRadius(CCornerPosCastToCornerPos(pos), radiusXY.x, radiusXY.y);
}
OH_Drawing_Corner_Radii OH_Drawing_RoundRectGetCorner(OH_Drawing_RoundRect* cRoundRect, OH_Drawing_CornerPos pos)
{
RoundRect* rounRect = CastToRoundRect(cRoundRect);
if (rounRect == nullptr) {
return {0, 0};
}
Point radiusXY = rounRect->GetCornerRadius(CCornerPosCastToCornerPos(pos));
return {radiusXY.GetX(), radiusXY.GetY()};
}
void OH_Drawing_RoundRectDestroy(OH_Drawing_RoundRect* cRoundRect)
{
delete CastToRoundRect(cRoundRect);

View File

@ -1061,6 +1061,14 @@ void OH_Drawing_SetTypographyTextEllipsisModal(OH_Drawing_TypographyStyle* style
#else
ConvertToOriginalText<TypographyStyle>(style)->ellipsisModal = rosenEllipsisModal;
#endif
if (!ConvertToOriginalText<TypographyStyle>(style)->ellipsizedForNDK) {
#ifndef USE_GRAPHIC_TEXT_GINE
ConvertToOriginalText<TypographyStyle>(style)->ellipsis_ = TypographyStyle::ELLIPSIS;
#else
ConvertToOriginalText<TypographyStyle>(style)->ellipsis = TypographyStyle::ELLIPSIS;
#endif
ConvertToOriginalText<TypographyStyle>(style)->ellipsizedForNDK = true;
}
}
double OH_Drawing_TypographyGetLineHeight(OH_Drawing_Typography* typography, int lineNumber)
@ -1813,6 +1821,7 @@ void OH_Drawing_SetTypographyTextEllipsis(OH_Drawing_TypographyStyle* style, con
#else
ConvertToOriginalText<TypographyStyle>(style)->ellipsis = u16Ellipsis;
#endif
ConvertToOriginalText<TypographyStyle>(style)->ellipsizedForNDK = true;
}
void OH_Drawing_TextStyleSetBackgroundRect(OH_Drawing_TextStyle* style, const OH_Drawing_RectStyle_Info* rectStyleInfo,

View File

@ -31,8 +31,8 @@ class DRAWING_API Bitmap {
public:
Bitmap();
virtual ~Bitmap();
void Build(int32_t width, int32_t height, const BitmapFormat& format, int32_t stride = 0);
void Build(const ImageInfo& imageInfo, int32_t stride = 0);
bool Build(int32_t width, int32_t height, const BitmapFormat& format, int32_t stride = 0);
bool Build(const ImageInfo& imageInfo, int32_t stride = 0);
/**
* @brief Gets the width of Bitmap.

View File

@ -24,7 +24,7 @@
namespace OHOS {
namespace Rosen {
namespace Drawing {
class BaseImpl : public std::enable_shared_from_this<BaseImpl> {
class BaseImpl {
public:
BaseImpl() noexcept {}
virtual ~BaseImpl() {}

View File

@ -34,8 +34,8 @@ public:
BitmapImpl() {}
~BitmapImpl() override {}
virtual void Build(int32_t width, int32_t height, const BitmapFormat& format, int32_t stride = 0) = 0;
virtual void Build(const ImageInfo& imageInfo, int32_t stride = 0) = 0;
virtual bool Build(int32_t width, int32_t height, const BitmapFormat& format, int32_t stride = 0) = 0;
virtual bool Build(const ImageInfo& imageInfo, int32_t stride = 0) = 0;
virtual int GetWidth() const = 0;
virtual int GetHeight() const = 0;
virtual int GetRowBytes() const = 0;

View File

@ -28,6 +28,8 @@
#include "src/core/SkReadBuffer.h"
#include "src/core/SkWriteBuffer.h"
#include "utils/data.h"
#include "utils/log.h"
namespace OHOS {
namespace Rosen {
namespace Drawing {
@ -41,18 +43,26 @@ static inline SkImageInfo MakeSkImageInfo(const int width, const int height, con
return imageInfo;
}
void SkiaBitmap::Build(int32_t width, int32_t height, const BitmapFormat& format, int32_t stride)
bool SkiaBitmap::Build(int32_t width, int32_t height, const BitmapFormat& format, int32_t stride)
{
auto imageInfo = MakeSkImageInfo(width, height, format);
skiaBitmap_.setInfo(imageInfo, stride);
skiaBitmap_.allocPixels();
bool isBuildSuccess = skiaBitmap_.setInfo(imageInfo, stride) && skiaBitmap_.tryAllocPixels();
if (!isBuildSuccess) {
LOGE("SkiaBitmap::Build failed, the format is incorrect");
return false;
}
return true;
}
void SkiaBitmap::Build(const ImageInfo& imageInfo, int32_t stride)
bool SkiaBitmap::Build(const ImageInfo& imageInfo, int32_t stride)
{
auto skImageInfo = SkiaImageInfo::ConvertToSkImageInfo(imageInfo);
skiaBitmap_.setInfo(skImageInfo, stride);
skiaBitmap_.allocPixels();
bool isBuildSuccess = skiaBitmap_.setInfo(skImageInfo, stride) && skiaBitmap_.tryAllocPixels();
if (!isBuildSuccess) {
LOGE("SkiaBitmap::Build failed, the format is incorrect");
return false;
}
return true;
}
int SkiaBitmap::GetWidth() const

View File

@ -35,8 +35,8 @@ public:
return AdapterType::SKIA_ADAPTER;
}
void Build(int32_t width, int32_t height, const BitmapFormat& format, int32_t stride) override;
void Build(const ImageInfo& imageInfo, int32_t stride) override;
bool Build(int32_t width, int32_t height, const BitmapFormat& format, int32_t stride) override;
bool Build(const ImageInfo& imageInfo, int32_t stride) override;
int GetWidth() const override;
int GetHeight() const override;
int GetRowBytes() const override;

View File

@ -41,10 +41,10 @@ void SkiaRuntimeEffect::GlslToSksl(std::string& sksl, std::string& glsl)
searchStart = match.suffix().first;
}
for (auto& childName : childNames) {
std::string pattern(childName + R"(\((.*?)\))");
for (const auto& childName : childNames) {
std::string patternStr(childName + R"(\((.*?)\))");
std::string replacement = childName + ".eval($1)";
fixup(pattern.c_str(), replacement.c_str());
fixup(patternStr.c_str(), replacement.c_str());
}
// change "uniform sampler2D inputTexture" to "uniform shader inputTexture"
fixup(R"(\buniform\s+sampler2D\b)", "uniform shader ");

View File

@ -26,14 +26,14 @@ Bitmap::Bitmap()
Bitmap::~Bitmap() {}
void Bitmap::Build(int32_t width, int32_t height, const BitmapFormat& format, int32_t stride)
bool Bitmap::Build(int32_t width, int32_t height, const BitmapFormat& format, int32_t stride)
{
bmpImplPtr->Build(width, height, format, stride);
return bmpImplPtr->Build(width, height, format, stride);
}
void Bitmap::Build(const ImageInfo& imageInfo, int32_t stride)
bool Bitmap::Build(const ImageInfo& imageInfo, int32_t stride)
{
bmpImplPtr->Build(imageInfo, stride);
return bmpImplPtr->Build(imageInfo, stride);
}
int Bitmap::GetWidth() const

View File

@ -85,6 +85,9 @@ public:
const std::vector<GraphicHDRMetaData> &graphicMetaData) = 0;
virtual int32_t SetLayerMetaDataSet(uint32_t screenId, uint32_t layerId, GraphicHDRMetadataKey gkey,
const std::vector<uint8_t> &metaData) = 0;
virtual int32_t GetSupportedLayerPerFrameParameterKey(std::vector<std::string>& keys) = 0;
virtual int32_t SetLayerPerFrameParameter(uint32_t devId, uint32_t layerId, const std::string& key,
const std::vector<int8_t>& value) = 0;
virtual int32_t SetLayerTunnelHandle(uint32_t screenId, uint32_t layerId, GraphicExtDataHandle *handle) = 0;
virtual int32_t GetSupportedPresentTimestampType(uint32_t screenId, uint32_t layerId,
GraphicPresentTimestampType &type) = 0;

View File

@ -83,6 +83,9 @@ public:
const std::vector<GraphicHDRMetaData> &metaData) override;
int32_t SetLayerMetaDataSet(uint32_t screenId, uint32_t layerId, GraphicHDRMetadataKey key,
const std::vector<uint8_t> &metaData) override;
int32_t GetSupportedLayerPerFrameParameterKey(std::vector<std::string>& keys) override;
int32_t SetLayerPerFrameParameter(uint32_t devId, uint32_t layerId, const std::string& key,
const std::vector<int8_t>& value) override;
int32_t SetLayerTunnelHandle(uint32_t screenId, uint32_t layerId, GraphicExtDataHandle *handle) override;
int32_t GetSupportedPresentTimestampType(uint32_t screenId, uint32_t layerId,
GraphicPresentTimestampType &type) override;

View File

@ -130,6 +130,9 @@ private:
inline bool CheckFbSurface();
bool CheckAndUpdateClientBufferCahce(sptr<SurfaceBuffer> buffer, uint32_t& index);
static void SetBufferColorSpace(sptr<SurfaceBuffer>& buffer, const std::vector<LayerPtr>& layers);
// DISPLAY ENGINE
bool CheckIfDoArsrPre(const LayerInfoPtr &layerInfo);
};
} // namespace Rosen
} // namespace OHOS

View File

@ -576,6 +576,19 @@ int32_t HdiDeviceImpl::SetLayerMetaDataSet(uint32_t screenId, uint32_t layerId,
return g_composer->SetLayerMetaDataSet(screenId, layerId, hdiKey, metaData);
}
int32_t HdiDeviceImpl::GetSupportedLayerPerFrameParameterKey(std::vector<std::string>& keys)
{
CHECK_FUNC(g_composer);
return g_composer->GetSupportedLayerPerFrameParameterKey(keys);
}
int32_t HdiDeviceImpl::SetLayerPerFrameParameter(uint32_t devId, uint32_t layerId, const std::string& key,
const std::vector<int8_t>& value)
{
CHECK_FUNC(g_composer);
return g_composer->SetLayerPerFrameParameter(devId, layerId, key, value);
}
int32_t HdiDeviceImpl::SetLayerTunnelHandle(uint32_t screenId, uint32_t layerId, GraphicExtDataHandle *handle)
{
CHECK_FUNC(g_composer);

View File

@ -15,6 +15,7 @@
#include <cstdint>
#include <scoped_bytrace.h>
#include <unordered_set>
#include "rs_trace.h"
#include "hdi_output.h"
#include "metadata_helper.h"
@ -186,6 +187,26 @@ int32_t HdiOutput::CreateLayer(uint64_t surfaceId, const LayerInfoPtr &layerInfo
}
surfaceIdMap_[surfaceId] = layer;
// DISPLAY ENGINE
uint32_t ret = 0;
std::vector<std::string> validKeys{};
ret = device_->GetSupportedLayerPerFrameParameterKey(validKeys);
if (ret != 0) {
HLOGD("GetSupportedLayerPreFrameParameter Fail! ret = %{public}d", ret);
return GRAPHIC_DISPLAY_SUCCESS;
}
const std::string GENERIC_METADATA_KEY_ARSR_PRE_NEEDED = "ArsrDoEnhance";
if (std::find(validKeys.begin(), validKeys.end(), GENERIC_METADATA_KEY_ARSR_PRE_NEEDED) != validKeys.end()) {
if (CheckIfDoArsrPre(layerInfo)) {
const std::vector<int8_t> valueBlob{static_cast<int8_t>(1)};
ret = device_->SetLayerPerFrameParameter(screenId_, layerId,
GENERIC_METADATA_KEY_ARSR_PRE_NEEDED, valueBlob);
}
if (ret != 0) {
HLOGD("SetLayerPerFrameParameter Fail! ret = %{public}d", ret);
}
}
return GRAPHIC_DISPLAY_SUCCESS;
}
@ -426,6 +447,38 @@ void HdiOutput::SetBufferColorSpace(sptr<SurfaceBuffer>& buffer, const std::vect
}
}
// DISPLAY ENGINE
bool HdiOutput::CheckIfDoArsrPre(const LayerInfoPtr &layerInfo)
{
static const std::unordered_set<GraphicPixelFormat> yuvFormats {
GRAPHIC_PIXEL_FMT_YUV_422_I,
GRAPHIC_PIXEL_FMT_YCBCR_422_SP,
GRAPHIC_PIXEL_FMT_YCRCB_422_SP,
GRAPHIC_PIXEL_FMT_YCBCR_420_SP,
GRAPHIC_PIXEL_FMT_YCRCB_420_SP,
GRAPHIC_PIXEL_FMT_YCBCR_422_P,
GRAPHIC_PIXEL_FMT_YCRCB_422_P,
GRAPHIC_PIXEL_FMT_YCBCR_420_P,
GRAPHIC_PIXEL_FMT_YCRCB_420_P,
GRAPHIC_PIXEL_FMT_YUYV_422_PKG,
GRAPHIC_PIXEL_FMT_UYVY_422_PKG,
GRAPHIC_PIXEL_FMT_YVYU_422_PKG,
GRAPHIC_PIXEL_FMT_VYUY_422_PKG,
};
static const std::unordered_set<std::string> videoLayers {
"xcomponentIdSurface",
"componentIdSurface",
};
if ((yuvFormats.count(static_cast<GraphicPixelFormat>(layerInfo->GetBuffer()->GetFormat())) > 0) ||
(videoLayers.count(layerInfo->GetSurface()->GetName()) > 0)) {
return true;
}
return false;
}
int32_t HdiOutput::FlushScreen(std::vector<LayerPtr> &compClientLayers)
{
auto fbEntry = GetFramebuffer();

View File

@ -70,6 +70,13 @@ namespace OHOS {
device->SetLayerTunnelHandle(screenId, layerId, nullptr);
device->GetPresentTimestamp(screenId, layerId, timestamp);
device->SetLayerMaskInfo(screenId, layerId, maskInfo);
// DISPLAY ENGINE
std::vector<std::string> keys{};
device->GetSupportedLayerPerFrameParameterKey(keys);
std::vector<int8_t> valueBlob{static_cast<int8_t>(1)};
std::string validKey = "ArsrDoEnhance";
device->SetLayerPerFrameParameter(screenId, layerId, validKey, valueBlob);
}
void HdiDeviceFuzzTest2()

View File

@ -80,6 +80,9 @@ public:
MOCK_METHOD3(GetLayerColorDataSpace, int32_t(uint32_t, uint32_t, GraphicColorDataSpace&));
MOCK_METHOD3(SetLayerMetaData, int32_t(uint32_t, uint32_t, const std::vector<GraphicHDRMetaData>&));
MOCK_METHOD4(SetLayerMetaDataSet, int32_t(uint32_t, uint32_t, GraphicHDRMetadataKey, const std::vector<uint8_t>&));
MOCK_METHOD1(GetSupportedLayerPerFrameParameterKey, int32_t(std::vector<std::string>&));
MOCK_METHOD4(SetLayerPerFrameParameter,
int32_t(uint32_t, uint32_t, const std::string&, const std::vector<int8_t>&));
MOCK_METHOD3(SetLayerTunnelHandle, int32_t(uint32_t, uint32_t, GraphicExtDataHandle *));
MOCK_METHOD3(GetSupportedPresentTimestampType, int32_t(uint32_t, uint32_t, GraphicPresentTimestampType&));
MOCK_METHOD3(GetPresentTimestamp, int32_t(uint32_t, uint32_t, GraphicPresentTimestamp&));

View File

@ -194,6 +194,12 @@ HWTEST_F(HdiDeviceTest, LayerFuncs002, Function | MediumTest| Level3)
GRAPHIC_DISPLAY_NOT_SUPPORT);
uint32_t layerMask = 0;
ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerMaskInfo(screenId, layerId, layerMask), GRAPHIC_DISPLAY_SUCCESS);
std::vector<std::string> keys;
ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetSupportedLayerPerFrameParameterKey(keys), GRAPHIC_DISPLAY_SUCCESS);
const std::vector<int8_t> valueBlob{static_cast<int8_t>(1)};
const std::string validKey = "ArsrDoEnhance";
ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerPerFrameParameter(screenId, layerId, validKey, valueBlob),
GRAPHIC_DISPLAY_SUCCESS);
GraphicLayerInfo layerInfo;
uint32_t cacheCount = 1;
ASSERT_EQ(HdiDeviceTest::hdiDevice_->CreateLayer(screenId, layerInfo, cacheCount, layerId),

View File

@ -78,6 +78,8 @@ void HdiLayerTest::SetUpTestCase()
EXPECT_CALL(*hdiDeviceMock_, GetLayerColorDataSpace(_, _, _)).WillRepeatedly(testing::Return(0));
EXPECT_CALL(*hdiDeviceMock_, SetLayerMetaData(_, _, _)).WillRepeatedly(testing::Return(0));
EXPECT_CALL(*hdiDeviceMock_, SetLayerMetaDataSet(_, _, _, _)).WillRepeatedly(testing::Return(0));
EXPECT_CALL(*hdiDeviceMock_, GetSupportedLayerPerFrameParameterKey(_)).WillRepeatedly(testing::Return(0));
EXPECT_CALL(*hdiDeviceMock_, SetLayerPerFrameParameter(_, _, _, _)).WillRepeatedly(testing::Return(0));
EXPECT_CALL(*hdiDeviceMock_, SetLayerTunnelHandle(_, _, _)).WillRepeatedly(testing::Return(0));
EXPECT_CALL(*hdiDeviceMock_, GetSupportedPresentTimestampType(_, _, _)).WillRepeatedly(testing::Return(0));
EXPECT_CALL(*hdiDeviceMock_, GetPresentTimestamp(_, _, _)).WillRepeatedly(testing::Return(0));

View File

@ -79,6 +79,9 @@ public:
MOCK_METHOD3(GetLayerColorDataSpace, int32_t(uint32_t, uint32_t, GraphicColorDataSpace&));
MOCK_METHOD3(SetLayerMetaData, int32_t(uint32_t, uint32_t, const std::vector<GraphicHDRMetaData>&));
MOCK_METHOD4(SetLayerMetaDataSet, int32_t(uint32_t, uint32_t, GraphicHDRMetadataKey, const std::vector<uint8_t>&));
MOCK_METHOD1(GetSupportedLayerPerFrameParameterKey, int32_t(std::vector<std::string>&));
MOCK_METHOD4(SetLayerPerFrameParameter,
int32_t(uint32_t, uint32_t, const std::string&, const std::vector<int8_t>&));
MOCK_METHOD3(SetLayerTunnelHandle, int32_t(uint32_t, uint32_t, GraphicExtDataHandle *));
MOCK_METHOD3(GetSupportedPresentTimestampType, int32_t(uint32_t, uint32_t, GraphicPresentTimestampType&));
MOCK_METHOD3(GetPresentTimestamp, int32_t(uint32_t, uint32_t, GraphicPresentTimestamp&));

View File

@ -117,8 +117,7 @@ public:
// used by DVSync
bool IsDVsyncOn();
void MarkRSNotRendering();
void UnmarkRSNotRendering();
void SetFrameIsRender(bool isRender);
void MarkRSAnimate();
void UnmarkRSAnimate();
bool HasPendingUIRNV();
@ -174,6 +173,8 @@ private:
sptr<DVsync> dvsync_ = nullptr;
bool pendingRNVInVsync_ = false; // for vsync switch to dvsync
std::atomic<int64_t> lastDVsyncTS_ = 0; // for dvsync switch to vsync
bool pendingRNVInDVsync_ = false;
bool lockExecute_ = false;
#endif
bool isRs_ = false;
};

View File

@ -342,6 +342,7 @@ void VSyncDistributor::WaitForVsyncOrRequest(std::unique_lock<std::mutex> &locke
ScopedBytrace func(name_ + "_EnableVsync");
EnableVSync();
}
lockExecute_ = true;
}
}
#endif
@ -418,12 +419,16 @@ void VSyncDistributor::ThreadMain()
#if defined(RS_ENABLE_DVSYNC)
// ensure the preexecution only gets ahead for at most one period(i.e., 3 buffer rotation)
if (IsDVsyncOn()) {
int64_t periodBeforeDelay = 0L;
int64_t periodAfterDelay = 0L;
{
std::unique_lock<std::mutex> locker(mutex_);
periodBeforeDelay = event_.period;
dvsync_->MarkDistributorSleep(true);
dvsync_->RNVNotify();
dvsync_->DelayBeforePostEvent(timestamp, locker);
dvsync_->MarkDistributorSleep(false);
periodAfterDelay = event_.period;
}
// if getting switched into vsync mode after sleep
if (!IsDVsyncOn()) {
@ -433,11 +438,15 @@ void VSyncDistributor::ThreadMain()
RequestNextVSync(conn);
} // resend RNV for vsync
continue; // do not accumulate frame;
} else if (std::abs(periodAfterDelay - periodBeforeDelay) > MAX_PERIOD_BIAS) {
timestamp = timestamp + periodAfterDelay - periodBeforeDelay;
dvsync_->SetLastVirtualVSyncTS(timestamp);
}
}
{
std::unique_lock<std::mutex> locker(mutex_);
pendingRNVInVsync_ = false;
pendingRNVInDVsync_ = false;
}
#endif
PostVSyncEvent(conns, timestamp);
@ -674,7 +683,20 @@ VsyncError VSyncDistributor::RequestNextVSync(const sptr<VSyncConnection> &conne
connection->rate_ = 0;
}
connection->triggerThisTime_ = true;
#if defined(RS_ENABLE_DVSYNC)
if (IsDVsyncOn()) {
if (!lockExecute_) {
con_.notify_all();
} else {
pendingRNVInDVsync_ = true;
dvsync_->RNVNotify();
}
} else {
con_.notify_all();
}
#else
con_.notify_all();
#endif
VLOGD("conn name:%{public}s, rate:%{public}d", connection->info_.name_.c_str(), connection->rate_);
return VSYNC_ERROR_OK;
}
@ -847,17 +869,21 @@ bool VSyncDistributor::IsDVsyncOn()
#endif
}
void VSyncDistributor::MarkRSNotRendering()
void VSyncDistributor::SetFrameIsRender(bool isRender)
{
#if defined(RS_ENABLE_DVSYNC)
dvsync_->MarkRSNotRendering();
#endif
}
void VSyncDistributor::UnmarkRSNotRendering()
{
#if defined(RS_ENABLE_DVSYNC)
dvsync_->UnMarkRSNotRendering();
std::unique_lock<std::mutex> locker(mutex_);
ScopedBytrace trace("VSyncDistributor::SetFrameIsRender");
if (isRender) {
dvsync_->UnMarkRSNotRendering();
} else {
dvsync_->MarkRSNotRendering();
}
lockExecute_ = false;
if (IsDVsyncOn() && pendingRNVInDVsync_) {
ScopedBytrace func("pendingRNVInDVsync_ is true, notify");
con_.notify_all();
}
#endif
}

View File

@ -269,27 +269,27 @@ HWTEST_F(VSyncDistributorTest, GetVSyncConnectionInfos001, Function | MediumTest
}
/*
* Function: MarkRSNotRendering001
* Function: SetFrameIsRender001
* Type: Function
* Rank: Important(2)
* EnvConditions: N/A
* CaseDescription: 1. call MarkRSNotRendering
* CaseDescription: 1. call SetFrameIsRender with render is true
*/
HWTEST_F(VSyncDistributorTest, MarkRSNotRendering001, Function | MediumTest| Level3)
HWTEST_F(VSyncDistributorTest, SetFrameIsRender001, Function | MediumTest| Level3)
{
VSyncDistributorTest::vsyncDistributor->MarkRSNotRendering();
VSyncDistributorTest::vsyncDistributor->SetFrameIsRender(true);
}
/*
* Function: UnmarkRSNotRendering001
* Function: SetFrameIsRender002
* Type: Function
* Rank: Important(2)
* EnvConditions: N/A
* CaseDescription: 1. call UnmarkRSNotRendering
* CaseDescription: 1. call SetFrameIsRender with render is false
*/
HWTEST_F(VSyncDistributorTest, UnmarkRSNotRendering001, Function | MediumTest| Level3)
HWTEST_F(VSyncDistributorTest, SetFrameIsRender002, Function | MediumTest| Level3)
{
VSyncDistributorTest::vsyncDistributor->UnmarkRSNotRendering();
VSyncDistributorTest::vsyncDistributor->SetFrameIsRender(false);
}
} // namespace
} // namespace Rosen

View File

@ -44,6 +44,7 @@ ohos_unittest("EffectTest") {
"program_unittest.cpp",
"saturation_filter_unittest.cpp",
"scale_filter_unittest.cpp",
"sk_image_filter_factory_unittest.cpp",
"vertical_blur_filter_unittest.cpp",
]
}
@ -53,6 +54,7 @@ ohos_unittest("EffectTest") {
"$graphic_2d_root/rosen/modules/effect/color_picker:color_picker",
"$graphic_2d_root/rosen/modules/effect/effectChain:libeffectchain",
"$graphic_2d_root/rosen/modules/effect/egl:libegl_effect",
"$graphic_2d_root/rosen/modules/effect/skia_effectChain:skeffectchain",
"$graphic_2d_root/utils/color_manager:color_manager",
"//foundation/multimedia/image_framework/interfaces/innerkits:image_native",
"//foundation/multimedia/image_framework/interfaces/kits/js/common:image",

View File

@ -0,0 +1,317 @@
/*
* Copyright (c) 2024 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 "sk_image_filter_factory_unittest.h"
#include "sk_image_filter_factory.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
/**
* @tc.name: BlurTest001
* @tc.desc: create a blur filter
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(SKImageFilterFactoryUnittest, BlurTest001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SKImageFilterFactoryUnittest BlurTest001 start";
// 0.5 blur radius for test
auto filter = Rosen::SKImageFilterFactory::Blur(0.5);
EXPECT_TRUE(filter != nullptr);
}
/**
* @tc.name: BlurTest002
* @tc.desc: create a blur filter
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(SKImageFilterFactoryUnittest, BlurTest002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SKImageFilterFactoryUnittest BlurTest002 start";
// 0 blur radius for test
auto filter = Rosen::SKImageFilterFactory::Blur(0);
EXPECT_TRUE(filter == nullptr);
}
/**
* @tc.name: BrightnessTest001
* @tc.desc: create a brightness filter
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(SKImageFilterFactoryUnittest, BrightnessTest001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SKImageFilterFactoryUnittest BrightnessTest001 start";
// 0.5 brightness for test
auto filter = Rosen::SKImageFilterFactory::Brightness(0.5);
EXPECT_TRUE(filter != nullptr);
}
/**
* @tc.name: BrightnessTest002
* @tc.desc: create a brightness filter
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(SKImageFilterFactoryUnittest, BrightnessTest002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SKImageFilterFactoryUnittest BrightnessTest002 start";
// -1 brightness for test
auto filter = Rosen::SKImageFilterFactory::Brightness(-1);
EXPECT_TRUE(filter != nullptr);
}
/**
* @tc.name: GrayscaleTest001
* @tc.desc: create a grayscale filter
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(SKImageFilterFactoryUnittest, GrayscaleTest001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SKImageFilterFactoryUnittest GrayscaleTest001 start";
auto filter = Rosen::SKImageFilterFactory::Grayscale();
EXPECT_TRUE(filter != nullptr);
}
/**
* @tc.name: InvertTest001
* @tc.desc: create a invert filter
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(SKImageFilterFactoryUnittest, InvertTest001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SKImageFilterFactoryUnittest InvertTest001 start";
auto filter = Rosen::SKImageFilterFactory::Invert();
EXPECT_TRUE(filter != nullptr);
}
/**
* @tc.name: ApplyColorMatrixTest001
* @tc.desc: create a custom filter with a default matrix
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(SKImageFilterFactoryUnittest, ApplyColorMatrixTest001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SKImageFilterFactoryUnittest ApplyColorMatrixTest001 start";
struct PixelColorMatrix matrix;
auto filter = Rosen::SKImageFilterFactory::ApplyColorMatrix(matrix);
EXPECT_TRUE(filter != nullptr);
}
/**
* @tc.name: ApplyColorMatrixTest002
* @tc.desc: create a filter with a grayscale matrix
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(SKImageFilterFactoryUnittest, ApplyColorMatrixTest002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SKImageFilterFactoryUnittest ApplyColorMatrixTest002 start";
struct PixelColorMatrix colorMatrix;
// grayscale matrix
// [0.2126, 0.7152, 0.0722, 0, 0, 0.2126, 0.7152, 0.0722, 0, 0, 0.2126, 0.7152, 0.0722, 0, 0, 0, 0, 0, 1, 0]
// for test
float matrix[colorMatrix.MATRIX_SIZE] = {
0.2126, 0.7152, 0.0722, 0, 0,
0.2126, 0.7152, 0.0722, 0, 0,
0.2126, 0.7152, 0.0722, 0, 0,
0, 0, 0, 1, 0
};
for (int i = 0; i < colorMatrix.MATRIX_SIZE; ++i) {
colorMatrix.val[i] = matrix[i];
}
auto filter = Rosen::SKImageFilterFactory::ApplyColorMatrix(colorMatrix);
EXPECT_TRUE(filter != nullptr);
}
/**
* @tc.name: ApplyColorMatrixTest003
* @tc.desc: create a filter with a brightness matrix
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(SKImageFilterFactoryUnittest, ApplyColorMatrixTest003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SKImageFilterFactoryUnittest ApplyColorMatrixTest003 start";
// 0.5 for test
float degree = 0.5;
struct PixelColorMatrix colorMatrix;
// brightness matrix for test
float matrix[colorMatrix.MATRIX_SIZE] = {
1, 0, 0, 0, degree,
0, 1, 0, 0, degree,
0, 0, 1, 0, degree,
0, 0, 0, 1, 0
};
for (int i = 0; i < colorMatrix.MATRIX_SIZE; ++i) {
colorMatrix.val[i] = matrix[i];
}
auto filter = Rosen::SKImageFilterFactory::ApplyColorMatrix(colorMatrix);
EXPECT_TRUE(filter != nullptr);
}
/**
* @tc.name: ApplyColorMatrixTest004
* @tc.desc: create a filter with a brightness matrix
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(SKImageFilterFactoryUnittest, ApplyColorMatrixTest004, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SKImageFilterFactoryUnittest ApplyColorMatrixTest004 start";
// -1.0 for test
float degree = -1.0;
struct PixelColorMatrix colorMatrix;
// brightness matrix for test
float matrix[colorMatrix.MATRIX_SIZE] = {
1, 0, 0, 0, degree,
0, 1, 0, 0, degree,
0, 0, 1, 0, degree,
0, 0, 0, 1, 0
};
for (int i = 0; i < colorMatrix.MATRIX_SIZE; ++i) {
colorMatrix.val[i] = matrix[i];
}
auto filter = Rosen::SKImageFilterFactory::ApplyColorMatrix(colorMatrix);
EXPECT_TRUE(filter != nullptr);
}
/**
* @tc.name: ApplyColorMatrixTest005
* @tc.desc: create a filter with a brightness matrix
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(SKImageFilterFactoryUnittest, ApplyColorMatrixTest005, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SKImageFilterFactoryUnittest ApplyColorMatrixTest005 start";
// 1.0 for test
float degree = 1.0;
struct PixelColorMatrix colorMatrix;
// brightness matrix for test
float matrix[colorMatrix.MATRIX_SIZE] = {
1, 0, 0, 0, degree,
0, 1, 0, 0, degree,
0, 0, 1, 0, degree,
0, 0, 0, 1, 0
};
for (int i = 0; i < colorMatrix.MATRIX_SIZE; ++i) {
colorMatrix.val[i] = matrix[i];
}
auto filter = Rosen::SKImageFilterFactory::ApplyColorMatrix(colorMatrix);
EXPECT_TRUE(filter != nullptr);
}
/**
* @tc.name: ApplyColorMatrixTest006
* @tc.desc: create a filter with a invert matrix
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(SKImageFilterFactoryUnittest, ApplyColorMatrixTest006, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SKImageFilterFactoryUnittest ApplyColorMatrixTest006 start";
struct PixelColorMatrix colorMatrix;
// invert matrix
// [-1.0, 0, 0, 0, 1, 0, -1.0, 0, 0, 1, 0, 0, -1.0, 0, 1, 0, 0, 0, 1, 0]
// for test
float matrix[colorMatrix.MATRIX_SIZE] = {
-1.0, 0, 0, 0, 1,
0, -1.0, 0, 0, 1,
0, 0, -1.0, 0, 1,
0, 0, 0, 1, 0
};
for (int i = 0; i < colorMatrix.MATRIX_SIZE; ++i) {
colorMatrix.val[i] = matrix[i];
}
auto filter = Rosen::SKImageFilterFactory::ApplyColorMatrix(colorMatrix);
EXPECT_TRUE(filter != nullptr);
}
/**
* @tc.name: ApplyColorMatrixTest007
* @tc.desc: create a filter with a increase matrix
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(SKImageFilterFactoryUnittest, ApplyColorMatrixTest007, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SKImageFilterFactoryUnittest ApplyColorMatrixTest007 start";
struct PixelColorMatrix colorMatrix;
// increase matrix
// [1.5, 0, 0, 0, -0.25, 0, 1.5, 0, 0, -0.25, 0, 0, 1.5, 0, -0.25, 0, 0, 0, 1, 0]
// for test
float matrix[colorMatrix.MATRIX_SIZE] = {
1.5, 0, 0, 0, -0.25,
0, 1.5, 0, 0, -0.25,
0, 0, 1.5, 0, -0.25,
0, 0, 0, 1, 0
};
for (int i = 0; i < colorMatrix.MATRIX_SIZE; ++i) {
colorMatrix.val[i] = matrix[i];
}
auto filter = Rosen::SKImageFilterFactory::ApplyColorMatrix(colorMatrix);
EXPECT_TRUE(filter != nullptr);
}
/**
* @tc.name: ApplyColorMatrixTest008
* @tc.desc: create a filter with a decrease matrix
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(SKImageFilterFactoryUnittest, ApplyColorMatrixTest008, TestSize.Level1)
{
GTEST_LOG_(INFO) << "SKImageFilterFactoryUnittest ApplyColorMatrixTest008 start";
struct PixelColorMatrix colorMatrix;
// decrease matrix
// [0.6065, 0.3575, 0.036, 0, 0, 0.1065, 0.8575, 0.036, 0, 0, 0.1065, 0.3575, 0.536, 0, 0, 0, 0, 0, 1, 0]
// for test
float matrix[colorMatrix.MATRIX_SIZE] = {
0.6065, 0.3575, 0.036, 0, 0,
0.1065, 0.8575, 0.036, 0, 0,
0.1065, 0.3575, 0.536, 0, 0,
0, 0, 0, 1, 0
};
for (int i = 0; i < colorMatrix.MATRIX_SIZE; ++i) {
colorMatrix.val[i] = matrix[i];
}
auto filter = Rosen::SKImageFilterFactory::ApplyColorMatrix(colorMatrix);
EXPECT_TRUE(filter != nullptr);
}
} // namespace Rosen
} // namespace OHOS

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2024 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 SK_IMAGE_FILTER_FACTORY_UNITTEST_H
#define SK_IMAGE_FILTER_FACTORY_UNITTEST_H
#include <gtest/gtest.h>
namespace OHOS {
namespace Rosen {
class SKImageFilterFactoryUnittest : public testing::Test {
public:
static void SetUpTestCase() {};
static void TearDownTestCase() {};
void SetUp() override {};
void TearDown() override {};
};
} // namespace Rosen
} // namespace OHOS
#endif // SK_IMAGE_FILTER_FACTORY_UNITTEST_H

View File

@ -158,6 +158,11 @@ void HgmFrameRateManager::UniProcessDataForLtpo(uint64_t timestamp,
FrameRateReport();
}
}
if (isDvsyncOn) {
pendingRefreshRate_ = std::make_shared<uint32_t>(currRefreshRate_);
}
ReportHiSysEvent(frameRateVoteInfo);
}

View File

@ -27,9 +27,9 @@ ohos_source_set("render_frame_trace") {
cflags += [ "-fwhole-program-vtables" ]
}
}
deps = [ "//third_party/jsoncpp:jsoncpp" ]
external_deps = [ "jsoncpp:jsoncpp" ]
if (!build_ohos_sdk) {
external_deps = [
external_deps += [
"ipc:ipc_single",
"qos_manager:concurrent_task_client",
]

View File

@ -349,6 +349,11 @@ ohos_executable("render_service") {
cfi = true
cfi_cross_dso = true
debug = false
if (rosen_is_ohos) {
boundary_sanitize = true
integer_overflow = true
ubsan = true
}
}
sources = [ "core/main.cpp" ]

View File

@ -65,6 +65,7 @@ void RSRcdRenderManager::DoProcessRenderTask(const RcdProcessInfo& info)
RS_TRACE_BEGIN("RSUniRender:DoRCDProcessTask");
if (!IsRcdProcessInfoValid(info)) {
RS_LOGE("RCD: RcdProcessInfo is incorrect");
RS_TRACE_END();
return;
}
auto visitor = std::make_shared<RSRcdRenderVisitor>();

View File

@ -381,6 +381,7 @@ void RoundCornerDisplay::DrawOneRoundCorner(RSPaintFilterCanvas* canvas, int sur
std::lock_guard<std::mutex> lock(resourceMut_);
if (canvas == nullptr) {
RS_LOGE("[%{public}s] Canvas is null \n", __func__);
RS_TRACE_END();
return;
}
UpdateParameter(updateFlag_);

View File

@ -298,6 +298,10 @@ void RSMainThread::Init()
Render();
RS_PROFILER_ON_RENDER_END();
if (!hasMark_) {
SetFrameIsRender(true);
}
hasMark_ = false;
// move rnv after mark rsnotrendering
if (needRequestNextVsyncAnimate_ || rsVSyncDistributor_->HasPendingUIRNV()) {
rsVSyncDistributor_->MarkRSAnimate();
@ -1491,6 +1495,14 @@ void RSMainThread::ProcessHgmFrameRate(uint64_t timestamp)
// if RS get here means it has frame coming in
frameRateMgr_->touchMgr_->ResetRSTimer(frameRateMgr_->GetCurScreenId());
frameRateMgr_->touchMgr_->HandleRSFrameUpdate(rsIdleTimerExpiredFlag_);
if (rsVSyncDistributor_->IsDVsyncOn()) {
auto pendingRefreshRate = frameRateMgr_->GetPendingRefreshRate();
if (pendingRefreshRate != nullptr) {
hgmCore.SetPendingScreenRefreshRate(*pendingRefreshRate);
frameRateMgr_->ResetPendingRefreshRate();
}
}
}
bool RSMainThread::GetParallelCompositionEnabled()
@ -1498,6 +1510,12 @@ bool RSMainThread::GetParallelCompositionEnabled()
return doParallelComposition_;
}
void RSMainThread::SetFrameIsRender(bool isRender)
{
hasMark_ = true;
rsVSyncDistributor_->SetFrameIsRender(isRender);
}
void RSMainThread::ColorPickerRequestVsyncIfNeed()
{
if (colorPickerForceRequestVsync_) {
@ -1560,6 +1578,7 @@ void RSMainThread::UniRender(std::shared_ptr<RSBaseRenderNode> rootNode)
return;
} else {
RS_LOGD("RSMainThread::Render nothing to update");
RSMainThread::Instance()->SetFrameIsRender(false);
for (auto& node: hardwareEnabledNodes_) {
if (!node->IsHardwareForcedDisabled()) {
node->MarkCurrentFrameHardwareEnabled();

View File

@ -281,6 +281,8 @@ public:
const std::vector<std::shared_ptr<RSSurfaceRenderNode>>& GetSelfDrawingNodes() const;
bool GetParallelCompositionEnabled();
std::shared_ptr<HgmFrameRateManager> GetFrameRateMgr() { return frameRateMgr_; };
void SetFrameIsRender(bool isRender);
private:
using TransactionDataIndexMap = std::unordered_map<pid_t,
std::pair<uint64_t, std::vector<std::unique_ptr<RSTransactionData>>>>;
@ -548,6 +550,7 @@ private:
// for dvsync (animate requestNextVSync after mark rsnotrendering)
bool needRequestNextVsyncAnimate_ = false;
bool hasMark_ = false;
// for statistic of jank frames
std::atomic_bool mainLooping_ = false;

View File

@ -747,11 +747,11 @@ void RSUniRenderUtil::PostReleaseSurfaceTask(std::shared_ptr<Drawing::Surface>&&
}
}
void RSUniRenderUtil::FloorTransXYInCanvasMatrix(RSPaintFilterCanvas& canvas)
void RSUniRenderUtil::CeilTransXYInCanvasMatrix(RSPaintFilterCanvas& canvas)
{
auto matrix = canvas.GetTotalMatrix();
matrix.Set(Drawing::Matrix::TRANS_X, std::floor(matrix.Get(Drawing::Matrix::TRANS_X)));
matrix.Set(Drawing::Matrix::TRANS_Y, std::floor(matrix.Get(Drawing::Matrix::TRANS_Y)));
matrix.Set(Drawing::Matrix::TRANS_X, std::ceil(matrix.Get(Drawing::Matrix::TRANS_X)));
matrix.Set(Drawing::Matrix::TRANS_Y, std::ceil(matrix.Get(Drawing::Matrix::TRANS_Y)));
canvas.SetMatrix(matrix);
}
} // namespace Rosen

View File

@ -78,7 +78,7 @@ public:
static void CacheSubThreadNodes(std::list<std::shared_ptr<RSSurfaceRenderNode>>& oldSubThreadNodes,
std::list<std::shared_ptr<RSSurfaceRenderNode>>& subThreadNodes);
// use floor value of translateX and translateY in matrix of canvas to avoid jittering
static void FloorTransXYInCanvasMatrix(RSPaintFilterCanvas& canvas);
static void CeilTransXYInCanvasMatrix(RSPaintFilterCanvas& canvas);
static bool IsNodeAssignSubThread(std::shared_ptr<RSSurfaceRenderNode> node, bool isDisplayRotation);
private:
static void AssignMainThreadNode(std::list<std::shared_ptr<RSSurfaceRenderNode>>& mainThreadNodes,

View File

@ -2495,7 +2495,7 @@ void RSUniRenderVisitor::ProcessDisplayRenderNode(RSDisplayRenderNode& node)
#endif
resetRotate_ = CheckIfNeedResetRotate();
if (!IsHardwareComposerEnabled()) {
RSMainThread::Instance()->rsVSyncDistributor_->MarkRSNotRendering();
RSMainThread::Instance()->SetFrameIsRender(false);
return;
}
if (!RSMainThread::Instance()->WaitHardwareThreadTaskExcute()) {
@ -2508,10 +2508,10 @@ void RSUniRenderVisitor::ProcessDisplayRenderNode(RSDisplayRenderNode& node)
}
}
RS_TRACE_NAME("DisplayNodeSkip skip commit");
RSMainThread::Instance()->rsVSyncDistributor_->MarkRSNotRendering();
RSMainThread::Instance()->SetFrameIsRender(false);
return;
}
RSMainThread::Instance()->rsVSyncDistributor_->UnmarkRSNotRendering();
RSMainThread::Instance()->SetFrameIsRender(true);
bool needCreateDisplayNodeLayer = false;
for (auto& surfaceNode: hardwareEnabledNodes_) {
if (!surfaceNode->IsHardwareForcedDisabled()) {
@ -2526,7 +2526,7 @@ void RSUniRenderVisitor::ProcessDisplayRenderNode(RSDisplayRenderNode& node)
}
return;
} else {
RSMainThread::Instance()->rsVSyncDistributor_->UnmarkRSNotRendering();
RSMainThread::Instance()->SetFrameIsRender(true);
}
auto rsSurface = node.GetRSSurface();
@ -4033,7 +4033,7 @@ void RSUniRenderVisitor::ProcessSurfaceRenderNode(RSSurfaceRenderNode& node)
DrawSpherize(node);
} else {
if (isSelfDrawingSurface) {
RSUniRenderUtil::FloorTransXYInCanvasMatrix(*canvas_);
RSUniRenderUtil::CeilTransXYInCanvasMatrix(*canvas_);
}
if (isUIFirst_ && node.GetCacheType() == CacheType::ANIMATE_PROPERTY) {
RSUniRenderUtil::HandleSubThreadNode(node, *canvas_);
@ -4483,7 +4483,7 @@ void RSUniRenderVisitor::ProcessCanvasRenderNode(RSCanvasRenderNode& node)
// in case preparation'update is skipped
canvas_->Save();
if (node.GetType() == RSRenderNodeType::CANVAS_DRAWING_NODE) {
RSUniRenderUtil::FloorTransXYInCanvasMatrix(*canvas_);
RSUniRenderUtil::CeilTransXYInCanvasMatrix(*canvas_);
}
const auto& property = node.GetRenderProperties();
if (node.GetSharedTransitionParam().has_value()) {

View File

@ -250,6 +250,7 @@ void RSUniUICapture::RSUniUICaptureVisitor::SetCanvas(std::shared_ptr<ExtendReco
canvas_->Scale(scaleX_, scaleY_);
canvas_->SetDisableFilterCache(true);
canvas_->SetRecordingState(true);
canvas_->SetCacheType(Drawing::CacheType::DISABLED);
}
void RSUniUICapture::RSUniUICaptureVisitor::ProcessChildren(RSRenderNode& node)

View File

@ -62,6 +62,11 @@ ohos_source_set("render_service_base_src") {
cfi_cross_dso = false
debug = false
blocklist = "./rs_base_blocklist.txt"
if (rosen_is_ohos) {
boundary_sanitize = true
integer_overflow = true
ubsan = true
}
}
defines = []
defines += gpu_defines

View File

@ -108,18 +108,19 @@ enum class RSModifierType : int16_t {
ILLUMINATED_BORDER_WIDTH, // 81
ILLUMINATED_TYPE, // 82
BLOOM, // 83
DYNAMIC_DIM_DEGREE, // 84
CUSTOM, // 85
EXTENDED, // 86
TRANSITION, // 87
BACKGROUND_STYLE, // 88
CONTENT_STYLE, // 89
FOREGROUND_STYLE, // 90
OVERLAY_STYLE, // 91
NODE_MODIFIER, // 92
ENV_FOREGROUND_COLOR, // 93
ENV_FOREGROUND_COLOR_STRATEGY, // 94
GEOMETRYTRANS, // 95
FOREGROUND_EFFECT_RADIUS, // 84
DYNAMIC_DIM_DEGREE, // 85
CUSTOM, // 86
EXTENDED, // 87
TRANSITION, // 88
BACKGROUND_STYLE, // 89
CONTENT_STYLE, // 90
FOREGROUND_STYLE, // 91
OVERLAY_STYLE, // 92
NODE_MODIFIER, // 93
ENV_FOREGROUND_COLOR, // 94
ENV_FOREGROUND_COLOR_STRATEGY, // 95
GEOMETRYTRANS, // 96
MAX_RS_MODIFIER_TYPE,
};

View File

@ -181,3 +181,5 @@ DECLARE_ANIMATABLE_MODIFIER(LightIntensity, float, LIGHT_INTENSITY, Replace, For
DECLARE_ANIMATABLE_MODIFIER(IlluminatedBorderWidth, float, ILLUMINATED_BORDER_WIDTH, Replace, Foreground, COARSE)
DECLARE_NOANIMATABLE_MODIFIER(IlluminatedType, int, ILLUMINATED_TYPE, Foreground)
DECLARE_ANIMATABLE_MODIFIER(ForegroundEffectRadius, float, FOREGROUND_EFFECT_RADIUS, Replace, Foreground, COARSE)

View File

@ -209,6 +209,10 @@ public:
Vector4f GetOutlineRadius() const;
const std::shared_ptr<RSBorder>& GetOutline() const;
void SetForegroundEffectRadius(const float foregroundEffectRadius);
float GetForegroundEffectRadius() const;
bool IsForegroundEffectRadiusValid() const;
// filter properties
void SetBackgroundFilter(const std::shared_ptr<RSFilter>& backgroundFilter);
void SetLinearGradientBlurPara(const std::shared_ptr<RSLinearGradientBlurPara>& para);
@ -433,6 +437,7 @@ private:
std::shared_ptr<RSLightSource> lightSourcePtr_ = nullptr;
std::shared_ptr<RSIlluminated> illuminatedPtr_ = nullptr;
float foregroundEffectRadius_ = 0.f;
std::shared_ptr<RSFilter> backgroundFilter_ = nullptr;
std::shared_ptr<RSLinearGradientBlurPara> linearGradientBlurPara_ = nullptr;
std::shared_ptr<RSBorder> border_ = nullptr;

View File

@ -73,7 +73,7 @@ enum class RSPropertyDrawableSlot : uint8_t {
COLOR_FILTER,
DYNAMIC_DIM,
LIGHT_UP_EFFECT,
FOREGROUND_FILTER,
COMPOSITING_FILTER,
FOREGROUND_COLOR,
FG_RESTORE_BOUNDS,

View File

@ -286,11 +286,11 @@ public:
bool Update(const RSRenderContent& content) override;
};
// ForegroundFilter
class RSForegroundFilterDrawable : public RSPropertyDrawable {
// CompositingFilter
class RSCompositingFilterDrawable : public RSPropertyDrawable {
public:
explicit RSForegroundFilterDrawable() = default;
~RSForegroundFilterDrawable() override = default;
explicit RSCompositingFilterDrawable() = default;
~RSCompositingFilterDrawable() override = default;
static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content);
void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override;
bool Update(const RSRenderContent& content) override;

View File

@ -57,7 +57,6 @@ public:
private:
float blurRadiusX_;
float blurRadiusY_;
bool useKawase_ = false;
std::optional<Vector2f> greyCoef_;
};
} // namespace Rosen

View File

@ -80,7 +80,9 @@ std::shared_ptr<RSInterpolator> RSInterpolator::Unmarshalling(Parcel& parcel)
default:
break;
}
if (ret == nullptr) { return nullptr; }
if (ret == nullptr) {
return nullptr;
}
static std::mutex cachedInterpolatorsMutex_;
static std::unordered_map<uint32_t, std::weak_ptr<RSInterpolator>> cachedInterpolators_;

View File

@ -151,8 +151,9 @@ ohos_source_set("rosen_ohos_sources") {
public_deps += [
"$graphic_2d_root:libgl",
"$graphic_2d_root:libvulkan",
"//third_party/openssl:libcrypto_shared",
]
public_external_deps = [ "openssl:libcrypto_shared" ]
}
if (graphic_2d_feature_enable_opinc) {

View File

@ -138,6 +138,7 @@ const std::array<ResetPropertyFunc, static_cast<int>(RSModifierType::CUSTOM)> g_
[](RSProperties* prop) { prop->SetIlluminatedType(-1); }, // ILLUMINATED_TYPE
[](RSProperties* prop) { prop->SetBloom({}); }, // BLOOM
[](RSProperties* prop) { prop->SetDynamicDimDegree({}); }, // DYNAMIC_LIGHT_UP_DEGREE
[](RSProperties* prop) { prop->SetForegroundEffectRadius(0.f); }, // FOREGROUND_EFFECT_RADIUS
};
} // namespace
@ -1048,6 +1049,27 @@ const std::shared_ptr<RSBorder>& RSProperties::GetOutline() const
return outline_;
}
void RSProperties::SetForegroundEffectRadius(const float foregroundEffectRadius)
{
foregroundEffectRadius_ = foregroundEffectRadius;
if (IsForegroundEffectRadiusValid()) {
isDrawn_ = true;
}
filterNeedUpdate_ = true;
SetDirty();
contentDirty_ = true;
}
float RSProperties::GetForegroundEffectRadius() const
{
return foregroundEffectRadius_;
}
bool RSProperties::IsForegroundEffectRadiusValid() const
{
return ROSEN_GNE(foregroundEffectRadius_, 0.0);
}
void RSProperties::SetBackgroundFilter(const std::shared_ptr<RSFilter>& backgroundFilter)
{
backgroundFilter_ = backgroundFilter;

View File

@ -90,9 +90,9 @@ static const std::unordered_map<RSModifierType, RSPropertyDrawableSlot> g_proper
{ RSModifierType::BORDER_COLOR, RSPropertyDrawableSlot::BORDER },
{ RSModifierType::BORDER_WIDTH, RSPropertyDrawableSlot::BORDER },
{ RSModifierType::BORDER_STYLE, RSPropertyDrawableSlot::BORDER },
{ RSModifierType::FILTER, RSPropertyDrawableSlot::FOREGROUND_FILTER },
{ RSModifierType::FILTER, RSPropertyDrawableSlot::COMPOSITING_FILTER },
{ RSModifierType::BACKGROUND_FILTER, RSPropertyDrawableSlot::BACKGROUND_FILTER },
{ RSModifierType::LINEAR_GRADIENT_BLUR_PARA, RSPropertyDrawableSlot::FOREGROUND_FILTER },
{ RSModifierType::LINEAR_GRADIENT_BLUR_PARA, RSPropertyDrawableSlot::COMPOSITING_FILTER },
{ RSModifierType::DYNAMIC_LIGHT_UP_RATE, RSPropertyDrawableSlot::DYNAMIC_LIGHT_UP },
{ RSModifierType::DYNAMIC_LIGHT_UP_DEGREE, RSPropertyDrawableSlot::DYNAMIC_LIGHT_UP },
{ RSModifierType::FRAME_GRAVITY, RSPropertyDrawableSlot::FRAME_OFFSET },
@ -199,7 +199,7 @@ static const std::array<RSPropertyDrawable::DrawableGenerator, LUT_SIZE> g_drawa
RSColorFilterDrawable::Generate, // COLOR_FILTER
RSDynamicDimDrawable::Generate, // DYNAMIC_DIM
RSLightUpEffectDrawable::Generate, // LIGHT_UP_EFFECT
RSForegroundFilterDrawable::Generate, // FOREGROUND_FILTER
RSCompositingFilterDrawable::Generate, // COMPOSITING_FILTER
RSForegroundColorDrawable::Generate, // FOREGROUND_COLOR
nullptr, // FG_RESTORE_BOUNDS

View File

@ -729,26 +729,26 @@ void RSBackgroundFilterDrawable::Draw(const RSRenderContent& content, RSPaintFil
RSPropertiesPainter::DrawFilter(content.GetRenderProperties(), canvas, FilterType::BACKGROUND_FILTER);
}
// foreground filter
RSPropertyDrawable::DrawablePtr RSForegroundFilterDrawable::Generate(const RSRenderContent& content)
// compositing filter
RSPropertyDrawable::DrawablePtr RSCompositingFilterDrawable::Generate(const RSRenderContent& content)
{
if (!RSPropertiesPainter::BLUR_ENABLED) {
ROSEN_LOGD("RSForegroundFilterDrawable::Generate close blur.");
ROSEN_LOGD("RSCompositingFilterDrawable::Generate close blur.");
return nullptr;
}
auto& filter = content.GetRenderProperties().GetFilter();
if (filter == nullptr) {
return nullptr;
}
return std::make_unique<RSForegroundFilterDrawable>();
return std::make_unique<RSCompositingFilterDrawable>();
}
bool RSForegroundFilterDrawable::Update(const RSRenderContent& content)
bool RSCompositingFilterDrawable::Update(const RSRenderContent& content)
{
return content.GetRenderProperties().GetFilter() != nullptr;
}
void RSForegroundFilterDrawable::Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const
void RSCompositingFilterDrawable::Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const
{
RSPropertiesPainter::DrawFilter(content.GetRenderProperties(), canvas, FilterType::FOREGROUND_FILTER);
}

View File

@ -57,25 +57,21 @@ void RSAIBarFilter::DrawImageRect(Drawing::Canvas& canvas, const std::shared_ptr
ROSEN_LOGE("RSAIBarFilter::DrawImageRect invertedImage is null");
return;
}
// apply blur effect on invertedImage
KawaseParameter param = KawaseParameter(src, dst, radius, nullptr, 1.0);
if (RSSystemProperties::GetGpuApiType() != GpuApiType::DDGR &&
static bool DDGR_ENABLED = RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR;
if (!DDGR_ENABLED && KAWASE_BLUR_ENABLED &&
KawaseBlurFilter::GetKawaseBlurFilter()->ApplyKawaseBlur(canvas, invertedImage, param)) {
return;
}
// if kawase blur failed, use gauss blur
Drawing::Brush brush;
brush.SetShaderEffect(builder->MakeShader(nullptr, false));
Drawing::Filter filter;
if (KAWASE_BLUR_ENABLED) {
filter.SetImageFilter(Drawing::ImageFilter::CreateBlurImageFilter(radius, radius, Drawing::TileMode::CLAMP,
nullptr, Drawing::ImageBlurType::KAWASE));
} else {
filter.SetImageFilter(Drawing::ImageFilter::CreateBlurImageFilter(radius, radius, Drawing::TileMode::CLAMP,
nullptr));
}
auto blurType = KAWASE_BLUR_ENABLED ? Drawing::ImageBlurType::KAWASE : Drawing::ImageBlurType::GAUSS;
filter.SetImageFilter(Drawing::ImageFilter::CreateBlurImageFilter(radius, radius, Drawing::TileMode::CLAMP,
nullptr, blurType));
brush.SetFilter(filter);
canvas.AttachBrush(brush);
canvas.DrawRect(dst);
canvas.DrawImageRect(*invertedImage, src, dst, Drawing::SamplingOptions());
canvas.DetachBrush();
}

View File

@ -24,9 +24,11 @@
namespace OHOS {
namespace Rosen {
const bool KAWASE_BLUR_ENABLED = RSSystemProperties::GetKawaseEnabled();
const auto BLUR_TYPE = KAWASE_BLUR_ENABLED ? Drawing::ImageBlurType::KAWASE : Drawing::ImageBlurType::GAUSS;
RSBlurFilter::RSBlurFilter(float blurRadiusX, float blurRadiusY) : RSDrawingFilter(
Drawing::ImageFilter::CreateBlurImageFilter(blurRadiusX, blurRadiusY, Drawing::TileMode::CLAMP, nullptr,
Drawing::ImageBlurType::KAWASE)),
BLUR_TYPE)),
blurRadiusX_(blurRadiusX),
blurRadiusY_(blurRadiusY)
{
@ -37,7 +39,6 @@ RSBlurFilter::RSBlurFilter(float blurRadiusX, float blurRadiusY) : RSDrawingFilt
hash_ = SkOpts::hash(&type_, sizeof(type_), 0);
hash_ = SkOpts::hash(&blurRadiusXForHash, sizeof(blurRadiusXForHash), hash_);
hash_ = SkOpts::hash(&blurRadiusYForHash, sizeof(blurRadiusYForHash), hash_);
useKawase_ = RSSystemProperties::GetKawaseEnabled();
}
RSBlurFilter::~RSBlurFilter() = default;
@ -60,7 +61,8 @@ std::string RSBlurFilter::GetDescription()
std::string RSBlurFilter::GetDetailedDescription()
{
return "RSBlurFilterBlur, radius: " + std::to_string(blurRadiusX_) + " sigma" +
", greyCoef1: " + std::to_string(greyCoef_->x_) + ", greyCoef2: " + std::to_string(greyCoef_->y_);
", greyCoef1: " + std::to_string(greyCoef_ == std::nullopt ? 0.0f : greyCoef_->x_) +
", greyCoef2: " + std::to_string(greyCoef_ == std::nullopt ? 0.0f : greyCoef_->y_);
}
bool RSBlurFilter::IsValid() const
@ -138,7 +140,7 @@ void RSBlurFilter::DrawImageRect(Drawing::Canvas& canvas, const std::shared_ptr<
// if kawase blur failed, use gauss blur
static bool DDGR_ENABLED = RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR;
KawaseParameter param = KawaseParameter(src, dst, blurRadiusX_, nullptr, brush.GetColor().GetAlphaF());
if (!DDGR_ENABLED && useKawase_ &&
if (!DDGR_ENABLED && KAWASE_BLUR_ENABLED &&
KawaseBlurFilter::GetKawaseBlurFilter()->ApplyKawaseBlur(canvas, greyImage, param)) {
return;
}

View File

@ -343,8 +343,7 @@ bool KawaseBlurFilter::ApplyBlur(Drawing::Canvas& canvas, const std::shared_ptr<
void KawaseBlurFilter::ComputeRadiusAndScale(int radius)
{
static constexpr int noiseFactor = 3; // 3 : smooth the radius change
blurRadius_ = radius * 4 / noiseFactor * noiseFactor; // 4 : scale between gauss radius and kawase
blurRadius_ = radius * 4; // 4 : scale between gauss radius and kawase
AdjustRadiusAndScale();
}

View File

@ -134,7 +134,8 @@ std::string RSMaterialFilter::GetDetailedDescription()
if (sprintf_s(maskColorStr, UINT8_MAX, "%08X", maskColor_.AsArgbInt()) != -1) {
return "RSMaterialFilterBlur, radius: " + std::to_string(radius_) + " sigma" +
", saturation: " + std::to_string(saturation_) + ", brightness: " + std::to_string(brightness_) +
", greyCoef1: " + std::to_string(greyCoef_->x_) + ", greyCoef2: " + std::to_string(greyCoef_->y_) +
", greyCoef1: " + std::to_string(greyCoef_ == std::nullopt ? 0.0f : greyCoef_->x_) +
", greyCoef2: " + std::to_string(greyCoef_ == std::nullopt ? 0.0f : greyCoef_->y_) +
", color: " + maskColorStr + ", colorMode: " + std::to_string(colorMode_);
};
return "RSMaterialFilterBlur, maskColorStr failed";
@ -175,7 +176,8 @@ std::shared_ptr<Drawing::ColorFilter> RSMaterialFilter::GetColorFilter(float sat
std::shared_ptr<Drawing::ImageFilter> RSMaterialFilter::CreateMaterialFilter(float radius, float sat, float brightness)
{
colorFilter_ = GetColorFilter(sat, brightness);
return Drawing::ImageFilter::CreateColorBlurImageFilter(*colorFilter_, radius, radius);
auto blurType = KAWASE_BLUR_ENABLED ? Drawing::ImageBlurType::KAWASE : Drawing::ImageBlurType::GAUSS;
return Drawing::ImageFilter::CreateColorBlurImageFilter(*colorFilter_, radius, radius, blurType);
}
std::shared_ptr<Drawing::ImageFilter> RSMaterialFilter::CreateMaterialStyle(
@ -304,8 +306,10 @@ void RSMaterialFilter::DrawImageRect(Drawing::Canvas& canvas, const std::shared_
if (greyImage == nullptr) {
greyImage = image;
}
static bool DDGR_ENABLED = RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR;
KawaseParameter param = KawaseParameter(src, dst, radius_, colorFilter_, brush.GetColor().GetAlphaF());
if (KAWASE_BLUR_ENABLED && KawaseBlurFilter::GetKawaseBlurFilter()->ApplyKawaseBlur(canvas, greyImage, param)) {
if (!DDGR_ENABLED && KAWASE_BLUR_ENABLED &&
KawaseBlurFilter::GetKawaseBlurFilter()->ApplyKawaseBlur(canvas, greyImage, param)) {
return;
}
canvas.AttachBrush(brush);

View File

@ -77,8 +77,9 @@ ohos_static_library("librender_backend") {
"$graphic_2d_root:libgl",
"$graphic_2d_root:libvulkan",
"$graphic_2d_root/rosen/modules/2d_graphics:2d_graphics",
"//third_party/openssl:libcrypto_shared",
]
public_external_deps = [ "openssl:libcrypto_shared" ]
}
public_deps += [ "//third_party/skia:skia_ohos" ]

View File

@ -39,6 +39,11 @@ template("render_service_client_source_set") {
cfi_cross_dso = false
debug = false
blocklist = "./rs_client_blocklist.txt"
if (rosen_is_ohos) {
boundary_sanitize = true
integer_overflow = true
ubsan = true
}
}
defines = []
defines += gpu_defines

View File

@ -242,6 +242,11 @@ Vector4f RSModifierExtractor::GetOutlineRadius() const
GET_PROPERTY_FROM_MODIFIERS_EQRETURN(Vector4f, OUTLINE_RADIUS, Vector4f(0.f), =);
}
float RSModifierExtractor::GetForegroundEffectRadius() const
{
GET_PROPERTY_FROM_MODIFIERS(float, FOREGROUND_EFFECT_RADIUS, 0.f, =);
}
std::shared_ptr<RSFilter> RSModifierExtractor::GetBackgroundFilter() const
{
GET_PROPERTY_FROM_MODIFIERS_EQRETURN(std::shared_ptr<RSFilter>, BACKGROUND_FILTER, nullptr, =);

View File

@ -68,6 +68,7 @@ public:
Vector4<uint32_t> GetOutlineStyle() const;
Vector4f GetOutlineRadius() const;
float GetForegroundEffectRadius() const;
std::shared_ptr<RSFilter> GetBackgroundFilter() const;
std::shared_ptr<RSFilter> GetFilter() const;

View File

@ -373,6 +373,15 @@ protected:
std::shared_ptr<RSRenderModifier> CreateRenderModifier() const override;
};
class RSC_EXPORT RSForegroundEffectRadiusModifier : public RSForegroundModifier {
public:
explicit RSForegroundEffectRadiusModifier(const std::shared_ptr<RSPropertyBase>& property);
virtual ~RSForegroundEffectRadiusModifier() = default;
protected:
RSModifierType GetModifierType() const override;
std::shared_ptr<RSRenderModifier> CreateRenderModifier() const override;
};
class RSC_EXPORT RSFilterModifier : public RSForegroundModifier {
public:
explicit RSFilterModifier(const std::shared_ptr<RSPropertyBase>& property);

View File

@ -1171,6 +1171,12 @@ void RSNode::SetOutlineRadius(const Vector4f& radius)
RSModifierType::OUTLINE_RADIUS, radius);
}
void RSNode::SetForegroundEffectRadius(const float blurRadius)
{
SetProperty<RSForegroundEffectRadiusModifier, RSAnimatableProperty<float>>(
RSModifierType::FOREGROUND_EFFECT_RADIUS, blurRadius);
}
void RSNode::SetBackgroundFilter(const std::shared_ptr<RSFilter>& backgroundFilter)
{
SetProperty<RSBackgroundFilterModifier, RSAnimatableProperty<std::shared_ptr<RSFilter>>>(

View File

@ -256,6 +256,7 @@ public:
void SetOutlineStyle(const Vector4<BorderStyle>& style);
void SetOutlineRadius(const Vector4f& radius);
void SetForegroundEffectRadius(const float blurRadius);
void SetBackgroundFilter(const std::shared_ptr<RSFilter>& backgroundFilter);
void SetFilter(const std::shared_ptr<RSFilter>& filter);
void SetLinearGradientBlurPara(const std::shared_ptr<RSLinearGradientBlurPara>& para);

View File

@ -309,6 +309,12 @@ void RSSurfaceNode::CreateTextureExportRenderNodeInRT()
return;
}
transactionProxy->AddCommand(command, false);
command = std::make_unique<RSSurfaceNodeConnectToNodeInRenderService>(GetId());
transactionProxy->AddCommand(command, false);
RSRTRefreshCallback::Instance().SetRefresh([] { RSRenderThread::Instance().RequestNextVSync(); });
command = std::make_unique<RSSurfaceNodeSetCallbackForRenderThreadRefresh>(GetId(), true);
transactionProxy->AddCommand(command, false);
}
void RSSurfaceNode::SetIsTextureExportNode(bool isTextureExportNode)
@ -321,6 +327,7 @@ void RSSurfaceNode::SetIsTextureExportNode(bool isTextureExportNode)
}
transactionProxy->AddCommand(command, false);
// need to reset isTextureExport sign in renderService
command = std::make_unique<RSSurfaceNodeSetIsTextureExportNode>(GetId(), isTextureExportNode);
transactionProxy->AddCommand(command, true);
}

View File

@ -355,7 +355,7 @@ HWTEST_F(RSInterfacesTest, CreateVirtualScreen004, Function | SmallTest | Level2
rsInterfaces->SetScreenPowerStatus(virtualScreenId, ScreenPowerStatus::POWER_STATUS_ON);
usleep(SET_REFRESHRATE_SLEEP_US); // wait 50000us to ensure SetScreenPowerStatus done.
auto powerStatus = rsInterfaces->GetScreenPowerStatus(virtualScreenId);
EXPECT_EQ(powerStatus, ScreenPowerStatus::INVALID_POWER_STATUS);
EXPECT_NE(powerStatus, ScreenPowerStatus::POWER_STATUS_ON);
auto screenCapability = rsInterfaces->GetScreenCapability(virtualScreenId);
EXPECT_EQ(screenCapability.GetPhyWidth(), 0);
@ -564,7 +564,7 @@ HWTEST_F(RSInterfacesTest, GetScreenPowerStatus001, Function | SmallTest | Level
HWTEST_F(RSInterfacesTest, GetScreenPowerStatus002, Function | SmallTest | Level2)
{
auto powerStatus = rsInterfaces->GetScreenPowerStatus(INVALID_SCREEN_ID);
EXPECT_EQ(powerStatus, ScreenPowerStatus::INVALID_POWER_STATUS);
EXPECT_NE(powerStatus, ScreenPowerStatus::POWER_STATUS_ON);
}
/*
@ -987,7 +987,7 @@ HWTEST_F(RSInterfacesTest, SetScreenSkipFrameInterval003, Function | SmallTest |
EXPECT_NE(screenId, INVALID_SCREEN_ID);
uint32_t skipFrameInterval = 100; // for test
int32_t ret = rsInterfaces->SetScreenSkipFrameInterval(screenId, skipFrameInterval);
EXPECT_EQ(ret, StatusCode::INVALID_ARGUMENTS);
EXPECT_EQ(ret, StatusCode::SUCCESS);
}
/*

View File

@ -123,8 +123,10 @@ ohos_source_set("libtexgine_source") {
if (enable_text_gine) {
defines += [ "USE_GRAPHIC_TEXT_GINE" ]
}
deps = [ "//third_party/bounds_checking_function:libsec_static" ]
include_dirs = [ "//third_party/bounds_checking_function/include" ]
external_deps = [
"bounds_checking_function:libsec_static",
"cJSON:cjson_static",
]
if (platform == "ohos") {
defines += [ "BUILD_NON_SDK_VER" ]
@ -137,8 +139,7 @@ ohos_source_set("libtexgine_source") {
defines += [ "TEXGINE_ENABLE_DEBUGLOG" ]
}
external_deps = [
"cJSON:cjson_static",
external_deps += [
"c_utils:utils",
"hilog:libhilog",
"hitrace:hitrace_meter",
@ -157,8 +158,6 @@ ohos_source_set("libtexgine_source") {
public_deps +=
[ "$graphic_2d_root/rosen/build/icu:rosen_libicu_$platform" ]
}
include_dirs += [ "//third_party/cJSON" ]
deps += [ "//third_party/cJSON:cjson_static" ]
}
}

View File

@ -33,6 +33,7 @@ namespace TextEngine {
* including parameters for default TextStyle, multi-text, and line style.
*/
struct TypographyStyle {
const static inline std::u16string ELLIPSIS = u"\u2026";
// default TextStyle
FontWeight fontWeight = FontWeight::W400;
FontStyle fontStyle = FontStyle::NORMAL;
@ -77,6 +78,7 @@ struct TypographyStyle {
* @brief Returns the default TextStyle.
*/
TextStyle ConvertToTextStyle() const;
bool ellipsizedForNDK = false;
};
} // namespace TextEngine
} // namespace Rosen

View File

@ -69,7 +69,6 @@ ohos_executable("drawing_engine_sample") {
"$graphic_2d_root/rosen/include/common",
"$graphic_2d_root/rosen/modules/render_service_base/src/platform/ohos/backend",
"$graphic_2d_root/rosen/modules/render_service_base/src",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
]
sources += [
@ -107,7 +106,6 @@ ohos_executable("drawing_engine_sample") {
public_deps += [
"$graphic_2d_root:libvulkan",
"$graphic_2d_root/rosen/modules/render_service_base:librender_service_base",
"//third_party/openssl:libcrypto_shared",
]
external_deps = [
"c_utils:utils",
@ -117,6 +115,7 @@ ohos_executable("drawing_engine_sample") {
"init:libbegetutil",
"ipc:ipc_core",
]
public_external_deps = [ "openssl:libcrypto_shared" ]
subsystem_name = "graphic"
part_name = "graphic_2d"
@ -134,7 +133,6 @@ ohos_executable("drawing_sample_rs") {
"$graphic_2d_root/rosen/modules/render_service_base/include",
"$graphic_2d_root/rosen/modules/render_service_client",
"$graphic_2d_root/rosen/include/common",
"//foundation/window/window_manager/interfaces/innerkits/wm",
]
deps = [
@ -142,7 +140,6 @@ ohos_executable("drawing_sample_rs") {
"$graphic_2d_root/rosen/modules/2d_graphics/drawing_ndk:native_drawing_ndk",
"$graphic_2d_root/rosen/modules/render_service_base:librender_service_base",
"$graphic_2d_root/rosen/modules/render_service_client:librender_service_client",
"//third_party/zlib:libz",
]
external_deps = [

View File

@ -16,6 +16,7 @@ group("test") {
deps = [
"drawing:drawing_demo",
"drawing:libdrawing_demo",
"fuzztest:fuzztest",
"unittest:unittest",
]

View File

@ -14,18 +14,20 @@
import("//build/test.gni")
import("//foundation/graphic/graphic_2d/graphic_config.gni")
ohos_systemtest("drawing_demo") {
module_out_path = "graphic_2d/drawing"
defines = []
include_dirs =
[ "../../../../../../window/window_manager/interfaces/innerkits" ]
ohos_source_set("demo_set") {
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
sources = [
"drawing_demo.cpp",
"test_base.cpp",
"test_case/draw_path.cpp",
"test_case/draw_rect.cpp",
"test_common.cpp",
"test_case/draw_path_test.cpp",
"test_case/draw_rect_test.cpp",
"test_case/test_base.cpp",
"test_case/test_common.cpp",
"test_case_factory.cpp",
]
deps = [
@ -34,11 +36,30 @@ ohos_systemtest("drawing_demo") {
"../../../../rosen/modules/render_service_client:librender_service_client",
]
public_external_deps = [ "window_manager:libwm" ]
external_deps = [
"c_utils:utils",
"hilog:libhilog",
"image_framework:image_native",
"window_manager:libdm",
"window_manager:libwm",
]
part_name = "graphic_2d"
subsystem_name = "graphic"
}
ohos_systemtest("drawing_demo") {
module_out_path = "graphic_2d/drawing"
deps = [ ":demo_set" ]
}
ohos_shared_library("libdrawing_demo") {
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
deps = [ ":demo_set" ]
part_name = "graphic_2d"
subsystem_name = "graphic"
}

View File

@ -13,33 +13,15 @@
* limitations under the License.
*/
#include "drawing_demo.h"
#include <sstream>
#include "display_manager.h"
#include "test_case/draw_path.h"
#include "test_case/draw_rect.h"
#include "test_common.h"
#include "test_case_factory.h"
#include "test_case/test_common.h"
using namespace OHOS::Rosen;
namespace {
std::unordered_map<std::string, std::function<std::shared_ptr<TestBase>()>> FunctionalCpuMap = {
{"drawrect", []() -> std::shared_ptr<TestBase> {return std::make_shared<DrawRectTest>();}},
{"drawpath", []() -> std::shared_ptr<TestBase> {return std::make_shared<DrawPathTest>();}},
};
std::unordered_map<std::string, std::function<std::shared_ptr<TestBase>()>> PerformanceCpuMap = {
{"drawrect", []() -> std::shared_ptr<TestBase> {return std::make_shared<DrawRectTest>();}},
{"drawpath", []() -> std::shared_ptr<TestBase> {return std::make_shared<DrawPathTest>();}},
};
std::unordered_map<std::string, std::function<std::shared_ptr<TestBase>()>> FunctionalGpuUpScreenMap = {
{"drawrect", []() -> std::shared_ptr<TestBase> {return std::make_shared<DrawRectTest>();}},
{"drawpath", []() -> std::shared_ptr<TestBase> {return std::make_shared<DrawPathTest>();}},
};
std::unordered_map<std::string, std::function<std::shared_ptr<TestBase>()>> PerformanceGpuUpScreenMap = {
{"drawrect", []() -> std::shared_ptr<TestBase> {return std::make_shared<DrawRectTest>();}},
{"drawpath", []() -> std::shared_ptr<TestBase> {return std::make_shared<DrawPathTest>();}},
};
} // namespace
namespace OHOS {
namespace Rosen {
DrawingDemo::DrawingDemo(int argc, char* argv[])
@ -59,7 +41,7 @@ DrawingDemo::~DrawingDemo()
}
};
int DrawingDemo::Test()
int DrawingDemo::Test(TestDisplayCanvas* canvas)
{
TestCommon::Log("eg: drawing_demo function [cpu | gpu] {caseName?} {displayTime?}");
TestCommon::Log("eg: drawing_demo performance [cpu | gpu] caseName count {displayTime?}");
@ -71,15 +53,15 @@ int DrawingDemo::Test()
drawingType_ = argv_[INDEX_DRAWING_TYPE];
if (testType_ == "function") {
if (drawingType_ == "cpu") {
return TestFunction(FunctionalCpuMap, FUNCTION_CPU);
return TestFunction(FUNCTION_CPU);
} else if (drawingType_ == "gpu") {
return TestFunction(FunctionalGpuUpScreenMap, FUNCTION_GPU_UPSCREEN);
return TestFunction(FUNCTION_GPU_UPSCREEN);
}
} else if (testType_ == "performance") {
if (drawingType_ == "cpu") {
return TestPerformance(PerformanceCpuMap, PERFORMANCE_CPU);
return TestPerformance(canvas, PERFORMANCE_CPU);
} else if (drawingType_ == "gpu") {
return TestPerformance(PerformanceGpuUpScreenMap, PERFORMANCE_GPU_UPSCREEN);
return TestPerformance(canvas, PERFORMANCE_GPU_UPSCREEN);
}
}
return RET_PARAM_ERR;
@ -198,9 +180,9 @@ int DrawingDemo::GetFunctionalParam(std::unordered_map<std::string, std::functio
return RET_OK;
}
int DrawingDemo::TestFunction(
std::unordered_map<std::string, std::function<std::shared_ptr<TestBase>()>>& map, int type)
int DrawingDemo::TestFunction(int type)
{
auto map = TestCaseFactory::GetFunctionCase();
int ret = GetFunctionalParam(map);
if (ret != RET_OK) {
return ret;
@ -211,7 +193,6 @@ int DrawingDemo::TestFunction(
if (ret != RET_OK) {
return ret;
}
for (auto iter : map) {
if ((caseName_ != ALL_TAST_CASE) && (caseName_ != iter.first)) {
continue;
@ -250,7 +231,7 @@ int DrawingDemo::TestFunction(
return RET_OK;
}
int DrawingDemo::GetPerformanceParam()
int DrawingDemo::GetPerformanceParam(std::shared_ptr<TestBase>& testCase)
{
// drawing_demo performance {cpu | gpu} caseName count {displaytime?}
if (argc_ <= INDEX_COUNT) {
@ -258,6 +239,20 @@ int DrawingDemo::GetPerformanceParam()
}
caseName_ = argv_[INDEX_CASE_NAME];
auto map = TestCaseFactory::GetPerformanceCase();
auto iter = map.find(caseName_);
if (iter == map.end()) {
TestCommon::Log("TestCase not exist, please try again. All testcase:");
for (auto iter : map) {
TestCommon::Log(iter.first);
}
return RET_PARAM_ERR;
}
testCase = iter->second();
if (testCase == nullptr) {
TestCommon::Log("Failed to create testcase");
return RET_FAILED;
}
std::string testCountStr = argv_[INDEX_COUNT];
testCount_ = std::stoi(testCountStr);
@ -269,51 +264,49 @@ int DrawingDemo::GetPerformanceParam()
return RET_OK;
}
int DrawingDemo::TestPerformance(
std::unordered_map<std::string, std::function<std::shared_ptr<TestBase>()>>& map, int type)
int DrawingDemo::TestPerformance(TestDisplayCanvas* canvasExt, int type)
{
int ret = GetPerformanceParam();
if (ret != RET_OK) {
std::shared_ptr<TestBase> testCase = nullptr;
int ret = GetPerformanceParam(testCase);
if (ret != RET_OK || testCase == nullptr) {
return ret;
}
auto iter = map.find(caseName_);
if (iter == map.end()) {
TestCommon::Log("TestCase not exist, please try again. All testcase:");
for (auto iter : map) {
TestCommon::Log(iter.first);
}
return RET_PARAM_ERR;
}
TestCommon::Log("TestPerformance start!");
ret = CreateWindow();
if (ret != RET_OK) {
return ret;
TestDisplayCanvas* canvas = nullptr;
if (canvasExt == nullptr) {
ret = CreateWindow();
if (ret != RET_OK) {
return ret;
}
canvas = reinterpret_cast<TestDisplayCanvas*>(canvasNode_->BeginRecording(rect_.width_, rect_.height_));
if (canvas == nullptr) {
TestCommon::Log("Failed to get canvas");
return RET_FAILED;
}
} else {
canvas = canvasExt;
}
auto canvas = canvasNode_->BeginRecording(rect_.width_, rect_.height_);
auto testCase = iter->second();
if (testCase == nullptr) {
TestCommon::Log("Failed to create testcase");
return RET_FAILED;
}
testCase->SetCanvas((TestDisplayCanvas*)(canvas));
testCase->SetTestCount(testCount_);
sleep(5); // Time reserved for hiperf to crawl, 5s.
if (type == PERFORMANCE_CPU) {
testCase->TestPerformanceCpu();
} else if (type == PERFORMANCE_GPU_UPSCREEN) {
testCase->TestPerformanceGpuUpScreen();
}
canvasNode_->FinishRecording();
rsUiDirector_->SendMessages();
std::ostringstream stream;
stream << "wait: " << displayTime_ << "s";
TestCommon::Log(stream.str());
sleep(displayTime_);
if (canvasExt == nullptr) {
canvasNode_->FinishRecording();
rsUiDirector_->SendMessages();
std::ostringstream stream;
stream << "wait: " << displayTime_ << "s";
TestCommon::Log(stream.str());
sleep(displayTime_);
}
TestCommon::Log("TestPerformance end!");
return RET_OK;
}
@ -327,9 +320,33 @@ int main(int argc, char* argv[])
TestCommon::Log("Failed to create DrawingDemo");
return 0;
}
int ret = drawingDemo->Test();
int ret = drawingDemo->Test(nullptr);
if (ret == RET_PARAM_ERR) {
TestCommon::Log("Invalid parameter, please confirm");
}
return ret;
}
}
#ifdef __cplusplus
extern "C" {
#endif
int DrawingTest(void* canvas, int argc, char* argv[])
{
if (canvas == nullptr) {
TestCommon::Log("canvas is nullptr");
return 0;
}
std::shared_ptr<DrawingDemo> drawingDemo = std::make_shared<DrawingDemo>(argc, argv);
if (drawingDemo == nullptr) {
TestCommon::Log("Failed to create DrawingDemo");
return 0;
}
int ret = drawingDemo->Test((TestDisplayCanvas*)(canvas));
if (ret == RET_PARAM_ERR) {
TestCommon::Log("Invalid parameter, please confirm");
}
return ret;
}
#ifdef __cplusplus
}
#endif

View File

@ -17,14 +17,15 @@
#include <chrono>
#include <iostream>
#include <string>
#include <surface.h>
#include "test_base.h"
#include "transaction/rs_transaction.h"
#include "ui/rs_root_node.h"
#include "ui/rs_surface_node.h"
#include "ui/rs_ui_director.h"
#include "utils/log.h"
#include "wm/window.h"
#include "window.h"
#include "test_case/test_base.h"
namespace OHOS {
namespace Rosen {
@ -43,7 +44,7 @@ class DrawingDemo {
public:
DrawingDemo(int argc, char* argv[]);
~DrawingDemo();
int Test();
int Test(TestDisplayCanvas* canvas);
enum {
FUNCTION_CPU = 0,
FUNCTION_GPU_UPSCREEN,
@ -55,9 +56,9 @@ protected:
int InitWindow();
int CreateWindow();
int GetFunctionalParam(std::unordered_map<std::string, std::function<std::shared_ptr<TestBase>()>>& map);
int TestFunction(std::unordered_map<std::string, std::function<std::shared_ptr<TestBase>()>>& map, int type);
int GetPerformanceParam();
int TestPerformance(std::unordered_map<std::string, std::function<std::shared_ptr<TestBase>()>>& map, int type);
int TestFunction(int type);
int GetPerformanceParam(std::shared_ptr<TestBase>& testCase);
int TestPerformance(TestDisplayCanvas* canvasExt, int type);
int argc_ = 0;
std::vector<std::string> argv_;

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "draw_path.h"
#include "draw_path_test.h"
namespace OHOS {
namespace Rosen {

View File

@ -12,9 +12,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DRAWING_DEMO_DRAW_PATH_H
#define DRAWING_DEMO_DRAW_PATH_H
#include "../test_base.h"
#ifndef DRAWING_DEMO_DRAW_PATH_TEST_H
#define DRAWING_DEMO_DRAW_PATH_TEST_H
#include "test_base.h"
namespace OHOS {
namespace Rosen {
@ -29,4 +29,4 @@ protected:
};
} // namespace Rosen
} // namespace OHOS
#endif // DRAWING_DEMO_DRAW_PATH_H
#endif // DRAWING_DEMO_DRAW_PATH_TEST_H

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "draw_rect.h"
#include "draw_rect_test.h"
namespace OHOS {
namespace Rosen {

View File

@ -12,9 +12,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DRAWING_DEMO_DRAW_RECT_H
#define DRAWING_DEMO_DRAW_RECT_H
#include "../test_base.h"
#ifndef DRAWING_DEMO_DRAW_RECT_TEST_H
#define DRAWING_DEMO_DRAW_RECT_TEST_H
#include "test_base.h"
namespace OHOS {
namespace Rosen {
@ -28,4 +28,4 @@ protected:
};
} // namespace Rosen
} // namespace OHOS
#endif // DRAWING_DEMO_DRAW_RECT_H
#endif // DRAWING_DEMO_DRAW_RECT_TEST_H

View File

@ -13,10 +13,12 @@
* limitations under the License.
*/
#include "test_base.h"
#include <sstream>
#include <string>
#include "image/image.h"
#include "test_common.h"
#include "image/image.h"
#include "utils/log.h"
namespace OHOS {

View File

@ -32,7 +32,7 @@ public:
virtual ~TestBase() = default;
void SetCanvas(TestDisplayCanvas* canvas);
void SetFileName(std::string fileName);
void SetTestCount(uint32_t copunt);
void SetTestCount(uint32_t count);
void TestFunctionCpu();
void TestPerformanceCpu();
void TestFunctionGpuUpScreen();

View File

@ -13,7 +13,9 @@
* limitations under the License.
*/
#include "test_common.h"
#include <fcntl.h>
#include "image/image.h"
#include "image_packer.h"
#include "utils/log.h"
@ -40,7 +42,7 @@ int TestCommon::PackingPixmap(std::shared_ptr<OHOS::Media::PixelMap> pixmap, std
return RET_FAILED;
}
std::string path = "/data/test/" + fileName + ".jpg";
std::string path = "/data/test/" + fileName + ".png";
int32_t fileDes = open(path.c_str(), O_CREAT | O_RDWR);
if (fileDes <= 0) {
Log("failed to open");
@ -48,7 +50,7 @@ int TestCommon::PackingPixmap(std::shared_ptr<OHOS::Media::PixelMap> pixmap, std
}
OHOS::Media::PackOption option;
option.format = "image/jpeg";
option.format = "image/png";
uint32_t result = imagePacker.StartPacking(fileDes, option);
if (result != 0) {
Log("failed to StartPacking");

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2024 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 "test_case_factory.h"
#include "test_case/draw_path_test.h"
#include "test_case/draw_rect_test.h"
using namespace OHOS::Rosen;
namespace {
std::unordered_map<std::string, std::function<std::shared_ptr<TestBase>()>> FunctionalMap = {
{"drawrect", []() -> std::shared_ptr<TestBase> {return std::make_shared<DrawRectTest>();}},
{"drawpath", []() -> std::shared_ptr<TestBase> {return std::make_shared<DrawPathTest>();}},
};
std::unordered_map<std::string, std::function<std::shared_ptr<TestBase>()>> PerformanceMap = {
{"drawrect", []() -> std::shared_ptr<TestBase> {return std::make_shared<DrawRectTest>();}},
{"drawpath", []() -> std::shared_ptr<TestBase> {return std::make_shared<DrawPathTest>();}},
};
} // namespace
namespace OHOS {
namespace Rosen {
std::unordered_map<std::string, std::function<std::shared_ptr<TestBase>()>> TestCaseFactory::GetFunctionCase()
{
return FunctionalMap;
}
std::unordered_map<std::string, std::function<std::shared_ptr<TestBase>()>> TestCaseFactory::GetPerformanceCase()
{
return PerformanceMap;
}
} // namespace Rosen
} // namespace OHOS

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 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 TEST_CASE_FACTORY_H
#define TEST_CASE_FACTORY_H
#include "test_case/test_base.h"
namespace OHOS {
namespace Rosen {
class TestCaseFactory {
public:
TestCaseFactory(){};
virtual ~TestCaseFactory() = default;
static std::unordered_map<std::string, std::function<std::shared_ptr<TestBase>()>> GetFunctionCase();
static std::unordered_map<std::string, std::function<std::shared_ptr<TestBase>()>> GetPerformanceCase();
};
} // namespace Rosen
} // namespace OHOS
#endif // TEST_CASE_FACTORY_H

Some files were not shown because too many files have changed in this diff Show More