diff --git a/adapter/ohos/osal/BUILD.gn b/adapter/ohos/osal/BUILD.gn index c5415a723b1391bc01adba4f911ce0366051c11b..6121df63b11d86db36f352dc6d48257970b45812 100644 --- a/adapter/ohos/osal/BUILD.gn +++ b/adapter/ohos/osal/BUILD.gn @@ -109,7 +109,6 @@ template("ace_osal_ohos_source_set") { external_deps += [ "multimedia_image:image" ] } sources += [ - "image_source_ohos.cpp", "mouse_style_ohos.cpp", "pixel_map_ohos.cpp", ] diff --git a/adapter/ohos/osal/image_source_ohos.cpp b/adapter/ohos/osal/image_source_ohos.cpp deleted file mode 100644 index d563d6cd101d6346d5ec858cf443887129dae116..0000000000000000000000000000000000000000 --- a/adapter/ohos/osal/image_source_ohos.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 "image_source_ohos.h" - -#include "image_source.h" -#include "media_errors.h" - -namespace OHOS::Ace { -RefPtr ImageSource::Create(int32_t fd) -{ - uint32_t errorCode; - Media::SourceOptions options; - auto src = Media::ImageSource::CreateImageSource(fd, options, errorCode); - if (errorCode != Media::SUCCESS) { - LOGE("create image source failed, errorCode = %{public}u", errorCode); - return nullptr; - } - return MakeRefPtr(std::move(src)); -} - -std::string ImageSourceOhos::GetProperty(const std::string& key) -{ - std::string value; - uint32_t res = imageSource_->GetImagePropertyString(0, key, value); - if (res != Media::SUCCESS) { - LOGE("Get ImageSource property %{public}s failed, errorCode = %{public}u", key.c_str(), res); - } - return value; -} -} // namespace OHOS::Ace diff --git a/adapter/ohos/osal/image_source_ohos.h b/adapter/ohos/osal/image_source_ohos.h deleted file mode 100644 index 6b12b21f20fea8311c1dcb544a17ef46feced0ec..0000000000000000000000000000000000000000 --- a/adapter/ohos/osal/image_source_ohos.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 FOUNDATION_ACE_ADAPTER_OHOS_OSAL_IMAGE_SOURCE_OHOS_H -#define FOUNDATION_ACE_ADAPTER_OHOS_OSAL_IMAGE_SOURCE_OHOS_H - -#include - -#include "image_source.h" - -#include "base/image/image_source.h" - -namespace OHOS::Ace { -class ImageSourceOhos : public ImageSource { - DECLARE_ACE_TYPE(PixelMapOhos, ImageSource) -public: - explicit ImageSourceOhos(std::unique_ptr&& source) : imageSource_(std::move(source)) {} - - std::string GetProperty(const std::string& key) override; - -private: - std::unique_ptr imageSource_; -}; - -} // namespace OHOS::Ace -#endif // FOUNDATION_ACE_ADAPTER_OHOS_OSAL_IMAGE_SOURCE_OHOS_H diff --git a/adapter/preview/osal/image_source_preview.h b/adapter/preview/osal/image_source_preview.h deleted file mode 100644 index 37cd30cffc380eda3a82d5a5340156034ae7b52c..0000000000000000000000000000000000000000 --- a/adapter/preview/osal/image_source_preview.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 FOUNDATION_ACE_ADAPTER_PREVIEW_OSAL_IMAGE_SOURCE_PREVIEW_H -#define FOUNDATION_ACE_ADAPTER_PREVIEW_OSAL_IMAGE_SOURCE_PREVIEW_H - -#include "base/image/image_source.h" - -namespace OHOS::Ace { -RefPtr ImageSource::Create(int32_t fd) -{ - return nullptr; -} -class ImageSourcePreview : public ImageSource { - DECLARE_ACE_TYPE(ImageSourcePreview, ImageSource) - -public: - std::string GetProperty(const std::string& /* key */) override - { - return ""; - } -}; -} // namespace OHOS::Ace -#endif // FOUNDATION_ACE_ADAPTER_PREVIEW_OSAL_IMAGE_SOURCE_PREVIEW_H diff --git a/frameworks/base/image/image_source.h b/frameworks/base/image/image_source.h deleted file mode 100644 index f81749eee2898f84a60960027d4cc6fdb9431a97..0000000000000000000000000000000000000000 --- a/frameworks/base/image/image_source.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 FOUNDATION_ACE_FRAMEWORKS_BASE_IMAGE_ACE_IMAGE_SOURCE_H -#define FOUNDATION_ACE_FRAMEWORKS_BASE_IMAGE_ACE_IMAGE_SOURCE_H - -#include "base/memory/ace_type.h" - -namespace OHOS::Ace { -class ACE_EXPORT ImageSource : public AceType { - DECLARE_ACE_TYPE(ImageSource, AceType) - -public: - static RefPtr Create(int32_t fd); - virtual std::string GetProperty(const std::string& key) = 0; -}; -} // namespace OHOS::Ace - -#endif // FOUNDATION_ACE_FRAMEWORKS_BASE_IMAGE_ACE_IMAGE_SOURCE_H diff --git a/frameworks/base/resource/data_provider_manager.h b/frameworks/base/resource/data_provider_manager.h index 37e5f53c95d05713bab8190a5c79cff95612e04a..23b42179d20cd677d05a6c1146cfe3039319cf86 100644 --- a/frameworks/base/resource/data_provider_manager.h +++ b/frameworks/base/resource/data_provider_manager.h @@ -56,7 +56,6 @@ public: virtual std::unique_ptr GetDataProviderResFromUri(const std::string& uriStr) = 0; virtual void* GetDataProviderThumbnailResFromUri(const std::string& uriStr) = 0; - virtual int32_t GetDataProviderFile(const std::string& uriStr, const std::string& mode) = 0; ACE_DISALLOW_COPY_AND_MOVE(DataProviderManagerInterface); }; @@ -69,14 +68,10 @@ public: ~DataProviderManager() override = default; std::unique_ptr GetDataProviderResFromUri(const std::string& uriStr) override; - void* GetDataProviderThumbnailResFromUri(const std::string& /* uriStr */) override + void* GetDataProviderThumbnailResFromUri(const std::string& uriStr) override { return nullptr; }; - int32_t GetDataProviderFile(const std::string& /* uriStr */, const std::string& /* mode */) override - { - return -1; - } private: DataProviderImpl platformImpl_; @@ -98,7 +93,7 @@ public: std::unique_ptr GetDataProviderResFromUri(const std::string& uriStr) override; void* GetDataProviderThumbnailResFromUri(const std::string& uriStr) override; - int32_t GetDataProviderFile(const std::string& uriStr, const std::string& mode) override; + int32_t GetDataProviderFile(const std::string& uriStr, const std::string& mode); private: void InitHelper(); diff --git a/frameworks/core/components_ng/image_provider/image_provider.cpp b/frameworks/core/components_ng/image_provider/image_provider.cpp index b7fecf533ce76c4f9ddc80fd38015e6a8ad9e5a7..802e89bacc8e91e06c793577d9df5f9610262253 100644 --- a/frameworks/core/components_ng/image_provider/image_provider.cpp +++ b/frameworks/core/components_ng/image_provider/image_provider.cpp @@ -83,9 +83,6 @@ bool ImageProvider::PrepareImageData(const RefPtr& imageObj) RefPtr ImageProvider::QueryImageObjectFromCache(const ImageSourceInfo& src) { - if (!src.IsSupportCache()) { - return nullptr; - } auto pipelineCtx = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipelineCtx, nullptr); auto imageCache = pipelineCtx->GetImageCache(); diff --git a/frameworks/core/components_ng/test/mock/image_provider/mock_image_source_info.cpp b/frameworks/core/components_ng/test/mock/image_provider/mock_image_source_info.cpp index 6d09bb82899690738d49571fd6d7fbe129807e00..d91c487e0f5f1e004f2aa60971b2630844442667 100644 --- a/frameworks/core/components_ng/test/mock/image_provider/mock_image_source_info.cpp +++ b/frameworks/core/components_ng/test/mock/image_provider/mock_image_source_info.cpp @@ -184,9 +184,4 @@ std::string ImageSourceInfo::GetKey() const { return std::string(""); } - -bool ImageSourceInfo::IsSupportCache() const -{ - return false; -} } // namespace OHOS::Ace diff --git a/frameworks/core/image/image_cache.h b/frameworks/core/image/image_cache.h index 01bd72b5ab57c7f6636f8b9ef710742f266d90c9..59b8ceafda9803cd6d53537c9a037cf6600a8c30 100644 --- a/frameworks/core/image/image_cache.h +++ b/frameworks/core/image/image_cache.h @@ -24,7 +24,6 @@ #include #include -#include "base/image/pixel_map.h" #include "base/log/log.h" #include "base/memory/ace_type.h" #include "base/utils/macros.h" @@ -242,26 +241,6 @@ protected: static bool hasSetCacheFileInfo_; }; -struct PixmapCachedData : public CachedImageData { - DECLARE_ACE_TYPE(PixmapCachedData, CachedImageData); - -public: - explicit PixmapCachedData(const RefPtr& data) : pixmap_(data) {} - ~PixmapCachedData() override = default; - - size_t GetSize() override - { - return pixmap_ ? pixmap_->GetByteCount() : 0; - } - - const uint8_t* GetData() override - { - return pixmap_ ? pixmap_->GetPixels() : nullptr; - } - - const RefPtr pixmap_; -}; - } // namespace OHOS::Ace #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_IMAGE_IMAGE_CACHE_H diff --git a/frameworks/core/image/image_loader.cpp b/frameworks/core/image/image_loader.cpp index 6e55ae9daca6ca08144bfcc57468cd542a1bd3d3..4db5c72dea430b22814c42fedce6b18aa046089d 100644 --- a/frameworks/core/image/image_loader.cpp +++ b/frameworks/core/image/image_loader.cpp @@ -21,7 +21,6 @@ #include "third_party/skia/include/codec/SkCodec.h" #include "third_party/skia/include/utils/SkBase64.h" -#include "base/image/image_source.h" #include "base/log/ace_trace.h" #include "base/network/download_manager.h" #include "base/resource/ace_res_config.h" @@ -35,7 +34,6 @@ #include "core/components_ng/image_provider/image_data.h" #include "core/image/flutter_image_cache.h" // TODO: add adapter layer and use FlutterImageCache there #include "core/image/image_cache.h" -#include "core/pipeline/pipeline_context.h" namespace OHOS::Ace { namespace { @@ -61,31 +59,6 @@ char* realpath(const char* path, char* resolved_path) } #endif -#ifdef PIXEL_MAP_SUPPORTED -// return orientation of pixmap for cache key -std::string GetThumbnailOrientation(const ImageSourceInfo& src) -{ - auto pipeline = PipelineContext::GetCurrentContext(); - CHECK_NULL_RETURN(pipeline, ""); - auto dataProvider = pipeline->GetDataProviderManager(); - CHECK_NULL_RETURN(dataProvider, ""); - - // get file fd - // concat to get file path ("datashare://media/xx") - auto path = src.GetSrc(); - auto pos = path.find("/thumbnail"); - path = path.substr(0, pos); - int32_t fd = dataProvider->GetDataProviderFile(path, "r"); - CHECK_NULL_RETURN(fd >= 0, ""); - - // check image orientation - auto imageSrc = ImageSource::Create(fd); - CHECK_NULL_RETURN(imageSrc, ""); - std::string orientation = imageSrc->GetProperty("Orientation"); - LOGD("image %{public}s has orientation = %{public}s", path.c_str(), orientation.c_str()); - return orientation; -} -#endif } // namespace std::string ImageLoader::RemovePathHead(const std::string& uri) @@ -555,34 +528,29 @@ sk_sp DecodedDataProviderImageLoader::LoadImageData( } RefPtr DecodedDataProviderImageLoader::LoadDecodedImageData( - const ImageSourceInfo& src, const WeakPtr& pipelineWk) + const ImageSourceInfo& imageSourceInfo, const WeakPtr& context) { #if !defined(PIXEL_MAP_SUPPORTED) return nullptr; #else - auto orientation = GetThumbnailOrientation(src); - - // query thumbnail from cache - auto pipeline = pipelineWk.Upgrade(); - CHECK_NULL_RETURN(pipeline, nullptr); - auto cache = pipeline->GetImageCache(); - CHECK_NULL_RETURN(cache, nullptr); - auto data = DynamicCast(cache->GetCacheImageData(src.GetKey() + orientation)); - if (data) { - LOGD("thumbnail cache found %{public}s, orientation = %{public}s", src.GetSrc().c_str(), orientation.c_str()); - return MakeRefPtr(data->pixmap_); + auto pipelineContext = context.Upgrade(); + if (!pipelineContext) { + LOGE("pipeline context is null when try start thumbnailLoadTask, uri: %{public}s", + imageSourceInfo.ToString().c_str()); + return nullptr; } - - auto dataProvider = pipeline->GetDataProviderManager(); - CHECK_NULL_RETURN(dataProvider, nullptr); - - void* pixmapMediaUniquePtr = dataProvider->GetDataProviderThumbnailResFromUri(src.GetSrc()); - auto pixmap = PixelMap::CreatePixelMapFromDataAbility(pixmapMediaUniquePtr); - CHECK_NULL_RETURN(pixmap, nullptr); - if (cache) { - cache->CacheImageData(src.GetKey() + orientation, MakeRefPtr(pixmap)); + auto dataProvider = pipelineContext->GetDataProviderManager(); + if (!dataProvider) { + LOGE("the data provider is null when try load thumbnail resource, uri: %{public}s", + imageSourceInfo.ToString().c_str()); + return nullptr; + } + void* pixmapMediaUniquePtr = dataProvider->GetDataProviderThumbnailResFromUri(imageSourceInfo.GetSrc()); + auto pixmapOhos = PixelMap::CreatePixelMapFromDataAbility(pixmapMediaUniquePtr); + if (!pixmapOhos) { + return nullptr; } - return MakeRefPtr(pixmap); + return MakeRefPtr(pixmapOhos); #endif } diff --git a/frameworks/core/image/image_source_info.cpp b/frameworks/core/image/image_source_info.cpp index eb260c2ef4d2f1fb0baa1d627a19be61ae1d2ef6..33751c872fd5e838697c9c00873b88466bd0d2fd 100644 --- a/frameworks/core/image/image_source_info.cpp +++ b/frameworks/core/image/image_source_info.cpp @@ -298,14 +298,6 @@ const RefPtr& ImageSourceInfo::GetPixmap() const return pixmap_; } -bool ImageSourceInfo::IsSupportCache() const -{ - if (IsPixmap()) { - return false; - } - return !src_.empty() || resourceId_ != InternalResource::ResourceId::NO_ID; -} - std::string ImageSourceInfo::GetKey() const { // only svg sets fillColor diff --git a/frameworks/core/image/image_source_info.h b/frameworks/core/image/image_source_info.h index 747b6a248fd8f618f58e164a980066e020e30686..1a90bd3897ff469b42491f24d80aad807a9220e8 100644 --- a/frameworks/core/image/image_source_info.h +++ b/frameworks/core/image/image_source_info.h @@ -72,7 +72,10 @@ public: const RefPtr& GetPixmap() const; std::string GetKey() const; - bool IsSupportCache() const; + bool IsSupportCache() const + { + return !src_.empty() || resourceId_ != InternalResource::ResourceId::NO_ID; + } private: SrcType ResolveSrcType() const;