blob: 3ccf20183c10785cbaefc0e2e789d4ea1a317dfe [file] [log] [blame]
Mohsen Izadi1bcbf252019-06-27 01:26:291// Copyright 2019 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
5#ifndef CC_LAYERS_MIRROR_LAYER_IMPL_H_
6#define CC_LAYERS_MIRROR_LAYER_IMPL_H_
7
8#include <memory>
9
10#include "base/memory/ptr_util.h"
11#include "cc/cc_export.h"
12#include "cc/layers/layer_impl.h"
13
14namespace cc {
15
16// This type of layer is used to mirror contents of another layer (specified by
17// |mirrored_layer_id_|) by forcing a render pass for the mirrored layer and
Vladimir Levin4f331b422020-08-31 18:38:4718// adding a CompositorRenderPassDrawQuad in the compositor frame for this layer
19// referring to that render pass. The mirroring layer should not be a descendant
20// of the mirrored layer (in terms of the effect tree). Due to ordering
21// requirements for render passes in the compositor frame, the render pass
22// containing mirroring layer should appear after the render pass created for
23// the mirrored layer. Currently, render passes are in reverse-draw order of the
24// effect tree, so we should be careful that this reverse-draw order does not
25// conflict with render pass ordering requirement mentioned above.
Mohsen Izadi1bcbf252019-06-27 01:26:2926// TODO(mohsen): If necessary, reorder render passes in compositor frame such
27// that the render pass containing mirroring layer appears after the render pass
28// created for the mirrored layer.
29class CC_EXPORT MirrorLayerImpl : public LayerImpl {
30 public:
31 static std::unique_ptr<MirrorLayerImpl> Create(LayerTreeImpl* tree_impl,
32 int id) {
33 return base::WrapUnique(new MirrorLayerImpl(tree_impl, id));
34 }
35
36 MirrorLayerImpl(const MirrorLayerImpl&) = delete;
37 MirrorLayerImpl& operator=(const MirrorLayerImpl&) = delete;
38
39 ~MirrorLayerImpl() override;
40
41 void SetMirroredLayerId(int id) { mirrored_layer_id_ = id; }
42 int mirrored_layer_id() const { return mirrored_layer_id_; }
43
44 // LayerImpl overrides.
45 std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
Vladimir Levin4f331b422020-08-31 18:38:4746 void AppendQuads(viz::CompositorRenderPass* render_pass,
Mohsen Izadi1bcbf252019-06-27 01:26:2947 AppendQuadsData* append_quads_data) override;
48 void PushPropertiesTo(LayerImpl* layer) override;
49 gfx::Rect GetDamageRect() const override;
Mitsuru Oshima60cab6e2021-04-20 03:36:3750 gfx::Rect GetEnclosingVisibleRectInTargetSpace() const override;
Mohsen Izadi1bcbf252019-06-27 01:26:2951
52 protected:
53 MirrorLayerImpl(LayerTreeImpl* tree_impl, int id);
54
55 private:
56 const char* LayerTypeAsString() const override;
Vladimir Levin4f331b422020-08-31 18:38:4757 viz::CompositorRenderPassId mirrored_layer_render_pass_id() const {
58 return viz::CompositorRenderPassId{mirrored_layer_id()};
Vladimir Levin55d4d3c2020-07-20 20:41:2359 }
Mohsen Izadi1bcbf252019-06-27 01:26:2960
61 int mirrored_layer_id_ = 0;
62};
63
64} // namespace cc
65
66#endif // CC_LAYERS_MIRROR_LAYER_IMPL_H_