blob: cb1395f3132b67e3060d72ae937dcfce04439094 [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"
Mårten Kongstad24c9aa62018-06-20 08:46:41 +020023#include "androidfw/ConfigDescription.h"
Adam Lesinskice5e56e2016-10-21 17:56:45 -070024
Adam Lesinski355f2852016-02-13 20:26:45 -080025#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 {
Mårten Kongstad24c9aa62018-06-20 08:46:41 +020032 std::set<android::ConfigDescription> configs;
Todd Kennedy9fbdf892018-08-28 16:31:15 -070033 std::string name;
Adam Lesinski355f2852016-02-13 20:26:45 -080034};
35
36struct TableSplitterOptions {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070037 /**
Pierre Lecesne672384b2017-02-06 10:29:02 +000038 * The preferred densities to keep in the table, stripping out all others.
39 * If empty, no stripping is done.
Adam Lesinskicacb28f2016-10-19 12:18:14 -070040 */
Pierre Lecesne672384b2017-02-06 10:29:02 +000041 std::vector<uint16_t> preferred_densities;
Adam Lesinski355f2852016-02-13 20:26:45 -080042
Adam Lesinskicacb28f2016-10-19 12:18:14 -070043 /**
44 * Configuration filter that determines which resource configuration values
Pierre Lecesne672384b2017-02-06 10:29:02 +000045 * end up in the final table.
Adam Lesinskicacb28f2016-10-19 12:18:14 -070046 */
Adam Lesinskice5e56e2016-10-21 17:56:45 -070047 IConfigFilter* config_filter = nullptr;
Adam Lesinski355f2852016-02-13 20:26:45 -080048};
49
50class TableSplitter {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070051 public:
52 TableSplitter(const std::vector<SplitConstraints>& splits,
53 const TableSplitterOptions& options)
Adam Lesinskice5e56e2016-10-21 17:56:45 -070054 : split_constraints_(splits), options_(options) {
55 for (size_t i = 0; i < split_constraints_.size(); i++) {
56 splits_.push_back(util::make_unique<ResourceTable>());
Adam Lesinski355f2852016-02-13 20:26:45 -080057 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -070058 }
Adam Lesinski355f2852016-02-13 20:26:45 -080059
Adam Lesinskice5e56e2016-10-21 17:56:45 -070060 bool VerifySplitConstraints(IAaptContext* context);
Adam Lesinski355f2852016-02-13 20:26:45 -080061
Adam Lesinskice5e56e2016-10-21 17:56:45 -070062 void SplitTable(ResourceTable* original_table);
Adam Lesinski355f2852016-02-13 20:26:45 -080063
Adam Lesinskice5e56e2016-10-21 17:56:45 -070064 std::vector<std::unique_ptr<ResourceTable>>& splits() { return splits_; }
Adam Lesinski355f2852016-02-13 20:26:45 -080065
Adam Lesinskicacb28f2016-10-19 12:18:14 -070066 private:
Adam Lesinskice5e56e2016-10-21 17:56:45 -070067 std::vector<SplitConstraints> split_constraints_;
68 std::vector<std::unique_ptr<ResourceTable>> splits_;
69 TableSplitterOptions options_;
Adam Lesinski355f2852016-02-13 20:26:45 -080070
Adam Lesinskicacb28f2016-10-19 12:18:14 -070071 DISALLOW_COPY_AND_ASSIGN(TableSplitter);
Adam Lesinski355f2852016-02-13 20:26:45 -080072};
Adam Lesinski355f2852016-02-13 20:26:45 -080073}
74
75#endif /* AAPT_SPLIT_TABLESPLITTER_H */