1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_SLIM_SURFACE_LAYER_H_
6 #define CC_SLIM_SURFACE_LAYER_H_
8 #include "base/component_export.h"
9 #include "cc/layers/deadline_policy.h"
10 #include "cc/slim/layer.h"
11 #include "components/viz/common/surfaces/surface_id.h"
12 #include "components/viz/common/surfaces/surface_range.h"
13 #include "third_party/abseil-cpp/absl/types/optional.h"
21 // A layer that embeds content from another viz client.
22 class COMPONENT_EXPORT(CC_SLIM) SurfaceLayer : public Layer {
24 static scoped_refptr<SurfaceLayer> Create();
26 const viz::SurfaceId& surface_id() const;
28 // Set the surface id that this layer is embedding. `deadline_policy`
29 // specifies behavior and timeout for how long to wait for the surface to be
30 // ready to draw before giving up.
31 void SetSurfaceId(const viz::SurfaceId& surface_id,
32 const cc::DeadlinePolicy& deadline_policy);
34 // When stretch_content_to_fill_bounds is true, the scale of the embedded
35 // surface is ignored and the content will be stretched to fill the bounds.
36 void SetStretchContentToFillBounds(bool stretch_content_to_fill_bounds);
37 bool stretch_content_to_fill_bounds() const;
39 void SetMayContainVideo(bool may_contain_video);
41 // Set the oldest surface id that can be used as fallback assuming current
42 // surface being embedded isn't ready to be drawn yet (before first frame is
44 void SetOldestAcceptableFallback(const viz::SurfaceId& surface_id);
45 const absl::optional<viz::SurfaceId>& oldest_acceptable_fallback() const;
47 void SetLayerTree(LayerTree* layer_tree) override;
50 explicit SurfaceLayer(scoped_refptr<cc::SurfaceLayer> cc_layer);
51 ~SurfaceLayer() override;
53 cc::SurfaceLayer* cc_layer() const;
54 void SetSurfaceRange(const viz::SurfaceRange& surface_range);
56 // Layer implementation.
57 void AppendQuads(viz::CompositorRenderPass& render_pass,
59 const gfx::Transform& transform_to_root,
60 const gfx::Transform& transform_to_target,
61 const gfx::Rect* clip_in_target,
62 const gfx::Rect& visible_rect,
63 float opacity) override;
65 bool stretch_content_to_fill_bounds_ = false;
66 viz::SurfaceRange surface_range_;
67 absl::optional<uint32_t> deadline_in_frames_;
70 } // namespace cc::slim
72 #endif // CC_SLIM_SURFACE_LAYER_H_