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

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

Issue 2584643002: Revamp OffscreenCanvas commit flow (Closed)
Patch Set: Furnish 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" 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,
37 const cc::FrameSinkId& frame_sink_id) {
38 if (frame_sink_id_.is_valid()) { 38 if (frame_sink_id_.is_valid()) {
39 // This IPC should be only called once for each HTMLCanvasElement. In this 39 // This IPC should be only called once for each HTMLCanvasElement. In this
40 // case, frame_sink_id_ is still unset. 40 // case, frame_sink_id_ is still unset.
41 // As the browser makes no assumption of correct behavior of renderer, in 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 42 // an unwanted situation when this function is invoked twice, we ignore
43 // unregister the instance from manager. 43 // the second call.
44 OffscreenCanvasSurfaceManager::GetInstance()
45 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_);
46 mojo::ReportBadMessage( 44 mojo::ReportBadMessage(
47 "The same OffscreenCanvasSurfaceImpl is registered to " 45 "The same OffscreenCanvasSurfaceImpl sets client "
48 "OffscreenCanvasSurfaceManager twice."); 46 "twice.");
47 return;
49 } 48 }
50 49 client_ = std::move(client);
51 frame_sink_id_ = AllocateFrameSinkId(); 50 frame_sink_id_ = frame_sink_id;
52 cc::SurfaceId surface_id =
53 cc::SurfaceId(frame_sink_id_, id_allocator_->GenerateId());
54 51
55 OffscreenCanvasSurfaceManager::GetInstance() 52 OffscreenCanvasSurfaceManager::GetInstance()
56 ->RegisterOffscreenCanvasSurfaceInstance(frame_sink_id_, this); 53 ->RegisterOffscreenCanvasSurfaceInstance(frame_sink_id_, this);
54 }
57 55
58 std::move(callback).Run(surface_id); 56 void OffscreenCanvasSurfaceImpl::OnSurfaceCreated(
57 const cc::SurfaceId& surface_id,
58 const gfx::Size& frame_size,
59 float device_scale_factor) {
60 DCHECK_EQ(surface_id.frame_sink_id(), frame_sink_id_);
61 if (!current_local_frame_id_.is_valid() ||
62 surface_id.local_frame_id() != current_local_frame_id_) {
63 current_local_frame_id_ = surface_id.local_frame_id();
64 if (client_) {
65 client_->OnSurfaceCreated(surface_id, frame_size.width(),
66 frame_size.height(), device_scale_factor);
67 }
68 }
59 } 69 }
60 70
61 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, 71 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id,
62 const cc::SurfaceSequence& sequence) { 72 const cc::SurfaceSequence& sequence) {
63 cc::SurfaceManager* manager = GetSurfaceManager(); 73 cc::SurfaceManager* manager = GetSurfaceManager();
64 cc::Surface* surface = manager->GetSurfaceForId(surface_id); 74 cc::Surface* surface = manager->GetSurfaceForId(surface_id);
65 if (!surface) { 75 if (!surface) {
66 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; 76 DLOG(ERROR) << "Attempting to require callback on nonexistent surface";
67 return; 77 return;
68 } 78 }
69 surface->AddDestructionDependency(sequence); 79 surface->AddDestructionDependency(sequence);
70 } 80 }
71 81
72 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { 82 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) {
73 std::vector<uint32_t> sequences; 83 std::vector<uint32_t> sequences;
74 sequences.push_back(sequence.sequence); 84 sequences.push_back(sequence.sequence);
75 cc::SurfaceManager* manager = GetSurfaceManager(); 85 cc::SurfaceManager* manager = GetSurfaceManager();
76 manager->DidSatisfySequences(sequence.frame_sink_id, &sequences); 86 manager->DidSatisfySequences(sequence.frame_sink_id, &sequences);
77 } 87 }
78 88
79 } // namespace content 89 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698