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
22 namespace OHOS::Rosen {
23
UploadTextureWithDrawing(bool paraUpload,const std::shared_ptr<Drawing::Image> & imageUp,const std::shared_ptr<Media::PixelMap> & pixelMapUp,uint64_t uniqueId)24 void UploadTextureWithDrawing(bool paraUpload, const std::shared_ptr<Drawing::Image>& imageUp,
25 const std::shared_ptr<Media::PixelMap>& pixelMapUp, uint64_t uniqueId)
26 {
27 auto& instance = RSUploadResourceThread::Instance();
28 if (paraUpload && instance.IsEnable() && imageUp &&
29 (instance.ImageSupportParallelUpload(imageUp->GetWidth(), imageUp->GetHeight()))) {
30 std::function<void()> uploadTexturetask =
31 [image = imageUp, pixelMap = pixelMapUp, count = instance.GetFrameCount()]() -> void {
32 auto& instance = RSUploadResourceThread::Instance();
33 auto grContext = instance.GetShareGrContext();
34 if (grContext && image && pixelMap && instance.TaskIsValid(count)) {
35 RS_TRACE_NAME_FMT("parallel upload texture w%d h%d", image->GetWidth(), image->GetHeight());
36 #ifdef RS_ENABLE_GPU
37 // Need To Pin Image here.
38 #endif
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 }