| 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 #include "content/browser/renderer_host/offscreen_canvas_provider_impl.h" | 5 #include "content/browser/renderer_host/offscreen_canvas_provider_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" | 8 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| 11 | 11 |
| 12 OffscreenCanvasProviderImpl::OffscreenCanvasProviderImpl( | 12 OffscreenCanvasProviderImpl::OffscreenCanvasProviderImpl( |
| 13 viz::FrameSinkManagerHost* frame_sink_manager_host, |
| 13 uint32_t renderer_client_id) | 14 uint32_t renderer_client_id) |
| 14 : renderer_client_id_(renderer_client_id) {} | 15 : frame_sink_manager_host_(frame_sink_manager_host), |
| 16 renderer_client_id_(renderer_client_id) {} |
| 15 | 17 |
| 16 OffscreenCanvasProviderImpl::~OffscreenCanvasProviderImpl() = default; | 18 OffscreenCanvasProviderImpl::~OffscreenCanvasProviderImpl() = default; |
| 17 | 19 |
| 18 void OffscreenCanvasProviderImpl::Add( | 20 void OffscreenCanvasProviderImpl::Add( |
| 19 blink::mojom::OffscreenCanvasProviderRequest request) { | 21 blink::mojom::OffscreenCanvasProviderRequest request) { |
| 20 bindings_.AddBinding(this, std::move(request)); | 22 bindings_.AddBinding(this, std::move(request)); |
| 21 } | 23 } |
| 22 | 24 |
| 23 void OffscreenCanvasProviderImpl::CreateOffscreenCanvasSurface( | 25 void OffscreenCanvasProviderImpl::CreateOffscreenCanvasSurface( |
| 24 const cc::FrameSinkId& parent_frame_sink_id, | 26 const cc::FrameSinkId& parent_frame_sink_id, |
| 25 const cc::FrameSinkId& frame_sink_id, | 27 const cc::FrameSinkId& frame_sink_id, |
| 26 blink::mojom::OffscreenCanvasSurfaceClientPtr client, | 28 blink::mojom::OffscreenCanvasSurfaceClientPtr client, |
| 27 blink::mojom::OffscreenCanvasSurfaceRequest request) { | 29 blink::mojom::OffscreenCanvasSurfaceRequest request) { |
| 28 // TODO(kylechar): Kill the renderer too. | 30 // TODO(kylechar): Kill the renderer too. |
| 29 if (parent_frame_sink_id.client_id() != renderer_client_id_) { | 31 if (parent_frame_sink_id.client_id() != renderer_client_id_) { |
| 30 DLOG(ERROR) << "Invalid parent client id " << parent_frame_sink_id; | 32 DLOG(ERROR) << "Invalid parent client id " << parent_frame_sink_id; |
| 31 return; | 33 return; |
| 32 } | 34 } |
| 33 if (frame_sink_id.client_id() != renderer_client_id_) { | 35 if (frame_sink_id.client_id() != renderer_client_id_) { |
| 34 DLOG(ERROR) << "Invalid client id " << frame_sink_id; | 36 DLOG(ERROR) << "Invalid client id " << frame_sink_id; |
| 35 return; | 37 return; |
| 36 } | 38 } |
| 37 | 39 |
| 38 auto destroy_callback = base::BindOnce( | 40 auto destroy_callback = base::BindOnce( |
| 39 &OffscreenCanvasProviderImpl::DestroyOffscreenCanvasSurface, | 41 &OffscreenCanvasProviderImpl::DestroyOffscreenCanvasSurface, |
| 40 base::Unretained(this), frame_sink_id); | 42 base::Unretained(this), frame_sink_id); |
| 41 | 43 |
| 42 canvas_map_[frame_sink_id] = base::MakeUnique<OffscreenCanvasSurfaceImpl>( | 44 canvas_map_[frame_sink_id] = base::MakeUnique<OffscreenCanvasSurfaceImpl>( |
| 43 parent_frame_sink_id, frame_sink_id, std::move(client), | 45 frame_sink_manager_host_, parent_frame_sink_id, frame_sink_id, |
| 44 std::move(request), std::move(destroy_callback)); | 46 std::move(client), std::move(request), std::move(destroy_callback)); |
| 45 } | 47 } |
| 46 | 48 |
| 47 void OffscreenCanvasProviderImpl::CreateCompositorFrameSink( | 49 void OffscreenCanvasProviderImpl::CreateCompositorFrameSink( |
| 48 const cc::FrameSinkId& frame_sink_id, | 50 const cc::FrameSinkId& frame_sink_id, |
| 49 cc::mojom::MojoCompositorFrameSinkClientPtr client, | 51 cc::mojom::MojoCompositorFrameSinkClientPtr client, |
| 50 cc::mojom::MojoCompositorFrameSinkRequest request) { | 52 cc::mojom::MojoCompositorFrameSinkRequest request) { |
| 51 // TODO(kylechar): Kill the renderer too. | 53 // TODO(kylechar): Kill the renderer too. |
| 52 if (frame_sink_id.client_id() != renderer_client_id_) { | 54 if (frame_sink_id.client_id() != renderer_client_id_) { |
| 53 DLOG(ERROR) << "Invalid client id " << frame_sink_id; | 55 DLOG(ERROR) << "Invalid client id " << frame_sink_id; |
| 54 return; | 56 return; |
| 55 } | 57 } |
| 56 | 58 |
| 57 auto iter = canvas_map_.find(frame_sink_id); | 59 auto iter = canvas_map_.find(frame_sink_id); |
| 58 if (iter == canvas_map_.end()) { | 60 if (iter == canvas_map_.end()) { |
| 59 DLOG(ERROR) << "No OffscreenCanvasSurfaceImpl for " << frame_sink_id; | 61 DLOG(ERROR) << "No OffscreenCanvasSurfaceImpl for " << frame_sink_id; |
| 60 return; | 62 return; |
| 61 } | 63 } |
| 62 | 64 |
| 63 iter->second->CreateCompositorFrameSink(std::move(client), | 65 iter->second->CreateCompositorFrameSink(std::move(client), |
| 64 std::move(request)); | 66 std::move(request)); |
| 65 } | 67 } |
| 66 | 68 |
| 67 void OffscreenCanvasProviderImpl::DestroyOffscreenCanvasSurface( | 69 void OffscreenCanvasProviderImpl::DestroyOffscreenCanvasSurface( |
| 68 cc::FrameSinkId frame_sink_id) { | 70 cc::FrameSinkId frame_sink_id) { |
| 69 canvas_map_.erase(frame_sink_id); | 71 canvas_map_.erase(frame_sink_id); |
| 70 } | 72 } |
| 71 | 73 |
| 72 } // namespace content | 74 } // namespace content |
| OLD | NEW |