nine_patch_generator.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Copyright 2016 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 CC_LAYERS_NINE_PATCH_GENERATOR_H_
  5. #define CC_LAYERS_NINE_PATCH_GENERATOR_H_
  6. #include <string>
  7. #include <vector>
  8. #include "cc/cc_export.h"
  9. #include "cc/resources/ui_resource_client.h"
  10. #include "ui/gfx/geometry/rect.h"
  11. #include "ui/gfx/geometry/rect_f.h"
  12. #include "ui/gfx/geometry/size.h"
  13. namespace base {
  14. namespace trace_event {
  15. class TracedValue;
  16. }
  17. }
  18. namespace viz {
  19. class CompositorRenderPass;
  20. class SharedQuadState;
  21. } // namespace viz
  22. namespace cc {
  23. class LayerImpl;
  24. class CC_EXPORT NinePatchGenerator {
  25. public:
  26. class Patch {
  27. public:
  28. Patch(const gfx::RectF& image_rect,
  29. const gfx::Size& total_image_bounds,
  30. const gfx::RectF& output_rect);
  31. gfx::RectF image_rect;
  32. gfx::RectF normalized_image_rect;
  33. gfx::RectF output_rect;
  34. };
  35. NinePatchGenerator();
  36. // The bitmap stretches out the bounds of the layer. The following picture
  37. // illustrates the parameters associated with the dimensions.
  38. //
  39. // Layer space layout
  40. //
  41. // --------------------------------
  42. // | : : |
  43. // | J C |
  44. // | : : |
  45. // | ------------------ |
  46. // | | : | |
  47. // |~~~I~~| ------------ | |
  48. // | | | | | |
  49. // | | | | | |
  50. // |~~~A~~|~~| |~~|~B~~~~|
  51. // | | | | | |
  52. // | L ------------ | |
  53. // | | : | |
  54. // | ---K-------------- |
  55. // | D |
  56. // | : |
  57. // | : |
  58. // --------------------------------
  59. //
  60. // Bitmap space layout
  61. //
  62. // ~~~~~~~~~~ W ~~~~~~~~~~
  63. // : : |
  64. // : Y |
  65. // : : |
  66. // :~~X~~------------ |
  67. // : | : |
  68. // : | : |
  69. // H | Q |
  70. // : | : |
  71. // : ~~~~~P~~~~~ |
  72. // : |
  73. // : |
  74. // : |
  75. // ------------------------
  76. //
  77. // |image_bounds| = (W, H)
  78. // |image_aperture| = (X, Y, P, Q)
  79. // |border| = (A, C, A + B, C + D)
  80. // |occlusion_rectangle| = (I, J, K, L)
  81. // |fill_center| indicates whether to draw the center quad or not.
  82. bool SetLayout(const gfx::Size& image_bounds,
  83. const gfx::Size& output_bounds,
  84. const gfx::Rect& image_aperture,
  85. const gfx::Rect& border,
  86. const gfx::Rect& output_occlusion,
  87. bool fill_center,
  88. bool nearest_neighbor);
  89. std::vector<Patch> GeneratePatches() const;
  90. void AppendQuads(LayerImpl* layer_impl,
  91. UIResourceId ui_resource_id,
  92. viz::CompositorRenderPass* render_pass,
  93. viz::SharedQuadState* shared_quad_state,
  94. const std::vector<Patch>& patches);
  95. void AsValueInto(base::trace_event::TracedValue* state) const;
  96. void CheckGeometryLimitations();
  97. private:
  98. std::vector<Patch> ComputeQuadsWithOcclusion() const;
  99. std::vector<Patch> ComputeQuadsWithoutOcclusion() const;
  100. // The center patch in image space.
  101. gfx::Rect image_aperture_;
  102. // An inset border that the patches will be mapped to.
  103. gfx::Rect border_;
  104. gfx::Size image_bounds_;
  105. gfx::Size output_bounds_;
  106. bool fill_center_;
  107. bool nearest_neighbor_;
  108. gfx::Rect output_occlusion_;
  109. };
  110. } // namespace cc
  111. #endif // CC_LAYERS_NINE_PATCH_GENERATOR_H_