1c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// found in the LICENSE file. 4c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 5b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" 6c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 7a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/memory/shared_memory.h" 8a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "gpu/command_buffer/service/safe_shared_memory_pool.h" 9a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 10b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)namespace gpu { 11c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 12a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace { 13a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 14a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void* GetAddressImpl(base::SharedMemory* shared_memory, 15a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) uint32 shm_size, 16a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) uint32 shm_data_offset, 17a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) uint32 shm_data_size) { 18a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // Memory bounds have already been validated, so there 19a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // are just DCHECKS here. 20a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) DCHECK(shared_memory); 21a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) DCHECK(shared_memory->memory()); 22a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) DCHECK_LE(shm_data_offset + shm_data_size, shm_size); 23a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return static_cast<int8*>(shared_memory->memory()) + shm_data_offset; 24a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} 25a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 26a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} // namespace 27a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)AsyncPixelTransferUploadStats::AsyncPixelTransferUploadStats() 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) : texture_upload_count_(0) {} 3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)AsyncPixelTransferUploadStats::~AsyncPixelTransferUploadStats() {} 3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void AsyncPixelTransferUploadStats::AddUpload(base::TimeDelta transfer_time) { 3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::AutoLock scoped_lock(lock_); 3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) texture_upload_count_++; 3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) total_texture_upload_time_ += transfer_time; 3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)int AsyncPixelTransferUploadStats::GetStats( 4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::TimeDelta* total_texture_upload_time) { 4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::AutoLock scoped_lock(lock_); 4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (total_texture_upload_time) 4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) *total_texture_upload_time = total_texture_upload_time_; 4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return texture_upload_count_; 4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 47a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)AsyncPixelTransferDelegate::AsyncPixelTransferDelegate(){} 48c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 49a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)AsyncPixelTransferDelegate::~AsyncPixelTransferDelegate(){} 50c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 51a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// static 52a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void* AsyncPixelTransferDelegate::GetAddress( 53a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) const AsyncMemoryParams& mem_params) { 54a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return GetAddressImpl(mem_params.shared_memory, 55a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) mem_params.shm_size, 56a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) mem_params.shm_data_offset, 57a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) mem_params.shm_data_size); 58a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} 59c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 60a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// static 61a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void* AsyncPixelTransferDelegate::GetAddress( 62a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) ScopedSafeSharedMemory* safe_shared_memory, 63a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) const AsyncMemoryParams& mem_params) { 64a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return GetAddressImpl(safe_shared_memory->shared_memory(), 65a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) mem_params.shm_size, 66a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) mem_params.shm_data_offset, 67a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) mem_params.shm_data_size); 68a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} 69c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace gpu 71