| 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" | 7 #include "base/bind.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" | 8 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" |
| 10 | 9 |
| 11 namespace content { | 10 namespace content { |
| 12 | 11 |
| 13 OffscreenCanvasProviderImpl::OffscreenCanvasProviderImpl( | 12 OffscreenCanvasProviderImpl::OffscreenCanvasProviderImpl( |
| 14 uint32_t renderer_client_id) | 13 uint32_t renderer_client_id) |
| 15 : renderer_client_id_(renderer_client_id) {} | 14 : renderer_client_id_(renderer_client_id) {} |
| 16 | 15 |
| 17 OffscreenCanvasProviderImpl::~OffscreenCanvasProviderImpl() = default; | 16 OffscreenCanvasProviderImpl::~OffscreenCanvasProviderImpl() = default; |
| 18 | 17 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 29 // TODO(kylechar): Kill the renderer too. | 28 // TODO(kylechar): Kill the renderer too. |
| 30 if (parent_frame_sink_id.client_id() != renderer_client_id_) { | 29 if (parent_frame_sink_id.client_id() != renderer_client_id_) { |
| 31 DLOG(ERROR) << "Invalid parent client id " << parent_frame_sink_id; | 30 DLOG(ERROR) << "Invalid parent client id " << parent_frame_sink_id; |
| 32 return; | 31 return; |
| 33 } | 32 } |
| 34 if (frame_sink_id.client_id() != renderer_client_id_) { | 33 if (frame_sink_id.client_id() != renderer_client_id_) { |
| 35 DLOG(ERROR) << "Invalid client id " << frame_sink_id; | 34 DLOG(ERROR) << "Invalid client id " << frame_sink_id; |
| 36 return; | 35 return; |
| 37 } | 36 } |
| 38 | 37 |
| 39 OffscreenCanvasSurfaceImpl::Create(parent_frame_sink_id, frame_sink_id, | 38 auto destroy_callback = base::BindOnce( |
| 40 std::move(client), std::move(request)); | 39 &OffscreenCanvasProviderImpl::DestroyOffscreenCanvasSurface, |
| 40 base::Unretained(this), frame_sink_id); |
| 41 |
| 42 canvas_map_[frame_sink_id] = base::MakeUnique<OffscreenCanvasSurfaceImpl>( |
| 43 parent_frame_sink_id, frame_sink_id, std::move(client), |
| 44 std::move(request), std::move(destroy_callback)); |
| 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 = canvas_map_.find(frame_sink_id); |
| 54 auto* manager = OffscreenCanvasCompositorFrameSinkManager::GetInstance(); | 58 if (iter == canvas_map_.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 |
| 67 void OffscreenCanvasProviderImpl::DestroyOffscreenCanvasSurface( |
| 68 cc::FrameSinkId frame_sink_id) { |
| 69 canvas_map_.erase(frame_sink_id); |
| 70 } |
| 71 |
| 65 } // namespace content | 72 } // namespace content |
| OLD | NEW |