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 "cc/raster/one_copy_raster_buffer_provider.h" | 5 #include "cc/raster/one_copy_raster_buffer_provider.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "cc/base/math_util.h" | 14 #include "cc/base/math_util.h" |
15 #include "cc/resources/platform_color.h" | 15 #include "cc/resources/platform_color.h" |
16 #include "cc/resources/resource_format.h" | 16 #include "cc/resources/resource_format.h" |
17 #include "cc/resources/resource_util.h" | 17 #include "cc/resources/resource_util.h" |
18 #include "cc/resources/scoped_resource.h" | 18 #include "cc/resources/scoped_resource.h" |
19 #include "gpu/GLES2/gl2extchromium.h" | 19 #include "gpu/GLES2/gl2extchromium.h" |
20 #include "gpu/command_buffer/client/gles2_interface.h" | 20 #include "gpu/command_buffer/client/gles2_interface.h" |
21 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 21 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
22 #include "ui/gfx/buffer_format_util.h" | 22 #include "ui/gfx/buffer_format_util.h" |
23 | 23 |
24 namespace cc { | 24 namespace cc { |
25 namespace { | 25 namespace { |
26 | 26 |
27 class RasterBufferImpl : public RasterBuffer { | |
28 public: | |
29 RasterBufferImpl(OneCopyRasterBufferProvider* worker_pool, | |
30 ResourceProvider* resource_provider, | |
31 ResourceFormat resource_format, | |
32 const Resource* resource, | |
33 uint64_t previous_content_id) | |
34 : worker_pool_(worker_pool), | |
35 resource_(resource), | |
36 lock_(resource_provider, resource->id()), | |
37 previous_content_id_(previous_content_id) {} | |
38 | |
39 ~RasterBufferImpl() override {} | |
40 | |
41 // Overridden from RasterBuffer: | |
42 void Playback( | |
43 const RasterSource* raster_source, | |
44 const gfx::Rect& raster_full_rect, | |
45 const gfx::Rect& raster_dirty_rect, | |
46 uint64_t new_content_id, | |
47 float scale, | |
48 const RasterSource::PlaybackSettings& playback_settings) override { | |
49 worker_pool_->PlaybackAndCopyOnWorkerThread( | |
50 resource_, &lock_, raster_source, raster_full_rect, raster_dirty_rect, | |
51 scale, playback_settings, previous_content_id_, new_content_id); | |
52 } | |
53 | |
54 private: | |
55 OneCopyRasterBufferProvider* worker_pool_; | |
56 const Resource* resource_; | |
57 ResourceProvider::ScopedWriteLockGL lock_; | |
58 uint64_t previous_content_id_; | |
59 | |
60 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | |
61 }; | |
62 | |
63 // 4MiB is the size of 4 512x512 tiles, which has proven to be a good | 27 // 4MiB is the size of 4 512x512 tiles, which has proven to be a good |
64 // default batch size for copy operations. | 28 // default batch size for copy operations. |
65 const int kMaxBytesPerCopyOperation = 1024 * 1024 * 4; | 29 const int kMaxBytesPerCopyOperation = 1024 * 1024 * 4; |
66 | 30 |
67 } // namespace | 31 } // namespace |
68 | 32 |
33 OneCopyRasterBufferProvider::RasterBufferImpl::RasterBufferImpl( | |
34 OneCopyRasterBufferProvider* client, | |
35 ResourceProvider* resource_provider, | |
36 const Resource* resource, | |
37 uint64_t previous_content_id, | |
38 bool async_worker_context_enabled) | |
39 : client_(client), | |
40 resource_(resource), | |
41 lock_(resource_provider, resource->id(), async_worker_context_enabled), | |
42 previous_content_id_(previous_content_id) { | |
43 client_->pending_raster_buffers_.insert(this); | |
44 } | |
45 | |
46 OneCopyRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { | |
47 client_->pending_raster_buffers_.erase(this); | |
48 } | |
49 | |
50 void OneCopyRasterBufferProvider::RasterBufferImpl::Playback( | |
51 const RasterSource* raster_source, | |
52 const gfx::Rect& raster_full_rect, | |
53 const gfx::Rect& raster_dirty_rect, | |
54 uint64_t new_content_id, | |
55 float scale, | |
56 const RasterSource::PlaybackSettings& playback_settings) { | |
57 client_->PlaybackAndCopyOnWorkerThread( | |
58 resource_, &lock_, sync_token_, raster_source, raster_full_rect, | |
59 raster_dirty_rect, scale, playback_settings, previous_content_id_, | |
60 new_content_id); | |
61 } | |
62 | |
69 OneCopyRasterBufferProvider::OneCopyRasterBufferProvider( | 63 OneCopyRasterBufferProvider::OneCopyRasterBufferProvider( |
70 base::SequencedTaskRunner* task_runner, | 64 base::SequencedTaskRunner* task_runner, |
71 ContextProvider* compositor_context_provider, | 65 ContextProvider* compositor_context_provider, |
72 ContextProvider* worker_context_provider, | 66 ContextProvider* worker_context_provider, |
73 ResourceProvider* resource_provider, | 67 ResourceProvider* resource_provider, |
74 int max_copy_texture_chromium_size, | 68 int max_copy_texture_chromium_size, |
75 bool use_partial_raster, | 69 bool use_partial_raster, |
76 int max_staging_buffer_usage_in_bytes, | 70 int max_staging_buffer_usage_in_bytes, |
77 ResourceFormat preferred_tile_format) | 71 ResourceFormat preferred_tile_format, |
72 bool async_worker_context_enabled) | |
78 : compositor_context_provider_(compositor_context_provider), | 73 : compositor_context_provider_(compositor_context_provider), |
79 worker_context_provider_(worker_context_provider), | 74 worker_context_provider_(worker_context_provider), |
80 resource_provider_(resource_provider), | 75 resource_provider_(resource_provider), |
81 max_bytes_per_copy_operation_( | 76 max_bytes_per_copy_operation_( |
82 max_copy_texture_chromium_size | 77 max_copy_texture_chromium_size |
83 ? std::min(kMaxBytesPerCopyOperation, | 78 ? std::min(kMaxBytesPerCopyOperation, |
84 max_copy_texture_chromium_size) | 79 max_copy_texture_chromium_size) |
85 : kMaxBytesPerCopyOperation), | 80 : kMaxBytesPerCopyOperation), |
86 use_partial_raster_(use_partial_raster), | 81 use_partial_raster_(use_partial_raster), |
87 bytes_scheduled_since_last_flush_(0), | 82 bytes_scheduled_since_last_flush_(0), |
88 preferred_tile_format_(preferred_tile_format), | 83 preferred_tile_format_(preferred_tile_format), |
89 staging_pool_(task_runner, | 84 staging_pool_(task_runner, |
90 worker_context_provider, | 85 worker_context_provider, |
91 resource_provider, | 86 resource_provider, |
92 use_partial_raster, | 87 use_partial_raster, |
93 max_staging_buffer_usage_in_bytes) { | 88 max_staging_buffer_usage_in_bytes), |
94 DCHECK(compositor_context_provider_); | 89 async_worker_context_enabled_(async_worker_context_enabled) { |
90 DCHECK(compositor_context_provider); | |
95 DCHECK(worker_context_provider); | 91 DCHECK(worker_context_provider); |
96 } | 92 } |
97 | 93 |
98 OneCopyRasterBufferProvider::~OneCopyRasterBufferProvider() {} | 94 OneCopyRasterBufferProvider::~OneCopyRasterBufferProvider() { |
95 DCHECK(pending_raster_buffers_.empty()); | |
96 } | |
99 | 97 |
100 std::unique_ptr<RasterBuffer> | 98 std::unique_ptr<RasterBuffer> |
101 OneCopyRasterBufferProvider::AcquireBufferForRaster( | 99 OneCopyRasterBufferProvider::AcquireBufferForRaster( |
102 const Resource* resource, | 100 const Resource* resource, |
103 uint64_t resource_content_id, | 101 uint64_t resource_content_id, |
104 uint64_t previous_content_id) { | 102 uint64_t previous_content_id) { |
105 // TODO(danakj): If resource_content_id != 0, we only need to copy/upload | 103 // TODO(danakj): If resource_content_id != 0, we only need to copy/upload |
106 // the dirty rect. | 104 // the dirty rect. |
107 return base::WrapUnique<RasterBuffer>( | 105 return base::WrapUnique(new RasterBufferImpl(this, resource_provider_, |
108 new RasterBufferImpl(this, resource_provider_, resource->format(), | 106 resource, previous_content_id, |
109 resource, previous_content_id)); | 107 async_worker_context_enabled_)); |
110 } | 108 } |
111 | 109 |
112 void OneCopyRasterBufferProvider::ReleaseBufferForRaster( | 110 void OneCopyRasterBufferProvider::ReleaseBufferForRaster( |
113 std::unique_ptr<RasterBuffer> buffer) { | 111 std::unique_ptr<RasterBuffer> buffer) { |
114 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 112 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
115 } | 113 } |
116 | 114 |
117 void OneCopyRasterBufferProvider::OrderingBarrier() { | 115 bool OneCopyRasterBufferProvider::OrderingBarrier() { |
118 TRACE_EVENT0("cc", "OneCopyRasterBufferProvider::OrderingBarrier"); | 116 TRACE_EVENT0("cc", "OneCopyRasterBufferProvider::OrderingBarrier"); |
119 compositor_context_provider_->ContextGL()->OrderingBarrierCHROMIUM(); | 117 |
118 gpu::gles2::GLES2Interface* gl = compositor_context_provider_->ContextGL(); | |
119 GLuint64 fence = gl->InsertFenceSyncCHROMIUM(); | |
120 gl->OrderingBarrierCHROMIUM(); | |
121 | |
122 gpu::SyncToken sync_token; | |
123 gl->GenUnverifiedSyncTokenCHROMIUM(fence, sync_token.GetData()); | |
124 | |
125 for (RasterBufferImpl* buffer : pending_raster_buffers_) | |
126 buffer->set_sync_token(sync_token); | |
127 pending_raster_buffers_.clear(); | |
128 | |
129 // Do not proceed with ScheduleTasks if sync token was invalid. | |
piman
2016/06/10 01:02:47
nit: same here
sunnyps
2016/06/10 22:13:56
Done.
| |
130 return sync_token.HasData(); | |
120 } | 131 } |
121 | 132 |
122 ResourceFormat OneCopyRasterBufferProvider::GetResourceFormat( | 133 ResourceFormat OneCopyRasterBufferProvider::GetResourceFormat( |
123 bool must_support_alpha) const { | 134 bool must_support_alpha) const { |
124 if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && | 135 if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && |
125 (DoesResourceFormatSupportAlpha(preferred_tile_format_) || | 136 (DoesResourceFormatSupportAlpha(preferred_tile_format_) || |
126 !must_support_alpha)) { | 137 !must_support_alpha)) { |
127 return preferred_tile_format_; | 138 return preferred_tile_format_; |
128 } | 139 } |
129 | 140 |
130 return resource_provider_->best_texture_format(); | 141 return resource_provider_->best_texture_format(); |
131 } | 142 } |
132 | 143 |
133 bool OneCopyRasterBufferProvider::GetResourceRequiresSwizzle( | 144 bool OneCopyRasterBufferProvider::GetResourceRequiresSwizzle( |
134 bool must_support_alpha) const { | 145 bool must_support_alpha) const { |
135 return ResourceFormatRequiresSwizzle(GetResourceFormat(must_support_alpha)); | 146 return ResourceFormatRequiresSwizzle(GetResourceFormat(must_support_alpha)); |
136 } | 147 } |
137 | 148 |
138 void OneCopyRasterBufferProvider::Shutdown() { | 149 void OneCopyRasterBufferProvider::Shutdown() { |
139 staging_pool_.Shutdown(); | 150 staging_pool_.Shutdown(); |
151 pending_raster_buffers_.clear(); | |
140 } | 152 } |
141 | 153 |
142 void OneCopyRasterBufferProvider::PlaybackAndCopyOnWorkerThread( | 154 void OneCopyRasterBufferProvider::PlaybackAndCopyOnWorkerThread( |
143 const Resource* resource, | 155 const Resource* resource, |
144 ResourceProvider::ScopedWriteLockGL* resource_lock, | 156 ResourceProvider::ScopedWriteLockGL* resource_lock, |
157 const gpu::SyncToken& sync_token, | |
145 const RasterSource* raster_source, | 158 const RasterSource* raster_source, |
146 const gfx::Rect& raster_full_rect, | 159 const gfx::Rect& raster_full_rect, |
147 const gfx::Rect& raster_dirty_rect, | 160 const gfx::Rect& raster_dirty_rect, |
148 float scale, | 161 float scale, |
149 const RasterSource::PlaybackSettings& playback_settings, | 162 const RasterSource::PlaybackSettings& playback_settings, |
150 uint64_t previous_content_id, | 163 uint64_t previous_content_id, |
151 uint64_t new_content_id) { | 164 uint64_t new_content_id) { |
152 std::unique_ptr<StagingBuffer> staging_buffer = | 165 std::unique_ptr<StagingBuffer> staging_buffer = |
153 staging_pool_.AcquireStagingBuffer(resource, previous_content_id); | 166 staging_pool_.AcquireStagingBuffer(resource, previous_content_id); |
154 | 167 |
155 PlaybackToStagingBuffer(staging_buffer.get(), resource, raster_source, | 168 PlaybackToStagingBuffer(staging_buffer.get(), resource, raster_source, |
156 raster_full_rect, raster_dirty_rect, scale, | 169 raster_full_rect, raster_dirty_rect, scale, |
157 playback_settings, previous_content_id, | 170 playback_settings, previous_content_id, |
158 new_content_id); | 171 new_content_id); |
159 | 172 |
160 CopyOnWorkerThread(staging_buffer.get(), resource, resource_lock, | 173 CopyOnWorkerThread(staging_buffer.get(), resource_lock, sync_token, |
161 raster_source, previous_content_id, new_content_id); | 174 raster_source, previous_content_id, new_content_id); |
162 | 175 |
163 staging_pool_.ReleaseStagingBuffer(std::move(staging_buffer)); | 176 staging_pool_.ReleaseStagingBuffer(std::move(staging_buffer)); |
164 } | 177 } |
165 | 178 |
166 void OneCopyRasterBufferProvider::PlaybackToStagingBuffer( | 179 void OneCopyRasterBufferProvider::PlaybackToStagingBuffer( |
167 StagingBuffer* staging_buffer, | 180 StagingBuffer* staging_buffer, |
168 const Resource* resource, | 181 const Resource* resource, |
169 const RasterSource* raster_source, | 182 const RasterSource* raster_source, |
170 const gfx::Rect& raster_full_rect, | 183 const gfx::Rect& raster_full_rect, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 buffer->memory(0), resource->format(), staging_buffer->size, | 222 buffer->memory(0), resource->format(), staging_buffer->size, |
210 buffer->stride(0), raster_source, raster_full_rect, playback_rect, | 223 buffer->stride(0), raster_source, raster_full_rect, playback_rect, |
211 scale, playback_settings); | 224 scale, playback_settings); |
212 buffer->Unmap(); | 225 buffer->Unmap(); |
213 staging_buffer->content_id = new_content_id; | 226 staging_buffer->content_id = new_content_id; |
214 } | 227 } |
215 } | 228 } |
216 | 229 |
217 void OneCopyRasterBufferProvider::CopyOnWorkerThread( | 230 void OneCopyRasterBufferProvider::CopyOnWorkerThread( |
218 StagingBuffer* staging_buffer, | 231 StagingBuffer* staging_buffer, |
219 const Resource* resource, | |
220 ResourceProvider::ScopedWriteLockGL* resource_lock, | 232 ResourceProvider::ScopedWriteLockGL* resource_lock, |
233 const gpu::SyncToken& sync_token, | |
221 const RasterSource* raster_source, | 234 const RasterSource* raster_source, |
222 uint64_t previous_content_id, | 235 uint64_t previous_content_id, |
223 uint64_t new_content_id) { | 236 uint64_t new_content_id) { |
224 { | 237 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); |
225 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); | |
226 | 238 |
227 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); | 239 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
228 DCHECK(gl); | 240 DCHECK(gl); |
229 | 241 |
230 unsigned image_target = | 242 ResourceProvider::ScopedTextureProvider scoped_texture( |
231 resource_provider_->GetImageTextureTarget(resource->format()); | 243 gl, resource_lock, async_worker_context_enabled_); |
232 | 244 |
233 // Create and bind staging texture. | 245 // Synchronize with compositor. |
234 if (!staging_buffer->texture_id) { | 246 DCHECK(sync_token.HasData()); |
235 gl->GenTextures(1, &staging_buffer->texture_id); | 247 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); |
236 gl->BindTexture(image_target, staging_buffer->texture_id); | |
237 gl->TexParameteri(image_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
238 gl->TexParameteri(image_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
239 gl->TexParameteri(image_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
240 gl->TexParameteri(image_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
241 } else { | |
242 gl->BindTexture(image_target, staging_buffer->texture_id); | |
243 } | |
244 | 248 |
245 // Create and bind image. | 249 unsigned resource_texture_id = scoped_texture.texture_id(); |
246 if (!staging_buffer->image_id) { | 250 unsigned image_target = |
247 if (staging_buffer->gpu_memory_buffer) { | 251 resource_provider_->GetImageTextureTarget(resource_lock->format()); |
248 staging_buffer->image_id = gl->CreateImageCHROMIUM( | 252 |
249 staging_buffer->gpu_memory_buffer->AsClientBuffer(), | 253 // Create and bind staging texture. |
250 staging_buffer->size.width(), staging_buffer->size.height(), | 254 if (!staging_buffer->texture_id) { |
251 GLInternalFormat(resource->format())); | 255 gl->GenTextures(1, &staging_buffer->texture_id); |
252 gl->BindTexImage2DCHROMIUM(image_target, staging_buffer->image_id); | 256 gl->BindTexture(image_target, staging_buffer->texture_id); |
253 } | 257 gl->TexParameteri(image_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
254 } else { | 258 gl->TexParameteri(image_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
255 gl->ReleaseTexImage2DCHROMIUM(image_target, staging_buffer->image_id); | 259 gl->TexParameteri(image_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
260 gl->TexParameteri(image_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
261 } else { | |
262 gl->BindTexture(image_target, staging_buffer->texture_id); | |
263 } | |
264 | |
265 // Create and bind image. | |
266 if (!staging_buffer->image_id) { | |
267 if (staging_buffer->gpu_memory_buffer) { | |
268 staging_buffer->image_id = gl->CreateImageCHROMIUM( | |
269 staging_buffer->gpu_memory_buffer->AsClientBuffer(), | |
270 staging_buffer->size.width(), staging_buffer->size.height(), | |
271 GLInternalFormat(resource_lock->format())); | |
256 gl->BindTexImage2DCHROMIUM(image_target, staging_buffer->image_id); | 272 gl->BindTexImage2DCHROMIUM(image_target, staging_buffer->image_id); |
257 } | 273 } |
274 } else { | |
275 gl->ReleaseTexImage2DCHROMIUM(image_target, staging_buffer->image_id); | |
276 gl->BindTexImage2DCHROMIUM(image_target, staging_buffer->image_id); | |
277 } | |
258 | 278 |
259 // Unbind staging texture. | 279 // Unbind staging texture. |
260 gl->BindTexture(image_target, 0); | 280 gl->BindTexture(image_target, 0); |
261 | 281 |
262 if (resource_provider_->use_sync_query()) { | 282 if (resource_provider_->use_sync_query()) { |
263 if (!staging_buffer->query_id) | 283 if (!staging_buffer->query_id) |
264 gl->GenQueriesEXT(1, &staging_buffer->query_id); | 284 gl->GenQueriesEXT(1, &staging_buffer->query_id); |
265 | 285 |
266 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) | 286 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) |
267 // TODO(reveman): This avoids a performance problem on ARM ChromeOS | 287 // TODO(reveman): This avoids a performance problem on ARM ChromeOS |
268 // devices. crbug.com/580166 | 288 // devices. crbug.com/580166 |
269 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, staging_buffer->query_id); | 289 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, staging_buffer->query_id); |
270 #else | 290 #else |
271 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, | 291 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, staging_buffer->query_id); |
272 staging_buffer->query_id); | |
273 #endif | 292 #endif |
274 } | 293 } |
275 | 294 |
276 // Since compressed texture's cannot be pre-allocated we might have an | 295 // Since compressed texture's cannot be pre-allocated we might have an |
277 // unallocated resource in which case we need to perform a full size copy. | 296 // unallocated resource in which case we need to perform a full size copy. |
278 if (IsResourceFormatCompressed(resource->format())) { | 297 if (IsResourceFormatCompressed(resource_lock->format())) { |
279 gl->CompressedCopyTextureCHROMIUM(staging_buffer->texture_id, | 298 gl->CompressedCopyTextureCHROMIUM(staging_buffer->texture_id, |
280 resource_lock->texture_id()); | 299 resource_texture_id); |
281 } else { | 300 } else { |
282 int bytes_per_row = ResourceUtil::UncheckedWidthInBytes<int>( | 301 int bytes_per_row = ResourceUtil::UncheckedWidthInBytes<int>( |
283 resource->size().width(), resource->format()); | 302 resource_lock->size().width(), resource_lock->format()); |
284 int chunk_size_in_rows = | 303 int chunk_size_in_rows = |
285 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); | 304 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); |
286 // Align chunk size to 4. Required to support compressed texture formats. | 305 // Align chunk size to 4. Required to support compressed texture formats. |
287 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); | 306 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); |
288 int y = 0; | 307 int y = 0; |
289 int height = resource->size().height(); | 308 int height = resource_lock->size().height(); |
290 while (y < height) { | 309 while (y < height) { |
291 // Copy at most |chunk_size_in_rows|. | 310 // Copy at most |chunk_size_in_rows|. |
292 int rows_to_copy = std::min(chunk_size_in_rows, height - y); | 311 int rows_to_copy = std::min(chunk_size_in_rows, height - y); |
293 DCHECK_GT(rows_to_copy, 0); | 312 DCHECK_GT(rows_to_copy, 0); |
294 | 313 |
295 gl->CopySubTextureCHROMIUM( | 314 gl->CopySubTextureCHROMIUM( |
296 staging_buffer->texture_id, resource_lock->texture_id(), 0, y, 0, y, | 315 staging_buffer->texture_id, resource_texture_id, 0, y, 0, y, |
297 resource->size().width(), rows_to_copy, false, false, false); | 316 resource_lock->size().width(), rows_to_copy, false, false, false); |
298 y += rows_to_copy; | 317 y += rows_to_copy; |
299 | 318 |
300 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory | 319 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory |
301 // used for this copy operation. | 320 // used for this copy operation. |
302 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; | 321 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; |
303 | 322 |
304 if (bytes_scheduled_since_last_flush_ >= | 323 if (bytes_scheduled_since_last_flush_ >= max_bytes_per_copy_operation_) { |
305 max_bytes_per_copy_operation_) { | 324 gl->ShallowFlushCHROMIUM(); |
306 gl->ShallowFlushCHROMIUM(); | 325 bytes_scheduled_since_last_flush_ = 0; |
307 bytes_scheduled_since_last_flush_ = 0; | |
308 } | |
309 } | 326 } |
310 } | 327 } |
328 } | |
311 | 329 |
312 if (resource_provider_->use_sync_query()) { | 330 if (resource_provider_->use_sync_query()) { |
313 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) | 331 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) |
314 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | 332 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
315 #else | 333 #else |
316 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | 334 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); |
317 #endif | 335 #endif |
318 } | 336 } |
319 | 337 |
320 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); | 338 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); |
321 | 339 |
322 // Barrier to sync worker context output to cc context. | 340 // Barrier to sync worker context output to cc context. |
323 gl->OrderingBarrierCHROMIUM(); | 341 gl->OrderingBarrierCHROMIUM(); |
324 | 342 |
325 // Generate sync token after the barrier for cross context synchronization. | 343 // Generate sync token after the barrier for cross context synchronization. |
326 gpu::SyncToken sync_token; | 344 gpu::SyncToken resource_sync_token; |
327 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 345 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData()); |
328 resource_lock->UpdateResourceSyncToken(sync_token); | 346 resource_lock->set_sync_token(resource_sync_token); |
329 } | |
330 } | 347 } |
331 | 348 |
332 } // namespace cc | 349 } // namespace cc |
OLD | NEW |