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

Side by Side Diff: components/mus/surfaces/top_level_display_client.cc

Issue 1976663003: Pull parts of TopLevelDisplayClient into DisplayCompositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: RegisterSurfaceIdNamespace Created 4 years, 7 months 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 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/threading/thread_task_runner_handle.h" 8 #include "cc/output/output_surface.h"
9 #include "cc/output/compositor_frame.h"
10 #include "cc/output/copy_output_request.h"
11 #include "cc/scheduler/begin_frame_source.h"
12 #include "cc/surfaces/display.h" 9 #include "cc/surfaces/display.h"
13 #include "cc/surfaces/display_scheduler.h"
14 #include "cc/surfaces/surface.h"
15 #include "components/mus/gles2/gpu_state.h"
16 #include "components/mus/surfaces/direct_output_surface.h"
17 #include "components/mus/surfaces/surfaces_context_provider.h"
18 #include "components/mus/surfaces/surfaces_state.h"
19 10
20 #if defined(USE_OZONE) 11 namespace mus {
21 #include "components/mus/surfaces/direct_output_surface_ozone.h"
22 #include "gpu/command_buffer/client/gles2_interface.h"
23 #endif
24 12
25 namespace base { 13 TopLevelDisplayClient::TopLevelDisplayClient(
26 class SingleThreadTaskRunner; 14 std::unique_ptr<cc::OutputSurface> output_surface,
15 cc::SurfaceManager* surface_manager,
16 cc::SharedBitmapManager* bitmap_manager,
17 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
18 const cc::RendererSettings& settings,
19 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
20 uint32_t compositor_surface_namespace)
21 : output_surface_(std::move(output_surface)),
22 task_runner_(task_runner),
23 display_(new cc::Display(this,
24 surface_manager,
25 bitmap_manager,
26 gpu_memory_buffer_manager,
27 settings,
28 compositor_surface_namespace)) {}
29
30 TopLevelDisplayClient::~TopLevelDisplayClient() {
27 } 31 }
28 32
29 namespace mus { 33 bool TopLevelDisplayClient::Initialize() {
30 namespace { 34 DCHECK(output_surface_);
31 void CallCallback(const base::Closure& callback, cc::SurfaceDrawStatus status) { 35 return display_->Initialize(std::move(output_surface_), task_runner_.get());
32 callback.Run();
33 }
34 }
35
36 TopLevelDisplayClient::TopLevelDisplayClient(
37 gfx::AcceleratedWidget widget,
38 const scoped_refptr<GpuState>& gpu_state,
39 const scoped_refptr<SurfacesState>& surfaces_state)
40 : task_runner_(base::ThreadTaskRunnerHandle::Get()),
41 surfaces_state_(surfaces_state),
42 factory_(surfaces_state->manager(), this),
43 cc_id_(static_cast<uint64_t>(surfaces_state->next_id_namespace()) << 32) {
44 factory_.Create(cc_id_);
45 surfaces_state_->manager()->RegisterSurfaceIdNamespace(cc_id_.id_namespace());
46
47 display_.reset(new cc::Display(this, surfaces_state_->manager(), nullptr,
48 nullptr, cc::RendererSettings(),
49 cc_id_.id_namespace()));
50
51 scoped_refptr<SurfacesContextProvider> surfaces_context_provider(
52 new SurfacesContextProvider(widget, gpu_state));
53 // TODO(rjkroege): If there is something better to do than CHECK, add it.
54 CHECK(surfaces_context_provider->BindToCurrentThread());
55
56 std::unique_ptr<cc::OutputSurface> output_surface;
57 if (surfaces_context_provider->ContextCapabilities().surfaceless) {
58 #if defined(USE_OZONE)
59 output_surface = base::WrapUnique(new DirectOutputSurfaceOzone(
60 surfaces_context_provider, widget, task_runner_.get(), GL_TEXTURE_2D,
61 GL_RGB));
62 #else
63 NOTREACHED();
64 #endif
65 } else {
66 output_surface = base::WrapUnique(
67 new DirectOutputSurface(surfaces_context_provider, task_runner_.get()));
68 }
69
70 int max_frames_pending = output_surface->capabilities().max_frames_pending;
71 DCHECK_GT(max_frames_pending, 0);
72
73 if (gpu_state->HardwareRenderingAvailable()) {
74 display_->Initialize(std::move(output_surface), task_runner_.get());
75 } else {
76 // TODO(rjkroege): Implement software compositing.
77 }
78 display_->Resize(last_submitted_frame_size_);
79
80 // TODO(fsamuel): Plumb the proper device scale factor.
81 display_->SetSurfaceId(cc_id_, 1.f /* device_scale_factor */);
82 }
83
84 TopLevelDisplayClient::~TopLevelDisplayClient() {
85 surfaces_state_->manager()->InvalidateSurfaceIdNamespace(
86 cc_id_.id_namespace());
87 factory_.Destroy(cc_id_);
88 }
89
90 void TopLevelDisplayClient::SubmitCompositorFrame(
91 std::unique_ptr<cc::CompositorFrame> frame,
92 const base::Closure& callback) {
93 pending_frame_ = std::move(frame);
94
95 last_submitted_frame_size_ =
96 pending_frame_->delegated_frame_data->render_pass_list.back()
97 ->output_rect.size();
98 display_->Resize(last_submitted_frame_size_);
99 factory_.SubmitCompositorFrame(cc_id_, std::move(pending_frame_),
100 base::Bind(&CallCallback, callback));
101 }
102
103 void TopLevelDisplayClient::RequestCopyOfOutput(
104 std::unique_ptr<cc::CopyOutputRequest> output_request) {
105 factory_.RequestCopyOfSurface(cc_id_, std::move(output_request));
106 } 36 }
107 37
108 void TopLevelDisplayClient::OutputSurfaceLost() { 38 void TopLevelDisplayClient::OutputSurfaceLost() {
109 if (!display_) // Shutdown case 39 if (!display_) // Shutdown case
110 return; 40 return;
111 display_.reset(); 41 display_.reset();
112 } 42 }
113 43
114 void TopLevelDisplayClient::SetMemoryPolicy( 44 void TopLevelDisplayClient::SetMemoryPolicy(
115 const cc::ManagedMemoryPolicy& policy) {} 45 const cc::ManagedMemoryPolicy& policy) {}
116 46
117 void TopLevelDisplayClient::ReturnResources(
118 const cc::ReturnedResourceArray& resources) {
119 // TODO(fsamuel): Implement this.
120 }
121
122 void TopLevelDisplayClient::SetBeginFrameSource(
123 cc::BeginFrameSource* begin_frame_source) {
124 // TODO(tansell): Implement this.
125 }
126
127 } // namespace mus 47 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/surfaces/top_level_display_client.h ('k') | components/mus/ws/platform_display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698