OLD | NEW |
---|---|
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 "LayerTreeHostImpl::SetVisible", | 82 "LayerTreeHostImpl::SetVisible", |
83 id, | 83 id, |
84 "LayerTreeHostImpl", | 84 "LayerTreeHostImpl", |
85 id); | 85 id); |
86 return; | 86 return; |
87 } | 87 } |
88 | 88 |
89 TRACE_EVENT_ASYNC_END0("webkit", "LayerTreeHostImpl::SetVisible", id); | 89 TRACE_EVENT_ASYNC_END0("webkit", "LayerTreeHostImpl::SetVisible", id); |
90 } | 90 } |
91 | 91 |
92 size_t GetMaxTransferBufferUsageBytes(cc::ContextProvider* context_provider) { | 92 size_t GetMaxTransferBufferUsageBytes(cc::ContextProvider* context_provider, |
93 double refresh_rate) { | |
93 // Software compositing should not use this value in production. Just use a | 94 // Software compositing should not use this value in production. Just use a |
94 // default value when testing uploads with the software compositor. | 95 // default value when testing uploads with the software compositor. |
95 if (!context_provider) | 96 if (!context_provider) |
96 return std::numeric_limits<size_t>::max(); | 97 return std::numeric_limits<size_t>::max(); |
97 | 98 |
98 // We want to make sure the default transfer buffer size is equal to the | 99 // We want to make sure the default transfer buffer size is equal to the |
99 // amount of data that can be uploaded by the compositor to avoid stalling | 100 // amount of data that can be uploaded by the compositor to avoid stalling |
100 // the pipeline. | 101 // the pipeline. |
101 // For reference Chromebook Pixel can upload 1MB in about 0.5ms. | 102 // For reference Chromebook Pixel can upload 1MB in about 0.5ms. |
102 const size_t kMaxBytesUploadedPerMs = 1024 * 1024 * 2; | 103 const size_t kMaxBytesUploadedPerMs = 1024 * 1024 * 2; |
103 // Assuming a two frame deep pipeline between CPU and GPU and we are | 104 |
104 // drawing 60 frames per second which would require us to draw one | 105 // This is the number of bytes the compositor would be able to upload before |
105 // frame in 16 milliseconds. | 106 // the next frame deadline. |
106 const size_t kMaxTransferBufferUsageBytes = 16 * 2 * kMaxBytesUploadedPerMs; | 107 // This assumes that the compositor does not send incomplete resources to the |
108 // browser. Beginning to upload a resource that won't make it before the | |
109 // next deadline will mean the compositor will not send the resource to the | |
110 // browser, so there's no benefit to starting it early. | |
reveman
2014/08/30 02:00:56
I don't understand how frame deadlines would effec
| |
111 size_t ms_per_frame = std::floor(1000.0 / refresh_rate); | |
112 size_t max_transfer_buffer_usage_bytes = | |
113 ms_per_frame * kMaxBytesUploadedPerMs; | |
114 | |
115 // The context may request a lower limit based on the device capabilities. | |
107 return std::min( | 116 return std::min( |
108 context_provider->ContextCapabilities().max_transfer_buffer_usage_bytes, | 117 context_provider->ContextCapabilities().max_transfer_buffer_usage_bytes, |
109 kMaxTransferBufferUsageBytes); | 118 max_transfer_buffer_usage_bytes); |
110 } | 119 } |
111 | 120 |
112 unsigned GetMapImageTextureTarget(cc::ContextProvider* context_provider) { | 121 unsigned GetMapImageTextureTarget(cc::ContextProvider* context_provider) { |
113 if (!context_provider) | 122 if (!context_provider) |
114 return GL_TEXTURE_2D; | 123 return GL_TEXTURE_2D; |
115 | 124 |
116 if (context_provider->ContextCapabilities().gpu.egl_image_external) | 125 if (context_provider->ContextCapabilities().gpu.egl_image_external) |
117 return GL_TEXTURE_EXTERNAL_OES; | 126 return GL_TEXTURE_EXTERNAL_OES; |
118 if (context_provider->ContextCapabilities().gpu.texture_rectangle) | 127 if (context_provider->ContextCapabilities().gpu.texture_rectangle) |
119 return GL_TEXTURE_RECTANGLE_ARB; | 128 return GL_TEXTURE_RECTANGLE_ARB; |
(...skipping 1812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1932 | 1941 |
1933 void LayerTreeHostImpl::CreateAndSetTileManager() { | 1942 void LayerTreeHostImpl::CreateAndSetTileManager() { |
1934 DCHECK(!tile_manager_); | 1943 DCHECK(!tile_manager_); |
1935 DCHECK(settings_.impl_side_painting); | 1944 DCHECK(settings_.impl_side_painting); |
1936 DCHECK(output_surface_); | 1945 DCHECK(output_surface_); |
1937 DCHECK(resource_provider_); | 1946 DCHECK(resource_provider_); |
1938 DCHECK(proxy_->ImplThreadTaskRunner()); | 1947 DCHECK(proxy_->ImplThreadTaskRunner()); |
1939 | 1948 |
1940 ContextProvider* context_provider = output_surface_->context_provider(); | 1949 ContextProvider* context_provider = output_surface_->context_provider(); |
1941 transfer_buffer_memory_limit_ = | 1950 transfer_buffer_memory_limit_ = |
1942 GetMaxTransferBufferUsageBytes(context_provider); | 1951 GetMaxTransferBufferUsageBytes(context_provider, settings_.refresh_rate); |
1943 | 1952 |
1944 if (use_gpu_rasterization_ && context_provider) { | 1953 if (use_gpu_rasterization_ && context_provider) { |
1945 resource_pool_ = | 1954 resource_pool_ = |
1946 ResourcePool::Create(resource_provider_.get(), | 1955 ResourcePool::Create(resource_provider_.get(), |
1947 GL_TEXTURE_2D, | 1956 GL_TEXTURE_2D, |
1948 resource_provider_->best_texture_format()); | 1957 resource_provider_->best_texture_format()); |
1949 | 1958 |
1950 raster_worker_pool_ = | 1959 raster_worker_pool_ = |
1951 GpuRasterWorkerPool::Create(proxy_->ImplThreadTaskRunner(), | 1960 GpuRasterWorkerPool::Create(proxy_->ImplThreadTaskRunner(), |
1952 context_provider, | 1961 context_provider, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2059 settings_.highp_threshold_min, | 2068 settings_.highp_threshold_min, |
2060 settings_.use_rgba_4444_textures, | 2069 settings_.use_rgba_4444_textures, |
2061 settings_.texture_id_allocation_chunk_size, | 2070 settings_.texture_id_allocation_chunk_size, |
2062 settings_.use_distance_field_text); | 2071 settings_.use_distance_field_text); |
2063 | 2072 |
2064 if (output_surface_->capabilities().deferred_gl_initialization) | 2073 if (output_surface_->capabilities().deferred_gl_initialization) |
2065 EnforceZeroBudget(true); | 2074 EnforceZeroBudget(true); |
2066 | 2075 |
2067 CreateAndSetRenderer(); | 2076 CreateAndSetRenderer(); |
2068 | 2077 |
2069 transfer_buffer_memory_limit_ = | |
2070 GetMaxTransferBufferUsageBytes(output_surface_->context_provider()); | |
2071 | |
2072 if (settings_.impl_side_painting) | 2078 if (settings_.impl_side_painting) |
2073 CreateAndSetTileManager(); | 2079 CreateAndSetTileManager(); |
2074 | 2080 |
2075 // Initialize vsync parameters to sane values. | 2081 // Initialize vsync parameters to sane values. |
2076 const base::TimeDelta display_refresh_interval = | 2082 const base::TimeDelta display_refresh_interval = |
2077 base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond / | 2083 base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond / |
2078 settings_.refresh_rate); | 2084 settings_.refresh_rate); |
2079 CommitVSyncParameters(base::TimeTicks(), display_refresh_interval); | 2085 CommitVSyncParameters(base::TimeTicks(), display_refresh_interval); |
2080 | 2086 |
2081 // TODO(brianderson): Don't use a hard-coded parent draw time. | 2087 // TODO(brianderson): Don't use a hard-coded parent draw time. |
(...skipping 1270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3352 } | 3358 } |
3353 | 3359 |
3354 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3360 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
3355 std::vector<PictureLayerImpl*>::iterator it = | 3361 std::vector<PictureLayerImpl*>::iterator it = |
3356 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3362 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
3357 DCHECK(it != picture_layers_.end()); | 3363 DCHECK(it != picture_layers_.end()); |
3358 picture_layers_.erase(it); | 3364 picture_layers_.erase(it); |
3359 } | 3365 } |
3360 | 3366 |
3361 } // namespace cc | 3367 } // namespace cc |
OLD | NEW |