Mohsen Izadi | 1bcbf25 | 2019-06-27 01:26:29 | [diff] [blame] | 1 | // 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 | |
| 14 | namespace 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 Levin | 4f331b42 | 2020-08-31 18:38:47 | [diff] [blame] | 18 | // 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 Izadi | 1bcbf25 | 2019-06-27 01:26:29 | [diff] [blame] | 26 | // 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. |
| 29 | class 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 Levin | 4f331b42 | 2020-08-31 18:38:47 | [diff] [blame] | 46 | void AppendQuads(viz::CompositorRenderPass* render_pass, |
Mohsen Izadi | 1bcbf25 | 2019-06-27 01:26:29 | [diff] [blame] | 47 | AppendQuadsData* append_quads_data) override; |
| 48 | void PushPropertiesTo(LayerImpl* layer) override; |
| 49 | gfx::Rect GetDamageRect() const override; |
Mitsuru Oshima | 60cab6e | 2021-04-20 03:36:37 | [diff] [blame] | 50 | gfx::Rect GetEnclosingVisibleRectInTargetSpace() const override; |
Mohsen Izadi | 1bcbf25 | 2019-06-27 01:26:29 | [diff] [blame] | 51 | |
| 52 | protected: |
| 53 | MirrorLayerImpl(LayerTreeImpl* tree_impl, int id); |
| 54 | |
| 55 | private: |
| 56 | const char* LayerTypeAsString() const override; |
Vladimir Levin | 4f331b42 | 2020-08-31 18:38:47 | [diff] [blame] | 57 | viz::CompositorRenderPassId mirrored_layer_render_pass_id() const { |
| 58 | return viz::CompositorRenderPassId{mirrored_layer_id()}; |
Vladimir Levin | 55d4d3c | 2020-07-20 20:41:23 | [diff] [blame] | 59 | } |
Mohsen Izadi | 1bcbf25 | 2019-06-27 01:26:29 | [diff] [blame] | 60 | |
| 61 | int mirrored_layer_id_ = 0; |
| 62 | }; |
| 63 | |
| 64 | } // namespace cc |
| 65 | |
| 66 | #endif // CC_LAYERS_MIRROR_LAYER_IMPL_H_ |