| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "media/renderers/mock_gpu_video_accelerator_factories.h" | 5 #include "media/renderers/mock_gpu_video_accelerator_factories.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "ui/gfx/buffer_format_util.h" | 8 #include "ui/gfx/buffer_format_util.h" |
| 9 #include "ui/gfx/gpu_memory_buffer.h" | 9 #include "ui/gfx/gpu_memory_buffer.h" |
| 10 | 10 |
| 11 namespace media { | 11 namespace media { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 bool gpu_memory_buffers_in_use_by_window_server = false; | |
| 16 int g_next_gpu_memory_buffer_id = 1; | 15 int g_next_gpu_memory_buffer_id = 1; |
| 17 | 16 |
| 18 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { | 17 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { |
| 19 public: | 18 public: |
| 20 GpuMemoryBufferImpl(const gfx::Size& size, gfx::BufferFormat format) | 19 GpuMemoryBufferImpl(const gfx::Size& size, gfx::BufferFormat format) |
| 21 : mapped_(false), | 20 : mapped_(false), |
| 22 format_(format), | 21 format_(format), |
| 23 size_(size), | 22 size_(size), |
| 24 num_planes_(gfx::NumberOfPlanesForBufferFormat(format)), | 23 num_planes_(gfx::NumberOfPlanesForBufferFormat(format)), |
| 25 id_(g_next_gpu_memory_buffer_id++) { | 24 id_(g_next_gpu_memory_buffer_id++) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 42 } | 41 } |
| 43 void* memory(size_t plane) override { | 42 void* memory(size_t plane) override { |
| 44 DCHECK(mapped_); | 43 DCHECK(mapped_); |
| 45 DCHECK_LT(plane, num_planes_); | 44 DCHECK_LT(plane, num_planes_); |
| 46 return &bytes_[plane][0]; | 45 return &bytes_[plane][0]; |
| 47 } | 46 } |
| 48 void Unmap() override { | 47 void Unmap() override { |
| 49 DCHECK(mapped_); | 48 DCHECK(mapped_); |
| 50 mapped_ = false; | 49 mapped_ = false; |
| 51 } | 50 } |
| 52 bool IsInUseByMacOSWindowServer() const override { | |
| 53 return gpu_memory_buffers_in_use_by_window_server; | |
| 54 } | |
| 55 gfx::Size GetSize() const override { return size_; } | 51 gfx::Size GetSize() const override { return size_; } |
| 56 gfx::BufferFormat GetFormat() const override { | 52 gfx::BufferFormat GetFormat() const override { |
| 57 return format_; | 53 return format_; |
| 58 } | 54 } |
| 59 int stride(size_t plane) const override { | 55 int stride(size_t plane) const override { |
| 60 DCHECK_LT(plane, num_planes_); | 56 DCHECK_LT(plane, num_planes_); |
| 61 return static_cast<int>(gfx::RowSizeForBufferFormat( | 57 return static_cast<int>(gfx::RowSizeForBufferFormat( |
| 62 size_.width(), format_, static_cast<int>(plane))); | 58 size_.width(), format_, static_cast<int>(plane))); |
| 63 } | 59 } |
| 64 gfx::GpuMemoryBufferId GetId() const override { return id_; } | 60 gfx::GpuMemoryBufferId GetId() const override { return id_; } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 std::unique_ptr<gfx::GpuMemoryBuffer> | 92 std::unique_ptr<gfx::GpuMemoryBuffer> |
| 97 MockGpuVideoAcceleratorFactories::AllocateGpuMemoryBuffer( | 93 MockGpuVideoAcceleratorFactories::AllocateGpuMemoryBuffer( |
| 98 const gfx::Size& size, | 94 const gfx::Size& size, |
| 99 gfx::BufferFormat format, | 95 gfx::BufferFormat format, |
| 100 gfx::BufferUsage /* usage */) { | 96 gfx::BufferUsage /* usage */) { |
| 101 if (fail_to_allocate_gpu_memory_buffer_) | 97 if (fail_to_allocate_gpu_memory_buffer_) |
| 102 return nullptr; | 98 return nullptr; |
| 103 return base::WrapUnique(new GpuMemoryBufferImpl(size, format)); | 99 return base::WrapUnique(new GpuMemoryBufferImpl(size, format)); |
| 104 } | 100 } |
| 105 | 101 |
| 106 void MockGpuVideoAcceleratorFactories:: | |
| 107 SetGpuMemoryBuffersInUseByMacOSWindowServer(bool in_use) { | |
| 108 gpu_memory_buffers_in_use_by_window_server = in_use; | |
| 109 } | |
| 110 | |
| 111 std::unique_ptr<base::SharedMemory> | 102 std::unique_ptr<base::SharedMemory> |
| 112 MockGpuVideoAcceleratorFactories::CreateSharedMemory(size_t size) { | 103 MockGpuVideoAcceleratorFactories::CreateSharedMemory(size_t size) { |
| 113 return nullptr; | 104 return nullptr; |
| 114 } | 105 } |
| 115 | 106 |
| 116 std::unique_ptr<VideoDecodeAccelerator> | 107 std::unique_ptr<VideoDecodeAccelerator> |
| 117 MockGpuVideoAcceleratorFactories::CreateVideoDecodeAccelerator() { | 108 MockGpuVideoAcceleratorFactories::CreateVideoDecodeAccelerator() { |
| 118 return base::WrapUnique(DoCreateVideoDecodeAccelerator()); | 109 return base::WrapUnique(DoCreateVideoDecodeAccelerator()); |
| 119 } | 110 } |
| 120 | 111 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 148 }; | 139 }; |
| 149 } // namespace | 140 } // namespace |
| 150 | 141 |
| 151 std::unique_ptr<GpuVideoAcceleratorFactories::ScopedGLContextLock> | 142 std::unique_ptr<GpuVideoAcceleratorFactories::ScopedGLContextLock> |
| 152 MockGpuVideoAcceleratorFactories::GetGLContextLock() { | 143 MockGpuVideoAcceleratorFactories::GetGLContextLock() { |
| 153 DCHECK(gles2_); | 144 DCHECK(gles2_); |
| 154 return base::WrapUnique(new ScopedGLContextLockImpl(this)); | 145 return base::WrapUnique(new ScopedGLContextLockImpl(this)); |
| 155 } | 146 } |
| 156 | 147 |
| 157 } // namespace media | 148 } // namespace media |
| OLD | NEW |