1 /*
2 * Copyright (c) 2022 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 "render_post_process_upscale.h"
17
18 #include <core/property_tools/property_api_impl.inl>
19
20 #include "util/log.h"
21
22 using namespace BASE_NS;
23 using namespace CORE_NS;
24 using namespace RENDER_NS;
25
26 CORE_BEGIN_NAMESPACE()
27 DATA_TYPE_METADATA(RenderPostProcessUpscaleNode::EffectProperties, MEMBER_PROPERTY(enabled, "Enabled", 0),
28 MEMBER_PROPERTY(ratio, "Upscaling ratio", 1.5f))
29 CORE_END_NAMESPACE()
30
31 RENDER_BEGIN_NAMESPACE()
32
33 namespace {
34 constexpr size_t PROPERTY_BYTE_SIZE { sizeof(RenderPostProcessUpscaleNode::EffectProperties) };
35 }
36
RenderPostProcessUpscale()37 RenderPostProcessUpscale::RenderPostProcessUpscale()
38 : properties_(&propertiesData,
39 array_view(PropertyType::DataType<RenderPostProcessUpscaleNode::EffectProperties>::properties))
40 {}
41
GetProperties()42 CORE_NS::IPropertyHandle* RenderPostProcessUpscale::GetProperties()
43 {
44 return properties_.GetData();
45 }
46
SetData(BASE_NS::array_view<const uint8_t> data)47 void RenderPostProcessUpscale::SetData(BASE_NS::array_view<const uint8_t> data)
48 {
49 if (data.size_bytes() == PROPERTY_BYTE_SIZE) {
50 BASE_NS::CloneData(&propertiesData, PROPERTY_BYTE_SIZE, data.data(), data.size_bytes());
51 }
52 #if (RENDER_VALIDATION_ENABLED == 1)
53 if (data.size_bytes() != PROPERTY_BYTE_SIZE) {
54 PLUGIN_LOG_ONCE_E("RenderPostProcessUpscale_Size_Mismatch",
55 "RENDER_VALIDATION_ENABLED: RenderPostProcessUpscale::SetData(), size missmatch (ignored)");
56 }
57 #endif
58 }
59
GetData() const60 array_view<const uint8_t> RenderPostProcessUpscale::GetData() const
61 {
62 return { reinterpret_cast<const uint8_t*>(&propertiesData), PROPERTY_BYTE_SIZE };
63 }
64 RENDER_END_NAMESPACE()
65