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" |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 } | 27 } |
28 | 28 |
29 // static | 29 // static |
30 void OffscreenCanvasSurfaceImpl::Create( | 30 void OffscreenCanvasSurfaceImpl::Create( |
31 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) { | 31 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) { |
32 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasSurfaceImpl>(), | 32 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasSurfaceImpl>(), |
33 std::move(request)); | 33 std::move(request)); |
34 } | 34 } |
35 | 35 |
36 void OffscreenCanvasSurfaceImpl::GetSurfaceId(GetSurfaceIdCallback callback) { | 36 void OffscreenCanvasSurfaceImpl::GetSurfaceId( |
| 37 blink::mojom::OffscreenCanvasSurfaceClientPtr client, |
| 38 GetSurfaceIdCallback callback) { |
37 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 39 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
38 if (frame_sink_id_.is_valid()) { | 40 if (frame_sink_id_.is_valid()) { |
39 // This IPC should be only called once for each HTMLCanvasElement. In this | 41 // This IPC should be only called once for each HTMLCanvasElement. In this |
40 // case, frame_sink_id_ is still unset. | 42 // case, frame_sink_id_ is still unset. |
41 // As the browser makes no assumption of correct behavior of renderer, in | 43 // 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 | 44 // an unwanted situation when this function is invoked twice, we need to |
43 // unregister the instance from manager. | 45 // unregister the instance from manager. |
44 OffscreenCanvasSurfaceManager::GetInstance() | 46 OffscreenCanvasSurfaceManager::GetInstance() |
45 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_); | 47 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_); |
46 mojo::ReportBadMessage( | 48 mojo::ReportBadMessage( |
47 "The same OffscreenCanvasSurfaceImpl is registered to " | 49 "The same OffscreenCanvasSurfaceImpl is registered to " |
48 "OffscreenCanvasSurfaceManager twice."); | 50 "OffscreenCanvasSurfaceManager twice."); |
49 } | 51 } |
50 | 52 |
| 53 client_ = std::move(client); |
51 frame_sink_id_ = AllocateFrameSinkId(); | 54 frame_sink_id_ = AllocateFrameSinkId(); |
52 cc::SurfaceId surface_id = | 55 cc::SurfaceId surface_id = |
53 cc::SurfaceId(frame_sink_id_, id_allocator_->GenerateId()); | 56 cc::SurfaceId(frame_sink_id_, GenerateLocalFrameId()); |
54 | 57 |
55 OffscreenCanvasSurfaceManager::GetInstance() | 58 OffscreenCanvasSurfaceManager::GetInstance() |
56 ->RegisterOffscreenCanvasSurfaceInstance(frame_sink_id_, this); | 59 ->RegisterOffscreenCanvasSurfaceInstance(frame_sink_id_, this); |
57 | 60 |
58 std::move(callback).Run(surface_id); | 61 std::move(callback).Run(surface_id); |
59 } | 62 } |
60 | 63 |
61 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, | 64 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, |
62 const cc::SurfaceSequence& sequence) { | 65 const cc::SurfaceSequence& sequence) { |
63 cc::SurfaceManager* manager = GetSurfaceManager(); | 66 cc::SurfaceManager* manager = GetSurfaceManager(); |
64 cc::Surface* surface = manager->GetSurfaceForId(surface_id); | 67 cc::Surface* surface = manager->GetSurfaceForId(surface_id); |
65 if (!surface) { | 68 if (!surface) { |
66 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; | 69 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; |
67 return; | 70 return; |
68 } | 71 } |
69 surface->AddDestructionDependency(sequence); | 72 surface->AddDestructionDependency(sequence); |
70 } | 73 } |
71 | 74 |
72 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { | 75 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { |
73 std::vector<uint32_t> sequences; | 76 std::vector<uint32_t> sequences; |
74 sequences.push_back(sequence.sequence); | 77 sequences.push_back(sequence.sequence); |
75 cc::SurfaceManager* manager = GetSurfaceManager(); | 78 cc::SurfaceManager* manager = GetSurfaceManager(); |
76 manager->DidSatisfySequences(sequence.frame_sink_id, &sequences); | 79 manager->DidSatisfySequences(sequence.frame_sink_id, &sequences); |
77 } | 80 } |
78 | 81 |
| 82 void OffscreenCanvasSurfaceImpl::OnSurfaceSizeChanged( |
| 83 const cc::SurfaceId& surface_id, |
| 84 gfx::Size new_surface_size) { |
| 85 client_->OnSurfaceSizeChanged(surface_id, new_surface_size.width(), |
| 86 new_surface_size.height()); |
| 87 } |
| 88 |
79 } // namespace content | 89 } // namespace content |
OLD | NEW |