[email protected] | c1ae8294 | 2014-01-17 23:17:04 | [diff] [blame] | 1 | // Copyright 2014 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_SURFACE_LAYER_H_ | ||||
6 | #define CC_LAYERS_SURFACE_LAYER_H_ | ||||
7 | |||||
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 8 | #include "base/macros.h" |
[email protected] | c1ae8294 | 2014-01-17 23:17:04 | [diff] [blame] | 9 | #include "cc/base/cc_export.h" |
10 | #include "cc/layers/layer.h" | ||||
[email protected] | 16a6af15 | 2014-06-13 04:20:16 | [diff] [blame] | 11 | #include "cc/surfaces/surface_id.h" |
jbauman | dbccae1ab | 2014-11-06 23:26:44 | [diff] [blame] | 12 | #include "cc/surfaces/surface_sequence.h" |
tfarina | ebe974f0 | 2015-01-03 04:25:32 | [diff] [blame] | 13 | #include "ui/gfx/geometry/size.h" |
[email protected] | c1ae8294 | 2014-01-17 23:17:04 | [diff] [blame] | 14 | |
15 | namespace cc { | ||||
16 | |||||
17 | // A layer that renders a surface referencing the output of another compositor | ||||
18 | // instance or client. | ||||
19 | class CC_EXPORT SurfaceLayer : public Layer { | ||||
20 | public: | ||||
jbauman | dbccae1ab | 2014-11-06 23:26:44 | [diff] [blame] | 21 | // This callback is run when a SurfaceSequence needs to be satisfied, but |
22 | // the parent compositor is unable to. It can be called on either the main | ||||
23 | // or impl threads. | ||||
xlai | 92e6534 | 2016-06-30 15:58:57 | [diff] [blame] | 24 | using SatisfyCallback = base::Callback<void(const SurfaceSequence&)>; |
jbauman | dbccae1ab | 2014-11-06 23:26:44 | [diff] [blame] | 25 | |
26 | // This callback is run to require that a specific SurfaceSequence is | ||||
27 | // received before a SurfaceId is destroyed. | ||||
xlai | 92e6534 | 2016-06-30 15:58:57 | [diff] [blame] | 28 | using RequireCallback = |
29 | base::Callback<void(const SurfaceId&, const SurfaceSequence&)>; | ||||
jbauman | dbccae1ab | 2014-11-06 23:26:44 | [diff] [blame] | 30 | |
31 | static scoped_refptr<SurfaceLayer> Create( | ||||
32 | const SatisfyCallback& satisfy_callback, | ||||
33 | const RequireCallback& require_callback); | ||||
[email protected] | c1ae8294 | 2014-01-17 23:17:04 | [diff] [blame] | 34 | |
xlai | 5e87e71 | 2016-12-16 02:10:25 | [diff] [blame^] | 35 | // When stretch_content_to_fill_bounds is true, scale is unused. |
fsamuel | 27866427 | 2016-07-13 04:06:59 | [diff] [blame] | 36 | void SetSurfaceId(const SurfaceId& surface_id, |
37 | float scale, | ||||
xlai | 5e87e71 | 2016-12-16 02:10:25 | [diff] [blame^] | 38 | const gfx::Size& size, |
39 | bool stretch_content_to_fill_bounds); | ||||
[email protected] | c1ae8294 | 2014-01-17 23:17:04 | [diff] [blame] | 40 | |
41 | // Layer overrides. | ||||
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 42 | std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override; |
jbauman | dbccae1ab | 2014-11-06 23:26:44 | [diff] [blame] | 43 | void SetLayerTreeHost(LayerTreeHost* host) override; |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 44 | void PushPropertiesTo(LayerImpl* layer) override; |
[email protected] | c1ae8294 | 2014-01-17 23:17:04 | [diff] [blame] | 45 | |
domlaskowski | 4b33bfe | 2016-10-27 00:34:22 | [diff] [blame] | 46 | SurfaceId surface_id() const { return surface_id_; } |
47 | const gfx::Size& surface_size() const { return surface_size_; } | ||||
48 | float surface_scale() const { return surface_scale_; } | ||||
49 | |||||
50 | const SatisfyCallback& satisfy_callback() const { return satisfy_callback_; } | ||||
51 | const RequireCallback& require_callback() const { return require_callback_; } | ||||
52 | |||||
[email protected] | c1ae8294 | 2014-01-17 23:17:04 | [diff] [blame] | 53 | protected: |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 54 | SurfaceLayer(const SatisfyCallback& satisfy_callback, |
jbauman | dbccae1ab | 2014-11-06 23:26:44 | [diff] [blame] | 55 | const RequireCallback& require_callback); |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 56 | bool HasDrawableContent() const override; |
[email protected] | c1ae8294 | 2014-01-17 23:17:04 | [diff] [blame] | 57 | |
58 | private: | ||||
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 59 | ~SurfaceLayer() override; |
jbauman | dbccae1ab | 2014-11-06 23:26:44 | [diff] [blame] | 60 | void CreateNewDestroySequence(); |
61 | void SatisfyDestroySequence(); | ||||
[email protected] | c1ae8294 | 2014-01-17 23:17:04 | [diff] [blame] | 62 | |
[email protected] | 16a6af15 | 2014-06-13 04:20:16 | [diff] [blame] | 63 | SurfaceId surface_id_; |
jbauman | 5a8f0ab | 2014-11-07 01:41:16 | [diff] [blame] | 64 | gfx::Size surface_size_; |
xlai | 5e87e71 | 2016-12-16 02:10:25 | [diff] [blame^] | 65 | float surface_scale_ = 1.f; |
66 | bool stretch_content_to_fill_bounds_ = false; | ||||
jbauman | dbccae1ab | 2014-11-06 23:26:44 | [diff] [blame] | 67 | SurfaceSequence destroy_sequence_; |
68 | SatisfyCallback satisfy_callback_; | ||||
69 | RequireCallback require_callback_; | ||||
[email protected] | c1ae8294 | 2014-01-17 23:17:04 | [diff] [blame] | 70 | |
71 | DISALLOW_COPY_AND_ASSIGN(SurfaceLayer); | ||||
72 | }; | ||||
73 | |||||
74 | } // namespace cc | ||||
75 | |||||
76 | #endif // CC_LAYERS_SURFACE_LAYER_H_ |