1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "rs_upload_resource_thread.h"
17
18 #include "platform/common/rs_system_properties.h"
19 #include "rs_trace.h"
20 #include "platform/common/rs_log.h"
21 #include "src/core/SkImagePriv.h"
22 #include "src/image/SkImage_Base.h"
23
24 namespace OHOS::Rosen {
25
UploadTextureWithSkia(bool paraUpload,const sk_sp<SkImage> & imageUp,const std::shared_ptr<Media::PixelMap> & pixelMapUp,uint64_t uniqueId)26 void UploadTextureWithSkia(bool paraUpload, const sk_sp<SkImage>& imageUp,
27 const std::shared_ptr<Media::PixelMap>& pixelMapUp, uint64_t uniqueId)
28 {
29 auto& instance = RSUploadResourceThread::Instance();
30 if (paraUpload && instance.IsEnable() && imageUp &&
31 (instance.ImageSupportParallelUpload(imageUp->width(), imageUp->height()))) {
32 std::function<void()> uploadTexturetask =
33 [image = imageUp, pixelMap = pixelMapUp, count = instance.GetFrameCount()]() -> void {
34 auto& instance = RSUploadResourceThread::Instance();
35 auto grContext = instance.GetShareGrContext().get();
36 if (grContext && image && pixelMap && instance.TaskIsValid(count)) {
37 RS_TRACE_NAME_FMT("parallel upload texture w%d h%d", image->width(), image->height());
38 SkImage_pinAsTexture(image.get(), grContext);
39 #ifdef RS_ENABLE_VK
40 if (OHOS::Rosen::RSSystemProperties::GetGpuApiType() == OHOS::Rosen::GpuApiType::VULKAN ||
41 OHOS::Rosen::RSSystemProperties::GetGpuApiType() == OHOS::Rosen::GpuApiType::DDGR) {
42 RSUploadResourceThread::Instance().GetShareGrContext()->submit();
43 }
44 #endif // RS_ENABLE_VK
45 }
46 };
47 RSUploadResourceThread::Instance().PostTask(uploadTexturetask, std::to_string(uniqueId));
48 }
49 }
50 }