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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 void AddMirroringLayer(Layer* layer) override {} | 39 void AddMirroringLayer(Layer* layer) override {} |
40 void RemoveMirroringLayer(Layer* layer) override {} | 40 void RemoveMirroringLayer(Layer* layer) override {} |
41 }; | 41 }; |
42 | 42 |
43 // An OutputSurface implementation that directly draws and swaps to an actual | 43 // An OutputSurface implementation that directly draws and swaps to an actual |
44 // GL surface. | 44 // GL surface. |
45 class DirectOutputSurface : public cc::OutputSurface { | 45 class DirectOutputSurface : public cc::OutputSurface { |
46 public: | 46 public: |
47 DirectOutputSurface( | 47 DirectOutputSurface( |
48 const scoped_refptr<cc::ContextProvider>& context_provider, | 48 const scoped_refptr<cc::ContextProvider>& context_provider, |
49 const scoped_refptr<cc::ContextProvider>& worker_context_provider) | 49 const scoped_refptr<cc::ContextProvider>& worker_context_provider, |
| 50 scoped_ptr<cc::BeginFrameSource> begin_frame_source) |
50 : cc::OutputSurface(context_provider, worker_context_provider), | 51 : cc::OutputSurface(context_provider, worker_context_provider), |
| 52 begin_frame_source_(std::move(begin_frame_source)), |
51 weak_ptr_factory_(this) {} | 53 weak_ptr_factory_(this) {} |
52 | 54 |
53 ~DirectOutputSurface() override {} | 55 ~DirectOutputSurface() override {} |
54 | 56 |
55 // cc::OutputSurface implementation | 57 // cc::OutputSurface implementation |
| 58 bool BindToClient(cc::OutputSurfaceClient* client) override { |
| 59 if (!OutputSurface::BindToClient(client)) |
| 60 return false; |
| 61 |
| 62 client->SetBeginFrameSource(begin_frame_source_.get()); |
| 63 return true; |
| 64 } |
56 void SwapBuffers(cc::CompositorFrame* frame) override { | 65 void SwapBuffers(cc::CompositorFrame* frame) override { |
57 DCHECK(context_provider_.get()); | 66 DCHECK(context_provider_.get()); |
58 DCHECK(frame->gl_frame_data); | 67 DCHECK(frame->gl_frame_data); |
59 if (frame->gl_frame_data->sub_buffer_rect == | 68 if (frame->gl_frame_data->sub_buffer_rect == |
60 gfx::Rect(frame->gl_frame_data->size)) { | 69 gfx::Rect(frame->gl_frame_data->size)) { |
61 context_provider_->ContextSupport()->Swap(); | 70 context_provider_->ContextSupport()->Swap(); |
62 } else { | 71 } else { |
63 context_provider_->ContextSupport()->PartialSwapBuffers( | 72 context_provider_->ContextSupport()->PartialSwapBuffers( |
64 frame->gl_frame_data->sub_buffer_rect); | 73 frame->gl_frame_data->sub_buffer_rect); |
65 } | 74 } |
66 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | 75 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
67 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); | 76 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); |
68 gl->ShallowFlushCHROMIUM(); | 77 gl->ShallowFlushCHROMIUM(); |
69 | 78 |
70 gpu::SyncToken sync_token; | 79 gpu::SyncToken sync_token; |
71 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 80 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
72 | 81 |
73 context_provider_->ContextSupport()->SignalSyncToken( | 82 context_provider_->ContextSupport()->SignalSyncToken( |
74 sync_token, base::Bind(&OutputSurface::OnSwapBuffersComplete, | 83 sync_token, base::Bind(&OutputSurface::OnSwapBuffersComplete, |
75 weak_ptr_factory_.GetWeakPtr())); | 84 weak_ptr_factory_.GetWeakPtr())); |
76 client_->DidSwapBuffers(); | 85 client_->DidSwapBuffers(); |
77 } | 86 } |
78 | 87 |
79 private: | 88 private: |
| 89 scoped_ptr<cc::BeginFrameSource> begin_frame_source_; |
| 90 |
80 base::WeakPtrFactory<DirectOutputSurface> weak_ptr_factory_; | 91 base::WeakPtrFactory<DirectOutputSurface> weak_ptr_factory_; |
81 | 92 |
82 DISALLOW_COPY_AND_ASSIGN(DirectOutputSurface); | 93 DISALLOW_COPY_AND_ASSIGN(DirectOutputSurface); |
83 }; | 94 }; |
84 | 95 |
85 } // namespace | 96 } // namespace |
86 | 97 |
87 InProcessContextFactory::InProcessContextFactory( | 98 InProcessContextFactory::InProcessContextFactory( |
88 bool context_factory_for_test, | 99 bool context_factory_for_test, |
89 cc::SurfaceManager* surface_manager) | 100 cc::SurfaceManager* surface_manager) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 shared_worker_context_provider_ = InProcessContextProvider::CreateOffscreen( | 144 shared_worker_context_provider_ = InProcessContextProvider::CreateOffscreen( |
134 &gpu_memory_buffer_manager_, &image_factory_); | 145 &gpu_memory_buffer_manager_, &image_factory_); |
135 if (shared_worker_context_provider_ && | 146 if (shared_worker_context_provider_ && |
136 !shared_worker_context_provider_->BindToCurrentThread()) | 147 !shared_worker_context_provider_->BindToCurrentThread()) |
137 shared_worker_context_provider_ = nullptr; | 148 shared_worker_context_provider_ = nullptr; |
138 if (shared_worker_context_provider_) | 149 if (shared_worker_context_provider_) |
139 shared_worker_context_provider_->SetupLock(); | 150 shared_worker_context_provider_->SetupLock(); |
140 } | 151 } |
141 | 152 |
142 scoped_ptr<cc::OutputSurface> real_output_surface; | 153 scoped_ptr<cc::OutputSurface> real_output_surface; |
| 154 scoped_ptr<cc::SyntheticBeginFrameSource> begin_frame_source( |
| 155 new cc::SyntheticBeginFrameSource(compositor->task_runner().get(), |
| 156 cc::BeginFrameArgs::DefaultInterval())); |
143 | 157 |
144 if (use_test_surface_) { | 158 if (use_test_surface_) { |
145 bool flipped_output_surface = false; | 159 bool flipped_output_surface = false; |
146 real_output_surface = make_scoped_ptr(new cc::PixelTestOutputSurface( | 160 real_output_surface = make_scoped_ptr(new cc::PixelTestOutputSurface( |
147 context_provider, shared_worker_context_provider_, | 161 context_provider, shared_worker_context_provider_, |
148 flipped_output_surface)); | 162 flipped_output_surface, std::move(begin_frame_source))); |
149 } else { | 163 } else { |
150 real_output_surface = make_scoped_ptr(new DirectOutputSurface( | 164 real_output_surface = make_scoped_ptr(new DirectOutputSurface( |
151 context_provider, shared_worker_context_provider_)); | 165 context_provider, shared_worker_context_provider_, |
| 166 std::move(begin_frame_source))); |
152 } | 167 } |
153 | 168 |
154 if (surface_manager_) { | 169 if (surface_manager_) { |
155 scoped_ptr<cc::OnscreenDisplayClient> display_client( | 170 scoped_ptr<cc::OnscreenDisplayClient> display_client( |
156 new cc::OnscreenDisplayClient( | 171 new cc::OnscreenDisplayClient( |
157 std::move(real_output_surface), surface_manager_, | 172 std::move(real_output_surface), surface_manager_, |
158 GetSharedBitmapManager(), GetGpuMemoryBufferManager(), | 173 GetSharedBitmapManager(), GetGpuMemoryBufferManager(), |
159 compositor->GetRendererSettings(), compositor->task_runner())); | 174 compositor->GetRendererSettings(), compositor->task_runner(), |
| 175 compositor->surface_id_allocator()->id_namespace())); |
160 scoped_ptr<cc::SurfaceDisplayOutputSurface> surface_output_surface( | 176 scoped_ptr<cc::SurfaceDisplayOutputSurface> surface_output_surface( |
161 new cc::SurfaceDisplayOutputSurface( | 177 new cc::SurfaceDisplayOutputSurface( |
162 surface_manager_, compositor->surface_id_allocator(), | 178 surface_manager_, compositor->surface_id_allocator(), |
163 context_provider, shared_worker_context_provider_)); | 179 context_provider, shared_worker_context_provider_)); |
164 display_client->set_surface_output_surface(surface_output_surface.get()); | 180 display_client->set_surface_output_surface(surface_output_surface.get()); |
165 surface_output_surface->set_display_client(display_client.get()); | 181 surface_output_surface->set_display_client(display_client.get()); |
166 | 182 |
167 compositor->SetOutputSurface(std::move(surface_output_surface)); | 183 compositor->SetOutputSurface(std::move(surface_output_surface)); |
168 | 184 |
169 delete per_compositor_data_[compositor.get()]; | 185 delete per_compositor_data_[compositor.get()]; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } | 254 } |
239 | 255 |
240 void InProcessContextFactory::ResizeDisplay(ui::Compositor* compositor, | 256 void InProcessContextFactory::ResizeDisplay(ui::Compositor* compositor, |
241 const gfx::Size& size) { | 257 const gfx::Size& size) { |
242 if (!per_compositor_data_.count(compositor)) | 258 if (!per_compositor_data_.count(compositor)) |
243 return; | 259 return; |
244 per_compositor_data_[compositor]->display()->Resize(size); | 260 per_compositor_data_[compositor]->display()->Resize(size); |
245 } | 261 } |
246 | 262 |
247 } // namespace ui | 263 } // namespace ui |
OLD | NEW |