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