OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "blimp/client/support/compositor/compositor_dependencies_impl.h" | 5 #include "blimp/client/support/compositor/compositor_dependencies_impl.h" |
6 | 6 |
7 #include "blimp/client/support/compositor/blimp_context_provider.h" | 7 #include "blimp/client/support/compositor/blimp_context_provider.h" |
8 #include "blimp/client/support/compositor/blimp_gpu_memory_buffer_manager.h" | 8 #include "blimp/client/support/compositor/blimp_gpu_memory_buffer_manager.h" |
9 #include "blimp/client/support/compositor/blimp_layer_tree_settings.h" | 9 #include "blimp/client/support/compositor/blimp_layer_tree_settings.h" |
10 #include "cc/output/context_provider.h" | 10 #include "cc/output/context_provider.h" |
11 #include "cc/surfaces/surface_manager.h" | 11 #include "cc/surfaces/surface_manager.h" |
12 #include "cc/trees/layer_tree_settings.h" | 12 #include "cc/trees/layer_tree_settings.h" |
13 | 13 |
14 #if defined(OS_ANDROID) | |
15 #include "ui/gfx/android/device_display_info.h" | |
16 #endif | |
17 | |
18 namespace blimp { | 14 namespace blimp { |
19 namespace client { | 15 namespace client { |
20 | 16 |
21 CompositorDependenciesImpl::CompositorDependenciesImpl() | 17 CompositorDependenciesImpl::CompositorDependenciesImpl() |
22 : gpu_memory_buffer_manager_( | 18 : gpu_memory_buffer_manager_( |
23 base::MakeUnique<BlimpGpuMemoryBufferManager>()), | 19 base::MakeUnique<BlimpGpuMemoryBufferManager>()), |
24 surface_manager_(base::MakeUnique<cc::SurfaceManager>()), | 20 surface_manager_(base::MakeUnique<cc::SurfaceManager>()), |
25 next_surface_id_(0) {} | 21 next_surface_id_(0) {} |
26 | 22 |
27 CompositorDependenciesImpl::~CompositorDependenciesImpl() = default; | 23 CompositorDependenciesImpl::~CompositorDependenciesImpl() = default; |
28 | 24 |
29 cc::LayerTreeSettings* CompositorDependenciesImpl::GetLayerTreeSettings() { | |
30 if (!settings_) { | |
31 settings_ = base::MakeUnique<cc::LayerTreeSettings>(); | |
32 | |
33 PopulateCommonLayerTreeSettings(settings_.get()); | |
34 settings_->abort_commit_before_output_surface_creation = false; | |
35 settings_->renderer_settings.buffer_to_texture_target_map = | |
36 BlimpGpuMemoryBufferManager::GetDefaultBufferToTextureTargetMap(); | |
37 settings_->use_output_surface_begin_frame_source = true; | |
38 | |
39 int default_tile_size = 256; | |
40 #if defined(OS_ANDROID) | |
41 gfx::DeviceDisplayInfo info; | |
42 bool real_size_supported = true; | |
43 int display_width = info.GetPhysicalDisplayWidth(); | |
44 int display_height = info.GetPhysicalDisplayHeight(); | |
45 if (display_width == 0 || display_height == 0) { | |
46 real_size_supported = false; | |
47 display_width = info.GetDisplayWidth(); | |
48 display_height = info.GetDisplayHeight(); | |
49 } | |
50 | |
51 int portrait_width = std::min(display_width, display_height); | |
52 int landscape_width = std::max(display_width, display_height); | |
53 | |
54 if (real_size_supported) { | |
55 // Maximum HD dimensions should be 768x1280 | |
56 // Maximum FHD dimensions should be 1200x1920 | |
57 if (portrait_width > 768 || landscape_width > 1280) | |
58 default_tile_size = 384; | |
59 if (portrait_width > 1200 || landscape_width > 1920) | |
60 default_tile_size = 512; | |
61 | |
62 // Adjust for some resolutions that barely straddle an extra | |
63 // tile when in portrait mode. This helps worst case scroll/raster | |
64 // by not needing a full extra tile for each row. | |
65 if (default_tile_size == 256 && portrait_width == 768) | |
66 default_tile_size += 32; | |
67 if (default_tile_size == 384 && portrait_width == 1200) | |
68 default_tile_size += 32; | |
69 } else { | |
70 // We don't know the exact resolution due to screen controls etc. | |
71 // So this just estimates the values above using tile counts. | |
72 int numTiles = (display_width * display_height) / (256 * 256); | |
73 if (numTiles > 16) | |
74 default_tile_size = 384; | |
75 if (numTiles >= 40) | |
76 default_tile_size = 512; | |
77 } | |
78 #endif | |
79 settings_->default_tile_size.SetSize(default_tile_size, default_tile_size); | |
80 } | |
81 | |
82 return settings_.get(); | |
83 } | |
84 | |
85 gpu::GpuMemoryBufferManager* | 25 gpu::GpuMemoryBufferManager* |
86 CompositorDependenciesImpl::GetGpuMemoryBufferManager() { | 26 CompositorDependenciesImpl::GetGpuMemoryBufferManager() { |
87 return gpu_memory_buffer_manager_.get(); | 27 return gpu_memory_buffer_manager_.get(); |
88 } | 28 } |
89 | 29 |
90 cc::SurfaceManager* CompositorDependenciesImpl::GetSurfaceManager() { | 30 cc::SurfaceManager* CompositorDependenciesImpl::GetSurfaceManager() { |
91 return surface_manager_.get(); | 31 return surface_manager_.get(); |
92 } | 32 } |
93 | 33 |
94 uint32_t CompositorDependenciesImpl::AllocateSurfaceId() { | 34 uint32_t CompositorDependenciesImpl::AllocateSurfaceClientId() { |
95 return ++next_surface_id_; | 35 return ++next_surface_id_; |
96 } | 36 } |
97 | 37 |
98 void CompositorDependenciesImpl::GetContextProvider( | 38 void CompositorDependenciesImpl::GetContextProviders( |
99 const CompositorDependencies::ContextProviderCallback& callback) { | 39 const CompositorDependencies::ContextProviderCallback& callback) { |
100 scoped_refptr<cc::ContextProvider> provider = BlimpContextProvider::Create( | 40 scoped_refptr<cc::ContextProvider> compositor_context = |
101 gfx::kNullAcceleratedWidget, gpu_memory_buffer_manager_.get()); | 41 BlimpContextProvider::Create(gfx::kNullAcceleratedWidget, |
102 callback.Run(provider); | 42 gpu_memory_buffer_manager_.get()); |
| 43 |
| 44 // TODO(khushalsagar): Make a worker context and bind to the current thread. |
| 45 callback.Run(compositor_context, nullptr); |
103 } | 46 } |
104 | 47 |
105 } // namespace client | 48 } // namespace client |
106 } // namespace blimp | 49 } // namespace blimp |
OLD | NEW |