James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [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 | |
| 8 | #include "cc/base/cc_export.h" |
| 9 | #include "cc/layers/layer.h" |
| 10 | #include "cc/surfaces/surface_id.h" |
James Robinson | 1ae030a | 2014-11-07 08:32:47 -0800 | [diff] [blame] | 11 | #include "cc/surfaces/surface_sequence.h" |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 12 | #include "ui/gfx/size.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 13 | |
| 14 | namespace cc { |
| 15 | |
| 16 | // A layer that renders a surface referencing the output of another compositor |
| 17 | // instance or client. |
| 18 | class CC_EXPORT SurfaceLayer : public Layer { |
| 19 | public: |
James Robinson | 1ae030a | 2014-11-07 08:32:47 -0800 | [diff] [blame] | 20 | // This callback is run when a SurfaceSequence needs to be satisfied, but |
| 21 | // the parent compositor is unable to. It can be called on either the main |
| 22 | // or impl threads. |
| 23 | using SatisfyCallback = base::Callback<void(SurfaceSequence)>; |
| 24 | |
| 25 | // This callback is run to require that a specific SurfaceSequence is |
| 26 | // received before a SurfaceId is destroyed. |
| 27 | using RequireCallback = base::Callback<void(SurfaceId, SurfaceSequence)>; |
| 28 | |
| 29 | static scoped_refptr<SurfaceLayer> Create( |
| 30 | const SatisfyCallback& satisfy_callback, |
| 31 | const RequireCallback& require_callback); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 32 | |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 33 | void SetSurfaceId(SurfaceId surface_id, float scale, const gfx::Size& size); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 34 | |
| 35 | // Layer overrides. |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 36 | scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override; |
James Robinson | 1ae030a | 2014-11-07 08:32:47 -0800 | [diff] [blame] | 37 | void SetLayerTreeHost(LayerTreeHost* host) override; |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 38 | void PushPropertiesTo(LayerImpl* layer) override; |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 39 | void CalculateContentsScale(float ideal_contents_scale, |
| 40 | float* contents_scale_x, |
| 41 | float* contents_scale_y, |
| 42 | gfx::Size* content_bounds) override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 43 | |
| 44 | protected: |
James Robinson | 1ae030a | 2014-11-07 08:32:47 -0800 | [diff] [blame] | 45 | SurfaceLayer(const SatisfyCallback& satisfy_callback, |
| 46 | const RequireCallback& require_callback); |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 47 | bool HasDrawableContent() const override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 48 | |
| 49 | private: |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 50 | ~SurfaceLayer() override; |
James Robinson | 1ae030a | 2014-11-07 08:32:47 -0800 | [diff] [blame] | 51 | void CreateNewDestroySequence(); |
| 52 | void SatisfyDestroySequence(); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 53 | |
| 54 | SurfaceId surface_id_; |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 55 | gfx::Size surface_size_; |
| 56 | float surface_scale_; |
James Robinson | 1ae030a | 2014-11-07 08:32:47 -0800 | [diff] [blame] | 57 | SurfaceSequence destroy_sequence_; |
| 58 | SatisfyCallback satisfy_callback_; |
| 59 | RequireCallback require_callback_; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 60 | |
| 61 | DISALLOW_COPY_AND_ASSIGN(SurfaceLayer); |
| 62 | }; |
| 63 | |
| 64 | } // namespace cc |
| 65 | |
| 66 | #endif // CC_LAYERS_SURFACE_LAYER_H_ |