-
Notifications
You must be signed in to change notification settings - Fork 10
/
Android.go
179 lines (146 loc) · 5.35 KB
/
Android.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package librga
import (
"android/soong/android"
"android/soong/cc"
"fmt"
"strings"
"strconv"
"unsafe"
)
func init() {
fmt.Println("librga want to conditional Compile")
android.RegisterModuleType("cc_librga", DefaultsFactory)
}
func DefaultsFactory() (android.Module) {
module := cc.DefaultsFactory()
android.AddLoadHook(module, Defaults)
return module
}
func Defaults(ctx android.LoadHookContext) {
sdkVersion := ctx.AConfig().PlatformSdkVersion()
sdkVersionInt, err := strconv.Atoi(*(*string)(unsafe.Pointer(&sdkVersion)))
if err != nil {
fmt.Printf("librga cannot get ApiLevel, %q could not be parsed as an integer\n", sdkVersion)
panic(1)
}
var gralloc_version string
var platform string
gralloc_version = ctx.AConfig().Getenv("TARGET_RK_GRALLOC_VERSION")
if (gralloc_version == "") {
gralloc_version = ctx.Config().VendorConfig("graphic_rockchip").String("gralloc_version")
}
platform = ctx.AConfig().Getenv("TARGET_BOARD_PLATFORM")
if (platform == "") {
platform = ctx.Config().VendorConfig("core_rockchip").String("platform")
}
//fmt.Printf("librga, api %q, gralloc: %q, platform: %q\n", sdkVersion, gralloc_version, platform)
if (sdkVersionInt >= 29 ) {
type props struct {
Srcs []string
Cflags []string
Shared_libs []string
Include_dirs []string
Header_libs []string
Export_header_lib_headers []string
Double_loadable *bool
}
p := &props{}
p.Srcs = getSrcs(ctx, sdkVersionInt, gralloc_version)
p.Cflags = getCflags(ctx, sdkVersionInt, platform, gralloc_version)
p.Shared_libs = getSharedLibs(ctx, sdkVersionInt, gralloc_version)
p.Include_dirs = getIncludeDirs(ctx, sdkVersionInt, gralloc_version)
p.Header_libs = getHeaders(ctx, sdkVersionInt)
p.Export_header_lib_headers = getExportHeaders(ctx, sdkVersionInt)
double_loadable := true
p.Double_loadable = &double_loadable
ctx.AppendProperties(p)
} else {
type props struct {
Srcs []string
Cflags []string
Shared_libs []string
Include_dirs []string
}
p := &props{}
p.Srcs = getSrcs(ctx, sdkVersionInt, gralloc_version)
p.Cflags = getCflags(ctx, sdkVersionInt, platform, gralloc_version)
p.Shared_libs = getSharedLibs(ctx, sdkVersionInt, gralloc_version)
p.Include_dirs = getIncludeDirs(ctx, sdkVersionInt, gralloc_version)
ctx.AppendProperties(p)
}
}
//条件编译主要修改函数
func getSrcs(ctx android.BaseContext, sdkVersion int, gralloc_version string) ([]string) {
var src []string
if (strings.EqualFold(gralloc_version, "4") ) {
if (sdkVersion >= 30 ) {
src = append(src, "core/platform_gralloc4.cpp")
}
}
return src
}
func getCflags(ctx android.BaseContext, sdkVersion int, platform string, gralloc_version string) ([]string) {
var cppflags []string
//该打印输出为: TARGET_PRODUCT:rk3328 fmt.Println("TARGET_PRODUCT:",ctx.AConfig().Getenv("TARGET_PRODUCT")) //通过 strings.EqualFold 比较字符串,可参考go语言字符串对比
if (strings.EqualFold(platform, "rk3368") ) {
//添加 DEBUG 宏定义
cppflags = append(cppflags,"-DRK3368=1")
}
if (strings.EqualFold(gralloc_version, "4") ) {
if (sdkVersion >= 30 ) {
cppflags = append(cppflags,"-DUSE_GRALLOC_4")
}
}
//Android 12开始使用libhardware_rockchip存放RK私有定义
if (sdkVersion >= 31 ) {
cppflags = append(cppflags,"-DUSE_HARDWARE_ROCKCHIP")
}
//将需要区分的环境变量在此区域添加 //....
return cppflags
}
func getSharedLibs(ctx android.BaseContext, sdkVersion int, gralloc_version string) ([]string) {
var libs []string
if (strings.EqualFold(gralloc_version, "4") ) {
if (sdkVersion >= 30 ) {
libs = append(libs, "libgralloctypes")
libs = append(libs, "libhidlbase")
libs = append(libs, "android.hardware.graphics.mapper@4.0")
}
}
if (sdkVersion < 29 ) {
libs = append(libs, "libdrm")
}
return libs
}
func getIncludeDirs(ctx android.BaseContext, sdkVersion int, gralloc_version string) ([]string) {
var dirs []string
if (strings.EqualFold(gralloc_version, "4") ) {
if (sdkVersion >= 30 ) {
dirs = append(dirs, "hardware/rockchip/libgralloc/bifrost")
dirs = append(dirs, "hardware/rockchip/libgralloc/bifrost/src")
}
}
// Add libion for RK3368
if (sdkVersion >= 29) {
if (sdkVersion >= 30) {
dirs = append(dirs, "system/memory/libion/original-kernel-headers")
} else {
dirs = append(dirs, "system/core/libion/original-kernel-headers")
}
}
return dirs
}
func getHeaders(ctx android.BaseContext, sdkVersion int) ([]string) {
var headers []string
if (sdkVersion >= 31 ) {
headers = append(headers, "libhardware_rockchip_headers")
}
return headers
}
func getExportHeaders(ctx android.BaseContext, sdkVersion int) ([]string) {
var headers []string
if (sdkVersion >= 31 ) {
headers = append(headers, "libhardware_rockchip_headers")
}
return headers
}