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
3 // found in the LICENSE file.
5 #include "media/renderers/mock_gpu_video_accelerator_factories.h"
7 #include "ui/gfx/buffer_format_util.h"
8 #include "ui/gfx/gpu_memory_buffer.h"
14 class GpuMemoryBufferImpl
: public gfx::GpuMemoryBuffer
{
16 GpuMemoryBufferImpl(const gfx::Size
& size
, gfx::BufferFormat format
)
17 : format_(format
), size_(size
),
18 num_planes_(gfx::NumberOfPlanesForBufferFormat(format
)) {
19 DCHECK(gfx::BufferFormat::R_8
== format_
||
20 gfx::BufferFormat::YUV_420_BIPLANAR
== format_
||
21 gfx::BufferFormat::UYVY_422
== format_
);
22 DCHECK(num_planes_
<= kMaxPlanes
);
23 for (int i
= 0; i
< static_cast<int>(num_planes_
); ++i
) {
25 gfx::RowSizeForBufferFormat(size_
.width(), format_
, i
) *
26 size_
.height() / gfx::SubsamplingFactorForBufferFormat(format_
, i
));
30 // Overridden from gfx::GpuMemoryBuffer:
31 bool Map(void** data
) override
{
32 for (size_t plane
= 0; plane
< num_planes_
; ++plane
)
33 data
[plane
] = &bytes_
[plane
][0];
36 void Unmap() override
{};
37 bool IsMapped() const override
{
41 gfx::BufferFormat
GetFormat() const override
{
44 void GetStride(int* strides
) const override
{
45 for (int plane
= 0; plane
< static_cast<int>(num_planes_
); ++plane
) {
46 strides
[plane
] = static_cast<int>(
47 gfx::RowSizeForBufferFormat(size_
.width(), format_
, plane
));
50 gfx::GpuMemoryBufferId
GetId() const override
{
52 return gfx::GpuMemoryBufferId(0);
54 gfx::GpuMemoryBufferHandle
GetHandle() const override
{
56 return gfx::GpuMemoryBufferHandle();
58 ClientBuffer
AsClientBuffer() override
{
59 return reinterpret_cast<ClientBuffer
>(this);
63 static const size_t kMaxPlanes
= 3;
65 gfx::BufferFormat format_
;
66 const gfx::Size size_
;
68 std::vector
<uint8
> bytes_
[kMaxPlanes
];
71 } // unnamed namespace
73 MockGpuVideoAcceleratorFactories::MockGpuVideoAcceleratorFactories() {}
75 MockGpuVideoAcceleratorFactories::~MockGpuVideoAcceleratorFactories() {}
77 bool MockGpuVideoAcceleratorFactories::IsGpuVideoAcceleratorEnabled() {
81 scoped_ptr
<gfx::GpuMemoryBuffer
>
82 MockGpuVideoAcceleratorFactories::AllocateGpuMemoryBuffer(
83 const gfx::Size
& size
,
84 gfx::BufferFormat format
,
85 gfx::BufferUsage usage
) {
86 return make_scoped_ptr
<gfx::GpuMemoryBuffer
>(
87 new GpuMemoryBufferImpl(size
, format
));
90 scoped_ptr
<base::SharedMemory
>
91 MockGpuVideoAcceleratorFactories::CreateSharedMemory(size_t size
) {
95 scoped_ptr
<VideoDecodeAccelerator
>
96 MockGpuVideoAcceleratorFactories::CreateVideoDecodeAccelerator() {
97 return scoped_ptr
<VideoDecodeAccelerator
>(DoCreateVideoDecodeAccelerator());
100 scoped_ptr
<VideoEncodeAccelerator
>
101 MockGpuVideoAcceleratorFactories::CreateVideoEncodeAccelerator() {
102 return scoped_ptr
<VideoEncodeAccelerator
>(DoCreateVideoEncodeAccelerator());
105 bool MockGpuVideoAcceleratorFactories::ShouldUseGpuMemoryBuffersForVideoFrames()
110 unsigned MockGpuVideoAcceleratorFactories::ImageTextureTarget() {
111 return GL_TEXTURE_2D
;