Skip to content

Commit

Permalink
Add c api for pag.
Browse files Browse the repository at this point in the history
  • Loading branch information
lvpengwei committed Oct 17, 2023
1 parent 3ee70f7 commit 00a36f8
Show file tree
Hide file tree
Showing 50 changed files with 3,501 additions and 74 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ option(PAG_USE_SWIFTSHADER "allow build with SwiftShader library" OFF)
option(PAG_USE_QT "allow build with QT frameworks" OFF)
option(PAG_USE_RTTR "enable RTTR support" OFF)
option(PAG_USE_HARFBUZZ "enable HarfBuzz support" OFF)
option(PAG_USE_C "enable c API" OFF)

if (NOT APPLE AND NOT WEB)
option(PAG_USE_FREETYPE "Allow use of embedded freetype library" ON)
Expand Down Expand Up @@ -98,6 +99,7 @@ message("PAG_USE_RTTR: ${PAG_USE_RTTR}")
message("PAG_USE_HARFBUZZ: ${PAG_USE_HARFBUZZ}")
message("PAG_BUILD_SHARED: ${PAG_BUILD_SHARED}")
message("PAG_BUILD_TESTS: ${PAG_BUILD_TESTS}")
message("PAG_USE_C: ${PAG_USE_C}")

set(TGFX_USE_OPENGL ${PAG_USE_OPENGL})
set(TGFX_USE_QT ${PAG_USE_QT})
Expand All @@ -114,6 +116,11 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
add_subdirectory(tgfx/ EXCLUDE_FROM_ALL)
list(APPEND PAG_INCLUDES tgfx/include)

if (PAG_USE_C)
file(GLOB_RECURSE PAG_C_FILES src/c/*.*)
list(APPEND PAG_FILES ${PAG_C_FILES})
endif()

if (PAG_USE_LIBAVC)
add_definitions(-DPAG_USE_LIBAVC)
list(APPEND PAG_STATIC_VENDORS libavc)
Expand Down
36 changes: 36 additions & 0 deletions include/pag/c/pag.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "pag_animator.h"
#include "pag_backend_semaphore.h"
#include "pag_backend_texture.h"
#include "pag_byte_data.h"
#include "pag_composition.h"
#include "pag_decoder.h"
#include "pag_disk_cache.h"
#include "pag_file.h"
#include "pag_font.h"
#include "pag_image.h"
#include "pag_image_layer.h"
#include "pag_layer.h"
#include "pag_player.h"
#include "pag_solid_layer.h"
#include "pag_surface.h"
#include "pag_text_document.h"
54 changes: 54 additions & 0 deletions include/pag/c/pag_animator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "pag_types.h"

PAG_C_PLUS_PLUS_BEGIN_GUARD

/**
* Creates a new pag_animator with the specified listener. Release it by pag_release.
*/
PAG_API pag_animator* pag_animator_create(pag_animator_listener* listener, void* user);

PAG_API bool pag_animator_is_sync(pag_animator* animator);

PAG_API void pag_animator_set_sync(pag_animator* animator, bool sync);

PAG_API int64_t pag_animator_get_duration(pag_animator* animator);

PAG_API void pag_animator_set_duration(pag_animator* animator, int64_t duration);

PAG_API int pag_animator_get_repeat_count(pag_animator* animator);

PAG_API void pag_animator_set_repeat_count(pag_animator* animator, int repeatCount);

PAG_API double pag_animator_get_progress(pag_animator* animator);

PAG_API void pag_animator_set_progress(pag_animator* animator, double progress);

PAG_API bool pag_animator_is_running(pag_animator* animator);

PAG_API void pag_animator_start(pag_animator* animator);

PAG_API void pag_animator_cancel(pag_animator* animator);

PAG_API void pag_animator_update(pag_animator* animator);

PAG_C_PLUS_PLUS_END_GUARD
36 changes: 36 additions & 0 deletions include/pag/c/pag_backend_semaphore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "pag_types.h"

PAG_C_PLUS_PLUS_BEGIN_GUARD

/**
* Creates a new pag_backend_semaphore. Release it by pag_release.
*/
PAG_API pag_backend_semaphore* pag_backend_semaphore_create();

PAG_API bool pag_backend_semaphore_is_initialized(pag_backend_semaphore* semaphore);

PAG_API void pag_backend_semaphore_init_gl(pag_backend_semaphore* semaphore, void* glSync);

PAG_API void* pag_backend_semaphore_get_gl_sync(pag_backend_semaphore* semaphore);

PAG_C_PLUS_PLUS_END_GUARD
41 changes: 41 additions & 0 deletions include/pag/c/pag_backend_texture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "pag_types.h"

PAG_C_PLUS_PLUS_BEGIN_GUARD

/**
* Creates a new pag_backend_texture with texture info, width and height.
* Release it by pag_release.
*/
PAG_API pag_backend_texture* pag_backend_texture_create_from_gl_texture_info(
pag_gl_texture_info textureInfo, int width, int height);

PAG_API bool pag_backend_texture_get_gl_texture_info(pag_backend_texture* texture,
pag_gl_texture_info* textureInfo);

PAG_API bool pag_backend_texture_get_vk_image_info(pag_backend_texture* texture,
pag_vk_image_info* imageInfo);

PAG_API bool pag_backend_texture_get_mtl_texture_info(pag_backend_texture* texture,
pag_mtl_texture_info* mtl_texture_info);

PAG_C_PLUS_PLUS_END_GUARD
30 changes: 30 additions & 0 deletions include/pag/c/pag_byte_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "pag_types.h"

PAG_C_PLUS_PLUS_BEGIN_GUARD

/**
* Creates a new pag_byte_data and copy the bytes and length. Release it by pag_release.
*/
PAG_API pag_byte_data* pag_byte_data_copy(const void* bytes, size_t length);

PAG_C_PLUS_PLUS_END_GUARD
41 changes: 41 additions & 0 deletions include/pag/c/pag_composition.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "pag_types.h"

PAG_C_PLUS_PLUS_BEGIN_GUARD

PAG_API int pag_composition_get_width(pag_composition* composition);

PAG_API int pag_composition_get_height(pag_composition* composition);

/**
* Returns an array of layers that match the specified layer name. Release it by pag_release.
*/
PAG_API pag_layer** pag_composition_get_layers_by_name(pag_composition* composition,
const char* layerName, size_t* count);

/**
* Returns an array of layers that match the specified layer type. Release it by pag_release.
*/
PAG_API pag_layer** pag_composition_get_layers_by_type(pag_composition* composition,
pag_layer_type layerType, size_t* count);

PAG_C_PLUS_PLUS_END_GUARD
48 changes: 48 additions & 0 deletions include/pag/c/pag_decoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "pag_types.h"

PAG_C_PLUS_PLUS_BEGIN_GUARD

/**
* Creates a new pag_decoder with a pag_composition, a frame rate limit, and a scale factor for the
* decoded image size. Release it by pag_release.
*/
PAG_API pag_decoder* pag_decoder_create(pag_composition* composition, float maxFrameRate,
float scale);

PAG_API int pag_decoder_get_width(pag_decoder* decoder);

PAG_API int pag_decoder_get_height(pag_decoder* decoder);

PAG_API int pag_decoder_get_num_frames(pag_decoder* decoder);

PAG_API float pag_decoder_get_frame_rate(pag_decoder* decoder);

PAG_API bool pag_decoder_check_frame_changed(pag_decoder* decoder, int index);

PAG_API bool pag_decoder_read_frame(pag_decoder* decoder, int index, void* pixels, size_t rowBytes,
pag_color_type colorType, pag_alpha_type alphaType);

PAG_API bool pag_decoder_read_frame_to_hardware_buffer(pag_decoder* decoder, int index,
void* buffer);

PAG_C_PLUS_PLUS_END_GUARD
31 changes: 31 additions & 0 deletions include/pag/c/pag_disk_cache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "pag_types.h"

PAG_C_PLUS_PLUS_BEGIN_GUARD

PAG_API size_t pag_disk_cache_get_max_disk_size();

PAG_API void pag_disk_cache_set_max_disk_size(size_t maxDiskSize);

PAG_API void pag_disk_cache_remove_all();

PAG_C_PLUS_PLUS_END_GUARD
Loading

0 comments on commit 00a36f8

Please sign in to comment.