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