• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "image.h"
17 
18 #include <mutex>
19 
20 #include <render/device/intf_gpu_resource_manager.h>
21 
SCENE_BEGIN_NAMESPACE()22 SCENE_BEGIN_NAMESPACE()
23 
24 bool Image::SetRenderHandle(RENDER_NS::RenderHandleReference handle)
25 {
26     if (handle.GetHandleType() != RENDER_NS::RenderHandleType::GPU_IMAGE) {
27         CORE_LOG_E("Image requires GPU_IMAGE handle");
28         return false;
29     }
30     IRenderContext::Ptr context;
31     {
32         std::unique_lock lock { mutex_ };
33         if (handle_.GetHandle() == handle.GetHandle()) {
34             return true;
35         }
36         handle_ = handle;
37         context = context_.lock();
38         if (!context) {
39             return false;
40         }
41     }
42 
43     RENDER_NS::GpuImageDesc desc;
44     context
45         ->AddTask([&] {
46             auto& resources = context->GetRenderer()->GetDevice().GetGpuResourceManager();
47             desc = resources.GetImageDescriptor(handle);
48         })
49         .Wait();
50 
51     // todo: notify in right queue
52     Size()->SetValue({ desc.width, desc.height });
53     if (auto ev = EventOnResourceChanged(META_NS::MetadataQuery::EXISTING)) {
54         META_NS::Invoke<META_NS::IOnChanged>(ev);
55     }
56     return true;
57 }
58 
59 SCENE_END_NAMESPACE()
60