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

Side by Side Diff: ui/compositor/test/in_process_context_factory.cc

Issue 888783002: Composite to cc::Display from ui::InProcessContextFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « ui/compositor/test/in_process_context_factory.h ('k') | ui/views/examples/examples_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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() {
91 DCHECK(per_compositor_data_.empty());
92 }
86 93
87 void InProcessContextFactory::CreateOutputSurface( 94 void InProcessContextFactory::CreateOutputSurface(
88 base::WeakPtr<Compositor> compositor, 95 base::WeakPtr<Compositor> compositor,
89 bool software_fallback) { 96 bool software_fallback) {
90 DCHECK(!software_fallback); 97 DCHECK(!software_fallback);
91 gpu::gles2::ContextCreationAttribHelper attribs; 98 gpu::gles2::ContextCreationAttribHelper attribs;
92 attribs.alpha_size = 8; 99 attribs.alpha_size = 8;
93 attribs.blue_size = 8; 100 attribs.blue_size = 8;
94 attribs.green_size = 8; 101 attribs.green_size = 8;
95 attribs.red_size = 8; 102 attribs.red_size = 8;
96 attribs.depth_size = 0; 103 attribs.depth_size = 0;
97 attribs.stencil_size = 0; 104 attribs.stencil_size = 0;
98 attribs.samples = 0; 105 attribs.samples = 0;
99 attribs.sample_buffers = 0; 106 attribs.sample_buffers = 0;
100 attribs.fail_if_major_perf_caveat = false; 107 attribs.fail_if_major_perf_caveat = false;
101 attribs.bind_generates_resource = false; 108 attribs.bind_generates_resource = false;
102 bool lose_context_when_out_of_memory = true; 109 bool lose_context_when_out_of_memory = true;
103 110
104 scoped_refptr<InProcessContextProvider> context_provider = 111 scoped_refptr<InProcessContextProvider> context_provider =
105 InProcessContextProvider::Create(attribs, lose_context_when_out_of_memory, 112 InProcessContextProvider::Create(attribs, lose_context_when_out_of_memory,
106 compositor->widget(), "UICompositor"); 113 compositor->widget(), "UICompositor");
107 114
115 scoped_ptr<cc::OutputSurface> real_output_surface;
116
108 if (use_test_surface_) { 117 if (use_test_surface_) {
109 bool flipped_output_surface = false; 118 bool flipped_output_surface = false;
110 compositor->SetOutputSurface(make_scoped_ptr(new cc::PixelTestOutputSurface( 119 real_output_surface = make_scoped_ptr(new cc::PixelTestOutputSurface(
111 context_provider, flipped_output_surface))); 120 context_provider, flipped_output_surface));
112 } else { 121 } else {
113 compositor->SetOutputSurface( 122 real_output_surface =
114 make_scoped_ptr(new DirectOutputSurface(context_provider))); 123 make_scoped_ptr(new DirectOutputSurface(context_provider));
124 }
125
126 if (surface_manager_) {
127 scoped_ptr<cc::OnscreenDisplayClient> display_client(
128 new cc::OnscreenDisplayClient(
129 real_output_surface.Pass(), surface_manager_,
130 GetSharedBitmapManager(), GetGpuMemoryBufferManager(),
131 compositor->GetRendererSettings(), compositor->task_runner()));
132 scoped_ptr<cc::SurfaceDisplayOutputSurface> surface_output_surface(
133 new cc::SurfaceDisplayOutputSurface(surface_manager_,
134 compositor->surface_id_allocator(),
135 context_provider));
136 display_client->set_surface_output_surface(surface_output_surface.get());
137 surface_output_surface->set_display_client(display_client.get());
138
139 compositor->SetOutputSurface(surface_output_surface.Pass());
140
141 delete per_compositor_data_[compositor.get()];
142 per_compositor_data_[compositor.get()] = display_client.release();
143 } else {
144 compositor->SetOutputSurface(real_output_surface.Pass());
115 } 145 }
116 } 146 }
117 147
118 scoped_refptr<Reflector> InProcessContextFactory::CreateReflector( 148 scoped_refptr<Reflector> InProcessContextFactory::CreateReflector(
119 Compositor* mirroed_compositor, 149 Compositor* mirroed_compositor,
120 Layer* mirroring_layer) { 150 Layer* mirroring_layer) {
121 return new Reflector(); 151 return new Reflector();
122 } 152 }
123 153
124 void InProcessContextFactory::RemoveReflector( 154 void InProcessContextFactory::RemoveReflector(
125 scoped_refptr<Reflector> reflector) {} 155 scoped_refptr<Reflector> reflector) {}
126 156
127 scoped_refptr<cc::ContextProvider> 157 scoped_refptr<cc::ContextProvider>
128 InProcessContextFactory::SharedMainThreadContextProvider() { 158 InProcessContextFactory::SharedMainThreadContextProvider() {
129 if (shared_main_thread_contexts_.get() && 159 if (shared_main_thread_contexts_.get() &&
130 !shared_main_thread_contexts_->DestroyedOnMainThread()) 160 !shared_main_thread_contexts_->DestroyedOnMainThread())
131 return shared_main_thread_contexts_; 161 return shared_main_thread_contexts_;
132 162
133 bool lose_context_when_out_of_memory = false; 163 bool lose_context_when_out_of_memory = false;
134 shared_main_thread_contexts_ = InProcessContextProvider::CreateOffscreen( 164 shared_main_thread_contexts_ = InProcessContextProvider::CreateOffscreen(
135 lose_context_when_out_of_memory); 165 lose_context_when_out_of_memory);
136 if (shared_main_thread_contexts_.get() && 166 if (shared_main_thread_contexts_.get() &&
137 !shared_main_thread_contexts_->BindToCurrentThread()) 167 !shared_main_thread_contexts_->BindToCurrentThread())
138 shared_main_thread_contexts_ = NULL; 168 shared_main_thread_contexts_ = NULL;
139 169
140 return shared_main_thread_contexts_; 170 return shared_main_thread_contexts_;
141 } 171 }
142 172
143 void InProcessContextFactory::RemoveCompositor(Compositor* compositor) {} 173 void InProcessContextFactory::RemoveCompositor(Compositor* compositor) {
174 if (!per_compositor_data_.count(compositor))
175 return;
176 delete per_compositor_data_[compositor];
177 per_compositor_data_.erase(compositor);
178 }
144 179
145 bool InProcessContextFactory::DoesCreateTestContexts() { 180 bool InProcessContextFactory::DoesCreateTestContexts() {
146 return context_factory_for_test_; 181 return context_factory_for_test_;
147 } 182 }
148 183
149 cc::SharedBitmapManager* InProcessContextFactory::GetSharedBitmapManager() { 184 cc::SharedBitmapManager* InProcessContextFactory::GetSharedBitmapManager() {
150 return &shared_bitmap_manager_; 185 return &shared_bitmap_manager_;
151 } 186 }
152 187
153 gpu::GpuMemoryBufferManager* 188 gpu::GpuMemoryBufferManager*
154 InProcessContextFactory::GetGpuMemoryBufferManager() { 189 InProcessContextFactory::GetGpuMemoryBufferManager() {
155 return &gpu_memory_buffer_manager_; 190 return &gpu_memory_buffer_manager_;
156 } 191 }
157 192
158 base::MessageLoopProxy* InProcessContextFactory::GetCompositorMessageLoop() { 193 base::MessageLoopProxy* InProcessContextFactory::GetCompositorMessageLoop() {
159 if (!compositor_thread_) 194 if (!compositor_thread_)
160 return NULL; 195 return NULL;
161 return compositor_thread_->message_loop_proxy().get(); 196 return compositor_thread_->message_loop_proxy().get();
162 } 197 }
163 198
164 scoped_ptr<cc::SurfaceIdAllocator> 199 scoped_ptr<cc::SurfaceIdAllocator>
165 InProcessContextFactory::CreateSurfaceIdAllocator() { 200 InProcessContextFactory::CreateSurfaceIdAllocator() {
166 return make_scoped_ptr( 201 return make_scoped_ptr(
167 new cc::SurfaceIdAllocator(next_surface_id_namespace_++)); 202 new cc::SurfaceIdAllocator(next_surface_id_namespace_++));
168 } 203 }
169 204
170 void InProcessContextFactory::ResizeDisplay(ui::Compositor* compositor, 205 void InProcessContextFactory::ResizeDisplay(ui::Compositor* compositor,
171 const gfx::Size& size) { 206 const gfx::Size& size) {
207 if (!per_compositor_data_.count(compositor))
208 return;
209 per_compositor_data_[compositor]->display()->Resize(size);
172 } 210 }
173 211
174 } // namespace ui 212 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/test/in_process_context_factory.h ('k') | ui/views/examples/examples_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698