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