aboutsummaryrefslogtreecommitdiff
path: root/encoded_view.cc
diff options
context:
space:
mode:
authorSamuel Huang <huangs@chromium.org>2018-03-13 18:19:34 +0000
committerEdward Lesmes <ehmaldonado@google.com>2021-07-23 21:50:59 +0000
commit06f1ae9aaca969ee95ef840f22b6b461c304542d (patch)
treef1e5c6624e70628e81fbf38d6cd14b974abe5d93 /encoded_view.cc
downloadzucchini-06f1ae9aaca969ee95ef840f22b6b461c304542d.tar.gz
[Zucchini] Move Zucchini from /chrome/installer/ to /components/.
(Use "git log --follow" to see older revisions of files). /components/ is the most logical place to put Zucchini, which only depends on /base and /testing/gtest. This move also enables Zucchini to be used by the Component Updater. Details: - Move all files; run the following to change deps and guards: sed 's/chrome\/installer/components/' *.cc *.h -i sed 's/CHROME_INSTALLER/COMPONENTS/' *.cc *.h -i - Sorting works out pretty well! - Change all 'chrome/installer/zucchini' to 'components/zucchini' throughout other parts of the repo; sort if necessary. - Fix 6 'git cl lint' errors. - Change 1 Bind() usage to BindRepeated(). - Update OWNER. Bug: 729154 Change-Id: I50c5a7d411ea85f707b5994ab319dfb2a1acccf7 Reviewed-on: https://chromium-review.googlesource.com/954923 Reviewed-by: Greg Thompson <grt@chromium.org> Reviewed-by: Jochen Eisinger <jochen@chromium.org> Reviewed-by: Samuel Huang <huangs@chromium.org> Commit-Queue: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#542857} NOKEYCHECK=True GitOrigin-RevId: 577ef6c435e8d43be6e3e60ccbcbd1881780f4ec
Diffstat (limited to 'encoded_view.cc')
-rw-r--r--encoded_view.cc77
1 files changed, 77 insertions, 0 deletions
diff --git a/encoded_view.cc b/encoded_view.cc
new file mode 100644
index 0000000..5b55b51
--- /dev/null
+++ b/encoded_view.cc
@@ -0,0 +1,77 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/zucchini/encoded_view.h"
+
+#include <algorithm>
+#include <utility>
+
+#include "base/logging.h"
+
+namespace zucchini {
+
+EncodedView::EncodedView(const ImageIndex& image_index)
+ : image_index_(image_index), pool_infos_(image_index.PoolCount()) {}
+EncodedView::~EncodedView() = default;
+
+EncodedView::value_type EncodedView::Projection(offset_t location) const {
+ DCHECK_LT(location, image_index_.size());
+
+ // Find out what lies at |location|.
+ TypeTag type = image_index_.LookupType(location);
+
+ // |location| points into raw data.
+ if (type == kNoTypeTag) {
+ // The projection is the identity function on raw content.
+ return image_index_.GetRawValue(location);
+ }
+
+ // |location| points into a Reference.
+ const ReferenceSet& ref_set = image_index_.refs(type);
+ IndirectReference ref = ref_set.at(location);
+ DCHECK_GE(location, ref.location);
+ DCHECK_LT(location, ref.location + ref_set.width());
+
+ // |location| is not the first byte of the reference.
+ if (location != ref.location) {
+ // Trailing bytes of a reference are all projected to the same value.
+ return kReferencePaddingProjection;
+ }
+
+ PoolTag pool_tag = ref_set.pool_tag();
+
+ // Targets with an associated Label will use its Label index in projection.
+ DCHECK_EQ(image_index_.pool(pool_tag).size(),
+ pool_infos_[pool_tag.value()].labels.size());
+ uint32_t label = pool_infos_[pool_tag.value()].labels[ref.target_key];
+
+ // Projection is done on (|target|, |type|), shifted by
+ // kBaseReferenceProjection to avoid collisions with raw content.
+ value_type projection = label;
+ projection *= image_index_.TypeCount();
+ projection += type.value();
+ return projection + kBaseReferenceProjection;
+}
+
+size_t EncodedView::Cardinality() const {
+ size_t max_width = 0;
+ for (const auto& pool_info : pool_infos_)
+ max_width = std::max(max_width, pool_info.bound);
+ return max_width * image_index_.TypeCount() + kBaseReferenceProjection;
+}
+
+void EncodedView::SetLabels(PoolTag pool,
+ std::vector<uint32_t>&& labels,
+ size_t bound) {
+ DCHECK_EQ(labels.size(), image_index_.pool(pool).size());
+ DCHECK(labels.empty() || *max_element(labels.begin(), labels.end()) < bound);
+ pool_infos_[pool.value()].labels = std::move(labels);
+ pool_infos_[pool.value()].bound = bound;
+}
+
+EncodedView::PoolInfo::PoolInfo() = default;
+EncodedView::PoolInfo::PoolInfo(PoolInfo&&) = default;
+EncodedView::PoolInfo::~PoolInfo() = default;
+
+} // namespace zucchini