Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: content/browser/renderer_host/offscreen_canvas_surface_impl.cc

Issue 2584643002: Revamp OffscreenCanvas commit flow (Closed)
Patch Set: rebase and fix conflict Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
16 15
17 namespace content { 16 namespace content {
18 17
19 OffscreenCanvasSurfaceImpl::OffscreenCanvasSurfaceImpl() 18 OffscreenCanvasSurfaceImpl::OffscreenCanvasSurfaceImpl(
20 : id_allocator_(new cc::SurfaceIdAllocator()) {} 19 const cc::FrameSinkId& frame_sink_id,
20 blink::mojom::OffscreenCanvasSurfaceClientPtr client)
21 : client_(std::move(client)), frame_sink_id_(frame_sink_id) {
22 OffscreenCanvasSurfaceManager::GetInstance()
23 ->RegisterOffscreenCanvasSurfaceInstance(frame_sink_id_, this);
24 }
21 25
22 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() { 26 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() {
23 if (frame_sink_id_.is_valid()) { 27 if (frame_sink_id_.is_valid()) {
24 OffscreenCanvasSurfaceManager::GetInstance() 28 OffscreenCanvasSurfaceManager::GetInstance()
25 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_); 29 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_);
26 } 30 }
27 } 31 }
28 32
29 // static 33 // static
30 void OffscreenCanvasSurfaceImpl::Create( 34 void OffscreenCanvasSurfaceImpl::Create(
31 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) { 35 const cc::FrameSinkId& frame_sink_id,
32 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasSurfaceImpl>(), 36 blink::mojom::OffscreenCanvasSurfaceClientPtr client,
33 std::move(request)); 37 blink::mojom::OffscreenCanvasSurfaceRequest request) {
38 std::unique_ptr<OffscreenCanvasSurfaceImpl> impl =
39 base::MakeUnique<OffscreenCanvasSurfaceImpl>(frame_sink_id,
40 std::move(client));
41 OffscreenCanvasSurfaceImpl* surface_service = impl.get();
42 surface_service->binding_ =
43 mojo::MakeStrongBinding(std::move(impl), std::move(request));
34 } 44 }
35 45
36 void OffscreenCanvasSurfaceImpl::GetSurfaceId(GetSurfaceIdCallback callback) { 46 void OffscreenCanvasSurfaceImpl::OnSurfaceCreated(
37 DCHECK_CURRENTLY_ON(BrowserThread::UI); 47 const cc::SurfaceId& surface_id,
38 if (frame_sink_id_.is_valid()) { 48 const gfx::Size& frame_size,
39 // This IPC should be only called once for each HTMLCanvasElement. In this 49 float device_scale_factor) {
40 // case, frame_sink_id_ is still unset. 50 DCHECK_EQ(surface_id.frame_sink_id(), frame_sink_id_);
41 // As the browser makes no assumption of correct behavior of renderer, in 51 if (!current_local_frame_id_.is_valid() ||
42 // an unwanted situation when this function is invoked twice, we need to 52 surface_id.local_frame_id() != current_local_frame_id_) {
43 // unregister the instance from manager. 53 current_local_frame_id_ = surface_id.local_frame_id();
44 OffscreenCanvasSurfaceManager::GetInstance() 54 if (client_) {
45 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_); 55 client_->OnSurfaceCreated(surface_id, frame_size.width(),
46 mojo::ReportBadMessage( 56 frame_size.height(), device_scale_factor);
47 "The same OffscreenCanvasSurfaceImpl is registered to " 57 }
48 "OffscreenCanvasSurfaceManager twice.");
49 } 58 }
50
51 frame_sink_id_ = AllocateFrameSinkId();
52 cc::SurfaceId surface_id =
53 cc::SurfaceId(frame_sink_id_, id_allocator_->GenerateId());
54
55 OffscreenCanvasSurfaceManager::GetInstance()
56 ->RegisterOffscreenCanvasSurfaceInstance(frame_sink_id_, this);
57
58 std::move(callback).Run(surface_id);
59 } 59 }
60 60
61 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, 61 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id,
62 const cc::SurfaceSequence& sequence) { 62 const cc::SurfaceSequence& sequence) {
63 cc::SurfaceManager* manager = GetSurfaceManager(); 63 cc::SurfaceManager* manager = GetSurfaceManager();
64 cc::Surface* surface = manager->GetSurfaceForId(surface_id); 64 cc::Surface* surface = manager->GetSurfaceForId(surface_id);
65 if (!surface) { 65 if (!surface) {
66 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; 66 DLOG(ERROR) << "Attempting to require callback on nonexistent surface";
67 return; 67 return;
68 } 68 }
69 surface->AddDestructionDependency(sequence); 69 surface->AddDestructionDependency(sequence);
70 } 70 }
71 71
72 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { 72 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) {
73 std::vector<uint32_t> sequences; 73 std::vector<uint32_t> sequences;
74 sequences.push_back(sequence.sequence); 74 sequences.push_back(sequence.sequence);
75 cc::SurfaceManager* manager = GetSurfaceManager(); 75 cc::SurfaceManager* manager = GetSurfaceManager();
76 manager->DidSatisfySequences(sequence.frame_sink_id, &sequences); 76 manager->DidSatisfySequences(sequence.frame_sink_id, &sequences);
77 } 77 }
78 78
79 } // namespace content 79 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698