| 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/test/test_gpu_memory_buffer_manager.h" | 5 #include "cc/test/test_gpu_memory_buffer_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/numerics/safe_conversions.h" | 8 #include "base/numerics/safe_conversions.h" |
| 9 #include "ui/gfx/buffer_format_util.h" | 9 #include "ui/gfx/buffer_format_util.h" |
| 10 #include "ui/gfx/gpu_memory_buffer.h" | 10 #include "ui/gfx/gpu_memory_buffer.h" |
| 11 | 11 |
| 12 namespace cc { | 12 namespace cc { |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { | 15 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { |
| 16 public: | 16 public: |
| 17 GpuMemoryBufferImpl(const gfx::Size& size, | 17 GpuMemoryBufferImpl(const gfx::Size& size, |
| 18 gfx::BufferFormat format, | 18 gfx::BufferFormat format, |
| 19 scoped_ptr<base::SharedMemory> shared_memory) | 19 scoped_ptr<base::SharedMemory> shared_memory) |
| 20 : size_(size), | 20 : size_(size), |
| 21 format_(format), | 21 format_(format), |
| 22 shared_memory_(shared_memory.Pass()), | 22 shared_memory_(shared_memory.Pass()), |
| 23 mapped_(false) {} | 23 mapped_(false) {} |
| 24 | 24 |
| 25 // Overridden from gfx::GpuMemoryBuffer: | 25 // Overridden from gfx::GpuMemoryBuffer: |
| 26 bool Map(void** data) override { | 26 bool Map() override { |
| 27 DCHECK(!mapped_); | 27 DCHECK(!mapped_); |
| 28 if (!shared_memory_->Map(gfx::BufferSizeForBufferFormat(size_, format_))) | 28 if (!shared_memory_->Map(gfx::BufferSizeForBufferFormat(size_, format_))) |
| 29 return false; | 29 return false; |
| 30 mapped_ = true; | 30 mapped_ = true; |
| 31 size_t offset = 0; | |
| 32 int num_planes = | |
| 33 static_cast<int>(gfx::NumberOfPlanesForBufferFormat(format_)); | |
| 34 for (int i = 0; i < num_planes; ++i) { | |
| 35 data[i] = reinterpret_cast<uint8*>(shared_memory_->memory()) + offset; | |
| 36 offset += | |
| 37 gfx::RowSizeForBufferFormat(size_.width(), format_, i) * | |
| 38 (size_.height() / gfx::SubsamplingFactorForBufferFormat(format_, i)); | |
| 39 } | |
| 40 return true; | 31 return true; |
| 41 } | 32 } |
| 33 void* memory(size_t plane) override { |
| 34 DCHECK(mapped_); |
| 35 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); |
| 36 return reinterpret_cast<uint8_t*>(shared_memory_->memory()) + |
| 37 gfx::BufferOffsetForBufferFormat(size_, format_, plane); |
| 38 } |
| 42 void Unmap() override { | 39 void Unmap() override { |
| 43 DCHECK(mapped_); | 40 DCHECK(mapped_); |
| 44 shared_memory_->Unmap(); | 41 shared_memory_->Unmap(); |
| 45 mapped_ = false; | 42 mapped_ = false; |
| 46 } | 43 } |
| 47 gfx::Size GetSize() const override { return size_; } | 44 gfx::Size GetSize() const override { return size_; } |
| 48 gfx::BufferFormat GetFormat() const override { return format_; } | 45 gfx::BufferFormat GetFormat() const override { return format_; } |
| 49 void GetStride(int* stride) const override { | 46 int stride(size_t plane) const override { |
| 50 int num_planes = | 47 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); |
| 51 static_cast<int>(gfx::NumberOfPlanesForBufferFormat(format_)); | 48 return base::checked_cast<int>(gfx::RowSizeForBufferFormat( |
| 52 for (int i = 0; i < num_planes; ++i) | 49 size_.width(), format_, static_cast<int>(plane))); |
| 53 stride[i] = base::checked_cast<int>( | |
| 54 gfx::RowSizeForBufferFormat(size_.width(), format_, i)); | |
| 55 } | 50 } |
| 56 gfx::GpuMemoryBufferId GetId() const override { | 51 gfx::GpuMemoryBufferId GetId() const override { |
| 57 NOTREACHED(); | 52 NOTREACHED(); |
| 58 return gfx::GpuMemoryBufferId(0); | 53 return gfx::GpuMemoryBufferId(0); |
| 59 } | 54 } |
| 60 gfx::GpuMemoryBufferHandle GetHandle() const override { | 55 gfx::GpuMemoryBufferHandle GetHandle() const override { |
| 61 gfx::GpuMemoryBufferHandle handle; | 56 gfx::GpuMemoryBufferHandle handle; |
| 62 handle.type = gfx::SHARED_MEMORY_BUFFER; | 57 handle.type = gfx::SHARED_MEMORY_BUFFER; |
| 63 handle.handle = shared_memory_->handle(); | 58 handle.handle = shared_memory_->handle(); |
| 64 return handle; | 59 return handle; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 ClientBuffer buffer) { | 103 ClientBuffer buffer) { |
| 109 return reinterpret_cast<gfx::GpuMemoryBuffer*>(buffer); | 104 return reinterpret_cast<gfx::GpuMemoryBuffer*>(buffer); |
| 110 } | 105 } |
| 111 | 106 |
| 112 void TestGpuMemoryBufferManager::SetDestructionSyncPoint( | 107 void TestGpuMemoryBufferManager::SetDestructionSyncPoint( |
| 113 gfx::GpuMemoryBuffer* buffer, | 108 gfx::GpuMemoryBuffer* buffer, |
| 114 uint32 sync_point) { | 109 uint32 sync_point) { |
| 115 } | 110 } |
| 116 | 111 |
| 117 } // namespace cc | 112 } // namespace cc |
| OLD | NEW |