zucchini_gen.h 3.7 KB

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