• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_bloom.h"
17 
18 #include <core/property/property_types.h>
19 #include <core/property_tools/property_api_impl.inl>
20 
21 #include "util/log.h"
22 
23 using namespace BASE_NS;
24 using namespace CORE_NS;
25 using namespace RENDER_NS;
26 
27 CORE_BEGIN_NAMESPACE()
28 DECLARE_PROPERTY_TYPE(BloomConfiguration);
29 DECLARE_PROPERTY_TYPE(BloomConfiguration::BloomQualityType);
30 DECLARE_PROPERTY_TYPE(BloomConfiguration::BloomType);
31 ENUM_TYPE_METADATA(BloomConfiguration::BloomQualityType, ENUM_VALUE(QUALITY_TYPE_LOW, "Low Quality"),
32     ENUM_VALUE(QUALITY_TYPE_NORMAL, "Normal Quality"), ENUM_VALUE(QUALITY_TYPE_HIGH, "High Quality"))
33 
34 ENUM_TYPE_METADATA(BloomConfiguration::BloomType, ENUM_VALUE(TYPE_NORMAL, "Normal"),
35     ENUM_VALUE(TYPE_HORIZONTAL, "Horizontal"), ENUM_VALUE(TYPE_VERTICAL, "Vertical"),
36     ENUM_VALUE(TYPE_BILATERAL, "Bilateral"))
37 
38 DATA_TYPE_METADATA(BloomConfiguration, MEMBER_PROPERTY(bloomType, "Type", 0),
39     MEMBER_PROPERTY(bloomQualityType, "Quality Type", 0), MEMBER_PROPERTY(thresholdHard, "Threshold Hard", 0),
40     MEMBER_PROPERTY(thresholdSoft, "Threshold Soft", 0), MEMBER_PROPERTY(amountCoefficient, "Amount Coefficient", 0),
41     MEMBER_PROPERTY(dirtMaskCoefficient, "Dirt Mask Coefficient", 0), MEMBER_PROPERTY(scatter, "Scatter", 0),
42     MEMBER_PROPERTY(scaleFactor, "Scale Factor", 0), MEMBER_PROPERTY(useCompute, "Use Compute", 0))
43 
44 DATA_TYPE_METADATA(RenderPostProcessBloomNode::EffectProperties, MEMBER_PROPERTY(enabled, "Enabled", 0),
45     MEMBER_PROPERTY(bloomConfiguration, "Bloom Configuration", 0))
46 CORE_END_NAMESPACE()
47 
48 RENDER_BEGIN_NAMESPACE()
49 namespace {
50 constexpr size_t PROPERTY_BYTE_SIZE { sizeof(RenderPostProcessBloomNode::EffectProperties) };
51 }
52 
RenderPostProcessBloom()53 RenderPostProcessBloom::RenderPostProcessBloom()
54     : properties_(
55           &propertiesData, array_view(PropertyType::DataType<RenderPostProcessBloomNode::EffectProperties>::properties))
56 {}
57 
GetProperties()58 CORE_NS::IPropertyHandle* RenderPostProcessBloom::GetProperties()
59 {
60     return properties_.GetData();
61 }
62 
SetData(BASE_NS::array_view<const uint8_t> data)63 void RenderPostProcessBloom::SetData(BASE_NS::array_view<const uint8_t> data)
64 {
65     if (data.size_bytes() == PROPERTY_BYTE_SIZE) {
66         BASE_NS::CloneData(&propertiesData, PROPERTY_BYTE_SIZE, data.data(), data.size_bytes());
67     }
68 #if (RENDER_VALIDATION_ENABLED == 1)
69     if (data.size_bytes() != PROPERTY_BYTE_SIZE) {
70         PLUGIN_LOG_ONCE_E("RenderPostProcessBloom_Size_Mismatch",
71             "RENDER_VALIDATION_ENABLED: RenderPostProcessBloom::SetData(), size missmatch (ignored)");
72     }
73 #endif
74 }
75 
GetData() const76 BASE_NS::array_view<const uint8_t> RenderPostProcessBloom::GetData() const
77 {
78     return { reinterpret_cast<const uint8_t*>(&propertiesData), PROPERTY_BYTE_SIZE };
79 }
80 RENDER_END_NAMESPACE()
81