| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_OFFSCREEN_CANVAS_SURFACE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_OFFSCREEN_CANVAS_SURFACE_IMPL_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_OFFSCREEN_CANVAS_SURFACE_IMPL_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_OFFSCREEN_CANVAS_SURFACE_IMPL_H_ |
| 7 | 7 |
| 8 #include "cc/surfaces/surface_id.h" | 8 #include "base/callback.h" |
| 9 #include "mojo/public/cpp/bindings/strong_binding.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "cc/surfaces/frame_sink_id.h" |
| 11 #include "cc/surfaces/surface_info.h" |
| 12 #include "content/browser/compositor/frame_sink_observer.h" |
| 13 #include "content/common/content_export.h" |
| 14 #include "mojo/public/cpp/bindings/binding.h" |
| 10 #include "third_party/WebKit/public/platform/modules/offscreencanvas/offscreen_c
anvas_surface.mojom.h" | 15 #include "third_party/WebKit/public/platform/modules/offscreencanvas/offscreen_c
anvas_surface.mojom.h" |
| 11 | 16 |
| 12 namespace content { | 17 namespace content { |
| 13 | 18 |
| 14 // The browser owned object for an offscreen canvas connection. Holds | 19 // The browser owned object for an offscreen canvas connection. Holds |
| 15 // connections to both the renderer and frame sink manager. | 20 // connections to both the renderer and frame sink manager. |
| 16 class CONTENT_EXPORT OffscreenCanvasSurfaceImpl | 21 class CONTENT_EXPORT OffscreenCanvasSurfaceImpl |
| 17 : public blink::mojom::OffscreenCanvasSurface { | 22 : public blink::mojom::OffscreenCanvasSurface, |
| 23 public NON_EXPORTED_BASE(FrameSinkObserver) { |
| 18 public: | 24 public: |
| 25 using DestroyCallback = base::OnceCallback<void()>; |
| 26 |
| 19 OffscreenCanvasSurfaceImpl( | 27 OffscreenCanvasSurfaceImpl( |
| 20 const cc::FrameSinkId& parent_frame_sink_id, | 28 const cc::FrameSinkId& parent_frame_sink_id, |
| 21 const cc::FrameSinkId& frame_sink_id, | 29 const cc::FrameSinkId& frame_sink_id, |
| 22 blink::mojom::OffscreenCanvasSurfaceClientPtr client); | 30 blink::mojom::OffscreenCanvasSurfaceClientPtr client, |
| 31 blink::mojom::OffscreenCanvasSurfaceRequest request, |
| 32 DestroyCallback destroy_callback); |
| 23 ~OffscreenCanvasSurfaceImpl() override; | 33 ~OffscreenCanvasSurfaceImpl() override; |
| 24 | 34 |
| 25 static void Create(const cc::FrameSinkId& parent_frame_sink_id, | 35 const cc::FrameSinkId& frame_sink_id() const { return frame_sink_id_; } |
| 26 const cc::FrameSinkId& frame_sink_id, | 36 |
| 27 blink::mojom::OffscreenCanvasSurfaceClientPtr client, | 37 const cc::FrameSinkId& parent_frame_sink_id() const { |
| 28 blink::mojom::OffscreenCanvasSurfaceRequest request); | 38 return parent_frame_sink_id_; |
| 39 } |
| 40 |
| 41 const cc::LocalSurfaceId& local_surface_id() const { |
| 42 return local_surface_id_; |
| 43 } |
| 29 | 44 |
| 30 // Creates a MojoCompositorFrameSink connection to FrameSinkManager for an | 45 // Creates a MojoCompositorFrameSink connection to FrameSinkManager for an |
| 31 // offscreen canvas client. The corresponding private interface will be owned | 46 // offscreen canvas client. The corresponding private interface will be owned |
| 32 // here to control CompositorFrameSink lifetime. This should only ever be | 47 // here to control CompositorFrameSink lifetime. This should only ever be |
| 33 // called once. | 48 // called once. |
| 34 void CreateCompositorFrameSink( | 49 void CreateCompositorFrameSink( |
| 35 cc::mojom::MojoCompositorFrameSinkClientPtr client, | 50 cc::mojom::MojoCompositorFrameSinkClientPtr client, |
| 36 cc::mojom::MojoCompositorFrameSinkRequest request); | 51 cc::mojom::MojoCompositorFrameSinkRequest request); |
| 37 | 52 |
| 38 void OnSurfaceCreated(const cc::SurfaceInfo& surface_info); | 53 // FrameSinkObserver implementation. |
| 54 void OnSurfaceCreated(const cc::SurfaceInfo& surface_info) override; |
| 39 | 55 |
| 40 // blink::mojom::OffscreenCanvasSurface implementation. | 56 // blink::mojom::OffscreenCanvasSurface implementation. |
| 41 void Require(const cc::SurfaceId& surface_id, | 57 void Require(const cc::SurfaceId& surface_id, |
| 42 const cc::SurfaceSequence& sequence) override; | 58 const cc::SurfaceSequence& sequence) override; |
| 43 void Satisfy(const cc::SurfaceSequence& sequence) override; | 59 void Satisfy(const cc::SurfaceSequence& sequence) override; |
| 44 | 60 |
| 45 const cc::FrameSinkId& frame_sink_id() const { return frame_sink_id_; } | 61 private: |
| 62 // Registered as a callback for when |binding_| is closed. Will call |
| 63 // |destroy_callback_|. |
| 64 void OnSurfaceConnectionClosed(); |
| 46 | 65 |
| 47 const cc::FrameSinkId& parent_frame_sink_id() const { | |
| 48 return parent_frame_sink_id_; | |
| 49 } | |
| 50 | |
| 51 const cc::LocalSurfaceId& current_local_surface_id() const { | |
| 52 return current_local_surface_id_; | |
| 53 } | |
| 54 | |
| 55 private: | |
| 56 blink::mojom::OffscreenCanvasSurfaceClientPtr client_; | 66 blink::mojom::OffscreenCanvasSurfaceClientPtr client_; |
| 57 mojo::StrongBindingPtr<blink::mojom::OffscreenCanvasSurface> binding_; | 67 mojo::Binding<blink::mojom::OffscreenCanvasSurface> binding_; |
| 58 | 68 |
| 59 // Private connection for the CompositorFrameSink. The CompositorFrameSink | 69 // Private connection for the CompositorFrameSink. The CompositorFrameSink |
| 60 // will not be destroyed until both private and offscreen canvas client | 70 // will not be destroyed until both private and offscreen canvas client |
| 61 // connections are closed. | 71 // connections are closed. |
| 62 cc::mojom::MojoCompositorFrameSinkPrivatePtr compositor_frame_sink_private_; | 72 cc::mojom::MojoCompositorFrameSinkPrivatePtr compositor_frame_sink_private_; |
| 63 | 73 |
| 74 // To be called if |binding_| is closed. |
| 75 DestroyCallback destroy_callback_; |
| 76 |
| 64 // Surface-related state | 77 // Surface-related state |
| 65 const cc::FrameSinkId frame_sink_id_; | 78 const cc::FrameSinkId frame_sink_id_; |
| 66 cc::LocalSurfaceId current_local_surface_id_; | 79 cc::LocalSurfaceId local_surface_id_; |
| 67 const cc::FrameSinkId parent_frame_sink_id_; | 80 const cc::FrameSinkId parent_frame_sink_id_; |
| 68 | 81 |
| 69 bool has_created_compositor_frame_sink_ = false; | 82 bool has_created_compositor_frame_sink_ = false; |
| 70 | 83 |
| 71 DISALLOW_COPY_AND_ASSIGN(OffscreenCanvasSurfaceImpl); | 84 DISALLOW_COPY_AND_ASSIGN(OffscreenCanvasSurfaceImpl); |
| 72 }; | 85 }; |
| 73 | 86 |
| 74 } // namespace content | 87 } // namespace content |
| 75 | 88 |
| 76 #endif // CONTENT_BROWSER_RENDERER_HOST_OFFSCREEN_CANVAS_SURFACE_IMPL_H_ | 89 #endif // CONTENT_BROWSER_RENDERER_HOST_OFFSCREEN_CANVAS_SURFACE_IMPL_H_ |
| OLD | NEW |