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