Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: cc/raster/one_copy_raster_buffer_provider.cc

Issue 2726263003: cc::ResourcePool - Re-use larger resources for smaller requests (Closed)
Patch Set: fix compile Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/raster/one_copy_raster_buffer_provider.h ('k') | cc/resources/resource_pool.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 233
234 std::unique_ptr<StagingBuffer> staging_buffer = 234 std::unique_ptr<StagingBuffer> staging_buffer =
235 staging_pool_.AcquireStagingBuffer(resource, previous_content_id); 235 staging_pool_.AcquireStagingBuffer(resource, previous_content_id);
236 236
237 PlaybackToStagingBuffer( 237 PlaybackToStagingBuffer(
238 staging_buffer.get(), resource, raster_source, raster_full_rect, 238 staging_buffer.get(), resource, raster_source, raster_full_rect,
239 raster_dirty_rect, transform, resource_lock->color_space_for_raster(), 239 raster_dirty_rect, transform, resource_lock->color_space_for_raster(),
240 playback_settings, previous_content_id, new_content_id); 240 playback_settings, previous_content_id, new_content_id);
241 241
242 CopyOnWorkerThread(staging_buffer.get(), resource_lock, sync_token, 242 CopyOnWorkerThread(staging_buffer.get(), resource_lock, sync_token,
243 raster_source, previous_content_id, new_content_id); 243 raster_source, raster_full_rect);
244 244
245 staging_pool_.ReleaseStagingBuffer(std::move(staging_buffer)); 245 staging_pool_.ReleaseStagingBuffer(std::move(staging_buffer));
246 } 246 }
247 247
248 void OneCopyRasterBufferProvider::PlaybackToStagingBuffer( 248 void OneCopyRasterBufferProvider::PlaybackToStagingBuffer(
249 StagingBuffer* staging_buffer, 249 StagingBuffer* staging_buffer,
250 const Resource* resource, 250 const Resource* resource,
251 const RasterSource* raster_source, 251 const RasterSource* raster_source,
252 const gfx::Rect& raster_full_rect, 252 const gfx::Rect& raster_full_rect,
253 const gfx::Rect& raster_dirty_rect, 253 const gfx::Rect& raster_dirty_rect,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 buffer->Unmap(); 305 buffer->Unmap();
306 staging_buffer->content_id = new_content_id; 306 staging_buffer->content_id = new_content_id;
307 } 307 }
308 } 308 }
309 309
310 void OneCopyRasterBufferProvider::CopyOnWorkerThread( 310 void OneCopyRasterBufferProvider::CopyOnWorkerThread(
311 StagingBuffer* staging_buffer, 311 StagingBuffer* staging_buffer,
312 ResourceProvider::ScopedWriteLockGL* resource_lock, 312 ResourceProvider::ScopedWriteLockGL* resource_lock,
313 const gpu::SyncToken& sync_token, 313 const gpu::SyncToken& sync_token,
314 const RasterSource* raster_source, 314 const RasterSource* raster_source,
315 uint64_t previous_content_id, 315 const gfx::Rect& rect_to_copy) {
316 uint64_t new_content_id) {
317 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); 316 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_);
318 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); 317 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL();
319 DCHECK(gl); 318 DCHECK(gl);
320 319
321 // Create texture after synchronizing with compositor. 320 // Create texture after synchronizing with compositor.
322 ResourceProvider::ScopedTextureProvider scoped_texture( 321 ResourceProvider::ScopedTextureProvider scoped_texture(
323 gl, resource_lock, async_worker_context_enabled_); 322 gl, resource_lock, async_worker_context_enabled_);
324 323
325 unsigned resource_texture_id = scoped_texture.texture_id(); 324 unsigned resource_texture_id = scoped_texture.texture_id();
326 unsigned image_target = resource_provider_->GetImageTextureTarget( 325 unsigned image_target = resource_provider_->GetImageTextureTarget(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 #endif 367 #endif
369 } 368 }
370 369
371 // Since compressed texture's cannot be pre-allocated we might have an 370 // Since compressed texture's cannot be pre-allocated we might have an
372 // unallocated resource in which case we need to perform a full size copy. 371 // unallocated resource in which case we need to perform a full size copy.
373 if (IsResourceFormatCompressed(resource_lock->format())) { 372 if (IsResourceFormatCompressed(resource_lock->format())) {
374 gl->CompressedCopyTextureCHROMIUM(staging_buffer->texture_id, 373 gl->CompressedCopyTextureCHROMIUM(staging_buffer->texture_id,
375 resource_texture_id); 374 resource_texture_id);
376 } else { 375 } else {
377 int bytes_per_row = ResourceUtil::UncheckedWidthInBytes<int>( 376 int bytes_per_row = ResourceUtil::UncheckedWidthInBytes<int>(
378 resource_lock->size().width(), resource_lock->format()); 377 rect_to_copy.width(), resource_lock->format());
379 int chunk_size_in_rows = 378 int chunk_size_in_rows =
380 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); 379 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row);
381 // Align chunk size to 4. Required to support compressed texture formats. 380 // Align chunk size to 4. Required to support compressed texture formats.
382 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); 381 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4);
383 int y = 0; 382 int y = 0;
384 int height = resource_lock->size().height(); 383 int height = rect_to_copy.height();
385 while (y < height) { 384 while (y < height) {
386 // Copy at most |chunk_size_in_rows|. 385 // Copy at most |chunk_size_in_rows|.
387 int rows_to_copy = std::min(chunk_size_in_rows, height - y); 386 int rows_to_copy = std::min(chunk_size_in_rows, height - y);
388 DCHECK_GT(rows_to_copy, 0); 387 DCHECK_GT(rows_to_copy, 0);
389 388
390 gl->CopySubTextureCHROMIUM(staging_buffer->texture_id, 0, GL_TEXTURE_2D, 389 gl->CopySubTextureCHROMIUM(
391 resource_texture_id, 0, 0, y, 0, y, 390 staging_buffer->texture_id, 0, GL_TEXTURE_2D, resource_texture_id, 0,
392 resource_lock->size().width(), rows_to_copy, 391 0, y, 0, y, rect_to_copy.width(), rows_to_copy, false, false, false);
393 false, false, false);
394 y += rows_to_copy; 392 y += rows_to_copy;
395 393
396 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory 394 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory
397 // used for this copy operation. 395 // used for this copy operation.
398 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; 396 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row;
399 397
400 if (bytes_scheduled_since_last_flush_ >= max_bytes_per_copy_operation_) { 398 if (bytes_scheduled_since_last_flush_ >= max_bytes_per_copy_operation_) {
401 gl->ShallowFlushCHROMIUM(); 399 gl->ShallowFlushCHROMIUM();
402 bytes_scheduled_since_last_flush_ = 0; 400 bytes_scheduled_since_last_flush_ = 0;
403 } 401 }
(...skipping 20 matching lines...) Expand all
424 resource_lock->set_synchronized(!async_worker_context_enabled_); 422 resource_lock->set_synchronized(!async_worker_context_enabled_);
425 } 423 }
426 424
427 gfx::BufferUsage OneCopyRasterBufferProvider::StagingBufferUsage() const { 425 gfx::BufferUsage OneCopyRasterBufferProvider::StagingBufferUsage() const {
428 return use_partial_raster_ 426 return use_partial_raster_
429 ? gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT 427 ? gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT
430 : gfx::BufferUsage::GPU_READ_CPU_READ_WRITE; 428 : gfx::BufferUsage::GPU_READ_CPU_READ_WRITE;
431 } 429 }
432 430
433 } // namespace cc 431 } // namespace cc
OLDNEW
« no previous file with comments | « cc/raster/one_copy_raster_buffer_provider.h ('k') | cc/resources/resource_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698