| 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_surface_impl.h" | 5 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "cc/surfaces/surface.h" | 11 #include "cc/surfaces/surface.h" |
| 12 #include "cc/surfaces/surface_manager.h" | 12 #include "cc/surfaces/surface_manager.h" |
| 13 #include "content/browser/compositor/surface_utils.h" | 13 #include "content/browser/compositor/surface_utils.h" |
| 14 #include "content/browser/renderer_host/offscreen_canvas_surface_manager.h" | 14 #include "content/browser/renderer_host/offscreen_canvas_surface_manager.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 OffscreenCanvasSurfaceImpl::OffscreenCanvasSurfaceImpl( | 19 OffscreenCanvasSurfaceImpl::OffscreenCanvasSurfaceImpl( |
| 20 const cc::FrameSinkId& parent_frame_sink_id, |
| 20 const cc::FrameSinkId& frame_sink_id, | 21 const cc::FrameSinkId& frame_sink_id, |
| 21 blink::mojom::OffscreenCanvasSurfaceClientPtr client) | 22 blink::mojom::OffscreenCanvasSurfaceClientPtr client) |
| 22 : client_(std::move(client)), frame_sink_id_(frame_sink_id) { | 23 : client_(std::move(client)), |
| 24 frame_sink_id_(frame_sink_id), |
| 25 parent_frame_sink_id_(parent_frame_sink_id) { |
| 23 OffscreenCanvasSurfaceManager::GetInstance() | 26 OffscreenCanvasSurfaceManager::GetInstance() |
| 24 ->RegisterOffscreenCanvasSurfaceInstance(frame_sink_id_, this); | 27 ->RegisterOffscreenCanvasSurfaceInstance(frame_sink_id_, this); |
| 25 } | 28 } |
| 26 | 29 |
| 27 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() { | 30 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() { |
| 28 if (frame_sink_id_.is_valid()) { | 31 if (frame_sink_id_.is_valid()) { |
| 29 OffscreenCanvasSurfaceManager::GetInstance() | 32 OffscreenCanvasSurfaceManager::GetInstance() |
| 30 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_); | 33 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_); |
| 31 } | 34 } |
| 32 } | 35 } |
| 33 | 36 |
| 34 // static | 37 // static |
| 35 void OffscreenCanvasSurfaceImpl::Create( | 38 void OffscreenCanvasSurfaceImpl::Create( |
| 39 const cc::FrameSinkId& parent_frame_sink_id, |
| 36 const cc::FrameSinkId& frame_sink_id, | 40 const cc::FrameSinkId& frame_sink_id, |
| 37 blink::mojom::OffscreenCanvasSurfaceClientPtr client, | 41 blink::mojom::OffscreenCanvasSurfaceClientPtr client, |
| 38 blink::mojom::OffscreenCanvasSurfaceRequest request) { | 42 blink::mojom::OffscreenCanvasSurfaceRequest request) { |
| 39 std::unique_ptr<OffscreenCanvasSurfaceImpl> impl = | 43 std::unique_ptr<OffscreenCanvasSurfaceImpl> impl = |
| 40 base::MakeUnique<OffscreenCanvasSurfaceImpl>(frame_sink_id, | 44 base::MakeUnique<OffscreenCanvasSurfaceImpl>( |
| 41 std::move(client)); | 45 parent_frame_sink_id, frame_sink_id, std::move(client)); |
| 42 OffscreenCanvasSurfaceImpl* surface_service = impl.get(); | 46 OffscreenCanvasSurfaceImpl* surface_service = impl.get(); |
| 43 surface_service->binding_ = | 47 surface_service->binding_ = |
| 44 mojo::MakeStrongBinding(std::move(impl), std::move(request)); | 48 mojo::MakeStrongBinding(std::move(impl), std::move(request)); |
| 45 } | 49 } |
| 46 | 50 |
| 47 void OffscreenCanvasSurfaceImpl::OnSurfaceCreated( | 51 void OffscreenCanvasSurfaceImpl::OnSurfaceCreated( |
| 48 const cc::SurfaceInfo& surface_info) { | 52 const cc::SurfaceInfo& surface_info) { |
| 49 DCHECK_EQ(surface_info.id().frame_sink_id(), frame_sink_id_); | 53 DCHECK_EQ(surface_info.id().frame_sink_id(), frame_sink_id_); |
| 50 if (!current_local_frame_id_.is_valid() || | 54 if (!current_local_frame_id_.is_valid() || |
| 51 surface_info.id().local_frame_id() != current_local_frame_id_) { | 55 surface_info.id().local_frame_id() != current_local_frame_id_) { |
| 52 current_local_frame_id_ = surface_info.id().local_frame_id(); | 56 current_local_frame_id_ = surface_info.id().local_frame_id(); |
| 53 if (client_) | 57 if (client_) |
| 54 client_->OnSurfaceCreated(surface_info); | 58 client_->OnSurfaceCreated(surface_info); |
| 55 } | 59 } |
| 56 } | 60 } |
| 57 | 61 |
| 58 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, | 62 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, |
| 59 const cc::SurfaceSequence& sequence) { | 63 const cc::SurfaceSequence& sequence) { |
| 60 GetSurfaceManager()->RequireSequence(surface_id, sequence); | 64 GetSurfaceManager()->RequireSequence(surface_id, sequence); |
| 61 } | 65 } |
| 62 | 66 |
| 63 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { | 67 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { |
| 64 GetSurfaceManager()->SatisfySequence(sequence); | 68 GetSurfaceManager()->SatisfySequence(sequence); |
| 65 } | 69 } |
| 66 | 70 |
| 67 } // namespace content | 71 } // namespace content |
| OLD | NEW |