1*a03ca8b9SKrzysztof Kosiński // Copyright 2017 The Chromium Authors. All rights reserved. 2*a03ca8b9SKrzysztof Kosiński // Use of this source code is governed by a BSD-style license that can be 3*a03ca8b9SKrzysztof Kosiński // found in the LICENSE file. 4*a03ca8b9SKrzysztof Kosiński 5*a03ca8b9SKrzysztof Kosiński #ifndef COMPONENTS_ZUCCHINI_ZUCCHINI_GEN_H_ 6*a03ca8b9SKrzysztof Kosiński #define COMPONENTS_ZUCCHINI_ZUCCHINI_GEN_H_ 7*a03ca8b9SKrzysztof Kosiński 8*a03ca8b9SKrzysztof Kosiński #include <vector> 9*a03ca8b9SKrzysztof Kosiński 10*a03ca8b9SKrzysztof Kosiński #include "components/zucchini/buffer_view.h" 11*a03ca8b9SKrzysztof Kosiński #include "components/zucchini/image_utils.h" 12*a03ca8b9SKrzysztof Kosiński #include "components/zucchini/zucchini.h" 13*a03ca8b9SKrzysztof Kosiński 14*a03ca8b9SKrzysztof Kosiński namespace zucchini { 15*a03ca8b9SKrzysztof Kosiński 16*a03ca8b9SKrzysztof Kosiński class EquivalenceMap; 17*a03ca8b9SKrzysztof Kosiński class OffsetMapper; 18*a03ca8b9SKrzysztof Kosiński class ImageIndex; 19*a03ca8b9SKrzysztof Kosiński class PatchElementWriter; 20*a03ca8b9SKrzysztof Kosiński class ReferenceBytesMixer; 21*a03ca8b9SKrzysztof Kosiński class ReferenceDeltaSink; 22*a03ca8b9SKrzysztof Kosiński class ReferenceSet; 23*a03ca8b9SKrzysztof Kosiński class TargetPool; 24*a03ca8b9SKrzysztof Kosiński 25*a03ca8b9SKrzysztof Kosiński // Extract all targets in |new_targets| with no associated target in 26*a03ca8b9SKrzysztof Kosiński // |projected_old_targets| and returns these targets in a new vector. 27*a03ca8b9SKrzysztof Kosiński std::vector<offset_t> FindExtraTargets(const TargetPool& projected_old_targets, 28*a03ca8b9SKrzysztof Kosiński const TargetPool& new_targets); 29*a03ca8b9SKrzysztof Kosiński 30*a03ca8b9SKrzysztof Kosiński // Creates an EquivalenceMap from "old" image to "new" image and returns the 31*a03ca8b9SKrzysztof Kosiński // result. The params |*_image_index|: 32*a03ca8b9SKrzysztof Kosiński // - Provide "old" and "new" raw image data and references. 33*a03ca8b9SKrzysztof Kosiński // - Mediate Label matching, which links references between "old" and "new", and 34*a03ca8b9SKrzysztof Kosiński // guides EquivalenceMap construction. 35*a03ca8b9SKrzysztof Kosiński EquivalenceMap CreateEquivalenceMap(const ImageIndex& old_image_index, 36*a03ca8b9SKrzysztof Kosiński const ImageIndex& new_image_index); 37*a03ca8b9SKrzysztof Kosiński 38*a03ca8b9SKrzysztof Kosiński // Writes equivalences from |equivalence_map|, and extra data from |new_image| 39*a03ca8b9SKrzysztof Kosiński // found in gaps between equivalences to |patch_writer|. 40*a03ca8b9SKrzysztof Kosiński bool GenerateEquivalencesAndExtraData(ConstBufferView new_image, 41*a03ca8b9SKrzysztof Kosiński const EquivalenceMap& equivalence_map, 42*a03ca8b9SKrzysztof Kosiński PatchElementWriter* patch_writer); 43*a03ca8b9SKrzysztof Kosiński 44*a03ca8b9SKrzysztof Kosiński // Writes raw delta between |old_image| and |new_image| matched by 45*a03ca8b9SKrzysztof Kosiński // |equivalence_map| to |patch_writer|, using |new_image_index| to ignore 46*a03ca8b9SKrzysztof Kosiński // reference bytes. 47*a03ca8b9SKrzysztof Kosiński bool GenerateRawDelta(ConstBufferView old_image, 48*a03ca8b9SKrzysztof Kosiński ConstBufferView new_image, 49*a03ca8b9SKrzysztof Kosiński const EquivalenceMap& equivalence_map, 50*a03ca8b9SKrzysztof Kosiński const ImageIndex& new_image_index, 51*a03ca8b9SKrzysztof Kosiński ReferenceBytesMixer* reference_bytes_mixer, 52*a03ca8b9SKrzysztof Kosiński PatchElementWriter* patch_writer); 53*a03ca8b9SKrzysztof Kosiński 54*a03ca8b9SKrzysztof Kosiński // Writes reference delta between references from |old_refs| and from 55*a03ca8b9SKrzysztof Kosiński // |new_refs| to |patch_writer|. |projected_target_pool| contains projected 56*a03ca8b9SKrzysztof Kosiński // targets from old to new image for references pool associated with |new_refs|. 57*a03ca8b9SKrzysztof Kosiński bool GenerateReferencesDelta(const ReferenceSet& src_refs, 58*a03ca8b9SKrzysztof Kosiński const ReferenceSet& dst_refs, 59*a03ca8b9SKrzysztof Kosiński const TargetPool& projected_target_pool, 60*a03ca8b9SKrzysztof Kosiński const OffsetMapper& offset_mapper, 61*a03ca8b9SKrzysztof Kosiński const EquivalenceMap& equivalence_map, 62*a03ca8b9SKrzysztof Kosiński ReferenceDeltaSink* reference_delta_sink); 63*a03ca8b9SKrzysztof Kosiński 64*a03ca8b9SKrzysztof Kosiński // Writes |extra_targets| associated with |pool_tag| to |patch_writer|. 65*a03ca8b9SKrzysztof Kosiński bool GenerateExtraTargets(const std::vector<offset_t>& extra_targets, 66*a03ca8b9SKrzysztof Kosiński PoolTag pool_tag, 67*a03ca8b9SKrzysztof Kosiński PatchElementWriter* patch_writer); 68*a03ca8b9SKrzysztof Kosiński 69*a03ca8b9SKrzysztof Kosiński // Generates raw patch element data between |old_image| and |new_image|, and 70*a03ca8b9SKrzysztof Kosiński // writes them to |patch_writer|. |old_sa| is the suffix array for |old_image|. 71*a03ca8b9SKrzysztof Kosiński bool GenerateRawElement(const std::vector<offset_t>& old_sa, 72*a03ca8b9SKrzysztof Kosiński ConstBufferView old_image, 73*a03ca8b9SKrzysztof Kosiński ConstBufferView new_image, 74*a03ca8b9SKrzysztof Kosiński PatchElementWriter* patch_writer); 75*a03ca8b9SKrzysztof Kosiński 76*a03ca8b9SKrzysztof Kosiński // Generates patch element of type |exe_type| from |old_image| to |new_image|, 77*a03ca8b9SKrzysztof Kosiński // and writes it to |patch_writer|. 78*a03ca8b9SKrzysztof Kosiński bool GenerateExecutableElement(ExecutableType exe_type, 79*a03ca8b9SKrzysztof Kosiński ConstBufferView old_image, 80*a03ca8b9SKrzysztof Kosiński ConstBufferView new_image, 81*a03ca8b9SKrzysztof Kosiński PatchElementWriter* patch_writer); 82*a03ca8b9SKrzysztof Kosiński 83*a03ca8b9SKrzysztof Kosiński } // namespace zucchini 84*a03ca8b9SKrzysztof Kosiński 85*a03ca8b9SKrzysztof Kosiński #endif // COMPONENTS_ZUCCHINI_ZUCCHINI_GEN_H_ 86