| 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 "cc/surfaces/surface.h" | 10 #include "cc/surfaces/surface.h" |
| 11 #include "cc/surfaces/surface_manager.h" | 11 #include "cc/surfaces/surface_manager.h" |
| 12 #include "content/browser/compositor/surface_utils.h" | 12 #include "content/browser/compositor/surface_utils.h" |
| 13 #include "content/browser/renderer_host/offscreen_canvas_surface_manager.h" | 13 #include "content/browser/renderer_host/offscreen_canvas_surface_manager.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "mojo/public/cpp/bindings/strong_binding.h" | 15 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 OffscreenCanvasSurfaceImpl::OffscreenCanvasSurfaceImpl() | 19 OffscreenCanvasSurfaceImpl::OffscreenCanvasSurfaceImpl() {} |
| 20 : id_allocator_(new cc::SurfaceIdAllocator()) {} | |
| 21 | 20 |
| 22 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() { | 21 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() { |
| 23 if (frame_sink_id_.is_valid()) { | 22 if (frame_sink_id_.is_valid()) { |
| 24 OffscreenCanvasSurfaceManager::GetInstance() | 23 OffscreenCanvasSurfaceManager::GetInstance() |
| 25 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_); | 24 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_); |
| 26 } | 25 } |
| 27 } | 26 } |
| 28 | 27 |
| 29 // static | 28 // static |
| 30 void OffscreenCanvasSurfaceImpl::Create( | 29 void OffscreenCanvasSurfaceImpl::Create( |
| 31 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) { | 30 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) { |
| 32 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasSurfaceImpl>(), | 31 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasSurfaceImpl>(), |
| 33 std::move(request)); | 32 std::move(request)); |
| 34 } | 33 } |
| 35 | 34 |
| 36 void OffscreenCanvasSurfaceImpl::GetSurfaceId(GetSurfaceIdCallback callback) { | 35 void OffscreenCanvasSurfaceImpl::SetClient( |
| 37 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 36 blink::mojom::OffscreenCanvasSurfaceClientPtr client, |
| 38 if (frame_sink_id_.is_valid()) { | 37 const cc::FrameSinkId& frame_sink_id) { |
| 39 // This IPC should be only called once for each HTMLCanvasElement. In this | 38 client_ = std::move(client); |
| 40 // case, frame_sink_id_ is still unset. | 39 frame_sink_id_ = frame_sink_id; |
| 41 // As the browser makes no assumption of correct behavior of renderer, in | |
| 42 // an unwanted situation when this function is invoked twice, we need to | |
| 43 // unregister the instance from manager. | |
| 44 OffscreenCanvasSurfaceManager::GetInstance() | |
| 45 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_); | |
| 46 mojo::ReportBadMessage( | |
| 47 "The same OffscreenCanvasSurfaceImpl is registered to " | |
| 48 "OffscreenCanvasSurfaceManager twice."); | |
| 49 } | |
| 50 | |
| 51 frame_sink_id_ = AllocateFrameSinkId(); | |
| 52 cc::SurfaceId surface_id = | |
| 53 cc::SurfaceId(frame_sink_id_, id_allocator_->GenerateId()); | |
| 54 | 40 |
| 55 OffscreenCanvasSurfaceManager::GetInstance() | 41 OffscreenCanvasSurfaceManager::GetInstance() |
| 56 ->RegisterOffscreenCanvasSurfaceInstance(frame_sink_id_, this); | 42 ->RegisterOffscreenCanvasSurfaceInstance(frame_sink_id_, this); |
| 43 } |
| 57 | 44 |
| 58 std::move(callback).Run(surface_id); | 45 void OffscreenCanvasSurfaceImpl::OnSurfaceCreated( |
| 46 const cc::SurfaceId& surface_id, |
| 47 const gfx::Size& frame_size, |
| 48 float device_scale_factor) { |
| 49 if (client_) { |
| 50 client_->OnSurfaceCreated(surface_id, frame_size.width(), |
| 51 frame_size.height(), device_scale_factor); |
| 52 } |
| 59 } | 53 } |
| 60 | 54 |
| 61 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, | 55 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, |
| 62 const cc::SurfaceSequence& sequence) { | 56 const cc::SurfaceSequence& sequence) { |
| 63 cc::SurfaceManager* manager = GetSurfaceManager(); | 57 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 64 cc::Surface* surface = manager->GetSurfaceForId(surface_id); | 58 cc::Surface* surface = manager->GetSurfaceForId(surface_id); |
| 65 if (!surface) { | 59 if (!surface) { |
| 66 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; | 60 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; |
| 67 return; | 61 return; |
| 68 } | 62 } |
| 69 surface->AddDestructionDependency(sequence); | 63 surface->AddDestructionDependency(sequence); |
| 70 } | 64 } |
| 71 | 65 |
| 72 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { | 66 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { |
| 73 std::vector<uint32_t> sequences; | 67 std::vector<uint32_t> sequences; |
| 74 sequences.push_back(sequence.sequence); | 68 sequences.push_back(sequence.sequence); |
| 75 cc::SurfaceManager* manager = GetSurfaceManager(); | 69 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 76 manager->DidSatisfySequences(sequence.frame_sink_id, &sequences); | 70 manager->DidSatisfySequences(sequence.frame_sink_id, &sequences); |
| 77 } | 71 } |
| 78 | 72 |
| 79 } // namespace content | 73 } // namespace content |
| OLD | NEW |