Skip to content

Commit

Permalink
~ Added pixman-arm-intrisics.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
gindemit committed Jul 10, 2023
1 parent cd1cdfa commit 7c11dc1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
46 changes: 46 additions & 0 deletions dependency/pixman/pixman-arm-intrisics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <arm_neon.h>

extern "C" void pixman_composite_src_n_8888_asm_neon(int32_t w, int32_t h,
uint32_t *dst,
int32_t dst_stride,
uint32_t src)
{
uint8x8_t v_src = vdup_n_u8(src);

for (int32_t y = 0; y < h; y++)
{
for (int32_t x = 0; x < w; x += 8)
{
vst1_u8((uint8_t *)(dst + x), v_src);
}
dst += dst_stride;
}
}

extern "C" void pixman_composite_over_n_8888_asm_neon(int32_t w, int32_t h,
uint32_t *dst,
int32_t dst_stride,
uint32_t src)
{
// Extract the source alpha and replicate it to all 8 lanes of a NEON vector
uint8x8_t v_src_alpha = vdup_n_u8(src >> 24);
// Extract the source color and replicate it to all 8 lanes of a NEON vector
uint8x8_t v_src_color = vdup_n_u8(src);

for (int32_t y = 0; y < h; y++)
{
for (int32_t x = 0; x < w; x += 8)
{
// Load 8 destination pixels
uint8x8_t v_dst_color = vld1_u8((uint8_t *)(dst + x));

// Calculate the result color = source color * source alpha + destination color * (1 - source alpha)
// Note that we need to shift right by 8 because the alpha blending operation can result in values greater than 255
uint8x8_t v_res_color = vshrq_n_u8(vmlaq_u8(vmlsq_u8(v_dst_color, v_dst_color, v_src_alpha), v_src_color, v_src_alpha), 8);

// Store the result to memory
vst1_u8((uint8_t *)(dst + x), v_res_color);
}
dst += dst_stride;
}
}
4 changes: 2 additions & 2 deletions projects/CMake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ if (ANDROID)
message("Compile asm source for armv7-a")
target_compile_options(rlottie PUBLIC -fno-integrated-as)
target_compile_definitions(rlottie PUBLIC USE_ARM_NEON)
target_sources(rlottie PRIVATE ${PIXMAN_ROOT}/pixman-arm-neon-asm.S)
target_sources(rlottie PRIVATE ${PIXMAN_ROOT}/pixman-arm-intrisics.cpp)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
message("Compile asm source for aarch64")
target_compile_options(rlottie PUBLIC -fno-integrated-as)
target_compile_definitions(rlottie PUBLIC USE_ARM_NEON __ARM64_NEON__)
target_sources(rlottie PRIVATE ${PIXMAN_ROOT}/pixman-arma64-neon-asm.S)
target_sources(rlottie PRIVATE ${PIXMAN_ROOT}/pixman-arm-intrisics.cpp)
endif()
endif()

Expand Down

0 comments on commit 7c11dc1

Please sign in to comment.