| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/views/mus/surface_context_factory.h" | 5 #include "ui/views/mus/surface_context_factory.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "cc/resources/shared_bitmap_manager.h" | 8 #include "cc/resources/shared_bitmap_manager.h" |
| 9 #include "cc/surfaces/surface_id_allocator.h" | 9 #include "cc/surfaces/surface_id_allocator.h" |
| 10 #include "services/ui/public/cpp/context_provider.h" | 10 #include "services/ui/public/cpp/context_provider.h" |
| 11 #include "services/ui/public/cpp/gpu_service.h" | 11 #include "services/ui/public/cpp/gpu_service.h" |
| 12 #include "services/ui/public/cpp/window.h" | 12 #include "services/ui/public/cpp/window.h" |
| 13 #include "services/ui/public/cpp/window_compositor_frame_sink.h" | 13 #include "services/ui/public/cpp/window_compositor_frame_sink.h" |
| 14 #include "ui/aura/mus/gpu_service.h" |
| 15 #include "ui/aura/mus/window_port_mus.h" |
| 14 #include "ui/compositor/reflector.h" | 16 #include "ui/compositor/reflector.h" |
| 15 #include "ui/gl/gl_bindings.h" | 17 #include "ui/gl/gl_bindings.h" |
| 16 #include "ui/views/mus/native_widget_mus.h" | 18 #include "ui/views/mus/native_widget_mus.h" |
| 17 | 19 |
| 18 namespace views { | 20 namespace views { |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 class FakeReflector : public ui::Reflector { | 23 class FakeReflector : public ui::Reflector { |
| 22 public: | 24 public: |
| 23 FakeReflector() {} | 25 FakeReflector() {} |
| 24 ~FakeReflector() override {} | 26 ~FakeReflector() override {} |
| 25 void OnMirroringCompositorResized() override {} | 27 void OnMirroringCompositorResized() override {} |
| 26 void AddMirroringLayer(ui::Layer* layer) override {} | 28 void AddMirroringLayer(ui::Layer* layer) override {} |
| 27 void RemoveMirroringLayer(ui::Layer* layer) override {} | 29 void RemoveMirroringLayer(ui::Layer* layer) override {} |
| 28 }; | 30 }; |
| 29 | 31 |
| 30 } // namespace | 32 } // namespace |
| 31 | 33 |
| 32 SurfaceContextFactory::SurfaceContextFactory(ui::GpuService* gpu_service) | 34 SurfaceContextFactory::SurfaceContextFactory(ui::GpuService* gpu_service) |
| 35 : next_sink_id_(1u), gpu_service_ui_(gpu_service) {} |
| 36 |
| 37 SurfaceContextFactory::SurfaceContextFactory(aura::GpuService* gpu_service) |
| 33 : next_sink_id_(1u), gpu_service_(gpu_service) {} | 38 : next_sink_id_(1u), gpu_service_(gpu_service) {} |
| 34 | 39 |
| 35 SurfaceContextFactory::~SurfaceContextFactory() {} | 40 SurfaceContextFactory::~SurfaceContextFactory() {} |
| 36 | 41 |
| 37 void SurfaceContextFactory::CreateCompositorFrameSink( | 42 void SurfaceContextFactory::CreateCompositorFrameSink( |
| 38 base::WeakPtr<ui::Compositor> compositor) { | 43 base::WeakPtr<ui::Compositor> compositor) { |
| 39 ui::Window* window = compositor->window(); | 44 ui::Window* window = compositor->window(); |
| 40 NativeWidgetMus* native_widget = NativeWidgetMus::GetForWindow(window); | 45 if (window) { |
| 41 ui::mojom::CompositorFrameSinkType compositor_frame_sink_type = | 46 // TODO(mfomitchev): Remove this clause once all clients switch to using |
| 42 native_widget->compositor_frame_sink_type(); | 47 // Aura-Mus. |
| 43 auto compositor_frame_sink = window->RequestCompositorFrameSink( | 48 NativeWidgetMus* native_widget = NativeWidgetMus::GetForWindow(window); |
| 44 compositor_frame_sink_type, make_scoped_refptr(new ui::ContextProvider( | 49 ui::mojom::CompositorFrameSinkType compositor_frame_sink_type = |
| 45 gpu_service_->EstablishGpuChannelSync())), | 50 native_widget->compositor_frame_sink_type(); |
| 46 gpu_service_->gpu_memory_buffer_manager()); | 51 auto compositor_frame_sink = window->RequestCompositorFrameSink( |
| 47 compositor->SetCompositorFrameSink(std::move(compositor_frame_sink)); | 52 compositor_frame_sink_type, |
| 53 make_scoped_refptr(new ui::ContextProvider( |
| 54 gpu_service_ui_->EstablishGpuChannelSync())), |
| 55 gpu_service_ui_->gpu_memory_buffer_manager()); |
| 56 compositor->SetCompositorFrameSink(std::move(compositor_frame_sink)); |
| 57 } else { |
| 58 aura::WindowTreeHost* host = |
| 59 aura::WindowTreeHost::GetForAcceleratedWidget(compositor->widget()); |
| 60 aura::WindowPortMus* window_port = aura::WindowPortMus::Get(host->window()); |
| 61 DCHECK(window_port); |
| 62 auto compositor_frame_sink = window_port->RequestCompositorFrameSink( |
| 63 ui::mojom::CompositorFrameSinkType::DEFAULT, |
| 64 make_scoped_refptr( |
| 65 new ui::ContextProvider(gpu_service_->EstablishGpuChannelSync())), |
| 66 gpu_service_->gpu_memory_buffer_manager()); |
| 67 compositor->SetCompositorFrameSink(std::move(compositor_frame_sink)); |
| 68 } |
| 48 } | 69 } |
| 49 | 70 |
| 50 std::unique_ptr<ui::Reflector> SurfaceContextFactory::CreateReflector( | 71 std::unique_ptr<ui::Reflector> SurfaceContextFactory::CreateReflector( |
| 51 ui::Compositor* mirroed_compositor, | 72 ui::Compositor* mirroed_compositor, |
| 52 ui::Layer* mirroring_layer) { | 73 ui::Layer* mirroring_layer) { |
| 53 // NOTIMPLEMENTED(); | 74 // NOTIMPLEMENTED(); |
| 54 return base::WrapUnique(new FakeReflector); | 75 return base::WrapUnique(new FakeReflector); |
| 55 } | 76 } |
| 56 | 77 |
| 57 void SurfaceContextFactory::RemoveReflector(ui::Reflector* reflector) { | 78 void SurfaceContextFactory::RemoveReflector(ui::Reflector* reflector) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 73 } | 94 } |
| 74 | 95 |
| 75 uint32_t SurfaceContextFactory::GetImageTextureTarget(gfx::BufferFormat format, | 96 uint32_t SurfaceContextFactory::GetImageTextureTarget(gfx::BufferFormat format, |
| 76 gfx::BufferUsage usage) { | 97 gfx::BufferUsage usage) { |
| 77 // No GpuMemoryBuffer support, so just return GL_TEXTURE_2D. | 98 // No GpuMemoryBuffer support, so just return GL_TEXTURE_2D. |
| 78 return GL_TEXTURE_2D; | 99 return GL_TEXTURE_2D; |
| 79 } | 100 } |
| 80 | 101 |
| 81 gpu::GpuMemoryBufferManager* | 102 gpu::GpuMemoryBufferManager* |
| 82 SurfaceContextFactory::GetGpuMemoryBufferManager() { | 103 SurfaceContextFactory::GetGpuMemoryBufferManager() { |
| 104 if (gpu_service_ui_) |
| 105 return gpu_service_ui_->gpu_memory_buffer_manager(); |
| 83 return gpu_service_->gpu_memory_buffer_manager(); | 106 return gpu_service_->gpu_memory_buffer_manager(); |
| 84 } | 107 } |
| 85 | 108 |
| 86 cc::TaskGraphRunner* SurfaceContextFactory::GetTaskGraphRunner() { | 109 cc::TaskGraphRunner* SurfaceContextFactory::GetTaskGraphRunner() { |
| 87 return raster_thread_helper_.task_graph_runner(); | 110 return raster_thread_helper_.task_graph_runner(); |
| 88 } | 111 } |
| 89 | 112 |
| 90 cc::FrameSinkId SurfaceContextFactory::AllocateFrameSinkId() { | 113 cc::FrameSinkId SurfaceContextFactory::AllocateFrameSinkId() { |
| 91 return cc::FrameSinkId(0, next_sink_id_++); | 114 return cc::FrameSinkId(0, next_sink_id_++); |
| 92 } | 115 } |
| 93 | 116 |
| 94 cc::SurfaceManager* SurfaceContextFactory::GetSurfaceManager() { | 117 cc::SurfaceManager* SurfaceContextFactory::GetSurfaceManager() { |
| 95 return &surface_manager_; | 118 return &surface_manager_; |
| 96 } | 119 } |
| 97 | 120 |
| 98 void SurfaceContextFactory::SetDisplayVisible(ui::Compositor* compositor, | 121 void SurfaceContextFactory::SetDisplayVisible(ui::Compositor* compositor, |
| 99 bool visible) { | 122 bool visible) { |
| 100 // TODO(fsamuel): display[compositor]->SetVisible(visible); | 123 // TODO(fsamuel): display[compositor]->SetVisible(visible); |
| 101 } | 124 } |
| 102 | 125 |
| 103 void SurfaceContextFactory::ResizeDisplay(ui::Compositor* compositor, | 126 void SurfaceContextFactory::ResizeDisplay(ui::Compositor* compositor, |
| 104 const gfx::Size& size) { | 127 const gfx::Size& size) { |
| 105 // TODO(fsamuel): display[compositor]->Resize(size); | 128 // TODO(fsamuel): display[compositor]->Resize(size); |
| 106 } | 129 } |
| 107 | 130 |
| 108 } // namespace views | 131 } // namespace views |
| OLD | NEW |