Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions harmony/fast_image/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@
cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)

file(GLOB rnoh_fast_image_SRC CONFIGURE_DEPENDS *.cpp colorUtils/*.cpp)
set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${NATIVERENDER_ROOT_PATH}
${NATIVERENDER_ROOT_PATH}/include)

if(DEFINED PACKAGE_FIND_FILE)
include(${PACKAGE_FIND_FILE})
endif()
file(GLOB rnoh_fast_image_SRC CONFIGURE_DEPENDS *.cpp colorUtils/*.cpp downloadUtils/*.cpp)
add_library(rnoh_fast_image SHARED ${rnoh_fast_image_SRC})
target_include_directories(rnoh_fast_image PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(rnoh_fast_image PUBLIC rnoh)
target_link_libraries(rnoh_fast_image PUBLIC rnoh)

target_link_libraries(rnoh_fast_image PUBLIC librcp_c.so
libohfileuri.so libimage_source.so
libace_ndk.z.so )

target_link_directories(rnoh_fast_image PUBLIC ${HMOS_SDK_NATIVE}/sysroot/usr/lib/aarch64-linux-ohos)
31 changes: 0 additions & 31 deletions harmony/fast_image/src/main/cpp/FastImageLoaderTurboModule.cpp

This file was deleted.

169 changes: 0 additions & 169 deletions harmony/fast_image/src/main/cpp/FastImageLoaderTurboModule.h

This file was deleted.

9 changes: 9 additions & 0 deletions harmony/fast_image/src/main/cpp/FastImageNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ FastImageNode& FastImageNode::setSources(std::string const& uri, std::string pre
} else {
item = {.string = uri.c_str()};
}

maybeThrow(NativeNodeApi::getInstance()->setAttribute(
m_nodeHandle, NODE_IMAGE_SRC, &item));
return *this;
}

FastImageNode& FastImageNode::setSources(ArkUI_DrawableDescriptor* image) {
ArkUI_AttributeItem item;
item = {.object = reinterpret_cast<void*>(image)};
maybeThrow(NativeNodeApi::getInstance()->setAttribute(
m_nodeHandle, NODE_IMAGE_SRC, &item));
return *this;
Expand Down
1 change: 1 addition & 0 deletions harmony/fast_image/src/main/cpp/FastImageNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class FastImageNode : public ArkUINode {
FastImageNode();
~FastImageNode();
FastImageNode& setSources(std::string const& uri, std::string prefix = "");
FastImageNode& setSources(ArkUI_DrawableDescriptor* image);
FastImageNode& setResizeMode(facebook::react::ImageResizeMode const& mode);
FastImageNode& setTintColor(facebook::react::SharedColor const& sharedColor);
FastImageNode& setBlur(facebook::react::Float blur);
Expand Down
3 changes: 0 additions & 3 deletions harmony/fast_image/src/main/cpp/FastImagePackage.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "ComponentDescriptors.h"
#include "FastImageViewJSIBinder.h"
#include "RNCFastImageViewTurboModule.h"
#include "FastImageLoaderTurboModule.h"
#include "FastImageViewComponentInstance.h"

namespace rnoh {
Expand All @@ -24,8 +23,6 @@ class FastImageTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
if (name == "RNCFastImageView") {
return std::make_shared<RNCFastImageViewTurboModule>(ctx, name);
} else if (name == "FastImageLoader") {
return std::make_shared<FastImageLoaderTurboModule>(ctx, name);
}
return nullptr;
};
Expand Down
93 changes: 93 additions & 0 deletions harmony/fast_image/src/main/cpp/FastImageSourceResolver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@

#include "FastImageSourceResolver.h"
#include <fstream>
#include <multimedia/image_framework/image/image_source_native.h>

namespace rnoh {

std::string FastImageSourceResolver::resolveImageSources(ImageSourceUpdateListener &listener, std::string uri) {
//先找是不是还在下载
if(pendingSet.find(uri) != pendingSet.end()){
removeListener(&listener);
addListenerForURI(uri, &listener);
return "";
}
DownloadUri downloadUri;
std::string fileUri = downloadUri.getUri(uri);
bool exist = remoteImageSourceMap.get(fileUri);
if(exist){
uri = "file://"+ fileCacheDir + fileUri;
}

return uri;
}

void FastImageSourceResolver::addListenerForURI(const std::string &uri, ImageSourceUpdateListener *listener) {
listener->observedUri = uri;
auto it = uriListenersMap.find(uri);
if (it == uriListenersMap.end()) {
uriListenersMap.emplace(uri, std::initializer_list<ImageSourceUpdateListener *>{listener});
return;
}
if (std::find(it->second.begin(), it->second.end(), listener) != it->second.end()) {
return;
}
it->second.push_back(listener);
}

void FastImageSourceResolver::removeListenerForURI(const std::string &uri, ImageSourceUpdateListener *listener) {
auto it = uriListenersMap.find(uri);
if (it == uriListenersMap.end()) {
return;
}
auto &listeners = it->second;
auto listenerPos = std::find(listeners.begin(), listeners.end(), listener);
if (listenerPos != listeners.end()) {
listeners.erase(listenerPos);
if (listeners.empty()) {
uriListenersMap.erase(uri);
}
}
}

void FastImageSourceResolver::removeListener(ImageSourceUpdateListener *listener) {
if(!listener->observedUri.empty()){
removeListenerForURI(listener->observedUri, listener);
}
}

void FastImageSourceResolver::imageDownloadComplete(std::string uri,std::string fileUri){
auto pend = pendingSet.find(uri);
if(pend != pendingSet.end()){
pendingSet.erase(uri);
}

remoteImageSourceMap.put(fileUri, true);
auto it = uriListenersMap.find(uri);
if (it == uriListenersMap.end()) {
return;
}

auto &listeners = it->second;
for (auto listener : listeners) {
listener->onImageSourceCacheUpdate(fileUri);
removeListenerForURI(uri, listener);
}
}
void FastImageSourceResolver::imageDownloadFail(std::string uri){
auto pend = pendingSet.find(uri);
if(pend != pendingSet.end()){
pendingSet.erase(uri);
}

auto it = uriListenersMap.find(uri);
if (it == uriListenersMap.end()) {
return;
}
auto &listeners = it->second;
for (auto listener : listeners) {
listener->onImageSourceCacheDownloadFileFail();
removeListenerForURI(uri, listener);
}
}
}
Loading