| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/mus/surfaces/top_level_display_client.h" | 5 #include "components/mus/surfaces/top_level_display_client.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
| 9 #include "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
| 10 #include "cc/output/copy_output_request.h" | 10 #include "cc/output/copy_output_request.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 TopLevelDisplayClient::TopLevelDisplayClient( | 36 TopLevelDisplayClient::TopLevelDisplayClient( |
| 37 gfx::AcceleratedWidget widget, | 37 gfx::AcceleratedWidget widget, |
| 38 const scoped_refptr<GpuState>& gpu_state, | 38 const scoped_refptr<GpuState>& gpu_state, |
| 39 const scoped_refptr<SurfacesState>& surfaces_state) | 39 const scoped_refptr<SurfacesState>& surfaces_state) |
| 40 : task_runner_(base::ThreadTaskRunnerHandle::Get()), | 40 : task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 41 surfaces_state_(surfaces_state), | 41 surfaces_state_(surfaces_state), |
| 42 factory_(surfaces_state->manager(), this), | 42 factory_(surfaces_state->manager(), this), |
| 43 cc_id_(static_cast<uint64_t>(surfaces_state->next_id_namespace()) << 32) { | 43 cc_id_(static_cast<uint64_t>(surfaces_state->next_id_namespace()) << 32) { |
| 44 factory_.Create(cc_id_); | 44 factory_.Create(cc_id_); |
| 45 surfaces_state_->manager()->RegisterSurfaceIdNamespace(cc_id_.id_namespace()); |
| 45 | 46 |
| 46 display_.reset(new cc::Display(this, surfaces_state_->manager(), nullptr, | 47 display_.reset(new cc::Display(this, surfaces_state_->manager(), nullptr, |
| 47 nullptr, cc::RendererSettings())); | 48 nullptr, cc::RendererSettings(), |
| 49 cc_id_.id_namespace())); |
| 48 | 50 |
| 49 scoped_refptr<SurfacesContextProvider> surfaces_context_provider( | 51 scoped_refptr<SurfacesContextProvider> surfaces_context_provider( |
| 50 new SurfacesContextProvider(this, widget, gpu_state)); | 52 new SurfacesContextProvider(widget, gpu_state)); |
| 51 // TODO(rjkroege): If there is something better to do than CHECK, add it. | 53 // TODO(rjkroege): If there is something better to do than CHECK, add it. |
| 52 CHECK(surfaces_context_provider->BindToCurrentThread()); | 54 CHECK(surfaces_context_provider->BindToCurrentThread()); |
| 53 | 55 |
| 54 std::unique_ptr<cc::OutputSurface> output_surface; | 56 std::unique_ptr<cc::OutputSurface> output_surface; |
| 55 if (surfaces_context_provider->ContextCapabilities().gpu.surfaceless) { | 57 if (surfaces_context_provider->ContextCapabilities().gpu.surfaceless) { |
| 56 #if defined(USE_OZONE) | 58 #if defined(USE_OZONE) |
| 57 output_surface = base::WrapUnique(new DirectOutputSurfaceOzone( | 59 output_surface = base::WrapUnique(new DirectOutputSurfaceOzone( |
| 58 surfaces_context_provider, widget, GL_TEXTURE_2D, GL_RGB)); | 60 surfaces_context_provider, widget, task_runner_.get(), GL_TEXTURE_2D, |
| 61 GL_RGB)); |
| 59 #else | 62 #else |
| 60 NOTREACHED(); | 63 NOTREACHED(); |
| 61 #endif | 64 #endif |
| 62 } else { | 65 } else { |
| 63 output_surface = | 66 output_surface = base::WrapUnique( |
| 64 base::WrapUnique(new DirectOutputSurface(surfaces_context_provider)); | 67 new DirectOutputSurface(surfaces_context_provider, task_runner_.get())); |
| 65 } | 68 } |
| 66 | 69 |
| 67 int max_frames_pending = output_surface->capabilities().max_frames_pending; | 70 int max_frames_pending = output_surface->capabilities().max_frames_pending; |
| 68 DCHECK_GT(max_frames_pending, 0); | 71 DCHECK_GT(max_frames_pending, 0); |
| 69 | 72 |
| 70 synthetic_frame_source_.reset(new cc::SyntheticBeginFrameSource( | |
| 71 task_runner_.get(), cc::BeginFrameArgs::DefaultInterval())); | |
| 72 | |
| 73 scheduler_.reset( | |
| 74 new cc::DisplayScheduler(display_.get(), synthetic_frame_source_.get(), | |
| 75 task_runner_.get(), max_frames_pending)); | |
| 76 | |
| 77 if (gpu_state->HardwareRenderingAvailable()) { | 73 if (gpu_state->HardwareRenderingAvailable()) { |
| 78 display_->Initialize(std::move(output_surface), scheduler_.get()); | 74 display_->Initialize(std::move(output_surface), task_runner_.get()); |
| 79 } else { | 75 } else { |
| 80 // TODO(rjkroege): Implement software compositing. | 76 // TODO(rjkroege): Implement software compositing. |
| 81 } | 77 } |
| 82 display_->Resize(last_submitted_frame_size_); | 78 display_->Resize(last_submitted_frame_size_); |
| 83 | 79 |
| 84 // TODO(fsamuel): Plumb the proper device scale factor. | 80 // TODO(fsamuel): Plumb the proper device scale factor. |
| 85 display_->SetSurfaceId(cc_id_, 1.f /* device_scale_factor */); | 81 display_->SetSurfaceId(cc_id_, 1.f /* device_scale_factor */); |
| 86 } | 82 } |
| 87 | 83 |
| 88 TopLevelDisplayClient::~TopLevelDisplayClient() { | 84 TopLevelDisplayClient::~TopLevelDisplayClient() { |
| 85 surfaces_state_->manager()->InvalidateSurfaceIdNamespace( |
| 86 cc_id_.id_namespace()); |
| 89 factory_.Destroy(cc_id_); | 87 factory_.Destroy(cc_id_); |
| 90 } | 88 } |
| 91 | 89 |
| 92 void TopLevelDisplayClient::SubmitCompositorFrame( | 90 void TopLevelDisplayClient::SubmitCompositorFrame( |
| 93 std::unique_ptr<cc::CompositorFrame> frame, | 91 std::unique_ptr<cc::CompositorFrame> frame, |
| 94 const base::Closure& callback) { | 92 const base::Closure& callback) { |
| 95 pending_frame_ = std::move(frame); | 93 pending_frame_ = std::move(frame); |
| 96 | 94 |
| 97 last_submitted_frame_size_ = | 95 last_submitted_frame_size_ = |
| 98 pending_frame_->delegated_frame_data->render_pass_list.back() | 96 pending_frame_->delegated_frame_data->render_pass_list.back() |
| 99 ->output_rect.size(); | 97 ->output_rect.size(); |
| 100 display_->Resize(last_submitted_frame_size_); | 98 display_->Resize(last_submitted_frame_size_); |
| 101 factory_.SubmitCompositorFrame(cc_id_, std::move(pending_frame_), | 99 factory_.SubmitCompositorFrame(cc_id_, std::move(pending_frame_), |
| 102 base::Bind(&CallCallback, callback)); | 100 base::Bind(&CallCallback, callback)); |
| 103 } | 101 } |
| 104 | 102 |
| 105 void TopLevelDisplayClient::RequestCopyOfOutput( | 103 void TopLevelDisplayClient::RequestCopyOfOutput( |
| 106 std::unique_ptr<cc::CopyOutputRequest> output_request) { | 104 std::unique_ptr<cc::CopyOutputRequest> output_request) { |
| 107 factory_.RequestCopyOfSurface(cc_id_, std::move(output_request)); | 105 factory_.RequestCopyOfSurface(cc_id_, std::move(output_request)); |
| 108 } | 106 } |
| 109 | 107 |
| 110 void TopLevelDisplayClient::CommitVSyncParameters(base::TimeTicks timebase, | |
| 111 base::TimeDelta interval) {} | |
| 112 | |
| 113 void TopLevelDisplayClient::OutputSurfaceLost() { | 108 void TopLevelDisplayClient::OutputSurfaceLost() { |
| 114 if (!display_) // Shutdown case | 109 if (!display_) // Shutdown case |
| 115 return; | 110 return; |
| 116 display_.reset(); | 111 display_.reset(); |
| 117 } | 112 } |
| 118 | 113 |
| 119 void TopLevelDisplayClient::SetMemoryPolicy( | 114 void TopLevelDisplayClient::SetMemoryPolicy( |
| 120 const cc::ManagedMemoryPolicy& policy) {} | 115 const cc::ManagedMemoryPolicy& policy) {} |
| 121 | 116 |
| 122 void TopLevelDisplayClient::OnVSyncParametersUpdated(int64_t timebase, | |
| 123 int64_t interval) { | |
| 124 auto timebase_time_ticks = base::TimeTicks::FromInternalValue(timebase); | |
| 125 auto interval_time_delta = base::TimeDelta::FromInternalValue(interval); | |
| 126 | |
| 127 if (interval_time_delta.is_zero()) { | |
| 128 // TODO(brianderson): We should not be receiving 0 intervals. | |
| 129 interval_time_delta = cc::BeginFrameArgs::DefaultInterval(); | |
| 130 } | |
| 131 | |
| 132 synthetic_frame_source_->OnUpdateVSyncParameters(timebase_time_ticks, | |
| 133 interval_time_delta); | |
| 134 } | |
| 135 | |
| 136 void TopLevelDisplayClient::ReturnResources( | 117 void TopLevelDisplayClient::ReturnResources( |
| 137 const cc::ReturnedResourceArray& resources) { | 118 const cc::ReturnedResourceArray& resources) { |
| 138 // TODO(fsamuel): Implement this. | 119 // TODO(fsamuel): Implement this. |
| 139 } | 120 } |
| 140 | 121 |
| 141 void TopLevelDisplayClient::SetBeginFrameSource( | 122 void TopLevelDisplayClient::SetBeginFrameSource( |
| 142 cc::BeginFrameSource* begin_frame_source) { | 123 cc::BeginFrameSource* begin_frame_source) { |
| 143 // TODO(tansell): Implement this. | 124 // TODO(tansell): Implement this. |
| 144 } | 125 } |
| 145 | 126 |
| 146 } // namespace mus | 127 } // namespace mus |
| OLD | NEW |