Merge branch 'master' into dev_utils

This commit is contained in:
wanganjie 2023-11-18 19:54:12 +08:00
commit 17ce6c3ec6
391 changed files with 16268 additions and 2743 deletions

View File

@ -69,7 +69,9 @@
"accessibility",
"frame_aware_sched",
"memmgr",
"memmgr_plugin"
"memmgr_plugin",
"sensor",
"qos_manager"
],
"third_party": [
"flutter",
@ -103,7 +105,6 @@
"//foundation/graphic/graphic_2d/rosen/modules/effect/skia_effectChain:skeffectchain",
"//foundation/graphic/graphic_2d/frameworks/opengl_wrapper:EGL",
"//foundation/graphic/graphic_2d/frameworks/opengl_wrapper:GLESv3",
"//foundation/graphic/graphic_2d/frameworks/surfaceimage:libnative_image",
"//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text",
"//foundation/graphic/graphic_2d/rosen/modules/effect/egl:libegl_effect",
"//foundation/graphic/graphic_2d/rosen/modules/texgine:libtexgine",
@ -134,7 +135,6 @@
"external_window.h",
"native_buffer.h",
"native_buffer_inner.h",
"native_image.h",
"ibuffer_consumer_listener.h",
"ibuffer_producer.h",
"iconsumer_surface.h",
@ -167,6 +167,16 @@
"header_base": "//foundation/graphic/graphic_2d/interfaces/inner_api/composer"
}
},
{
"type": "so",
"name": "//foundation/graphic/graphic_2d/frameworks/surfaceimage:libnative_image",
"header": {
"header_files": [
"native_image.h"
],
"header_base": "//foundation/graphic/graphic_2d/interfaces/inner_api/surface"
}
},
{
"type": "so",
"name": "//foundation/graphic/graphic_2d:libgl",
@ -332,6 +342,7 @@
"ifont_provider.h",
"system_font_provider.h",
"text_style.h",
"theme_font_provider.h",
"typography_builder.h",
"typography_style.h",
"typography_types.h",

View File

@ -33,7 +33,10 @@ ohos_shared_library("libbootanimation_utils") {
"init:libbegetutil",
]
innerapi_tags = [ "platformsdk" ]
innerapi_tags = [
"platformsdk",
"sasdk",
]
part_name = "graphic_2d"
subsystem_name = "graphic"
}

View File

@ -81,10 +81,7 @@ ohos_shared_library("surface") {
"//commonlibrary/c_utils/base:utils_config",
]
deps = [
"$graphic_2d_root/utils/gslogger:libgslogger",
"$graphic_2d_root/utils/sync_fence:sync_fence",
]
deps = [ "$graphic_2d_root/utils/sync_fence:sync_fence" ]
public_deps = [
"$graphic_2d_root/utils/buffer_handle:buffer_handle",
@ -94,6 +91,7 @@ ohos_shared_library("surface") {
external_deps = [
"c_utils:utils",
"drivers_interface_display:display_buffer_idl_headers",
"hilog:libhilog",
"hitrace:hitrace_meter",
"ipc:ipc_single",

View File

@ -36,6 +36,7 @@ struct NativeWindow : public NativeWindowMagic {
OHOS::BufferRequestConfig config = {0};
OHOS::sptr<OHOS::Surface> surface;
int64_t uiTimestamp = 0;
uint32_t lastBufferSeqNum = 0;
std::unordered_map<uint32_t, NativeWindowBuffer*> bufferCache_;
};

View File

@ -20,8 +20,46 @@
#include "buffer_log.h"
#include "native_window.h"
#include "surface_buffer_impl.h"
#include <v1_0/cm_color_space.h>
#include <v1_0/buffer_handle_meta_key_type.h>
#include <metadata_convertor.h>
using namespace OHOS;
using namespace HDI::Display::Graphic::Common::V1_0;
static std::unordered_map<OH_NativeBuffer_ColorSpace, CM_ColorSpaceType> NATIVE_COLORSPACE_TO_HDI_MAP = {
{OH_COLORSPACE_NONE, CM_COLORSPACE_NONE},
{OH_COLORSPACE_BT601_EBU_FULL, CM_BT601_EBU_FULL},
{OH_COLORSPACE_BT601_SMPTE_C_FULL, CM_BT601_SMPLE_C_FULL},
{OH_COLORSPACE_BT709_FULL, CM_BT709_FULL},
{OH_COLORSPACE_BT2020_HLG_FULL, CM_BT2020_HLG_FULL},
{OH_COLORSPACE_BT2020_PQ_FULL, CM_BT2020_PQ_FULL},
{OH_COLORSPACE_BT601_EBU_LIMIT, CM_BT601_EBU_LIMIT},
{OH_COLORSPACE_BT601_SMPTE_C_LIMIT, CM_BT601_SMPLE_C_LIMIT},
{OH_COLORSPACE_BT709_LIMIT, CM_BT709_LIMIT},
{OH_COLORSPACE_BT2020_HLG_LIMIT, CM_BT2020_HLG_LIMIT},
{OH_COLORSPACE_BT2020_PQ_LIMIT, CM_BT2020_PQ_LIMIT},
{OH_COLORSPACE_SRGB_FULL, CM_SRGB_FULL},
{OH_COLORSPACE_P3_FULL, CM_P3_FULL},
{OH_COLORSPACE_P3_HLG_FULL, CM_P3_HLG_FULL},
{OH_COLORSPACE_P3_PQ_FULL, CM_P3_PQ_FULL},
{OH_COLORSPACE_ADOBERGB_FULL, CM_ADOBERGB_FULL},
{OH_COLORSPACE_SRGB_LIMIT, CM_SRGB_LIMIT},
{OH_COLORSPACE_P3_LIMIT, CM_P3_LIMIT},
{OH_COLORSPACE_P3_HLG_LIMIT, CM_P3_HLG_LIMIT},
{OH_COLORSPACE_P3_PQ_LIMIT, CM_P3_PQ_LIMIT},
{OH_COLORSPACE_ADOBERGB_LIMIT, CM_ADOBERGB_LIMIT},
{OH_COLORSPACE_LINEAR_SRGB, CM_LINEAR_SRGB},
{OH_COLORSPACE_LINEAR_BT709, CM_LINEAR_BT709},
{OH_COLORSPACE_LINEAR_P3, CM_LINEAR_P3},
{OH_COLORSPACE_LINEAR_BT2020, CM_LINEAR_BT2020},
{OH_COLORSPACE_DISPLAY_SRGB, CM_DISPLAY_SRGB},
{OH_COLORSPACE_DISPLAY_P3_SRGB, CM_DISPLAY_P3_SRGB},
{OH_COLORSPACE_DISPLAY_P3_HLG, CM_DISPLAY_P3_HLG},
{OH_COLORSPACE_DISPLAY_P3_PQ, CM_DISPLAY_P3_PQ},
{OH_COLORSPACE_DISPLAY_BT2020_SRGB, CM_DISPLAY_BT2020_SRGB},
{OH_COLORSPACE_DISPLAY_BT2020_HLG, CM_DISPLAY_BT2020_HLG},
{OH_COLORSPACE_DISPLAY_BT2020_PQ, CM_DISPLAY_BT2020_PQ}
};
static OH_NativeBuffer* OH_NativeBufferFromSurfaceBuffer(SurfaceBuffer* buffer)
{
@ -172,3 +210,21 @@ OH_NativeBuffer* OH_NativeBufferFromNativeWindowBuffer(OHNativeWindowBuffer* nat
OH_NativeBuffer* buffer = OH_NativeBufferFromSurfaceBuffer(nativeWindowBuffer->sfbuffer);
return buffer;
}
int32_t OH_NativeBuffer_SetColorSpace(OH_NativeBuffer *buffer, OH_NativeBuffer_ColorSpace colorSpace)
{
if (buffer == nullptr || NATIVE_COLORSPACE_TO_HDI_MAP.find(colorSpace) == NATIVE_COLORSPACE_TO_HDI_MAP.end()) {
BLOGE("parameter error, please check input parameter");
return OHOS::GSERROR_INVALID_ARGUMENTS;
}
SurfaceBuffer* sbuffer = OH_NativeBufferToSurfaceBuffer(buffer);
std::vector<uint8_t> setData;
if (MetadataManager::ConvertMetadataToVec(NATIVE_COLORSPACE_TO_HDI_MAP[colorSpace], setData) != GSERROR_OK) {
return OHOS::GSERROR_INTERNAL;
}
GSError ret = sbuffer->SetMetadata(BufferHandleAttrKey::ATTRKEY_COLORSPACE_TYPE, setData);
if (GSErrorStr(ret) == "<500 api call failed>with low error <Not supported>") {
return OHOS::GSERROR_NOT_SUPPORT;
}
return ret;
}

View File

@ -74,6 +74,21 @@ OHNativeWindowBuffer* CreateNativeWindowBufferFromSurfaceBuffer(void* pSurfaceBu
NativeObjectReference(nwBuffer);
return nwBuffer;
}
OHNativeWindowBuffer* CreateNativeWindowBufferFromNativeBuffer(OH_NativeBuffer* nativeBuffer)
{
if (nativeBuffer == nullptr) {
BLOGE("parameter error, please check input parameter");
return nullptr;
}
OHNativeWindowBuffer *nwBuffer = new OHNativeWindowBuffer();
OHOS::sptr<OHOS::SurfaceBuffer> surfaceBuffer(reinterpret_cast<OHOS::SurfaceBuffer *>(nativeBuffer));
nwBuffer->sfbuffer = surfaceBuffer;
NativeObjectReference(nwBuffer);
return nwBuffer;
}
void DestroyNativeWindowBuffer(OHNativeWindowBuffer* buffer)
{
if (buffer == nullptr) {
@ -150,9 +165,35 @@ int32_t NativeWindowFlushBuffer(OHNativeWindow *window, OHNativeWindowBuffer *bu
OHOS::sptr<OHOS::SyncFence> acquireFence = new OHOS::SyncFence(fenceFd);
window->surface->FlushBuffer(buffer->sfbuffer, acquireFence, config);
for (auto &[seqNum, buf] : window->bufferCache_) {
if (buf == buffer) {
window->lastBufferSeqNum = seqNum;
break;
}
}
return OHOS::GSERROR_OK;
}
int32_t GetLastFlushedBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer)
{
if (window == nullptr) {
BLOGE("parameter error, please check input parameter");
return OHOS::GSERROR_INVALID_ARGUMENTS;
}
if (window->bufferCache_.find(window->lastBufferSeqNum) != window->bufferCache_.end()) {
if (window->bufferCache_[window->lastBufferSeqNum]->sfbuffer->GetUsage() & BUFFER_USAGE_PROTECTED) {
BLOGE("Not allowed to obtain protect surface buffer");
return OHOS::GSERROR_NO_PERMISSION;
}
buffer = window->bufferCache_[window->lastBufferSeqNum];
return OHOS::GSERROR_OK;
}
return OHOS::GSERROR_NO_BUFFER;
}
int32_t NativeWindowCancelBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer)
{
if (window == nullptr || buffer == nullptr) {
@ -389,9 +430,11 @@ NativeWindowBuffer::NativeWindowBuffer() : NativeWindowMagic(NATIVE_OBJECT_MAGIC
WEAK_ALIAS(CreateNativeWindowFromSurface, OH_NativeWindow_CreateNativeWindow);
WEAK_ALIAS(DestoryNativeWindow, OH_NativeWindow_DestroyNativeWindow);
WEAK_ALIAS(CreateNativeWindowBufferFromSurfaceBuffer, OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer);
WEAK_ALIAS(CreateNativeWindowBufferFromNativeBuffer, OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer);
WEAK_ALIAS(DestroyNativeWindowBuffer, OH_NativeWindow_DestroyNativeWindowBuffer);
WEAK_ALIAS(NativeWindowRequestBuffer, OH_NativeWindow_NativeWindowRequestBuffer);
WEAK_ALIAS(NativeWindowFlushBuffer, OH_NativeWindow_NativeWindowFlushBuffer);
WEAK_ALIAS(GetLastFlushedBuffer, OH_NativeWindow_GetLastFlushedBuffer);
WEAK_ALIAS(NativeWindowCancelBuffer, OH_NativeWindow_NativeWindowAbortBuffer);
WEAK_ALIAS(NativeWindowHandleOpt, OH_NativeWindow_NativeWindowHandleOpt);
WEAK_ALIAS(GetBufferHandleFromNative, OH_NativeWindow_GetBufferHandleFromNative);

View File

@ -263,6 +263,41 @@ HWTEST_F(NativeBufferTest, OHNativeBufferGetNativeBufferConfig001, Function | Me
ASSERT_EQ(testConfig.usage, config.usage);
}
/*
* Function: OH_NativeBuffer_SetColorSpace
* Type: Function
* Rank: Important(2)
* EnvConditions: N/A
* CaseDescription: 1. call OH_NativeBuffer_SetColorSpace by abnormal input
* 2. check ret
*/
HWTEST_F(NativeBufferTest, OHNativeBufferSetColorSpace001, Function | MediumTest | Level2)
{
int32_t ret = OH_NativeBuffer_SetColorSpace(nullptr, OH_COLORSPACE_DISPLAY_BT2020_PQ);
ASSERT_NE(ret, GSERROR_OK);
}
/*
* Function: OH_NativeBuffer_SetColorSpace
* Type: Function
* Rank: Important(2)
* EnvConditions: N/A
* CaseDescription: 1. call OH_NativeBuffer_SetColorSpace
* 2. check ret
*/
HWTEST_F(NativeBufferTest, OHNativeBufferSetColorSpace002, Function | MediumTest | Level2)
{
if (buffer == nullptr) {
buffer = OH_NativeBuffer_Alloc(&config);
ASSERT_NE(buffer, nullptr);
}
int32_t ret = OH_NativeBuffer_SetColorSpace(buffer, OH_COLORSPACE_BT709_LIMIT);
if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
ASSERT_EQ(ret, GSERROR_OK);
}
}
/*
* Function: OH_NativeBuffer_Map
* Type: Function

View File

@ -98,9 +98,16 @@ public:
static inline GLuint textureId2 = 0;
static inline EGLDisplay eglDisplay_ = EGL_NO_DISPLAY;
static inline EGLContext eglContext_ = EGL_NO_CONTEXT;
static inline EGLConfig config_;;
static inline EGLConfig config_;
static void OnFrameAvailable(void *context);
};
void NativeImageTest::OnFrameAvailable(void *context)
{
(void) context;
cout << "OnFrameAvailable is called" << endl;
}
void NativeImageTest::SetUpTestCase()
{
image = nullptr;
@ -562,6 +569,92 @@ HWTEST_F(NativeImageTest, OHNativeImageUpdateSurfaceImage005, Function | MediumT
ASSERT_EQ(ret, SURFACE_ERROR_OK);
}
/*
* Function: OH_NativeImage_GetSurfaceId
* Type: Function
* Rank: Important(1)
* EnvConditions: N/A
* CaseDescription: 1. create image
* 2. GetSurfaceId
* 2. check ret
* @tc.require: issueI86VH2
*/
HWTEST_F(NativeImageTest, OHNativeImageGetSurfaceId001, Function | MediumTest | Level1)
{
if (image == nullptr) {
image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
ASSERT_NE(image, nullptr);
}
uint64_t surfaceId;
int32_t ret = OH_NativeImage_GetSurfaceId(image, &surfaceId);
ASSERT_EQ(ret, SURFACE_ERROR_OK);
}
/*
* Function: OH_NativeImage_SetOnFrameAvailableListener
* Type: Function
* Rank: Important(1)
* EnvConditions: N/A
* CaseDescription: 1. check image and nativeWindow
* 2. call OH_NativeImage_SetOnFrameAvailableListener
* 3. call OH_NativeWindow_NativeWindowFlushBuffer
* 4. check OnFrameAvailable is called
* @tc.require: issueI86VH2
*/
HWTEST_F(NativeImageTest, OHNativeImageSetOnFrameAvailableListener001, Function | MediumTest | Level1)
{
if (image == nullptr) {
image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
ASSERT_NE(image, nullptr);
}
if (nativeWindow == nullptr) {
nativeWindow = OH_NativeImage_AcquireNativeWindow(image);
ASSERT_NE(nativeWindow, nullptr);
}
OH_OnFrameAvailableListener listener;
listener.context = this;
listener.onFrameAvailable = NativeImageTest::OnFrameAvailable;
int32_t ret = OH_NativeImage_SetOnFrameAvailableListener(image, listener);
ASSERT_EQ(ret, GSERROR_OK);
NativeWindowBuffer* nativeWindowBuffer = nullptr;
int fenceFd = -1;
ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
ASSERT_EQ(ret, GSERROR_OK);
struct Region *region = new Region();
struct Region::Rect *rect = new Region::Rect();
rect->x = 0x100;
rect->y = 0x100;
rect->w = 0x100;
rect->h = 0x100;
region->rects = rect;
ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
ASSERT_EQ(ret, GSERROR_OK);
delete region;
ret = OH_NativeImage_UpdateSurfaceImage(image);
ASSERT_EQ(ret, SURFACE_ERROR_OK);
}
/*
* Function: OH_NativeImage_UnsetOnFrameAvailableListener
* Type: Function
* Rank: Important(1)
* EnvConditions: N/A
* CaseDescription: 1. call OH_NativeImage_UnsetOnFrameAvailableListener
* 2. check ret
* @tc.require: issueI86VH2
*/
HWTEST_F(NativeImageTest, OHNativeImageUnsetOnFrameAvailableListener001, Function | MediumTest | Level1)
{
int32_t ret = OH_NativeImage_UnsetOnFrameAvailableListener(image);
ASSERT_EQ(ret, SURFACE_ERROR_OK);
}
/*
* Function: OH_NativeImage_Destroy
* Type: Function

View File

@ -307,6 +307,23 @@ HWTEST_F(NativeWindowTest, CreateNativeWindowBuffer002, Function | MediumTest |
ASSERT_NE(nativeWindowBuffer, nullptr);
}
/*
* Function: OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer
* Type: Function
* Rank: Important(2)
* EnvConditions: N/A
* CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer
* 2. check ret
*/
HWTEST_F(NativeWindowTest, CreateNativeWindowBuffer003, Function | MediumTest | Level2)
{
OH_NativeBuffer* nativeBuffer = sBuffer->SurfaceBufferToNativeBuffer();
ASSERT_NE(nativeBuffer, nullptr);
NativeWindowBuffer* nwBuffer = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(nativeBuffer);
ASSERT_NE(nwBuffer, nullptr);
OH_NativeWindow_DestroyNativeWindowBuffer(nwBuffer);
}
/*
* Function: OH_NativeWindow_NativeWindowRequestBuffer
* Type: Function
@ -442,6 +459,70 @@ HWTEST_F(NativeWindowTest, FlushBuffer003, Function | MediumTest | Level2)
delete region;
}
/*
* Function: OH_NativeWindow_GetLastFlushedBuffer
* Type: Function
* Rank: Important(2)
* EnvConditions: N/A
* CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer
* 2. call OH_NativeWindow_NativeWindowFlushBuffer
* 3. call OH_NativeWindow_GetLastFlushedBuffer
* 4. check ret
*/
HWTEST_F(NativeWindowTest, GetLastFlushedBuffer001, Function | MediumTest | Level2)
{
NativeWindowBuffer* nativeWindowBuffer = nullptr;
int fenceFd = -1;
int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
ASSERT_EQ(ret, GSERROR_OK);
struct Region *region = new Region();
struct Region::Rect *rect = new Region::Rect();
rect->x = 0x100;
rect->y = 0x100;
rect->w = 0x100;
rect->h = 0x100;
region->rects = rect;
ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
ASSERT_EQ(ret, GSERROR_OK);
NativeWindowBuffer* lastFlushedBuffer = nullptr;
ASSERT_EQ(OH_NativeWindow_GetLastFlushedBuffer(nativeWindow, lastFlushedBuffer), OHOS::GSERROR_OK);
}
/*
* Function: OH_NativeWindow_GetLastFlushedBuffer
* Type: Function
* Rank: Important(2)
* EnvConditions: N/A
* CaseDescription: 1. call NativeWindowHandleOpt set BUFFER_USAGE_PROTECTED
* 2. call OH_NativeWindow_NativeWindowRequestBuffer
* 3. call OH_NativeWindow_NativeWindowFlushBuffer
* 4. call OH_NativeWindow_GetLastFlushedBuffer
* 5. check ret
*/
HWTEST_F(NativeWindowTest, GetLastFlushedBuffer002, Function | MediumTest | Level2)
{
int code = SET_USAGE;
uint64_t usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA | BUFFER_USAGE_PROTECTED;
ASSERT_EQ(NativeWindowHandleOpt(nativeWindow, code, usage), OHOS::GSERROR_OK);
NativeWindowBuffer* nativeWindowBuffer = nullptr;
int fenceFd = -1;
int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
ASSERT_EQ(ret, GSERROR_OK);
struct Region *region = new Region();
struct Region::Rect *rect = new Region::Rect();
rect->x = 0x100;
rect->y = 0x100;
rect->w = 0x100;
rect->h = 0x100;
region->rects = rect;
ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
ASSERT_EQ(ret, GSERROR_OK);
NativeWindowBuffer* lastFlushedBuffer = nullptr;
ASSERT_EQ(OH_NativeWindow_GetLastFlushedBuffer(nativeWindow, lastFlushedBuffer), OHOS::GSERROR_NO_PERMISSION);
}
/*
* Function: OH_NativeWindow_NativeWindowAbortBuffer
* Type: Function

View File

@ -36,6 +36,7 @@ struct ImageCacheSeq {
};
static constexpr int64_t TRANSFORM_MATRIX_ELE_COUNT = 16;
typedef void (*OnBufferAvailableListener)(void *context);
class SurfaceImage : public ConsumerSurface {
public:
@ -69,6 +70,10 @@ public:
SurfaceError DetachContext();
SurfaceError GetTransformMatrix(float matrix[16]);
SurfaceError SetOnBufferAvailableListener(void *context, OnBufferAvailableListener listener);
SurfaceError UnsetOnBufferAvailableListener();
OnBufferAvailableListener listener_ = nullptr;
void *context_ = nullptr;
protected:
SurfaceError AcquireBuffer(sptr<SurfaceBuffer>& buffer, int32_t &fence,

View File

@ -99,12 +99,43 @@ int32_t OH_NativeImage_GetTransformMatrix(OH_NativeImage* image, float matrix[16
return image->consumer->GetTransformMatrix(matrix);
}
int32_t OH_NativeImage_GetSurfaceId(OH_NativeImage* image, uint64_t* surfaceId)
{
if (image == nullptr || surfaceId == nullptr || image->consumer == nullptr) {
BLOGE("parameter error, please check input parameter");
return SURFACE_ERROR_ERROR;
}
*surfaceId = image->consumer->GetUniqueId();
return SURFACE_ERROR_OK;
}
int32_t OH_NativeImage_SetOnFrameAvailableListener(OH_NativeImage* image, OH_OnFrameAvailableListener listener)
{
if (image == nullptr || image->consumer == nullptr) {
BLOGE("parameter error, please check input parameter");
return SURFACE_ERROR_ERROR;
}
return image->consumer->SetOnBufferAvailableListener(listener.context, listener.onFrameAvailable);
}
int32_t OH_NativeImage_UnsetOnFrameAvailableListener(OH_NativeImage* image)
{
if (image == nullptr || image->consumer == nullptr) {
BLOGE("parameter error, please check input parameter");
return SURFACE_ERROR_ERROR;
}
return image->consumer->UnsetOnBufferAvailableListener();
}
void OH_NativeImage_Destroy(OH_NativeImage** image)
{
if (image == nullptr || *image == nullptr) {
BLOGE("parameter error, please check input parameter");
return;
}
if ((*image)->consumer != nullptr) {
(void)(*image)->consumer->UnsetOnBufferAvailableListener();
}
if ((*image)->nativeWindow != nullptr) {
DestoryNativeWindow((*image)->nativeWindow);

View File

@ -195,7 +195,7 @@ SurfaceError SurfaceImage::UpdateSurfaceImage()
return ret;
}
if (seqNum != currentSurfaceImage_) {
if (seqNum != currentSurfaceImage_ && currentSurfaceBuffer_ != nullptr) {
ret = ReleaseBuffer(currentSurfaceBuffer_, -1);
if (ret != SURFACE_ERROR_OK) {
BLOGE("release currentSurfaceBuffer_ failed %{public}d", ret);
@ -418,6 +418,27 @@ SurfaceError SurfaceImage::WaitOnFence()
return SURFACE_ERROR_OK;
}
SurfaceError SurfaceImage::SetOnBufferAvailableListener(void *context, OnBufferAvailableListener listener)
{
std::lock_guard<std::mutex> lockGuard(opMutex_);
if (listener == nullptr) {
BLOGE("listener is nullptr");
return SURFACE_ERROR_ERROR;
}
listener_ = listener;
context_ = context;
return SURFACE_ERROR_OK;
}
SurfaceError SurfaceImage::UnsetOnBufferAvailableListener()
{
std::lock_guard<std::mutex> lockGuard(opMutex_);
listener_ = nullptr;
context_ = nullptr;
return SURFACE_ERROR_OK;
}
SurfaceImageListener::~SurfaceImageListener()
{
BLOGE("~SurfaceImageListener");
@ -435,5 +456,8 @@ void SurfaceImageListener::OnBufferAvailable()
// check here maybe a messagequeue, flag instead now
surfaceImage->OnUpdateBufferAvailableState(true);
if (surfaceImage->listener_ != nullptr) {
surfaceImage->listener_(surfaceImage->context_);
}
}
} // namespace OHOS

View File

@ -493,7 +493,7 @@ HWTEST_F(VulkanLoaderUnitTest, vkCreateDevice_Test, TestSize.Level1)
queueInfo.queueCount = 1;
queueInfo.pQueuePriorities = &defaultQueuePriority;
queueCreateInfos.push_back(queueInfo);
deviceCreateInfo.queueCreateInfoCount = static_cast<uint32_t>(queueCreateInfos.size());;
deviceCreateInfo.queueCreateInfoCount = static_cast<uint32_t>(queueCreateInfos.size());
deviceCreateInfo.pQueueCreateInfos = queueCreateInfos.data();
std::vector<const char*> deviceExtensions;

View File

@ -93,8 +93,7 @@ if (graphic_2d_feature_ace_enable_gpu) {
libvulkan = []
}
if ((graphic_2d_feature_rs_enable_eglimage &&
!graphic_2d_feature_enable_vulkan) || current_os == "android") {
if (graphic_2d_feature_rs_enable_eglimage || current_os == "android") {
gpu_defines += [
"RS_ENABLE_EGLIMAGE",
"RS_ENABLE_EGLQUERYSURFACE",

View File

@ -39,6 +39,7 @@
#include <stdint.h>
#include "buffer_handle.h"
#include "native_buffer.h"
#ifdef __cplusplus
extern "C" {
@ -268,7 +269,7 @@ typedef struct OHExtDataHandle {
} OHExtDataHandle;
/**
* @brief Creates a <b>OHNativeWindow</b> instance. A new <b>OHNativeWindow</b> instance is created each time this function is called.
* @brief Creates an <b>OHNativeWindow</b> instance. A new <b>OHNativeWindow</b> instance is created each time this function is called.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param pSurface Indicates the pointer to a <b>ProduceSurface</b>. The type is a pointer to <b>sptr<OHOS::Surface></b>.
@ -279,17 +280,17 @@ typedef struct OHExtDataHandle {
OHNativeWindow* OH_NativeWindow_CreateNativeWindow(void* pSurface);
/**
* @brief Decreases the reference count of a <b>OHNativeWindow</b> instance by 1, and when the reference count reaches 0, destroys the instance.
* @brief Decreases the reference count of an <b>OHNativeWindow</b> instance by 1, and when the reference count reaches 0, destroys the instance.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
* @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
* @since 8
* @version 1.0
*/
void OH_NativeWindow_DestroyNativeWindow(OHNativeWindow* window);
/**
* @brief Creates a <b>OHNativeWindowBuffer</b> instance. A new <b>OHNativeWindowBuffer</b> instance is created each time this function is called.
* @brief Creates an <b>OHNativeWindowBuffer</b> instance. A new <b>OHNativeWindowBuffer</b> instance is created each time this function is called.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param pSurfaceBuffer Indicates the pointer to a produce buffer. The type is <b>sptr<OHOS::SurfaceBuffer></b>.
@ -300,21 +301,32 @@ void OH_NativeWindow_DestroyNativeWindow(OHNativeWindow* window);
OHNativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(void* pSurfaceBuffer);
/**
* @brief Decreases the reference count of a <b>OHNativeWindowBuffer</b> instance by 1 and, when the reference count reaches 0, destroys the instance.
* @brief Creates an <b>OHNativeWindowBuffer</b> instance. A new <b>OHNativeWindowBuffer</b> instance is created each time this function is called.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance.
* @param nativeBuffer Indicates the pointer to a native buffer. The type is <b>OH_NativeBuffer*</b>.
* @return Returns the pointer to the <b>OHNativeWindowBuffer</b> instance created.
* @since 11
* @version 1.0
*/
OHNativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(OH_NativeBuffer* nativeBuffer);
/**
* @brief Decreases the reference count of an <b>OHNativeWindowBuffer</b> instance by 1 and, when the reference count reaches 0, destroys the instance.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param buffer Indicates the pointer to an <b>OHNativeWindowBuffer</b> instance.
* @since 8
* @version 1.0
*/
void OH_NativeWindow_DestroyNativeWindowBuffer(OHNativeWindowBuffer* buffer);
/**
* @brief Requests a <b>OHNativeWindowBuffer</b> through a <b>OHNativeWindow</b> instance for content production.
* @brief Requests an <b>OHNativeWindowBuffer</b> through an <b>OHNativeWindow</b> instance for content production.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
* @param buffer Indicates the double pointer to a <b>OHNativeWindowBuffer</b> instance.
* @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
* @param buffer Indicates the double pointer to an <b>OHNativeWindowBuffer</b> instance.
* @param fenceFd Indicates the pointer to a file descriptor handle.
* @return Returns an error code, 0 is success, otherwise, failed.
* @since 8
@ -324,11 +336,11 @@ int32_t OH_NativeWindow_NativeWindowRequestBuffer(OHNativeWindow *window,
OHNativeWindowBuffer **buffer, int *fenceFd);
/**
* @brief Flushes the <b>OHNativeWindowBuffer</b> filled with the content to the buffer queue through a <b>OHNativeWindow</b> instance for content consumption.
* @brief Flushes the <b>OHNativeWindowBuffer</b> filled with the content to the buffer queue through an <b>OHNativeWindow</b> instance for content consumption.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
* @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance.
* @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
* @param buffer Indicates the pointer to an <b>OHNativeWindowBuffer</b> instance.
* @param fenceFd Indicates a file descriptor handle, which is used for timing synchronization.
* @param region Indicates a dirty region where content is updated.
* @return Returns an error code, 0 is success, otherwise, failed.
@ -338,12 +350,24 @@ int32_t OH_NativeWindow_NativeWindowRequestBuffer(OHNativeWindow *window,
int32_t OH_NativeWindow_NativeWindowFlushBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer,
int fenceFd, Region region);
/**
* @brief Returns the <b>OHNativeWindowBuffer</b> to the buffer queue through a <b>OHNativeWindow</b> instance, without filling in any content. The <b>OHNativeWindowBuffer</b> can be used for another request.
/**
* @brief Get the last flushed <b>OHNativeWindowBuffer</b> from an <b>OHNativeWindow</b> instance.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
* @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance.
* @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
* @param buffer Indicates the pointer to an <b>OHNativeWindowBuffer</b> instance.
* @return Returns an error code, 0 is success, otherwise, failed.
* @since 11
* @version 1.0
*/
int32_t OH_NativeWindow_GetLastFlushedBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer);
/**
* @brief Returns the <b>OHNativeWindowBuffer</b> to the buffer queue through an <b>OHNativeWindow</b> instance, without filling in any content. The <b>OHNativeWindowBuffer</b> can be used for another request.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
* @param buffer Indicates the pointer to an <b>OHNativeWindowBuffer</b> instance.
* @return Returns an error code, 0 is success, otherwise, failed.
* @since 8
* @version 1.0
@ -354,7 +378,7 @@ int32_t OH_NativeWindow_NativeWindowAbortBuffer(OHNativeWindow *window, OHNative
* @brief Sets or obtains the attributes of a native window, including the width, height, and content format.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
* @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
* @param code Indicates the operation code, pointer to <b>NativeWindowOperation</b>.
* @param ... variable parameter, must correspond to code one-to-one.
* @return Returns an error code, 0 is success, otherwise, failed.
@ -364,10 +388,10 @@ int32_t OH_NativeWindow_NativeWindowAbortBuffer(OHNativeWindow *window, OHNative
int32_t OH_NativeWindow_NativeWindowHandleOpt(OHNativeWindow *window, int code, ...);
/**
* @brief Obtains the pointer to a <b>BufferHandle</b> of a <b>OHNativeWindowBuffer</b> instance.
* @brief Obtains the pointer to a <b>BufferHandle</b> of an <b>OHNativeWindowBuffer</b> instance.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance.
* @param buffer Indicates the pointer to an <b>OHNativeWindowBuffer</b> instance.
* @return Returns the pointer to the <b>BufferHandle</b> instance obtained.
* @since 8
* @version 1.0
@ -378,7 +402,7 @@ BufferHandle *OH_NativeWindow_GetBufferHandleFromNative(OHNativeWindowBuffer *bu
* @brief Adds the reference count of a native object.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param obj Indicates the pointer to a <b>OHNativeWindow</b> or <b>OHNativeWindowBuffer</b> instance.
* @param obj Indicates the pointer to an <b>OHNativeWindow</b> or <b>OHNativeWindowBuffer</b> instance.
* @return Returns an error code, 0 is success, otherwise, failed.
* @since 8
* @version 1.0
@ -389,7 +413,7 @@ int32_t OH_NativeWindow_NativeObjectReference(void *obj);
* @brief Decreases the reference count of a native object and, when the reference count reaches 0, destroys this object.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param obj Indicates the pointer to a <b>OHNativeWindow</b> or <b>OHNativeWindowBuffer</b> instance.
* @param obj Indicates the pointer to an <b>OHNativeWindow</b> or <b>OHNativeWindowBuffer</b> instance.
* @return Returns an error code, 0 is success, otherwise, failed.
* @since 8
* @version 1.0
@ -400,7 +424,7 @@ int32_t OH_NativeWindow_NativeObjectUnreference(void *obj);
* @brief Obtains the magic ID of a native object.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param obj Indicates the pointer to a <b>OHNativeWindow</b> or <b>OHNativeWindowBuffer</b> instance.
* @param obj Indicates the pointer to an <b>OHNativeWindow</b> or <b>OHNativeWindowBuffer</b> instance.
* @return Returns the magic ID, which is unique for each native object.
* @since 8
* @version 1.0
@ -411,7 +435,7 @@ int32_t OH_NativeWindow_GetNativeObjectMagic(void *obj);
* @brief Sets scalingMode of a native window.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
* @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
* @param sequence Indicates the sequence to a produce buffer.
* @param scalingMode Indicates the enum value to <b>OHScalingMode</b>
* @return Returns an error code, 0 is success, otherwise, failed.
@ -426,7 +450,7 @@ int32_t OH_NativeWindow_NativeWindowSetScalingMode(OHNativeWindow *window, uint3
* @brief Sets metaData of a native window.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
* @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
* @param sequence Indicates the sequence to a produce buffer.
* @param size Indicates the size of a <b>OHHDRMetaData</b> vector.
* @param metaDate Indicates the pointer to a <b>OHHDRMetaData</b> vector.
@ -442,7 +466,7 @@ int32_t OH_NativeWindow_NativeWindowSetMetaData(OHNativeWindow *window, uint32_t
* @brief Sets metaDataSet of a native window.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
* @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
* @param sequence Indicates the sequence to a produce buffer.
* @param key Indicates the enum value to <b>OHHDRMetadataKey</b>
* @param size Indicates the size of a uint8_t vector.
@ -459,7 +483,7 @@ int32_t OH_NativeWindow_NativeWindowSetMetaDataSet(OHNativeWindow *window, uint3
* @brief Sets tunnel handle of a native window.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
* @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
* @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
* @param handle Indicates the pointer to a <b>OHExtDataHandle</b>.
* @return Returns an error code, 0 is success, otherwise, failed.
* @since 9

View File

@ -88,6 +88,80 @@ enum OH_NativeBuffer_Format {
NATIVEBUFFER_PIXEL_FMT_BUTT = 0X7FFFFFFF /// < Invalid pixel format */
};
/**
* @brief Indicates the color space of a native buffer.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
* @since 11
* @version 1.0
*/
enum OH_NativeBuffer_ColorSpace {
/** None color space */
OH_COLORSPACE_NONE,
/** COLORPRIMARIES_BT601_P | (TRANSFUNC_BT709 << 8) | (MATRIX_BT601_P << 16) | (RANGE_FULL << 21) */
OH_COLORSPACE_BT601_EBU_FULL,
/** COLORPRIMARIES_BT601_N | (TRANSFUNC_BT709 << 8) | (MATRIX_BT601_N << 16) | (RANGE_FULL << 21)*/
OH_COLORSPACE_BT601_SMPTE_C_FULL,
/** COLORPRIMARIES_BT709 | (TRANSFUNC_BT709 << 8) | (MATRIX_BT709 << 16) | (RANGE_FULL << 21) */
OH_COLORSPACE_BT709_FULL,
/** COLORPRIMARIES_BT2020 | (TRANSFUNC_HLG << 8) | (MATRIX_BT2020 << 16) | (RANGE_FULL << 21) */
OH_COLORSPACE_BT2020_HLG_FULL,
/** COLORPRIMARIES_BT2020 | (TRANSFUNC_PQ << 8) | (MATRIX_BT2020 << 16) | (RANGE_FULL << 21) */
OH_COLORSPACE_BT2020_PQ_FULL,
/** COLORPRIMARIES_BT601_P | (TRANSFUNC_BT709 << 8) | (MATRIX_BT601_P << 16) | (RANGE_LIMITED << 21) */
OH_COLORSPACE_BT601_EBU_LIMIT,
/** COLORPRIMARIES_BT601_N | (TRANSFUNC_BT709 << 8) | (MATRIX_BT601_N << 16) | (RANGE_LIMITED << 21) */
OH_COLORSPACE_BT601_SMPTE_C_LIMIT,
/** COLORPRIMARIES_BT709 | (TRANSFUNC_BT709 << 8) | (MATRIX_BT709 << 16) | (RANGE_LIMITED << 21) */
OH_COLORSPACE_BT709_LIMIT,
/** COLORPRIMARIES_BT2020 | (TRANSFUNC_HLG << 8) | (MATRIX_BT2020 << 16) | (RANGE_LIMITED << 21) */
OH_COLORSPACE_BT2020_HLG_LIMIT,
/** COLORPRIMARIES_BT2020 | (TRANSFUNC_PQ << 8) | (MATRIX_BT2020 << 16) | (RANGE_LIMITED << 21) */
OH_COLORSPACE_BT2020_PQ_LIMIT,
/** COLORPRIMARIES_SRGB | (TRANSFUNC_SRGB << 8) | (MATRIX_BT601_N << 16) | (RANGE_FULL << 21) */
OH_COLORSPACE_SRGB_FULL,
/** COLORPRIMARIES_P3_D65 | (TRANSFUNC_SRGB << 8) | (MATRIX_P3 << 16) | (RANGE_FULL << 21) */
OH_COLORSPACE_P3_FULL,
/** COLORPRIMARIES_P3_D65 | (TRANSFUNC_HLG << 8) | (MATRIX_P3 << 16) | (RANGE_FULL << 21) */
OH_COLORSPACE_P3_HLG_FULL,
/** COLORPRIMARIES_P3_D65 | (TRANSFUNC_PQ << 8) | (MATRIX_P3 << 16) | (RANGE_FULL << 21) */
OH_COLORSPACE_P3_PQ_FULL,
/** COLORPRIMARIES_ADOBERGB | (TRANSFUNC_ADOBERGB << 8) | (MATRIX_ADOBERGB << 16) | (RANGE_FULL << 21) */
OH_COLORSPACE_ADOBERGB_FULL,
/** COLORPRIMARIES_SRGB | (TRANSFUNC_SRGB << 8) | (MATRIX_BT601_N << 16) | (RANGE_LIMITED << 21) */
OH_COLORSPACE_SRGB_LIMIT,
/** COLORPRIMARIES_P3_D65 | (TRANSFUNC_SRGB << 8) | (MATRIX_P3 << 16) | (RANGE_LIMITED << 21) */
OH_COLORSPACE_P3_LIMIT,
/** COLORPRIMARIES_P3_D65 | (TRANSFUNC_HLG << 8) | (MATRIX_P3 << 16) | (RANGE_LIMITED << 21) */
OH_COLORSPACE_P3_HLG_LIMIT,
/** COLORPRIMARIES_P3_D65 | (TRANSFUNC_PQ << 8) | (MATRIX_P3 << 16) | (RANGE_LIMITED << 21) */
OH_COLORSPACE_P3_PQ_LIMIT,
/** COLORPRIMARIES_ADOBERGB | (TRANSFUNC_ADOBERGB << 8) | (MATRIX_ADOBERGB << 16) | (RANGE_LIMITED << 21) */
OH_COLORSPACE_ADOBERGB_LIMIT,
/** COLORPRIMARIES_SRGB | (TRANSFUNC_LINEAR << 8) */
OH_COLORSPACE_LINEAR_SRGB,
/** equal to OH_COLORSPACE_LINEAR_SRGB */
OH_COLORSPACE_LINEAR_BT709,
/** COLORPRIMARIES_P3_D65 | (TRANSFUNC_LINEAR << 8) */
OH_COLORSPACE_LINEAR_P3,
/** COLORPRIMARIES_BT2020 | (TRANSFUNC_LINEAR << 8) */
OH_COLORSPACE_LINEAR_BT2020,
/** equal to OH_COLORSPACE_SRGB_FULL */
OH_COLORSPACE_DISPLAY_SRGB,
/** equal to OH_COLORSPACE_P3_FULL */
OH_COLORSPACE_DISPLAY_P3_SRGB,
/** equal to OH_COLORSPACE_P3_HLG_FULL */
OH_COLORSPACE_DISPLAY_P3_HLG,
/** equal to OH_COLORSPACE_P3_PQ_FULL */
OH_COLORSPACE_DISPLAY_P3_PQ,
/** COLORPRIMARIES_BT2020 | (TRANSFUNC_SRGB << 8) | (MATRIX_BT2020 << 16) | (RANGE_FULL << 21) */
OH_COLORSPACE_DISPLAY_BT2020_SRGB,
/** equal to OH_COLORSPACE_BT2020_HLG_FULL */
OH_COLORSPACE_DISPLAY_BT2020_HLG,
/** equal to OH_COLORSPACE_BT2020_PQ_FULL */
OH_COLORSPACE_DISPLAY_BT2020_PQ,
};
/**
* @brief <b>OH_NativeBuffer</b> config. \n
* Used to allocating new <b>OH_NativeBuffer</b> andquery parameters if existing ones.
@ -187,6 +261,17 @@ int32_t OH_NativeBuffer_Unmap(OH_NativeBuffer *buffer);
*/
uint32_t OH_NativeBuffer_GetSeqNum(OH_NativeBuffer *buffer);
/**
* @brief Set the color space of the OH_NativeBuffer.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
* @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
* @param colorSpace Indicates the color space of native buffer, see <b>OH_NativeBuffer_ColorSpace</b>.
* @return Returns the sequence number, which is unique for each OH_NativeBuffer.
* @since 11
* @version 1.0
*/
int32_t OH_NativeBuffer_SetColorSpace(OH_NativeBuffer *buffer, OH_NativeBuffer_ColorSpace colorSpace);
#ifdef __cplusplus
}
#endif

View File

@ -47,6 +47,30 @@ struct OH_NativeImage;
typedef struct OH_NativeImage OH_NativeImage;
typedef struct NativeWindow OHNativeWindow;
/**
* @brief The callback function of frame available.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeImage
* @param context User defined context, returned to the user in the callback function
* @since 11
* @version 1.0
*/
typedef void (*OH_OnFrameAvailable)(void *context);
/**
* @brief A listener for native image, use <b>OH_NativeImage_SetOnFrameAvailableListener</b> to register \n
* the listener object to <b>OH_NativeImage</b>, the callback will be triggered when there is available frame
*
* @since 11
* @version 1.0
*/
typedef struct OH_OnFrameAvailableListener
{
void *context;
OH_OnFrameAvailable onFrameAvailable;
} OH_OnFrameAvailableListener;
/**
* @brief Create a <b>OH_NativeImage</b> related to an Opengl ES texture and target. \n
*
@ -120,7 +144,7 @@ int32_t OH_NativeImage_UpdateSurfaceImage(OH_NativeImage* image);
int64_t OH_NativeImage_GetTimestamp(OH_NativeImage* image);
/**
* @brief Return the transform matrix of the texture image set by the most recent call to \n
* @brief Obtains the transform matrix of the texture image set by the most recent call to \n
* OH_NativeImage_UpdateSurfaceImage.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeImage
@ -132,6 +156,41 @@ int64_t OH_NativeImage_GetTimestamp(OH_NativeImage* image);
*/
int32_t OH_NativeImage_GetTransformMatrix(OH_NativeImage* image, float matrix[16]);
/**
* @brief Obtains the native image's surface id.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeImage
* @param image Indicates the pointer to a <b>OH_NativeImage</b> instance.
* @param surfaceId Indicates the surface id.
* @return Returns an error code, 0 is success, otherwise, failed.
* @since 11
* @version 1.0
*/
int32_t OH_NativeImage_GetSurfaceId(OH_NativeImage* image, uint64_t* surfaceId);
/**
* @brief Set the frame available callback.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeImage
* @param image Indicates the pointer to a <b>OH_NativeImage</b> instance.
* @param listener Indicates the callback function.
* @return Returns an error code, 0 is success, otherwise, failed.
* @since 11
* @version 1.0
*/
int32_t OH_NativeImage_SetOnFrameAvailableListener(OH_NativeImage* image, OH_OnFrameAvailableListener listener);
/**
* @brief Unset the frame available callback.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeImage
* @param image Indicates the pointer to a <b>OH_NativeImage</b> instance.
* @return Returns an error code, 0 is success, otherwise, failed.
* @since 11
* @version 1.0
*/
int32_t OH_NativeImage_UnsetOnFrameAvailableListener(OH_NativeImage* image);
/**
* @brief Destroy the <b>OH_NativeImage</b> created by OH_NativeImage_Create, and the pointer to \n
* <b>OH_NativeImage</b> will be null after this operation.

View File

@ -35,12 +35,14 @@ void DestoryNativeWindow(OHNativeWindow* window);
// pSurfaceBuffer type is OHOS::sptr<OHOS::SurfaceBuffer>*
OHNativeWindowBuffer* CreateNativeWindowBufferFromSurfaceBuffer(void* pSurfaceBuffer);
OHNativeWindowBuffer* CreateNativeWindowBufferFromNativeBuffer(OH_NativeBuffer* nativeBuffer);
void DestroyNativeWindowBuffer(OHNativeWindowBuffer* buffer);
int32_t NativeWindowRequestBuffer(OHNativeWindow *window, /* [out] */ OHNativeWindowBuffer **buffer,
/* [out] get release fence */ int *fenceFd);
int32_t NativeWindowFlushBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer,
int fenceFd, Region region);
int32_t GetLastFlushedBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer);
int32_t NativeWindowCancelBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer);
// The meaning and quantity of parameters vary according to the code type.

View File

@ -5,5 +5,6 @@
{ "name": "OH_NativeBuffer_GetConfig" },
{ "name": "OH_NativeBuffer_Map" },
{ "name": "OH_NativeBuffer_Unmap" },
{ "name": "OH_NativeBuffer_GetSeqNum" }
{ "name": "OH_NativeBuffer_GetSeqNum" },
{ "name": "OH_NativeBuffer_SetColorSpace" }
]

View File

@ -6,5 +6,8 @@
{ "name": "OH_NativeImage_UpdateSurfaceImage" },
{ "name": "OH_NativeImage_GetTimestamp" },
{ "name": "OH_NativeImage_GetTransformMatrix" },
{ "name": "OH_NativeImage_GetSurfaceId" },
{ "name": "OH_NativeImage_SetOnFrameAvailableListener" },
{ "name": "OH_NativeImage_UnsetOnFrameAvailableListener" },
{ "name": "OH_NativeImage_Destroy" }
]

View File

@ -2,9 +2,11 @@
{ "name": "OH_NativeWindow_CreateNativeWindow" },
{ "name": "OH_NativeWindow_DestroyNativeWindow" },
{ "name": "OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer" },
{ "name": "OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer" },
{ "name": "OH_NativeWindow_DestroyNativeWindowBuffer" },
{ "name": "OH_NativeWindow_NativeWindowRequestBuffer" },
{ "name": "OH_NativeWindow_NativeWindowFlushBuffer" },
{ "name": "OH_NativeWindow_GetLastFlushedBuffer" },
{ "name": "OH_NativeWindow_NativeWindowAbortBuffer" },
{ "name": "OH_NativeWindow_NativeWindowHandleOpt" },
{ "name": "OH_NativeWindow_GetBufferHandleFromNative" },

View File

@ -18,6 +18,7 @@
#include "texgine/dynamic_font_provider.h"
#include "texgine/font_providers.h"
#include "texgine/system_font_provider.h"
#include "texgine/theme_font_provider.h"
#include "convert.h"
@ -43,17 +44,28 @@ FontCollection::FontCollection()
{
fontProviders_ = TextEngine::FontProviders::Create();
dfprovider_ = TextEngine::DynamicFontProvider::Create();
tfprovider_ = TextEngine::ThemeFontProvider::GetInstance();
}
std::shared_ptr<TextEngine::FontProviders> FontCollection::Get()
{
std::lock_guard<std::mutex> lock(mutex_);
if (fontProviders_ == nullptr) {
fontProviders_ = TextEngine::FontProviders::Create();
}
if (dfprovider_ == nullptr) {
dfprovider_ = TextEngine::DynamicFontProvider::Create();
}
if (tfprovider_ == nullptr) {
tfprovider_ = TextEngine::ThemeFontProvider::GetInstance();
}
fontProviders_->AppendFontProvider(dfprovider_);
fontProviders_->AppendFontProvider(tfprovider_);
if (!disableSystemFont_) {
fontProviders_->AppendFontProvider(TextEngine::SystemFontProvider::GetInstance());
if (sysprovider_ == nullptr) {
sysprovider_ = TextEngine::SystemFontProvider::GetInstance();
}
fontProviders_->AppendFontProvider(sysprovider_);
}
return fontProviders_;
}
@ -73,6 +85,12 @@ void FontCollection::LoadFont(const std::string &familyName, const uint8_t *data
dfprovider_->LoadFont(familyName, data, datalen);
fontProviders_->Clear();
}
void FontCollection::LoadThemeFont(const std::string &familyName, const uint8_t *data, size_t datalen)
{
tfprovider_->LoadFont(familyName, data, datalen);
fontProviders_->Clear();
}
} // namespace AdapterTextEngine
} // namespace Rosen
} // namespace OHOS

View File

@ -16,6 +16,8 @@
#ifndef ROSEN_TEXT_ADAPTER_TEXGINE_FONT_COLLECTION_H
#define ROSEN_TEXT_ADAPTER_TEXGINE_FONT_COLLECTION_H
#include <mutex>
#include "rosen_text/font_collection.h"
#ifdef USE_GRAPHIC_TEXT_GINE
@ -25,6 +27,8 @@ namespace Rosen {
namespace TextEngine {
class FontProviders;
class DynamicFontProvider;
class ThemeFontProvider;
class SystemFontProvider;
} // namespace TextEngine
#ifdef USE_GRAPHIC_TEXT_GINE
} // namespace Rosen
@ -42,11 +46,15 @@ public:
void DisableFallback() override;
void DisableSystemFont() override;
void LoadFont(const std::string &familyName, const uint8_t *data, size_t datalen) override;
void LoadThemeFont(const std::string &familyName, const uint8_t *data, size_t datalen) override;
private:
std::shared_ptr<TextEngine::FontProviders> fontProviders_ = nullptr;
std::shared_ptr<TextEngine::DynamicFontProvider> dfprovider_ = nullptr;
std::shared_ptr<TextEngine::ThemeFontProvider> tfprovider_ = nullptr;
std::shared_ptr<TextEngine::SystemFontProvider> sysprovider_ = nullptr;
bool disableSystemFont_ = false;
std::mutex mutex_;
};
} // namespace AdapterTextEngine
} // namespace Rosen

View File

@ -21,6 +21,8 @@
namespace OHOS {
namespace Rosen {
#define OHOS_THEME_FONT "OhosThemeFont"
std::shared_ptr<FontCollection> g_instance;
std::shared_ptr<FontCollection> FontCollection::Create()
@ -75,6 +77,18 @@ void FontCollection::LoadFont(const std::string &familyName, const uint8_t *data
}
fontCollection_->ClearFontFamilyCache();
}
void FontCollection::LoadThemeFont(const std::string &familyName, const uint8_t *data, size_t datalen)
{
if (familyName.empty() || data == nullptr) {
dfmanager_->font_provider().RegisterTypeface(nullptr, OHOS_THEME_FONT);
} else {
auto stream = std::make_unique<SkMemoryStream>(data, datalen, true);
auto typeface = SkTypeface::MakeFromStream(std::move(stream));
dfmanager_->font_provider().RegisterTypeface(typeface, OHOS_THEME_FONT);
}
fontCollection_->ClearFontFamilyCache();
}
} // namespace AdapterTxt
} // namespace Rosen
} // namespace OHOS

View File

@ -35,6 +35,7 @@ public:
void DisableFallback() override;
void DisableSystemFont() override;
void LoadFont(const std::string &familyName, const uint8_t *data, size_t datalen) override;
void LoadThemeFont(const std::string &familyName, const uint8_t *data, size_t datalen) override;
private:
std::shared_ptr<txt::FontCollection> fontCollection_ = nullptr;

View File

@ -37,6 +37,7 @@ public:
virtual void DisableFallback() = 0;
virtual void DisableSystemFont() = 0;
virtual void LoadFont(const std::string &familyName, const uint8_t *data, size_t datalen) = 0;
virtual void LoadThemeFont(const std::string &familyName, const uint8_t *data, size_t datalen) = 0;
};
} // namespace Rosen
} // namespace OHOS

View File

@ -86,6 +86,8 @@ template("graphics2d_source_set") {
"$drawing_src_dir/effect/image_filter.cpp",
"$drawing_src_dir/effect/mask_filter.cpp",
"$drawing_src_dir/effect/path_effect.cpp",
"$drawing_src_dir/effect/runtime_effect.cpp",
"$drawing_src_dir/effect/runtime_shader_builder.cpp",
"$drawing_src_dir/effect/shader_effect.cpp",
"$drawing_src_dir/engine_adapter/impl_factory.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/rs_skia_memory_tracer.cpp",
@ -109,7 +111,10 @@ template("graphics2d_source_set") {
"$drawing_src_dir/engine_adapter/skia_adapter/skia_path.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/skia_path_effect.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/skia_picture.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/skia_pixmap.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/skia_region.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/skia_runtime_effect.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/skia_runtime_shader_builder.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/skia_shader_effect.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/skia_static_factory.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/skia_surface.cpp",
@ -122,6 +127,7 @@ template("graphics2d_source_set") {
"$drawing_src_dir/image/bitmap.cpp",
"$drawing_src_dir/image/image.cpp",
"$drawing_src_dir/image/picture.cpp",
"$drawing_src_dir/image/pixmap.cpp",
"$drawing_src_dir/image/trace_memory_dump.cpp",
"$drawing_src_dir/recording/adaptive_image_helper.cpp",
"$drawing_src_dir/recording/cmd_list.cpp",
@ -429,6 +435,8 @@ ohos_shared_library("2d_graphics_canvaskit0310") {
"$drawing_src_dir/effect/image_filter.cpp",
"$drawing_src_dir/effect/mask_filter.cpp",
"$drawing_src_dir/effect/path_effect.cpp",
"$drawing_src_dir/effect/runtime_effect.cpp",
"$drawing_src_dir/effect/runtime_shader_builder.cpp",
"$drawing_src_dir/effect/shader_effect.cpp",
"$drawing_src_dir/engine_adapter/impl_factory.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/skia_bitmap.cpp",
@ -446,10 +454,14 @@ ohos_shared_library("2d_graphics_canvaskit0310") {
"$drawing_src_dir/engine_adapter/skia_adapter/skia_path.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/skia_path_effect.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/skia_picture.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/skia_pixmap.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/skia_runtime_effect.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/skia_runtime_shader_builder.cpp",
"$drawing_src_dir/engine_adapter/skia_adapter/skia_shader_effect.cpp",
"$drawing_src_dir/image/bitmap.cpp",
"$drawing_src_dir/image/image.cpp",
"$drawing_src_dir/image/picture.cpp",
"$drawing_src_dir/image/pixmap.cpp",
"$drawing_src_dir/text/text.cpp",
"$drawing_src_dir/utils/camera3d.cpp",
"$drawing_src_dir/utils/matrix.cpp",

View File

@ -37,7 +37,7 @@ public:
Color GetColor() const;
void SetColor(const Color& c);
void SetColor(int c);
void SetARGB(int r, int g, int b, int a);
void SetARGB(int a, int r, int g, int b);
Color4f GetColor4f();
std::shared_ptr<ColorSpace> GetColorSpace() const;

View File

@ -34,6 +34,7 @@ enum ColorType {
COLORTYPE_ARGB_4444,
COLORTYPE_RGBA_8888,
COLORTYPE_BGRA_8888,
COLORTYPE_RGBA_F16,
COLORTYPE_N32,
};

View File

@ -91,6 +91,7 @@ public:
virtual void ArcTo(scalar pt1X, scalar pt1Y, scalar pt2X, scalar pt2Y, scalar startAngle, scalar sweepAngle);
virtual void ArcTo(const Point& pt1, const Point& pt2, scalar startAngle, scalar sweepAngle);
virtual void ArcTo(scalar rx, scalar ry, scalar angle, PathDirection direction, scalar endX, scalar endY);
virtual void ArcTo(scalar x1, scalar y1, scalar x2, scalar y2, scalar radius);
virtual void CubicTo(
scalar ctrlPt1X, scalar ctrlPt1Y, scalar ctrlPt2X, scalar ctrlPt2Y, scalar endPtX, scalar endPtY);
virtual void CubicTo(const Point& ctrlPt1, const Point& ctrlPt2, const Point& endPt);

View File

@ -48,7 +48,7 @@ public:
Color GetColor() const;
void SetColor(const Color& c);
void SetColor(int c);
void SetARGB(int r, int g, int b, int a);
void SetARGB(int a, int r, int g, int b);
Color4f GetColor4f();
std::shared_ptr<ColorSpace> GetColorSpace() const;

View File

@ -131,6 +131,11 @@ public:
*/
void FlushAndSubmit(bool syncCpu = false);
/*
* @brief Call to ensure all reads/writes of surface have been issue to the underlying 3D API.
*/
void Flush();
template<typename T>
const std::shared_ptr<T> GetImpl() const
{

View File

@ -74,6 +74,8 @@ public:
ColorFilter(FilterType t, const ColorMatrix& m) noexcept;
ColorFilter(FilterType t, ColorFilter& f1, ColorFilter& f2) noexcept;
ColorFilter(FilterType t) noexcept;
std::shared_ptr<Data> Serialize() const;
bool Deserialize(std::shared_ptr<Data> data);
protected:
ColorFilter() noexcept;

View File

@ -83,7 +83,8 @@ public:
ColorSpace(ColorSpaceType t) noexcept;
ColorSpace(ColorSpaceType t, const Image& image) noexcept;
ColorSpace(ColorSpaceType t, const CMSTransferFuncType& func, const CMSMatrixType& matrix) noexcept;
std::shared_ptr<Data> Serialize() const;
bool Deserialize(std::shared_ptr<Data> data);
protected:
ColorSpace() noexcept;

View File

@ -101,7 +101,10 @@ public:
ImageFilter(FilterType t, const std::vector<scalar>& coefficients, bool enforcePMColor,
std::shared_ptr<ImageFilter> background, std::shared_ptr<ImageFilter> foreground) noexcept;
ImageFilter(FilterType t, std::shared_ptr<ImageFilter> f1, std::shared_ptr<ImageFilter> f2) noexcept;
ImageFilter(FilterType t) noexcept;
std::shared_ptr<Data> Serialize() const;
bool Deserialize(std::shared_ptr<Data> data);
protected:
ImageFilter() noexcept;

View File

@ -60,7 +60,10 @@ public:
}
MaskFilter(FilterType t, BlurType blurType, scalar sigma) noexcept;
MaskFilter(FilterType t) noexcept;
std::shared_ptr<Data> Serialize() const;
bool Deserialize(std::shared_ptr<Data> data);
protected:
MaskFilter() noexcept;

View File

@ -60,6 +60,7 @@ public:
PathEffect(PathEffectType t, scalar radius) noexcept;
PathEffect(PathEffectType t, scalar segLength, scalar dev, uint32_t seedAssist) noexcept;
PathEffect(PathEffectType t, PathEffect& e1, PathEffect& e2) noexcept;
PathEffect(PathEffectType t) noexcept;
template<typename T>
const std::shared_ptr<T> GetImpl() const
@ -67,6 +68,8 @@ public:
return impl_->DowncastingTo<T>();
}
std::shared_ptr<Data> Serialize() const;
bool Deserialize(std::shared_ptr<Data> data);
protected:
PathEffect() noexcept;

View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef RUNTIME_EFFECT_H
#define RUNTIME_EFFECT_H
#include "drawing/engine_adapter/impl_interface/runtime_effect_impl.h"
#include "effect/shader_effect.h"
#include "utils/data.h"
#include "utils/matrix.h"
namespace OHOS {
namespace Rosen {
namespace Drawing {
class RuntimeEffectOptions {
public:
bool forceNoInline = false;
bool useAF = false;
};
class DRAWING_API RuntimeEffect {
public:
static std::shared_ptr<RuntimeEffect> CreateForShader(const std::string& sl,
const RuntimeEffectOptions&);
static std::shared_ptr<RuntimeEffect> CreateForShader(const std::string& sl);
RuntimeEffect(const std::string& sl, const RuntimeEffectOptions&) noexcept;
explicit RuntimeEffect(const std::string& sl) noexcept;
std::shared_ptr<ShaderEffect> MakeShader(std::shared_ptr<Data> uniforms,
std::shared_ptr<ShaderEffect> children[],
size_t childCount, const Matrix* localMatrix,
bool isOpaque);
virtual ~RuntimeEffect() = default;
virtual DrawingType GetDrawingType() const
{
return DrawingType::COMMON;
}
template<typename T>
const std::shared_ptr<T> GetImpl() const
{
return impl_->DowncastingTo<T>();
}
protected:
RuntimeEffect() noexcept;
private:
std::shared_ptr<RuntimeEffectImpl> impl_;
};
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS
#endif

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef RUNTIME_SHADER_BUILDER_H
#define RUNTIME_SHADER_BUILDER_H
#include "drawing/engine_adapter/impl_interface/runtime_shader_builder_impl.h"
#include "utils/drawing_macros.h"
namespace OHOS {
namespace Rosen {
namespace Drawing {
class RuntimeEffect;
class DRAWING_API RuntimeShaderBuilder {
public:
RuntimeShaderBuilder(std::shared_ptr<RuntimeEffect> runtimeEffect) noexcept;
virtual ~RuntimeShaderBuilder() = default;
std::shared_ptr<ShaderEffect> MakeShader(const Matrix* localMatrix, bool isOpaque);
std::shared_ptr<Image> MakeImage(GPUContext* gpuContext,
const Matrix* localMatrix, ImageInfo resultInfo, bool mipmapped);
void SetChild(const std::string& name, std::shared_ptr<ShaderEffect> shader);
void SetUniform(const std::string& name, float val);
void SetUniform(const std::string& name, float x, float y);
void SetUniform(const std::string& name, float x, float y, float width, float height);
private:
std::shared_ptr<RuntimeShaderBuilderImpl> impl_;
};
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS
#endif // RUNTIMR_SHADER_BUILDER_H

View File

@ -87,10 +87,11 @@ public:
const std::vector<ColorQuad>& colors, const std::vector<scalar>& pos, TileMode mode) noexcept;
ShaderEffect(ShaderEffectType t, const Point& centerPt, const std::vector<ColorQuad>& colors,
const std::vector<scalar>& pos, TileMode mode, scalar startAngle, scalar endAngle) noexcept;
protected:
ShaderEffect(ShaderEffectType t) noexcept;
ShaderEffect() noexcept;
std::shared_ptr<Data> Serialize() const;
bool Deserialize(std::shared_ptr<Data> data);
private:
ShaderEffectType type_;
std::shared_ptr<ShaderEffectImpl> impl_;

View File

@ -47,6 +47,10 @@ public:
int GetRowBytes() const;
ColorType GetColorType() const;
AlphaType GetAlphaType() const;
bool ExtractSubset(Bitmap& dst, const Rect& subset) const;
bool ReadPixels(const ImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
int srcX, int srcY) const;
bool PeekPixels(Pixmap& pixmap) const;
/*
* @brief Gets the pointer to Bitmap buffer.
@ -54,13 +58,17 @@ public:
void* GetPixels() const;
void SetPixels(void* pixel);
void CopyPixels(Bitmap& dst, int srcLeft, int srcTop) const;
bool InstallPixels(const ImageInfo& info, void* pixels, size_t rowBytes,
ReleaseProc releaseProc = nullptr, void* context = nullptr);
bool IsImmutable();
void SetImmutable();
void ClearWithColor(const ColorQuad& color) const;
bool IsValid() const;
bool IsEmpty() const;
ColorQuad GetColor(int x, int y) const;
void Free();
BitmapFormat GetFormat() const;
void SetFormat(const BitmapFormat& format);
ImageInfo GetImageInfo() const;
template<typename T>
const std::shared_ptr<T> GetImpl() const
@ -68,6 +76,9 @@ public:
return bmpImplPtr->DowncastingTo<T>();
}
std::shared_ptr<Data> Serialize() const;
bool Deserialize(std::shared_ptr<Data> data);
private:
std::shared_ptr<BitmapImpl> bmpImplPtr;
BitmapFormat format_;

View File

@ -176,11 +176,27 @@ public:
Image() noexcept;
// constructor adopt a raw image ptr, using for ArkUI, should remove after enable multi-media image decode.
explicit Image(void* rawImg) noexcept;
explicit Image(std::shared_ptr<ImageImpl> imageImpl);
virtual ~Image() {};
Image* BuildFromBitmap(const Bitmap& bitmap);
Image* BuildFromPicture(const Picture& picture, const SizeI& dimensions, const Matrix& matrix, const Brush& brush,
BitDepth bitDepth, std::shared_ptr<ColorSpace> colorSpace);
/*
* @brief Create Image from Pixmap.
* @param pixmap pixmap.
* @param rasterReleaseProc function called when pixels can be released; or nullptr.
* @param releaseContext state passed to rasterReleaseProc; or nullptr.
* @return Image sharing pixmap.
*/
static std::shared_ptr<Image> MakeFromRaster(const Pixmap& pixmap,
RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext);
/*
* @brief Create Image from ImageInfo, sharing pixels.
*/
static std::shared_ptr<Image> MakeRasterData(const ImageInfo& info, std::shared_ptr<Data> pixels,
size_t rowBytes);
#ifdef ACE_ENABLE_GPU
/*
* @brief Create Image from Bitmap. Image is uploaded to GPU back-end using context.
@ -224,6 +240,11 @@ public:
bool IsValid(GPUContext* context) const;
#endif
/*
* @brief Creates raster Bitmap with same pixels as Image.
*/
bool AsLegacyBitmap(Bitmap& bitmap) const;
/*
* @brief Gets the width of Image.
*/
@ -263,6 +284,9 @@ public:
*/
bool ReadPixels(Bitmap& bitmap, int x, int y);
bool ReadPixels(const ImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
int srcX, int srcY) const;
bool ScalePixels(const Bitmap& bitmap, const SamplingOptions& sampling,
bool allowCachingHint = true) const;
@ -270,6 +294,15 @@ public:
bool IsLazyGenerated() const;
/*
* @brief Get Bitmap by image's directContext, can call it if IsLazyGenerated return false.
*/
bool GetROPixels(Bitmap& bitmap);
std::shared_ptr<Image> MakeRasterImage() const;
bool CanPeekPixels() const;
/*
* @brief Returns true the contents of Image was created on or uploaded to GPU memory,
and is available as a GPU texture.

View File

@ -80,6 +80,27 @@ public:
return colorSpace_;
}
/*
* @brief Returns number of bytes per pixel.
*/
int GetBytesPerPixel() const
{
// returns the number of bytes per pixel: 1byte, 2bytes, 4bytes
switch (colorType_) {
case COLORTYPE_ALPHA_8:
return 1;
case COLORTYPE_RGB_565:
case COLORTYPE_ARGB_4444:
return 2;
case COLORTYPE_RGBA_8888:
case COLORTYPE_BGRA_8888:
case COLORTYPE_N32:
return 4;
default:
return 0;
}
}
/*
* @brief Sets the width value of ImageInfo.
*/

View File

@ -30,7 +30,8 @@ public:
{
return pictureImplPtr->DowncastingTo<T>();
}
std::shared_ptr<Data> Serialize() const;
bool Deserialize(std::shared_ptr<Data> data);
private:
std::shared_ptr<PictureImpl> pictureImplPtr;
};

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PIXMAP_H
#define PIXMAP_H
#include "drawing/engine_adapter/impl_interface/pixmap_impl.h"
#include "utils/drawing_macros.h"
namespace OHOS {
namespace Rosen {
namespace Drawing {
class DRAWING_API Pixmap {
public:
Pixmap();
Pixmap(const ImageInfo& imageInfo, const void* addr, size_t rowBytes);
virtual ~Pixmap();
std::shared_ptr<ColorSpace> GetColorSpace();
ColorType GetColorType();
AlphaType GetAlphaType();
size_t GetRowBytes();
const void* GetAddr();
int GetWidth();
int GetHeight();
template<typename T>
const std::shared_ptr<T> GetImpl() const
{
return pixmapImplPtr->DowncastingTo<T>();
}
private:
std::shared_ptr<PixmapImpl> pixmapImplPtr;
};
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS
#endif

View File

@ -40,6 +40,12 @@ struct ImageHandle {
AlphaType alphaType;
};
struct FlattenableHandle {
uint32_t offset;
size_t size;
uint32_t type;
};
struct VerticesHandle {
uint32_t offset;
size_t size;

View File

@ -188,6 +188,29 @@ public:
static ImageHandle AddDataToCmdList(CmdList& cmdList, const Data* data);
static std::shared_ptr<Data> GetDataFromCmdList(const CmdList& cmdList, const ImageHandle& imageHandle);
static ImageHandle AddColorSpaceToCmdList(CmdList& cmdList, const std::shared_ptr<ColorSpace> colorSpace);
static std::shared_ptr<ColorSpace> GetColorSpaceFromCmdList(const CmdList& cmdList, const ImageHandle& imageHandle);
static FlattenableHandle AddShaderEffectToCmdList(CmdList& cmdList, std::shared_ptr<ShaderEffect> shaderEffect);
static std::shared_ptr<ShaderEffect> GetShaderEffectFromCmdList(const CmdList& cmdList,
const FlattenableHandle& shaderEffectHandle);
static FlattenableHandle AddPathEffectToCmdList(CmdList& cmdList, std::shared_ptr<PathEffect> pathEffect);
static std::shared_ptr<PathEffect> GetPathEffectFromCmdList(const CmdList& cmdList,
const FlattenableHandle& pathEffectHandle);
static FlattenableHandle AddMaskFilterToCmdList(CmdList& cmdList, std::shared_ptr<MaskFilter> maskFilter);
static std::shared_ptr<MaskFilter> GetMaskFilterFromCmdList(const CmdList& cmdList,
const FlattenableHandle& maskFilterHandle);
static FlattenableHandle AddColorFilterToCmdList(CmdList& cmdList, std::shared_ptr<ColorFilter> colorFilter);
static std::shared_ptr<ShaderEffect> GetColorFilterFromCmdList(const CmdList& cmdList,
const FlattenableHandle& colorFilterHandle);
static FlattenableHandle AddImageFilterToCmdList(CmdList& cmdList, std::shared_ptr<ImageFilter> imageFilter);
static std::shared_ptr<ImageFilter> GetImageFilterFromCmdList(const CmdList& cmdList,
const FlattenableHandle& imageFilterHandle);
};
} // namespace Drawing
} // namespace Rosen

View File

@ -18,6 +18,7 @@
#include <unordered_map>
#include <functional>
#include <stack>
#include "draw/canvas.h"
#include "draw/pen.h"
@ -77,19 +78,36 @@ public:
UnmarshallingPlayer(const CmdList& cmdList);
~UnmarshallingPlayer() = default;
bool Unmarshalling(uint32_t type, void* opItem);
std::shared_ptr<OpItem> Unmarshalling(uint32_t type, void* opItem);
const CmdList& cmdList_;
using UnmarshallingFunc = void(*)(const CmdList& cmdList, void* opItem);
using UnmarshallingFunc = std::shared_ptr<OpItem>(*)(const CmdList& cmdList, void* opItem);
private:
static std::unordered_map<uint32_t, UnmarshallingFunc> opUnmarshallingFuncLUT_;
};
class NoIPCImageOpItem;
class GenerateCachedOpItemPlayer {
public:
GenerateCachedOpItemPlayer(CmdList &cmdList, Canvas* canvas = nullptr, const Rect* rect = nullptr);
~GenerateCachedOpItemPlayer() = default;
std::shared_ptr<NoIPCImageOpItem> GenerateCachedOpItem(uint32_t type, void* opItem, bool addCmdList,
bool& replaceSuccess);
Canvas* canvas_;
const Rect* rect_;
CmdList& cmdList_;
std::stack<void*> brushOpItemStack;
std::stack<void*> penOpItemStack;
};
class DrawOpItem : public OpItem {
public:
explicit DrawOpItem(uint32_t type) : OpItem(type) {}
~DrawOpItem() = default;
~DrawOpItem() override = default;
enum Type : uint32_t {
OPITEM_HEAD,
@ -146,14 +164,17 @@ public:
PATCH_OPITEM,
EDGEAAQUAD_OPITEM,
VERTICES_OPITEM,
NO_IPC_IMAGE_DRAW_OPITEM,
};
};
class DrawPointOpItem : public DrawOpItem {
public:
DrawPointOpItem();
explicit DrawPointOpItem(const Point& point);
~DrawPointOpItem() = default;
~DrawPointOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -163,10 +184,11 @@ private:
class DrawPointsOpItem : public DrawOpItem {
public:
DrawPointsOpItem();
explicit DrawPointsOpItem(PointMode mode, const std::pair<uint32_t, size_t> pts);
~DrawPointsOpItem() = default;
~DrawPointsOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -180,9 +202,11 @@ private:
class DrawLineOpItem : public DrawOpItem {
public:
DrawLineOpItem();
DrawLineOpItem(const Point& startPt, const Point& endPt);
~DrawLineOpItem() = default;
~DrawLineOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -193,9 +217,11 @@ private:
class DrawRectOpItem : public DrawOpItem {
public:
DrawRectOpItem();
explicit DrawRectOpItem(const Rect& rect);
~DrawRectOpItem() = default;
~DrawRectOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -205,10 +231,11 @@ private:
class DrawRoundRectOpItem : public DrawOpItem {
public:
DrawRoundRectOpItem();
explicit DrawRoundRectOpItem(const std::pair<uint32_t, size_t> radiusXYData, const Rect& rect);
~DrawRoundRectOpItem() = default;
~DrawRoundRectOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -222,11 +249,12 @@ private:
class DrawNestedRoundRectOpItem : public DrawOpItem {
public:
DrawNestedRoundRectOpItem();
DrawNestedRoundRectOpItem(const std::pair<uint32_t, size_t> outerRadiusXYData, const Rect& outerRect,
const std::pair<uint32_t, size_t> innerRadiusXYData, const Rect& innerRect);
~DrawNestedRoundRectOpItem() = default;
~DrawNestedRoundRectOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -242,9 +270,11 @@ private:
class DrawArcOpItem : public DrawOpItem {
public:
DrawArcOpItem();
DrawArcOpItem(const Rect& rect, scalar startAngle, scalar sweepAngle);
~DrawArcOpItem() = default;
~DrawArcOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -256,9 +286,11 @@ private:
class DrawPieOpItem : public DrawOpItem {
public:
DrawPieOpItem();
DrawPieOpItem(const Rect& rect, scalar startAngle, scalar sweepAngle);
~DrawPieOpItem() = default;
~DrawPieOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -270,9 +302,11 @@ private:
class DrawOvalOpItem : public DrawOpItem {
public:
DrawOvalOpItem();
explicit DrawOvalOpItem(const Rect& rect);
~DrawOvalOpItem() = default;
~DrawOvalOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -282,9 +316,11 @@ private:
class DrawCircleOpItem : public DrawOpItem {
public:
DrawCircleOpItem();
DrawCircleOpItem(const Point& centerPt, scalar radius);
~DrawCircleOpItem() = default;
~DrawCircleOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -295,10 +331,11 @@ private:
class DrawPathOpItem : public DrawOpItem {
public:
DrawPathOpItem();
explicit DrawPathOpItem(const CmdListHandle& path);
~DrawPathOpItem() = default;
~DrawPathOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -311,10 +348,11 @@ private:
class DrawBackgroundOpItem : public DrawOpItem {
public:
DrawBackgroundOpItem();
DrawBackgroundOpItem(const BrushHandle& brushHandle);
~DrawBackgroundOpItem() = default;
~DrawBackgroundOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -327,11 +365,12 @@ private:
class DrawShadowOpItem : public DrawOpItem {
public:
DrawShadowOpItem();
DrawShadowOpItem(const CmdListHandle& path, const Point3& planeParams, const Point3& devLightPos,
scalar lightRadius, Color ambientColor, Color spotColor, ShadowFlags flag);
~DrawShadowOpItem() = default;
~DrawShadowOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -350,10 +389,11 @@ private:
class DrawRegionOpItem : public DrawOpItem {
public:
DrawRegionOpItem();
DrawRegionOpItem(const CmdListHandle& path);
~DrawRegionOpItem() = default;
~DrawRegionOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -366,11 +406,12 @@ private:
class DrawPatchOpItem : public DrawOpItem {
public:
DrawPatchOpItem();
explicit DrawPatchOpItem(const std::pair<uint32_t, size_t> cubics, const std::pair<uint32_t, size_t> colors,
const std::pair<uint32_t, size_t> texCoords, BlendMode mode);
~DrawPatchOpItem() = default;
~DrawPatchOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -386,11 +427,12 @@ private:
class DrawEdgeAAQuadOpItem : public DrawOpItem {
public:
DrawEdgeAAQuadOpItem();
explicit DrawEdgeAAQuadOpItem(const Rect& rect, const std::pair<uint32_t, size_t> clipQuad,
QuadAAFlags aaFlags, ColorQuad color, BlendMode mode);
~DrawEdgeAAQuadOpItem() = default;
~DrawEdgeAAQuadOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -407,11 +449,12 @@ private:
class DrawImageNineOpItem : public DrawOpItem {
public:
DrawImageNineOpItem();
explicit DrawImageNineOpItem(const ImageHandle& image, const RectI& center, const Rect& dst,
FilterMode filterMode, const BrushHandle& brushHandle, bool hasBrush);
~DrawImageNineOpItem() = default;
~DrawImageNineOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -430,9 +473,9 @@ private:
class DrawAnnotationOpItem : public DrawOpItem {
public:
explicit DrawAnnotationOpItem(const Rect& rect, const char* key, const ImageHandle& data);
~DrawAnnotationOpItem() = default;
~DrawAnnotationOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -447,11 +490,12 @@ private:
class DrawImageLatticeOpItem : public DrawOpItem {
public:
DrawImageLatticeOpItem();
explicit DrawImageLatticeOpItem(const ImageHandle& image, const Lattice& lattice, const Rect& dst,
FilterMode filterMode, const BrushHandle& brushHandle, bool hasBrush);
~DrawImageLatticeOpItem() = default;
~DrawImageLatticeOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -469,10 +513,11 @@ private:
class DrawVerticesOpItem : public DrawOpItem {
public:
DrawVerticesOpItem();
DrawVerticesOpItem(const VerticesHandle& vertices, BlendMode mode);
~DrawVerticesOpItem() = default;
~DrawVerticesOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -486,10 +531,11 @@ private:
class DrawBitmapOpItem : public DrawOpItem {
public:
DrawBitmapOpItem();
DrawBitmapOpItem(const ImageHandle& bitmap, scalar px, scalar py);
~DrawBitmapOpItem() = default;
~DrawBitmapOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -504,10 +550,11 @@ private:
class DrawImageOpItem : public DrawOpItem {
public:
DrawImageOpItem();
DrawImageOpItem(const ImageHandle& image, scalar px, scalar py, const SamplingOptions& samplingOptions);
~DrawImageOpItem() = default;
~DrawImageOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -523,11 +570,12 @@ private:
class DrawImageRectOpItem : public DrawOpItem {
public:
DrawImageRectOpItem();
DrawImageRectOpItem(const ImageHandle& image, const Rect& src, const Rect& dst,
const SamplingOptions& sampling, SrcRectConstraint constraint);
~DrawImageRectOpItem() = default;
~DrawImageRectOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -544,10 +592,11 @@ private:
class DrawPictureOpItem : public DrawOpItem {
public:
DrawPictureOpItem();
explicit DrawPictureOpItem(const ImageHandle& picture);
~DrawPictureOpItem() = default;
~DrawPictureOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -560,9 +609,11 @@ private:
class DrawColorOpItem : public DrawOpItem {
public:
DrawColorOpItem();
explicit DrawColorOpItem(ColorQuad color, BlendMode mode);
~DrawColorOpItem() = default;
~DrawColorOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -571,17 +622,25 @@ private:
BlendMode mode_;
};
class AttachPenOpItem;
class AttachBrushOpItem;
class DrawTextBlobOpItem : public DrawOpItem {
public:
DrawTextBlobOpItem();
explicit DrawTextBlobOpItem(const ImageHandle& textBlob, const scalar x, const scalar y);
~DrawTextBlobOpItem() = default;
~DrawTextBlobOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas, const CmdList& cmdList);
std::shared_ptr<NoIPCImageOpItem> GenerateCachedOpItem(CmdList& cmdList, Canvas* canvas,
AttachPenOpItem* penOpItem, AttachBrushOpItem* brushOpItem, bool addCmdList, bool& replaceSuccess);
bool GenerateCachedOpItem(std::shared_ptr<CmdList> cacheCmdList, const TextBlob* textBlob);
private:
ImageHandle textBlob_;
scalar x_;
@ -591,9 +650,11 @@ private:
class ClipRectOpItem : public DrawOpItem {
public:
ClipRectOpItem();
ClipRectOpItem(const Rect& rect, ClipOp op, bool doAntiAlias);
~ClipRectOpItem() = default;
~ClipRectOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -605,9 +666,11 @@ private:
class ClipIRectOpItem : public DrawOpItem {
public:
ClipIRectOpItem();
ClipIRectOpItem(const RectI& rect, ClipOp op = ClipOp::INTERSECT);
~ClipIRectOpItem() = default;
~ClipIRectOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -618,10 +681,11 @@ private:
class ClipRoundRectOpItem : public DrawOpItem {
public:
ClipRoundRectOpItem();
ClipRoundRectOpItem(const std::pair<uint32_t, size_t> radiusXYData, const Rect& rect, ClipOp op, bool doAntiAlias);
~ClipRoundRectOpItem() = default;
~ClipRoundRectOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -637,10 +701,11 @@ private:
class ClipPathOpItem : public DrawOpItem {
public:
ClipPathOpItem();
ClipPathOpItem(const CmdListHandle& path, ClipOp clipOp, bool doAntiAlias);
~ClipPathOpItem() = default;
~ClipPathOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -655,10 +720,11 @@ private:
class ClipRegionOpItem : public DrawOpItem {
public:
ClipRegionOpItem();
ClipRegionOpItem(const CmdListHandle& region, ClipOp clipOp = ClipOp::INTERSECT);
~ClipRegionOpItem() = default;
~ClipRegionOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -672,9 +738,11 @@ private:
class SetMatrixOpItem : public DrawOpItem {
public:
SetMatrixOpItem();
explicit SetMatrixOpItem(const Matrix& matrix);
~SetMatrixOpItem() = default;
~SetMatrixOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -685,17 +753,20 @@ private:
class ResetMatrixOpItem : public DrawOpItem {
public:
ResetMatrixOpItem();
~ResetMatrixOpItem() = default;
~ResetMatrixOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
};
class ConcatMatrixOpItem : public DrawOpItem {
public:
ConcatMatrixOpItem();
explicit ConcatMatrixOpItem(const Matrix& matrix);
~ConcatMatrixOpItem() = default;
~ConcatMatrixOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -705,9 +776,11 @@ private:
class TranslateOpItem : public DrawOpItem {
public:
TranslateOpItem();
TranslateOpItem(scalar dx, scalar dy);
~TranslateOpItem() = default;
~TranslateOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -718,9 +791,11 @@ private:
class ScaleOpItem : public DrawOpItem {
public:
ScaleOpItem();
ScaleOpItem(scalar sx, scalar sy);
~ScaleOpItem() = default;
~ScaleOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -731,9 +806,11 @@ private:
class RotateOpItem : public DrawOpItem {
public:
RotateOpItem();
RotateOpItem(scalar deg, scalar sx, scalar sy);
~RotateOpItem() = default;
~RotateOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -745,9 +822,11 @@ private:
class ShearOpItem : public DrawOpItem {
public:
ShearOpItem();
ShearOpItem(scalar sx, scalar sy);
~ShearOpItem() = default;
~ShearOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -759,17 +838,20 @@ private:
class FlushOpItem : public DrawOpItem {
public:
FlushOpItem();
~FlushOpItem() = default;
~FlushOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
};
class ClearOpItem : public DrawOpItem {
public:
ClearOpItem();
explicit ClearOpItem(ColorQuad color);
~ClearOpItem() = default;
~ClearOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
@ -780,19 +862,21 @@ private:
class SaveOpItem : public DrawOpItem {
public:
SaveOpItem();
~SaveOpItem() = default;
~SaveOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
};
class SaveLayerOpItem : public DrawOpItem {
public:
SaveLayerOpItem();
SaveLayerOpItem(const Rect& rect, bool hasBrush, const BrushHandle& brushHandle, const CmdListHandle& imageFilter,
uint32_t saveLayerFlags);
~SaveLayerOpItem() = default;
~SaveLayerOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -810,8 +894,9 @@ private:
class RestoreOpItem : public DrawOpItem {
public:
RestoreOpItem();
~RestoreOpItem() = default;
~RestoreOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
};
@ -819,18 +904,20 @@ public:
class DiscardOpItem : public DrawOpItem {
public:
DiscardOpItem();
~DiscardOpItem() = default;
~DiscardOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
};
class AttachPenOpItem : public DrawOpItem {
public:
AttachPenOpItem();
AttachPenOpItem(const PenHandle& penHandle);
~AttachPenOpItem() = default;
~AttachPenOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -843,10 +930,11 @@ private:
class AttachBrushOpItem : public DrawOpItem {
public:
AttachBrushOpItem();
AttachBrushOpItem(const BrushHandle& brushHandle);
~AttachBrushOpItem() = default;
~AttachBrushOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList, Canvas* canvas = nullptr);
static void Playback(CanvasPlayer& player, void* opItem);
@ -860,8 +948,9 @@ private:
class DetachPenOpItem : public DrawOpItem {
public:
DetachPenOpItem();
~DetachPenOpItem() = default;
~DetachPenOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
};
@ -869,18 +958,20 @@ public:
class DetachBrushOpItem : public DrawOpItem {
public:
DetachBrushOpItem();
~DetachBrushOpItem() = default;
~DetachBrushOpItem() override = default;
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas);
};
class ClipAdaptiveRoundRectOpItem : public DrawOpItem {
public:
ClipAdaptiveRoundRectOpItem();
ClipAdaptiveRoundRectOpItem(const std::pair<uint32_t, size_t>& radiusData);
~ClipAdaptiveRoundRectOpItem() = default;
~ClipAdaptiveRoundRectOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList);
static void Playback(CanvasPlayer& player, void* opItem);
@ -893,11 +984,12 @@ private:
class DrawAdaptiveImageOpItem : public DrawOpItem {
public:
DrawAdaptiveImageOpItem();
DrawAdaptiveImageOpItem(const ImageHandle& image, const AdaptiveImageInfo& rsImageInfo,
const SamplingOptions& smapling, const bool isImage);
~DrawAdaptiveImageOpItem() = default;
~DrawAdaptiveImageOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList);
static void Playback(CanvasPlayer& player, void* opItem);
@ -913,11 +1005,12 @@ private:
class DrawAdaptivePixelMapOpItem : public DrawOpItem {
public:
DrawAdaptivePixelMapOpItem();
DrawAdaptivePixelMapOpItem(const ImageHandle& pixelMap, const AdaptiveImageInfo& imageInfo,
const SamplingOptions& smapling);
~DrawAdaptivePixelMapOpItem() = default;
~DrawAdaptivePixelMapOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList);
static void Playback(CanvasPlayer& player, void* opItem);
@ -932,10 +1025,11 @@ private:
class DrawExtendPixelMapOpItem : public DrawOpItem {
public:
DrawExtendPixelMapOpItem();
DrawExtendPixelMapOpItem(const ImageHandle& objectHandle, const SamplingOptions& sampling);
~DrawExtendPixelMapOpItem() = default;
~DrawExtendPixelMapOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList);
static void Playback(CanvasPlayer& player, void* opItem);
@ -949,10 +1043,11 @@ private:
class DrawImageWithParmOpItem : public DrawOpItem {
public:
DrawImageWithParmOpItem();
DrawImageWithParmOpItem(const ImageHandle& objectHandle, const SamplingOptions& sampling);
~DrawImageWithParmOpItem() = default;
~DrawImageWithParmOpItem() override = default;
static void Unmarshalling(const CmdList& cmdList, void* opItem);
static std::shared_ptr<OpItem> Unmarshalling(const CmdList& cmdList, void* opItem);
void Unmarshalling(const CmdList& cmdList);
static void Playback(CanvasPlayer& player, void* opItem);
@ -963,6 +1058,24 @@ private:
SamplingOptions sampling_;
std::function<void(Canvas&, const Rect&)> playbackTask_ = nullptr;
};
class NoIPCImageOpItem : public DrawOpItem {
public:
NoIPCImageOpItem(std::shared_ptr<Image> image, const Rect& src, const Rect& dst,
const SamplingOptions& sampling, SrcRectConstraint constraint);
~NoIPCImageOpItem() = default;
static void Playback(CanvasPlayer& player, void* opItem);
void Playback(Canvas& canvas, const CmdList& cmdList);
private:
std::shared_ptr<Image> image_;
Rect src_;
Rect dst_;
SamplingOptions sampling_;
SrcRectConstraint constraint_;
};
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS

View File

@ -53,7 +53,7 @@ public:
* @brief Calls the corresponding operations of all opitems in DrawCmdList to the canvas.
* @param canvas Implements the playback action of the DrawCmdList in the Canvas.
*/
void Playback(Canvas& canvas, const Rect* rect = nullptr) const;
void Playback(Canvas& canvas, const Rect* rect = nullptr);
/*
* @brief Gets the width of the DrawCmdList.
@ -75,10 +75,33 @@ public:
*/
void SetHeight(int32_t height);
void GenerateCache(Canvas* canvas = nullptr, const Rect* rect = nullptr);
void GenerateCacheInRenderService(Canvas* canvas, const Rect* rect);
void ClearCache();
bool GetIsCache();
void SetIsCache(bool isCached);
bool GetCachedHighContrast();
void SetCachedHighContrast(bool cachedHighContrast);
std::vector<std::pair<uint32_t, uint32_t>> GetReplacedOpList();
void SetReplacedOpList(std::vector<std::pair<uint32_t, uint32_t>> replacedOpList);
private:
MemAllocator largeObjectAllocator_;
std::vector<std::shared_ptr<OpItem>> unmarshalledOpItems_;
int32_t width_;
int32_t height_;
std::vector<std::pair<uint32_t, uint32_t>> replacedOpList_;
std::vector<std::pair<uint32_t, std::shared_ptr<OpItem>>> opReplacedByDrivenRender_;
bool isCached_ = false;
bool cachedHighContrast_ = false;
};
using DrawCmdListPtr = std::shared_ptr<DrawCmdList>;

View File

@ -43,7 +43,7 @@ public:
/*
* @brief Calls the corresponding operations of all opitems in MaskCmdList to the mask.
*/
bool Playback(Path& path, Brush& brush) const;
bool Playback(std::shared_ptr<Path>& path, Brush& brush) const;
};
/* OpItem */
@ -53,7 +53,7 @@ public:
*/
class MaskPlayer {
public:
MaskPlayer(Path& path, Brush& brush, const CmdList& cmdList);
MaskPlayer(std::shared_ptr<Path>& path, Brush& brush, const CmdList& cmdList);
~MaskPlayer() = default;
/*
@ -62,7 +62,7 @@ public:
*/
bool Playback(uint32_t type, const void* opItem);
Path& path_;
std::shared_ptr<Path>& path_;
Brush& brush_;
const CmdList& cmdList_;
@ -102,7 +102,7 @@ public:
static void Playback(MaskPlayer& player, const void* opItem);
void Playback(Path& path, const CmdList& cmdList) const;
void Playback(std::shared_ptr<Path>& path, const CmdList& cmdList) const;
private:
CmdListHandle pathHandle_;
};

View File

@ -24,7 +24,7 @@ namespace Drawing {
class OpItem {
public:
explicit OpItem(uint32_t type) : type_(type) {}
~OpItem() = default;
virtual ~OpItem() = default;
/*
* @brief Gets the offset of next OpItem.

View File

@ -73,7 +73,7 @@ private:
class PathOpItem : public OpItem {
public:
PathOpItem(uint32_t type) : OpItem(type) {}
~PathOpItem() = default;
~PathOpItem() override = default;
enum Type : uint32_t {
OPITEM_HEAD,
@ -154,6 +154,7 @@ public:
ArcToOpItem(const Point& pt1, const Point& pt2, const scalar startAngle, const scalar sweepAngle);
ArcToOpItem(const scalar rx, const scalar ry, const scalar angle, const PathDirection direction, const scalar endX,
const scalar endY);
ArcToOpItem(const scalar x1, const scalar y1, const scalar x2, const scalar y2, const scalar radius);
~ArcToOpItem() = default;
static void Playback(PathPlayer& player, const void* opItem);
void Playback(Path& path) const;
@ -420,7 +421,7 @@ private:
class ResetOpItem : public PathOpItem {
public:
ResetOpItem();
~ResetOpItem();
~ResetOpItem() override = default;
static void Playback(PathPlayer& player, const void* opItem);
void Playback(Path& path) const;
};
@ -428,7 +429,7 @@ public:
class CloseOpItem : public PathOpItem {
public:
CloseOpItem();
~CloseOpItem();
~CloseOpItem() override = default;
static void Playback(PathPlayer& player, const void* opItem);
void Playback(Path& path) const;
};

View File

@ -110,7 +110,10 @@ public:
CoreCanvas& DetachPen() override;
CoreCanvas& DetachBrush() override;
void SetIsCustomTextType(bool isCustomTextType);
bool IsCustomTextType() const;
private:
bool isCustomTextType_ = false;
std::shared_ptr<DrawCmdList> cmdList_ = nullptr;
int saveCount_ = 0;
};

View File

@ -41,6 +41,8 @@ public:
void ArcTo(scalar pt1X, scalar pt1Y, scalar pt2X, scalar pt2Y, scalar startAngle, scalar sweepAngle) override;
void ArcTo(const Point& pt1, const Point& pt2, scalar startAngle, scalar sweepAngle) override;
void ArcTo(scalar rx, scalar ry, scalar angle, PathDirection direction, scalar endX, scalar endY) override;
void ArcTo(scalar x1, scalar y1, scalar x2, scalar y2, scalar radius) override;
void CubicTo(scalar ctrlPt1X, scalar ctrlPt1Y, scalar ctrlPt2X, scalar ctrlPt2Y,
scalar endPtX, scalar endPtY) override;
void CubicTo(const Point& ctrlPt1, const Point& ctrlPt2, const Point& endPt) override;

View File

@ -62,6 +62,8 @@ public:
return nullptr;
}
std::shared_ptr<Rect> Bounds() const;
private:
std::shared_ptr<TextBlobImpl> textBlobImpl_;
};

View File

@ -43,6 +43,17 @@ public:
*/
bool BuildWithCopy(const void* data, size_t length);
/*
* @brief Create a new dataref, taking the ptr as is,
and using the releaseproc to free it. The proc may be NULL.
* @param ptr A pointer to data. It must not be nullptr.
* @param length Length of data.
* @param proc release callback func.
* @param ctx context, usually nullptr.
* @return If create Data successed, return true.
*/
bool BuildWithProc(const void* ptr, size_t length, DataReleaseProc proc, void* ctx);
/*
* @brief Create a new Data. When Data is destroyed, data isn't released.
* @param data A pointer to data.

View File

@ -128,6 +128,18 @@ public:
return matrixImplPtr->DowncastingTo<T>();
}
/*
* Returns true if matrix is Identity. Identity matrix is:
* | 1 0 0 |
* | 0 1 0 |
* | 0 0 1 |
*/
bool IsIdentity() const;
void PreRotate(scalar degree, scalar px, scalar py);
void PreScale(scalar sx, scalar sy, scalar px, scalar py);
void Reset();
void DeepCopy(const Matrix& matrix);
private:
std::shared_ptr<MatrixImpl> matrixImplPtr;
};

View File

@ -36,10 +36,190 @@ static inline int DrawingFloatSaturate2Int(float x)
return (int)x;
}
class DRAWING_API RectI {
public:
inline RectI() noexcept;
inline RectI(const RectI& r) noexcept;
inline RectI(const int l, const int t, const int r, const int b) noexcept;
~RectI() {}
inline bool IsValid() const;
inline bool IsEmpty() const;
inline int GetLeft() const;
inline int GetTop() const;
inline int GetRight() const;
inline int GetBottom() const;
inline int GetWidth() const;
inline int GetHeight() const;
inline void SetLeft(int pos);
inline void SetTop(int pos);
inline void SetRight(int pos);
inline void SetBottom(int pos);
inline void Offset(int dx, int dy);
inline void MakeOutset(int dx, int dy);
/*
* @brief If RectI intersects other, sets RectI to intersection.
* @param other limit of result.
* @return true if other and RectI have area in common.
*/
inline bool Intersect(const RectI& other);
/*
* @brief If other is valid, sets RectI to the union of itself and other.
* @param other expansion RectI.
* @return true if other is valid.
*/
inline bool Join(const RectI& other);
friend inline bool operator==(const RectI& r1, const RectI& r2);
friend inline bool operator!=(const RectI& r1, const RectI& r2);
private:
int32_t left_;
int32_t right_;
int32_t top_;
int32_t bottom_;
};
inline RectI::RectI() noexcept : left_(0), right_(0), top_(0), bottom_(0) {}
inline RectI::RectI(const RectI& r) noexcept
: left_(r.GetLeft()), right_(r.GetRight()), top_(r.GetTop()), bottom_(r.GetBottom())
{}
inline RectI::RectI(const int l, const int t, const int r, const int b) noexcept
: left_(l), right_(r), top_(t), bottom_(b)
{}
inline bool RectI::IsValid() const
{
return !IsEmpty();
}
inline bool RectI::IsEmpty() const
{
int64_t w = (int64_t)right_ - (int64_t)left_;
int64_t h = (int64_t)bottom_ - (int64_t)top_;
if (w <= 0 || h <= 0) {
return true;
}
// Return true if either exceeds int32_t
int32_t int32test = (w | h) & 0xFFFFFFFF;
return int32test < 0;
}
inline int RectI::GetLeft() const
{
return left_;
}
inline int RectI::GetTop() const
{
return top_;
}
inline int RectI::GetRight() const
{
return right_;
}
inline int RectI::GetBottom() const
{
return bottom_;
}
inline int RectI::GetWidth() const
{
return right_ - left_;
}
inline int RectI::GetHeight() const
{
return bottom_ - top_;
}
inline void RectI::SetLeft(int pos)
{
left_ = pos;
}
inline void RectI::SetTop(int pos)
{
top_ = pos;
}
inline void RectI::SetRight(int pos)
{
right_ = pos;
}
inline void RectI::SetBottom(int pos)
{
bottom_ = pos;
}
inline void RectI::Offset(int dx, int dy)
{
left_ += dx;
right_ += dx;
top_ += dy;
bottom_ += dy;
}
inline void RectI::MakeOutset(int dx, int dy)
{
left_ -= dx;
right_ += dx;
top_ -= dy;
bottom_ += dy;
}
inline bool RectI::Intersect(const RectI& other)
{
RectI rectI(left_ > other.left_ ? left_ : other.left_, top_ > other.top_ ? top_ : other.top_,
right_ < other.right_ ? right_ : other.right_, bottom_ < other.bottom_ ? bottom_ : other.bottom_);
if (!rectI.IsValid()) {
return false;
}
*this = rectI;
return true;
}
inline bool RectI::Join(const RectI& other)
{
if (!other.IsValid()) {
return false;
}
if (!IsValid()) {
*this = other;
} else {
*this = RectI(left_ < other.left_ ? left_ : other.left_, top_ < other.top_ ? top_ : other.top_,
right_ > other.right_ ? right_ : other.right_, bottom_ > other.bottom_ ? bottom_ : other.bottom_);
}
return true;
}
inline bool operator==(const RectI& r1, const RectI& r2)
{
return r1.left_ == r2.left_ && r1.right_ == r2.right_ && r1.top_ == r2.top_ && r1.bottom_ == r2.bottom_;
}
inline bool operator!=(const RectI& r1, const RectI& r2)
{
return r1.left_ != r2.left_ || r1.right_ != r2.right_ || r1.top_ != r2.top_ || r1.bottom_ != r2.bottom_;
}
class DRAWING_API RectF {
public:
inline RectF() noexcept;
inline RectF(const RectF& r) noexcept;
inline RectF(const RectI& r) noexcept;
inline RectF(const scalar l, const scalar t, const scalar r, const scalar b) noexcept;
~RectF() {}
@ -94,6 +274,10 @@ inline RectF::RectF(const RectF& r) noexcept
: left_(r.GetLeft()), right_(r.GetRight()), top_(r.GetTop()), bottom_(r.GetBottom())
{}
inline RectF::RectF(const RectI& r) noexcept
: left_(r.GetLeft()), right_(r.GetRight()), top_(r.GetTop()), bottom_(r.GetBottom())
{}
inline RectF::RectF(const scalar l, const scalar t, const scalar r, const scalar b) noexcept
: left_(l), right_(r), top_(t), bottom_(b)
{}
@ -218,184 +402,6 @@ inline bool operator!=(const RectF& r1, const RectF& r2)
return !IsScalarAlmostEqual(r1.left_, r2.left_) || !IsScalarAlmostEqual(r1.right_, r2.right_) ||
!IsScalarAlmostEqual(r1.top_, r2.top_) || !IsScalarAlmostEqual(r1.bottom_, r2.bottom_);
}
class DRAWING_API RectI {
public:
inline RectI() noexcept;
inline RectI(const RectI& r) noexcept;
inline RectI(const int l, const int t, const int r, const int b) noexcept;
~RectI() {}
inline bool IsValid() const;
inline bool IsEmpty() const;
inline int GetLeft() const;
inline int GetTop() const;
inline int GetRight() const;
inline int GetBottom() const;
inline int GetWidth() const;
inline int GetHeight() const;
inline void SetLeft(int pos);
inline void SetTop(int pos);
inline void SetRight(int pos);
inline void SetBottom(int pos);
inline void Offset(int dx, int dy);
inline void MakeOutset(int dx, int dy);
/*
* @brief If RectI intersects other, sets RectI to intersection.
* @param other limit of result.
* @return true if other and RectI have area in common.
*/
inline bool Intersect(const RectI& other);
/*
* @brief If other is valid, sets RectI to the union of itself and other.
* @param other expansion RectI.
* @return true if other is valid.
*/
inline bool Join(const RectI& other);
friend inline bool operator==(const RectI& r1, const RectI& r2);
friend inline bool operator!=(const RectI& r1, const RectI& r2);
private:
int32_t left_;
int32_t right_;
int32_t top_;
int32_t bottom_;
};
inline RectI::RectI() noexcept : left_(0), right_(0), top_(0), bottom_(0) {}
inline RectI::RectI(const RectI& r) noexcept
: left_(r.GetLeft()), right_(r.GetRight()), top_(r.GetTop()), bottom_(r.GetBottom())
{}
inline RectI::RectI(const int l, const int t, const int r, const int b) noexcept
: left_(l), right_(r), top_(t), bottom_(b)
{}
inline bool RectI::IsValid() const
{
return !IsEmpty();
}
inline bool RectI::IsEmpty() const
{
uint64_t w = (uint64_t)right_ - (uint64_t)left_;
uint64_t h = (uint64_t)bottom_ - (uint64_t)top_;
if (w <= 0 || h <= 0) {
return true;
}
// Return true if either exceeds int32_t
int32_t int32test = (w | h) & 0xFFFFFFFF;
return int32test < 0;
}
inline int RectI::GetLeft() const
{
return left_;
}
inline int RectI::GetTop() const
{
return top_;
}
inline int RectI::GetRight() const
{
return right_;
}
inline int RectI::GetBottom() const
{
return bottom_;
}
inline int RectI::GetWidth() const
{
return right_ - left_;
}
inline int RectI::GetHeight() const
{
return bottom_ - top_;
}
inline void RectI::SetLeft(int pos)
{
left_ = pos;
}
inline void RectI::SetTop(int pos)
{
top_ = pos;
}
inline void RectI::SetRight(int pos)
{
right_ = pos;
}
inline void RectI::SetBottom(int pos)
{
bottom_ = pos;
}
inline void RectI::Offset(int dx, int dy)
{
left_ += dx;
right_ += dx;
top_ += dy;
bottom_ += dy;
}
inline void RectI::MakeOutset(int dx, int dy)
{
left_ -= dx;
right_ += dx;
top_ -= dy;
bottom_ += dy;
}
inline bool RectI::Intersect(const RectI& other)
{
RectI rectI(left_ > other.left_ ? left_ : other.left_, top_ > other.top_ ? top_ : other.top_,
right_ < other.right_ ? right_ : other.right_, bottom_ < other.bottom_ ? bottom_ : other.bottom_);
if (!rectI.IsValid()) {
return false;
}
*this = rectI;
return true;
}
inline bool RectI::Join(const RectI& other)
{
if (!other.IsValid()) return false;
if (!IsValid()) {
*this = other;
} else {
*this = RectI(left_ < other.left_ ? left_ : other.left_, top_ < other.top_ ? top_ : other.top_,
right_ > other.right_ ? right_ : other.right_, bottom_ > other.bottom_ ? bottom_ : other.bottom_);
}
return true;
}
inline bool operator==(const RectI& r1, const RectI& r2)
{
return r1.left_ == r2.left_ && r1.right_ == r2.right_ && r1.top_ == r2.top_ && r1.bottom_ == r2.bottom_;
}
inline bool operator!=(const RectI& r1, const RectI& r2)
{
return r1.left_ != r2.left_ || r1.right_ != r2.right_ || r1.top_ != r2.top_ || r1.bottom_ != r2.bottom_;
}
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS

View File

@ -78,7 +78,8 @@ public:
}
return verticesImplPtr_->DowncastingTo<T>();
}
std::shared_ptr<Data> Serialize() const;
bool Deserialize(std::shared_ptr<Data> data);
class Builder {
public:
Builder(VertexMode mode, int vertexCount, int indexCount, uint32_t flags);

View File

@ -64,7 +64,7 @@ void Brush::SetColor(int c)
color_.SetColorQuad(c);
}
void Brush::SetARGB(int r, int g, int b, int a)
void Brush::SetARGB(int a, int r, int g, int b)
{
color_.SetRgb(r, g, b, a);
}

View File

@ -254,6 +254,11 @@ bool CoreCanvas::IsClipEmpty()
return impl_->IsClipEmpty();
}
bool CoreCanvas::IsClipRect()
{
return impl_->IsClipRect();
}
bool CoreCanvas::QuickReject(const Rect& rect)
{
return impl_->QuickReject(rect);
@ -357,6 +362,21 @@ std::shared_ptr<CoreCanvasImpl> CoreCanvas::GetCanvasData() const
{
return impl_;
}
bool CoreCanvas::isHighContrastEnabled() const
{
return false;
}
Drawing::CacheType CoreCanvas::GetCacheType() const
{
return Drawing::CacheType::UNDEFINED;
}
Drawing::Surface* CoreCanvas::GetSurface() const
{
return nullptr;
}
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS

View File

@ -65,6 +65,15 @@ struct Lattice {
Color fColors;
};
enum CacheType : uint8_t {
UNDEFINED, // do not change current cache status
ENABLED, // explicitly enable cache
DISABLED, // explicitly disable cache
OFFSCREEN, // offscreen rendering
};
class Surface;
/*
* @brief Contains the option used to create the layer.
*/
@ -290,6 +299,11 @@ public:
*/
virtual bool IsClipEmpty();
/*
* @brief Returns true if clip is SkRect and not empty.
*/
virtual bool IsClipRect();
/*
* @brief Returns true if clip is emptySkRect rect, transformed by SkMatrix,
* can be quickly determined to be outside of clip.
@ -342,6 +356,10 @@ public:
virtual CoreCanvas& DetachPen();
virtual CoreCanvas& DetachBrush();
virtual bool isHighContrastEnabled() const;
virtual Drawing::CacheType GetCacheType() const;
virtual Drawing::Surface* GetSurface() const;
template<typename T>
const std::shared_ptr<T> GetImpl() const
{

View File

@ -70,6 +70,11 @@ void Path::ArcTo(scalar rx, scalar ry, scalar angle, PathDirection direction, sc
impl_->ArcTo(rx, ry, angle, direction, endX, endY);
}
void Path::ArcTo(scalar x1, scalar y1, scalar x2, scalar y2, scalar radius)
{
impl_->ArcTo(x1, y1, x2, y2, radius);
}
void Path::CubicTo(scalar ctrlPt1X, scalar ctrlPt1Y, scalar ctrlPt2X, scalar ctrlPt2Y, scalar endPtX, scalar endPtY)
{
impl_->CubicTo(ctrlPt1X, ctrlPt1Y, ctrlPt2X, ctrlPt2Y, endPtX, endPtY);

View File

@ -54,9 +54,9 @@ void Pen::SetColor(int c)
brush_.SetColor(c);
}
void Pen::SetARGB(int r, int g, int b, int a)
void Pen::SetARGB(int a, int r, int g, int b)
{
return brush_.SetARGB(r, g, b, a);
return brush_.SetARGB(a, r, g, b);
}
Color4f Pen::GetColor4f()

View File

@ -99,6 +99,11 @@ void Surface::FlushAndSubmit(bool syncCpu)
impl_->FlushAndSubmit(syncCpu);
}
void Surface::Flush()
{
impl_->Flush();
}
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS

View File

@ -104,6 +104,17 @@ std::shared_ptr<ColorFilter> ColorFilter::CreateLumaColorFilter()
{
return std::make_shared<ColorFilter>(ColorFilter::FilterType::LUMA);
}
std::shared_ptr<Data> ColorFilter::Serialize() const
{
return impl_->Serialize();
}
bool ColorFilter::Deserialize(std::shared_ptr<Data> data)
{
return impl_->Deserialize(data);
}
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS

View File

@ -85,6 +85,17 @@ std::shared_ptr<ColorSpace> ColorSpace::CreateRGB(const CMSTransferFuncType& fun
{
return std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::RGB, func, matrix);
}
std::shared_ptr<Data> ColorSpace::Serialize() const
{
return impl_->Serialize();
}
bool ColorSpace::Deserialize(std::shared_ptr<Data> data)
{
return impl_->Deserialize(data);
}
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS

View File

@ -57,6 +57,10 @@ ImageFilter::ImageFilter(FilterType t, std::shared_ptr<ImageFilter> f1, std::sha
impl_->InitWithCompose(f1, f2);
}
ImageFilter::ImageFilter(FilterType t) noexcept
: type_(t), impl_(ImplFactory::CreateImageFilterImpl())
{}
ImageFilter::ImageFilter() noexcept
: type_(ImageFilter::FilterType::NO_TYPE), impl_(ImplFactory::CreateImageFilterImpl())
{}
@ -96,6 +100,17 @@ std::shared_ptr<ImageFilter> ImageFilter::CreateComposeImageFilter(
{
return std::make_shared<ImageFilter>(ImageFilter::FilterType::COMPOSE, f1, f2);
}
std::shared_ptr<Data> ImageFilter::Serialize() const
{
return impl_->Serialize();
}
bool ImageFilter::Deserialize(std::shared_ptr<Data> data)
{
return impl_->Deserialize(data);
}
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS

View File

@ -31,6 +31,9 @@ MaskFilter::MaskFilter(FilterType t, BlurType blurType, scalar sigma) noexcept :
MaskFilter::MaskFilter() noexcept : type_(MaskFilter::FilterType::NO_TYPE), impl_(ImplFactory::CreateMaskFilterImpl())
{}
MaskFilter::MaskFilter(FilterType t) noexcept : type_(t), impl_(ImplFactory::CreateMaskFilterImpl())
{}
MaskFilter::FilterType MaskFilter::GetType() const
{
return type_;
@ -40,6 +43,17 @@ std::shared_ptr<MaskFilter> MaskFilter::CreateBlurMaskFilter(BlurType blurType,
{
return std::make_shared<MaskFilter>(MaskFilter::FilterType::BLUR, blurType, sigma);
}
std::shared_ptr<Data> MaskFilter::Serialize() const
{
return impl_->Serialize();
}
bool MaskFilter::Deserialize(std::shared_ptr<Data> data)
{
return impl_->Deserialize(data);
}
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS

View File

@ -61,6 +61,10 @@ PathEffect::PathEffect() noexcept
: type_(PathEffect::PathEffectType::NO_TYPE), impl_(ImplFactory::CreatePathEffectImpl())
{}
PathEffect::PathEffect(PathEffectType t) noexcept
: type_(t), impl_(ImplFactory::CreatePathEffectImpl())
{}
PathEffect::PathEffectType PathEffect::GetType() const
{
return type_;
@ -96,6 +100,17 @@ std::shared_ptr<PathEffect> PathEffect::CreateComposePathEffect(PathEffect& e1,
{
return std::make_shared<PathEffect>(PathEffect::PathEffectType::COMPOSE, e1, e2);
}
std::shared_ptr<Data> PathEffect::Serialize() const
{
return impl_->Serialize();
}
bool PathEffect::Deserialize(std::shared_ptr<Data> data)
{
return impl_->Deserialize(data);
}
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "effect/runtime_effect.h"
#include "impl_factory.h"
namespace OHOS {
namespace Rosen {
namespace Drawing {
RuntimeEffect::RuntimeEffect(const std::string& sl, const RuntimeEffectOptions& options) noexcept : RuntimeEffect()
{
impl_->InitForShader(sl, options);
}
RuntimeEffect::RuntimeEffect(const std::string& sl) noexcept : RuntimeEffect()
{
impl_->InitForShader(sl);
}
RuntimeEffect::RuntimeEffect() noexcept : impl_(ImplFactory::CreateRuntimeEffectImpl())
{}
std::shared_ptr<RuntimeEffect> RuntimeEffect::CreateForShader(const std::string& sl,
const RuntimeEffectOptions& options)
{
return std::make_shared<RuntimeEffect>(sl, options);
}
std::shared_ptr<RuntimeEffect> RuntimeEffect::CreateForShader(const std::string& sl)
{
return std::make_shared<RuntimeEffect>(sl);
}
std::shared_ptr<ShaderEffect> RuntimeEffect::MakeShader(std::shared_ptr<Data> uniforms,
std::shared_ptr<ShaderEffect> children[], size_t childCount, const Matrix* localMatrix,
bool isOpaque)
{
return impl_->MakeShader(uniforms, children, childCount, localMatrix, isOpaque);
}
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "effect/runtime_effect.h"
#include "effect/runtime_shader_builder.h"
#include "impl_factory.h"
namespace OHOS {
namespace Rosen {
namespace Drawing {
RuntimeShaderBuilder::RuntimeShaderBuilder(std::shared_ptr<RuntimeEffect> runtimeEffect) noexcept
: impl_(ImplFactory::CreateRuntimeShaderBuilderImpl(runtimeEffect))
{}
std::shared_ptr<ShaderEffect> RuntimeShaderBuilder::MakeShader(const Matrix* localMatrix, bool isOpaque)
{
return impl_->MakeShader(localMatrix, isOpaque);
}
std::shared_ptr<Image> RuntimeShaderBuilder::MakeImage(GPUContext* gpuContext,
const Matrix* localMatrix, ImageInfo resultInfo, bool mipmapped)
{
return impl_->MakeImage(gpuContext, localMatrix, resultInfo, mipmapped);
}
void RuntimeShaderBuilder::SetChild(const std::string& name, std::shared_ptr<ShaderEffect> shader)
{
impl_->SetChild(name, shader);
}
void RuntimeShaderBuilder::SetUniform(const std::string& name, float val)
{
impl_->SetUniform(name, val);
}
void RuntimeShaderBuilder::SetUniform(const std::string& name, float x, float y)
{
impl_->SetUniform(name, x, y);
}
void RuntimeShaderBuilder::SetUniform(const std::string& name, float x, float y, float width, float height)
{
impl_->SetUniform(name, x, y, width, height);
}
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS

View File

@ -87,6 +87,10 @@ ShaderEffect::ShaderEffect() noexcept
: type_(ShaderEffect::ShaderEffectType::NO_TYPE), impl_(ImplFactory::CreateShaderEffectImpl())
{}
ShaderEffect::ShaderEffect(ShaderEffectType t) noexcept
: type_(t), impl_(ImplFactory::CreateShaderEffectImpl())
{}
ShaderEffect::ShaderEffectType ShaderEffect::GetType() const
{
return type_;
@ -144,6 +148,17 @@ std::shared_ptr<ShaderEffect> ShaderEffect::CreateSweepGradient(const Point& cen
return std::make_shared<ShaderEffect>(
ShaderEffect::ShaderEffectType::SWEEP_GRADIENT, centerPt, colors, pos, mode, startAngle, endAngle);
}
std::shared_ptr<Data> ShaderEffect::Serialize() const
{
return impl_->Serialize();
}
bool ShaderEffect::Deserialize(std::shared_ptr<Data> data)
{
return impl_->Deserialize(data);
}
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS

View File

@ -13,6 +13,8 @@
* limitations under the License.
*/
#include "effect/runtime_effect.h"
#include "impl_factory.h"
#include "skia_adapter/skia_impl_factory.h"
@ -59,6 +61,16 @@ std::unique_ptr<BitmapImpl> ImplFactory::CreateBitmapImpl()
return EngineImplFactory::CreateBitmap();
}
std::unique_ptr<PixmapImpl> ImplFactory::CreatePixmapImpl()
{
return EngineImplFactory::CreatePixmap();
}
std::unique_ptr<PixmapImpl> ImplFactory::CreatePixmapImpl(const ImageInfo& imageInfo, const void* addr, size_t rowBytes)
{
return EngineImplFactory::CreatePixmap(imageInfo, addr, rowBytes);
}
std::unique_ptr<ImageImpl> ImplFactory::CreateImageImpl()
{
return EngineImplFactory::CreateImage();
@ -98,6 +110,17 @@ std::unique_ptr<ShaderEffectImpl> ImplFactory::CreateShaderEffectImpl()
return EngineImplFactory::CreateShaderEffect();
}
std::unique_ptr<RuntimeEffectImpl> ImplFactory::CreateRuntimeEffectImpl()
{
return EngineImplFactory::CreateRuntimeEffect();
}
std::unique_ptr<RuntimeShaderBuilderImpl> ImplFactory::CreateRuntimeShaderBuilderImpl(
std::shared_ptr<RuntimeEffect> runtimeEffect)
{
return EngineImplFactory::CreateRuntimeShaderBuilder(runtimeEffect);
}
std::unique_ptr<SurfaceImpl> ImplFactory::CreateSurfaceImpl()
{
return EngineImplFactory::CreateSurface();

View File

@ -17,6 +17,7 @@
#define IMPLFACTORY_H
#include "impl_interface/bitmap_impl.h"
#include "impl_interface/pixmap_impl.h"
#include "impl_interface/camera_impl.h"
#include "impl_interface/color_filter_impl.h"
#include "impl_interface/color_space_impl.h"
@ -37,6 +38,8 @@
#include "impl_interface/path_impl.h"
#include "impl_interface/picture_impl.h"
#include "impl_interface/region_impl.h"
#include "impl_interface/runtime_effect_impl.h"
#include "impl_interface/runtime_shader_builder_impl.h"
#include "impl_interface/shader_effect_impl.h"
#include "impl_interface/surface_impl.h"
#include "impl_interface/text_blob_builder_impl.h"
@ -44,6 +47,7 @@
namespace OHOS {
namespace Rosen {
namespace Drawing {
class RuntimeEffect;
class ImplFactory {
public:
static std::unique_ptr<CoreCanvasImpl> CreateCoreCanvasImpl();
@ -55,6 +59,8 @@ public:
#endif
static std::unique_ptr<TraceMemoryDumpImpl> CreateTraceMemoryDumpImpl(const char* categoryKey, bool itemizeType);
static std::unique_ptr<BitmapImpl> CreateBitmapImpl();
static std::unique_ptr<PixmapImpl> CreatePixmapImpl();
static std::unique_ptr<PixmapImpl> CreatePixmapImpl(const ImageInfo& imageInfo, const void* addr, size_t rowBytes);
static std::unique_ptr<ImageImpl> CreateImageImpl();
static std::unique_ptr<ImageImpl> CreateImageImpl(void* rawImage);
static std::unique_ptr<PathImpl> CreatePathImpl();
@ -63,6 +69,8 @@ public:
static std::unique_ptr<ImageFilterImpl> CreateImageFilterImpl();
static std::unique_ptr<PictureImpl> CreatePictureImpl();
static std::unique_ptr<ShaderEffectImpl> CreateShaderEffectImpl();
static std::unique_ptr<RuntimeEffectImpl> CreateRuntimeEffectImpl();
static std::unique_ptr<RuntimeShaderBuilderImpl> CreateRuntimeShaderBuilderImpl(std::shared_ptr<RuntimeEffect>);
static std::unique_ptr<SurfaceImpl> CreateSurfaceImpl();
static std::unique_ptr<PathEffectImpl> CreatePathEffectImpl();
static std::unique_ptr<ColorSpaceImpl> CreateColorSpaceImpl();

View File

@ -17,15 +17,18 @@
#define BITMAPIMPL_H
#include "base_impl.h"
#include "draw/color.h"
#include "image/image_info.h"
#include "image/pixmap.h"
#include "utils/data.h"
#include "utils/rect.h"
namespace OHOS {
namespace Rosen {
namespace Drawing {
class Bitmap;
struct BitmapFormat;
typedef void (*ReleaseProc)(void* ptr, void* context);
class BitmapImpl : public BaseImpl {
public:
BitmapImpl() {}
@ -38,15 +41,24 @@ public:
virtual int GetRowBytes() const = 0;
virtual ColorType GetColorType() const = 0;
virtual AlphaType GetAlphaType() const = 0;
virtual bool ExtractSubset(Bitmap& dst, const Rect& subset) const = 0;
virtual bool ReadPixels(const ImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
int srcX, int srcY) const = 0;
virtual void* GetPixels() const = 0;
virtual void SetPixels(void* pixel) = 0;
virtual void CopyPixels(Bitmap& dst, int srcLeft, int srcTop) const = 0;
virtual bool InstallPixels(const ImageInfo& info, void* pixels, size_t rowBytes,
ReleaseProc releaseProc, void* context) = 0;
virtual bool PeekPixels(Pixmap& pixmap) const = 0;
virtual bool IsImmutable() = 0;
virtual void SetImmutable() = 0;
virtual void ClearWithColor(const ColorQuad& color) const = 0;
virtual ColorQuad GetColor(int x, int y) const = 0;
virtual void Free() = 0;
virtual bool IsValid() const = 0;
virtual bool IsEmpty() const = 0;
virtual std::shared_ptr<Data> Serialize() const = 0;
virtual bool Deserialize(std::shared_ptr<Data> data) = 0;
};
} // namespace Drawing
} // namespace Rosen

View File

@ -25,6 +25,7 @@
namespace OHOS {
namespace Rosen {
namespace Drawing {
class Data;
class ColorFilter;
class ColorFilterImpl : public BaseImpl {
public:
@ -38,6 +39,8 @@ public:
virtual void InitWithCompose(const ColorFilter& f1, const ColorFilter& f2) = 0;
virtual void Compose(const ColorFilter& f) = 0;
virtual void InitWithLuma() = 0;
virtual std::shared_ptr<Data> Serialize() const = 0;
virtual bool Deserialize(std::shared_ptr<Data> data) = 0;
};
} // namespace Drawing
} // namespace Rosen

View File

@ -21,6 +21,7 @@
namespace OHOS {
namespace Rosen {
namespace Drawing {
class Data;
enum class CMSTransferFuncType;
enum class CMSMatrixType;
class Image;
@ -33,6 +34,8 @@ public:
virtual void InitWithSRGBLinear() = 0;
virtual void InitWithImage(const Image& image) = 0;
virtual void InitWithRGB(const CMSTransferFuncType& func, const CMSMatrixType& matrix) = 0;
virtual std::shared_ptr<Data> Serialize() const = 0;
virtual bool Deserialize(std::shared_ptr<Data> data) = 0;
};
} // namespace Drawing
} // namespace Rosen

View File

@ -132,6 +132,7 @@ public:
virtual void ClipPath(const Path& path, ClipOp op, bool doAntiAlias = false) = 0;
virtual void ClipRegion(const Region& region, ClipOp op = ClipOp::INTERSECT) = 0;
virtual bool IsClipEmpty() = 0;
virtual bool IsClipRect() = 0;
virtual bool QuickReject(const Rect& rect) = 0;
// transform

View File

@ -22,6 +22,7 @@ namespace OHOS {
namespace Rosen {
namespace Drawing {
class Data;
typedef void (*DataReleaseProc)(const void* ptr, void* context);
class DataImpl : public BaseImpl {
public:
DataImpl() noexcept {}
@ -29,6 +30,7 @@ public:
virtual bool BuildFromMalloc(const void* data, size_t length) = 0;
virtual bool BuildWithCopy(const void* data, size_t length) = 0;
virtual bool BuildWithProc(const void* ptr, size_t length, DataReleaseProc proc, void* ctx) = 0;
virtual bool BuildWithoutCopy(const void* data, size_t length) = 0;
virtual bool BuildUninitialized(size_t length) = 0;

View File

@ -26,6 +26,7 @@
namespace OHOS {
namespace Rosen {
namespace Drawing {
class Data;
class ImageFilter;
class ColorFilter;
class ImageFilterImpl : public BaseImpl {
@ -39,6 +40,8 @@ public:
virtual void InitWithArithmetic(const std::vector<scalar>& coefficients, bool enforcePMColor,
const std::shared_ptr<ImageFilter> f1, const std::shared_ptr<ImageFilter> f2) = 0;
virtual void InitWithCompose(const std::shared_ptr<ImageFilter> f1, const std::shared_ptr<ImageFilter> f2) = 0;
virtual std::shared_ptr<Data> Serialize() const = 0;
virtual bool Deserialize(std::shared_ptr<Data> data) = 0;
};
} // namespace Drawing
} // namespace Rosen

View File

@ -21,6 +21,7 @@
#include "draw/brush.h"
#include "effect/color_space.h"
#include "image/bitmap.h"
#include "image/pixmap.h"
#include "image/picture.h"
#include "image/image_info.h"
#include "utils/matrix.h"
@ -38,6 +39,16 @@ enum class CompressedType;
class BackendTexture;
#endif
enum class BitDepth;
/** Caller data passed to RasterReleaseProc; may be nullptr.
*/
typedef void* ReleaseContext;
/** Function called when SkImage no longer shares pixels. ReleaseContext is
provided by caller when SkImage is created, and may be nullptr.
*/
typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext);
class ImageImpl : public BaseImpl {
public:
ImageImpl() noexcept {}
@ -57,6 +68,7 @@ public:
virtual BackendTexture GetBackendTexture(bool flushPendingGrContextIO, TextureOrigin* origin) = 0;
virtual bool IsValid(GPUContext* context) const = 0;
#endif
virtual bool AsLegacyBitmap(Bitmap& bitmap) const = 0;
virtual int GetWidth() const = 0;
virtual int GetHeight() const = 0;
virtual ColorType GetColorType() const = 0;
@ -64,11 +76,16 @@ public:
virtual uint32_t GetUniqueID() const = 0;
virtual ImageInfo GetImageInfo() = 0;
virtual bool ReadPixels(Bitmap& bitmap, int x, int y) = 0;
virtual bool ReadPixels(const ImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
int srcX, int srcY) const = 0;
virtual bool IsTextureBacked() const = 0;
virtual bool ScalePixels(const Bitmap& bitmap, const SamplingOptions& sampling,
bool allowCachingHint = true) const = 0;
virtual std::shared_ptr<Data> EncodeToData(EncodedImageFormat& encodedImageFormat, int quality) const = 0;
virtual bool IsLazyGenerated() const = 0;
virtual bool GetROPixels(Bitmap& bitmap) = 0;
virtual std::shared_ptr<Image> MakeRasterImage() const = 0;
virtual bool CanPeekPixels() const = 0;
virtual bool IsOpaque() const = 0;

View File

@ -25,6 +25,7 @@
namespace OHOS {
namespace Rosen {
namespace Drawing {
class Data;
enum class BlurType;
class MaskFilterImpl : public BaseImpl {
public:
@ -32,6 +33,8 @@ public:
~MaskFilterImpl() override {}
virtual void InitWithBlur(BlurType t, scalar sigma) = 0;
virtual std::shared_ptr<Data> Serialize() const = 0;
virtual bool Deserialize(std::shared_ptr<Data> data) = 0;
};
} // namespace Drawing
} // namespace Rosen

View File

@ -58,6 +58,11 @@ public:
virtual void Set(int index, scalar value);
virtual scalar Get(int index) const = 0;
virtual void GetAll(std::array<scalar, MATRIX_SIZE>& buffer) const = 0;
virtual bool IsIdentity() const = 0;
virtual MatrixImpl* Clone() = 0;
virtual void PreRotate(scalar degree, scalar px, scalar py) = 0;
virtual void PreScale(scalar sx, scalar sy, scalar px, scalar py) = 0;
virtual void Reset() = 0;
};
} // namespace Drawing
} // namespace Rosen

View File

@ -27,6 +27,7 @@
namespace OHOS {
namespace Rosen {
namespace Drawing {
class Data;
class PathEffect;
enum class PathDashStyle;
class PathEffectImpl : public BaseImpl {
@ -40,6 +41,8 @@ public:
virtual void InitWithDiscrete(scalar segLength, scalar dev, uint32_t seedAssist) = 0;
virtual void InitWithSum(const PathEffect& e1, const PathEffect& e2) = 0;
virtual void InitWithCompose(const PathEffect& e1, const PathEffect& e2) = 0;
virtual std::shared_ptr<Data> Serialize() const = 0;
virtual bool Deserialize(std::shared_ptr<Data> data) = 0;
};
} // namespace Drawing
} // namespace Rosen

View File

@ -49,6 +49,7 @@ public:
virtual void LineTo(scalar x, scalar y) = 0;
virtual void ArcTo(scalar pt1X, scalar pt1Y, scalar pt2X, scalar pt2Y, scalar startAngle, scalar sweepAngle) = 0;
virtual void ArcTo(scalar rx, scalar ry, scalar angle, PathDirection direction, scalar endX, scalar endY) = 0;
virtual void ArcTo(scalar x1, scalar y1, scalar x2, scalar y2, scalar radius) = 0;
virtual void CubicTo(
scalar ctrlPt1X, scalar ctrlPt1Y, scalar ctrlPt2X, scalar ctrlPt2Y, scalar endPtX, scalar endPtY) = 0;
virtual void QuadTo(scalar ctrlPtX, scalar ctrlPtY, scalar endPtX, scalar endPtY) = 0;

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PIXMAPIMPL_H
#define PIXMAPIMPL_H
#include "base_impl.h"
#include "image/image_info.h"
namespace OHOS {
namespace Rosen {
namespace Drawing {
class PixmapImpl : public BaseImpl {
public:
PixmapImpl() {}
~PixmapImpl() override {}
virtual std::shared_ptr<ColorSpace> GetColorSpace() = 0;
virtual ColorType GetColorType() = 0;
virtual AlphaType GetAlphaType() = 0;
virtual size_t GetRowBytes() = 0;
virtual const void* GetAddr() = 0;
virtual int GetWidth() = 0;
virtual int GetHeight() = 0;
};
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS
#endif

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef RUNTIME_EFFECT_IMPL_H
#define RUNTIME_EFFECT_IMPL_H
#include <memory>
#include "base_impl.h"
#include "effect/shader_effect.h"
#include "utils/data.h"
#include "utils/matrix.h"
namespace OHOS {
namespace Rosen {
namespace Drawing {
class RuntimeEffectOptions;
class RuntimeEffectImpl : public BaseImpl {
public:
RuntimeEffectImpl() noexcept {}
~RuntimeEffectImpl() override {}
virtual void InitForShader(const std::string& sl, const RuntimeEffectOptions& options) = 0;
virtual void InitForShader(const std::string& sl) = 0;
virtual std::shared_ptr<ShaderEffect> MakeShader(std::shared_ptr<Data> uniforms,
std::shared_ptr<ShaderEffect> children[], size_t childCount, const Matrix* localMatrix,
bool isOpaque) = 0;
};
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS
#endif

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef RUNTIME_SHADER_BUILDER_IMPL_H
#define RUNTIME_SHADER_BUILDER_IMPL_H
#include "base_impl.h"
#include "utils/matrix.h"
#include "utils/matrix44.h"
namespace OHOS {
namespace Rosen {
namespace Drawing {
class RuntimeEffect;
class Image;
class ShaderEffect;
class GPUContext;
class ImageInfo;
class RuntimeShaderBuilderImpl : public BaseImpl {
public:
RuntimeShaderBuilderImpl() {}
explicit RuntimeShaderBuilderImpl(std::shared_ptr<RuntimeEffect> runningTimeEffect) {}
~RuntimeShaderBuilderImpl() override {}
virtual std::shared_ptr<ShaderEffect> MakeShader(const Matrix* localMatrix, bool isOpaque) = 0;
virtual std::shared_ptr<Image> MakeImage(GPUContext* gpuContext,
const Matrix* localMatrix, ImageInfo resultInfo, bool mipmapped) = 0;
virtual void SetChild(const std::string& name, std::shared_ptr<ShaderEffect> shader) = 0;
virtual void SetUniform(const std::string& name, float val) = 0;
virtual void SetUniform(const std::string& name, float x, float y) = 0;
virtual void SetUniform(const std::string& name, float x, float y, float width, float height) = 0;
};
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS
#endif

View File

@ -32,6 +32,7 @@
namespace OHOS {
namespace Rosen {
namespace Drawing {
class Data;
class Image;
class ShaderEffect;
enum class TileMode;
@ -53,6 +54,8 @@ public:
scalar endRadius, const std::vector<ColorQuad>& colors, const std::vector<scalar>& pos, TileMode mode) = 0;
virtual void InitWithSweepGradient(const Point& centerPt, const std::vector<ColorQuad>& colors,
const std::vector<scalar>& pos, TileMode mode, scalar startAngle, scalar endAngle) = 0;
virtual std::shared_ptr<Data> Serialize() const = 0;
virtual bool Deserialize(std::shared_ptr<Data> data) = 0;
};
} // namespace Drawing
} // namespace Rosen

View File

@ -47,6 +47,7 @@ public:
virtual std::shared_ptr<Image> GetImageSnapshot(const RectI& bounds) const = 0;
virtual std::shared_ptr<Surface> MakeSurface(int width, int height) const = 0;
virtual void FlushAndSubmit(bool syncCpu) = 0;
virtual void Flush() = 0;
};
} // namespace Drawing
} // namespace Rosen

View File

@ -18,6 +18,7 @@
#include "impl_interface/base_impl.h"
#include "utils/data.h"
#include "utils/rect.h"
namespace OHOS {
namespace Rosen {
@ -27,6 +28,7 @@ public:
~TextBlobImpl() override = default;
virtual std::shared_ptr<Data> Serialize() const = 0;
virtual std::shared_ptr<Rect> Bounds() const = 0;
protected:
TextBlobImpl() noexcept = default;

View File

@ -14,6 +14,7 @@
*/
#include "skia_bitmap.h"
#include "skia_pixmap.h"
#include "include/core/SkImageInfo.h"
@ -21,6 +22,10 @@
#include "image/bitmap.h"
#include "src/core/SkAutoMalloc.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkWriteBuffer.h"
#include "utils/data.h"
namespace OHOS {
namespace Rosen {
namespace Drawing {
@ -73,6 +78,18 @@ AlphaType SkiaBitmap::GetAlphaType() const
return SkiaImageInfo::ConvertToAlphaType(skiaBitmap_.alphaType());
}
bool SkiaBitmap::ExtractSubset(Bitmap& dst, const Rect& subset) const
{
const SkBitmap& subBitmap = dst.GetImpl<SkiaBitmap>()->ExportSkiaBitmap();
SkIRect subRect = SkIRect::MakeLTRB(subset.GetLeft(), subset.GetTop(), subset.GetRight(), subset.GetBottom());
return skiaBitmap_.extractSubset(const_cast<SkBitmap*>(&subBitmap), subRect);
}
bool SkiaBitmap::ReadPixels(const ImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
int srcX, int srcY) const
{
SkImageInfo skImageInfo = SkiaImageInfo::ConvertToSkImageInfo(dstInfo);
return skiaBitmap_.readPixels(skImageInfo, dstPixels, dstRowBytes, srcX, srcY);
}
void* SkiaBitmap::GetPixels() const
{
return skiaBitmap_.getPixels();
@ -83,6 +100,19 @@ void SkiaBitmap::SetPixels(void* pixels)
skiaBitmap_.setPixels(pixels);
}
bool SkiaBitmap::InstallPixels(const ImageInfo& info, void* pixels, size_t rowBytes,
ReleaseProc releaseProc, void* context)
{
SkImageInfo skImageInfo = SkiaImageInfo::ConvertToSkImageInfo(info);
return skiaBitmap_.installPixels(skImageInfo, pixels, rowBytes, releaseProc, context);
}
bool SkiaBitmap::PeekPixels(Pixmap& pixmap) const
{
const SkPixmap& skiaPixmap = pixmap.GetImpl<SkiaPixmap>()->ExportSkiaPixmap();
return skiaBitmap_.peekPixels(const_cast<SkPixmap*>(&skiaPixmap));
}
const SkBitmap& SkiaBitmap::ExportSkiaBitmap() const
{
return skiaBitmap_;
@ -132,6 +162,99 @@ bool SkiaBitmap::IsValid() const
{
return skiaBitmap_.drawsNothing();
}
bool SkiaBitmap::IsEmpty() const
{
return skiaBitmap_.empty();
}
void SkiaBitmap::SetSkBitmap(const SkBitmap& skBitmap)
{
skiaBitmap_ = skBitmap;
}
std::shared_ptr<Data> SkiaBitmap::Serialize() const
{
#ifdef ROSEN_OHOS
SkBinaryWriteBuffer writer;
size_t rb = skiaBitmap_.rowBytes();
int width = skiaBitmap_.width();
int height = skiaBitmap_.height();
const void *addr = skiaBitmap_.pixmap().addr();
size_t pixmapSize = rb * static_cast<size_t>(height);
writer.writeUInt(pixmapSize);
if (addr == nullptr) {
return nullptr;
}
writer.writeByteArray(addr, pixmapSize);
writer.writeUInt(rb);
writer.writeInt(width);
writer.writeInt(height);
writer.writeUInt(skiaBitmap_.colorType());
writer.writeUInt(skiaBitmap_.alphaType());
if (skiaBitmap_.colorSpace() == nullptr) {
writer.writeUInt(0);
} else {
auto data = skiaBitmap_.colorSpace()->serialize();
writer.writeUInt(data->size());
writer.writeByteArray(data->data(), data->size());
}
size_t length = writer.bytesWritten();
std::shared_ptr<Data> data = std::make_shared<Data>();
data->BuildUninitialized(length);
writer.writeToMemory(data->WritableData());
return data;
#else
return nullptr;
#endif
}
bool SkiaBitmap::Deserialize(std::shared_ptr<Data> data)
{
if (data == nullptr) {
return false;
}
SkReadBuffer reader(data->GetData(), data->GetSize());
size_t pixmapSize = reader.readUInt();
if (pixmapSize == 0) {
return false;
}
SkAutoMalloc pixBuffer(pixmapSize);
if (!reader.readByteArray(pixBuffer.get(), pixmapSize)) {
return false;
}
size_t rb = reader.readUInt();
int width = reader.readInt();
int height = reader.readInt();
SkColorType colorType = static_cast<SkColorType>(reader.readUInt());
SkAlphaType alphaType = static_cast<SkAlphaType>(reader.readUInt());
sk_sp<SkColorSpace> colorSpace;
size_t size = reader.readUInt();
if (size == 0) {
colorSpace = nullptr;
} else {
SkAutoMalloc colorBuffer(size);
if (!reader.readByteArray(colorBuffer.get(), size)) {
return false;
}
colorSpace = SkColorSpace::Deserialize(colorBuffer.get(), size);
}
SkImageInfo imageInfo = SkImageInfo::Make(width, height, colorType, alphaType, colorSpace);
skiaBitmap_.setInfo(imageInfo, rb);
skiaBitmap_.allocPixels();
skiaBitmap_.setPixels(const_cast<void*>(pixBuffer.get()));
return true;
}
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS

View File

@ -42,8 +42,14 @@ public:
int GetRowBytes() const override;
ColorType GetColorType() const override;
AlphaType GetAlphaType() const override;
bool ExtractSubset(Bitmap& dst, const Rect& subset) const override;
bool ReadPixels(const ImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
int srcX, int srcY) const override;
void* GetPixels() const override;
void SetPixels(void* pixels) override;
bool InstallPixels(const ImageInfo& info, void* pixels, size_t rowBytes,
ReleaseProc releaseProc, void* context) override;
bool PeekPixels(Pixmap& pixmap) const override;
const SkBitmap& ExportSkiaBitmap() const;
void CopyPixels(Bitmap& dst, int srcLeft, int srcTop) const override;
bool IsImmutable() override;
@ -52,6 +58,11 @@ public:
ColorQuad GetColor(int x, int y) const override;
void Free() override;
bool IsValid() const override;
bool IsEmpty() const override;
void SetSkBitmap(const SkBitmap& skBitmap);
std::shared_ptr<Data> Serialize() const override;
bool Deserialize(std::shared_ptr<Data> data) override;
private:
SkBitmap skiaBitmap_;

View File

@ -892,6 +892,15 @@ bool SkiaCanvas::IsClipEmpty()
return skCanvas_->isClipEmpty();
}
bool SkiaCanvas::IsClipRect()
{
if (!skCanvas_) {
LOGE("skCanvas_ is null, return on line %{public}d", __LINE__);
return false;
}
return skCanvas_->isClipRect();
}
bool SkiaCanvas::QuickReject(const Rect& rect)
{
if (!skCanvas_) {

View File

@ -124,6 +124,7 @@ public:
void ClipPath(const Path& path, ClipOp op, bool doAntiAlias) override;
void ClipRegion(const Region& region, ClipOp op = ClipOp::INTERSECT) override;
bool IsClipEmpty() override;
bool IsClipRect() override;
bool QuickReject(const Rect& rect) override;
// transform

View File

@ -17,8 +17,12 @@
#include "include/effects/SkLumaColorFilter.h"
#include "include/effects/SkOverdrawColorFilter.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkWriteBuffer.h"
#include "effect/color_filter.h"
#include "utils/data.h"
#include "utils/log.h"
namespace OHOS {
namespace Rosen {
@ -78,6 +82,43 @@ void SkiaColorFilter::SetColorFilter(const sk_sp<SkColorFilter>& filter)
{
filter_ = filter;
}
std::shared_ptr<Data> SkiaColorFilter::Serialize() const
{
#ifdef ROSEN_OHOS
if (filter_ == nullptr) {
LOGE("SkiaColorFilter::Serialize, filter_ is nullptr!");
return nullptr;
}
SkBinaryWriteBuffer writer;
writer.writeFlattenable(filter_.get());
size_t length = writer.bytesWritten();
std::shared_ptr<Data> data = std::make_shared<Data>();
data->BuildUninitialized(length);
writer.writeToMemory(data->WritableData());
return data;
#else
return nullptr;
#endif
}
bool SkiaColorFilter::Deserialize(std::shared_ptr<Data> data)
{
#ifdef ROSEN_OHOS
if (data == nullptr) {
LOGE("SkiaColorFilter::Deserialize, data is invalid!");
return false;
}
SkReadBuffer reader(data->GetData(), data->GetSize());
filter_ = reader.readColorFilter();
return filter_ != nullptr;
#else
return false;
#endif
}
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS

View File

@ -49,6 +49,8 @@ public:
*/
void SetColorFilter(const sk_sp<SkColorFilter>& filter);
std::shared_ptr<Data> Serialize() const override;
bool Deserialize(std::shared_ptr<Data> data) override;
private:
sk_sp<SkColorFilter> filter_;
};

View File

@ -14,10 +14,11 @@
*/
#include "skia_color_space.h"
#include "skia_data.h"
#include "skia_image.h"
#include "image/image.h"
#include "utils/log.h"
namespace OHOS {
namespace Rosen {
@ -91,6 +92,31 @@ sk_sp<SkColorSpace> SkiaColorSpace::GetColorSpace() const
{
return colorSpace_;
}
std::shared_ptr<Data> SkiaColorSpace::Serialize() const
{
if (colorSpace_ == nullptr) {
LOGE("SkiaColorSpace::Serialize, colorSpace_ is nullptr!");
return nullptr;
}
auto skData = colorSpace_->serialize();
std::shared_ptr<Data> data = std::make_shared<Data>();
data->GetImpl<SkiaData>()->SetSkData(skData);
return data;
}
bool SkiaColorSpace::Deserialize(std::shared_ptr<Data> data)
{
if (data == nullptr) {
LOGE("SkiaColorSpace::Deserialize, data is invalid!");
return false;
}
colorSpace_ = SkColorSpace::Deserialize(data->GetData(), data->GetSize());
return colorSpace_ != nullptr;
}
} // namespace Drawing
} // namespace Rosen
} // namespace OHOS

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