1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROIDFW_ATTRIBUTERESOLUTION_H
18 #define ANDROIDFW_ATTRIBUTERESOLUTION_H
19 
20 #include "androidfw/AssetManager2.h"
21 #include "androidfw/ResourceTypes.h"
22 
23 namespace android {
24 
25 // Offsets into the outValues array populated by the methods below. outValues is a uint32_t
26 // array, but each logical element takes up 7 uint32_t-sized physical elements.
27 // Keep these in sync with android.content.res.TypedArray java class
28 enum {
29   STYLE_NUM_ENTRIES = 7,
30   STYLE_TYPE = 0,
31   STYLE_DATA = 1,
32   STYLE_ASSET_COOKIE = 2,
33   STYLE_RESOURCE_ID = 3,
34   STYLE_CHANGING_CONFIGURATIONS = 4,
35   STYLE_DENSITY = 5,
36   STYLE_SOURCE_RESOURCE_ID = 6
37 };
38 
39 // These are all variations of the same method. They each perform the exact same operation,
40 // but on various data sources. I *think* they are re-written to avoid an extra branch
41 // in the inner loop, but after one branch miss (some pointer != null), the branch predictor should
42 // predict the rest of the iterations' branch correctly.
43 // TODO(adamlesinski): Run performance tests against these methods and a new, single method
44 // that uses all the sources and branches to the right ones within the inner loop.
45 
46 // `out_values` must NOT be nullptr.
47 // `out_indices` may be nullptr.
48 base::expected<std::monostate, IOError> ResolveAttrs(Theme* theme, uint32_t def_style_attr,
49                                                      uint32_t def_style_resid, uint32_t* src_values,
50                                                      size_t src_values_length, uint32_t* attrs,
51                                                      size_t attrs_length, uint32_t* out_values,
52                                                      uint32_t* out_indices);
53 
54 // `out_values` must NOT be nullptr.
55 // `out_indices` is NOT optional and must NOT be nullptr.
56 base::expected<std::monostate, IOError> ApplyStyle(Theme* theme, ResXMLParser* xml_parser,
57                                                    uint32_t def_style_attr,
58                                                    uint32_t def_style_resid,
59                                                    const uint32_t* attrs, size_t attrs_length,
60                                                    uint32_t* out_values, uint32_t* out_indices);
61 
62 // `out_values` must NOT be nullptr.
63 // `out_indices` may be nullptr.
64 base::expected<std::monostate, IOError> RetrieveAttributes(AssetManager2* assetmanager,
65                                                            ResXMLParser* xml_parser,
66                                                            uint32_t* attrs,
67                                                            size_t attrs_length,
68                                                            uint32_t* out_values,
69                                                            uint32_t* out_indices);
70 
71 }  // namespace android
72 
73 #endif /* ANDROIDFW_ATTRIBUTERESOLUTION_H */
74