OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "cc/surfaces/display.h" | 5 #include "cc/surfaces/display.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 const RendererSettings& settings, | 35 const RendererSettings& settings, |
36 const FrameSinkId& frame_sink_id, | 36 const FrameSinkId& frame_sink_id, |
37 std::unique_ptr<BeginFrameSource> begin_frame_source, | 37 std::unique_ptr<BeginFrameSource> begin_frame_source, |
38 std::unique_ptr<OutputSurface> output_surface, | 38 std::unique_ptr<OutputSurface> output_surface, |
39 std::unique_ptr<DisplayScheduler> scheduler, | 39 std::unique_ptr<DisplayScheduler> scheduler, |
40 std::unique_ptr<TextureMailboxDeleter> texture_mailbox_deleter) | 40 std::unique_ptr<TextureMailboxDeleter> texture_mailbox_deleter) |
41 : bitmap_manager_(bitmap_manager), | 41 : bitmap_manager_(bitmap_manager), |
42 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 42 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
43 settings_(settings), | 43 settings_(settings), |
44 frame_sink_id_(frame_sink_id), | 44 frame_sink_id_(frame_sink_id), |
45 begin_frame_source_(std::move(begin_frame_source)), | 45 begin_frame_source_( |
| 46 new DisplayBeginFrameSource(std::move(begin_frame_source))), |
46 output_surface_(std::move(output_surface)), | 47 output_surface_(std::move(output_surface)), |
47 scheduler_(std::move(scheduler)), | 48 scheduler_(std::move(scheduler)), |
48 texture_mailbox_deleter_(std::move(texture_mailbox_deleter)) { | 49 texture_mailbox_deleter_(std::move(texture_mailbox_deleter)) { |
49 DCHECK(output_surface_); | 50 DCHECK(output_surface_); |
50 DCHECK_EQ(!scheduler_, !begin_frame_source_); | 51 DCHECK_EQ(!scheduler_, !begin_frame_source_->GetWrappedSource()); |
51 DCHECK(frame_sink_id_.is_valid()); | 52 DCHECK(frame_sink_id_.is_valid()); |
52 if (scheduler_) | 53 if (scheduler_) { |
53 scheduler_->SetClient(this); | 54 scheduler_->SetClient(this); |
| 55 scheduler_->SetBeginFrameSource(begin_frame_source_.get()); |
| 56 } |
54 } | 57 } |
55 | 58 |
56 Display::~Display() { | 59 Display::~Display() { |
57 // Only do this if Initialize() happened. | 60 // Only do this if Initialize() happened. |
58 if (client_) { | 61 if (client_) { |
59 if (auto* context = output_surface_->context_provider()) | 62 if (auto* context = output_surface_->context_provider()) |
60 context->SetLostContextCallback(base::Closure()); | 63 context->SetLostContextCallback(base::Closure()); |
61 if (begin_frame_source_) | 64 surface_manager_->UnregisterBeginFrameSource(begin_frame_source_.get()); |
62 surface_manager_->UnregisterBeginFrameSource(begin_frame_source_.get()); | |
63 surface_manager_->RemoveObserver(this); | 65 surface_manager_->RemoveObserver(this); |
64 } | 66 } |
65 if (aggregator_) { | 67 if (aggregator_) { |
66 for (const auto& id_entry : aggregator_->previous_contained_surfaces()) { | 68 for (const auto& id_entry : aggregator_->previous_contained_surfaces()) { |
67 Surface* surface = surface_manager_->GetSurfaceForId(id_entry.first); | 69 Surface* surface = surface_manager_->GetSurfaceForId(id_entry.first); |
68 if (surface) | 70 if (surface) |
69 surface->RunDrawCallbacks(); | 71 surface->RunDrawCallbacks(); |
70 } | 72 } |
71 } | 73 } |
72 } | 74 } |
73 | 75 |
74 void Display::Initialize(DisplayClient* client, | 76 void Display::Initialize(DisplayClient* client, |
75 SurfaceManager* surface_manager) { | 77 SurfaceManager* surface_manager) { |
76 DCHECK(client); | 78 DCHECK(client); |
77 DCHECK(surface_manager); | 79 DCHECK(surface_manager); |
78 client_ = client; | 80 client_ = client; |
79 surface_manager_ = surface_manager; | 81 surface_manager_ = surface_manager; |
80 | 82 |
81 surface_manager_->AddObserver(this); | 83 surface_manager_->AddObserver(this); |
82 | 84 |
83 // This must be done in Initialize() so that the caller can delay this until | 85 // This must be done in Initialize() so that the caller can delay this until |
84 // they are ready to receive a BeginFrameSource. | 86 // they are ready to receive a BeginFrameSource. |
85 if (begin_frame_source_) { | 87 surface_manager_->RegisterBeginFrameSource(begin_frame_source_.get(), |
86 surface_manager_->RegisterBeginFrameSource(begin_frame_source_.get(), | 88 frame_sink_id_); |
87 frame_sink_id_); | |
88 } | |
89 | 89 |
90 output_surface_->BindToClient(this); | 90 output_surface_->BindToClient(this); |
91 InitializeRenderer(); | 91 InitializeRenderer(); |
92 | 92 |
93 if (auto* context = output_surface_->context_provider()) { | 93 if (auto* context = output_surface_->context_provider()) { |
94 // This depends on assumptions that Display::Initialize will happen | 94 // This depends on assumptions that Display::Initialize will happen |
95 // on the same callstack as the ContextProvider being created/initialized | 95 // on the same callstack as the ContextProvider being created/initialized |
96 // or else it could miss a callback before setting this. | 96 // or else it could miss a callback before setting this. |
97 context->SetLostContextCallback(base::Bind( | 97 context->SetLostContextCallback(base::Bind( |
98 &Display::DidLoseContextProvider, | 98 &Display::DidLoseContextProvider, |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 396 |
397 const SurfaceId& Display::CurrentSurfaceId() { | 397 const SurfaceId& Display::CurrentSurfaceId() { |
398 return current_surface_id_; | 398 return current_surface_id_; |
399 } | 399 } |
400 | 400 |
401 void Display::ForceImmediateDrawAndSwapIfPossible() { | 401 void Display::ForceImmediateDrawAndSwapIfPossible() { |
402 if (scheduler_) | 402 if (scheduler_) |
403 scheduler_->ForceImmediateSwapIfPossible(); | 403 scheduler_->ForceImmediateSwapIfPossible(); |
404 } | 404 } |
405 | 405 |
| 406 void Display::SwapBeginFrameSource( |
| 407 std::unique_ptr<BeginFrameSource>* begin_frame_source) { |
| 408 begin_frame_source_->SwapWrappedSource(begin_frame_source); |
| 409 } |
| 410 |
406 } // namespace cc | 411 } // namespace cc |
OLD | NEW |