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 "ui/gfx/buffer_format_util.h" | 7 #include "ui/gfx/buffer_format_util.h" |
8 #include "ui/gfx/gpu_memory_buffer.h" | 8 #include "ui/gfx/gpu_memory_buffer.h" |
9 | 9 |
10 namespace media { | 10 namespace media { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { | 14 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { |
15 public: | 15 public: |
16 GpuMemoryBufferImpl(const gfx::Size& size, gfx::BufferFormat format) | 16 GpuMemoryBufferImpl(const gfx::Size& size, gfx::BufferFormat format) |
17 : format_(format), size_(size), | 17 : mapped_(false), |
| 18 format_(format), |
| 19 size_(size), |
18 num_planes_(gfx::NumberOfPlanesForBufferFormat(format)) { | 20 num_planes_(gfx::NumberOfPlanesForBufferFormat(format)) { |
19 DCHECK(gfx::BufferFormat::R_8 == format_ || | 21 DCHECK(gfx::BufferFormat::R_8 == format_ || |
20 gfx::BufferFormat::YUV_420_BIPLANAR == format_ || | 22 gfx::BufferFormat::YUV_420_BIPLANAR == format_ || |
21 gfx::BufferFormat::UYVY_422 == format_); | 23 gfx::BufferFormat::UYVY_422 == format_); |
22 DCHECK(num_planes_ <= kMaxPlanes); | 24 DCHECK(num_planes_ <= kMaxPlanes); |
23 for (int i = 0; i < static_cast<int>(num_planes_); ++i) { | 25 for (int i = 0; i < static_cast<int>(num_planes_); ++i) { |
24 bytes_[i].resize( | 26 bytes_[i].resize( |
25 gfx::RowSizeForBufferFormat(size_.width(), format_, i) * | 27 gfx::RowSizeForBufferFormat(size_.width(), format_, i) * |
26 size_.height() / gfx::SubsamplingFactorForBufferFormat(format_, i)); | 28 size_.height() / gfx::SubsamplingFactorForBufferFormat(format_, i)); |
27 } | 29 } |
28 } | 30 } |
29 | 31 |
30 // Overridden from gfx::GpuMemoryBuffer: | 32 // Overridden from gfx::GpuMemoryBuffer: |
31 bool Map(void** data) override { | 33 bool Map() override { |
32 for (size_t plane = 0; plane < num_planes_; ++plane) | 34 DCHECK(!mapped_); |
33 data[plane] = &bytes_[plane][0]; | 35 mapped_ = true; |
34 return true; | 36 return true; |
35 } | 37 } |
36 void Unmap() override {} | 38 void* memory(size_t plane) override { |
| 39 DCHECK(mapped_); |
| 40 DCHECK_LT(plane, num_planes_); |
| 41 return &bytes_[plane][0]; |
| 42 } |
| 43 void Unmap() override { |
| 44 DCHECK(mapped_); |
| 45 mapped_ = false; |
| 46 } |
37 gfx::Size GetSize() const override { return size_; } | 47 gfx::Size GetSize() const override { return size_; } |
38 gfx::BufferFormat GetFormat() const override { | 48 gfx::BufferFormat GetFormat() const override { |
39 return format_; | 49 return format_; |
40 } | 50 } |
41 void GetStride(int* strides) const override { | 51 int stride(size_t plane) const override { |
42 for (int plane = 0; plane < static_cast<int>(num_planes_); ++plane) { | 52 DCHECK_LT(plane, num_planes_); |
43 strides[plane] = static_cast<int>( | 53 return static_cast<int>(gfx::RowSizeForBufferFormat( |
44 gfx::RowSizeForBufferFormat(size_.width(), format_, plane)); | 54 size_.width(), format_, static_cast<int>(plane))); |
45 } | |
46 } | 55 } |
47 gfx::GpuMemoryBufferId GetId() const override { | 56 gfx::GpuMemoryBufferId GetId() const override { |
48 NOTREACHED(); | 57 NOTREACHED(); |
49 return gfx::GpuMemoryBufferId(0); | 58 return gfx::GpuMemoryBufferId(0); |
50 } | 59 } |
51 gfx::GpuMemoryBufferHandle GetHandle() const override { | 60 gfx::GpuMemoryBufferHandle GetHandle() const override { |
52 NOTREACHED(); | 61 NOTREACHED(); |
53 return gfx::GpuMemoryBufferHandle(); | 62 return gfx::GpuMemoryBufferHandle(); |
54 } | 63 } |
55 ClientBuffer AsClientBuffer() override { | 64 ClientBuffer AsClientBuffer() override { |
56 return reinterpret_cast<ClientBuffer>(this); | 65 return reinterpret_cast<ClientBuffer>(this); |
57 } | 66 } |
58 | 67 |
59 private: | 68 private: |
60 static const size_t kMaxPlanes = 3; | 69 static const size_t kMaxPlanes = 3; |
61 | 70 |
| 71 bool mapped_; |
62 gfx::BufferFormat format_; | 72 gfx::BufferFormat format_; |
63 const gfx::Size size_; | 73 const gfx::Size size_; |
64 size_t num_planes_; | 74 size_t num_planes_; |
65 std::vector<uint8> bytes_[kMaxPlanes]; | 75 std::vector<uint8> bytes_[kMaxPlanes]; |
66 }; | 76 }; |
67 | 77 |
68 } // unnamed namespace | 78 } // unnamed namespace |
69 | 79 |
70 MockGpuVideoAcceleratorFactories::MockGpuVideoAcceleratorFactories( | 80 MockGpuVideoAcceleratorFactories::MockGpuVideoAcceleratorFactories( |
71 gpu::gles2::GLES2Interface* gles2) | 81 gpu::gles2::GLES2Interface* gles2) |
72 : gles2_(gles2) {} | 82 : gles2_(gles2) {} |
73 | 83 |
74 MockGpuVideoAcceleratorFactories::~MockGpuVideoAcceleratorFactories() {} | 84 MockGpuVideoAcceleratorFactories::~MockGpuVideoAcceleratorFactories() {} |
75 | 85 |
76 bool MockGpuVideoAcceleratorFactories::IsGpuVideoAcceleratorEnabled() { | 86 bool MockGpuVideoAcceleratorFactories::IsGpuVideoAcceleratorEnabled() { |
77 return true; | 87 return true; |
78 } | 88 } |
79 | 89 |
80 scoped_ptr<gfx::GpuMemoryBuffer> | 90 scoped_ptr<gfx::GpuMemoryBuffer> |
81 MockGpuVideoAcceleratorFactories::AllocateGpuMemoryBuffer( | 91 MockGpuVideoAcceleratorFactories::AllocateGpuMemoryBuffer( |
82 const gfx::Size& size, | 92 const gfx::Size& size, |
83 gfx::BufferFormat format, | 93 gfx::BufferFormat format, |
84 gfx::BufferUsage usage) { | 94 gfx::BufferUsage /* usage */) { |
85 if (fail_to_allocate_gpu_memory_buffer_) | 95 if (fail_to_allocate_gpu_memory_buffer_) |
86 return nullptr; | 96 return nullptr; |
87 return make_scoped_ptr<gfx::GpuMemoryBuffer>( | 97 return make_scoped_ptr<gfx::GpuMemoryBuffer>( |
88 new GpuMemoryBufferImpl(size, format)); | 98 new GpuMemoryBufferImpl(size, format)); |
89 } | 99 } |
90 | 100 |
91 scoped_ptr<base::SharedMemory> | 101 scoped_ptr<base::SharedMemory> |
92 MockGpuVideoAcceleratorFactories::CreateSharedMemory(size_t size) { | 102 MockGpuVideoAcceleratorFactories::CreateSharedMemory(size_t size) { |
93 return nullptr; | 103 return nullptr; |
94 } | 104 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 }; | 137 }; |
128 } // namespace | 138 } // namespace |
129 | 139 |
130 scoped_ptr<GpuVideoAcceleratorFactories::ScopedGLContextLock> | 140 scoped_ptr<GpuVideoAcceleratorFactories::ScopedGLContextLock> |
131 MockGpuVideoAcceleratorFactories::GetGLContextLock() { | 141 MockGpuVideoAcceleratorFactories::GetGLContextLock() { |
132 DCHECK(gles2_); | 142 DCHECK(gles2_); |
133 return make_scoped_ptr(new ScopedGLContextLockImpl(this)); | 143 return make_scoped_ptr(new ScopedGLContextLockImpl(this)); |
134 } | 144 } |
135 | 145 |
136 } // namespace media | 146 } // namespace media |
OLD | NEW |