• 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 "bitmap.h"
17 
18 #include <scene/ext/intf_ecs_context.h>
19 
20 #include <render/device/intf_gpu_resource_manager.h>
21 
22 #include "util.h"
23 
SCENE_BEGIN_NAMESPACE()24 SCENE_BEGIN_NAMESPACE()
25 
26 bool Bitmap::SetRenderHandle(
27     const IInternalScene::Ptr& scene, RENDER_NS::RenderHandleReference handle, CORE_NS::EntityReference ent)
28 {
29     if (handle.GetHandleType() != RENDER_NS::RenderHandleType::GPU_IMAGE) {
30         CORE_LOG_E("Bitmap requires GPU_IMAGE handle");
31         return false;
32     }
33     {
34         std::unique_lock lock { mutex_ };
35         if (handle_.GetHandle() == handle.GetHandle() && entity_ == ent) {
36             return true;
37         }
38     }
39 
40     RENDER_NS::GpuImageDesc desc;
41     scene
42         ->AddTask([&] {
43             if (!ent) {
44                 ent = HandleFromRenderResource(scene, handle);
45             }
46             auto& resources = scene->GetRenderContext().GetDevice().GetGpuResourceManager();
47             desc = resources.GetImageDescriptor(handle);
48         })
49         .Wait();
50 
51     if (!ent) {
52         return false;
53     }
54     {
55         std::unique_lock lock { mutex_ };
56         handle_ = handle;
57         entity_ = ent;
58     }
59     META_ACCESS_PROPERTY(Size)->SetValue({ desc.width, desc.height });
60     META_NS::Invoke<META_NS::IOnChanged>(EventOnResourceChanged(META_NS::MetadataQuery::EXISTING));
61     return true;
62 }
GetRenderHandle() const63 RENDER_NS::RenderHandleReference Bitmap::GetRenderHandle() const
64 {
65     std::shared_lock lock { mutex_ };
66     return handle_;
67 }
GetEntity() const68 CORE_NS::Entity Bitmap::GetEntity() const
69 {
70     std::shared_lock lock { mutex_ };
71     return entity_;
72 }
73 
74 SCENE_END_NAMESPACE()
75