| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_LAYERS_NINE_PATCH_LAYER_IMPL_H_ | 5 #ifndef CC_QUADS_NINE_PATCH_GENERATOR_H_ |
| 6 #define CC_LAYERS_NINE_PATCH_LAYER_IMPL_H_ | 6 #define CC_QUADS_NINE_PATCH_GENERATOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "cc/base/cc_export.h" | 13 #include "cc/base/resource_id.h" |
| 13 #include "cc/layers/layer_impl.h" | |
| 14 #include "cc/layers/ui_resource_layer_impl.h" | |
| 15 #include "cc/resources/resource_provider.h" | |
| 16 #include "cc/resources/ui_resource_client.h" | |
| 17 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
| 15 #include "ui/gfx/geometry/rect_f.h" |
| 18 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
| 19 | 17 |
| 20 namespace base { | 18 namespace base { |
| 21 class DictionaryValue; | 19 class DictionaryValue; |
| 22 } | 20 } |
| 23 | 21 |
| 24 namespace cc { | 22 namespace cc { |
| 25 | 23 |
| 26 class CC_EXPORT NinePatchLayerImpl : public UIResourceLayerImpl { | 24 class NinePatchGenerator { |
| 27 public: | 25 public: |
| 28 static std::unique_ptr<NinePatchLayerImpl> Create(LayerTreeImpl* tree_impl, | 26 class Patch { |
| 29 int id) { | 27 public: |
| 30 return base::WrapUnique(new NinePatchLayerImpl(tree_impl, id)); | 28 Patch(const gfx::RectF& image_rect, |
| 31 } | 29 const gfx::Size& total_image_bounds, |
| 32 ~NinePatchLayerImpl() override; | 30 const gfx::RectF& output_rect); |
| 31 |
| 32 gfx::RectF image_rect; |
| 33 gfx::RectF normalized_image_rect; |
| 34 gfx::RectF output_rect; |
| 35 }; |
| 36 |
| 37 NinePatchGenerator(); |
| 33 | 38 |
| 34 // The bitmap stretches out the bounds of the layer. The following picture | 39 // The bitmap stretches out the bounds of the layer. The following picture |
| 35 // illustrates the parameters associated with the dimensions. | 40 // illustrates the parameters associated with the dimensions. |
| 36 // | 41 // |
| 37 // Layer space layout | 42 // Layer space layout |
| 38 // | 43 // |
| 39 // -------------------------------- | 44 // -------------------------------- |
| 40 // | : : | | 45 // | : : | |
| 41 // | J C | | 46 // | J C | |
| 42 // | : : | | 47 // | : : | |
| (...skipping 27 matching lines...) Expand all Loading... |
| 70 // : | | 75 // : | |
| 71 // : | | 76 // : | |
| 72 // : | | 77 // : | |
| 73 // ------------------------ | 78 // ------------------------ |
| 74 // | 79 // |
| 75 // |image_bounds| = (W, H) | 80 // |image_bounds| = (W, H) |
| 76 // |image_aperture| = (X, Y, P, Q) | 81 // |image_aperture| = (X, Y, P, Q) |
| 77 // |border| = (A, C, A + B, C + D) | 82 // |border| = (A, C, A + B, C + D) |
| 78 // |occlusion_rectangle| = (I, J, K, L) | 83 // |occlusion_rectangle| = (I, J, K, L) |
| 79 // |fill_center| indicates whether to draw the center quad or not. | 84 // |fill_center| indicates whether to draw the center quad or not. |
| 80 void SetLayout(const gfx::Rect& image_aperture, | 85 bool SetLayout(const gfx::Size& image_bounds, |
| 86 const gfx::Size& output_bounds, |
| 87 const gfx::Rect& image_aperture, |
| 81 const gfx::Rect& border, | 88 const gfx::Rect& border, |
| 82 const gfx::Rect& layer_occlusion, | 89 const gfx::Rect& output_occlusion, |
| 83 bool fill_center, | 90 bool fill_center); |
| 84 bool nearest_neighbor); | |
| 85 | 91 |
| 86 std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override; | 92 std::vector<Patch> GeneratePatches() const; |
| 87 void PushPropertiesTo(LayerImpl* layer) override; | |
| 88 | 93 |
| 89 void AppendQuads(RenderPass* render_pass, | 94 void AsJson(base::DictionaryValue* dictionary) const; |
| 90 AppendQuadsData* append_quads_data) override; | |
| 91 | |
| 92 std::unique_ptr<base::DictionaryValue> LayerTreeAsJson() override; | |
| 93 | |
| 94 protected: | |
| 95 NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id); | |
| 96 | 95 |
| 97 private: | 96 private: |
| 98 class Patch { | |
| 99 public: | |
| 100 Patch(const gfx::RectF& image_rect, const gfx::RectF& layer_rect); | |
| 101 | |
| 102 gfx::RectF image_rect; | |
| 103 gfx::RectF layer_rect; | |
| 104 }; | |
| 105 | |
| 106 const char* LayerTypeAsString() const override; | |
| 107 | |
| 108 void CheckGeometryLimitations(); | 97 void CheckGeometryLimitations(); |
| 109 | 98 |
| 110 std::vector<Patch> ComputeQuadsWithOcclusion() const; | 99 std::vector<Patch> ComputeQuadsWithOcclusion() const; |
| 111 std::vector<Patch> ComputeQuadsWithoutOcclusion() const; | 100 std::vector<Patch> ComputeQuadsWithoutOcclusion() const; |
| 112 | 101 |
| 113 // The transparent center region that shows the parent layer's contents in | 102 // The center patch in image space. |
| 114 // image space. | |
| 115 gfx::Rect image_aperture_; | 103 gfx::Rect image_aperture_; |
| 116 | 104 |
| 117 // An inset border that the patches will be mapped to. | 105 // An inset border that the patches will be mapped to. |
| 118 gfx::Rect border_; | 106 gfx::Rect border_; |
| 119 | 107 |
| 108 gfx::Size image_bounds_; |
| 109 gfx::Size output_bounds_; |
| 110 |
| 120 bool fill_center_; | 111 bool fill_center_; |
| 121 | 112 |
| 122 bool nearest_neighbor_; | 113 gfx::Rect output_occlusion_; |
| 123 | |
| 124 gfx::Rect layer_occlusion_; | |
| 125 | |
| 126 DISALLOW_COPY_AND_ASSIGN(NinePatchLayerImpl); | |
| 127 }; | 114 }; |
| 128 | 115 |
| 129 } // namespace cc | 116 } // namespace cc |
| 130 | 117 |
| 131 #endif // CC_LAYERS_NINE_PATCH_LAYER_IMPL_H_ | 118 #endif // CC_QUADS_NINE_PATCH_GENERATOR_H_ |
| OLD | NEW |