[email protected] | 35680c0 | 2012-11-06 05:53:00 | [diff] [blame] | 1 | // Copyright 2012 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 | |
[email protected] | bf691c2 | 2013-03-26 21:15:06 | [diff] [blame] | 5 | #include "cc/layers/nine_patch_layer_impl.h" |
[email protected] | 35680c0 | 2012-11-06 05:53:00 | [diff] [blame] | 6 | |
[email protected] | 8e61d4b | 2013-06-10 22:11:48 | [diff] [blame] | 7 | #include "base/strings/stringprintf.h" |
[email protected] | 4a23c374c | 2012-12-08 08:38:55 | [diff] [blame] | 8 | #include "base/values.h" |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 9 | #include "cc/base/math_util.h" |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 10 | #include "cc/trees/layer_tree_impl.h" |
vmpstr | 11b77b43 | 2014-10-07 20:11:40 | [diff] [blame] | 11 | #include "cc/trees/occlusion.h" |
danakj | e5805be | 2017-09-15 19:24:55 | [diff] [blame] | 12 | #include "components/viz/common/quads/texture_draw_quad.h" |
bokan | e7a058a | 2017-03-02 22:42:51 | [diff] [blame] | 13 | #include "ui/gfx/geometry/rect_conversions.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 14 | #include "ui/gfx/geometry/rect_f.h" |
[email protected] | 35680c0 | 2012-11-06 05:53:00 | [diff] [blame] | 15 | |
| 16 | namespace cc { |
| 17 | |
[email protected] | 37adf94 | 2013-03-08 04:43:17 | [diff] [blame] | 18 | NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id) |
bokan | e7a058a | 2017-03-02 22:42:51 | [diff] [blame] | 19 | : UIResourceLayerImpl(tree_impl, id) {} |
[email protected] | 37adf94 | 2013-03-08 04:43:17 | [diff] [blame] | 20 | |
Chris Watkins | f635329 | 2017-12-04 02:36:05 | [diff] [blame] | 21 | NinePatchLayerImpl::~NinePatchLayerImpl() = default; |
[email protected] | 37adf94 | 2013-03-08 04:43:17 | [diff] [blame] | 22 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 23 | std::unique_ptr<LayerImpl> NinePatchLayerImpl::CreateLayerImpl( |
[email protected] | 37adf94 | 2013-03-08 04:43:17 | [diff] [blame] | 24 | LayerTreeImpl* tree_impl) { |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 25 | return NinePatchLayerImpl::Create(tree_impl, id()); |
[email protected] | 35680c0 | 2012-11-06 05:53:00 | [diff] [blame] | 26 | } |
| 27 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 28 | void NinePatchLayerImpl::PushPropertiesTo(LayerImpl* layer) { |
[email protected] | efbdb3a | 2013-10-04 00:35:13 | [diff] [blame] | 29 | UIResourceLayerImpl::PushPropertiesTo(layer); |
[email protected] | 37adf94 | 2013-03-08 04:43:17 | [diff] [blame] | 30 | NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); |
| 31 | |
bokan | e7a058a | 2017-03-02 22:42:51 | [diff] [blame] | 32 | layer_impl->quad_generator_ = this->quad_generator_; |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 33 | } |
| 34 | |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 35 | void NinePatchLayerImpl::SetLayout(const gfx::Rect& aperture, |
| 36 | const gfx::Rect& border, |
lionel.g.landwerlin | 258c7d3 | 2016-07-27 09:55:24 | [diff] [blame] | 37 | const gfx::Rect& layer_occlusion, |
kkimlabs | 22367f64 | 2016-01-23 23:23:24 | [diff] [blame] | 38 | bool fill_center, |
| 39 | bool nearest_neighbor) { |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 40 | // This check imposes an ordering on the call sequence. An UIResource must |
| 41 | // exist before SetLayout can be called. |
| 42 | DCHECK(ui_resource_id_); |
| 43 | |
bokan | e7a058a | 2017-03-02 22:42:51 | [diff] [blame] | 44 | if (!quad_generator_.SetLayout(image_bounds_, bounds(), aperture, border, |
| 45 | layer_occlusion, fill_center, |
| 46 | nearest_neighbor)) |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 47 | return; |
| 48 | |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 49 | NoteLayerPropertyChanged(); |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 50 | } |
| 51 | |
danakj | e5805be | 2017-09-15 19:24:55 | [diff] [blame] | 52 | void NinePatchLayerImpl::AppendQuads(viz::RenderPass* render_pass, |
| 53 | AppendQuadsData* append_quads_data) { |
yiyix | 74cbbdde | 2017-09-11 06:54:12 | [diff] [blame] | 54 | DCHECK(!bounds().IsEmpty()); |
bokan | e7a058a | 2017-03-02 22:42:51 | [diff] [blame] | 55 | quad_generator_.CheckGeometryLimitations(); |
yiyix | 74cbbdde | 2017-09-11 06:54:12 | [diff] [blame] | 56 | |
Alex Zhang | abad229 | 2017-08-23 21:55:19 | [diff] [blame] | 57 | viz::SharedQuadState* shared_quad_state = |
[email protected] | c6707fd | 2014-06-23 05:50:36 | [diff] [blame] | 58 | render_pass->CreateAndAppendSharedQuadState(); |
yiyix | 74cbbdde | 2017-09-11 06:54:12 | [diff] [blame] | 59 | bool is_resource = |
| 60 | ui_resource_id_ && |
| 61 | layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_); |
yiyix | 10141eca | 2017-09-05 20:36:52 | [diff] [blame] | 62 | bool are_contents_opaque = |
yiyix | 74cbbdde | 2017-09-11 06:54:12 | [diff] [blame] | 63 | is_resource ? layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_) || |
| 64 | contents_opaque() |
| 65 | : false; |
yiyix | 10141eca | 2017-09-05 20:36:52 | [diff] [blame] | 66 | PopulateSharedQuadState(shared_quad_state, are_contents_opaque); |
Vladimir Levin | 88f611ff | 2017-09-29 17:54:15 | [diff] [blame] | 67 | AppendDebugBorderQuad(render_pass, gfx::Rect(bounds()), shared_quad_state, |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 68 | append_quads_data); |
[email protected] | 37adf94 | 2013-03-08 04:43:17 | [diff] [blame] | 69 | |
yiyix | 74cbbdde | 2017-09-11 06:54:12 | [diff] [blame] | 70 | if (!is_resource) |
| 71 | return; |
lionel.g.landwerlin | 258c7d3 | 2016-07-27 09:55:24 | [diff] [blame] | 72 | |
bokan | e7a058a | 2017-03-02 22:42:51 | [diff] [blame] | 73 | std::vector<NinePatchGenerator::Patch> patches = |
| 74 | quad_generator_.GeneratePatches(); |
lionel.g.landwerlin | 258c7d3 | 2016-07-27 09:55:24 | [diff] [blame] | 75 | |
bokan | e7a058a | 2017-03-02 22:42:51 | [diff] [blame] | 76 | for (auto& patch : patches) |
| 77 | patch.output_rect = |
| 78 | gfx::RectF(gfx::ToFlooredRectDeprecated(patch.output_rect)); |
lionel.g.landwerlin | 258c7d3 | 2016-07-27 09:55:24 | [diff] [blame] | 79 | |
bokan | e7a058a | 2017-03-02 22:42:51 | [diff] [blame] | 80 | quad_generator_.AppendQuads(this, ui_resource_id_, render_pass, |
| 81 | shared_quad_state, patches); |
[email protected] | 35680c0 | 2012-11-06 05:53:00 | [diff] [blame] | 82 | } |
| 83 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 84 | const char* NinePatchLayerImpl::LayerTypeAsString() const { |
[email protected] | f256b7fd | 2013-05-15 01:49:30 | [diff] [blame] | 85 | return "cc::NinePatchLayerImpl"; |
[email protected] | 35680c0 | 2012-11-06 05:53:00 | [diff] [blame] | 86 | } |
| 87 | |
Philip Rogers | 92f7238f | 2019-01-04 19:01:59 | [diff] [blame] | 88 | std::unique_ptr<base::DictionaryValue> NinePatchLayerImpl::LayerAsJson() const { |
Philip Rogers | 8089055 | 2017-10-12 02:42:19 | [diff] [blame] | 89 | std::unique_ptr<base::DictionaryValue> result = LayerImpl::LayerAsJson(); |
bokan | e7a058a | 2017-03-02 22:42:51 | [diff] [blame] | 90 | quad_generator_.AsJson(result.get()); |
[email protected] | 37adf94 | 2013-03-08 04:43:17 | [diff] [blame] | 91 | return result; |
[email protected] | 35680c0 | 2012-11-06 05:53:00 | [diff] [blame] | 92 | } |
| 93 | |
[email protected] | 37adf94 | 2013-03-08 04:43:17 | [diff] [blame] | 94 | } // namespace cc |