mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-11-23 23:20:32 +00:00
Merge branch 'master' of gitee.com:openharmony/graphic_graphic_2d into vsync_dfx
Signed-off-by: shegangbin <shegangbin1@huawei.com>
This commit is contained in:
commit
7da45723f2
4
BUILD.gn
4
BUILD.gn
@ -61,10 +61,6 @@ ohos_prebuilt_etc("graphic.rc") {
|
||||
|
||||
## Install graphic.rc to /system/etc/init/graphic.rc }}}
|
||||
|
||||
group("libfence") {
|
||||
public_deps = [ "frameworks/fence:libfence" ]
|
||||
}
|
||||
|
||||
group("libvulkan") {
|
||||
public_deps = libvulkan
|
||||
}
|
||||
|
@ -1,53 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
## Build libfence.so {{{
|
||||
config("fence_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
]
|
||||
}
|
||||
|
||||
config("fence_public_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("libfence") {
|
||||
sources = [ "src/fence.cpp" ]
|
||||
|
||||
configs = [ ":fence_config" ]
|
||||
|
||||
public_configs = [ ":fence_public_config" ]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
]
|
||||
|
||||
part_name = "graphic_2d"
|
||||
subsystem_name = "graphic"
|
||||
}
|
||||
|
||||
## Build libfence.so }}}
|
||||
|
||||
group("test") {
|
||||
testonly = true
|
||||
|
||||
deps = [ "test:test" ]
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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 FRAMEWORKS_FENCE_INCLUDE_FENCE_H
|
||||
#define FRAMEWORKS_FENCE_INCLUDE_FENCE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum FenceStatus {
|
||||
ERROR, ACTIVE, SIGNALED
|
||||
};
|
||||
|
||||
bool IsSupportSwSync(void);
|
||||
int CreateTimeline(void);
|
||||
int CreateFenceFromTimeline(int timeline, const char* name, unsigned int totalSteps);
|
||||
int FenceHold(int fd, int timeout);
|
||||
int TimelineActivate(int timeline, unsigned int step);
|
||||
enum FenceStatus FenceGetStatus(int fd);
|
||||
int FenceMerge(const char* name, int fd1, int fd2);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // FRAMEWORKS_FENCE_INCLUDE_FENCE_H
|
@ -1,155 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "fence.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <hilog/log.h>
|
||||
#include <securec.h>
|
||||
#include <linux/sync_file.h>
|
||||
|
||||
bool IsSupportSwSync()
|
||||
{
|
||||
struct stat syncStatus = {};
|
||||
if (!stat("/sys/kernel/debug/sync/sw_sync", &syncStatus)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int CreateTimeline()
|
||||
{
|
||||
int timeline = open("/sys/kernel/debug/sync/sw_sync", O_RDWR);
|
||||
if (timeline < 0) {
|
||||
HiLogPrint(LOG_CORE, LOG_ERROR, 0, "fence", "open file failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fcntl(timeline, F_GETFD, 0) < 0) {
|
||||
HiLogPrint(LOG_CORE, LOG_ERROR, 0, "fence", "the timeline is valid");
|
||||
close(timeline);
|
||||
return -1;
|
||||
}
|
||||
return timeline;
|
||||
}
|
||||
|
||||
int CreateFenceFromTimeline(int timeline, const char* name, unsigned int totalSteps)
|
||||
{
|
||||
struct sw_sync_create_fence_data {
|
||||
unsigned int value;
|
||||
char name[32];
|
||||
unsigned int fence;
|
||||
};
|
||||
|
||||
struct sw_sync_create_fence_data data = {
|
||||
.value = totalSteps
|
||||
};
|
||||
|
||||
if (strcpy_s(data.name, sizeof(data.name), name)) {
|
||||
HiLogPrint(LOG_CORE, LOG_ERROR, 0, "fence", "Create Fence From Timeline Failed");
|
||||
return -1;
|
||||
}
|
||||
int ret = ioctl(timeline, _IOWR('W', 0, struct sw_sync_create_fence_data), &data);
|
||||
if (ret != 0) {
|
||||
HiLogPrint(LOG_CORE, LOG_ERROR, 0, "fence", " data.fence are invalid");
|
||||
return -1;
|
||||
}
|
||||
return data.fence;
|
||||
}
|
||||
|
||||
int FenceHold(int fd, int timeout)
|
||||
{
|
||||
int ret = 0;
|
||||
if (fd < 0) {
|
||||
HiLogPrint(LOG_CORE, LOG_ERROR, 0, "fence", "the fd is invalid");
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct pollfd pollfds = {
|
||||
.fd = fd,
|
||||
.events = POLLIN | POLLERR,
|
||||
};
|
||||
|
||||
do {
|
||||
ret = poll(&pollfds, 1, timeout);
|
||||
} while (ret == -1 && errno == EINTR);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int TimelineActivate(int timeline, unsigned int step)
|
||||
{
|
||||
int ret = ioctl(timeline, _IOW('W', 1, unsigned int), &step);
|
||||
if (ret != 0) {
|
||||
return errno;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
enum FenceStatus FenceGetStatus(int fd)
|
||||
{
|
||||
int ret = FenceHold(fd, 0);
|
||||
|
||||
enum FenceStatus status = ACTIVE;
|
||||
if (ret < 0) {
|
||||
status = ERROR;
|
||||
} else if (ret > 0) {
|
||||
status = SIGNALED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int FenceMerge(const char* name, int fd1, int fd2)
|
||||
{
|
||||
int result_code;
|
||||
struct sync_merge_data sync_merge_data = {};
|
||||
if (strcpy_s(sync_merge_data.name, sizeof(sync_merge_data.name), name)) {
|
||||
HiLogPrint(LOG_CORE, LOG_ERROR, 0, "fence", "FenceMerge strcpy name failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fd1 >= 0 && fd2 < 0) {
|
||||
sync_merge_data.fd2 = fd1;
|
||||
result_code = ioctl(fd1, SYNC_IOC_MERGE, &sync_merge_data);
|
||||
}
|
||||
|
||||
if (fd1 < 0 && fd2 >= 0) {
|
||||
sync_merge_data.fd2 = fd2;
|
||||
result_code = ioctl(fd2, SYNC_IOC_MERGE, &sync_merge_data);
|
||||
}
|
||||
|
||||
if (fd1 >= 0 && fd2 >= 0) {
|
||||
sync_merge_data.fd2 = fd2;
|
||||
result_code = ioctl(fd1, SYNC_IOC_MERGE, &sync_merge_data);
|
||||
}
|
||||
|
||||
if (fd1 < 0 && fd2 < 0) {
|
||||
HiLogPrint(LOG_CORE, LOG_ERROR, 0, "fence", "fd1 and fd2 are invalid");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (result_code < 0) {
|
||||
HiLogPrint(LOG_CORE, LOG_ERROR, 0, "fence", "merge failed %{public}d", errno);
|
||||
return result_code;
|
||||
}
|
||||
return sync_merge_data.fence;
|
||||
}
|
||||
|
@ -1,64 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import("//build/test.gni")
|
||||
|
||||
module_out_path = "graphic_2d/fence"
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":fence_fd_test" ]
|
||||
}
|
||||
|
||||
## UnitTest fence_test {{{
|
||||
ohos_unittest("fence_fd_test") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "fence_fd_test.cpp" ]
|
||||
|
||||
deps = [ ":fence_test_common" ]
|
||||
|
||||
external_deps = [ "hilog:libhilog" ]
|
||||
}
|
||||
|
||||
## UnitTest fence_test }}}
|
||||
|
||||
## Build fence_test_common.a {{{
|
||||
config("fence_test_common_public_config") {
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
"-Dprivate=public",
|
||||
"-Dprotected=public",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_static_library("fence_test_common") {
|
||||
visibility = [ ":*" ]
|
||||
testonly = true
|
||||
|
||||
public_configs = [ ":fence_test_common_public_config" ]
|
||||
|
||||
public_deps = [
|
||||
"//foundation/graphic/graphic_2d:libfence",
|
||||
"//foundation/graphic/graphic_2d/utils:libgraphic_utils",
|
||||
]
|
||||
|
||||
public_external_deps = [ "graphic_surface:surface" ]
|
||||
|
||||
subsystem_name = "graphic"
|
||||
part_name = "graphic_2d"
|
||||
}
|
||||
## Build fence_test_common.a }}}
|
@ -1,94 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "fence_fd_test.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <thread>
|
||||
|
||||
#include <linux/sync_file.h>
|
||||
#include "test_header.h"
|
||||
|
||||
namespace OHOS {
|
||||
void FenceFdTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void FenceFdTest::TearDownTestCase()
|
||||
{
|
||||
csurf = nullptr;
|
||||
producer = nullptr;
|
||||
psurf = nullptr;
|
||||
}
|
||||
|
||||
void FenceFdTest::OnBufferAvailable()
|
||||
{
|
||||
}
|
||||
|
||||
namespace {
|
||||
HWTEST_F(FenceFdTest, BufferQueueFenceItem, testing::ext::TestSize.Level0)
|
||||
{
|
||||
PART("EnvConditions") {
|
||||
STEP("surf create success.") {
|
||||
csurf = IConsumerSurface::Create();
|
||||
STEP_ASSERT_NE(csurf, nullptr);
|
||||
csurf->RegisterConsumerListener(this);
|
||||
producer = csurf->GetProducer();
|
||||
STEP_ASSERT_NE(producer, nullptr);
|
||||
psurf = Surface::CreateSurfaceAsProducer(producer);
|
||||
STEP_ASSERT_NE(psurf, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
PART("CaseDescription") {
|
||||
sptr<SurfaceBuffer> buffer = nullptr;
|
||||
int32_t releaseFence = 0;
|
||||
GSError ret = GSERROR_INTERNAL;
|
||||
|
||||
STEP("1. Check release fence fd") {
|
||||
ret = psurf->RequestBuffer(buffer, releaseFence, requestConfig);
|
||||
STEP_ASSERT_EQ(ret, GSERROR_OK);
|
||||
STEP_ASSERT_EQ(releaseFence, -1);
|
||||
STEP_ASSERT_NE(buffer, nullptr);
|
||||
}
|
||||
|
||||
STEP("2. Check acquire fence from FlushBuffer to AcquireBuffer") {
|
||||
int32_t acquireFence = 1;
|
||||
ret = psurf->FlushBuffer(buffer, acquireFence, flushConfig);
|
||||
STEP_ASSERT_EQ(ret, GSERROR_OK);
|
||||
|
||||
int32_t outAcquireFence = 0;
|
||||
ret = csurf->AcquireBuffer(buffer, outAcquireFence, timestamp, damage);
|
||||
STEP_ASSERT_EQ(ret, GSERROR_OK);
|
||||
STEP_ASSERT_EQ(outAcquireFence, acquireFence);
|
||||
}
|
||||
|
||||
STEP("3. Check this release fence and the release fence of the next RequestBuffer") {
|
||||
int32_t newReleaseFence = 2;
|
||||
ret = csurf->ReleaseBuffer(buffer, newReleaseFence);
|
||||
STEP_ASSERT_EQ(ret, GSERROR_OK);
|
||||
|
||||
int32_t outReleaseFence = 0;
|
||||
ret = psurf->RequestBuffer(buffer, outReleaseFence, requestConfig);
|
||||
STEP_ASSERT_EQ(ret, GSERROR_OK);
|
||||
STEP_ASSERT_NE(buffer, nullptr);
|
||||
STEP_ASSERT_EQ(outReleaseFence, newReleaseFence);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
} // namespace OHOS
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* 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 FRAMEWORKS_FENCE_TEST_UNITTEST_FD_TEST_H
|
||||
#define FRAMEWORKS_FENCE_TEST_UNITTEST_FD_TEST_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <surface.h>
|
||||
#include "fence.h"
|
||||
#include "iconsumer_surface.h"
|
||||
|
||||
namespace OHOS {
|
||||
class FenceFdTest : public testing::Test, public IBufferConsumerListenerClazz {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
|
||||
virtual void OnBufferAvailable() override;
|
||||
|
||||
static inline BufferRequestConfig requestConfig = {
|
||||
.width = 0x100,
|
||||
.height = 0x100,
|
||||
.strideAlignment = 0x8,
|
||||
.format = GRAPHIC_PIXEL_FMT_RGBA_8888,
|
||||
.usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
|
||||
.timeout = 0,
|
||||
};
|
||||
static inline BufferFlushConfig flushConfig = {
|
||||
.damage = { .w = 0x100, .h = 0x100, },
|
||||
};
|
||||
static inline int64_t timestamp = 0;
|
||||
static inline Rect damage = {};
|
||||
static inline sptr<IConsumerSurface> csurf = nullptr;
|
||||
static inline sptr<IBufferProducer> producer = nullptr;
|
||||
static inline sptr<Surface> psurf = nullptr;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_FENCE_TEST_UNITTEST_FD_TEST_H
|
@ -197,7 +197,7 @@ int32_t OH_NativeImage_ReleaseNativeWindowBuffer(OH_NativeImage* image,
|
||||
}
|
||||
|
||||
|
||||
int32_t OH_ConsumerSuface_SetDefaultUsage(OH_NativeImage* image, uint64_t usage)
|
||||
int32_t OH_ConsumerSurface_SetDefaultUsage(OH_NativeImage* image, uint64_t usage)
|
||||
{
|
||||
if (image == nullptr || image->consumer == nullptr) {
|
||||
BLOGE("parameter error");
|
||||
@ -206,7 +206,7 @@ int32_t OH_ConsumerSuface_SetDefaultUsage(OH_NativeImage* image, uint64_t usage)
|
||||
return image->consumer->SetDefaultUsage(usage);
|
||||
}
|
||||
|
||||
int32_t OH_ConsumerSuface_SetDefaultSize(OH_NativeImage* image, int32_t width, int32_t height)
|
||||
int32_t OH_ConsumerSurface_SetDefaultSize(OH_NativeImage* image, int32_t width, int32_t height)
|
||||
{
|
||||
if (image == nullptr || image->consumer == nullptr || width <= 0 || height <= 0) {
|
||||
BLOGE("parameter error");
|
||||
|
@ -15,7 +15,7 @@ group("test") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
"systemtest:systemtest",
|
||||
"systemtest:unittest",
|
||||
"unittest:unittest",
|
||||
]
|
||||
}
|
||||
|
@ -16,14 +16,14 @@ import("//foundation/graphic/graphic_2d/graphic_config.gni")
|
||||
|
||||
module_out_path = "graphic_2d/surfaceimage"
|
||||
|
||||
group("systemtest") {
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":native_image_system_test" ]
|
||||
deps = [ ":native_image_system_test_st" ]
|
||||
}
|
||||
|
||||
## SystemTest native_image_system_test {{{
|
||||
ohos_systemtest("native_image_system_test") {
|
||||
ohos_unittest("native_image_system_test_st") {
|
||||
module_out_path = module_out_path
|
||||
sources = []
|
||||
if (surface_enable_gpu) {
|
||||
|
@ -1350,43 +1350,43 @@ HWTEST_F(NativeImageTest, OH_ConsumerSurface_Create002, Function | MediumTest |
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: OH_ConsumerSuface_SetDefaultUsage
|
||||
* Function: OH_ConsumerSurface_SetDefaultUsage
|
||||
* Type: Function
|
||||
* Rank: Important(1)
|
||||
* EnvConditions: N/A
|
||||
* CaseDescription: 1. call OH_ConsumerSuface_SetDefaultUsage
|
||||
* CaseDescription: 1. call OH_ConsumerSurface_SetDefaultUsage
|
||||
* 2. check ret
|
||||
* @tc.require: issueI5KG61
|
||||
*/
|
||||
HWTEST_F(NativeImageTest, OH_ConsumerSuface_SetDefaultUsage001, Function | MediumTest | Level1)
|
||||
HWTEST_F(NativeImageTest, OH_ConsumerSurface_SetDefaultUsage001, Function | MediumTest | Level1)
|
||||
{
|
||||
uint64_t usage = BUFFER_USAGE_CPU_READ;
|
||||
OH_NativeImage* consumerSurface = OH_ConsumerSurface_Create();
|
||||
ASSERT_NE(consumerSurface, nullptr);
|
||||
ASSERT_EQ(OH_ConsumerSuface_SetDefaultUsage(nullptr, usage), SURFACE_ERROR_INVALID_PARAM);
|
||||
ASSERT_EQ(OH_ConsumerSuface_SetDefaultUsage(consumerSurface, usage), GSERROR_OK);
|
||||
ASSERT_EQ(OH_ConsumerSurface_SetDefaultUsage(nullptr, usage), SURFACE_ERROR_INVALID_PARAM);
|
||||
ASSERT_EQ(OH_ConsumerSurface_SetDefaultUsage(consumerSurface, usage), GSERROR_OK);
|
||||
OH_NativeImage_Destroy(&consumerSurface);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: OH_ConsumerSuface_SetDefaultSize
|
||||
* Function: OH_ConsumerSurface_SetDefaultSize
|
||||
* Type: Function
|
||||
* Rank: Important(1)
|
||||
* EnvConditions: N/A
|
||||
* CaseDescription: 1. call OH_ConsumerSuface_SetDefaultSize
|
||||
* CaseDescription: 1. call OH_ConsumerSurface_SetDefaultSize
|
||||
* 2. check ret
|
||||
* @tc.require: issueI5KG61
|
||||
*/
|
||||
HWTEST_F(NativeImageTest, OH_ConsumerSuface_SetDefaultSize001, Function | MediumTest | Level1)
|
||||
HWTEST_F(NativeImageTest, OH_ConsumerSurface_SetDefaultSize001, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t width = 100;
|
||||
int32_t height = 100;
|
||||
OH_NativeImage* consumerSurface = OH_ConsumerSurface_Create();
|
||||
ASSERT_NE(consumerSurface, nullptr);
|
||||
ASSERT_EQ(OH_ConsumerSuface_SetDefaultSize(nullptr, 1, 1), SURFACE_ERROR_INVALID_PARAM);
|
||||
ASSERT_EQ(OH_ConsumerSuface_SetDefaultSize(consumerSurface, 0, -1), SURFACE_ERROR_INVALID_PARAM);
|
||||
ASSERT_EQ(OH_ConsumerSuface_SetDefaultSize(consumerSurface, 1, -1), SURFACE_ERROR_INVALID_PARAM);
|
||||
ASSERT_EQ(OH_ConsumerSuface_SetDefaultSize(consumerSurface, width, height), GSERROR_OK);
|
||||
ASSERT_EQ(OH_ConsumerSurface_SetDefaultSize(nullptr, 1, 1), SURFACE_ERROR_INVALID_PARAM);
|
||||
ASSERT_EQ(OH_ConsumerSurface_SetDefaultSize(consumerSurface, 0, -1), SURFACE_ERROR_INVALID_PARAM);
|
||||
ASSERT_EQ(OH_ConsumerSurface_SetDefaultSize(consumerSurface, 1, -1), SURFACE_ERROR_INVALID_PARAM);
|
||||
ASSERT_EQ(OH_ConsumerSurface_SetDefaultSize(consumerSurface, width, height), GSERROR_OK);
|
||||
OH_NativeImage_Destroy(&consumerSurface);
|
||||
}
|
||||
}
|
@ -93,7 +93,7 @@ void RSGraphicTest::TearDown()
|
||||
}
|
||||
|
||||
RSGraphicTestDirector::Instance().FlushMessage();
|
||||
RSGraphicTestDirector::Instance().WaitForVSync();
|
||||
WaitTimeout(RSParameterParse::Instance().testCaseWaitTime);
|
||||
|
||||
const ::testing::TestInfo* const testInfo =
|
||||
::testing::UnitTest::GetInstance()->current_test_info();
|
||||
@ -131,7 +131,7 @@ void RSGraphicTest::TearDown()
|
||||
|
||||
GetRootNode()->ResetTestSurface();
|
||||
RSGraphicTestDirector::Instance().FlushMessage();
|
||||
RSGraphicTestDirector::Instance().WaitForVSync();
|
||||
WaitTimeout(RSParameterParse::Instance().testCaseWaitTime);
|
||||
|
||||
++imageWriteId_;
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ RSGraphicTestDirector::~RSGraphicTestDirector()
|
||||
{
|
||||
rootNode_->screenSurfaceNode_->RemoveFromTree();
|
||||
rsUiDirector_->SendMessages();
|
||||
vsyncWaiter_ = nullptr;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
void RSGraphicTestDirector::Run()
|
||||
@ -122,7 +122,6 @@ void RSGraphicTestDirector::Run()
|
||||
[handler](const std::function<void()>& task, uint32_t delay) { handler->PostTask(task); });
|
||||
runner->Run();
|
||||
|
||||
vsyncWaiter_ = std::make_shared<VSyncWaiter>(handler_, RSParameterParse::Instance().vsyncRate);
|
||||
screenId_ = RSInterfaces::GetInstance().GetDefaultScreenId();
|
||||
|
||||
auto defaultDisplay = DisplayManager::GetInstance().GetDefaultDisplay();
|
||||
@ -138,7 +137,7 @@ void RSGraphicTestDirector::Run()
|
||||
|
||||
rsUiDirector_->SetRSSurfaceNode(rootNode_->screenSurfaceNode_);
|
||||
rsUiDirector_->SendMessages();
|
||||
WaitForVSync();
|
||||
sleep(1);
|
||||
|
||||
ResetImagePath();
|
||||
}
|
||||
|
@ -171,8 +171,8 @@ GPU_SUBHEALTH_MONITORING:
|
||||
WAIT_ACQUIRE_FENCE_TIME: {type: UINT64, desc: wait acquire fence time}
|
||||
FRAME_RATE: {type: INT32, desc: real frame rate}
|
||||
|
||||
COMMIT_TRANSACTION_DATA:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, desc: receive large commit transaction data}
|
||||
IPC_DATA_OVER_ERROR:
|
||||
__BASE: {type: STATISTIC, level: MINOR, desc: receive large commit transaction data}
|
||||
PID: {type: INT32, desc: application pid}
|
||||
UID: {type: INT32, desc: application uid}
|
||||
BUNDLE_NAME: {type: STRING, desc: application package name}
|
||||
|
@ -291,7 +291,7 @@ OH_NativeImage* OH_ConsumerSurface_Create();
|
||||
* @since 13
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OH_ConsumerSuface_SetDefaultUsage(OH_NativeImage* image, uint64_t usage);
|
||||
int32_t OH_ConsumerSurface_SetDefaultUsage(OH_NativeImage* image, uint64_t usage);
|
||||
|
||||
/**
|
||||
* @brief Set the default size of the <b>OH_NativeImage</b>.\n
|
||||
@ -306,7 +306,7 @@ int32_t OH_ConsumerSuface_SetDefaultUsage(OH_NativeImage* image, uint64_t usage)
|
||||
* @since 13
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OH_ConsumerSuface_SetDefaultSize(OH_NativeImage* image, int32_t width, int32_t height);
|
||||
int32_t OH_ConsumerSurface_SetDefaultSize(OH_NativeImage* image, int32_t width, int32_t height);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -128,6 +128,7 @@ JsBrush::JsBrush(const Brush& brush)
|
||||
JsBrush::~JsBrush()
|
||||
{
|
||||
delete brush_;
|
||||
brush_ = nullptr;
|
||||
}
|
||||
|
||||
napi_value JsBrush::SetColor(napi_env env, napi_callback_info info)
|
||||
|
@ -111,8 +111,7 @@ napi_value JsFont::Constructor(napi_env env, napi_callback_info info)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
status = napi_wrap(env, jsThis, jsFont,
|
||||
JsFont::Destructor, nullptr, nullptr);
|
||||
status = napi_wrap_async_finalizer(env, jsThis, jsFont, JsFont::Destructor, nullptr, nullptr, 0);
|
||||
if (status != napi_ok) {
|
||||
delete jsFont;
|
||||
ROSEN_LOGE("Failed to wrap native instance");
|
||||
|
@ -144,6 +144,7 @@ JsPen::JsPen(const Pen& pen)
|
||||
JsPen::~JsPen()
|
||||
{
|
||||
delete pen_;
|
||||
pen_ = nullptr;
|
||||
}
|
||||
|
||||
napi_value JsPen::SetColor(napi_env env, napi_callback_info info)
|
||||
|
@ -77,9 +77,7 @@ napi_value JsRegion::Constructor(napi_env env, napi_callback_info info)
|
||||
status = napi_wrap(env, jsThis, jsRegion,
|
||||
JsRegion::Destructor, nullptr, nullptr);
|
||||
if (status != napi_ok) {
|
||||
if (jsRegion != nullptr) {
|
||||
delete jsRegion;
|
||||
}
|
||||
delete jsRegion;
|
||||
ROSEN_LOGE("JsRegion::Constructor Failed to wrap native instance");
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ bool ParseContextFilePath(napi_env env, napi_value* argv, std::shared_ptr<FontAr
|
||||
return false;
|
||||
} else if (valueType == napi_string) {
|
||||
if (!ConvertFromJsValue(env, argv[ARGC_ONE], context->filePath)) {
|
||||
std::string errMessage("ParseContextFilePath ConvertFromJsValue failed, context->filePath = ");
|
||||
std::string errMessage("Failed to convert file path:");
|
||||
errMessage += context->filePath;
|
||||
context->status = napi_invalid_arg;
|
||||
context->errMessage = errMessage;
|
||||
@ -59,7 +59,7 @@ napi_value JsFontCollection::Constructor(napi_env env, napi_callback_info info)
|
||||
napi_value jsThis = nullptr;
|
||||
napi_status status = napi_get_cb_info(env, info, &argCount, nullptr, &jsThis, nullptr);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("failed from napi_get_cb_info");
|
||||
TEXT_LOGE("Failed to get params");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ napi_value JsFontCollection::Constructor(napi_env env, napi_callback_info info)
|
||||
JsFontCollection::Destructor, nullptr, nullptr);
|
||||
if (status != napi_ok) {
|
||||
delete jsFontCollection;
|
||||
TEXT_LOGE("failed from napi_wrap");
|
||||
TEXT_LOGE("Failed to wrap font collection");
|
||||
return nullptr;
|
||||
}
|
||||
return jsThis;
|
||||
@ -136,14 +136,14 @@ napi_value JsFontCollection::GetGlobalInstance(napi_env env, napi_callback_info
|
||||
napi_value object = nullptr;
|
||||
status = napi_new_instance(env, constructor, 0, nullptr, &object);
|
||||
if (status != napi_ok || !object) {
|
||||
TEXT_LOGE("Failed to instantiate instance");
|
||||
TEXT_LOGE("Failed to new instance");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JsFontCollection* jsFontCollection = nullptr;
|
||||
status = napi_unwrap(env, object, reinterpret_cast<void**>(&jsFontCollection));
|
||||
if (status != napi_ok || !jsFontCollection) {
|
||||
TEXT_LOGE("Failed to unwrap JsFontCollection");
|
||||
TEXT_LOGE("Failed to unwrap font collection");
|
||||
return nullptr;
|
||||
}
|
||||
jsFontCollection->fontcollection_ = OHOS::Rosen::FontCollection::Create();
|
||||
@ -161,7 +161,7 @@ bool JsFontCollection::SpiltAbsoluteFontPath(std::string& absolutePath)
|
||||
{
|
||||
auto iter = absolutePath.find_first_of(':');
|
||||
if (iter == std::string::npos) {
|
||||
TEXT_LOGE("font file directory is not absolute path");
|
||||
TEXT_LOGE("Failed to find separator in path:%{public}s", absolutePath.c_str());
|
||||
return false;
|
||||
}
|
||||
std::string head = absolutePath.substr(0, iter);
|
||||
@ -180,9 +180,11 @@ bool JsFontCollection::GetResourcePartData(napi_env env, ResourceInfo& info, nap
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
bool isArray = false;
|
||||
if (napi_is_array(env, paramsNApi, &isArray) != napi_ok) {
|
||||
TEXT_LOGE("Failed to get array type");
|
||||
return false;
|
||||
}
|
||||
if (!isArray) {
|
||||
TEXT_LOGE("Invalid array type");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -203,7 +205,7 @@ bool JsFontCollection::GetResourcePartData(napi_env env, ResourceInfo& info, nap
|
||||
napi_get_value_int32(env, indexValue, &num);
|
||||
info.params.emplace_back(std::to_string(num));
|
||||
} else {
|
||||
TEXT_LOGE("invalid argument %{public}d", valueType);
|
||||
TEXT_LOGE("Invalid value type %{public}d", valueType);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -311,7 +313,7 @@ bool JsFontCollection::ParseResourcePath(const std::string familyName, ResourceI
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
TEXT_LOGE("incorrect path type of font file");
|
||||
TEXT_LOGE("Invalid resource type %{public}d", info.type);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -319,20 +321,20 @@ bool JsFontCollection::ParseResourcePath(const std::string familyName, ResourceI
|
||||
|
||||
bool JsFontCollection::GetFontFileProperties(const std::string path, const std::string familyName)
|
||||
{
|
||||
size_t datalen;
|
||||
|
||||
if (fontcollection_ == nullptr) {
|
||||
TEXT_LOGE("fontcollection_ is nullptr");
|
||||
TEXT_LOGE("Font collection is nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
char tmpPath[PATH_MAX] = {0};
|
||||
if (realpath(path.c_str(), tmpPath) == nullptr) {
|
||||
TEXT_LOGE("Path is invalid");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ifstream f(tmpPath);
|
||||
if (!f.good()) {
|
||||
TEXT_LOGE("Failed to access %{public}s, %{public}s", tmpPath, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -347,7 +349,7 @@ bool JsFontCollection::GetFontFileProperties(const std::string path, const std::
|
||||
return false;
|
||||
}
|
||||
|
||||
datalen = static_cast<size_t>(ifs.tellg());
|
||||
size_t datalen = static_cast<size_t>(ifs.tellg());
|
||||
if (ifs.fail()) {
|
||||
ifs.close();
|
||||
return false;
|
||||
@ -362,12 +364,15 @@ bool JsFontCollection::GetFontFileProperties(const std::string path, const std::
|
||||
std::unique_ptr<char[]> buffer = std::make_unique<char[]>(datalen);
|
||||
ifs.read(buffer.get(), datalen);
|
||||
if (!ifs.good()) {
|
||||
TEXT_LOGE("Failed to read %{public}s, data len %{public}zu, %{public}s",
|
||||
tmpPath, datalen, strerror(errno));
|
||||
ifs.close();
|
||||
return false;
|
||||
}
|
||||
ifs.close();
|
||||
const uint8_t* rawData = reinterpret_cast<uint8_t*>(buffer.get());
|
||||
if (!fontcollection_->LoadFont(familyName.c_str(), rawData, datalen)) {
|
||||
TEXT_LOGE("Failed to load font %{public}s", familyName.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -379,19 +384,20 @@ napi_value JsFontCollection::OnLoadFont(napi_env env, napi_callback_info info)
|
||||
napi_value argv[ARGC_TWO] = {nullptr};
|
||||
if (napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr) != napi_ok ||
|
||||
argc < ARGC_TWO) {
|
||||
TEXT_LOGE("Failed to get argument, argc %{public}zu", argc);
|
||||
return nullptr;
|
||||
}
|
||||
std::string familyName;
|
||||
std::string familySrc;
|
||||
if (!ConvertFromJsValue(env, argv[0], familyName)) {
|
||||
TEXT_LOGE("OnLoadFont argv[0] convert fail");
|
||||
TEXT_LOGE("Failed to convert argv[0]");
|
||||
return nullptr;
|
||||
}
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
napi_typeof(env, argv[1], &valueType);
|
||||
if (valueType != napi_object) {
|
||||
if (!ConvertFromJsValue(env, argv[1], familySrc)) {
|
||||
TEXT_LOGE("OnLoadFont argv[1] convert fail");
|
||||
TEXT_LOGE("Failed to convert argv[1]");
|
||||
return nullptr;
|
||||
}
|
||||
if (!SpiltAbsoluteFontPath(familySrc) || !GetFontFileProperties(familySrc, familyName)) {
|
||||
|
@ -29,7 +29,7 @@ napi_value JsParagraphBuilder::Constructor(napi_env env, napi_callback_info info
|
||||
napi_value argv[ARGC_TWO] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argCount, argv, &jsThis, nullptr);
|
||||
if (status != napi_ok || argCount != ARGC_TWO) {
|
||||
TEXT_LOGE("JsParagraphBuilder::Constructor Argc is invalid: %{public}zu", argCount);
|
||||
TEXT_LOGE("Failed to get parameter, argc %{public}zu, ret %{public}d", argCount, status);
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
TypographyStyle typographyStyle;
|
||||
@ -46,14 +46,14 @@ napi_value JsParagraphBuilder::Constructor(napi_env env, napi_callback_info info
|
||||
|
||||
std::shared_ptr<FontCollection> fontCollection = jsFontCollection->GetFontCollection();
|
||||
std::unique_ptr<TypographyCreate> typographyCreate = TypographyCreate::Create(typographyStyle, fontCollection);
|
||||
|
||||
if (!typographyCreate) {
|
||||
TEXT_LOGE("JsParagraphBuilder::Constructor TypographyCreate Create error");
|
||||
TEXT_LOGE("Failed to create typography creator");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "TypographyCreate Create error.");
|
||||
}
|
||||
|
||||
JsParagraphBuilder* jsParagraphBuilder = new(std::nothrow) JsParagraphBuilder();
|
||||
if (!jsParagraphBuilder) {
|
||||
TEXT_LOGE("JsParagraphBuilder::Constructor jsParagraphBuilder Create error");
|
||||
TEXT_LOGE("Failed to create paragraph builder");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "JsParagraphBuilder Create error.");
|
||||
}
|
||||
jsParagraphBuilder->SetTypographyCreate(std::move(typographyCreate));
|
||||
@ -61,8 +61,8 @@ napi_value JsParagraphBuilder::Constructor(napi_env env, napi_callback_info info
|
||||
status = napi_wrap(env, jsThis, jsParagraphBuilder,
|
||||
JsParagraphBuilder::Destructor, nullptr, nullptr);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("Failed to wrap paragraphy builder, ret %{public}d", status);
|
||||
delete jsParagraphBuilder;
|
||||
TEXT_LOGE("JsParagraphBuilder::Constructor Failed to wrap native instance");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -89,19 +89,19 @@ napi_value JsParagraphBuilder::Init(napi_env env, napi_value exportObj)
|
||||
napi_status status = napi_define_class(env, CLASS_NAME.c_str(), NAPI_AUTO_LENGTH, Constructor, nullptr,
|
||||
sizeof(properties) / sizeof(properties[0]), properties, &constructor);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("JsParagraphBuilder::Init Failed to define FontCollection class");
|
||||
TEXT_LOGE("Failed to define class, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
status = napi_create_reference(env, constructor, 1, &constructor_);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("JsParagraphBuilder::Init Failed to create reference of constructor");
|
||||
TEXT_LOGE("Failed to create reference");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
status = napi_set_named_property(env, exportObj, CLASS_NAME.c_str(), constructor);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("JsParagraphBuilder::Init Failed to set constructor");
|
||||
TEXT_LOGE("Failed to set named property, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
return exportObj;
|
||||
@ -195,24 +195,25 @@ napi_value JsParagraphBuilder::AddPlaceholder(napi_env env, napi_callback_info i
|
||||
napi_value JsParagraphBuilder::OnAddPlaceholder(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (typographyCreate_ == nullptr) {
|
||||
TEXT_LOGE("OnAddPlaceholder typographyCreate_ is null");
|
||||
TEXT_LOGE("Typography creator is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
TEXT_LOGE("JsParagraphBuilder::AddPlaceholder Argc is invalid: %{public}zu", argc);
|
||||
TEXT_LOGE("Failed to get parameter, argc %{public}zu, ret %{public}d", argc, status);
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
if (argv[0] == nullptr || napi_typeof(env, argv[0], &valueType) != napi_ok || valueType != napi_object) {
|
||||
TEXT_LOGE("JsParagraphBuilder::AddPlaceholder Argv[0] is invalid");
|
||||
TEXT_LOGE("Invalid argv[0]");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
PlaceholderSpan placeholderSpan;
|
||||
bool res = GetPlaceholderSpanFromJS(env, argv[0], placeholderSpan);
|
||||
if (!res) {
|
||||
TEXT_LOGE("Failed to get placeholder from js");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
typographyCreate_->AppendPlaceholder(placeholderSpan);
|
||||
@ -245,17 +246,20 @@ napi_value JsParagraphBuilder::AppendSymbol(napi_env env, napi_callback_info inf
|
||||
napi_value JsParagraphBuilder::OnAppendSymbol(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (typographyCreate_ == nullptr) {
|
||||
TEXT_LOGE("Typography creator is null");
|
||||
return nullptr;
|
||||
}
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
if (napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr) != napi_ok ||
|
||||
argc < ARGC_ONE) {
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if ((status != napi_ok) || (argc < ARGC_ONE)) {
|
||||
TEXT_LOGE("Failed to get parameter, argc %{public}zu, ret %{public}d", argc, status);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32_t symbolId = 0;
|
||||
if (!ConvertFromJsNumber(env, argv[0], symbolId)) {
|
||||
TEXT_LOGE("Failed to convert symbol id");
|
||||
return nullptr;
|
||||
}
|
||||
typographyCreate_->AppendSymbol(symbolId);
|
||||
|
@ -34,7 +34,7 @@ napi_value JsParagraph::Constructor(napi_env env, napi_callback_info info)
|
||||
napi_value jsThis = nullptr;
|
||||
napi_status status = napi_get_cb_info(env, info, &argCount, nullptr, &jsThis, nullptr);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("JsParagraph::Constructor failed to napi_get_cb_info");
|
||||
TEXT_LOGE("Failed to get parameter, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ napi_value JsParagraph::Constructor(napi_env env, napi_callback_info info)
|
||||
JsParagraph::Destructor, nullptr, nullptr);
|
||||
if (status != napi_ok) {
|
||||
delete jsParagraph;
|
||||
TEXT_LOGE("JsParagraph::Constructor failed to wrap native instance");
|
||||
TEXT_LOGE("Failed to wrap paragraph, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
return jsThis;
|
||||
@ -90,19 +90,19 @@ napi_value JsParagraph::Init(napi_env env, napi_value exportObj)
|
||||
napi_status status = napi_define_class(env, CLASS_NAME.c_str(), NAPI_AUTO_LENGTH, Constructor, nullptr,
|
||||
sizeof(properties) / sizeof(properties[0]), properties, &constructor);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("Failed to define Paragraph class");
|
||||
TEXT_LOGE("Failed to define paragraph class, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
status = napi_create_reference(env, constructor, 1, &constructor_);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("Failed to create reference of result");
|
||||
TEXT_LOGE("Failed to create reference, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
status = napi_set_named_property(env, exportObj, CLASS_NAME.c_str(), constructor);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("Failed to set result");
|
||||
TEXT_LOGE("Failed to set named property, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
return exportObj;
|
||||
@ -127,19 +127,19 @@ napi_value JsParagraph::Layout(napi_env env, napi_callback_info info)
|
||||
napi_value JsParagraph::OnLayout(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnLayout paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
TEXT_LOGE("JsParagraph::OnLayout Argc is invalid: %{public}zu", argc);
|
||||
TEXT_LOGE("Failed to get parameter, argc %{public}zu, ret %{public}d", argc, status);
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
double width = 0.0;
|
||||
if (!(ConvertFromJsValue(env, argv[0], width))) {
|
||||
TEXT_LOGE("JsParagraph::OnLayout Argv is invalid");
|
||||
TEXT_LOGE("Failed to convert");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
paragraph_->Layout(width);
|
||||
@ -155,14 +155,14 @@ napi_value JsParagraph::Paint(napi_env env, napi_callback_info info)
|
||||
napi_value JsParagraph::OnPaint(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnPaint paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_THREE;
|
||||
napi_value argv[ARGC_THREE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_THREE) {
|
||||
TEXT_LOGE("JsParagraph::OnPaint Argc is invalid: %{public}zu", argc);
|
||||
TEXT_LOGE("Failed to get parameter, argc %{public}zu, ret %{public}d", argc, status);
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
Drawing::JsCanvas* jsCanvas = nullptr;
|
||||
@ -171,7 +171,7 @@ napi_value JsParagraph::OnPaint(napi_env env, napi_callback_info info)
|
||||
napi_unwrap(env, argv[0], reinterpret_cast<void **>(&jsCanvas));
|
||||
if (!jsCanvas || !jsCanvas->GetCanvas() ||
|
||||
!(ConvertFromJsValue(env, argv[ARGC_ONE], x) && ConvertFromJsValue(env, argv[ARGC_TWO], y))) {
|
||||
TEXT_LOGE("JsParagraph::OnPaint Argv is invalid");
|
||||
TEXT_LOGE("Failed to get paint parameter");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
paragraph_->Paint(jsCanvas->GetCanvas(), x, y);
|
||||
@ -188,14 +188,14 @@ napi_value JsParagraph::PaintOnPath(napi_env env, napi_callback_info info)
|
||||
napi_value JsParagraph::OnPaintOnPath(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnPaintOnPath paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_FOUR;
|
||||
napi_value argv[ARGC_FOUR] = { nullptr };
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_FOUR) {
|
||||
TEXT_LOGE("JsParagraph::OnPaintOnPath Argc is invalid: %{public}zu", argc);
|
||||
TEXT_LOGE("Failed to get parameter, argc %{public}zu, ret %{public}d", argc, status);
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
Drawing::JsCanvas* jsCanvas = nullptr;
|
||||
@ -206,7 +206,7 @@ napi_value JsParagraph::OnPaintOnPath(napi_env env, napi_callback_info info)
|
||||
GET_UNWRAP_PARAM(ARGC_ONE, jsPath);
|
||||
if (!jsCanvas || !jsCanvas->GetCanvas() || !jsPath || !jsPath->GetPath() ||
|
||||
!(ConvertFromJsValue(env, argv[ARGC_TWO], hOffset) && ConvertFromJsValue(env, argv[ARGC_THREE], vOffset))) {
|
||||
TEXT_LOGE("JsParagraph::OnPaintOnPath Argv is invalid");
|
||||
TEXT_LOGE("Failed to get paint parameter");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
paragraph_->Paint(jsCanvas->GetCanvas(), jsPath->GetPath(), hOffset, vOffset);
|
||||
@ -223,7 +223,7 @@ napi_value JsParagraph::GetMaxWidth(napi_env env, napi_callback_info info)
|
||||
napi_value JsParagraph::OnGetMaxWidth(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetMaxWidth paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
double maxWidth = paragraph_->GetMaxWidth();
|
||||
@ -239,7 +239,7 @@ napi_value JsParagraph::GetHeight(napi_env env, napi_callback_info info)
|
||||
napi_value JsParagraph::OnGetHeight(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetHeight paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
double height = paragraph_->GetHeight();
|
||||
@ -255,7 +255,7 @@ napi_value JsParagraph::GetLongestLine(napi_env env, napi_callback_info info)
|
||||
napi_value JsParagraph::OnGetLongestLine(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetLongestLine paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
double longestLine = paragraph_->GetActualWidth();
|
||||
@ -271,7 +271,7 @@ napi_value JsParagraph::GetMinIntrinsicWidth(napi_env env, napi_callback_info in
|
||||
napi_value JsParagraph::OnGetMinIntrinsicWidth(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetMinIntrinsicWidth paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
double minIntrinsicWidth = paragraph_->GetMinIntrinsicWidth();
|
||||
@ -287,7 +287,7 @@ napi_value JsParagraph::GetMaxIntrinsicWidth(napi_env env, napi_callback_info in
|
||||
napi_value JsParagraph::OnGetMaxIntrinsicWidth(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetMaxIntrinsicWidth paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
double maxIntrinsicWidth = paragraph_->GetMaxIntrinsicWidth();
|
||||
@ -303,7 +303,7 @@ napi_value JsParagraph::GetAlphabeticBaseline(napi_env env, napi_callback_info i
|
||||
napi_value JsParagraph::OnGetAlphabeticBaseline(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetAlphabeticBaseline paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
double alphabeticBaseline = paragraph_->GetAlphabeticBaseline();
|
||||
@ -319,7 +319,7 @@ napi_value JsParagraph::GetIdeographicBaseline(napi_env env, napi_callback_info
|
||||
napi_value JsParagraph::OnGetIdeographicBaseline(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetIdeographicBaseline paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
double ideographicBaseline = paragraph_->GetIdeographicBaseline();
|
||||
@ -335,19 +335,19 @@ napi_value JsParagraph::GetRectsForRange(napi_env env, napi_callback_info info)
|
||||
napi_value JsParagraph::OnGetRectsForRange(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetRectsForRange paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_THREE;
|
||||
napi_value argv[ARGC_THREE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_THREE) {
|
||||
TEXT_LOGE("JsParagraph::OnGetRectsForRange Argc is invalid: %{public}zu", argc);
|
||||
TEXT_LOGE("Failed to get parameter, argc %{public}zu, ret %{public}d", argc, status);
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
if (argv[0] == nullptr || napi_typeof(env, argv[0], &valueType) != napi_ok || valueType != napi_object) {
|
||||
TEXT_LOGE("JsParagraph::OnGetRectsForRange Argv[0] is invalid");
|
||||
TEXT_LOGE("Argv[0] is invalid");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
napi_value tempValue = nullptr;
|
||||
@ -361,7 +361,7 @@ napi_value JsParagraph::OnGetRectsForRange(napi_env env, napi_callback_info info
|
||||
bool isEndOk = ConvertFromJsValue(env, tempValue, end);
|
||||
if (!(isStartOk && isEndOk && ConvertFromJsValue(env, argv[ARGC_ONE], wstyle) &&
|
||||
ConvertFromJsValue(env, argv[ARGC_TWO], hstyle))) {
|
||||
TEXT_LOGE("JsParagraph::OnGetRectsForRange Argv is invalid");
|
||||
TEXT_LOGE("Failed to convert, start ok:%{public}d, end ok:%{public}d", isStartOk, isEndOk);
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
std::vector<TextRect> rectsForRange = paragraph_->GetTextRectsByBoundary(start, end, hstyle, wstyle);
|
||||
@ -384,7 +384,7 @@ napi_value JsParagraph::GetRectsForPlaceholders(napi_env env, napi_callback_info
|
||||
napi_value JsParagraph::OnGetRectsForPlaceholders(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetRectsForPlaceholders paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
std::vector<TextRect> rectsForPlaceholders = paragraph_->GetTextRectsOfPlaceholders();
|
||||
@ -407,20 +407,20 @@ napi_value JsParagraph::GetGlyphPositionAtCoordinate(napi_env env, napi_callback
|
||||
napi_value JsParagraph::OnGetGlyphPositionAtCoordinate(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetGlyphPositionAtCoordinate paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_TWO;
|
||||
napi_value argv[ARGC_TWO] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_TWO) {
|
||||
TEXT_LOGE("JsParagraph::OnGetGlyphPositionAtCoordinate Argc is invalid: %{public}zu", argc);
|
||||
TEXT_LOGE("Failed to get parameter, arg %{public}zu, ret %{public}d", argc, status);
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
double dx = 0.0;
|
||||
double dy = 0.0;
|
||||
if (!(ConvertFromJsValue(env, argv[0], dx) && ConvertFromJsValue(env, argv[1], dy))) {
|
||||
TEXT_LOGE("JsParagraph::OnGetGlyphPositionAtCoordinate Argv is invalid");
|
||||
TEXT_LOGE("Failed to convert");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
IndexAndAffinity positionWithAffinity = paragraph_->GetGlyphIndexByCoordinate(dx, dy);
|
||||
@ -436,19 +436,19 @@ napi_value JsParagraph::GetWordBoundary(napi_env env, napi_callback_info info)
|
||||
napi_value JsParagraph::OnGetWordBoundary(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetWordBoundary paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
TEXT_LOGE("JsParagraph::OnGetWordBoundary Argc is invalid: %{public}zu", argc);
|
||||
TEXT_LOGE("Failed to get parameter, argc %{public}zu, ret %{public}d", argc, status);
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t offset = 0;
|
||||
if (!(ConvertFromJsValue(env, argv[0], offset))) {
|
||||
TEXT_LOGE("JsParagraph::OnGetWordBoundary Argv is invalid");
|
||||
TEXT_LOGE("Failed to convert");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
Boundary range = paragraph_->GetWordBoundaryByIndex(offset);
|
||||
@ -464,7 +464,7 @@ napi_value JsParagraph::GetLineCount(napi_env env, napi_callback_info info)
|
||||
napi_value JsParagraph::OnGetLineCount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetLineCount paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t lineCount = static_cast<size_t>(paragraph_->GetLineCount());
|
||||
@ -480,19 +480,19 @@ napi_value JsParagraph::GetLineHeight(napi_env env, napi_callback_info info)
|
||||
napi_value JsParagraph::OnGetLineHeight(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetLineHeight paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
TEXT_LOGE("JsParagraph::OnGetLineHeight Argc is invalid: %{public}zu", argc);
|
||||
TEXT_LOGE("Failed to get parameter, argc %{public}zu, ret %{public}d", argc, status);
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
int lineNumber = 0;
|
||||
if (!(ConvertFromJsValue(env, argv[0], lineNumber))) {
|
||||
TEXT_LOGE("JsParagraph::OnGetLineHeight Argv is invalid");
|
||||
TEXT_LOGE("Failed to convert");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
double lineHeight = paragraph_->GetLineHeight(lineNumber);
|
||||
@ -508,19 +508,19 @@ napi_value JsParagraph::GetLineWidth(napi_env env, napi_callback_info info)
|
||||
napi_value JsParagraph::OnGetLineWidth(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetLineWidth paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
TEXT_LOGE("JsParagraph::OnGetLineWidth Argc is invalid: %{public}zu", argc);
|
||||
TEXT_LOGE("Failed to get parameter, argc %{public}zu, ret %{public}d", argc, status);
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
int lineNumber = 0;
|
||||
if (!(ConvertFromJsValue(env, argv[0], lineNumber))) {
|
||||
TEXT_LOGE("JsParagraph::OnGetLineWidth Argv is invalid");
|
||||
TEXT_LOGE("Failed to convert line number");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
double lineWidth = paragraph_->GetLineWidth(lineNumber);
|
||||
@ -536,7 +536,7 @@ napi_value JsParagraph::DidExceedMaxLines(napi_env env, napi_callback_info info)
|
||||
napi_value JsParagraph::OnDidExceedMaxLines(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnDidExceedMaxLines paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
bool didExceedMaxLines = paragraph_->DidExceedMaxLines();
|
||||
@ -552,7 +552,7 @@ napi_value JsParagraph::GetActualTextRange(napi_env env, napi_callback_info info
|
||||
napi_value JsParagraph::OnGetActualTextRange(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetActualTextRange paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
@ -560,17 +560,17 @@ napi_value JsParagraph::OnGetActualTextRange(napi_env env, napi_callback_info in
|
||||
napi_value argv[ARGC_TWO] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_TWO) {
|
||||
TEXT_LOGE("JsParagraph::OnGetActualTextRange Argc is invalid: %{public}zu", argc);
|
||||
TEXT_LOGE("Failed to get parameter, argc %{public}zu, ret %{public}d", argc, status);
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
int lineNumber = 0;
|
||||
if (!(ConvertFromJsValue(env, argv[0], lineNumber))) {
|
||||
TEXT_LOGE("JsParagraph::OnGetActualTextRange Argv is invalid");
|
||||
TEXT_LOGE("Failed to convert line number");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
bool includeSpaces = false;
|
||||
if (!(ConvertFromJsValue(env, argv[1], includeSpaces))) {
|
||||
TEXT_LOGE("JsParagraph::OnGetActualTextRange Argv is invalid");
|
||||
TEXT_LOGE("Failed to convert include spaces");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
OHOS::Rosen::Boundary range = paragraph_->GetActualTextRange(lineNumber, includeSpaces);
|
||||
@ -592,7 +592,7 @@ napi_value JsParagraph::GetLineMetrics(napi_env env, napi_callback_info info)
|
||||
napi_value JsParagraph::OnGetLineMetrics(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetLineMetrics paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
std::vector<LineMetrics> vectorLineMetrics = paragraph_->GetLineMetrics();
|
||||
@ -609,23 +609,24 @@ napi_value JsParagraph::OnGetLineMetrics(napi_env env, napi_callback_info info)
|
||||
napi_value JsParagraph::OnGetLineMetricsAt(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetLineMetricsAt paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
TEXT_LOGE("JsParagraph::OnLayout Argc is invalid: %{public}zu", argc);
|
||||
TEXT_LOGE("Failed to get parameter, argc %{public}zu, ret %{public}d", argc, status);
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
int lineNumber = 0;
|
||||
if (!(ConvertFromJsValue(env, argv[0], lineNumber))) {
|
||||
TEXT_LOGE("JsParagraph::OnGetLineMetricsAt Argv is invalid");
|
||||
TEXT_LOGE("Failed to convert line number");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
LineMetrics lineMetrics;
|
||||
if (!paragraph_->GetLineMetricsAt(lineNumber, &lineMetrics)) {
|
||||
TEXT_LOGE("Failed to get line metrics");
|
||||
return nullptr;
|
||||
}
|
||||
return CreateLineMetricsJsValue(env, lineMetrics);
|
||||
@ -640,19 +641,19 @@ napi_value JsParagraph::GetFontMetricsByTextStyle(napi_env env, napi_callback_in
|
||||
napi_value JsParagraph::OnGetFontMetricsByTextStyle(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetFontMetricsByTextStyle paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
TEXT_LOGE("JsParagraph::OnGetFontMetricsByTextStyle Argc is invalid: %{public}zu", argc);
|
||||
TEXT_LOGE("Failed to get parameter, argc %{public}zu, ret %{public}d", argc, status);
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
TextStyle textStyle;
|
||||
if (!GetTextStyleFromJS(env, argv[0], textStyle)) {
|
||||
TEXT_LOGE("JsParagraph::OnGetLineWidth Argv is invalid");
|
||||
TEXT_LOGE("Failed to convert text style");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
|
||||
@ -669,19 +670,19 @@ napi_value JsParagraph::GetLineFontMetrics(napi_env env, napi_callback_info info
|
||||
napi_value JsParagraph::OnGetLineFontMetrics(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (paragraph_ == nullptr) {
|
||||
TEXT_LOGE("JsParagraph::OnGetLineFontMetrics paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_ONE;
|
||||
napi_value argv[ARGC_ONE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_ONE) {
|
||||
TEXT_LOGE("JsParagraph::OnGetLineFontMetrics Argc is invalid: %{public}zu", argc);
|
||||
TEXT_LOGE("Failed to get parameter, argc %{public}zu, ret %{public}d", argc, status);
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
int lineNumber = 0;
|
||||
if (!(ConvertFromJsValue(env, argv[0], lineNumber))) {
|
||||
TEXT_LOGE("JsParagraph::OnGetLineFontMetrics Argv is invalid");
|
||||
TEXT_LOGE("Failed to convert line number");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
|
||||
@ -690,7 +691,7 @@ napi_value JsParagraph::OnGetLineFontMetrics(napi_env env, napi_callback_info in
|
||||
size_t fontMetricsSize = 0;
|
||||
std::vector<Drawing::FontMetrics> grabFontMetrics;
|
||||
if (!paragraph_->GetLineFontMetrics(lineNumber, fontMetricsSize, grabFontMetrics)) {
|
||||
TEXT_LOGE("JsParagraph::OnGetLineFontMetrics GetLineFontMetrics failed");
|
||||
TEXT_LOGE("Failed to get line font metrics");
|
||||
return returnFontMetrics;
|
||||
}
|
||||
|
||||
@ -722,7 +723,7 @@ napi_value JsParagraph::CreateJsTypography(napi_env env, std::unique_ptr<Typogra
|
||||
if (status == napi_ok) {
|
||||
return result;
|
||||
} else {
|
||||
TEXT_LOGE("CreateJsTypography: New instance could not be obtained");
|
||||
TEXT_LOGE("Failed to new instance");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -737,13 +738,13 @@ napi_value JsParagraph::GetTextLines(napi_env env, napi_callback_info info)
|
||||
napi_value JsParagraph::OnGetTextLines(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (!paragraph_) {
|
||||
TEXT_LOGE("JsParagraph::OnGetTextLines paragraph_ is nullptr");
|
||||
TEXT_LOGE("Paragraph is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
std::shared_ptr<Typography> paragraphCopy = paragraph_->CloneSelf();
|
||||
if (!paragraphCopy) {
|
||||
TEXT_LOGE("JsParagraph::OnGetTextLines paragraphCopy is nullptr");
|
||||
TEXT_LOGE("Failed to clone paragraph");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
@ -754,13 +755,13 @@ napi_value JsParagraph::OnGetTextLines(napi_env env, napi_callback_info info)
|
||||
for (std::unique_ptr<TextLineBase>& item : textlineArr) {
|
||||
napi_value itemObject = JsTextLine::CreateTextLine(env, info);
|
||||
if (!itemObject) {
|
||||
TEXT_LOGE("JsParagraph::OnGetTextLines itemObject is null");
|
||||
TEXT_LOGE("Failed to create text line");
|
||||
continue;
|
||||
}
|
||||
JsTextLine* jsTextLine = nullptr;
|
||||
napi_unwrap(env, itemObject, reinterpret_cast<void**>(&jsTextLine));
|
||||
if (!jsTextLine) {
|
||||
TEXT_LOGE("JsParagraph::OnGetTextLines napi_unwrap jsTextLine is null");
|
||||
TEXT_LOGE("Failed to unwrap text line");
|
||||
continue;
|
||||
}
|
||||
jsTextLine->SetTextLine(std::move(item));
|
||||
|
@ -29,13 +29,13 @@ napi_value JsRun::Constructor(napi_env env, napi_callback_info info)
|
||||
napi_value jsThis = nullptr;
|
||||
napi_status status = napi_get_cb_info(env, info, &argCount, nullptr, &jsThis, nullptr);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("JsRun::Constructor failed to napi_get_cb_info");
|
||||
TEXT_LOGE("Failed to get parameter, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JsRun* jsRun = new(std::nothrow) JsRun();
|
||||
if (!jsRun) {
|
||||
TEXT_LOGE("JsRun::Constructor failed to create JsRun");
|
||||
TEXT_LOGE("Failed to new run");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ napi_value JsRun::Constructor(napi_env env, napi_callback_info info)
|
||||
JsRun::Destructor, nullptr, nullptr);
|
||||
if (status != napi_ok) {
|
||||
delete jsRun;
|
||||
TEXT_LOGE("JsRun::Constructor Failed to wrap native instance");
|
||||
TEXT_LOGE("Failed to wrap run, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -65,19 +65,19 @@ napi_value JsRun::Init(napi_env env, napi_value exportObj)
|
||||
napi_status status = napi_define_class(env, CLASS_NAME.c_str(), NAPI_AUTO_LENGTH, Constructor, nullptr,
|
||||
sizeof(properties) / sizeof(properties[0]), properties, &constructor);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("JsRun::Init Failed to define JsRun class");
|
||||
TEXT_LOGE("Failed to define class, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
status = napi_create_reference(env, constructor, 1, &constructor_);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("JsRun::Init Failed to create reference of constructor");
|
||||
TEXT_LOGE("Failed to create reference, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
status = napi_set_named_property(env, exportObj, CLASS_NAME.c_str(), constructor);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("JsRun::Init Failed to set constructor");
|
||||
TEXT_LOGE("Failed to set named property, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -99,13 +99,13 @@ napi_value JsRun::CreateRun(napi_env env, napi_callback_info info)
|
||||
napi_value constructor = nullptr;
|
||||
napi_status status = napi_get_reference_value(env, constructor_, &constructor);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("Failed to get the representation of constructor object");
|
||||
TEXT_LOGE("Failed to get reference, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
status = napi_new_instance(env, constructor, 0, nullptr, &result);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("Failed to instantiate JavaScript font instance");
|
||||
TEXT_LOGE("Failed to new instance, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
return result;
|
||||
@ -129,7 +129,7 @@ napi_value JsRun::GetGlyphCount(napi_env env, napi_callback_info info)
|
||||
napi_value JsRun::OnGetGlyphCount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (!run_) {
|
||||
TEXT_LOGE("JsRun::OnGetGlyphCount run is nullptr");
|
||||
TEXT_LOGE("Run is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "JsRun::OnGetGlyphCount run is nullptr.");
|
||||
}
|
||||
int64_t count = static_cast<int64_t>(run_->GetGlyphCount());
|
||||
@ -145,7 +145,7 @@ napi_value JsRun::GetGlyphs(napi_env env, napi_callback_info info)
|
||||
napi_value JsRun::OnGetGlyphs(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (!run_) {
|
||||
TEXT_LOGE("JsRun::OnGetGlyphs run is nullptr");
|
||||
TEXT_LOGE("Run is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "JsRun::OnGetGlyphs run is nullptr.");
|
||||
}
|
||||
|
||||
@ -169,7 +169,7 @@ napi_value JsRun::GetPositions(napi_env env, napi_callback_info info)
|
||||
napi_value JsRun::OnGetPositions(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (!run_) {
|
||||
TEXT_LOGE("JsRun::OnGetPositions run is nullptr");
|
||||
TEXT_LOGE("Run is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "JsRun::OnGetPositions run is nullptr.");
|
||||
}
|
||||
|
||||
@ -193,7 +193,7 @@ napi_value JsRun::GetOffsets(napi_env env, napi_callback_info info)
|
||||
napi_value JsRun::OnGetOffsets(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (!run_) {
|
||||
TEXT_LOGE("JsRun::OnGetOffsets run is nullptr");
|
||||
TEXT_LOGE("Run is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "JsRun::OnGetOffsets run is nullptr.");
|
||||
}
|
||||
|
||||
@ -217,25 +217,25 @@ napi_value JsRun::GetFont(napi_env env, napi_callback_info info)
|
||||
napi_value JsRun::OnGetFont(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (!run_) {
|
||||
TEXT_LOGE("JsRun::OnGetFont run is nullptr");
|
||||
TEXT_LOGE("Run is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "JsRun::OnGetFont run is nullptr.");
|
||||
}
|
||||
|
||||
std::shared_ptr<Drawing::Font> fontPtr = std::make_shared<Drawing::Font>(run_->GetFont());
|
||||
if (!fontPtr) {
|
||||
TEXT_LOGE("JsRun::OnGetFont fontPtr is nullptr");
|
||||
TEXT_LOGE("Font is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "JsRun::OnGetFont fontPtr is nullptr.");
|
||||
}
|
||||
|
||||
napi_value resultValue = Drawing::JsFont::CreateFont(env, info);
|
||||
if (!resultValue) {
|
||||
TEXT_LOGE("JsRun::OnGetFont JsFont::CreateFont resultValue is null");
|
||||
TEXT_LOGE("Failed to create font");
|
||||
return nullptr;
|
||||
}
|
||||
Drawing::JsFont* jsFont = nullptr;
|
||||
napi_unwrap(env, resultValue, reinterpret_cast<void**>(&jsFont));
|
||||
if (!jsFont) {
|
||||
TEXT_LOGE("JsRun::OnGetFont napi_unwrap jsFont is null");
|
||||
TEXT_LOGE("Failed to unwrap font");
|
||||
return nullptr;
|
||||
}
|
||||
jsFont->SetFont(fontPtr);
|
||||
@ -251,14 +251,14 @@ napi_value JsRun::Paint(napi_env env, napi_callback_info info)
|
||||
napi_value JsRun::OnPaint(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (run_ == nullptr) {
|
||||
TEXT_LOGE("JsRun::OnPaint run is nullptr");
|
||||
TEXT_LOGE("Run is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "JsRun::OnPaint run is nullptr.");
|
||||
}
|
||||
size_t argc = ARGC_THREE;
|
||||
napi_value argv[ARGC_THREE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_THREE) {
|
||||
TEXT_LOGE("JsRun::OnPaint Argc is invalid: %{public}zu", argc);
|
||||
TEXT_LOGE("Failed to get parameter, argc %{public}zu, ret %{public}d", argc, status);
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
Drawing::JsCanvas* jsCanvas = nullptr;
|
||||
@ -267,7 +267,7 @@ napi_value JsRun::OnPaint(napi_env env, napi_callback_info info)
|
||||
napi_unwrap(env, argv[0], reinterpret_cast<void **>(&jsCanvas));
|
||||
if (!jsCanvas || !jsCanvas->GetCanvas() ||
|
||||
!(ConvertFromJsValue(env, argv[ARGC_ONE], x) && ConvertFromJsValue(env, argv[ARGC_TWO], y))) {
|
||||
TEXT_LOGE("JsRun::OnPaint Argv is invalid");
|
||||
TEXT_LOGE("Failed to get paint parameter");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
run_->Paint(jsCanvas->GetCanvas(), x, y);
|
||||
|
@ -28,19 +28,19 @@ napi_value JsTextLine::Constructor(napi_env env, napi_callback_info info)
|
||||
napi_value jsThis = nullptr;
|
||||
napi_status status = napi_get_cb_info(env, info, &argCount, nullptr, &jsThis, nullptr);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("failed to napi_get_cb_info");
|
||||
TEXT_LOGE("Failed to get parameter, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
JsTextLine *jsTextLineBase = new(std::nothrow) JsTextLine();
|
||||
if (!jsTextLineBase) {
|
||||
TEXT_LOGE("failed to create JsTextLine");
|
||||
TEXT_LOGE("Failed to new text line");
|
||||
return nullptr;
|
||||
}
|
||||
status = napi_wrap(env, jsThis, jsTextLineBase,
|
||||
JsTextLine::Destructor, nullptr, nullptr);
|
||||
if (status != napi_ok) {
|
||||
delete jsTextLineBase;
|
||||
TEXT_LOGE("JsTextLine::Constructor Failed to wrap native instance");
|
||||
TEXT_LOGE("Failed to wrap text line, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
return jsThis;
|
||||
@ -60,18 +60,18 @@ napi_value JsTextLine::Init(napi_env env, napi_value exportObj)
|
||||
napi_status status = napi_define_class(env, CLASS_NAME.c_str(), NAPI_AUTO_LENGTH, Constructor, nullptr,
|
||||
sizeof(properties) / sizeof(properties[0]), properties, &constructor);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("Failed to define TextLine class");
|
||||
TEXT_LOGE("Failed to define class, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
status = napi_create_reference(env, constructor, 1, &constructor_);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("Failed to create reference of constructor");
|
||||
TEXT_LOGE("Failed to create reference, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
status = napi_set_named_property(env, exportObj, CLASS_NAME.c_str(), constructor);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("Failed to set constructor");
|
||||
TEXT_LOGE("Failed to set named property, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
return exportObj;
|
||||
@ -92,13 +92,13 @@ napi_value JsTextLine::CreateTextLine(napi_env env, napi_callback_info info)
|
||||
napi_value constructor = nullptr;
|
||||
napi_status status = napi_get_reference_value(env, constructor_, &constructor);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("Failed to get the representation of constructor object");
|
||||
TEXT_LOGE("Failed to get reference, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
status = napi_new_instance(env, constructor, 0, nullptr, &result);
|
||||
if (status != napi_ok) {
|
||||
TEXT_LOGE("Failed to instantiate JavaScript font instance");
|
||||
TEXT_LOGE("Failed to new instance, ret %{public}d", status);
|
||||
return nullptr;
|
||||
}
|
||||
return result;
|
||||
@ -140,7 +140,7 @@ napi_value JsTextLine::Paint(napi_env env, napi_callback_info info)
|
||||
napi_value JsTextLine::OnGetGlyphCount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (textLine_ == nullptr) {
|
||||
TEXT_LOGE("JsTextLine::OnGetGlyphCount textLine_ is nullptr");
|
||||
TEXT_LOGE("Text line is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
@ -151,12 +151,12 @@ napi_value JsTextLine::OnGetGlyphCount(napi_env env, napi_callback_info info)
|
||||
napi_value JsTextLine::OnGetGlyphRuns(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (textLine_ == nullptr) {
|
||||
TEXT_LOGE("JsTextLine::OnGetGlyphRuns TextLine is nullptr");
|
||||
TEXT_LOGE("Text line is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
std::vector<std::unique_ptr<Run>> runs = textLine_->GetGlyphRuns();
|
||||
if (runs.empty()) {
|
||||
TEXT_LOGE("JsTextLine::OnGetGlyphRuns runs is empty");
|
||||
TEXT_LOGE("Run is empty");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
napi_value array = nullptr;
|
||||
@ -165,13 +165,13 @@ napi_value JsTextLine::OnGetGlyphRuns(napi_env env, napi_callback_info info)
|
||||
for (std::unique_ptr<Run>& item : runs) {
|
||||
napi_value itemObject = JsRun::CreateRun(env, info);
|
||||
if (!itemObject) {
|
||||
TEXT_LOGE("JsTextLine::OnGetGlyphRuns itemObject is null");
|
||||
TEXT_LOGE("Failed to create run");
|
||||
continue;
|
||||
}
|
||||
JsRun* jsRun = nullptr;
|
||||
napi_unwrap(env, itemObject, reinterpret_cast<void**>(&jsRun));
|
||||
if (!jsRun) {
|
||||
TEXT_LOGE("JsTextLine::OnGetGlyphRuns napi_unwrap jsRun is null");
|
||||
TEXT_LOGE("Failed to unwrap run");
|
||||
continue;
|
||||
}
|
||||
jsRun->SetRun(std::move(item));
|
||||
@ -184,7 +184,7 @@ napi_value JsTextLine::OnGetGlyphRuns(napi_env env, napi_callback_info info)
|
||||
napi_value JsTextLine::OnGetTextRange(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (textLine_ == nullptr) {
|
||||
TEXT_LOGE("JsTextLine::OnGetTextRange TextLine is nullptr");
|
||||
TEXT_LOGE("Text line is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
|
||||
@ -201,20 +201,20 @@ napi_value JsTextLine::OnGetTextRange(napi_env env, napi_callback_info info)
|
||||
napi_value JsTextLine::OnPaint(napi_env env, napi_callback_info info)
|
||||
{
|
||||
if (textLine_ == nullptr) {
|
||||
TEXT_LOGE("JsTextLine::OnPaint TextLine is nullptr");
|
||||
TEXT_LOGE("Text line is null");
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
size_t argc = ARGC_THREE;
|
||||
napi_value argv[ARGC_THREE] = {nullptr};
|
||||
napi_status status = napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (status != napi_ok || argc < ARGC_THREE) {
|
||||
TEXT_LOGE("JsTextLine::OnPaint Argc is invalid: %{public}zu", argc);
|
||||
TEXT_LOGE("Failed to get paramter, argc %{public}zu, ret %{public}d", argc, status);
|
||||
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
|
||||
}
|
||||
Drawing::JsCanvas* jsCanvas = nullptr;
|
||||
napi_unwrap(env, argv[0], reinterpret_cast<void**>(&jsCanvas));
|
||||
if (!jsCanvas || !jsCanvas->GetCanvas()) {
|
||||
TEXT_LOGE("JsTextLine::OnPaint jsCanvas is nullptr");
|
||||
TEXT_LOGE("Failed to get canvas");
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
double x = 0.0;
|
||||
|
@ -157,10 +157,6 @@ ohos_source_set("skia_paragraph") {
|
||||
"//third_party/skia/modules/skparagraph",
|
||||
]
|
||||
|
||||
if (is_arkui_x) {
|
||||
include_dirs +=
|
||||
[ "//foundation/multimedia/image_framework/mock/native/include/log" ]
|
||||
}
|
||||
defines = [ "OHOS_SUPPORT" ]
|
||||
|
||||
sources = [
|
||||
@ -204,6 +200,7 @@ ohos_source_set("skia_paragraph") {
|
||||
|
||||
if (is_arkui_x) {
|
||||
deps += [
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_${target_os}",
|
||||
"//third_party/bounds_checking_function:libsec_static",
|
||||
"//third_party/skia:skia_$platform",
|
||||
]
|
||||
|
@ -36,6 +36,9 @@ OH_Drawing_Bitmap* OH_Drawing_BitmapCreate()
|
||||
|
||||
void OH_Drawing_BitmapDestroy(OH_Drawing_Bitmap* cBitmap)
|
||||
{
|
||||
if (!cBitmap) {
|
||||
return;
|
||||
}
|
||||
delete CastToBitmap(cBitmap);
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,9 @@ OH_Drawing_Brush* OH_Drawing_BrushCopy(OH_Drawing_Brush* cBrush)
|
||||
|
||||
void OH_Drawing_BrushDestroy(OH_Drawing_Brush* cBrush)
|
||||
{
|
||||
if (!cBrush) {
|
||||
return;
|
||||
}
|
||||
delete CastToBrush(cBrush);
|
||||
}
|
||||
|
||||
|
@ -117,6 +117,9 @@ OH_Drawing_Canvas* OH_Drawing_CanvasCreate()
|
||||
|
||||
void OH_Drawing_CanvasDestroy(OH_Drawing_Canvas* cCanvas)
|
||||
{
|
||||
if (!cCanvas) {
|
||||
return;
|
||||
}
|
||||
delete CastToCanvas(cCanvas);
|
||||
}
|
||||
|
||||
|
@ -77,5 +77,8 @@ OH_Drawing_ColorFilter* OH_Drawing_ColorFilterCreateLuma()
|
||||
|
||||
void OH_Drawing_ColorFilterDestroy(OH_Drawing_ColorFilter* cColorFilter)
|
||||
{
|
||||
if (!cColorFilter) {
|
||||
return;
|
||||
}
|
||||
delete CastToColorFilter(cColorFilter);
|
||||
}
|
||||
|
@ -112,5 +112,8 @@ void OH_Drawing_FilterGetColorFilter(OH_Drawing_Filter* cFliter, OH_Drawing_Colo
|
||||
|
||||
void OH_Drawing_FilterDestroy(OH_Drawing_Filter* cFilter)
|
||||
{
|
||||
if (!cFilter) {
|
||||
return;
|
||||
}
|
||||
delete CastToFilter(cFilter);
|
||||
}
|
||||
|
@ -360,6 +360,9 @@ bool OH_Drawing_FontIsEmbeddedBitmaps(const OH_Drawing_Font* cFont)
|
||||
|
||||
void OH_Drawing_FontDestroy(OH_Drawing_Font* cFont)
|
||||
{
|
||||
if (!cFont) {
|
||||
return;
|
||||
}
|
||||
delete CastToFont(cFont);
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,9 @@ OH_Drawing_Image* OH_Drawing_ImageCreate()
|
||||
|
||||
void OH_Drawing_ImageDestroy(OH_Drawing_Image* cImage)
|
||||
{
|
||||
if (!cImage) {
|
||||
return;
|
||||
}
|
||||
delete CastToImage(cImage);
|
||||
}
|
||||
|
||||
|
@ -53,5 +53,8 @@ OH_Drawing_ImageFilter* OH_Drawing_ImageFilterCreateFromColorFilter(
|
||||
|
||||
void OH_Drawing_ImageFilterDestroy(OH_Drawing_ImageFilter* cImageFilter)
|
||||
{
|
||||
if (!cImageFilter) {
|
||||
return;
|
||||
}
|
||||
delete reinterpret_cast<ImageFilter*>(cImageFilter);
|
||||
}
|
||||
|
@ -34,5 +34,8 @@ OH_Drawing_MaskFilter* OH_Drawing_MaskFilterCreateBlur(OH_Drawing_BlurType blurT
|
||||
|
||||
void OH_Drawing_MaskFilterDestroy(OH_Drawing_MaskFilter* cMaskFilter)
|
||||
{
|
||||
if (!cMaskFilter) {
|
||||
return;
|
||||
}
|
||||
delete CastToMaskFilter(cMaskFilter);
|
||||
}
|
||||
|
@ -65,9 +65,6 @@ OH_Drawing_Matrix* OH_Drawing_MatrixCreate()
|
||||
OH_Drawing_Matrix* OH_Drawing_MatrixCreateRotation(float deg, float x, float y)
|
||||
{
|
||||
Matrix* matrix = new Matrix();
|
||||
if (matrix == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
matrix->Rotate(deg, x, y);
|
||||
return (OH_Drawing_Matrix*)matrix;
|
||||
}
|
||||
@ -75,9 +72,6 @@ OH_Drawing_Matrix* OH_Drawing_MatrixCreateRotation(float deg, float x, float y)
|
||||
OH_Drawing_Matrix* OH_Drawing_MatrixCreateScale(float sx, float sy, float px, float py)
|
||||
{
|
||||
Matrix* matrix = new Matrix();
|
||||
if (matrix == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
matrix->Scale(sx, sy, px, py);
|
||||
return (OH_Drawing_Matrix*)matrix;
|
||||
}
|
||||
@ -85,9 +79,6 @@ OH_Drawing_Matrix* OH_Drawing_MatrixCreateScale(float sx, float sy, float px, fl
|
||||
OH_Drawing_Matrix* OH_Drawing_MatrixCreateTranslation(float dx, float dy)
|
||||
{
|
||||
Matrix* matrix = new Matrix();
|
||||
if (matrix == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
matrix->Translate(dx, dy);
|
||||
return (OH_Drawing_Matrix*)matrix;
|
||||
}
|
||||
@ -357,5 +348,8 @@ OH_Drawing_ErrorCode OH_Drawing_MatrixGetAll(OH_Drawing_Matrix* cMatrix, float v
|
||||
|
||||
void OH_Drawing_MatrixDestroy(OH_Drawing_Matrix* cMatrix)
|
||||
{
|
||||
if (!cMatrix) {
|
||||
return;
|
||||
}
|
||||
delete CastToMatrix(cMatrix);
|
||||
}
|
||||
|
@ -80,6 +80,9 @@ OH_Drawing_Path* OH_Drawing_PathCopy(OH_Drawing_Path* cPath)
|
||||
|
||||
void OH_Drawing_PathDestroy(OH_Drawing_Path* cPath)
|
||||
{
|
||||
if (!cPath) {
|
||||
return;
|
||||
}
|
||||
delete CastToPath(cPath);
|
||||
}
|
||||
|
||||
|
@ -34,9 +34,6 @@ OH_Drawing_PathEffect* OH_Drawing_CreateDashPathEffect(float* intervals, int cou
|
||||
return nullptr;
|
||||
}
|
||||
NativeHandle<PathEffect>* pathEffectHandle = new NativeHandle<PathEffect>;
|
||||
if (pathEffectHandle == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
pathEffectHandle->value = PathEffect::CreateDashPathEffect(intervals, count, phase);
|
||||
if (pathEffectHandle->value == nullptr) {
|
||||
delete pathEffectHandle;
|
||||
@ -47,5 +44,8 @@ OH_Drawing_PathEffect* OH_Drawing_CreateDashPathEffect(float* intervals, int cou
|
||||
|
||||
void OH_Drawing_PathEffectDestroy(OH_Drawing_PathEffect* cPathEffect)
|
||||
{
|
||||
if (!cPathEffect) {
|
||||
return;
|
||||
}
|
||||
delete Helper::CastTo<OH_Drawing_PathEffect*, NativeHandle<PathEffect>*>(cPathEffect);
|
||||
}
|
||||
|
@ -124,6 +124,9 @@ OH_Drawing_Pen* OH_Drawing_PenCopy(OH_Drawing_Pen* cPen)
|
||||
|
||||
void OH_Drawing_PenDestroy(OH_Drawing_Pen* cPen)
|
||||
{
|
||||
if (!cPen) {
|
||||
return;
|
||||
}
|
||||
delete CastToPen(cPen);
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,9 @@ OH_Drawing_Point* OH_Drawing_PointCreate(float x, float y)
|
||||
|
||||
void OH_Drawing_PointDestroy(OH_Drawing_Point* cPoint)
|
||||
{
|
||||
if (!cPoint) {
|
||||
return;
|
||||
}
|
||||
delete CastToPoint(cPoint);
|
||||
}
|
||||
|
||||
|
@ -177,5 +177,8 @@ void OH_Drawing_RectCopy(OH_Drawing_Rect* sRect, OH_Drawing_Rect* dRect)
|
||||
|
||||
void OH_Drawing_RectDestroy(OH_Drawing_Rect* cRect)
|
||||
{
|
||||
if (!cRect) {
|
||||
return;
|
||||
}
|
||||
delete CastToRect(cRect);
|
||||
}
|
||||
|
@ -96,6 +96,9 @@ OH_Drawing_Corner_Radii OH_Drawing_RoundRectGetCorner(OH_Drawing_RoundRect* cRou
|
||||
|
||||
void OH_Drawing_RoundRectDestroy(OH_Drawing_RoundRect* cRoundRect)
|
||||
{
|
||||
if (!cRoundRect) {
|
||||
return;
|
||||
}
|
||||
delete CastToRoundRect(cRoundRect);
|
||||
}
|
||||
|
||||
|
@ -37,5 +37,8 @@ OH_Drawing_SamplingOptions* OH_Drawing_SamplingOptionsCreate(OH_Drawing_FilterMo
|
||||
|
||||
void OH_Drawing_SamplingOptionsDestroy(OH_Drawing_SamplingOptions* cSamplingOptions)
|
||||
{
|
||||
if (!cSamplingOptions) {
|
||||
return;
|
||||
}
|
||||
delete CastToSamplingOptions(cSamplingOptions);
|
||||
}
|
@ -231,5 +231,8 @@ OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateTwoPointConicalGradient(co
|
||||
|
||||
void OH_Drawing_ShaderEffectDestroy(OH_Drawing_ShaderEffect* cShaderEffect)
|
||||
{
|
||||
if (!cShaderEffect) {
|
||||
return;
|
||||
}
|
||||
delete CastToShaderEffect(cShaderEffect);
|
||||
}
|
||||
|
@ -31,9 +31,6 @@ OH_Drawing_ShadowLayer* OH_Drawing_ShadowLayerCreate(float blurRadius, float x,
|
||||
return nullptr;
|
||||
}
|
||||
NativeHandle<BlurDrawLooper>* blurDrawLooperHandle = new NativeHandle<BlurDrawLooper>;
|
||||
if (blurDrawLooperHandle == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
blurDrawLooperHandle->value = BlurDrawLooper::CreateBlurDrawLooper(blurRadius, x, y, color);
|
||||
if (blurDrawLooperHandle->value == nullptr) {
|
||||
delete blurDrawLooperHandle;
|
||||
@ -44,5 +41,8 @@ OH_Drawing_ShadowLayer* OH_Drawing_ShadowLayerCreate(float blurRadius, float x,
|
||||
|
||||
void OH_Drawing_ShadowLayerDestroy(OH_Drawing_ShadowLayer* cShadowLayer)
|
||||
{
|
||||
if (!cShadowLayer) {
|
||||
return;
|
||||
}
|
||||
delete Helper::CastTo<OH_Drawing_ShadowLayer*, NativeHandle<BlurDrawLooper>*>(cShadowLayer);
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ OH_Drawing_TextBlob* OH_Drawing_TextBlobCreateFromPosText(const void* text, size
|
||||
if (count <= 0) {
|
||||
return nullptr;
|
||||
}
|
||||
Point* pts = new Point[count];
|
||||
Point* pts = new (std::nothrow) Point[count];
|
||||
if (pts == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -217,5 +217,8 @@ void OH_Drawing_TextBlobDestroy(OH_Drawing_TextBlob* cTextBlob)
|
||||
|
||||
void OH_Drawing_TextBlobBuilderDestroy(OH_Drawing_TextBlobBuilder* cTextBlobBuilder)
|
||||
{
|
||||
if (!cTextBlobBuilder) {
|
||||
return;
|
||||
}
|
||||
delete CastToTextBlobBuilder(cTextBlobBuilder);
|
||||
}
|
||||
|
@ -251,18 +251,6 @@ public:
|
||||
*/
|
||||
bool AsBlendMode();
|
||||
|
||||
/**
|
||||
* @brief Set whether to discount the drawing(for HDR).
|
||||
* @param disableBrightnessRatio setting for HDR ratio.
|
||||
*/
|
||||
void SetForceBrightnessDisable(bool forceBrightnessDisable);
|
||||
|
||||
/**
|
||||
* @brief Queries Whether the current draw can discount.
|
||||
* @return true if can not be discount, otherwise false.
|
||||
*/
|
||||
bool IsForceBrightnessDisable() const { return forceBrightnessDisable_; }
|
||||
|
||||
/**
|
||||
* @brief Sets all Brush contents to their initial values. This is equivalent to replacing
|
||||
* Brush with the result of Brush().
|
||||
@ -279,18 +267,6 @@ public:
|
||||
*/
|
||||
std::shared_ptr<BlurDrawLooper> GetLooper() const;
|
||||
|
||||
/**
|
||||
* @brief Queries the brush HDR state.
|
||||
* @return true if Brush is used for HDR video which has HLG/ST2084 OETF, otherwise false.
|
||||
*/
|
||||
bool IsHdr() const;
|
||||
|
||||
/**
|
||||
* @brief Set HDR state.
|
||||
* @param bool HDR state.
|
||||
*/
|
||||
void SetHdr(bool isHdr);
|
||||
|
||||
friend DRAWING_API bool operator==(const Brush& b1, const Brush& b2);
|
||||
friend DRAWING_API bool operator!=(const Brush& b1, const Brush& b2);
|
||||
|
||||
@ -308,8 +284,6 @@ private:
|
||||
bool antiAlias_;
|
||||
bool blenderEnabled_ = true;
|
||||
bool hasFilter_ = false;
|
||||
bool forceBrightnessDisable_ = false;
|
||||
bool isHdr_ = false;
|
||||
};
|
||||
} // namespace Drawing
|
||||
} // namespace Rosen
|
||||
|
@ -48,6 +48,7 @@ private:
|
||||
class DRAWING_API Canvas : public CoreCanvas {
|
||||
public:
|
||||
Canvas() {}
|
||||
Canvas(DrawingType type) : CoreCanvas(type) {}
|
||||
Canvas(int32_t width, int32_t height) : CoreCanvas(width, height) {}
|
||||
|
||||
virtual Canvas* GetRecordingCanvas() const;
|
||||
@ -94,7 +95,7 @@ protected:
|
||||
|
||||
class DRAWING_API OverDrawCanvas : public Canvas {
|
||||
public:
|
||||
OverDrawCanvas(std::shared_ptr<Drawing::Canvas> canvas)
|
||||
OverDrawCanvas(std::shared_ptr<Drawing::Canvas> canvas) : Canvas(DrawingType::OVER_DRAW)
|
||||
{
|
||||
BuildOverDraw(canvas);
|
||||
}
|
||||
@ -107,7 +108,7 @@ public:
|
||||
|
||||
class DRAWING_API NoDrawCanvas : public Canvas {
|
||||
public:
|
||||
NoDrawCanvas(int32_t width, int32_t height)
|
||||
NoDrawCanvas(int32_t width, int32_t height) : Canvas(DrawingType::NO_DRAW)
|
||||
{
|
||||
BuildNoDraw(width, height);
|
||||
}
|
||||
|
@ -27,6 +27,11 @@
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
namespace Drawing {
|
||||
enum class Clamp {
|
||||
NO,
|
||||
YES,
|
||||
};
|
||||
|
||||
enum ColorType {
|
||||
COLORTYPE_UNKNOWN = 0,
|
||||
COLORTYPE_ALPHA_8,
|
||||
|
@ -101,9 +101,6 @@ public:
|
||||
void SetAntiAlias(bool aa);
|
||||
bool IsAntiAlias() const { return antiAlias_; }
|
||||
|
||||
void SetHDRImage(bool hdrImage);
|
||||
bool IsHDRImage() const { return hdrImage_; }
|
||||
|
||||
void Reset();
|
||||
void Disable();
|
||||
|
||||
@ -124,7 +121,6 @@ private:
|
||||
|
||||
bool blenderEnabled_ = true;
|
||||
bool hasFilter_ = false;
|
||||
bool hdrImage_ = false;
|
||||
Filter filter_;
|
||||
|
||||
std::shared_ptr<ColorSpace> colorSpace_ = nullptr;
|
||||
|
@ -155,6 +155,13 @@ public:
|
||||
*/
|
||||
std::shared_ptr<Surface> MakeSurface(int width, int height) const;
|
||||
|
||||
/**
|
||||
* @brief Returns a compatible Surface, with the specified width and height.
|
||||
* @param imageinfo surface imageinfo
|
||||
* @return A shared pointer to Surface
|
||||
*/
|
||||
std::shared_ptr<Surface> MakeSurface(const ImageInfo& imageinfo) const;
|
||||
|
||||
/**
|
||||
* @brief Gets ImageInfo of Surface.
|
||||
* @return ImageInfo
|
||||
|
@ -48,9 +48,10 @@ public:
|
||||
static std::shared_ptr<ColorFilter> CreateBlendModeColorFilter(ColorQuad c, BlendMode mode);
|
||||
static std::shared_ptr<ColorFilter> CreateComposeColorFilter(ColorFilter& f1, ColorFilter& f2);
|
||||
static std::shared_ptr<ColorFilter> CreateComposeColorFilter(
|
||||
const float (&f1)[MATRIX_SIZE], const float (&f2)[MATRIX_SIZE]);
|
||||
static std::shared_ptr<ColorFilter> CreateMatrixColorFilter(const ColorMatrix& m);
|
||||
static std::shared_ptr<ColorFilter> CreateFloatColorFilter(const float (&f)[MATRIX_SIZE]);
|
||||
const float (&f1)[MATRIX_SIZE], const float (&f2)[MATRIX_SIZE], Clamp clamp = Clamp::YES);
|
||||
static std::shared_ptr<ColorFilter> CreateMatrixColorFilter(const ColorMatrix& m, Clamp clamp = Clamp::YES);
|
||||
static std::shared_ptr<ColorFilter> CreateFloatColorFilter(const float (&f)[MATRIX_SIZE],
|
||||
Clamp clamp = Clamp::YES);
|
||||
static std::shared_ptr<ColorFilter> CreateLinearToSrgbGamma();
|
||||
static std::shared_ptr<ColorFilter> CreateSrgbGammaToLinear();
|
||||
static std::shared_ptr<ColorFilter> CreateOverDrawColorFilter(const ColorQuad colors[OVER_DRAW_COLOR_NUM]);
|
||||
@ -80,17 +81,18 @@ public:
|
||||
}
|
||||
|
||||
ColorFilter(FilterType t, ColorQuad c, BlendMode mode) noexcept;
|
||||
ColorFilter(FilterType t, const ColorMatrix& m) noexcept;
|
||||
ColorFilter(FilterType t, const float f[MATRIX_SIZE]) noexcept;
|
||||
ColorFilter(FilterType t, const ColorMatrix& m, Clamp clamp = Clamp::YES) noexcept;
|
||||
ColorFilter(FilterType t, const float f[MATRIX_SIZE], Clamp clamp = Clamp::YES) noexcept;
|
||||
ColorFilter(FilterType t, ColorFilter& f1, ColorFilter& f2) noexcept;
|
||||
ColorFilter(FilterType t, const float f1[MATRIX_SIZE], const float f2[MATRIX_SIZE]) noexcept;
|
||||
ColorFilter(FilterType t, const float f1[MATRIX_SIZE], const float f2[MATRIX_SIZE],
|
||||
Clamp clamp = Clamp::YES) noexcept;
|
||||
ColorFilter(FilterType t) noexcept;
|
||||
ColorFilter(FilterType t, const ColorQuad colors[OVER_DRAW_COLOR_NUM]) noexcept;
|
||||
std::shared_ptr<Data> Serialize() const;
|
||||
bool Deserialize(std::shared_ptr<Data> data);
|
||||
bool AsAColorMatrix(scalar matrix[MATRIX_SIZE]) const;
|
||||
|
||||
void InitWithCompose(const float f1[MATRIX_SIZE], const float f2[MATRIX_SIZE]);
|
||||
void InitWithCompose(const float f1[MATRIX_SIZE], const float f2[MATRIX_SIZE], Clamp clamp = Clamp::YES);
|
||||
|
||||
protected:
|
||||
ColorFilter() noexcept;
|
||||
|
@ -96,7 +96,10 @@ public:
|
||||
template<typename T>
|
||||
T* GetImpl() const
|
||||
{
|
||||
return fontMgrImpl_->DowncastingTo<T>();
|
||||
if (fontMgrImpl_) {
|
||||
return fontMgrImpl_->DowncastingTo<T>();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,10 +113,22 @@ public:
|
||||
*/
|
||||
void SetHash(uint32_t hash);
|
||||
|
||||
/**
|
||||
* @brief Get serialized data size of typeface. Firstly set size before GetSize().
|
||||
* @return serialized data size
|
||||
*/
|
||||
uint32_t GetSize();
|
||||
|
||||
/**
|
||||
* @brief Set serialized data size of typeface.
|
||||
*/
|
||||
void SetSize(uint32_t size);
|
||||
|
||||
private:
|
||||
std::shared_ptr<TypefaceImpl> typefaceImpl_;
|
||||
static std::function<bool(std::shared_ptr<Typeface>)> registerTypefaceCallBack_;
|
||||
static std::function<bool(std::shared_ptr<Typeface>)> unregisterTypefaceCallBack_;
|
||||
uint32_t size_ = 0;
|
||||
};
|
||||
} // namespace Drawing
|
||||
} // namespace Rosen
|
||||
|
@ -170,32 +170,11 @@ bool Brush::AsBlendMode()
|
||||
return StaticFactory::AsBlendMode(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
* In these cases, disable HDR paintfilter by setting forceBrightnessDisable_ as true:
|
||||
* 1. Filter(effect): HDR paintfilter is already applied when take snapshot.
|
||||
* 2. UIFirst: Disable main thread since sub thread is already applied.
|
||||
*/
|
||||
void Brush::SetForceBrightnessDisable(bool forceBrightnessDisable)
|
||||
{
|
||||
forceBrightnessDisable_ = forceBrightnessDisable;
|
||||
}
|
||||
|
||||
bool Brush::IsHdr() const
|
||||
{
|
||||
return isHdr_;
|
||||
}
|
||||
|
||||
void Brush::SetHdr(bool isHdr)
|
||||
{
|
||||
isHdr_ = isHdr;
|
||||
}
|
||||
|
||||
bool operator==(const Brush& b1, const Brush& b2)
|
||||
{
|
||||
return b1.color_ == b2.color_ && b1.blendMode_ == b2.blendMode_ && b1.shaderEffect_ == b2.shaderEffect_ &&
|
||||
b1.blender_ == b2.blender_ && b1.blenderEnabled_ == b2.blenderEnabled_ && b1.colorSpace_ == b2.colorSpace_ &&
|
||||
b1.filter_ == b2.filter_ && b1.antiAlias_ == b2.antiAlias_ && b1.blurDrawLooper_ == b2.blurDrawLooper_ &&
|
||||
b1.isHdr_ == b2.isHdr_;
|
||||
b1.filter_ == b2.filter_ && b1.antiAlias_ == b2.antiAlias_ && b1.blurDrawLooper_ == b2.blurDrawLooper_;
|
||||
}
|
||||
|
||||
bool operator!=(const Brush& b1, const Brush& b2)
|
||||
@ -219,8 +198,6 @@ void Brush::Dump(std::string& out) const
|
||||
out += " isAntiAlias:" + std::string(antiAlias_ ? "true" : "false");
|
||||
out += " blenderEnabled:" + std::string(blenderEnabled_ ? "true" : "false");
|
||||
out += " hasFilter:" + std::string(hasFilter_ ? "true" : "false");
|
||||
out += " forceBrightnessDisable:" + std::string(forceBrightnessDisable_ ? "true" : "false");
|
||||
out += " isHDR:" + std::string(isHdr_ ? "true" : "false");
|
||||
out += ']';
|
||||
}
|
||||
} // namespace Drawing
|
||||
|
@ -109,6 +109,12 @@ CoreCanvas::CoreCanvas() : impl_(ImplFactory::CreateCoreCanvasImpl())
|
||||
defaultPaint_.SetStyle(Drawing::Paint::PaintStyle::PAINT_FILL);
|
||||
}
|
||||
|
||||
CoreCanvas::CoreCanvas(DrawingType type) : impl_(ImplFactory::CreateCoreCanvasImpl(type))
|
||||
{
|
||||
defaultPaint_.SetAntiAlias(true);
|
||||
defaultPaint_.SetStyle(Drawing::Paint::PaintStyle::PAINT_FILL);
|
||||
}
|
||||
|
||||
CoreCanvas::CoreCanvas(void* rawCanvas) : impl_(ImplFactory::CreateCoreCanvasImpl(rawCanvas))
|
||||
{
|
||||
defaultPaint_.SetAntiAlias(true);
|
||||
|
@ -134,6 +134,7 @@ private:
|
||||
class DRAWING_API CoreCanvas {
|
||||
public:
|
||||
CoreCanvas();
|
||||
CoreCanvas(DrawingType type);
|
||||
explicit CoreCanvas(void* rawCanvas);
|
||||
virtual ~CoreCanvas() {}
|
||||
void Bind(const Bitmap& bitmap);
|
||||
|
@ -45,7 +45,6 @@ Paint::Paint(const Paint& other) noexcept
|
||||
blender_ = other.blender_;
|
||||
blenderEnabled_ = other.blenderEnabled_;
|
||||
blurDrawLooper_ = other.blurDrawLooper_;
|
||||
hdrImage_ = other.hdrImage_;
|
||||
}
|
||||
|
||||
Paint::Paint(const Color& c, std::shared_ptr<ColorSpace> colorSpace) noexcept
|
||||
@ -74,7 +73,6 @@ Paint& Paint::operator=(const Paint& other)
|
||||
blender_ = other.blender_;
|
||||
blenderEnabled_ = other.blenderEnabled_;
|
||||
blurDrawLooper_ = other.blurDrawLooper_;
|
||||
hdrImage_ = other.hdrImage_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -239,11 +237,6 @@ void Paint::SetAntiAlias(bool aa)
|
||||
antiAlias_ = aa;
|
||||
}
|
||||
|
||||
void Paint::SetHDRImage(bool hdrImage)
|
||||
{
|
||||
hdrImage_ = hdrImage;
|
||||
}
|
||||
|
||||
void Paint::Reset()
|
||||
{
|
||||
antiAlias_ = false;
|
||||
@ -256,7 +249,6 @@ void Paint::Reset()
|
||||
cap_ = Pen::CapStyle::DEFAULT_CAP;
|
||||
|
||||
hasFilter_ = false;
|
||||
hdrImage_ = false;
|
||||
filter_.Reset();
|
||||
|
||||
colorSpace_ = nullptr;
|
||||
@ -322,7 +314,6 @@ void Paint::Dump(std::string& out) const
|
||||
out += " cap:" + std::to_string(static_cast<int>(cap_));
|
||||
out += " blenderEnabled:" + std::string(blenderEnabled_ ? "true" : "false");
|
||||
out += " hasFilter:" + std::string(hasFilter_ ? "true" : "false");
|
||||
out += " hdrImage:" + std::string(hdrImage_ ? "true" : "false");
|
||||
out += ']';
|
||||
}
|
||||
|
||||
|
@ -111,6 +111,11 @@ std::shared_ptr<Surface> Surface::MakeSurface(int width, int height) const
|
||||
return impl_->MakeSurface(width, height);
|
||||
}
|
||||
|
||||
std::shared_ptr<Surface> Surface::MakeSurface(const ImageInfo& imageinfo) const
|
||||
{
|
||||
return impl_->MakeSurface(imageinfo);
|
||||
}
|
||||
|
||||
ImageInfo Surface::GetImageInfo()
|
||||
{
|
||||
std::shared_ptr<Canvas> canvas = GetCanvas();
|
||||
|
@ -28,16 +28,16 @@ ColorFilter::ColorFilter(FilterType t, ColorQuad c, BlendMode mode) noexcept : C
|
||||
impl_->InitWithBlendMode(c, mode);
|
||||
}
|
||||
|
||||
ColorFilter::ColorFilter(FilterType t, const ColorMatrix& m) noexcept : ColorFilter()
|
||||
ColorFilter::ColorFilter(FilterType t, const ColorMatrix& m, Clamp clamp) noexcept : ColorFilter()
|
||||
{
|
||||
type_ = t;
|
||||
impl_->InitWithColorMatrix(m);
|
||||
impl_->InitWithColorMatrix(m, clamp);
|
||||
}
|
||||
|
||||
ColorFilter::ColorFilter(FilterType t, const float f[20]) noexcept : ColorFilter()
|
||||
ColorFilter::ColorFilter(FilterType t, const float f[20], Clamp clamp) noexcept : ColorFilter()
|
||||
{
|
||||
type_ = t;
|
||||
impl_->InitWithColorFloat(f);
|
||||
impl_->InitWithColorFloat(f, clamp);
|
||||
}
|
||||
|
||||
ColorFilter::ColorFilter(FilterType t, ColorFilter& f1, ColorFilter& f2) noexcept : ColorFilter()
|
||||
@ -47,10 +47,10 @@ ColorFilter::ColorFilter(FilterType t, ColorFilter& f1, ColorFilter& f2) noexcep
|
||||
}
|
||||
|
||||
ColorFilter::ColorFilter(FilterType t, const float f1[MATRIX_SIZE],
|
||||
const float f2[MATRIX_SIZE]) noexcept : ColorFilter()
|
||||
const float f2[MATRIX_SIZE], Clamp clamp) noexcept : ColorFilter()
|
||||
{
|
||||
type_ = t;
|
||||
impl_->InitWithCompose(f1, f2);
|
||||
impl_->InitWithCompose(f1, f2, clamp);
|
||||
}
|
||||
|
||||
ColorFilter::ColorFilter(FilterType t,
|
||||
@ -60,10 +60,10 @@ ColorFilter::ColorFilter(FilterType t,
|
||||
impl_->InitWithOverDrawColor(colors);
|
||||
}
|
||||
|
||||
void ColorFilter::InitWithCompose(const float f1[MATRIX_SIZE], const float f2[MATRIX_SIZE])
|
||||
void ColorFilter::InitWithCompose(const float f1[MATRIX_SIZE], const float f2[MATRIX_SIZE], Clamp clamp)
|
||||
{
|
||||
type_ = ColorFilter::FilterType::COMPOSE;
|
||||
impl_->InitWithCompose(f1, f2);
|
||||
impl_->InitWithCompose(f1, f2, clamp);
|
||||
}
|
||||
|
||||
ColorFilter::ColorFilter(FilterType t) noexcept : ColorFilter()
|
||||
@ -112,19 +112,19 @@ std::shared_ptr<ColorFilter> ColorFilter::CreateComposeColorFilter(ColorFilter&
|
||||
}
|
||||
|
||||
std::shared_ptr<ColorFilter> ColorFilter::CreateComposeColorFilter(
|
||||
const float (&f1)[MATRIX_SIZE], const float (&f2)[MATRIX_SIZE])
|
||||
const float (&f1)[MATRIX_SIZE], const float (&f2)[MATRIX_SIZE], Clamp clamp)
|
||||
{
|
||||
return std::make_shared<ColorFilter>(ColorFilter::FilterType::COMPOSE, f1, f2);
|
||||
return std::make_shared<ColorFilter>(ColorFilter::FilterType::COMPOSE, f1, f2, clamp);
|
||||
}
|
||||
|
||||
std::shared_ptr<ColorFilter> ColorFilter::CreateMatrixColorFilter(const ColorMatrix& m)
|
||||
std::shared_ptr<ColorFilter> ColorFilter::CreateMatrixColorFilter(const ColorMatrix& m, Clamp clamp)
|
||||
{
|
||||
return std::make_shared<ColorFilter>(ColorFilter::FilterType::MATRIX, m);
|
||||
return std::make_shared<ColorFilter>(ColorFilter::FilterType::MATRIX, m, clamp);
|
||||
}
|
||||
|
||||
std::shared_ptr<ColorFilter> ColorFilter::CreateFloatColorFilter(const float (&f)[MATRIX_SIZE])
|
||||
std::shared_ptr<ColorFilter> ColorFilter::CreateFloatColorFilter(const float (&f)[MATRIX_SIZE], Clamp clamp)
|
||||
{
|
||||
return std::make_shared<ColorFilter>(ColorFilter::FilterType::MATRIX, f);
|
||||
return std::make_shared<ColorFilter>(ColorFilter::FilterType::MATRIX, f, clamp);
|
||||
}
|
||||
|
||||
std::shared_ptr<ColorFilter> ColorFilter::CreateLinearToSrgbGamma()
|
||||
|
@ -37,6 +37,16 @@ std::unique_ptr<CoreCanvasImpl> ImplFactory::CreateCoreCanvasImpl()
|
||||
return EngineImplFactory::CreateCoreCanvas();
|
||||
}
|
||||
|
||||
std::unique_ptr<CoreCanvasImpl> ImplFactory::CreateCoreCanvasImpl(DrawingType type)
|
||||
{
|
||||
#ifdef ENABLE_DDGR_OPTIMIZE
|
||||
if (SystemProperties::GetGpuApiType() == GpuApiType::DDGR) {
|
||||
return DDGRImplFactory::CreateCoreCanvas();
|
||||
}
|
||||
#endif
|
||||
return EngineImplFactory::CreateCoreCanvas(type);
|
||||
}
|
||||
|
||||
std::unique_ptr<CoreCanvasImpl> ImplFactory::CreateCoreCanvasImpl(void* rawCanvas)
|
||||
{
|
||||
#ifdef ENABLE_DDGR_OPTIMIZE
|
||||
|
@ -55,6 +55,7 @@ namespace Drawing {
|
||||
class ImplFactory {
|
||||
public:
|
||||
static std::unique_ptr<CoreCanvasImpl> CreateCoreCanvasImpl();
|
||||
static std::unique_ptr<CoreCanvasImpl> CreateCoreCanvasImpl(DrawingType type);
|
||||
static std::unique_ptr<CoreCanvasImpl> CreateCoreCanvasImpl(void* rawCanvas);
|
||||
static std::unique_ptr<CoreCanvasImpl> CreateCoreCanvasImpl(int32_t width, int32_t height);
|
||||
static std::unique_ptr<DataImpl> CreateDataImpl();
|
||||
|
@ -37,12 +37,12 @@ public:
|
||||
~ColorFilterImpl() override {}
|
||||
|
||||
virtual void InitWithBlendMode(ColorQuad c, BlendMode mode) = 0;
|
||||
virtual void InitWithColorMatrix(const ColorMatrix& m) = 0;
|
||||
virtual void InitWithColorFloat(const float f[20]) = 0;
|
||||
virtual void InitWithColorMatrix(const ColorMatrix& m, Clamp clamp) = 0;
|
||||
virtual void InitWithColorFloat(const float f[20], Clamp clamp) = 0;
|
||||
virtual void InitWithLinearToSrgbGamma() = 0;
|
||||
virtual void InitWithSrgbGammaToLinear() = 0;
|
||||
virtual void InitWithCompose(const ColorFilter& f1, const ColorFilter& f2) = 0;
|
||||
virtual void InitWithCompose(const float f1[MATRIX_SIZE], const float f2[MATRIX_SIZE]) = 0;
|
||||
virtual void InitWithCompose(const float f1[MATRIX_SIZE], const float f2[MATRIX_SIZE], Clamp clamp) = 0;
|
||||
virtual void InitWithOverDrawColor(const ColorQuad colors[OVER_DRAW_COLOR_NUM]) = 0;
|
||||
virtual void Compose(const ColorFilter& f) = 0;
|
||||
virtual void InitWithLuma() = 0;
|
||||
|
@ -57,6 +57,7 @@ public:
|
||||
virtual std::shared_ptr<Image> GetImageSnapshot() const = 0;
|
||||
virtual std::shared_ptr<Image> GetImageSnapshot(const RectI& bounds) const = 0;
|
||||
virtual std::shared_ptr<Surface> MakeSurface(int width, int height) const = 0;
|
||||
virtual std::shared_ptr<Surface> MakeSurface(const ImageInfo& imageInfo) const = 0;
|
||||
virtual BackendTexture GetBackendTexture(BackendAccess access) const = 0;
|
||||
virtual void FlushAndSubmit(bool syncCpu) = 0;
|
||||
virtual void Flush(FlushInfo *drawingflushInfo = nullptr) = 0;
|
||||
|
@ -48,6 +48,19 @@ SkiaCanvas::SkiaCanvas() : skiaCanvas_(std::make_shared<SkCanvas>())
|
||||
skCanvas_ = skiaCanvas_.get();
|
||||
}
|
||||
|
||||
SkiaCanvas::SkiaCanvas(DrawingType type)
|
||||
{
|
||||
switch (type) {
|
||||
case DrawingType::OVER_DRAW:
|
||||
case DrawingType::NO_DRAW:
|
||||
skiaCanvas_ = nullptr;
|
||||
skCanvas_ = nullptr;
|
||||
break;
|
||||
default:
|
||||
SkiaCanvas();
|
||||
}
|
||||
}
|
||||
|
||||
SkiaCanvas::SkiaCanvas(const std::shared_ptr<SkCanvas>& skCanvas) : skiaCanvas_(skCanvas)
|
||||
{
|
||||
skCanvas_ = skiaCanvas_.get();
|
||||
|
@ -49,6 +49,7 @@ public:
|
||||
static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER;
|
||||
|
||||
SkiaCanvas();
|
||||
SkiaCanvas(DrawingType type);
|
||||
explicit SkiaCanvas(const std::shared_ptr<SkCanvas>& skCanvas);
|
||||
SkiaCanvas(int32_t width, int32_t height);
|
||||
~SkiaCanvas() override {};
|
||||
|
@ -29,21 +29,26 @@ namespace Rosen {
|
||||
namespace Drawing {
|
||||
SkiaColorFilter::SkiaColorFilter() noexcept : filter_(nullptr) {}
|
||||
|
||||
static SkColorFilters::Clamp ConverToSkClamp(Drawing::Clamp clamp)
|
||||
{
|
||||
return (clamp == Drawing::Clamp::YES ? SkColorFilters::Clamp::kYes : SkColorFilters::Clamp::kNo);
|
||||
}
|
||||
|
||||
void SkiaColorFilter::InitWithBlendMode(ColorQuad c, BlendMode mode)
|
||||
{
|
||||
filter_ = SkColorFilters::Blend(static_cast<SkColor>(c), static_cast<SkBlendMode>(mode));
|
||||
}
|
||||
|
||||
void SkiaColorFilter::InitWithColorMatrix(const ColorMatrix& m)
|
||||
void SkiaColorFilter::InitWithColorMatrix(const ColorMatrix& m, Clamp clamp)
|
||||
{
|
||||
scalar dst[ColorMatrix::MATRIX_SIZE];
|
||||
m.GetArray(dst);
|
||||
filter_ = SkColorFilters::Matrix(dst);
|
||||
filter_ = SkColorFilters::Matrix(dst, ConverToSkClamp(clamp));
|
||||
}
|
||||
|
||||
void SkiaColorFilter::InitWithColorFloat(const float f[20])
|
||||
void SkiaColorFilter::InitWithColorFloat(const float f[20], Clamp clamp)
|
||||
{
|
||||
filter_ = SkColorFilters::Matrix(f);
|
||||
filter_ = SkColorFilters::Matrix(f, ConverToSkClamp(clamp));
|
||||
}
|
||||
|
||||
void SkiaColorFilter::InitWithLinearToSrgbGamma()
|
||||
@ -73,9 +78,10 @@ void SkiaColorFilter::Compose(const ColorFilter& f)
|
||||
}
|
||||
}
|
||||
|
||||
void SkiaColorFilter::InitWithCompose(const float f1[MATRIX_SIZE], const float f2[MATRIX_SIZE])
|
||||
void SkiaColorFilter::InitWithCompose(const float f1[MATRIX_SIZE], const float f2[MATRIX_SIZE], Clamp clamp)
|
||||
{
|
||||
filter_ = SkColorFilters::Compose(SkColorFilters::Matrix(f1), SkColorFilters::Matrix(f2));
|
||||
filter_ = SkColorFilters::Compose(SkColorFilters::Matrix(f1, ConverToSkClamp(clamp)),
|
||||
SkColorFilters::Matrix(f2, ConverToSkClamp(clamp)));
|
||||
}
|
||||
|
||||
void SkiaColorFilter::InitWithOverDrawColor(const ColorQuad colors[OVER_DRAW_COLOR_NUM])
|
||||
|
@ -36,12 +36,12 @@ public:
|
||||
}
|
||||
|
||||
void InitWithBlendMode(ColorQuad c, BlendMode mode) override;
|
||||
void InitWithColorMatrix(const ColorMatrix& m) override;
|
||||
void InitWithColorFloat(const float f[20]) override;
|
||||
void InitWithColorMatrix(const ColorMatrix& m, Clamp clamp = Clamp::YES) override;
|
||||
void InitWithColorFloat(const float f[20], Clamp clamp = Clamp::YES) override;
|
||||
void InitWithLinearToSrgbGamma() override;
|
||||
void InitWithSrgbGammaToLinear() override;
|
||||
void InitWithCompose(const ColorFilter& f1, const ColorFilter& f2) override;
|
||||
void InitWithCompose(const float f1[MATRIX_SIZE], const float f2[MATRIX_SIZE]) override;
|
||||
void InitWithCompose(const float f1[MATRIX_SIZE], const float f2[MATRIX_SIZE], Clamp clamp = Clamp::YES) override;
|
||||
void Compose(const ColorFilter& f) override;
|
||||
void InitWithLuma() override;
|
||||
void InitWithOverDrawColor(const ColorQuad colors[OVER_DRAW_COLOR_NUM]) override;
|
||||
|
@ -57,6 +57,11 @@ std::unique_ptr<CoreCanvasImpl> SkiaImplFactory::CreateCoreCanvas()
|
||||
return std::make_unique<SkiaCanvas>();
|
||||
}
|
||||
|
||||
std::unique_ptr<CoreCanvasImpl> SkiaImplFactory::CreateCoreCanvas(DrawingType type)
|
||||
{
|
||||
return std::make_unique<SkiaCanvas>(type);
|
||||
}
|
||||
|
||||
std::unique_ptr<CoreCanvasImpl> SkiaImplFactory::CreateCoreCanvas(void* rawCanvas)
|
||||
{
|
||||
auto skCanvasPtr = reinterpret_cast<std::shared_ptr<SkCanvas>*>(rawCanvas);
|
||||
|
@ -55,6 +55,7 @@ namespace Drawing {
|
||||
class SkiaImplFactory {
|
||||
public:
|
||||
static std::unique_ptr<CoreCanvasImpl> CreateCoreCanvas();
|
||||
static std::unique_ptr<CoreCanvasImpl> CreateCoreCanvas(DrawingType type);
|
||||
static std::unique_ptr<CoreCanvasImpl> CreateCoreCanvas(void* rawCanvas);
|
||||
static std::unique_ptr<CoreCanvasImpl> CreateCoreCanvas(int32_t width, int32_t height);
|
||||
static std::unique_ptr<DataImpl> CreateData();
|
||||
|
@ -87,6 +87,7 @@ std::shared_ptr<Surface> SkiaStaticFactory::MakeFromBackendTexture(GPUContext* g
|
||||
return SkiaSurface::MakeFromBackendTexture(gpuContext, info, origin, sampleCnt, colorType,
|
||||
colorSpace, deleteVkImage, cleanHelper);
|
||||
}
|
||||
|
||||
std::shared_ptr<Surface> SkiaStaticFactory::MakeRenderTarget(GPUContext* gpuContext,
|
||||
bool budgeted, const ImageInfo& imageInfo)
|
||||
{
|
||||
|
@ -417,6 +417,24 @@ std::shared_ptr<Surface> SkiaSurface::MakeSurface(int width, int height) const
|
||||
return drawingSurface;
|
||||
}
|
||||
|
||||
std::shared_ptr<Surface> SkiaSurface::MakeSurface(const ImageInfo& imageInfo) const
|
||||
{
|
||||
if (skSurface_ == nullptr) {
|
||||
LOGD("skSurface is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
SkImageInfo skImageInfo = SkiaImageInfo::ConvertToSkImageInfo(imageInfo);
|
||||
auto surface = skSurface_->makeSurface(skImageInfo);
|
||||
if (surface == nullptr) {
|
||||
LOGD("SkiaSurface::MakeSurface failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto drawingSurface = std::make_shared<Surface>();
|
||||
drawingSurface->GetImpl<SkiaSurface>()->SetSkSurface(surface);
|
||||
return drawingSurface;
|
||||
}
|
||||
|
||||
void SkiaSurface::SetSkSurface(const sk_sp<SkSurface>& skSurface)
|
||||
{
|
||||
skSurface_ = skSurface;
|
||||
|
@ -59,6 +59,7 @@ public:
|
||||
std::shared_ptr<Image> GetImageSnapshot() const override;
|
||||
std::shared_ptr<Image> GetImageSnapshot(const RectI& bounds) const override;
|
||||
std::shared_ptr<Surface> MakeSurface(int width, int height) const override;
|
||||
std::shared_ptr<Surface> MakeSurface(const ImageInfo& imageInfo) const override;
|
||||
BackendTexture GetBackendTexture(BackendAccess access) const override;
|
||||
void SetSkSurface(const sk_sp<SkSurface>& skSurface);
|
||||
void FlushAndSubmit(bool syncCpu) override;
|
||||
|
@ -703,7 +703,10 @@ void DrawPathOpItem::Marshalling(DrawCmdList& cmdList)
|
||||
{
|
||||
PaintHandle paintHandle;
|
||||
GenerateHandleFromPaint(cmdList, paint_, paintHandle);
|
||||
auto pathHandle = CmdListHelper::AddPathToCmdList(cmdList, *path_);
|
||||
OpDataHandle pathHandle;
|
||||
if (path_) {
|
||||
pathHandle = CmdListHelper::AddPathToCmdList(cmdList, *path_);
|
||||
}
|
||||
cmdList.AddOp<ConstructorHandle>(pathHandle, paintHandle);
|
||||
}
|
||||
|
||||
@ -777,7 +780,10 @@ std::shared_ptr<DrawOpItem> DrawShadowStyleOpItem::Unmarshalling(const DrawCmdLi
|
||||
|
||||
void DrawShadowStyleOpItem::Marshalling(DrawCmdList& cmdList)
|
||||
{
|
||||
auto pathHandle = CmdListHelper::AddPathToCmdList(cmdList, *path_);
|
||||
OpDataHandle pathHandle;
|
||||
if (path_) {
|
||||
pathHandle = CmdListHelper::AddPathToCmdList(cmdList, *path_);
|
||||
}
|
||||
cmdList.AddOp<ConstructorHandle>(
|
||||
pathHandle, planeParams_, devLightPos_, lightRadius_, ambientColor_, spotColor_, flag_, isLimitElevation_);
|
||||
}
|
||||
@ -826,7 +832,10 @@ std::shared_ptr<DrawOpItem> DrawShadowOpItem::Unmarshalling(const DrawCmdList& c
|
||||
|
||||
void DrawShadowOpItem::Marshalling(DrawCmdList& cmdList)
|
||||
{
|
||||
auto pathHandle = CmdListHelper::AddPathToCmdList(cmdList, *path_);
|
||||
OpDataHandle pathHandle;
|
||||
if (path_) {
|
||||
pathHandle = CmdListHelper::AddPathToCmdList(cmdList, *path_);
|
||||
}
|
||||
cmdList.AddOp<ConstructorHandle>(
|
||||
pathHandle, planeParams_, devLightPos_, lightRadius_, ambientColor_, spotColor_, flag_);
|
||||
}
|
||||
@ -880,7 +889,10 @@ void DrawRegionOpItem::Marshalling(DrawCmdList& cmdList)
|
||||
{
|
||||
PaintHandle paintHandle;
|
||||
GenerateHandleFromPaint(cmdList, paint_, paintHandle);
|
||||
auto regionHandle = CmdListHelper::AddRegionToCmdList(cmdList, *region_);
|
||||
OpDataHandle regionHandle;
|
||||
if (region_) {
|
||||
regionHandle = CmdListHelper::AddRegionToCmdList(cmdList, *region_);
|
||||
}
|
||||
cmdList.AddOp<ConstructorHandle>(regionHandle, paintHandle);
|
||||
}
|
||||
|
||||
@ -920,7 +932,10 @@ void DrawVerticesOpItem::Marshalling(DrawCmdList& cmdList)
|
||||
{
|
||||
PaintHandle paintHandle;
|
||||
GenerateHandleFromPaint(cmdList, paint_, paintHandle);
|
||||
auto opDataHandle = CmdListHelper::AddVerticesToCmdList(cmdList, *vertices_);
|
||||
OpDataHandle opDataHandle;
|
||||
if (vertices_) {
|
||||
opDataHandle = CmdListHelper::AddVerticesToCmdList(cmdList, *vertices_);
|
||||
}
|
||||
cmdList.AddOp<ConstructorHandle>(opDataHandle, mode_, paintHandle);
|
||||
}
|
||||
|
||||
@ -995,7 +1010,10 @@ std::shared_ptr<DrawOpItem> DrawImageNineOpItem::Unmarshalling(const DrawCmdList
|
||||
|
||||
void DrawImageNineOpItem::Marshalling(DrawCmdList& cmdList)
|
||||
{
|
||||
auto imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *image_);
|
||||
OpDataHandle imageHandle;
|
||||
if (image_) {
|
||||
imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *image_);
|
||||
}
|
||||
BrushHandle brushHandle;
|
||||
if (hasBrush_) {
|
||||
BrushToBrushHandle(brush_, cmdList, brushHandle);
|
||||
@ -1061,7 +1079,10 @@ void DrawImageLatticeOpItem::Marshalling(DrawCmdList& cmdList)
|
||||
{
|
||||
PaintHandle paintHandle;
|
||||
GenerateHandleFromPaint(cmdList, paint_, paintHandle);
|
||||
auto imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *image_);
|
||||
OpDataHandle imageHandle;
|
||||
if (image_) {
|
||||
imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *image_);
|
||||
}
|
||||
auto latticeHandle = CmdListHelper::AddLatticeToCmdList(cmdList, lattice_);
|
||||
cmdList.AddOp<ConstructorHandle>(imageHandle, latticeHandle, dst_, filter_, paintHandle);
|
||||
}
|
||||
@ -1138,7 +1159,10 @@ void DrawAtlasOpItem::Marshalling(DrawCmdList& cmdList)
|
||||
{
|
||||
PaintHandle paintHandle;
|
||||
GenerateHandleFromPaint(cmdList, paint_, paintHandle);
|
||||
auto imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *atlas_);
|
||||
OpDataHandle imageHandle;
|
||||
if (atlas_) {
|
||||
imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *atlas_);
|
||||
}
|
||||
auto xformData = CmdListHelper::AddVectorToCmdList<RSXform>(cmdList, xform_);
|
||||
auto texData = CmdListHelper::AddVectorToCmdList<Rect>(cmdList, tex_);
|
||||
auto colorData = CmdListHelper::AddVectorToCmdList<ColorQuad>(cmdList, colors_);
|
||||
@ -1221,7 +1245,10 @@ void DrawBitmapOpItem::Marshalling(DrawCmdList& cmdList)
|
||||
{
|
||||
PaintHandle paintHandle;
|
||||
GenerateHandleFromPaint(cmdList, paint_, paintHandle);
|
||||
auto bitmapHandle = CmdListHelper::AddBitmapToCmdList(cmdList, *bitmap_);
|
||||
ImageHandle bitmapHandle;
|
||||
if (bitmap_) {
|
||||
bitmapHandle = CmdListHelper::AddBitmapToCmdList(cmdList, *bitmap_);
|
||||
}
|
||||
cmdList.AddOp<ConstructorHandle>(bitmapHandle, px_, py_, paintHandle);
|
||||
}
|
||||
|
||||
@ -1266,7 +1293,10 @@ void DrawImageOpItem::Marshalling(DrawCmdList& cmdList)
|
||||
{
|
||||
PaintHandle paintHandle;
|
||||
GenerateHandleFromPaint(cmdList, paint_, paintHandle);
|
||||
auto imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *image_);
|
||||
OpDataHandle imageHandle;
|
||||
if (image_) {
|
||||
imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *image_);
|
||||
}
|
||||
cmdList.AddOp<ConstructorHandle>(imageHandle, px_, py_, samplingOptions_, paintHandle);
|
||||
}
|
||||
|
||||
@ -1324,7 +1354,10 @@ void DrawImageRectOpItem::Marshalling(DrawCmdList& cmdList)
|
||||
{
|
||||
PaintHandle paintHandle;
|
||||
GenerateHandleFromPaint(cmdList, paint_, paintHandle);
|
||||
auto imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *image_);
|
||||
OpDataHandle imageHandle;
|
||||
if (image_) {
|
||||
imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *image_);
|
||||
}
|
||||
cmdList.AddOp<ConstructorHandle>(imageHandle, src_, dst_, sampling_, constraint_, paintHandle);
|
||||
}
|
||||
|
||||
@ -1434,7 +1467,10 @@ std::shared_ptr<DrawOpItem> DrawPictureOpItem::Unmarshalling(const DrawCmdList&
|
||||
|
||||
void DrawPictureOpItem::Marshalling(DrawCmdList& cmdList)
|
||||
{
|
||||
auto pictureHandle = CmdListHelper::AddPictureToCmdList(cmdList, *picture_);
|
||||
OpDataHandle pictureHandle;
|
||||
if (picture_) {
|
||||
pictureHandle = CmdListHelper::AddPictureToCmdList(cmdList, *picture_);
|
||||
}
|
||||
cmdList.AddOp<ConstructorHandle>(pictureHandle);
|
||||
}
|
||||
|
||||
@ -1682,6 +1718,9 @@ bool DrawTextBlobOpItem::ConstructorHandle::GenerateCachedOpItem(DrawCmdList& cm
|
||||
}
|
||||
|
||||
Canvas* offscreenCanvas = offscreenSurface->GetCanvas().get();
|
||||
if (!offscreenCanvas) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// align draw op to [0, 0]
|
||||
if (bounds->GetLeft() != 0 || bounds->GetTop() != 0) {
|
||||
@ -1739,6 +1778,9 @@ std::shared_ptr<DrawImageRectOpItem> DrawTextBlobOpItem::GenerateCachedOpItem(Ca
|
||||
}
|
||||
|
||||
Canvas* offscreenCanvas = offscreenSurface->GetCanvas().get();
|
||||
if (!offscreenCanvas) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// align draw op to [0, 0]
|
||||
if (bounds->GetLeft() != 0 || bounds->GetTop() != 0) {
|
||||
@ -1984,7 +2026,10 @@ std::shared_ptr<DrawOpItem> ClipPathOpItem::Unmarshalling(const DrawCmdList& cmd
|
||||
|
||||
void ClipPathOpItem::Marshalling(DrawCmdList& cmdList)
|
||||
{
|
||||
auto pathHandle = CmdListHelper::AddPathToCmdList(cmdList, *path_);
|
||||
OpDataHandle pathHandle;
|
||||
if (path_) {
|
||||
pathHandle = CmdListHelper::AddPathToCmdList(cmdList, *path_);
|
||||
}
|
||||
cmdList.AddOp<ConstructorHandle>(pathHandle, clipOp_, doAntiAlias_);
|
||||
}
|
||||
|
||||
@ -2013,7 +2058,10 @@ std::shared_ptr<DrawOpItem> ClipRegionOpItem::Unmarshalling(const DrawCmdList& c
|
||||
|
||||
void ClipRegionOpItem::Marshalling(DrawCmdList& cmdList)
|
||||
{
|
||||
auto regionHandle = CmdListHelper::AddRegionToCmdList(cmdList, *region_);
|
||||
OpDataHandle regionHandle;
|
||||
if (region_) {
|
||||
regionHandle = CmdListHelper::AddRegionToCmdList(cmdList, *region_);
|
||||
}
|
||||
cmdList.AddOp<ConstructorHandle>(regionHandle, clipOp_);
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ bool MemAllocator::Resize(size_t size)
|
||||
if (size > LARGE_MALLOC) {
|
||||
LOGW("MemAllocator::Resize this time malloc large memory, size:%{public}zu", size);
|
||||
}
|
||||
char* newData = new char[size];
|
||||
char* newData = new(std::nothrow) char[size];
|
||||
if (!newData) {
|
||||
return false;
|
||||
}
|
||||
|
@ -125,7 +125,11 @@ std::shared_ptr<Data> Typeface::Serialize() const
|
||||
|
||||
std::shared_ptr<Typeface> Typeface::Deserialize(const void* data, size_t size)
|
||||
{
|
||||
return StaticFactory::DeserializeTypeface(data, size);
|
||||
auto typeface = StaticFactory::DeserializeTypeface(data, size);
|
||||
if (typeface != nullptr) {
|
||||
typeface->SetSize(size);
|
||||
}
|
||||
return typeface;
|
||||
}
|
||||
|
||||
std::function<bool(std::shared_ptr<Typeface>)> Typeface::registerTypefaceCallBack_ = nullptr;
|
||||
@ -165,6 +169,26 @@ void Typeface::SetHash(uint32_t hash)
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Typeface::GetSize()
|
||||
{
|
||||
if (size_ != 0) {
|
||||
return size_;
|
||||
}
|
||||
if (!typefaceImpl_) {
|
||||
return 0;
|
||||
}
|
||||
auto data = typefaceImpl_->Serialize();
|
||||
if (!data) {
|
||||
return 0;
|
||||
}
|
||||
size_ = data->GetSize();
|
||||
return size_;
|
||||
}
|
||||
|
||||
void Typeface::SetSize(uint32_t size)
|
||||
{
|
||||
size_ = size;
|
||||
}
|
||||
} // namespace Drawing
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <refbase.h>
|
||||
#include <mutex>
|
||||
|
||||
#include "hdi_layer.h"
|
||||
#include "hdi_device.h"
|
||||
@ -38,7 +39,7 @@ public:
|
||||
|
||||
int32_t GetScreenCapability(GraphicDisplayCapability &info) const;
|
||||
int32_t GetScreenSupportedModes(std::vector<GraphicDisplayModeInfo> &modes) const;
|
||||
int32_t GetScreenMode(uint32_t &modeId) const;
|
||||
int32_t GetScreenMode(uint32_t &modeId);
|
||||
int32_t SetScreenMode(uint32_t modeId);
|
||||
int32_t SetScreenOverlayResolution(uint32_t width, uint32_t height) const;
|
||||
int32_t GetScreenPowerStatus(GraphicDispPowerStatus &status) const;
|
||||
@ -61,12 +62,12 @@ public:
|
||||
|
||||
/* only used for mock and fuzz tests */
|
||||
bool SetHdiDevice(HdiDevice* device);
|
||||
uint32_t GetScreenModeId() const;
|
||||
|
||||
private:
|
||||
uint32_t screenId_;
|
||||
HdiDevice *device_ = nullptr;
|
||||
uint32_t modeId_ = 0;
|
||||
uint32_t modeId_ = UINT32_MAX; // UINT32_MAX is invalid modeId
|
||||
std::mutex mutex_;
|
||||
|
||||
void Destroy();
|
||||
};
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "vsync_sampler.h"
|
||||
#include <hdf_base.h>
|
||||
#include <rs_trace.h>
|
||||
#include <mutex>
|
||||
|
||||
#define CHECK_DEVICE_NULL(sptrDevice) \
|
||||
do { \
|
||||
@ -123,23 +124,30 @@ int32_t HdiScreen::GetScreenSupportedModes(std::vector<GraphicDisplayModeInfo> &
|
||||
return device_->GetScreenSupportedModes(screenId_, modes);
|
||||
}
|
||||
|
||||
int32_t HdiScreen::GetScreenMode(uint32_t &modeId) const
|
||||
int32_t HdiScreen::GetScreenMode(uint32_t &modeId)
|
||||
{
|
||||
std::unique_lock<std::mutex> locker(mutex_);
|
||||
CHECK_DEVICE_NULL(device_);
|
||||
return device_->GetScreenMode(screenId_, modeId);
|
||||
}
|
||||
|
||||
uint32_t HdiScreen::GetScreenModeId() const
|
||||
{
|
||||
return modeId_;
|
||||
if (modeId_ != UINT32_MAX) {
|
||||
modeId = modeId_;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
int32_t ret = device_->GetScreenMode(screenId_, modeId);
|
||||
if (ret == HDF_SUCCESS) {
|
||||
modeId_ = modeId;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t HdiScreen::SetScreenMode(uint32_t modeId)
|
||||
{
|
||||
std::unique_lock<std::mutex> locker(mutex_);
|
||||
CHECK_DEVICE_NULL(device_);
|
||||
auto ret = device_->SetScreenMode(screenId_, modeId);
|
||||
int32_t ret = device_->SetScreenMode(screenId_, modeId);
|
||||
if (ret == HDF_SUCCESS) {
|
||||
modeId_ = modeId;
|
||||
} else {
|
||||
modeId_ = UINT32_MAX;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -193,12 +193,12 @@ int32_t VSyncConnection::PostEvent(int64_t now, int64_t period, int64_t vsyncCou
|
||||
if (ret > -1) {
|
||||
ScopedDebugTrace successful("successful");
|
||||
info_.postVSyncCount_++;
|
||||
if (gcNotifyTask_ != nullptr) {
|
||||
gcNotifyTask_(false);
|
||||
}
|
||||
} else {
|
||||
ScopedBytrace failed("failed");
|
||||
}
|
||||
if (gcNotifyTask_ != nullptr) {
|
||||
gcNotifyTask_(false);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -195,9 +195,9 @@ VsyncError VSyncReceiver::Init()
|
||||
void VSyncReceiver::ThreadCreateNotify()
|
||||
{
|
||||
int32_t pid = getprocpid();
|
||||
int32_t uid = getuid();
|
||||
uint32_t uid = getuid();
|
||||
int32_t tid = static_cast<int32_t>(getproctid());
|
||||
VLOGI("vsync thread pid=%{public}d, tid=%{public}d, uid=%{public}d.", pid, tid, uid);
|
||||
VLOGI("vsync thread pid=%{public}d, tid=%{public}d, uid=%{public}u.", pid, tid, uid);
|
||||
|
||||
std::unordered_map<std::string, std::string> mapPayload;
|
||||
mapPayload["pid"] = std::to_string(pid);
|
||||
|
@ -50,16 +50,13 @@ ohos_source_set("graphics_effect_src") {
|
||||
|
||||
sources = [
|
||||
"src/ge_aibar_shader_filter.cpp",
|
||||
"src/ge_cache.cpp",
|
||||
"src/ge_grey_shader_filter.cpp",
|
||||
"src/ge_hash.cpp",
|
||||
"src/ge_hps_blur_shader_filter.cpp",
|
||||
"src/ge_kawase_blur_shader_filter.cpp",
|
||||
"src/ge_linear_gradient_blur_shader_filter.cpp",
|
||||
"src/ge_magnifier_shader_filter.cpp",
|
||||
"src/ge_mesa_blur_shader_filter.cpp",
|
||||
"src/ge_render.cpp",
|
||||
"src/ge_shader.cpp",
|
||||
"src/ge_system_properties.cpp",
|
||||
"src/ge_visual_effect.cpp",
|
||||
"src/ge_visual_effect_container.cpp",
|
||||
|
@ -42,6 +42,8 @@ private:
|
||||
float aiBarThreshold_;
|
||||
float aiBarOpacity_;
|
||||
float aiBarSaturation_;
|
||||
std::shared_ptr<Drawing::RuntimeShaderBuilder> MakeBinarizationShader(
|
||||
float imageWidth, float imageHeight, std::shared_ptr<Drawing::ShaderEffect> imageShader);
|
||||
};
|
||||
|
||||
} // namespace Rosen
|
||||
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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 GRAPHICS_EFFECT_GE_CACHE_H
|
||||
#define GRAPHICS_EFFECT_GE_CACHE_H
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "image/image.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace GraphicsEffectEngine {
|
||||
|
||||
using namespace Rosen;
|
||||
|
||||
class GECache {
|
||||
public:
|
||||
static GECache& GetInstance();
|
||||
void Set(size_t key, const std::shared_ptr<Drawing::Image> value);
|
||||
const std::shared_ptr<Drawing::Image> Get(size_t key) const;
|
||||
void SetMaxCapacity(size_t size);
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
GECache() = default;
|
||||
~GECache() = default;
|
||||
GECache(const GECache&) = delete;
|
||||
GECache& operator=(const GECache&) = delete;
|
||||
|
||||
void EvictLeastUsed();
|
||||
|
||||
std::unordered_map<size_t, std::shared_ptr<Drawing::Image>> cache_;
|
||||
mutable std::mutex mutex_;
|
||||
|
||||
size_t maxCapacity_ = 10; // Use 10 as the default capacity
|
||||
std::list<size_t> accessOrder_;
|
||||
std::unordered_set<size_t> keySet_;
|
||||
};
|
||||
|
||||
} // namespace GraphicsEffectEngine
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // GRAPHICS_EFFECT_GE_CACHE_H
|
@ -1,225 +0,0 @@
|
||||
/*
|
||||
* 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 GRAPHICS_EFFECT_GE_HASH_REFER_H
|
||||
#define GRAPHICS_EFFECT_GE_HASH_REFER_H
|
||||
#include <cerrno>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <securec.h>
|
||||
#include "ge_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace GraphicsEffectEngine {
|
||||
|
||||
enum Constants {
|
||||
CONST_ERR = -1,
|
||||
CONST_0 = 0,
|
||||
CONST_1 = 1,
|
||||
CONST_2 = 2,
|
||||
CONST_3 = 3,
|
||||
CONST_4 = 4,
|
||||
CONST_8 = 8,
|
||||
CONST_16 = 16,
|
||||
CONST_24 = 24,
|
||||
CONST_32 = 32,
|
||||
CONST_40 = 40,
|
||||
CONST_48 = 48,
|
||||
CONST_64 = 64
|
||||
};
|
||||
|
||||
// the default secret parameters
|
||||
static const uint64_t SECRET[CONST_4] = { 0xa0761d6478bd642full, 0xe7037ed1a0b428dbull, 0x8ebc6af09c88c6e3ull,
|
||||
0x589965cc75374cc3ull };
|
||||
|
||||
// wyhash, a fast and good hash function, from https://github.com/wangyi-fudan/wyhash
|
||||
// Likely and Unlikely macros
|
||||
#if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__clang__)
|
||||
inline bool Likely(bool expression)
|
||||
{
|
||||
return __builtin_expect(static_cast<bool>(expression), true);
|
||||
}
|
||||
|
||||
inline bool Unlikely(bool expression)
|
||||
{
|
||||
return __builtin_expect(static_cast<bool>(expression), false);
|
||||
}
|
||||
#else
|
||||
inline bool Likely(bool expression)
|
||||
{
|
||||
return expression;
|
||||
}
|
||||
|
||||
inline bool Unlikely(bool expression)
|
||||
{
|
||||
return expression;
|
||||
}
|
||||
#endif /* */
|
||||
|
||||
// 128bit multiply function
|
||||
#if defined(__SIZEOF_INT128__)
|
||||
static inline void Multiply128bit(uint64_t* num1, uint64_t* num2)
|
||||
{
|
||||
if (num1 == nullptr || num2 == nullptr) {
|
||||
LOGE("Error: null pointer input\n");
|
||||
return;
|
||||
}
|
||||
__uint128_t r = *num1;
|
||||
r *= *num2;
|
||||
*num1 = (uint64_t)r;
|
||||
*num2 = (uint64_t)(r >> CONST_64);
|
||||
}
|
||||
#elif defined(_MSC_VER) && defined(_M_X64)
|
||||
static inline void Multiply128bit(uint64_t* num1, uint64_t* num2)
|
||||
{
|
||||
*num1 = _umul128(*num1, *num2, num2);
|
||||
}
|
||||
#else
|
||||
static void Multiply128bitInner(uint64_t* lowerBits, uint64_t* higherBits)
|
||||
{
|
||||
if (lowerBits == nullptr || higherBits == nullptr) {
|
||||
LOGE("Error: null pointer input\n");
|
||||
return;
|
||||
}
|
||||
uint64_t higherA = *lowerBits >> CONST_32;
|
||||
uint64_t higherB = *higherBits >> CONST_32;
|
||||
uint64_t lowerA = (uint32_t)*lowerBits;
|
||||
uint64_t lowerB = (uint32_t)*higherBits;
|
||||
uint64_t higherResult;
|
||||
uint64_t lowerResult;
|
||||
uint64_t higherProduct = higherA * higherB;
|
||||
uint64_t midProduct0 = higherA * lowerB;
|
||||
uint64_t midProduct1 = higherB * lowerA;
|
||||
uint64_t lowerProduct = lowerA * lowerB;
|
||||
uint64_t temp = lowerProduct + (midProduct0 << CONST_32);
|
||||
uint64_t carry = temp < lowerProduct;
|
||||
lowerResult = temp + (midProduct1 << CONST_32);
|
||||
carry += lowerResult < temp;
|
||||
higherResult = higherProduct + (midProduct0 >> CONST_32) + (midProduct1 >> CONST_32) + carry;
|
||||
*lowerBits = lowerResult;
|
||||
*higherBits = higherResult;
|
||||
}
|
||||
|
||||
static inline void Multiply128bit(uint64_t* lowerBits, uint64_t* higherBits)
|
||||
{
|
||||
Multiply128bitInner(lowerBits, higherBits);
|
||||
}
|
||||
#endif
|
||||
|
||||
// multiply and xor mix function, aka MUM
|
||||
static inline uint64_t MultiplyXorMix(uint64_t num1, uint64_t num2)
|
||||
{
|
||||
Multiply128bit(&num1, &num2);
|
||||
return num1 ^ num2;
|
||||
}
|
||||
|
||||
// read functions
|
||||
static inline uint64_t Read8(const uint8_t* p)
|
||||
{
|
||||
if (p == nullptr) {
|
||||
LOGE("Error: null pointer input\n");
|
||||
return CONST_ERR;
|
||||
}
|
||||
uint64_t value;
|
||||
errno_t err = memcpy_s(&value, CONST_8, p, CONST_8);
|
||||
if (err != 0) {
|
||||
// Handle error if needed, here we could set value to 0 or handle it differently
|
||||
value = 0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
static inline uint64_t Read4(const uint8_t* p)
|
||||
{
|
||||
if (p == nullptr) {
|
||||
LOGE("Error: null pointer input\n");
|
||||
return CONST_ERR;
|
||||
}
|
||||
uint32_t value;
|
||||
errno_t err = memcpy_s(&value, CONST_4, p, CONST_4);
|
||||
if (err != 0) {
|
||||
// Handle error if needed, here we could set value to 0 or handle it differently
|
||||
value = 0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
static inline uint64_t Read3(const uint8_t* p, size_t k)
|
||||
{
|
||||
if (p == nullptr) {
|
||||
LOGE("Error: null pointer input\n");
|
||||
return CONST_ERR;
|
||||
}
|
||||
return (((uint64_t)p[CONST_0]) << CONST_16) | (((uint64_t)p[k >> CONST_1]) << CONST_8) | p[k - CONST_1];
|
||||
}
|
||||
|
||||
// begin GEHash main function
|
||||
static uint64_t GEHashInner(const void* key, size_t length, uint64_t seed, const uint64_t* secret)
|
||||
{
|
||||
if (key == nullptr || secret == nullptr) {
|
||||
LOGE("Error: null pointer input\n");
|
||||
return CONST_ERR;
|
||||
}
|
||||
const uint8_t* data = (const uint8_t*)key;
|
||||
seed ^= MultiplyXorMix(seed ^ secret[CONST_0], secret[CONST_1]);
|
||||
uint64_t firstValue;
|
||||
uint64_t secondValue;
|
||||
if (Likely(length <= CONST_16)) {
|
||||
if (Likely(length >= CONST_4)) {
|
||||
firstValue = (Read4(data) << CONST_32) | Read4(data + ((length >> CONST_3) << CONST_2));
|
||||
secondValue = (Read4(data + length - CONST_4) << CONST_32) |
|
||||
Read4(data + length - CONST_4 - ((length >> CONST_3) << CONST_2));
|
||||
} else if (Likely(length > CONST_0)) {
|
||||
firstValue = Read3(data, length);
|
||||
secondValue = CONST_0;
|
||||
} else
|
||||
firstValue = secondValue = CONST_0;
|
||||
} else {
|
||||
size_t remainingLength = length;
|
||||
if (Unlikely(remainingLength > CONST_48)) {
|
||||
uint64_t seed1 = seed;
|
||||
uint64_t seed2 = seed;
|
||||
do {
|
||||
seed = MultiplyXorMix(Read8(data) ^ secret[CONST_1], Read8(data + CONST_8) ^ seed);
|
||||
seed1 = MultiplyXorMix(Read8(data + CONST_16) ^ secret[CONST_2], Read8(data + CONST_24) ^ seed1);
|
||||
seed2 = MultiplyXorMix(Read8(data + CONST_32) ^ secret[CONST_3], Read8(data + CONST_40) ^ seed2);
|
||||
data += CONST_48;
|
||||
remainingLength -= CONST_48;
|
||||
} while (Likely(remainingLength > CONST_48));
|
||||
seed ^= seed1 ^ seed2;
|
||||
}
|
||||
while (Unlikely(remainingLength > CONST_16)) {
|
||||
seed = MultiplyXorMix(Read8(data) ^ secret[CONST_1], Read8(data + CONST_8) ^ seed);
|
||||
remainingLength -= CONST_16;
|
||||
data += CONST_16;
|
||||
}
|
||||
firstValue = Read8(data + remainingLength - CONST_16);
|
||||
secondValue = Read8(data + remainingLength - CONST_8);
|
||||
}
|
||||
firstValue ^= secret[CONST_1];
|
||||
secondValue ^= seed;
|
||||
Multiply128bit(&firstValue, &secondValue);
|
||||
return MultiplyXorMix(firstValue ^ secret[CONST_0] ^ length, secondValue ^ secret[CONST_1]);
|
||||
}
|
||||
|
||||
static inline uint64_t GEHash(const void* key, size_t len, uint64_t seed, const uint64_t* secret)
|
||||
{
|
||||
return GEHashInner(key, len, seed, secret);
|
||||
}
|
||||
// end get_hash main function
|
||||
|
||||
} // namespace GraphicsEffectEngine
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHICS_EFFECT_GE_HASH_REFER_H
|
@ -1,94 +0,0 @@
|
||||
/*
|
||||
* 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 GRAPHICS_EFFECT_GE_SHADER_H
|
||||
#define GRAPHICS_EFFECT_GE_SHADER_H
|
||||
#include "effect/runtime_effect.h"
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
typedef enum {
|
||||
SHADER_AIBAR,
|
||||
SHADER_GREY,
|
||||
SHADER_BLUR,
|
||||
SHADER_BLURAF,
|
||||
SHADER_MIX,
|
||||
SHADER_SIMPLE,
|
||||
SHADER_HORIBLUR,
|
||||
SHADER_VERTBLUR,
|
||||
SHADER_MASKBLUR
|
||||
} ShaderIndex;
|
||||
// Union Shader Feature
|
||||
typedef enum {
|
||||
TYPE_NO_REFERENCE,
|
||||
TYPE_REFERENCE_ROW,
|
||||
TYPE_REFERENCE_COLUME,
|
||||
TYPE_REFERENCE_AROUND
|
||||
} ShaderType;
|
||||
typedef enum {
|
||||
GE_ERROR_NONE = 0,
|
||||
GE_ERROR_NOT_ACCEPTED_CONNECT,
|
||||
GE_ERROR_SHADER_STRING_INVALID,
|
||||
GE_ERROR_SHADER_COMPILE_FAILED
|
||||
} GE_Error;
|
||||
|
||||
class GEShader {
|
||||
public:
|
||||
GEShader(const std::string& name, ShaderType type,
|
||||
const std::string& shaderStr, const Drawing::RuntimeEffectOptions* opt = nullptr);
|
||||
GEShader(const std::shared_ptr<GEShader> rth);
|
||||
~GEShader();
|
||||
std::string GetName() const;
|
||||
ShaderType GetType() const;
|
||||
GEShader& String(const std::string& shaderStr);
|
||||
GEShader& Type(ShaderType type);
|
||||
GEShader& Name(const std::string& name);
|
||||
Drawing::RuntimeEffectOptions* GetOptions() const;
|
||||
bool Combine(const GEShader& rth);
|
||||
std::shared_ptr<Drawing::RuntimeEffect> GetShader() const;
|
||||
GE_Error Compile(const Drawing::RuntimeEffectOptions* ops = nullptr);
|
||||
private:
|
||||
std::string GetString() const;
|
||||
GE_Error Connect(const GEShader& subShader) ;
|
||||
static GE_Error CombineShaderString(std::string& cbStr,
|
||||
const std::string& shaderStrFirst, const std::string& shaderStrSecond);
|
||||
|
||||
// Union Shader Feature
|
||||
ShaderType type_ = TYPE_NO_REFERENCE;
|
||||
std::string name_ = {};
|
||||
std::string shaderStr_ = {};
|
||||
std::shared_ptr<Drawing::RuntimeEffect> shader_ = nullptr;
|
||||
Drawing::RuntimeEffectOptions* opt_ = nullptr;
|
||||
};
|
||||
|
||||
class GEShaderStore {
|
||||
public:
|
||||
static std::shared_ptr<GEShaderStore> GetInstance();
|
||||
std::shared_ptr<GEShader> GetShader(ShaderIndex which);
|
||||
std::shared_ptr<GEShader> GetShader(const std::vector<ShaderIndex>& which);
|
||||
private:
|
||||
void Initialize();
|
||||
void RegisterShader(ShaderIndex key, const std::string& name, ShaderType type, const std::string& shader,
|
||||
const Drawing::RuntimeEffectOptions* opt);
|
||||
std::unordered_map<std::string, std::shared_ptr<GEShader>> shaderMap_ = {};
|
||||
std::unordered_map<ShaderIndex, std::shared_ptr<GEShader>> shaderObjMap_ = {};
|
||||
};
|
||||
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // GRAPHICS_EFFECT_GE_SHADER_H
|
@ -18,7 +18,6 @@
|
||||
|
||||
#include "draw/canvas.h"
|
||||
#include "image/image.h"
|
||||
#include "ge_shader.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
|
@ -1,241 +0,0 @@
|
||||
/*
|
||||
* 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 GRAPHICS_EFFECT_SHADER_STRING_H
|
||||
#define GRAPHICS_EFFECT_SHADER_STRING_H
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
|
||||
static std::string g_aibarString(R"(
|
||||
uniform half low;
|
||||
uniform half high;
|
||||
uniform half threshold;
|
||||
uniform half opacity;
|
||||
uniform half saturation;
|
||||
uniform shader imageShader;
|
||||
|
||||
const vec3 toLuminance = vec3(0.3086, 0.6094, 0.0820);
|
||||
|
||||
half4 main(float2 coord) {
|
||||
half3 c = imageShader.eval(coord).rgb;
|
||||
float gray = 0.299 * c.r + 0.587 * c.g + 0.114 * c.b;
|
||||
float bin = mix(high, low, step(threshold, gray));
|
||||
float luminance = dot(c, toLuminance);
|
||||
half3 satAdjust = mix(vec3(luminance), c, saturation);
|
||||
half3 res = satAdjust - (opacity + 1.0) * gray + bin;
|
||||
return half4(mix(c, res, 0.42857), 1.0);
|
||||
}
|
||||
)");
|
||||
|
||||
static std::string g_greyGradationString(R"(
|
||||
uniform shader imageShader;
|
||||
uniform float coefficient1;
|
||||
uniform float coefficient2;
|
||||
|
||||
float poww(float x, float y) {
|
||||
return (x < 0) ? -pow(-x, y) : pow(x, y);
|
||||
}
|
||||
|
||||
float calculateT_y(float rgb) {
|
||||
if (rgb > 127.5) { rgb = 255 - rgb; }
|
||||
float b = 38.0;
|
||||
float c = 45.0;
|
||||
float d = 127.5;
|
||||
float A = 106.5; // 3 * b - 3 * c + d;
|
||||
float B = -93; // 3 * (c - 2 * b);
|
||||
float C = 114; // 3 * b;
|
||||
float p = 0.816240163988; // (3 * A * C - pow(B, 2)) / (3 * pow(A, 2));
|
||||
float q = -rgb / 106.5 + 0.262253485943; // -rgb/A - B*C/(3*pow(A,2)) + 2*pow(B,3)/(27*pow(A,3))
|
||||
float s1 = -(q / 2.0);
|
||||
float s2 = sqrt(pow(s1, 2) + pow(p / 3, 3));
|
||||
return poww((s1 + s2), 1.0 / 3) + poww((s1 - s2), 1.0 / 3) - (B / (3 * A));
|
||||
}
|
||||
|
||||
float calculateGreyAdjustY(float rgb) {
|
||||
float t_r = calculateT_y(rgb);
|
||||
return (rgb < 127.5) ? (rgb + coefficient1 * pow((1 - t_r), 3)) :
|
||||
(rgb - coefficient2 * pow((1 - t_r), 3));
|
||||
}
|
||||
|
||||
half4 main(float2 coord) {
|
||||
vec3 color = vec3(imageShader.eval(coord).r, imageShader.eval(coord).g, imageShader.eval(coord).b);
|
||||
float Y = (0.299 * color.r + 0.587 * color.g + 0.114 * color.b) * 255;
|
||||
float U = (-0.147 * color.r - 0.289 * color.g + 0.436 * color.b) * 255;
|
||||
float V = (0.615 * color.r - 0.515 * color.g - 0.100 * color.b) * 255;
|
||||
Y = calculateGreyAdjustY(Y);
|
||||
color.r = (Y + 1.14 * V) / 255.0;
|
||||
color.g = (Y - 0.39 * U - 0.58 * V) / 255.0;
|
||||
color.b = (Y + 2.03 * U) / 255.0;
|
||||
|
||||
return vec4(color, 1.0);
|
||||
}
|
||||
)");
|
||||
|
||||
static std::string g_blurStringAF(R"(
|
||||
uniform shader imageShader;
|
||||
uniform float2 in_blurOffset[5];
|
||||
|
||||
half4 main(float2 coord) {
|
||||
half4 c = half4(0, 0, 0, 0);
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
c += imageShader.eval(float2(coord.x + in_blurOffset[i].x, coord.y + in_blurOffset[i].y));
|
||||
}
|
||||
return half4(c.rgb * 0.2, 1.0);
|
||||
}
|
||||
)");
|
||||
|
||||
static std::string g_mixString(R"(
|
||||
uniform shader blurredInput;
|
||||
uniform shader originalInput;
|
||||
uniform float mixFactor;
|
||||
uniform float inColorFactor;
|
||||
|
||||
highp float random(float2 xy) {
|
||||
float t = dot(xy, float2(78.233, 12.9898));
|
||||
return fract(sin(t) * 43758.5453);
|
||||
}
|
||||
half4 main(float2 coord) {
|
||||
highp float noiseGranularity = inColorFactor / 255.0;
|
||||
half4 finalColor = mix(originalInput.eval(coord), blurredInput.eval(coord), mixFactor);
|
||||
float noise = mix(-noiseGranularity, noiseGranularity, random(coord));
|
||||
finalColor.rgb += noise;
|
||||
return finalColor;
|
||||
}
|
||||
)");
|
||||
|
||||
static std::string g_blurString(R"(
|
||||
uniform shader imageShader;
|
||||
uniform float2 in_blurOffset;
|
||||
uniform float2 in_maxSizeXY;
|
||||
|
||||
half4 main(float2 coord) {
|
||||
half4 c = imageShader.eval(coord);
|
||||
c += imageShader.eval(float2(clamp(in_blurOffset.x + coord.x, 0, in_maxSizeXY.x),
|
||||
clamp(in_blurOffset.y + coord.y, 0, in_maxSizeXY.y)));
|
||||
c += imageShader.eval(float2(clamp(in_blurOffset.x + coord.x, 0, in_maxSizeXY.x),
|
||||
clamp(-in_blurOffset.y + coord.y, 0, in_maxSizeXY.y)));
|
||||
c += imageShader.eval(float2(clamp(-in_blurOffset.x + coord.x, 0, in_maxSizeXY.x),
|
||||
clamp(in_blurOffset.y + coord.y, 0, in_maxSizeXY.y)));
|
||||
c += imageShader.eval(float2(clamp(-in_blurOffset.x + coord.x, 0, in_maxSizeXY.x),
|
||||
clamp(-in_blurOffset.y + coord.y, 0, in_maxSizeXY.y)));
|
||||
return half4(c.rgb * 0.2, 1.0);
|
||||
}
|
||||
)");
|
||||
|
||||
static std::string g_simpleString(R"(
|
||||
uniform shader imageShader;
|
||||
half4 main(float2 coord) {
|
||||
return imageShader.eval(coord);
|
||||
}
|
||||
)");
|
||||
|
||||
static const std::string g_hBlurString(R"(
|
||||
uniform half r;
|
||||
uniform shader imageShader;
|
||||
uniform shader gradientShader;
|
||||
half4 meanFilter(float2 coord, half radius)
|
||||
{
|
||||
half4 sum = vec4(0.0);
|
||||
half div = 0;
|
||||
for (half x = -30.0; x < 30.0; x += 1.0) {
|
||||
if (x > radius) {
|
||||
break;
|
||||
}
|
||||
if (abs(x) < radius) {
|
||||
div += 1;
|
||||
sum += imageShader.eval(coord + float2(x, 0));
|
||||
}
|
||||
}
|
||||
return half4(sum.xyz / div, 1.0);
|
||||
}
|
||||
half4 main(float2 coord)
|
||||
{
|
||||
if (abs(gradientShader.eval(coord).a - 0) < 0.001) {
|
||||
return imageShader.eval(coord);
|
||||
}
|
||||
else {
|
||||
float val = clamp(r * gradientShader.eval(coord).a, 1.0, r);
|
||||
return meanFilter(coord, val);
|
||||
}
|
||||
}
|
||||
)");
|
||||
|
||||
static const std::string g_vBlurString(R"(
|
||||
uniform half r;
|
||||
uniform shader imageShader;
|
||||
uniform shader gradientShader;
|
||||
half4 meanFilter(float2 coord, half radius)
|
||||
{
|
||||
half4 sum = vec4(0.0);
|
||||
half div = 0;
|
||||
for (half y = -30.0; y < 30.0; y += 1.0) {
|
||||
if (y > radius) {
|
||||
break;
|
||||
}
|
||||
if (abs(y) < radius) {
|
||||
div += 1;
|
||||
sum += imageShader.eval(coord + float2(0, y));
|
||||
}
|
||||
}
|
||||
return half4(sum.xyz / div, 1.0);
|
||||
}
|
||||
half4 main(float2 coord)
|
||||
{
|
||||
if (abs(gradientShader.eval(coord).a - 0) < 0.001) {
|
||||
return imageShader.eval(coord);
|
||||
}
|
||||
else {
|
||||
float val = clamp(r * gradientShader.eval(coord).a, 1.0, r);
|
||||
return meanFilter(coord, val);
|
||||
}
|
||||
}
|
||||
)");
|
||||
|
||||
static const std::string g_maskBlurString(R"(
|
||||
uniform shader srcImageShader;
|
||||
uniform shader blurImageShader;
|
||||
uniform shader gradientShader;
|
||||
half4 meanFilter(float2 coord)
|
||||
{
|
||||
vec3 srcColor = vec3(srcImageShader.eval(coord).r,
|
||||
srcImageShader.eval(coord).g, srcImageShader.eval(coord).b);
|
||||
vec3 blurColor = vec3(blurImageShader.eval(coord).r,
|
||||
blurImageShader.eval(coord).g, blurImageShader.eval(coord).b);
|
||||
float gradient = gradientShader.eval(coord).a;
|
||||
|
||||
vec3 color = blurColor * gradient + srcColor * (1 - gradient);
|
||||
return vec4(color, 1.0);
|
||||
}
|
||||
half4 main(float2 coord)
|
||||
{
|
||||
if (abs(gradientShader.eval(coord).a) < 0.001) {
|
||||
return srcImageShader.eval(coord);
|
||||
}
|
||||
else {
|
||||
if (abs(gradientShader.eval(coord).a) > 0.999) {
|
||||
return blurImageShader.eval(coord);
|
||||
}
|
||||
else {
|
||||
return meanFilter(coord);
|
||||
}
|
||||
}
|
||||
}
|
||||
)");
|
||||
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHICS_EFFECT_SHADER_STRING_H
|
@ -42,24 +42,12 @@ std::shared_ptr<Drawing::Image> GEAIBarShaderFilter::ProcessImage(Drawing::Canva
|
||||
return image;
|
||||
}
|
||||
|
||||
auto shader = GEShaderStore::GetInstance()->GetShader(SHADER_AIBAR);
|
||||
if (shader == nullptr) {
|
||||
return image;
|
||||
}
|
||||
|
||||
auto builder = std::make_shared<Drawing::RuntimeShaderBuilder>(shader->GetShader());
|
||||
|
||||
Drawing::Matrix matrix;
|
||||
auto imageShader = Drawing::ShaderEffect::CreateImageShader(*image, Drawing::TileMode::CLAMP,
|
||||
Drawing::TileMode::CLAMP, Drawing::SamplingOptions(Drawing::FilterMode::LINEAR), matrix);
|
||||
|
||||
builder->SetChild("imageShader", imageShader);
|
||||
builder->SetUniform("low", aiBarLow_); // aiInvertCoef[0] is low
|
||||
builder->SetUniform("high", aiBarHigh_); // aiInvertCoef[1] is high
|
||||
builder->SetUniform("threshold", aiBarThreshold_); // aiInvertCoef[2] is threshold
|
||||
builder->SetUniform("opacity", aiBarOpacity_); // aiInvertCoef[3] is opacity
|
||||
builder->SetUniform("saturation", aiBarSaturation_); // aiInvertCoef[4] is saturation
|
||||
|
||||
float imageWidth = image->GetWidth();
|
||||
float imageHeight = image->GetHeight();
|
||||
auto builder = MakeBinarizationShader(imageWidth, imageHeight, imageShader);
|
||||
auto invertedImage = builder->MakeImage(canvas.GetGPUContext().get(), nullptr, image->GetImageInfo(), false);
|
||||
if (invertedImage == nullptr) {
|
||||
LOGE("GEAIBarShaderFilter::ProcessImage invertedImage is null");
|
||||
@ -69,5 +57,52 @@ std::shared_ptr<Drawing::Image> GEAIBarShaderFilter::ProcessImage(Drawing::Canva
|
||||
return invertedImage;
|
||||
}
|
||||
|
||||
std::shared_ptr<Drawing::RuntimeShaderBuilder> GEAIBarShaderFilter::MakeBinarizationShader(
|
||||
float imageWidth, float imageHeight, std::shared_ptr<Drawing::ShaderEffect> imageShader)
|
||||
{
|
||||
static std::shared_ptr<Drawing::RuntimeEffect> binarizationShaderEffect_;
|
||||
|
||||
// coefficient of saturation borrowed from
|
||||
// the saturate filter in RSProperties::GenerateColorFilter()
|
||||
static constexpr char prog[] = R"(
|
||||
uniform half low;
|
||||
uniform half high;
|
||||
uniform half threshold;
|
||||
uniform half opacity;
|
||||
uniform half saturation;
|
||||
uniform shader imageShader;
|
||||
|
||||
const vec3 toLuminance = vec3(0.3086, 0.6094, 0.0820);
|
||||
|
||||
half4 main(float2 coord) {
|
||||
half3 c = imageShader.eval(coord).rgb;
|
||||
float gray = 0.299 * c.r + 0.587 * c.g + 0.114 * c.b;
|
||||
float bin = mix(high, low, step(threshold, gray));
|
||||
float luminance = dot(c, toLuminance);
|
||||
half3 satAdjust = mix(vec3(luminance), c, saturation);
|
||||
half3 res = satAdjust - (opacity + 1.0) * gray + bin;
|
||||
return half4(mix(c, res, 0.42857), 1.0);
|
||||
}
|
||||
)";
|
||||
|
||||
if (binarizationShaderEffect_ == nullptr) {
|
||||
binarizationShaderEffect_ = Drawing::RuntimeEffect::CreateForShader(prog);
|
||||
if (binarizationShaderEffect_ == nullptr) {
|
||||
LOGE("MakeBinarizationShader::RuntimeShader effect error\n");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
std::shared_ptr<Drawing::RuntimeShaderBuilder> builder =
|
||||
std::make_shared<Drawing::RuntimeShaderBuilder>(binarizationShaderEffect_);
|
||||
builder->SetChild("imageShader", imageShader);
|
||||
builder->SetUniform("low", aiBarLow_); // aiInvertCoef[0] is low
|
||||
builder->SetUniform("high", aiBarHigh_); // aiInvertCoef[1] is high
|
||||
builder->SetUniform("threshold", aiBarThreshold_); // aiInvertCoef[2] is threshold
|
||||
builder->SetUniform("opacity", aiBarOpacity_); // aiInvertCoef[3] is opacity
|
||||
builder->SetUniform("saturation", aiBarSaturation_); // aiInvertCoef[4] is saturation
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* 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 "ge_cache.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace GraphicsEffectEngine {
|
||||
|
||||
GECache& GECache::GetInstance()
|
||||
{
|
||||
static std::mutex mtx;
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
static GECache instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void GECache::Set(size_t key, const std::shared_ptr<Drawing::Image> value)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (cache_.size() >= maxCapacity_) {
|
||||
EvictLeastUsed();
|
||||
}
|
||||
auto it = keySet_.find(key);
|
||||
if (it != keySet_.end()) {
|
||||
accessOrder_.remove(key);
|
||||
keySet_.erase(it);
|
||||
}
|
||||
cache_[key] = value;
|
||||
accessOrder_.push_front(key);
|
||||
keySet_.insert(key);
|
||||
}
|
||||
|
||||
const std::shared_ptr<Drawing::Image> GECache::Get(size_t key) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto it = cache_.find(key);
|
||||
if (it != cache_.end()) {
|
||||
return it->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void GECache::EvictLeastUsed()
|
||||
{
|
||||
size_t key = accessOrder_.back();
|
||||
cache_.erase(key);
|
||||
accessOrder_.pop_back();
|
||||
}
|
||||
|
||||
void GECache::SetMaxCapacity(size_t size)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
maxCapacity_ = size;
|
||||
}
|
||||
|
||||
void GECache::Clear()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
cache_.clear();
|
||||
accessOrder_.clear();
|
||||
keySet_.clear();
|
||||
}
|
||||
|
||||
} // namespace GraphicsEffectEngine
|
||||
} // namespace OHOS
|
@ -25,8 +25,14 @@ namespace Rosen {
|
||||
GEGreyShaderFilter::GEGreyShaderFilter(const Drawing::GEGreyShaderFilterParams& params)
|
||||
: greyCoef1_(params.greyCoef1), greyCoef2_(params.greyCoef2)
|
||||
{
|
||||
if (!InitGreyAdjustmentEffect()) {
|
||||
LOGE("GEGreyShaderFilter::GEGreyShaderFilter failed to construct when initializing GreyAdjustmentEffect.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static std::shared_ptr<Drawing::RuntimeEffect> g_greyAdjustEffect;
|
||||
|
||||
std::shared_ptr<Drawing::Image> GEGreyShaderFilter::ProcessImage(Drawing::Canvas& canvas,
|
||||
const std::shared_ptr<Drawing::Image> image, const Drawing::Rect& src, const Drawing::Rect& dst)
|
||||
{
|
||||
@ -35,12 +41,11 @@ std::shared_ptr<Drawing::Image> GEGreyShaderFilter::ProcessImage(Drawing::Canvas
|
||||
return image;
|
||||
}
|
||||
|
||||
auto shader = GEShaderStore::GetInstance()->GetShader(SHADER_GREY);
|
||||
if (shader == nullptr) {
|
||||
return image;
|
||||
if (!g_greyAdjustEffect) {
|
||||
LOGE("GEGreyShaderFilter::DrawGreyAdjustment greyAdjustEffect is null");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Drawing::RuntimeShaderBuilder builder(shader->GetShader());
|
||||
Drawing::RuntimeShaderBuilder builder(g_greyAdjustEffect);
|
||||
Drawing::Matrix matrix;
|
||||
auto imageShader = Drawing::ShaderEffect::CreateImageShader(*image, Drawing::TileMode::CLAMP,
|
||||
Drawing::TileMode::CLAMP, Drawing::SamplingOptions(Drawing::FilterMode::LINEAR), matrix);
|
||||
@ -50,11 +55,69 @@ std::shared_ptr<Drawing::Image> GEGreyShaderFilter::ProcessImage(Drawing::Canvas
|
||||
builder.SetUniform("coefficient2", greyCoef2_);
|
||||
auto greyImage = builder.MakeImage(canvas.GetGPUContext().get(), nullptr, image->GetImageInfo(), false);
|
||||
if (greyImage == nullptr) {
|
||||
LOGE("DrawGreyAdjustment failed");
|
||||
LOGE("DrawGreyAdjustment successful");
|
||||
return image;
|
||||
}
|
||||
return greyImage;
|
||||
};
|
||||
|
||||
bool GEGreyShaderFilter::InitGreyAdjustmentEffect()
|
||||
{
|
||||
if (g_greyAdjustEffect != nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::string GreyGradationString(R"(
|
||||
uniform shader imageShader;
|
||||
uniform float coefficient1;
|
||||
uniform float coefficient2;
|
||||
|
||||
float poww(float x, float y) {
|
||||
return (x < 0) ? -pow(-x, y) : pow(x, y);
|
||||
}
|
||||
|
||||
float calculateT_y(float rgb) {
|
||||
if (rgb > 127.5) { rgb = 255 - rgb; }
|
||||
float b = 38.0;
|
||||
float c = 45.0;
|
||||
float d = 127.5;
|
||||
float A = 106.5; // 3 * b - 3 * c + d;
|
||||
float B = -93; // 3 * (c - 2 * b);
|
||||
float C = 114; // 3 * b;
|
||||
float p = 0.816240163988; // (3 * A * C - pow(B, 2)) / (3 * pow(A, 2));
|
||||
float q = -rgb / 106.5 + 0.262253485943; // -rgb/A - B*C/(3*pow(A,2)) + 2*pow(B,3)/(27*pow(A,3))
|
||||
float s1 = -(q / 2.0);
|
||||
float s2 = sqrt(pow(s1, 2) + pow(p / 3, 3));
|
||||
return poww((s1 + s2), 1.0 / 3) + poww((s1 - s2), 1.0 / 3) - (B / (3 * A));
|
||||
}
|
||||
|
||||
float calculateGreyAdjustY(float rgb) {
|
||||
float t_r = calculateT_y(rgb);
|
||||
return (rgb < 127.5) ? (rgb + coefficient1 * pow((1 - t_r), 3)) :
|
||||
(rgb - coefficient2 * pow((1 - t_r), 3));
|
||||
}
|
||||
|
||||
half4 main(float2 coord) {
|
||||
vec3 color = vec3(imageShader.eval(coord).r, imageShader.eval(coord).g, imageShader.eval(coord).b);
|
||||
float Y = (0.299 * color.r + 0.587 * color.g + 0.114 * color.b) * 255;
|
||||
float U = (-0.147 * color.r - 0.289 * color.g + 0.436 * color.b) * 255;
|
||||
float V = (0.615 * color.r - 0.515 * color.g - 0.100 * color.b) * 255;
|
||||
Y = calculateGreyAdjustY(Y);
|
||||
color.r = (Y + 1.14 * V) / 255.0;
|
||||
color.g = (Y - 0.39 * U - 0.58 * V) / 255.0;
|
||||
color.b = (Y + 2.03 * U) / 255.0;
|
||||
|
||||
return vec4(color, 1.0);
|
||||
}
|
||||
)");
|
||||
g_greyAdjustEffect = Drawing::RuntimeEffect::CreateForShader(GreyGradationString);
|
||||
if (g_greyAdjustEffect == nullptr) {
|
||||
LOGE("GEGreyShaderFilter::InitGreyAdjustmentEffect blurEffect create failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
@ -36,6 +36,11 @@ constexpr int32_t MAX_PASSES_LARGE_RADIUS = 7; // Maximum number of render passe
|
||||
constexpr float DILATED_CONVOLUTION_LARGE_RADIUS = 4.6f;
|
||||
// To avoid downscaling artifacts, interpolate the blurred fbo with the full composited image, up to this radius
|
||||
constexpr float MAX_CROSS_FADE_RADIUS = 10.0f;
|
||||
static std::shared_ptr<Drawing::RuntimeEffect> g_blurEffect;
|
||||
static std::shared_ptr<Drawing::RuntimeEffect> g_mixEffect;
|
||||
static std::shared_ptr<Drawing::RuntimeEffect> g_blurEffectAf;
|
||||
static std::shared_ptr<Drawing::RuntimeEffect> g_simpleFilter;
|
||||
|
||||
} // namespace
|
||||
|
||||
// Advanced Filter: we can get normalized uv offset from width and height
|
||||
@ -102,19 +107,19 @@ static const bool IS_ADVANCED_FILTER_USABLE_CHECK_ONCE = IsAdvancedFilterUsable(
|
||||
GEKawaseBlurShaderFilter::GEKawaseBlurShaderFilter(const Drawing::GEKawaseBlurShaderFilterParams& params)
|
||||
: radius_(params.radius)
|
||||
{
|
||||
GEShaderStore::GetInstance()->GetShader(SHADER_BLUR);
|
||||
// Advanced Filter
|
||||
if (IS_ADVANCED_FILTER_USABLE_CHECK_ONCE) {
|
||||
GEShaderStore::GetInstance()->GetShader(SHADER_BLURAF);
|
||||
if (!InitBlurEffect()) {
|
||||
LOGE("GEKawaseBlurShaderFilter::GEKawaseBlurShaderFilter failed when initializing BlurEffect.");
|
||||
return;
|
||||
}
|
||||
// Advanced Filter
|
||||
if (IS_ADVANCED_FILTER_USABLE_CHECK_ONCE && !InitBlurEffectForAdvancedFilter()) {
|
||||
LOGE("GEKawaseBlurShaderFilter::GEKawaseBlurShaderFilter failed when initializing BlurEffectAF.");
|
||||
return;
|
||||
}
|
||||
GEShaderStore::GetInstance()->GetShader(SHADER_MIX);
|
||||
|
||||
if (GetBlurExtraFilterEnabled()) {
|
||||
auto shader = GEShaderStore::GetInstance()->GetShader(SHADER_SIMPLE);
|
||||
if (shader == nullptr) {
|
||||
LOGE("GEKawaseBlurShaderFilter::GEKawaseBlurShaderFilter failed to construct SimpleFilter");
|
||||
return;
|
||||
}
|
||||
if (!InitMixEffect()) {
|
||||
LOGE("GEKawaseBlurShaderFilter::GEKawaseBlurShaderFilter failed when initializing MixEffect.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (radius_ < 1) {
|
||||
@ -126,6 +131,13 @@ GEKawaseBlurShaderFilter::GEKawaseBlurShaderFilter(const Drawing::GEKawaseBlurSh
|
||||
LOGI("GEKawaseBlurShaderFilter radius(%{public}d) should be [1, 8k], change to 8k.", radius_);
|
||||
radius_ = 8000; // 8000 experienced value
|
||||
}
|
||||
|
||||
if (GetBlurExtraFilterEnabled()) {
|
||||
if (!InitSimpleFilter()) {
|
||||
LOGE("GEKawaseBlurShaderFilter::GEKawaseBlurShaderFilter failed to construct SimpleFilter");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int GEKawaseBlurShaderFilter::GetRadius() const
|
||||
@ -137,31 +149,14 @@ std::shared_ptr<Drawing::ShaderEffect> GEKawaseBlurShaderFilter::ApplySimpleFilt
|
||||
const std::shared_ptr<Drawing::Image>& input, const std::shared_ptr<Drawing::ShaderEffect>& prevShader,
|
||||
const Drawing::ImageInfo& scaledInfo, const Drawing::SamplingOptions& linear) const
|
||||
{
|
||||
auto shader = GEShaderStore::GetInstance()->GetShader(SHADER_SIMPLE);
|
||||
if (shader == nullptr) {
|
||||
LOGW("Get simple shader failed");
|
||||
return prevShader;
|
||||
}
|
||||
Drawing::RuntimeShaderBuilder simpleBlurBuilder(shader->GetShader());
|
||||
simpleBlurBuilder.SetChild("imageShader", prevShader);
|
||||
Drawing::RuntimeShaderBuilder simpleBlurBuilder(g_simpleFilter);
|
||||
simpleBlurBuilder.SetChild("imageInput", prevShader);
|
||||
std::shared_ptr<Drawing::Image> tmpSimpleBlur(simpleBlurBuilder.MakeImage(
|
||||
canvas.GetGPUContext().get(), nullptr, scaledInfo, false));
|
||||
return Drawing::ShaderEffect::CreateImageShader(*tmpSimpleBlur, Drawing::TileMode::CLAMP, Drawing::TileMode::CLAMP,
|
||||
linear, Drawing::Matrix());
|
||||
}
|
||||
static std::shared_ptr<GEShader> GetAvailableShader()
|
||||
{
|
||||
// Advanced Filter: check is AF usable only the first time
|
||||
std::shared_ptr<GEShader> shader = nullptr;
|
||||
if (IS_ADVANCED_FILTER_USABLE_CHECK_ONCE) {
|
||||
shader = GEShaderStore::GetInstance()->GetShader(SHADER_BLURAF);
|
||||
}
|
||||
if (shader == nullptr) {
|
||||
shader = GEShaderStore::GetInstance()->GetShader(SHADER_BLUR);
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
std::shared_ptr<Drawing::Image> GEKawaseBlurShaderFilter::ProcessImage(Drawing::Canvas& canvas,
|
||||
const std::shared_ptr<Drawing::Image> image, const Drawing::Rect& src, const Drawing::Rect& dst)
|
||||
{
|
||||
@ -170,6 +165,9 @@ std::shared_ptr<Drawing::Image> GEKawaseBlurShaderFilter::ProcessImage(Drawing::
|
||||
}
|
||||
|
||||
auto input = image;
|
||||
if (!input) {
|
||||
return image;
|
||||
}
|
||||
CheckInputImage(canvas, image, input, src);
|
||||
ComputeRadiusAndScale(radius_);
|
||||
|
||||
@ -189,31 +187,31 @@ std::shared_ptr<Drawing::Image> GEKawaseBlurShaderFilter::ProcessImage(Drawing::
|
||||
Drawing::Matrix blurMatrix = BuildMatrix(src, scaledInfo, input);
|
||||
Drawing::SamplingOptions linear(Drawing::FilterMode::LINEAR, Drawing::MipmapMode::NONE);
|
||||
|
||||
auto shader = GetAvailableShader();
|
||||
if (shader == nullptr) {
|
||||
return image;
|
||||
}
|
||||
|
||||
// Advanced Filter: check is AF usable only the first time
|
||||
bool isUsingAF = IS_ADVANCED_FILTER_USABLE_CHECK_ONCE && g_blurEffectAf != nullptr;
|
||||
auto tmpShader = Drawing::ShaderEffect::CreateImageShader(
|
||||
*input, Drawing::TileMode::CLAMP, Drawing::TileMode::CLAMP, linear, blurMatrix);
|
||||
|
||||
Drawing::RuntimeShaderBuilder blurBuilder(shader->GetShader());
|
||||
if (GetBlurExtraFilterEnabled() && GEShaderStore::GetInstance()->GetShader(SHADER_SIMPLE) != nullptr) {
|
||||
Drawing::RuntimeShaderBuilder blurBuilder(isUsingAF ? g_blurEffectAf : g_blurEffect);
|
||||
if (GetBlurExtraFilterEnabled() && g_simpleFilter) {
|
||||
tmpShader = ApplySimpleFilter(canvas, input, tmpShader, scaledInfo, linear);
|
||||
}
|
||||
blurBuilder.SetChild("imageShader", tmpShader);
|
||||
blurBuilder.SetChild("imageInput", tmpShader);
|
||||
|
||||
auto offsetXY = radiusByPasses * blurScale_;
|
||||
SetBlurBuilderParam(blurBuilder, offsetXY, scaledInfo, width, height);
|
||||
|
||||
auto tmpBlur(blurBuilder.MakeImage(canvas.GetGPUContext().get(), nullptr, scaledInfo, false));
|
||||
|
||||
if (!tmpBlur) {
|
||||
return image;
|
||||
}
|
||||
|
||||
// And now we'll build our chain of scaled blur stages
|
||||
for (auto i = 1; i < numberOfPasses; i++) {
|
||||
auto blurShader = Drawing::ShaderEffect::CreateImageShader(
|
||||
*tmpBlur, Drawing::TileMode::CLAMP, Drawing::TileMode::CLAMP, linear, Drawing::Matrix());
|
||||
const float stepScale = static_cast<float>(i) * blurScale_;
|
||||
blurBuilder.SetChild("imageShader", blurShader);
|
||||
blurBuilder.SetChild("imageInput", blurShader);
|
||||
|
||||
// Advanced Filter
|
||||
auto offsetXYFilter = radiusByPasses * stepScale;
|
||||
@ -228,7 +226,7 @@ std::shared_ptr<Drawing::Image> GEKawaseBlurShaderFilter::ProcessImage(Drawing::
|
||||
bool GEKawaseBlurShaderFilter::IsInputValid(Drawing::Canvas& canvas, const std::shared_ptr<Drawing::Image>& image,
|
||||
const Drawing::Rect& src, const Drawing::Rect& dst)
|
||||
{
|
||||
if (!image) {
|
||||
if (!g_blurEffect || !g_mixEffect || !image) {
|
||||
LOGE("GEKawaseBlurShaderFilter::shader error");
|
||||
return false;
|
||||
}
|
||||
@ -248,8 +246,7 @@ void GEKawaseBlurShaderFilter::SetBlurBuilderParam(Drawing::RuntimeShaderBuilder
|
||||
const Drawing::ImageInfo& scaledInfo, const int width, const int height)
|
||||
{
|
||||
// Advanced Filter: check is AF usable only the first time
|
||||
auto shader = GEShaderStore::GetInstance()->GetShader(SHADER_BLURAF);
|
||||
bool isUsingAF = IS_ADVANCED_FILTER_USABLE_CHECK_ONCE && shader != nullptr;
|
||||
bool isUsingAF = IS_ADVANCED_FILTER_USABLE_CHECK_ONCE && g_blurEffectAf != nullptr;
|
||||
if (isUsingAF) {
|
||||
SkV2 offsets[BLUR_SAMPLE_COUNT];
|
||||
OffsetInfo offsetInfo = { offsetXY, offsetXY, scaledInfo.GetWidth(), scaledInfo.GetHeight() };
|
||||
@ -278,6 +275,123 @@ const OHOS::Rosen::Drawing::Matrix GEKawaseBlurShaderFilter::BuildMatrix(
|
||||
return blurMatrix;
|
||||
}
|
||||
|
||||
bool GEKawaseBlurShaderFilter::InitBlurEffect()
|
||||
{
|
||||
if (g_blurEffect != nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::string blurString(R"(
|
||||
uniform shader imageInput;
|
||||
uniform float2 in_blurOffset;
|
||||
uniform float2 in_maxSizeXY;
|
||||
|
||||
half4 main(float2 xy) {
|
||||
half4 c = imageInput.eval(xy);
|
||||
c += imageInput.eval(float2(clamp(in_blurOffset.x + xy.x, 0, in_maxSizeXY.x),
|
||||
clamp(in_blurOffset.y + xy.y, 0, in_maxSizeXY.y)));
|
||||
c += imageInput.eval(float2(clamp(in_blurOffset.x + xy.x, 0, in_maxSizeXY.x),
|
||||
clamp(-in_blurOffset.y + xy.y, 0, in_maxSizeXY.y)));
|
||||
c += imageInput.eval(float2(clamp(-in_blurOffset.x + xy.x, 0, in_maxSizeXY.x),
|
||||
clamp(in_blurOffset.y + xy.y, 0, in_maxSizeXY.y)));
|
||||
c += imageInput.eval(float2(clamp(-in_blurOffset.x + xy.x, 0, in_maxSizeXY.x),
|
||||
clamp(-in_blurOffset.y + xy.y, 0, in_maxSizeXY.y)));
|
||||
return half4(c.rgba * 0.2);
|
||||
}
|
||||
)");
|
||||
g_blurEffect = Drawing::RuntimeEffect::CreateForShader(blurString);
|
||||
if (g_blurEffect == nullptr) {
|
||||
LOGE("GEKawaseBlurShaderFilter::RuntimeShader blurEffect create failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GEKawaseBlurShaderFilter::InitMixEffect()
|
||||
{
|
||||
if (g_mixEffect != nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::string mixString(R"(
|
||||
uniform shader blurredInput;
|
||||
uniform shader originalInput;
|
||||
uniform float mixFactor;
|
||||
uniform float inColorFactor;
|
||||
|
||||
highp float random(float2 xy) {
|
||||
float t = dot(xy, float2(78.233, 12.9898));
|
||||
return fract(sin(t) * 43758.5453);
|
||||
}
|
||||
half4 main(float2 xy) {
|
||||
highp float noiseGranularity = inColorFactor / 255.0;
|
||||
half4 finalColor = mix(originalInput.eval(xy), blurredInput.eval(xy), mixFactor);
|
||||
float noise = mix(-noiseGranularity, noiseGranularity, random(xy));
|
||||
finalColor.rgb += noise;
|
||||
return finalColor;
|
||||
}
|
||||
)");
|
||||
g_mixEffect = Drawing::RuntimeEffect::CreateForShader(mixString);
|
||||
if (g_mixEffect == nullptr) {
|
||||
LOGE("GEKawaseBlurShaderFilter::RuntimeShader mixEffect create failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GEKawaseBlurShaderFilter::InitSimpleFilter()
|
||||
{
|
||||
if (g_simpleFilter != nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::string simpleShader(R"(
|
||||
uniform shader imageInput;
|
||||
half4 main(float2 xy) {
|
||||
return imageInput.eval(xy);
|
||||
}
|
||||
)");
|
||||
g_simpleFilter = Drawing::RuntimeEffect::CreateForShader(simpleShader);
|
||||
if (g_simpleFilter == nullptr) {
|
||||
LOGE("GEKawaseBlurShaderFilter::RuntimeShader failed to create simple filter");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Advanced Filter
|
||||
bool GEKawaseBlurShaderFilter::InitBlurEffectForAdvancedFilter()
|
||||
{
|
||||
if (g_blurEffectAf != nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Drawing::RuntimeEffectOptions ops;
|
||||
ops.useAF = true;
|
||||
static std::string blurStringAF(R"(
|
||||
uniform shader imageInput;
|
||||
uniform float2 in_blurOffset[5];
|
||||
|
||||
half4 main(float2 xy) {
|
||||
half4 c = half4(0, 0, 0, 0);
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
c += imageInput.eval(float2(xy.x + in_blurOffset[i].x, xy.y + in_blurOffset[i].y));
|
||||
}
|
||||
return half4(c.rgba * 0.2);
|
||||
}
|
||||
)");
|
||||
g_blurEffectAf = Drawing::RuntimeEffect::CreateForShader(blurStringAF, ops);
|
||||
if (g_blurEffectAf == nullptr) {
|
||||
LOGE("%s: RuntimeShader blurEffectAF create failed", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Drawing::Matrix GEKawaseBlurShaderFilter::GetShaderTransform(
|
||||
const Drawing::Canvas* canvas, const Drawing::Rect& blurRect, float scaleW, float scaleH)
|
||||
{
|
||||
@ -347,11 +461,8 @@ std::shared_ptr<Drawing::Image> GEKawaseBlurShaderFilter::ScaleAndAddRandomColor
|
||||
}
|
||||
|
||||
Drawing::SamplingOptions linear(Drawing::FilterMode::LINEAR, Drawing::MipmapMode::NONE);
|
||||
auto shader = GEShaderStore::GetInstance()->GetShader(SHADER_MIX);
|
||||
if (shader == nullptr) {
|
||||
return blurImage;
|
||||
}
|
||||
Drawing::RuntimeShaderBuilder mixBuilder(shader->GetShader());
|
||||
|
||||
Drawing::RuntimeShaderBuilder mixBuilder(g_mixEffect);
|
||||
const auto scaleMatrix = GetShaderTransform(
|
||||
&canvas, dst, dst.GetWidth() / blurImage->GetWidth(), dst.GetHeight() / blurImage->GetHeight());
|
||||
auto tmpShader = Drawing::ShaderEffect::CreateImageShader(
|
||||
|
@ -38,6 +38,10 @@ static bool GetMaskLinearBlurEnabled()
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::shared_ptr<Drawing::RuntimeEffect> GELinearGradientBlurShaderFilter::horizontalMeanBlurShaderEffect_ = nullptr;
|
||||
std::shared_ptr<Drawing::RuntimeEffect> GELinearGradientBlurShaderFilter::verticalMeanBlurShaderEffect_ = nullptr;
|
||||
std::shared_ptr<Drawing::RuntimeEffect> GELinearGradientBlurShaderFilter::maskBlurShaderEffect_ = nullptr;
|
||||
|
||||
GELinearGradientBlurShaderFilter::GELinearGradientBlurShaderFilter(
|
||||
const Drawing::GELinearGradientBlurShaderFilterParams& params)
|
||||
{
|
||||
@ -119,6 +123,8 @@ std::shared_ptr<Drawing::Image> GELinearGradientBlurShaderFilter::ProcessImage(D
|
||||
float radius = para->blurRadius_ - GELinearGradientBlurPara::ORIGINAL_BASE;
|
||||
radius = std::clamp(radius, 0.0f, 60.0f); // 60.0 represents largest blur radius
|
||||
radius = radius / 2 * imageScale_; // 2 half blur radius
|
||||
MakeHorizontalMeanBlurEffect();
|
||||
MakeVerticalMeanBlurEffect();
|
||||
DrawMeanLinearGradientBlur(image, canvas, radius, alphaGradientShader, dst);
|
||||
return image;
|
||||
}
|
||||
@ -283,22 +289,93 @@ std::shared_ptr<Drawing::ShaderEffect> GELinearGradientBlurShaderFilter::MakeAlp
|
||||
p.emplace_back(para->fractionStops_[i].second);
|
||||
}
|
||||
// 0.01 represents the fraction bias
|
||||
if (para->fractionStops_.back().second < (1 - 0.01)) {
|
||||
if (para->fractionStops_[para->fractionStops_.size() - 1].second < (1 - 0.01)) {
|
||||
c.emplace_back(Drawing::Color::ColorQuadSetARGB(ColorMin, ColorMax, ColorMax, ColorMax));
|
||||
// 0.01 represents the fraction bias
|
||||
p.emplace_back(para->fractionStops_.back().second + 0.01);
|
||||
p.emplace_back(para->fractionStops_[para->fractionStops_.size() - 1].second + 0.01);
|
||||
}
|
||||
return Drawing::ShaderEffect::CreateLinearGradient(pts[0], pts[1], c, p, Drawing::TileMode::CLAMP);
|
||||
}
|
||||
|
||||
void GELinearGradientBlurShaderFilter::MakeHorizontalMeanBlurEffect()
|
||||
{
|
||||
static const std::string HorizontalBlurString(
|
||||
R"(
|
||||
uniform half r;
|
||||
uniform shader imageShader;
|
||||
uniform shader gradientShader;
|
||||
half4 meanFilter(float2 coord, half radius)
|
||||
{
|
||||
half4 sum = vec4(0.0);
|
||||
half div = 0;
|
||||
for (half x = -30.0; x < 30.0; x += 1.0) {
|
||||
if (x > radius) {
|
||||
break;
|
||||
}
|
||||
if (abs(x) < radius) {
|
||||
div += 1;
|
||||
sum += imageShader.eval(coord + float2(x, 0));
|
||||
}
|
||||
}
|
||||
return half4(sum.xyz / div, 1.0);
|
||||
}
|
||||
half4 main(float2 coord)
|
||||
{
|
||||
if (abs(gradientShader.eval(coord).a - 0) < 0.001) {
|
||||
return imageShader.eval(coord);
|
||||
}
|
||||
float val = clamp(r * gradientShader.eval(coord).a, 1.0, r);
|
||||
return meanFilter(coord, val);
|
||||
}
|
||||
)");
|
||||
|
||||
if (horizontalMeanBlurShaderEffect_ == nullptr) {
|
||||
horizontalMeanBlurShaderEffect_ = Drawing::RuntimeEffect::CreateForShader(HorizontalBlurString);
|
||||
}
|
||||
}
|
||||
|
||||
void GELinearGradientBlurShaderFilter::MakeVerticalMeanBlurEffect()
|
||||
{
|
||||
static const std::string VerticalBlurString(
|
||||
R"(
|
||||
uniform half r;
|
||||
uniform shader imageShader;
|
||||
uniform shader gradientShader;
|
||||
half4 meanFilter(float2 coord, half radius)
|
||||
{
|
||||
half4 sum = vec4(0.0);
|
||||
half div = 0;
|
||||
for (half y = -30.0; y < 30.0; y += 1.0) {
|
||||
if (y > radius) {
|
||||
break;
|
||||
}
|
||||
if (abs(y) < radius) {
|
||||
div += 1;
|
||||
sum += imageShader.eval(coord + float2(0, y));
|
||||
}
|
||||
}
|
||||
return half4(sum.xyz / div, 1.0);
|
||||
}
|
||||
half4 main(float2 coord)
|
||||
{
|
||||
if (abs(gradientShader.eval(coord).a - 0) < 0.001) {
|
||||
return imageShader.eval(coord);
|
||||
}
|
||||
float val = clamp(r * gradientShader.eval(coord).a, 1.0, r);
|
||||
return meanFilter(coord, val);
|
||||
}
|
||||
)");
|
||||
|
||||
if (verticalMeanBlurShaderEffect_ == nullptr) {
|
||||
verticalMeanBlurShaderEffect_ = Drawing::RuntimeEffect::CreateForShader(VerticalBlurString);
|
||||
}
|
||||
}
|
||||
|
||||
void GELinearGradientBlurShaderFilter::DrawMeanLinearGradientBlur(const std::shared_ptr<Drawing::Image>& image,
|
||||
Drawing::Canvas& canvas, float radius, std::shared_ptr<Drawing::ShaderEffect> alphaGradientShader,
|
||||
const Drawing::Rect& dst)
|
||||
{
|
||||
auto shaderHorizontalBlur = GEShaderStore::GetInstance()->GetShader(SHADER_HORIBLUR);
|
||||
auto shaderVerticalBlur = GEShaderStore::GetInstance()->GetShader(SHADER_VERTBLUR);
|
||||
if (!shaderHorizontalBlur || !shaderVerticalBlur || !image) {
|
||||
if (!horizontalMeanBlurShaderEffect_ || !verticalMeanBlurShaderEffect_ || !image) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -339,11 +416,7 @@ std::shared_ptr<Drawing::Image> GELinearGradientBlurShaderFilter::BuildMeanLinea
|
||||
originImageInfo.GetColorType(), originImageInfo.GetAlphaType(), originImageInfo.GetColorSpace());
|
||||
Drawing::Matrix m;
|
||||
Drawing::SamplingOptions linear(Drawing::FilterMode::LINEAR, Drawing::MipmapMode::NONE);
|
||||
auto shaderHBlur = GEShaderStore::GetInstance()->GetShader(SHADER_HORIBLUR);
|
||||
if (shaderHBlur == nullptr) {
|
||||
return image;
|
||||
}
|
||||
Drawing::RuntimeShaderBuilder hBlurBuilder(shaderHBlur->GetShader());
|
||||
Drawing::RuntimeShaderBuilder hBlurBuilder(horizontalMeanBlurShaderEffect_);
|
||||
hBlurBuilder.SetUniform("r", radius);
|
||||
auto shader1 = Drawing::ShaderEffect::CreateImageShader(
|
||||
*image, Drawing::TileMode::CLAMP, Drawing::TileMode::CLAMP, linear, blurMatrix);
|
||||
@ -352,11 +425,7 @@ std::shared_ptr<Drawing::Image> GELinearGradientBlurShaderFilter::BuildMeanLinea
|
||||
std::shared_ptr<Drawing::Image> tmpBlur(
|
||||
hBlurBuilder.MakeImage(canvas.GetGPUContext().get(), nullptr, scaledInfo, false));
|
||||
|
||||
auto shaderVBlur = GEShaderStore::GetInstance()->GetShader(SHADER_VERTBLUR);
|
||||
if (shaderVBlur == nullptr) {
|
||||
return image;
|
||||
}
|
||||
Drawing::RuntimeShaderBuilder vBlurBuilder(shaderVBlur->GetShader());
|
||||
Drawing::RuntimeShaderBuilder vBlurBuilder(verticalMeanBlurShaderEffect_);
|
||||
vBlurBuilder.SetUniform("r", radius);
|
||||
auto tmpBlurShader = Drawing::ShaderEffect::CreateImageShader(
|
||||
*tmpBlur, Drawing::TileMode::CLAMP, Drawing::TileMode::CLAMP, linear, m);
|
||||
@ -416,11 +485,42 @@ std::shared_ptr<Drawing::RuntimeShaderBuilder> GELinearGradientBlurShaderFilter:
|
||||
std::shared_ptr<Drawing::ShaderEffect> srcImageShader, std::shared_ptr<Drawing::ShaderEffect> blurImageShader,
|
||||
std::shared_ptr<Drawing::ShaderEffect> gradientShader)
|
||||
{
|
||||
auto shader = GEShaderStore::GetInstance()->GetShader(SHADER_MASKBLUR);
|
||||
if (shader == nullptr) {
|
||||
return nullptr;
|
||||
if (maskBlurShaderEffect_ == nullptr) {
|
||||
static const char* prog = R"(
|
||||
uniform shader srcImageShader;
|
||||
uniform shader blurImageShader;
|
||||
uniform shader gradientShader;
|
||||
half4 meanFilter(float2 coord)
|
||||
{
|
||||
vec3 srcColor = vec3(srcImageShader.eval(coord).r,
|
||||
srcImageShader.eval(coord).g, srcImageShader.eval(coord).b);
|
||||
vec3 blurColor = vec3(blurImageShader.eval(coord).r,
|
||||
blurImageShader.eval(coord).g, blurImageShader.eval(coord).b);
|
||||
float gradient = gradientShader.eval(coord).a;
|
||||
|
||||
vec3 color = blurColor * gradient + srcColor * (1 - gradient);
|
||||
return vec4(color, 1.0);
|
||||
}
|
||||
half4 main(float2 coord)
|
||||
{
|
||||
if (abs(gradientShader.eval(coord).a) < 0.001) {
|
||||
return srcImageShader.eval(coord);
|
||||
}
|
||||
|
||||
if (abs(gradientShader.eval(coord).a) > 0.999) {
|
||||
return blurImageShader.eval(coord);
|
||||
}
|
||||
|
||||
return meanFilter(coord);
|
||||
}
|
||||
)";
|
||||
maskBlurShaderEffect_ = Drawing::RuntimeEffect::CreateForShader(prog);
|
||||
if (maskBlurShaderEffect_ == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
auto builder = std::make_shared<Drawing::RuntimeShaderBuilder>(shader->GetShader());
|
||||
|
||||
auto builder = std::make_shared<Drawing::RuntimeShaderBuilder>(maskBlurShaderEffect_);
|
||||
builder->SetChild("srcImageShader", srcImageShader);
|
||||
builder->SetChild("blurImageShader", blurImageShader);
|
||||
builder->SetChild("gradientShader", gradientShader);
|
||||
|
@ -1,369 +0,0 @@
|
||||
/*
|
||||
* 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 "ge_shader.h"
|
||||
#include "ge_shader_string.h"
|
||||
#include "ge_log.h"
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include <random>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
|
||||
static std::shared_ptr<GEShaderStore> g_ShaderStoreInstance = nullptr;
|
||||
std::shared_ptr<GEShaderStore> GEShaderStore::GetInstance()
|
||||
{
|
||||
if (g_ShaderStoreInstance == nullptr) {
|
||||
g_ShaderStoreInstance = std::make_shared<GEShaderStore>();
|
||||
g_ShaderStoreInstance->Initialize();
|
||||
}
|
||||
return g_ShaderStoreInstance;
|
||||
}
|
||||
|
||||
void GEShaderStore::RegisterShader(ShaderIndex key, const std::string& name, ShaderType type, const std::string& shader,
|
||||
const Drawing::RuntimeEffectOptions* opt)
|
||||
{
|
||||
auto sh = std::make_shared<GEShader>(name, type, shader, opt);
|
||||
shaderObjMap_[key] = sh;
|
||||
}
|
||||
|
||||
void GEShaderStore::Initialize()
|
||||
{
|
||||
LOGD("GEShaderStore::Initialize");
|
||||
RegisterShader(SHADER_AIBAR, "AIBAR", TYPE_NO_REFERENCE, g_aibarString, nullptr);
|
||||
RegisterShader(SHADER_GREY, "Grey", TYPE_NO_REFERENCE, g_greyGradationString, nullptr);
|
||||
RegisterShader(SHADER_BLUR, "blur", TYPE_REFERENCE_AROUND, g_blurString, nullptr);
|
||||
Drawing::RuntimeEffectOptions opt;
|
||||
opt.useAF = true;
|
||||
RegisterShader(SHADER_BLURAF, "blurAf", TYPE_REFERENCE_AROUND, g_blurStringAF, &opt);
|
||||
RegisterShader(SHADER_MIX, "mix", TYPE_REFERENCE_AROUND, g_mixString, nullptr);
|
||||
RegisterShader(SHADER_HORIBLUR, "horizontal", TYPE_REFERENCE_AROUND, g_hBlurString, nullptr);
|
||||
RegisterShader(SHADER_VERTBLUR, "vertical", TYPE_REFERENCE_AROUND, g_vBlurString, nullptr);
|
||||
RegisterShader(SHADER_MASKBLUR, "maskblur", TYPE_REFERENCE_AROUND, g_maskBlurString, nullptr);
|
||||
RegisterShader(SHADER_SIMPLE, "Simple", TYPE_NO_REFERENCE, g_simpleString, nullptr);
|
||||
}
|
||||
|
||||
static std::string GetKey(const std::vector<ShaderIndex>& which)
|
||||
{
|
||||
std::string key = {};
|
||||
for (auto w : which) {
|
||||
key += std::to_string(w);
|
||||
key += "_";
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
std::shared_ptr<GEShader> GEShaderStore::GetShader(ShaderIndex which)
|
||||
{
|
||||
LOGD("GEShaderStore::GetShader %{public}d ", which);
|
||||
std::string key = std::to_string(which) + "_";
|
||||
if (shaderMap_.count(key)) {
|
||||
LOGD("GetShader %{public}d is exist, total %{public}zu", which, shaderMap_.size());
|
||||
return shaderMap_[key];
|
||||
}
|
||||
|
||||
if (!shaderObjMap_.count(which)) {
|
||||
LOGD("GetShader %{public}d is NOT registered", which);
|
||||
return nullptr;
|
||||
}
|
||||
// copy a new obj because if combine failed, we don't need to recover the obj in shaderobjmap_
|
||||
std::shared_ptr<GEShader> shaderObj = std::make_shared<GEShader>(shaderObjMap_[which]);
|
||||
|
||||
if (shaderObj->Compile(shaderObj->GetOptions()) != GE_ERROR_NONE) {
|
||||
// else if failed, can be combined but can not be compiled, not accepted
|
||||
LOGD("GetShader %{public}d, shader %{public}s compile failed", which, shaderObj->GetName().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
shaderMap_[key] = shaderObj;
|
||||
return shaderObj;
|
||||
}
|
||||
|
||||
std::shared_ptr<GEShader> GEShaderStore::GetShader(const std::vector<ShaderIndex>& which)
|
||||
{
|
||||
if (which.empty()) {
|
||||
LOGD("GetShader but input is empty");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string key = GetKey(which);
|
||||
LOGD("GEShaderStore::GetShader %{public}s ", key.c_str());
|
||||
if (shaderMap_.count(key)) {
|
||||
LOGD("GetShader %{public}s is exist, total %{public}zu", key.c_str(), shaderMap_.size());
|
||||
return shaderMap_[key];
|
||||
}
|
||||
|
||||
for (auto w : which) {
|
||||
if (!shaderObjMap_.count(w)) {
|
||||
LOGD("GetShader %{public}d is NOT registered", w);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<GEShader> shaderObj = std::make_shared<GEShader>(shaderObjMap_[which[0]]);
|
||||
size_t curWhich = 1;
|
||||
for (; curWhich < which.size(); curWhich++) {
|
||||
auto rth = shaderObjMap_[which[curWhich]];
|
||||
if (!shaderObj->Combine(*rth)) {
|
||||
LOGD("GetShader %{public}s, %{public}s combine %{public}s failed",
|
||||
key.c_str(), shaderObj->GetName().c_str(), rth->GetName().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (shaderObj->Compile(shaderObj->GetOptions()) != GE_ERROR_NONE) {
|
||||
LOGD("GetShader %{public}s, shader %{public}s compile filed", key.c_str(), shaderObj->GetName().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
shaderMap_[key] = shaderObj;
|
||||
return shaderObj;
|
||||
}
|
||||
|
||||
GEShader::GEShader(
|
||||
const std::string& name, ShaderType type, const std::string& shaderStr, const Drawing::RuntimeEffectOptions* opt)
|
||||
: type_(type), name_(name), shaderStr_(shaderStr)
|
||||
{
|
||||
if (opt != nullptr) {
|
||||
opt_ = new Drawing::RuntimeEffectOptions;
|
||||
opt_->forceNoInline = opt->forceNoInline;
|
||||
opt_->useAF = opt->useAF;
|
||||
}
|
||||
}
|
||||
|
||||
GEShader::GEShader(const std::shared_ptr<GEShader> rth)
|
||||
{
|
||||
if (rth != nullptr) {
|
||||
name_ = rth->GetName();
|
||||
type_ = rth->GetType();
|
||||
shaderStr_ = rth->GetString();
|
||||
auto opt = rth->GetOptions();
|
||||
if (opt != nullptr) {
|
||||
opt_ = new Drawing::RuntimeEffectOptions;
|
||||
opt_->forceNoInline = opt->forceNoInline;
|
||||
opt_->useAF = opt->useAF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GEShader::~GEShader()
|
||||
{
|
||||
if (opt_ != nullptr) {
|
||||
delete opt_;
|
||||
opt_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::string GEShader::GetName() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
ShaderType GEShader::GetType() const
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
|
||||
std::string GEShader::GetString() const
|
||||
{
|
||||
return shaderStr_;
|
||||
}
|
||||
|
||||
GEShader& GEShader::String(const std::string& shaderStr)
|
||||
{
|
||||
shaderStr_ = shaderStr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GEShader& GEShader::Type(ShaderType type)
|
||||
{
|
||||
type_ = type;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GEShader& GEShader::Name(const std::string& name)
|
||||
{
|
||||
name_ = name;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Drawing::RuntimeEffectOptions* GEShader::GetOptions() const
|
||||
{
|
||||
return opt_;
|
||||
}
|
||||
|
||||
// if failed, nothing will be changed
|
||||
bool GEShader::Combine(const GEShader& rth)
|
||||
{
|
||||
auto ret = Connect(rth);
|
||||
if (ret != GE_ERROR_NONE) {
|
||||
LOGW("combine shader failed, cause = %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<Drawing::RuntimeEffect> GEShader::GetShader() const
|
||||
{
|
||||
return shader_;
|
||||
}
|
||||
|
||||
GE_Error GEShader::Compile(const Drawing::RuntimeEffectOptions* ops)
|
||||
{
|
||||
std::shared_ptr<Drawing::RuntimeEffect> shader;
|
||||
if (ops != nullptr) {
|
||||
shader = Drawing::RuntimeEffect::CreateForShader(shaderStr_, *ops);
|
||||
} else {
|
||||
shader = Drawing::RuntimeEffect::CreateForShader(shaderStr_);
|
||||
}
|
||||
|
||||
if (shader == nullptr) {
|
||||
LOGE("GEShader::Compile %{public}s failed", name_.c_str());
|
||||
return GE_ERROR_SHADER_COMPILE_FAILED;
|
||||
}
|
||||
shader_ = shader;
|
||||
return GE_ERROR_NONE;
|
||||
}
|
||||
|
||||
GE_Error GEShader::Connect(const GEShader& subShader)
|
||||
{
|
||||
std::string newName = name_ + "_" + subShader.GetName();
|
||||
if (subShader.GetType() != TYPE_NO_REFERENCE) {
|
||||
return GE_ERROR_NOT_ACCEPTED_CONNECT;
|
||||
}
|
||||
|
||||
std::string targetStr = {};
|
||||
if (CombineShaderString(targetStr, shaderStr_, subShader.GetString()) != GE_ERROR_NONE) {
|
||||
return GE_ERROR_SHADER_STRING_INVALID;
|
||||
}
|
||||
|
||||
name_ = newName;
|
||||
shaderStr_ = targetStr;
|
||||
|
||||
auto rthOpt = subShader.GetOptions();
|
||||
if (rthOpt != nullptr) {
|
||||
if (opt_ != nullptr) {
|
||||
opt_->useAF |= rthOpt->useAF;
|
||||
opt_->forceNoInline |= rthOpt->forceNoInline;
|
||||
} else {
|
||||
opt_ = new Drawing::RuntimeEffectOptions;
|
||||
opt_->forceNoInline = rthOpt->forceNoInline;
|
||||
opt_->useAF = rthOpt->useAF;
|
||||
}
|
||||
}
|
||||
return GE_ERROR_NONE;
|
||||
}
|
||||
|
||||
static std::string PrepareFirstString(
|
||||
const std::string& sourceStr, const std::string& oldStr, const std::string& newStr)
|
||||
{
|
||||
std::istringstream iss(sourceStr);
|
||||
std::ostringstream oss;
|
||||
std::string line;
|
||||
while (std::getline(iss, line)) {
|
||||
size_t pos = 0;
|
||||
while ((pos = line.find(oldStr, pos)) != std::string::npos) {
|
||||
// find "return ", maybe a sub path
|
||||
line.replace(pos, oldStr.length(), newStr);
|
||||
pos += newStr.length();
|
||||
}
|
||||
oss << line << '\n';
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
static std::string PrepareSecondString(
|
||||
const std::string& sourceStr, const std::string& oldStr, const std::string& newStr)
|
||||
{
|
||||
std::istringstream iss(sourceStr);
|
||||
std::ostringstream oss;
|
||||
std::string line;
|
||||
bool first = true;
|
||||
// Replace subStr with newStr in the line
|
||||
std::string reg(R"(\\.[\s\S]*[a-zA-Z0-9]*\\([a-zA-Z0-9]*\\))");
|
||||
std::regex from(oldStr + reg);
|
||||
std::string to = newStr;
|
||||
|
||||
while (std::getline(iss, line)) {
|
||||
if (first && line.find(oldStr) != std::string::npos) {
|
||||
// Skip the first line that contains subStr to remove duplicate imageShader
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
line = std::regex_replace(line, from, to);
|
||||
oss << line << '\n';
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
static std::string GenSimpleUUIDString()
|
||||
{
|
||||
const std::string characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
static constexpr int maxNumberRange = 99; // the max random number
|
||||
std::random_device randomDevice;
|
||||
std::mt19937 generator(randomDevice());
|
||||
std::uniform_int_distribution<> charDistribution(0, characters.size() - 1);
|
||||
std::uniform_int_distribution<> numDistribution(0, maxNumberRange);
|
||||
|
||||
std::string randomString = "";
|
||||
randomString += characters[charDistribution(generator)];
|
||||
randomString += std::to_string(numDistribution(generator));
|
||||
|
||||
return randomString;
|
||||
}
|
||||
/*
|
||||
the two shaders should follow the rules as below:
|
||||
1. import image param's name should be imageShader (casesentense)
|
||||
2. param of main function should be float2 type and the name should be "coord", and only one param
|
||||
*/
|
||||
GE_Error GEShader::CombineShaderString(std::string& cbStr, const std::string& shaderA, const std::string& shaderB)
|
||||
{
|
||||
// each valid shader string should be have 5 matches;
|
||||
static constexpr int validMatchCount = 5;
|
||||
static constexpr int sectionParam = 1; // 1 : the string before main
|
||||
static constexpr int sectionMainTitle = 2; // 2 : the string of main(...)
|
||||
static constexpr int sectionMainBody = 3; // 3 : the string in main
|
||||
static constexpr int sectionMainOthers = 4; // 4: the rest of shader string
|
||||
std::string var = GenSimpleUUIDString();
|
||||
auto strShaderB = PrepareSecondString(shaderB, "imageShader", var);
|
||||
|
||||
std::regex re(R"(([\s\S]*)(half4\s+main\s*\(\s*float2\s+coord\s*\)\s*\{)([\s\S]*)(\}))");
|
||||
|
||||
std::smatch matchA;
|
||||
std::regex_search(shaderA, matchA, re);
|
||||
if (matchA.size() < validMatchCount) {
|
||||
LOGW("GEShader::CombineShaderString, invalid first shader string");
|
||||
return GE_ERROR_SHADER_STRING_INVALID;
|
||||
}
|
||||
std::smatch matchB;
|
||||
std::regex_search(strShaderB, matchB, re);
|
||||
if (matchB.size() < validMatchCount) {
|
||||
LOGW("GEShader::CombineShaderString, invalid second shader string");
|
||||
return GE_ERROR_SHADER_STRING_INVALID;
|
||||
}
|
||||
// if have multi return , need to jump to next section
|
||||
std::string shaderABody = PrepareFirstString(matchA[sectionMainBody].str(), "return ", var +" = ");
|
||||
|
||||
std::string resultVar("vec4 " + var + "=vec4(1.0);\n");
|
||||
cbStr = matchA[sectionParam].str() + "\n" + matchB[sectionParam].str() + "\n" + resultVar +
|
||||
matchA[sectionMainTitle].str() + "\n{" + shaderABody + "}\n{" + matchB[sectionMainBody].str() + "}\n" +
|
||||
matchA[sectionMainOthers].str();
|
||||
|
||||
return GE_ERROR_NONE;
|
||||
}
|
||||
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
@ -21,9 +21,7 @@ ohos_unittest("GraphicsEffectTest") {
|
||||
|
||||
sources = [
|
||||
"ge_aibar_shader_filter_test.cpp",
|
||||
"ge_cache_test.cpp",
|
||||
"ge_grey_shader_filter_test.cpp",
|
||||
"ge_hash_test.cpp",
|
||||
"ge_kawase_blur_shader_filter_test.cpp",
|
||||
"ge_linear_gradient_blur_shader_filter_test.cpp",
|
||||
"ge_magnifier_shader_filter_test.cpp",
|
||||
|
@ -1,107 +0,0 @@
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include "ge_cache.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace GraphicsEffectEngine {
|
||||
|
||||
class GECacheTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
};
|
||||
|
||||
void GECacheTest::SetUpTestCase(void) {}
|
||||
void GECacheTest::TearDownTestCase(void) {}
|
||||
|
||||
void GECacheTest::SetUp() {}
|
||||
void GECacheTest::TearDown() {}
|
||||
|
||||
HWTEST_F(GECacheTest, SetAndGet, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "GECacheTest SetAndGet start";
|
||||
|
||||
// Arrange
|
||||
GECache& cache = GECache::GetInstance();
|
||||
size_t key = 123;
|
||||
std::shared_ptr<Drawing::Image> value = std::make_shared<Drawing::Image>();
|
||||
|
||||
// Act
|
||||
cache.Set(key, value);
|
||||
std::shared_ptr<Drawing::Image> retrievedValue = cache.Get(key);
|
||||
|
||||
// Assert
|
||||
EXPECT_TRUE(retrievedValue != nullptr);
|
||||
EXPECT_EQ(retrievedValue, value);
|
||||
cache.Clear();
|
||||
|
||||
GTEST_LOG_(INFO) << "GECacheTest SetAndGet end";
|
||||
}
|
||||
|
||||
HWTEST_F(GECacheTest, OverwriteValue, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "GECacheTest OverwriteValue start";
|
||||
|
||||
// Arrange
|
||||
GECache& cache = GECache::GetInstance();
|
||||
size_t key = 123; // Set a random key
|
||||
std::shared_ptr<Drawing::Image> value1 = std::make_shared<Drawing::Image>();
|
||||
std::shared_ptr<Drawing::Image> value2 = std::make_shared<Drawing::Image>();
|
||||
|
||||
// Act
|
||||
cache.Set(key, value1);
|
||||
cache.Set(key, value2);
|
||||
std::shared_ptr<Drawing::Image> retrievedValue = cache.Get(key);
|
||||
cache.Clear();
|
||||
|
||||
// Assert
|
||||
EXPECT_TRUE(retrievedValue != nullptr);
|
||||
EXPECT_EQ(retrievedValue, value2);
|
||||
|
||||
GTEST_LOG_(INFO) << "GECacheTest OverwriteValue end";
|
||||
}
|
||||
|
||||
HWTEST_F(GECacheTest, EvictLeastUsed, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "GECacheTest EvictLeastUsed start";
|
||||
|
||||
// Arrange
|
||||
GECache& cache = GECache::GetInstance();
|
||||
cache.Clear();
|
||||
cache.SetMaxCapacity(2); // Assuming a method to set max capacity
|
||||
std::shared_ptr<Drawing::Image> value1 = std::make_shared<Drawing::Image>();
|
||||
std::shared_ptr<Drawing::Image> value2 = std::make_shared<Drawing::Image>();
|
||||
std::shared_ptr<Drawing::Image> value3 = std::make_shared<Drawing::Image>();
|
||||
// Act
|
||||
cache.Set(1, value1); // Use 1 as the key here
|
||||
cache.Set(2, value2); // Use 2 as the key here
|
||||
cache.Set(3, value3); // This should evict the least used value1, use 3 as the key here
|
||||
// Assert
|
||||
EXPECT_EQ(cache.Get(1), nullptr);
|
||||
EXPECT_TRUE(cache.Get(2) == value2);
|
||||
EXPECT_TRUE(cache.Get(3) == value3);
|
||||
|
||||
GTEST_LOG_(INFO) << "GECacheTest EvictLeastUsed end";
|
||||
}
|
||||
} // namespace GraphicsEffectEngine
|
||||
} // namespace OHOS
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include "ge_hash.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace GraphicsEffectEngine {
|
||||
|
||||
// Test case for Hash32Next
|
||||
TEST(GEHashTest, Hash32Next)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "GECacheTest Hash32Next start";
|
||||
|
||||
const char* data = "Hello, world!";
|
||||
size_t bytes = strlen(data);
|
||||
uint32_t seed = 12345; // Example seed
|
||||
uint32_t previousHash = 0; // Initial hash value
|
||||
uint32_t expectedHash = 2835288348; // Compute expected hash manually
|
||||
|
||||
// Compute hash using Hash32Next
|
||||
uint32_t hash = Hash32Next(previousHash, data, bytes, seed);
|
||||
|
||||
// Check if the computed hash matches the expected hash
|
||||
EXPECT_EQ(hash, expectedHash);
|
||||
|
||||
GTEST_LOG_(INFO) << "GECacheTest Hash32Next end";
|
||||
}
|
||||
|
||||
// Test case for Hash64Next
|
||||
TEST(GEHashTest, Hash64Next)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "GECacheTest Hash64Next start";
|
||||
|
||||
const char* data = "Hello, world!";
|
||||
size_t bytes = strlen(data);
|
||||
uint64_t seed = 12345; // Example seed
|
||||
uint64_t previousHash = 0; // Initial hash value
|
||||
uint64_t expectedHash = 18252719311013571113ull;
|
||||
|
||||
// Compute hash using Hash64Next
|
||||
uint64_t hash = Hash64Next(previousHash, data, bytes, seed);
|
||||
|
||||
// Check if the computed hash matches the expected hash
|
||||
EXPECT_EQ(hash, expectedHash);
|
||||
|
||||
GTEST_LOG_(INFO) << "GECacheTest Hash64Next end";
|
||||
}
|
||||
|
||||
} // namespace GraphicsEffectEngine
|
||||
} // namespace OHOS
|
@ -180,6 +180,30 @@ HWTEST_F(GEKawaseBlurShaderFilterTest, ComputeRadiusAndScale001, TestSize.Level1
|
||||
EXPECT_EQ(geKawaseBlurShaderFilter->GetDescription(), expect);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: InitSimpleFilter001
|
||||
* @tc.desc: Verify function InitSimpleFilter
|
||||
* @tc.type:FUNC
|
||||
*/
|
||||
HWTEST_F(GEKawaseBlurShaderFilterTest, InitSimpleFilter001, TestSize.Level1)
|
||||
{
|
||||
Drawing::GEKawaseBlurShaderFilterParams params { 1 }; // 1 blur radius
|
||||
auto geKawaseBlurShaderFilter = std::make_shared<GEKawaseBlurShaderFilter>(params);
|
||||
EXPECT_TRUE(geKawaseBlurShaderFilter->InitSimpleFilter());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: InitBlurEffectForAdvancedFilter001
|
||||
* @tc.desc: Verify function InitBlurEffectForAdvancedFilter
|
||||
* @tc.type:FUNC
|
||||
*/
|
||||
HWTEST_F(GEKawaseBlurShaderFilterTest, InitBlurEffectForAdvancedFilter001, TestSize.Level1)
|
||||
{
|
||||
Drawing::GEKawaseBlurShaderFilterParams params { 1 }; // 1 blur radius
|
||||
auto geKawaseBlurShaderFilter = std::make_shared<GEKawaseBlurShaderFilter>(params);
|
||||
EXPECT_TRUE(geKawaseBlurShaderFilter->InitBlurEffectForAdvancedFilter());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CheckInputImage001
|
||||
* @tc.desc: Verify function CheckInputImage
|
||||
|
@ -497,6 +497,18 @@ HWTEST_F(GELinearGradientBlurShaderFilterTest, DrawMeanLinearGradientBlur001, Te
|
||||
filter->DrawMeanLinearGradientBlur(image_, canvas_, radius, nullptr, dst_);
|
||||
EXPECT_EQ(originalImage, image_);
|
||||
|
||||
// with HorizontalMeanBlurEffect
|
||||
filter->MakeHorizontalMeanBlurEffect();
|
||||
filter->DrawMeanLinearGradientBlur(image_, canvas_, radius, nullptr, dst_);
|
||||
EXPECT_EQ(originalImage, image_);
|
||||
|
||||
// with VerticalMeanBlurEffect
|
||||
filter->MakeVerticalMeanBlurEffect();
|
||||
filter->DrawMeanLinearGradientBlur(image_, canvas_, radius, nullptr, dst_);
|
||||
EXPECT_EQ(originalImage, image_);
|
||||
filter->MakeHorizontalMeanBlurEffect();
|
||||
filter->MakeVerticalMeanBlurEffect();
|
||||
|
||||
// test if image input is null
|
||||
filter->DrawMeanLinearGradientBlur(nullptr, canvas_, radius, nullptr, dst_);
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ int32_t XMLParser::ParseSubScreenConfig(xmlNode &node, PolicyConfigData::ScreenS
|
||||
} else if (name == "game_scene_list") {
|
||||
setResult = ParseSimplex(*thresholdNode, screenSetting.gameSceneList);
|
||||
} else if (name == "anco_scene_list") {
|
||||
setResult = ParseSimplex(*thresholdNode, screenSetting.ancoSceneList);
|
||||
setResult = ParseSimplex(*thresholdNode, screenSetting.ancoSceneList, "strategy");
|
||||
} else if (name == "app_list") {
|
||||
ParseMultiAppStrategy(*thresholdNode, screenSetting);
|
||||
} else if (name == "app_types") {
|
||||
|
@ -202,14 +202,12 @@ void HgmFrameRateManager::InitTouchManager()
|
||||
});
|
||||
touchManager_.RegisterEnterStateCallback(TouchState::DOWN_STATE,
|
||||
[this] (TouchState lastState, TouchState newState) {
|
||||
if (lastState == TouchState::IDLE_STATE) {
|
||||
HgmMultiAppStrategy::TouchInfo touchInfo = {
|
||||
.pkgName = touchManager_.GetPkgName(),
|
||||
.touchState = newState,
|
||||
.upExpectFps = OLED_120_HZ,
|
||||
};
|
||||
multiAppStrategy_.HandleTouchInfo(touchInfo);
|
||||
}
|
||||
HgmMultiAppStrategy::TouchInfo touchInfo = {
|
||||
.pkgName = touchManager_.GetPkgName(),
|
||||
.touchState = newState,
|
||||
.upExpectFps = OLED_120_HZ,
|
||||
};
|
||||
multiAppStrategy_.HandleTouchInfo(touchInfo);
|
||||
startCheck_.store(false);
|
||||
});
|
||||
touchManager_.RegisterEnterStateCallback(TouchState::IDLE_STATE,
|
||||
@ -244,17 +242,29 @@ void HgmFrameRateManager::ProcessPendingRefreshRate(
|
||||
}
|
||||
auto &hgmCore = HgmCore::Instance();
|
||||
hgmCore.SetTimestamp(timestamp);
|
||||
if (pendingRefreshRate_ != nullptr) {
|
||||
hgmCore.SetPendingConstraintRelativeTime(pendingConstraintRelativeTime_);
|
||||
hgmCore.SetPendingScreenRefreshRate(*pendingRefreshRate_);
|
||||
RS_TRACE_NAME_FMT("ProcessHgmFrameRate pendingRefreshRate: %d", *pendingRefreshRate_);
|
||||
pendingRefreshRate_.reset();
|
||||
pendingConstraintRelativeTime_ = 0;
|
||||
}
|
||||
static uint64_t lastPendingConstraintRelativeTime = 0;
|
||||
static uint32_t lastPendingRefreshRate = 0;
|
||||
if (curRefreshRateMode_ == HGM_REFRESHRATE_MODE_AUTO &&
|
||||
dvsyncInfo.isUiDvsyncOn && GetCurScreenStrategyId().find("LTPO") != std::string::npos) {
|
||||
RS_TRACE_NAME_FMT("ProcessHgmFrameRate pendingRefreshRate: %d ui-dvsync", rsRate);
|
||||
hgmCore.SetPendingScreenRefreshRate(rsRate);
|
||||
} else if (pendingRefreshRate_ != nullptr) {
|
||||
hgmCore.SetPendingConstraintRelativeTime(pendingConstraintRelativeTime_);
|
||||
lastPendingConstraintRelativeTime = pendingConstraintRelativeTime_;
|
||||
pendingConstraintRelativeTime_ = 0;
|
||||
|
||||
hgmCore.SetPendingScreenRefreshRate(*pendingRefreshRate_);
|
||||
lastPendingRefreshRate = *pendingRefreshRate_;
|
||||
pendingRefreshRate_.reset();
|
||||
RS_TRACE_NAME_FMT("ProcessHgmFrameRate pendingRefreshRate: %d", lastPendingRefreshRate);
|
||||
} else {
|
||||
if (lastPendingConstraintRelativeTime != 0) {
|
||||
hgmCore.SetPendingConstraintRelativeTime(lastPendingConstraintRelativeTime);
|
||||
}
|
||||
if (lastPendingRefreshRate != 0) {
|
||||
hgmCore.SetPendingScreenRefreshRate(lastPendingRefreshRate);
|
||||
RS_TRACE_NAME_FMT("ProcessHgmFrameRate pendingRefreshRate: %d", lastPendingRefreshRate);
|
||||
}
|
||||
}
|
||||
changeGeneratorRateValid_.store(true);
|
||||
}
|
||||
@ -439,6 +449,8 @@ void HgmFrameRateManager::FrameRateReport()
|
||||
}
|
||||
HGM_LOGD("FrameRateReport: RS(%{public}d) = %{public}d, APP(%{public}d) = %{public}d",
|
||||
GetRealPid(), rates[GetRealPid()], UNI_APP_PID, rates[UNI_APP_PID]);
|
||||
RS_TRACE_NAME_FMT("FrameRateReport: RS(%d) = %d, APP(%d) = %d",
|
||||
GetRealPid(), rates[GetRealPid()], UNI_APP_PID, rates[UNI_APP_PID]);
|
||||
FRAME_TRACE::FrameRateReport::GetInstance().SendFrameRates(rates);
|
||||
FRAME_TRACE::FrameRateReport::GetInstance().SendFrameRatesToRss(rates);
|
||||
schedulePreferredFpsChange_ = false;
|
||||
@ -490,8 +502,8 @@ bool HgmFrameRateManager::CollectFrameRateChange(FrameRateRange finalRange,
|
||||
linker.second->GetId(), appFrameRate);
|
||||
frameRateChanged = true;
|
||||
}
|
||||
if (expectedRange.min_ == OLED_NULL_HZ && expectedRange.max_ == OLED_144_HZ &&
|
||||
expectedRange.preferred_ == OLED_NULL_HZ) {
|
||||
if (expectedRange.min_ == OLED_NULL_HZ && expectedRange.preferred_ == OLED_NULL_HZ &&
|
||||
(expectedRange.max_ == OLED_144_HZ || expectedRange.max_ == OLED_NULL_HZ)) {
|
||||
continue;
|
||||
}
|
||||
RS_TRACE_NAME_FMT("HgmFrameRateManager::UniProcessData multiAppFrameRate: pid = %d, linkerId = %ld, "\
|
||||
@ -522,6 +534,11 @@ void HgmFrameRateManager::HandleFrameRateChangeForLTPO(uint64_t timestamp, bool
|
||||
}
|
||||
// ChangeGeneratorRate delay 1 frame
|
||||
if (!followRs) {
|
||||
// followRs == true means it need follow RS thread to make decision, otherwise it make decision on its own
|
||||
if (forceUpdateCallback_ != nullptr) {
|
||||
// force update to change the refresh rate soon, avoid unnecessary waiting vsync
|
||||
forceUpdateCallback_(false, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -1001,6 +1018,10 @@ void HgmFrameRateManager::MarkVoteChange(const std::string& voter)
|
||||
|
||||
// changeGenerator only once in a single vsync period
|
||||
if (!changeGeneratorRateValid_.load()) {
|
||||
if (forceUpdateCallback_ != nullptr) {
|
||||
// force update to change the refresh rate soon, avoid unnecessary waiting vsync
|
||||
forceUpdateCallback_(false, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
currRefreshRate_ = refreshRate;
|
||||
@ -1220,9 +1241,19 @@ bool HgmFrameRateManager::ProcessRefreshRateVote(
|
||||
ProcessVoteLog(curVoteInfo, true);
|
||||
return false;
|
||||
}
|
||||
if (voter == "VOTER_ANCO" && !ancoScenes_.empty() &&
|
||||
(curVoteInfo.min > OLED_60_HZ || curVoteInfo.max < OLED_90_HZ)) {
|
||||
curVoteInfo.SetRange(OLED_60_HZ, OLED_90_HZ);
|
||||
if (voter == "VOTER_ANCO" && !ancoScenes_.empty()) {
|
||||
// Multiple scene are not considered at this time
|
||||
auto configData = HgmCore::Instance().GetPolicyConfigData();
|
||||
auto screenSetting = multiAppStrategy_.GetScreenSetting();
|
||||
auto ancoSceneIt = screenSetting.ancoSceneList.find(*ancoScenes_.begin());
|
||||
uint32_t min = OLED_60_HZ;
|
||||
uint32_t max = OLED_90_HZ;
|
||||
if (configData != nullptr && ancoSceneIt != screenSetting.ancoSceneList.end() &&
|
||||
configData->strategyConfigs_.find(ancoSceneIt->second) != configData->strategyConfigs_.end()) {
|
||||
min = static_cast<uint32_t>(configData->strategyConfigs_[ancoSceneIt->second].min);
|
||||
max = static_cast<uint32_t>(configData->strategyConfigs_[ancoSceneIt->second].max);
|
||||
}
|
||||
curVoteInfo.SetRange(min, max);
|
||||
}
|
||||
ProcessVoteLog(curVoteInfo, false);
|
||||
auto [mergeVoteRange, mergeVoteInfo] = MergeRangeByPriority(voteRange, {curVoteInfo.min, curVoteInfo.max});
|
||||
|
@ -103,7 +103,7 @@ struct VoteInfo {
|
||||
|
||||
bool operator==(const VoteInfo& other) const
|
||||
{
|
||||
return this->max == other.max && this->voterName == other.voterName &&
|
||||
return this->min == other.min && this->max == other.max && this->voterName == other.voterName &&
|
||||
this->extInfo == other.extInfo && this->pid == other.pid && this->bundleName == other.bundleName;
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user