blob: b8a9739421149c5ce98a574165b9725cf5b8f10b [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
Xianzhu Wang61ace672020-02-08 02:32:427#include "base/trace_event/traced_value.h"
[email protected]741fba422013-09-20 03:34:148#include "cc/base/math_util.h"
[email protected]741fba422013-09-20 03:34:149#include "cc/trees/layer_tree_impl.h"
vmpstr11b77b432014-10-07 20:11:4010#include "cc/trees/occlusion.h"
danakje5805be2017-09-15 19:24:5511#include "components/viz/common/quads/texture_draw_quad.h"
bokane7a058a2017-03-02 22:42:5112#include "ui/gfx/geometry/rect_conversions.h"
heejin.r.chungd28506ba2014-10-23 16:36:2013#include "ui/gfx/geometry/rect_f.h"
[email protected]35680c02012-11-06 05:53:0014
15namespace cc {
16
[email protected]37adf942013-03-08 04:43:1717NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id)
bokane7a058a2017-03-02 22:42:5118 : UIResourceLayerImpl(tree_impl, id) {}
[email protected]37adf942013-03-08 04:43:1719
Chris Watkinsf6353292017-12-04 02:36:0520NinePatchLayerImpl::~NinePatchLayerImpl() = default;
[email protected]37adf942013-03-08 04:43:1721
danakj60bc3bc2016-04-09 00:24:4822std::unique_ptr<LayerImpl> NinePatchLayerImpl::CreateLayerImpl(
[email protected]37adf942013-03-08 04:43:1723 LayerTreeImpl* tree_impl) {
danakjf446a072014-09-27 21:55:4824 return NinePatchLayerImpl::Create(tree_impl, id());
[email protected]35680c02012-11-06 05:53:0025}
26
[email protected]7aba6662013-03-12 10:17:3427void NinePatchLayerImpl::PushPropertiesTo(LayerImpl* layer) {
[email protected]efbdb3a2013-10-04 00:35:1328 UIResourceLayerImpl::PushPropertiesTo(layer);
[email protected]37adf942013-03-08 04:43:1729 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer);
30
bokane7a058a2017-03-02 22:42:5131 layer_impl->quad_generator_ = this->quad_generator_;
[email protected]48871fc2013-01-23 07:36:5132}
33
[email protected]0023fc72014-01-10 20:05:0634void NinePatchLayerImpl::SetLayout(const gfx::Rect& aperture,
35 const gfx::Rect& border,
lionel.g.landwerlin258c7d32016-07-27 09:55:2436 const gfx::Rect& layer_occlusion,
kkimlabs22367f642016-01-23 23:23:2437 bool fill_center,
38 bool nearest_neighbor) {
[email protected]741fba422013-09-20 03:34:1439 // This check imposes an ordering on the call sequence. An UIResource must
40 // exist before SetLayout can be called.
41 DCHECK(ui_resource_id_);
42
bokane7a058a2017-03-02 22:42:5143 if (!quad_generator_.SetLayout(image_bounds_, bounds(), aperture, border,
44 layer_occlusion, fill_center,
45 nearest_neighbor))
[email protected]741fba422013-09-20 03:34:1446 return;
47
[email protected]741fba422013-09-20 03:34:1448 NoteLayerPropertyChanged();
[email protected]48871fc2013-01-23 07:36:5149}
50
Vladimir Levin4f331b422020-08-31 18:38:4751void NinePatchLayerImpl::AppendQuads(viz::CompositorRenderPass* render_pass,
danakje5805be2017-09-15 19:24:5552 AppendQuadsData* append_quads_data) {
yiyix74cbbdde2017-09-11 06:54:1253 DCHECK(!bounds().IsEmpty());
bokane7a058a2017-03-02 22:42:5154 quad_generator_.CheckGeometryLimitations();
yiyix74cbbdde2017-09-11 06:54:1255
Alex Zhangabad2292017-08-23 21:55:1956 viz::SharedQuadState* shared_quad_state =
[email protected]c6707fd2014-06-23 05:50:3657 render_pass->CreateAndAppendSharedQuadState();
yiyix74cbbdde2017-09-11 06:54:1258 bool is_resource =
59 ui_resource_id_ &&
60 layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_);
yiyix10141eca2017-09-05 20:36:5261 bool are_contents_opaque =
yiyix74cbbdde2017-09-11 06:54:1262 is_resource ? layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_) ||
63 contents_opaque()
64 : false;
yiyix10141eca2017-09-05 20:36:5265 PopulateSharedQuadState(shared_quad_state, are_contents_opaque);
Vladimir Levin88f611ff2017-09-29 17:54:1566 AppendDebugBorderQuad(render_pass, gfx::Rect(bounds()), shared_quad_state,
Dana Jansensc46d3742015-06-18 01:33:1467 append_quads_data);
[email protected]37adf942013-03-08 04:43:1768
yiyix74cbbdde2017-09-11 06:54:1269 if (!is_resource)
70 return;
lionel.g.landwerlin258c7d32016-07-27 09:55:2471
bokane7a058a2017-03-02 22:42:5172 std::vector<NinePatchGenerator::Patch> patches =
73 quad_generator_.GeneratePatches();
lionel.g.landwerlin258c7d32016-07-27 09:55:2474
bokane7a058a2017-03-02 22:42:5175 for (auto& patch : patches)
76 patch.output_rect =
77 gfx::RectF(gfx::ToFlooredRectDeprecated(patch.output_rect));
lionel.g.landwerlin258c7d32016-07-27 09:55:2478
bokane7a058a2017-03-02 22:42:5179 quad_generator_.AppendQuads(this, ui_resource_id_, render_pass,
80 shared_quad_state, patches);
[email protected]35680c02012-11-06 05:53:0081}
82
[email protected]7aba6662013-03-12 10:17:3483const char* NinePatchLayerImpl::LayerTypeAsString() const {
[email protected]f256b7fd2013-05-15 01:49:3084 return "cc::NinePatchLayerImpl";
[email protected]35680c02012-11-06 05:53:0085}
86
Xianzhu Wang61ace672020-02-08 02:32:4287void NinePatchLayerImpl::AsValueInto(
88 base::trace_event::TracedValue* state) const {
89 LayerImpl::AsValueInto(state);
90 quad_generator_.AsValueInto(state);
[email protected]35680c02012-11-06 05:53:0091}
92
[email protected]37adf942013-03-08 04:43:1793} // namespace cc