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 "ui/compositor/test/in_process_context_factory.h" | 5 #include "ui/compositor/test/in_process_context_factory.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
11 #include "cc/output/context_provider.h" | 11 #include "cc/output/context_provider.h" |
12 #include "cc/output/output_surface_client.h" | 12 #include "cc/output/output_surface_client.h" |
13 #include "cc/surfaces/onscreen_display_client.h" | |
14 #include "cc/surfaces/surface_display_output_surface.h" | |
13 #include "cc/surfaces/surface_id_allocator.h" | 15 #include "cc/surfaces/surface_id_allocator.h" |
14 #include "cc/test/pixel_test_output_surface.h" | 16 #include "cc/test/pixel_test_output_surface.h" |
15 #include "cc/test/test_shared_bitmap_manager.h" | 17 #include "cc/test/test_shared_bitmap_manager.h" |
16 #include "gpu/command_buffer/client/context_support.h" | 18 #include "gpu/command_buffer/client/context_support.h" |
17 #include "gpu/command_buffer/client/gles2_interface.h" | 19 #include "gpu/command_buffer/client/gles2_interface.h" |
18 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 20 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
19 #include "ui/compositor/compositor_switches.h" | 21 #include "ui/compositor/compositor_switches.h" |
20 #include "ui/compositor/reflector.h" | 22 #include "ui/compositor/reflector.h" |
21 #include "ui/compositor/test/in_process_context_provider.h" | 23 #include "ui/compositor/test/in_process_context_provider.h" |
22 #include "ui/gl/gl_implementation.h" | 24 #include "ui/gl/gl_implementation.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 } | 57 } |
56 | 58 |
57 private: | 59 private: |
58 base::WeakPtrFactory<DirectOutputSurface> weak_ptr_factory_; | 60 base::WeakPtrFactory<DirectOutputSurface> weak_ptr_factory_; |
59 | 61 |
60 DISALLOW_COPY_AND_ASSIGN(DirectOutputSurface); | 62 DISALLOW_COPY_AND_ASSIGN(DirectOutputSurface); |
61 }; | 63 }; |
62 | 64 |
63 } // namespace | 65 } // namespace |
64 | 66 |
65 InProcessContextFactory::InProcessContextFactory(bool context_factory_for_test) | 67 InProcessContextFactory::InProcessContextFactory( |
68 bool context_factory_for_test, | |
69 cc::SurfaceManager* surface_manager) | |
66 : next_surface_id_namespace_(1u), | 70 : next_surface_id_namespace_(1u), |
67 use_test_surface_(true), | 71 use_test_surface_(true), |
68 context_factory_for_test_(context_factory_for_test) { | 72 context_factory_for_test_(context_factory_for_test), |
73 surface_manager_(surface_manager) { | |
69 DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone) | 74 DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone) |
70 << "If running tests, ensure that main() is calling " | 75 << "If running tests, ensure that main() is calling " |
71 << "gfx::GLSurface::InitializeOneOffForTests()"; | 76 << "gfx::GLSurface::InitializeOneOffForTests()"; |
72 | 77 |
73 #if defined(OS_CHROMEOS) | 78 #if defined(OS_CHROMEOS) |
74 bool use_thread = !base::CommandLine::ForCurrentProcess()->HasSwitch( | 79 bool use_thread = !base::CommandLine::ForCurrentProcess()->HasSwitch( |
75 switches::kUIDisableThreadedCompositing); | 80 switches::kUIDisableThreadedCompositing); |
76 #else | 81 #else |
77 bool use_thread = false; | 82 bool use_thread = false; |
78 #endif | 83 #endif |
79 if (use_thread) { | 84 if (use_thread) { |
80 compositor_thread_.reset(new base::Thread("Browser Compositor")); | 85 compositor_thread_.reset(new base::Thread("Browser Compositor")); |
81 compositor_thread_->Start(); | 86 compositor_thread_->Start(); |
82 } | 87 } |
83 } | 88 } |
84 | 89 |
85 InProcessContextFactory::~InProcessContextFactory() {} | 90 InProcessContextFactory::~InProcessContextFactory() {} |
sky
2015/02/03 00:44:58
Might per_compositor_data_ be non-empty when you g
jbauman
2015/02/03 01:47:20
Added a DCHECK that it's empty - all compositors s
| |
86 | 91 |
87 void InProcessContextFactory::CreateOutputSurface( | 92 void InProcessContextFactory::CreateOutputSurface( |
88 base::WeakPtr<Compositor> compositor, | 93 base::WeakPtr<Compositor> compositor, |
89 bool software_fallback) { | 94 bool software_fallback) { |
90 DCHECK(!software_fallback); | 95 DCHECK(!software_fallback); |
91 gpu::gles2::ContextCreationAttribHelper attribs; | 96 gpu::gles2::ContextCreationAttribHelper attribs; |
92 attribs.alpha_size = 8; | 97 attribs.alpha_size = 8; |
93 attribs.blue_size = 8; | 98 attribs.blue_size = 8; |
94 attribs.green_size = 8; | 99 attribs.green_size = 8; |
95 attribs.red_size = 8; | 100 attribs.red_size = 8; |
96 attribs.depth_size = 0; | 101 attribs.depth_size = 0; |
97 attribs.stencil_size = 0; | 102 attribs.stencil_size = 0; |
98 attribs.samples = 0; | 103 attribs.samples = 0; |
99 attribs.sample_buffers = 0; | 104 attribs.sample_buffers = 0; |
100 attribs.fail_if_major_perf_caveat = false; | 105 attribs.fail_if_major_perf_caveat = false; |
101 attribs.bind_generates_resource = false; | 106 attribs.bind_generates_resource = false; |
102 bool lose_context_when_out_of_memory = true; | 107 bool lose_context_when_out_of_memory = true; |
103 | 108 |
104 scoped_refptr<InProcessContextProvider> context_provider = | 109 scoped_refptr<InProcessContextProvider> context_provider = |
105 InProcessContextProvider::Create(attribs, lose_context_when_out_of_memory, | 110 InProcessContextProvider::Create(attribs, lose_context_when_out_of_memory, |
106 compositor->widget(), "UICompositor"); | 111 compositor->widget(), "UICompositor"); |
107 | 112 |
113 scoped_ptr<cc::OutputSurface> real_output_surface; | |
114 | |
108 if (use_test_surface_) { | 115 if (use_test_surface_) { |
109 bool flipped_output_surface = false; | 116 bool flipped_output_surface = false; |
110 compositor->SetOutputSurface(make_scoped_ptr(new cc::PixelTestOutputSurface( | 117 real_output_surface = make_scoped_ptr(new cc::PixelTestOutputSurface( |
111 context_provider, flipped_output_surface))); | 118 context_provider, flipped_output_surface)); |
112 } else { | 119 } else { |
113 compositor->SetOutputSurface( | 120 real_output_surface = |
114 make_scoped_ptr(new DirectOutputSurface(context_provider))); | 121 make_scoped_ptr(new DirectOutputSurface(context_provider)); |
122 } | |
123 | |
124 if (surface_manager_) { | |
125 scoped_ptr<cc::OnscreenDisplayClient> display_client( | |
126 new cc::OnscreenDisplayClient( | |
127 real_output_surface.Pass(), surface_manager_, | |
128 GetSharedBitmapManager(), GetGpuMemoryBufferManager(), | |
129 compositor->GetRendererSettings(), compositor->task_runner())); | |
130 scoped_ptr<cc::SurfaceDisplayOutputSurface> surface_output_surface( | |
131 new cc::SurfaceDisplayOutputSurface(surface_manager_, | |
132 compositor->surface_id_allocator(), | |
133 context_provider)); | |
134 display_client->set_surface_output_surface(surface_output_surface.get()); | |
135 surface_output_surface->set_display_client(display_client.get()); | |
136 | |
137 compositor->SetOutputSurface(surface_output_surface.Pass()); | |
138 | |
139 delete per_compositor_data_[compositor.get()]; | |
140 per_compositor_data_[compositor.get()] = display_client.release(); | |
141 } else { | |
142 compositor->SetOutputSurface(real_output_surface.Pass()); | |
115 } | 143 } |
116 } | 144 } |
117 | 145 |
118 scoped_refptr<Reflector> InProcessContextFactory::CreateReflector( | 146 scoped_refptr<Reflector> InProcessContextFactory::CreateReflector( |
119 Compositor* mirroed_compositor, | 147 Compositor* mirroed_compositor, |
120 Layer* mirroring_layer) { | 148 Layer* mirroring_layer) { |
121 return new Reflector(); | 149 return new Reflector(); |
122 } | 150 } |
123 | 151 |
124 void InProcessContextFactory::RemoveReflector( | 152 void InProcessContextFactory::RemoveReflector( |
125 scoped_refptr<Reflector> reflector) {} | 153 scoped_refptr<Reflector> reflector) {} |
126 | 154 |
127 scoped_refptr<cc::ContextProvider> | 155 scoped_refptr<cc::ContextProvider> |
128 InProcessContextFactory::SharedMainThreadContextProvider() { | 156 InProcessContextFactory::SharedMainThreadContextProvider() { |
129 if (shared_main_thread_contexts_.get() && | 157 if (shared_main_thread_contexts_.get() && |
130 !shared_main_thread_contexts_->DestroyedOnMainThread()) | 158 !shared_main_thread_contexts_->DestroyedOnMainThread()) |
131 return shared_main_thread_contexts_; | 159 return shared_main_thread_contexts_; |
132 | 160 |
133 bool lose_context_when_out_of_memory = false; | 161 bool lose_context_when_out_of_memory = false; |
134 shared_main_thread_contexts_ = InProcessContextProvider::CreateOffscreen( | 162 shared_main_thread_contexts_ = InProcessContextProvider::CreateOffscreen( |
135 lose_context_when_out_of_memory); | 163 lose_context_when_out_of_memory); |
136 if (shared_main_thread_contexts_.get() && | 164 if (shared_main_thread_contexts_.get() && |
137 !shared_main_thread_contexts_->BindToCurrentThread()) | 165 !shared_main_thread_contexts_->BindToCurrentThread()) |
138 shared_main_thread_contexts_ = NULL; | 166 shared_main_thread_contexts_ = NULL; |
139 | 167 |
140 return shared_main_thread_contexts_; | 168 return shared_main_thread_contexts_; |
141 } | 169 } |
142 | 170 |
143 void InProcessContextFactory::RemoveCompositor(Compositor* compositor) {} | 171 void InProcessContextFactory::RemoveCompositor(Compositor* compositor) { |
172 if (!per_compositor_data_.count(compositor)) | |
173 return; | |
174 delete per_compositor_data_[compositor]; | |
175 per_compositor_data_.erase(compositor); | |
176 } | |
144 | 177 |
145 bool InProcessContextFactory::DoesCreateTestContexts() { | 178 bool InProcessContextFactory::DoesCreateTestContexts() { |
146 return context_factory_for_test_; | 179 return context_factory_for_test_; |
147 } | 180 } |
148 | 181 |
149 cc::SharedBitmapManager* InProcessContextFactory::GetSharedBitmapManager() { | 182 cc::SharedBitmapManager* InProcessContextFactory::GetSharedBitmapManager() { |
150 return &shared_bitmap_manager_; | 183 return &shared_bitmap_manager_; |
151 } | 184 } |
152 | 185 |
153 gpu::GpuMemoryBufferManager* | 186 gpu::GpuMemoryBufferManager* |
154 InProcessContextFactory::GetGpuMemoryBufferManager() { | 187 InProcessContextFactory::GetGpuMemoryBufferManager() { |
155 return &gpu_memory_buffer_manager_; | 188 return &gpu_memory_buffer_manager_; |
156 } | 189 } |
157 | 190 |
158 base::MessageLoopProxy* InProcessContextFactory::GetCompositorMessageLoop() { | 191 base::MessageLoopProxy* InProcessContextFactory::GetCompositorMessageLoop() { |
159 if (!compositor_thread_) | 192 if (!compositor_thread_) |
160 return NULL; | 193 return NULL; |
161 return compositor_thread_->message_loop_proxy().get(); | 194 return compositor_thread_->message_loop_proxy().get(); |
162 } | 195 } |
163 | 196 |
164 scoped_ptr<cc::SurfaceIdAllocator> | 197 scoped_ptr<cc::SurfaceIdAllocator> |
165 InProcessContextFactory::CreateSurfaceIdAllocator() { | 198 InProcessContextFactory::CreateSurfaceIdAllocator() { |
166 return make_scoped_ptr( | 199 return make_scoped_ptr( |
167 new cc::SurfaceIdAllocator(next_surface_id_namespace_++)); | 200 new cc::SurfaceIdAllocator(next_surface_id_namespace_++)); |
168 } | 201 } |
169 | 202 |
170 void InProcessContextFactory::ResizeDisplay(ui::Compositor* compositor, | 203 void InProcessContextFactory::ResizeDisplay(ui::Compositor* compositor, |
171 const gfx::Size& size) { | 204 const gfx::Size& size) { |
205 if (!per_compositor_data_.count(compositor)) | |
206 return; | |
207 per_compositor_data_[compositor]->display()->Resize(size); | |
172 } | 208 } |
173 | 209 |
174 } // namespace ui | 210 } // namespace ui |
OLD | NEW |