1 // Copyright 2016 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_SURFACE_LAYER_BRIDGE_H_
6 #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_SURFACE_LAYER_BRIDGE_H_
7 
8 #include <memory>
9 
10 #include "base/memory/scoped_refptr.h"
11 #include "base/time/time.h"
12 #include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
13 #include "components/viz/common/surfaces/surface_id.h"
14 #include "mojo/public/cpp/bindings/pending_receiver.h"
15 #include "mojo/public/cpp/bindings/receiver.h"
16 #include "third_party/blink/public/mojom/frame_sinks/embedded_frame_sink.mojom-blink.h"
17 #include "third_party/blink/public/platform/web_surface_layer_bridge.h"
18 #include "third_party/blink/renderer/platform/platform_export.h"
19 
20 namespace cc {
21 class SolidColorLayer;
22 class SurfaceLayer;
23 }  // namespace cc
24 
25 namespace blink {
26 
27 // The SurfaceLayerBridge facilitates communication about changes to a Surface
28 // between the Render and Browser processes.
29 class PLATFORM_EXPORT SurfaceLayerBridge
30     : public blink::mojom::blink::EmbeddedFrameSinkClient,
31       public blink::mojom::blink::SurfaceEmbedder,
32       public WebSurfaceLayerBridge {
33  public:
34   SurfaceLayerBridge(
35       viz::FrameSinkId parent_frame_sink_id,
36       WebSurfaceLayerBridgeObserver*,
37       cc::UpdateSubmissionStateCB update_submission_state_callback);
38   ~SurfaceLayerBridge() override;
39 
40   void CreateSolidColorLayer();
41 
42   // Implementation of blink::mojom::blink::EmbeddedFrameSinkClient
43   void BindSurfaceEmbedder(
44       mojo::PendingReceiver<mojom::blink::SurfaceEmbedder> receiver) override;
45 
46   void EmbedSurface(const viz::SurfaceId& surface_id);
47 
48   // Implementation of blink::mojom::blink::SurfaceEmbedder
49   void SetLocalSurfaceId(const viz::LocalSurfaceId& local_surface_id) override;
50 
51   // Implementation of WebSurfaceLayerBridge.
52   cc::Layer* GetCcLayer() const override;
53   const viz::FrameSinkId& GetFrameSinkId() const override;
54   void SetContentsOpaque(bool) override;
55   void CreateSurfaceLayer() override;
56   void ClearObserver() override;
57 
GetSurfaceId()58   const viz::SurfaceId& GetSurfaceId() const override {
59     return current_surface_id_;
60   }
61 
62   base::TimeTicks GetLocalSurfaceIdAllocationTime() const override;
63 
64  private:
65   scoped_refptr<cc::SurfaceLayer> surface_layer_;
66   scoped_refptr<cc::SolidColorLayer> solid_color_layer_;
67 
68   // The |observer_| handles unregistering the contents layer on its own.
69   WebSurfaceLayerBridgeObserver* observer_;
70   cc::UpdateSubmissionStateCB update_submission_state_callback_;
71   viz::ParentLocalSurfaceIdAllocator parent_local_surface_id_allocator_;
72   mojo::Receiver<blink::mojom::blink::EmbeddedFrameSinkClient> receiver_{this};
73   mojo::Receiver<blink::mojom::blink::SurfaceEmbedder>
74       surface_embedder_receiver_{this};
75 
76   const viz::FrameSinkId frame_sink_id_;
77   viz::SurfaceId current_surface_id_;
78   const viz::FrameSinkId parent_frame_sink_id_;
79   bool opaque_ = false;
80   bool surface_activated_ = false;
81 };
82 
83 }  // namespace blink
84 
85 #endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_SURFACE_LAYER_BRIDGE_H_
86