| 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" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "cc/output/compositor_frame.h" | 14 #include "cc/output/compositor_frame.h" |
| 15 #include "cc/output/context_provider.h" | 15 #include "cc/output/context_provider.h" |
| 16 #include "cc/output/output_surface_client.h" | 16 #include "cc/output/output_surface_client.h" |
| 17 #include "cc/output/texture_mailbox_deleter.h" |
| 18 #include "cc/scheduler/begin_frame_source.h" |
| 19 #include "cc/surfaces/display.h" |
| 20 #include "cc/surfaces/display_scheduler.h" |
| 17 #include "cc/surfaces/surface_display_output_surface.h" | 21 #include "cc/surfaces/surface_display_output_surface.h" |
| 18 #include "cc/surfaces/surface_id_allocator.h" | 22 #include "cc/surfaces/surface_id_allocator.h" |
| 19 #include "cc/test/pixel_test_output_surface.h" | 23 #include "cc/test/pixel_test_output_surface.h" |
| 20 #include "cc/test/test_shared_bitmap_manager.h" | 24 #include "cc/test/test_shared_bitmap_manager.h" |
| 21 #include "gpu/command_buffer/client/context_support.h" | 25 #include "gpu/command_buffer/client/context_support.h" |
| 22 #include "gpu/command_buffer/client/gles2_interface.h" | 26 #include "gpu/command_buffer/client/gles2_interface.h" |
| 23 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 27 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 24 #include "ui/compositor/compositor_switches.h" | 28 #include "ui/compositor/compositor_switches.h" |
| 25 #include "ui/compositor/layer.h" | 29 #include "ui/compositor/layer.h" |
| 26 #include "ui/compositor/reflector.h" | 30 #include "ui/compositor/reflector.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 39 void AddMirroringLayer(Layer* layer) override {} | 43 void AddMirroringLayer(Layer* layer) override {} |
| 40 void RemoveMirroringLayer(Layer* layer) override {} | 44 void RemoveMirroringLayer(Layer* layer) override {} |
| 41 }; | 45 }; |
| 42 | 46 |
| 43 // An OutputSurface implementation that directly draws and swaps to an actual | 47 // An OutputSurface implementation that directly draws and swaps to an actual |
| 44 // GL surface. | 48 // GL surface. |
| 45 class DirectOutputSurface : public cc::OutputSurface { | 49 class DirectOutputSurface : public cc::OutputSurface { |
| 46 public: | 50 public: |
| 47 DirectOutputSurface( | 51 DirectOutputSurface( |
| 48 const scoped_refptr<cc::ContextProvider>& context_provider, | 52 const scoped_refptr<cc::ContextProvider>& context_provider, |
| 49 const scoped_refptr<cc::ContextProvider>& worker_context_provider, | 53 const scoped_refptr<cc::ContextProvider>& worker_context_provider) |
| 50 std::unique_ptr<cc::BeginFrameSource> begin_frame_source) | |
| 51 : cc::OutputSurface(context_provider, worker_context_provider, nullptr), | 54 : cc::OutputSurface(context_provider, worker_context_provider, nullptr), |
| 52 begin_frame_source_(std::move(begin_frame_source)), | |
| 53 weak_ptr_factory_(this) {} | 55 weak_ptr_factory_(this) {} |
| 54 | 56 |
| 55 ~DirectOutputSurface() override {} | 57 ~DirectOutputSurface() override {} |
| 56 | 58 |
| 57 // cc::OutputSurface implementation | 59 // cc::OutputSurface implementation |
| 58 bool BindToClient(cc::OutputSurfaceClient* client) override { | 60 bool BindToClient(cc::OutputSurfaceClient* client) override { |
| 59 if (!OutputSurface::BindToClient(client)) | 61 if (!OutputSurface::BindToClient(client)) |
| 60 return false; | 62 return false; |
| 61 | |
| 62 client->SetBeginFrameSource(begin_frame_source_.get()); | |
| 63 return true; | 63 return true; |
| 64 } | 64 } |
| 65 void SwapBuffers(cc::CompositorFrame* frame) override { | 65 void SwapBuffers(cc::CompositorFrame* frame) override { |
| 66 DCHECK(context_provider_.get()); | 66 DCHECK(context_provider_.get()); |
| 67 DCHECK(frame->gl_frame_data); | 67 DCHECK(frame->gl_frame_data); |
| 68 if (frame->gl_frame_data->sub_buffer_rect == | 68 if (frame->gl_frame_data->sub_buffer_rect == |
| 69 gfx::Rect(frame->gl_frame_data->size)) { | 69 gfx::Rect(frame->gl_frame_data->size)) { |
| 70 context_provider_->ContextSupport()->Swap(); | 70 context_provider_->ContextSupport()->Swap(); |
| 71 } else { | 71 } else { |
| 72 context_provider_->ContextSupport()->PartialSwapBuffers( | 72 context_provider_->ContextSupport()->PartialSwapBuffers( |
| 73 frame->gl_frame_data->sub_buffer_rect); | 73 frame->gl_frame_data->sub_buffer_rect); |
| 74 } | 74 } |
| 75 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | 75 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
| 76 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); | 76 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); |
| 77 gl->ShallowFlushCHROMIUM(); | 77 gl->ShallowFlushCHROMIUM(); |
| 78 | 78 |
| 79 gpu::SyncToken sync_token; | 79 gpu::SyncToken sync_token; |
| 80 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 80 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
| 81 | 81 |
| 82 context_provider_->ContextSupport()->SignalSyncToken( | 82 context_provider_->ContextSupport()->SignalSyncToken( |
| 83 sync_token, base::Bind(&OutputSurface::OnSwapBuffersComplete, | 83 sync_token, base::Bind(&OutputSurface::OnSwapBuffersComplete, |
| 84 weak_ptr_factory_.GetWeakPtr())); | 84 weak_ptr_factory_.GetWeakPtr())); |
| 85 client_->DidSwapBuffers(); | 85 client_->DidSwapBuffers(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 std::unique_ptr<cc::BeginFrameSource> begin_frame_source_; | |
| 90 | |
| 91 base::WeakPtrFactory<DirectOutputSurface> weak_ptr_factory_; | 89 base::WeakPtrFactory<DirectOutputSurface> weak_ptr_factory_; |
| 92 | 90 |
| 93 DISALLOW_COPY_AND_ASSIGN(DirectOutputSurface); | 91 DISALLOW_COPY_AND_ASSIGN(DirectOutputSurface); |
| 94 }; | 92 }; |
| 95 | 93 |
| 96 } // namespace | 94 } // namespace |
| 97 | 95 |
| 98 InProcessContextFactory::InProcessContextFactory( | 96 InProcessContextFactory::InProcessContextFactory( |
| 99 bool context_factory_for_test, | 97 bool context_factory_for_test, |
| 100 cc::SurfaceManager* surface_manager) | 98 cc::SurfaceManager* surface_manager) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 attribs.sample_buffers = 0; | 140 attribs.sample_buffers = 0; |
| 143 attribs.fail_if_major_perf_caveat = false; | 141 attribs.fail_if_major_perf_caveat = false; |
| 144 attribs.bind_generates_resource = false; | 142 attribs.bind_generates_resource = false; |
| 145 scoped_refptr<InProcessContextProvider> context_provider = | 143 scoped_refptr<InProcessContextProvider> context_provider = |
| 146 InProcessContextProvider::Create( | 144 InProcessContextProvider::Create( |
| 147 attribs, shared_worker_context_provider_.get(), | 145 attribs, shared_worker_context_provider_.get(), |
| 148 &gpu_memory_buffer_manager_, &image_factory_, compositor->widget(), | 146 &gpu_memory_buffer_manager_, &image_factory_, compositor->widget(), |
| 149 "UICompositor"); | 147 "UICompositor"); |
| 150 | 148 |
| 151 std::unique_ptr<cc::OutputSurface> display_output_surface; | 149 std::unique_ptr<cc::OutputSurface> display_output_surface; |
| 152 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source( | |
| 153 new cc::SyntheticBeginFrameSource(compositor->task_runner().get(), | |
| 154 cc::BeginFrameArgs::DefaultInterval())); | |
| 155 | |
| 156 if (use_test_surface_) { | 150 if (use_test_surface_) { |
| 157 bool flipped_output_surface = false; | 151 bool flipped_output_surface = false; |
| 158 display_output_surface = base::WrapUnique(new cc::PixelTestOutputSurface( | 152 display_output_surface = base::WrapUnique(new cc::PixelTestOutputSurface( |
| 159 context_provider, shared_worker_context_provider_, | 153 context_provider, shared_worker_context_provider_, |
| 160 flipped_output_surface, std::move(begin_frame_source))); | 154 flipped_output_surface)); |
| 161 } else { | 155 } else { |
| 162 display_output_surface = base::WrapUnique(new DirectOutputSurface( | 156 display_output_surface = base::WrapUnique(new DirectOutputSurface( |
| 163 context_provider, shared_worker_context_provider_, | 157 context_provider, shared_worker_context_provider_)); |
| 164 std::move(begin_frame_source))); | |
| 165 } | 158 } |
| 166 | 159 |
| 167 if (surface_manager_) { | 160 if (surface_manager_) { |
| 168 std::unique_ptr<cc::Display> display(new cc::Display( | 161 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source( |
| 162 new cc::SyntheticBeginFrameSource( |
| 163 compositor->task_runner().get(), |
| 164 cc::BeginFrameArgs::DefaultInterval())); |
| 165 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( |
| 166 begin_frame_source.get(), compositor->task_runner().get(), |
| 167 display_output_surface->capabilities().max_frames_pending)); |
| 168 per_compositor_data_[compositor.get()] = base::MakeUnique<cc::Display>( |
| 169 surface_manager_, GetSharedBitmapManager(), GetGpuMemoryBufferManager(), | 169 surface_manager_, GetSharedBitmapManager(), GetGpuMemoryBufferManager(), |
| 170 compositor->GetRendererSettings(), | 170 compositor->GetRendererSettings(), |
| 171 compositor->surface_id_allocator()->id_namespace(), | 171 compositor->surface_id_allocator()->id_namespace(), |
| 172 compositor->task_runner().get(), std::move(display_output_surface))); | 172 std::move(begin_frame_source), std::move(display_output_surface), |
| 173 std::move(scheduler), base::MakeUnique<cc::TextureMailboxDeleter>( |
| 174 compositor->task_runner().get())); |
| 175 |
| 176 auto* display = per_compositor_data_[compositor.get()].get(); |
| 173 std::unique_ptr<cc::SurfaceDisplayOutputSurface> surface_output_surface( | 177 std::unique_ptr<cc::SurfaceDisplayOutputSurface> surface_output_surface( |
| 174 new cc::SurfaceDisplayOutputSurface( | 178 new cc::SurfaceDisplayOutputSurface( |
| 175 surface_manager_, compositor->surface_id_allocator(), display.get(), | 179 surface_manager_, compositor->surface_id_allocator(), display, |
| 176 context_provider, shared_worker_context_provider_)); | 180 context_provider, shared_worker_context_provider_)); |
| 177 | |
| 178 compositor->SetOutputSurface(std::move(surface_output_surface)); | 181 compositor->SetOutputSurface(std::move(surface_output_surface)); |
| 179 | |
| 180 per_compositor_data_[compositor.get()] = std::move(display); | |
| 181 } else { | 182 } else { |
| 182 compositor->SetOutputSurface(std::move(display_output_surface)); | 183 compositor->SetOutputSurface(std::move(display_output_surface)); |
| 183 } | 184 } |
| 184 } | 185 } |
| 185 | 186 |
| 186 std::unique_ptr<Reflector> InProcessContextFactory::CreateReflector( | 187 std::unique_ptr<Reflector> InProcessContextFactory::CreateReflector( |
| 187 Compositor* mirrored_compositor, | 188 Compositor* mirrored_compositor, |
| 188 Layer* mirroring_layer) { | 189 Layer* mirroring_layer) { |
| 189 return base::WrapUnique(new FakeReflector); | 190 return base::WrapUnique(new FakeReflector); |
| 190 } | 191 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 252 } |
| 252 | 253 |
| 253 void InProcessContextFactory::ResizeDisplay(ui::Compositor* compositor, | 254 void InProcessContextFactory::ResizeDisplay(ui::Compositor* compositor, |
| 254 const gfx::Size& size) { | 255 const gfx::Size& size) { |
| 255 if (!per_compositor_data_.count(compositor)) | 256 if (!per_compositor_data_.count(compositor)) |
| 256 return; | 257 return; |
| 257 per_compositor_data_[compositor]->Resize(size); | 258 per_compositor_data_[compositor]->Resize(size); |
| 258 } | 259 } |
| 259 | 260 |
| 260 } // namespace ui | 261 } // namespace ui |
| OLD | NEW |