blob: 1ae327120796dac482001b644e9561eda89fa98e [file] [log] [blame]
Adam Lesinski355f2852016-02-13 20:26:45 -08001/*
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 Lesinskice5e56e2016-10-21 17:56:45 -070020#include <set>
21#include <vector>
22#include "android-base/macros.h"
23
Adam Lesinski355f2852016-02-13 20:26:45 -080024#include "ConfigDescription.h"
25#include "ResourceTable.h"
26#include "filter/ConfigFilter.h"
27#include "process/IResourceTableConsumer.h"
28
Adam Lesinski355f2852016-02-13 20:26:45 -080029namespace aapt {
30
31struct SplitConstraints {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070032 std::set<ConfigDescription> configs;
Adam Lesinski355f2852016-02-13 20:26:45 -080033};
34
35struct TableSplitterOptions {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070036 /**
37 * The preferred density to keep in the table, stripping out all others.
38 */
Adam Lesinskice5e56e2016-10-21 17:56:45 -070039 Maybe<uint16_t> preferred_density;
Adam Lesinski355f2852016-02-13 20:26:45 -080040
Adam Lesinskicacb28f2016-10-19 12:18:14 -070041 /**
42 * Configuration filter that determines which resource configuration values
43 * end up in
44 * the final table.
45 */
Adam Lesinskice5e56e2016-10-21 17:56:45 -070046 IConfigFilter* config_filter = nullptr;
Adam Lesinski355f2852016-02-13 20:26:45 -080047};
48
49class TableSplitter {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070050 public:
51 TableSplitter(const std::vector<SplitConstraints>& splits,
52 const TableSplitterOptions& options)
Adam Lesinskice5e56e2016-10-21 17:56:45 -070053 : 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 Lesinski355f2852016-02-13 20:26:45 -080056 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -070057 }
Adam Lesinski355f2852016-02-13 20:26:45 -080058
Adam Lesinskice5e56e2016-10-21 17:56:45 -070059 bool VerifySplitConstraints(IAaptContext* context);
Adam Lesinski355f2852016-02-13 20:26:45 -080060
Adam Lesinskice5e56e2016-10-21 17:56:45 -070061 void SplitTable(ResourceTable* original_table);
Adam Lesinski355f2852016-02-13 20:26:45 -080062
Adam Lesinskice5e56e2016-10-21 17:56:45 -070063 std::vector<std::unique_ptr<ResourceTable>>& splits() { return splits_; }
Adam Lesinski355f2852016-02-13 20:26:45 -080064
Adam Lesinskicacb28f2016-10-19 12:18:14 -070065 private:
Adam Lesinskice5e56e2016-10-21 17:56:45 -070066 std::vector<SplitConstraints> split_constraints_;
67 std::vector<std::unique_ptr<ResourceTable>> splits_;
68 TableSplitterOptions options_;
Adam Lesinski355f2852016-02-13 20:26:45 -080069
Adam Lesinskicacb28f2016-10-19 12:18:14 -070070 DISALLOW_COPY_AND_ASSIGN(TableSplitter);
Adam Lesinski355f2852016-02-13 20:26:45 -080071};
Adam Lesinski355f2852016-02-13 20:26:45 -080072}
73
74#endif /* AAPT_SPLIT_TABLESPLITTER_H */