blob: 28a924103676d1ac66641447cd4991a0d4c9c450 [file] [log] [blame]
[email protected]35680c02012-11-06 05:53:001// 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]bf691c22013-03-26 21:15:065#include "cc/layers/nine_patch_layer_impl.h"
[email protected]35680c02012-11-06 05:53:006
[email protected]8e61d4b2013-06-10 22:11:487#include "base/strings/stringprintf.h"
[email protected]4a23c374c2012-12-08 08:38:558#include "base/values.h"
[email protected]741fba422013-09-20 03:34:149#include "cc/base/math_util.h"
[email protected]741fba422013-09-20 03:34:1410#include "cc/trees/layer_tree_impl.h"
vmpstr11b77b432014-10-07 20:11:4011#include "cc/trees/occlusion.h"
danakje5805be2017-09-15 19:24:5512#include "components/viz/common/quads/texture_draw_quad.h"
bokane7a058a2017-03-02 22:42:5113#include "ui/gfx/geometry/rect_conversions.h"
heejin.r.chungd28506ba2014-10-23 16:36:2014#include "ui/gfx/geometry/rect_f.h"
[email protected]35680c02012-11-06 05:53:0015
16namespace cc {
17
[email protected]37adf942013-03-08 04:43:1718NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id)
bokane7a058a2017-03-02 22:42:5119 : UIResourceLayerImpl(tree_impl, id) {}
[email protected]37adf942013-03-08 04:43:1720
Chris Watkinsf6353292017-12-04 02:36:0521NinePatchLayerImpl::~NinePatchLayerImpl() = default;
[email protected]37adf942013-03-08 04:43:1722
danakj60bc3bc2016-04-09 00:24:4823std::unique_ptr<LayerImpl> NinePatchLayerImpl::CreateLayerImpl(
[email protected]37adf942013-03-08 04:43:1724 LayerTreeImpl* tree_impl) {
danakjf446a072014-09-27 21:55:4825 return NinePatchLayerImpl::Create(tree_impl, id());
[email protected]35680c02012-11-06 05:53:0026}
27
[email protected]7aba6662013-03-12 10:17:3428void NinePatchLayerImpl::PushPropertiesTo(LayerImpl* layer) {
[email protected]efbdb3a2013-10-04 00:35:1329 UIResourceLayerImpl::PushPropertiesTo(layer);
[email protected]37adf942013-03-08 04:43:1730 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer);
31
bokane7a058a2017-03-02 22:42:5132 layer_impl->quad_generator_ = this->quad_generator_;
[email protected]48871fc2013-01-23 07:36:5133}
34
[email protected]0023fc72014-01-10 20:05:0635void NinePatchLayerImpl::SetLayout(const gfx::Rect& aperture,
36 const gfx::Rect& border,
lionel.g.landwerlin258c7d32016-07-27 09:55:2437 const gfx::Rect& layer_occlusion,
kkimlabs22367f642016-01-23 23:23:2438 bool fill_center,
39 bool nearest_neighbor) {
[email protected]741fba422013-09-20 03:34:1440 // 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
bokane7a058a2017-03-02 22:42:5144 if (!quad_generator_.SetLayout(image_bounds_, bounds(), aperture, border,
45 layer_occlusion, fill_center,
46 nearest_neighbor))
[email protected]741fba422013-09-20 03:34:1447 return;
48
[email protected]741fba422013-09-20 03:34:1449 NoteLayerPropertyChanged();
[email protected]48871fc2013-01-23 07:36:5150}
51
danakje5805be2017-09-15 19:24:5552void NinePatchLayerImpl::AppendQuads(viz::RenderPass* render_pass,
53 AppendQuadsData* append_quads_data) {
yiyix74cbbdde2017-09-11 06:54:1254 DCHECK(!bounds().IsEmpty());
bokane7a058a2017-03-02 22:42:5155 quad_generator_.CheckGeometryLimitations();
yiyix74cbbdde2017-09-11 06:54:1256
Alex Zhangabad2292017-08-23 21:55:1957 viz::SharedQuadState* shared_quad_state =
[email protected]c6707fd2014-06-23 05:50:3658 render_pass->CreateAndAppendSharedQuadState();
yiyix74cbbdde2017-09-11 06:54:1259 bool is_resource =
60 ui_resource_id_ &&
61 layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_);
yiyix10141eca2017-09-05 20:36:5262 bool are_contents_opaque =
yiyix74cbbdde2017-09-11 06:54:1263 is_resource ? layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_) ||
64 contents_opaque()
65 : false;
yiyix10141eca2017-09-05 20:36:5266 PopulateSharedQuadState(shared_quad_state, are_contents_opaque);
Vladimir Levin88f611ff2017-09-29 17:54:1567 AppendDebugBorderQuad(render_pass, gfx::Rect(bounds()), shared_quad_state,
Dana Jansensc46d3742015-06-18 01:33:1468 append_quads_data);
[email protected]37adf942013-03-08 04:43:1769
yiyix74cbbdde2017-09-11 06:54:1270 if (!is_resource)
71 return;
lionel.g.landwerlin258c7d32016-07-27 09:55:2472
bokane7a058a2017-03-02 22:42:5173 std::vector<NinePatchGenerator::Patch> patches =
74 quad_generator_.GeneratePatches();
lionel.g.landwerlin258c7d32016-07-27 09:55:2475
bokane7a058a2017-03-02 22:42:5176 for (auto& patch : patches)
77 patch.output_rect =
78 gfx::RectF(gfx::ToFlooredRectDeprecated(patch.output_rect));
lionel.g.landwerlin258c7d32016-07-27 09:55:2479
bokane7a058a2017-03-02 22:42:5180 quad_generator_.AppendQuads(this, ui_resource_id_, render_pass,
81 shared_quad_state, patches);
[email protected]35680c02012-11-06 05:53:0082}
83
[email protected]7aba6662013-03-12 10:17:3484const char* NinePatchLayerImpl::LayerTypeAsString() const {
[email protected]f256b7fd2013-05-15 01:49:3085 return "cc::NinePatchLayerImpl";
[email protected]35680c02012-11-06 05:53:0086}
87
Philip Rogers92f7238f2019-01-04 19:01:5988std::unique_ptr<base::DictionaryValue> NinePatchLayerImpl::LayerAsJson() const {
Philip Rogers80890552017-10-12 02:42:1989 std::unique_ptr<base::DictionaryValue> result = LayerImpl::LayerAsJson();
bokane7a058a2017-03-02 22:42:5190 quad_generator_.AsJson(result.get());
[email protected]37adf942013-03-08 04:43:1791 return result;
[email protected]35680c02012-11-06 05:53:0092}
93
[email protected]37adf942013-03-08 04:43:1794} // namespace cc