1 /*
2  * Copyright (c) 2021-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 #ifndef RENDER_SERVICE_CLIENT_CORE_COMMON_RS_MACROS_H
16 #define RENDER_SERVICE_CLIENT_CORE_COMMON_RS_MACROS_H
17 
18 /** about export template (most at _WIN32 platform)
19  *  Sometimes other module maybe use instantiated template classes or instantiate their own template class.
20  *  for example: arkui will use RSRenderAnimatableProperty<float> and instantiate the template
21  *      with type "NG::ColorBlend", so we need export instantiated template classes but cannot export
22  *      template itself. Because if you RSB_EXPORT the template, arkui will think the symbol
23  *      RSRenderAnimatableProperty<NG::ColorBlend> is importing from other module,
24  *      linker then raise a link problem.
25  *
26  *  So we should use RSB_EXPORT_TMP and use extern template & template to tell arkui that there are many
27  *      instantiated template classes, you don't need instantiate again.
28  *
29  *  correct way:
30  *      base view:
31  *          EXPORT RSRenderAnimatableProperty<T>
32  *          extern template class RSRenderAnimatableProperty<float>;
33  *          (in cpp) template class RSRenderAnimatableProperty<float>;
34  *      arkui view:
35  *                 RSRenderAnimatableProperty<T>
36  *          extern template class RSRenderAnimatableProperty<float>;
37  */
38 
39 #ifdef _WIN32
40 #define RS_EXPORT __attribute__((dllexport))
41 #define RS_IMPORT __attribute__((dllimport))
42 #else
43 #define RS_EXPORT __attribute__((visibility("default")))
44 #define RS_IMPORT __attribute__((visibility("default")))
45 #endif
46 
47 #ifdef MODULE_RSB
48 #define RSB_EXPORT      RS_EXPORT
49 #define RSB_EXPORT_TMP  RS_EXPORT
50 #else
51 #define RSB_EXPORT      RS_IMPORT
52 #define RSB_EXPORT_TMP
53 #endif
54 
55 #ifdef MODULE_RSC
56 #define RSC_EXPORT      RS_EXPORT
57 #define RSC_EXPORT_TMP  RS_EXPORT
58 #else
59 #define RSC_EXPORT      RS_IMPORT
60 #define RSC_EXPORT_TMP
61 #endif
62 
63 #endif // RENDER_SERVICE_CLIENT_CORE_COMMON_RS_MACROS_H
64