Adam Lesinski | 355f285 | 2016-02-13 20:26:45 -0800 | [diff] [blame] | 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 AAPT_SPLIT_TABLESPLITTER_H |
| 18 | #define AAPT_SPLIT_TABLESPLITTER_H |
| 19 | |
| 20 | #include "ConfigDescription.h" |
| 21 | #include "ResourceTable.h" |
| 22 | #include "filter/ConfigFilter.h" |
| 23 | #include "process/IResourceTableConsumer.h" |
| 24 | |
| 25 | #include <android-base/macros.h> |
| 26 | #include <set> |
| 27 | #include <vector> |
| 28 | |
| 29 | namespace aapt { |
| 30 | |
| 31 | struct SplitConstraints { |
| 32 | std::set<ConfigDescription> configs; |
| 33 | }; |
| 34 | |
| 35 | struct TableSplitterOptions { |
| 36 | /** |
| 37 | * The preferred density to keep in the table, stripping out all others. |
| 38 | */ |
| 39 | Maybe<uint16_t> preferredDensity; |
| 40 | |
| 41 | /** |
| 42 | * Configuration filter that determines which resource configuration values end up in |
| 43 | * the final table. |
| 44 | */ |
| 45 | IConfigFilter* configFilter = nullptr; |
| 46 | }; |
| 47 | |
| 48 | class TableSplitter { |
| 49 | public: |
| 50 | TableSplitter(const std::vector<SplitConstraints>& splits, |
| 51 | const TableSplitterOptions& options) : |
| 52 | mSplitConstraints(splits), mPreferredDensity(options.preferredDensity), |
| 53 | mConfigFilter(options.configFilter) { |
| 54 | for (size_t i = 0; i < mSplitConstraints.size(); i++) { |
| 55 | mSplits.push_back(util::make_unique<ResourceTable>()); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | bool verifySplitConstraints(IAaptContext* context); |
| 60 | |
| 61 | void splitTable(ResourceTable* originalTable); |
| 62 | |
Adam Lesinski | 36c73a5 | 2016-08-11 13:39:24 -0700 | [diff] [blame^] | 63 | std::vector<std::unique_ptr<ResourceTable>>& getSplits() { |
Adam Lesinski | 355f285 | 2016-02-13 20:26:45 -0800 | [diff] [blame] | 64 | return mSplits; |
| 65 | } |
| 66 | |
| 67 | private: |
| 68 | std::vector<SplitConstraints> mSplitConstraints; |
| 69 | std::vector<std::unique_ptr<ResourceTable>> mSplits; |
| 70 | Maybe<uint16_t> mPreferredDensity; |
| 71 | IConfigFilter* mConfigFilter; |
| 72 | |
| 73 | DISALLOW_COPY_AND_ASSIGN(TableSplitter); |
| 74 | }; |
| 75 | |
| 76 | } |
| 77 | |
| 78 | #endif /* AAPT_SPLIT_TABLESPLITTER_H */ |