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/gpu_memory_buffer.h" | 8 #include "ui/gfx/gpu_memory_buffer.h" |
8 | 9 |
9 namespace media { | 10 namespace media { |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
13 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { | 14 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { |
14 public: | 15 public: |
15 GpuMemoryBufferImpl(const gfx::Size& size, gfx::BufferFormat format) | 16 GpuMemoryBufferImpl(const gfx::Size& size, gfx::BufferFormat format) |
16 : format_(format), size_(size) { | 17 : format_(format), size_(size), |
| 18 num_planes_(gfx::NumberOfPlanesForBufferFormat(format)) { |
17 DCHECK(gfx::BufferFormat::R_8 == format_ || | 19 DCHECK(gfx::BufferFormat::R_8 == format_ || |
| 20 gfx::BufferFormat::YUV_420_BIPLANAR == format_ || |
18 gfx::BufferFormat::UYVY_422 == format_); | 21 gfx::BufferFormat::UYVY_422 == format_); |
19 bytes_.resize(size_.GetArea() * | 22 DCHECK(num_planes_ <= kMaxPlanes); |
20 (format_ == gfx::BufferFormat::UYVY_422 ? 2 : 1)); | 23 for (int i = 0; i < static_cast<int>(num_planes_); ++i) { |
| 24 bytes_[i].resize( |
| 25 gfx::RowSizeForBufferFormat(size_.width(), format_, i) * |
| 26 size_.height() / gfx::SubsamplingFactorForBufferFormat(format_, i)); |
| 27 } |
21 } | 28 } |
22 | 29 |
23 // Overridden from gfx::GpuMemoryBuffer: | 30 // Overridden from gfx::GpuMemoryBuffer: |
24 bool Map(void** data) override { | 31 bool Map(void** data) override { |
25 data[0] = &bytes_[0]; | 32 for (size_t plane = 0; plane < num_planes_; ++plane) |
| 33 data[plane] = &bytes_[plane][0]; |
26 return true; | 34 return true; |
27 } | 35 } |
28 void Unmap() override{}; | 36 void Unmap() override{}; |
29 bool IsMapped() const override { | 37 bool IsMapped() const override { |
30 NOTREACHED(); | 38 NOTREACHED(); |
31 return false; | 39 return false; |
32 } | 40 } |
33 gfx::BufferFormat GetFormat() const override { | 41 gfx::BufferFormat GetFormat() const override { |
34 NOTREACHED(); | 42 return format_; |
35 return gfx::BufferFormat::R_8; | |
36 } | 43 } |
37 void GetStride(int* stride) const override { | 44 void GetStride(int* strides) const override { |
38 stride[0] = | 45 for (int plane = 0; plane < static_cast<int>(num_planes_); ++plane) { |
39 size_.width() * (format_ == gfx::BufferFormat::UYVY_422 ? 2 : 1); | 46 strides[plane] = static_cast<int>( |
| 47 gfx::RowSizeForBufferFormat(size_.width(), format_, plane)); |
| 48 } |
40 } | 49 } |
41 gfx::GpuMemoryBufferId GetId() const override { | 50 gfx::GpuMemoryBufferId GetId() const override { |
42 NOTREACHED(); | 51 NOTREACHED(); |
43 return gfx::GpuMemoryBufferId(0); | 52 return gfx::GpuMemoryBufferId(0); |
44 } | 53 } |
45 gfx::GpuMemoryBufferHandle GetHandle() const override { | 54 gfx::GpuMemoryBufferHandle GetHandle() const override { |
46 NOTREACHED(); | 55 NOTREACHED(); |
47 return gfx::GpuMemoryBufferHandle(); | 56 return gfx::GpuMemoryBufferHandle(); |
48 } | 57 } |
49 ClientBuffer AsClientBuffer() override { | 58 ClientBuffer AsClientBuffer() override { |
50 return reinterpret_cast<ClientBuffer>(this); | 59 return reinterpret_cast<ClientBuffer>(this); |
51 } | 60 } |
52 | 61 |
53 private: | 62 private: |
| 63 static const size_t kMaxPlanes = 3; |
| 64 |
54 gfx::BufferFormat format_; | 65 gfx::BufferFormat format_; |
55 std::vector<unsigned char> bytes_; | |
56 const gfx::Size size_; | 66 const gfx::Size size_; |
| 67 size_t num_planes_; |
| 68 std::vector<uint8> bytes_[kMaxPlanes]; |
57 }; | 69 }; |
58 | 70 |
59 } // unnamed namespace | 71 } // unnamed namespace |
60 | 72 |
61 MockGpuVideoAcceleratorFactories::MockGpuVideoAcceleratorFactories() {} | 73 MockGpuVideoAcceleratorFactories::MockGpuVideoAcceleratorFactories() {} |
62 | 74 |
63 MockGpuVideoAcceleratorFactories::~MockGpuVideoAcceleratorFactories() {} | 75 MockGpuVideoAcceleratorFactories::~MockGpuVideoAcceleratorFactories() {} |
64 | 76 |
65 bool MockGpuVideoAcceleratorFactories::IsGpuVideoAcceleratorEnabled() { | 77 bool MockGpuVideoAcceleratorFactories::IsGpuVideoAcceleratorEnabled() { |
66 return true; | 78 return true; |
(...skipping 26 matching lines...) Expand all Loading... |
93 bool MockGpuVideoAcceleratorFactories::ShouldUseGpuMemoryBuffersForVideoFrames() | 105 bool MockGpuVideoAcceleratorFactories::ShouldUseGpuMemoryBuffersForVideoFrames() |
94 const { | 106 const { |
95 return false; | 107 return false; |
96 } | 108 } |
97 | 109 |
98 unsigned MockGpuVideoAcceleratorFactories::ImageTextureTarget() { | 110 unsigned MockGpuVideoAcceleratorFactories::ImageTextureTarget() { |
99 return GL_TEXTURE_2D; | 111 return GL_TEXTURE_2D; |
100 } | 112 } |
101 | 113 |
102 } // namespace media | 114 } // namespace media |
OLD | NEW |