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
3 // found in the LICENSE file.
5 #include "cc/test/test_gpu_memory_buffer_manager.h"
7 #include "base/logging.h"
8 #include "ui/gfx/gpu_memory_buffer.h"
13 class GpuMemoryBufferImpl
: public gfx::GpuMemoryBuffer
{
15 GpuMemoryBufferImpl(const gfx::Size
& size
, Format format
)
18 pixels_(new uint8
[size
.GetArea() * BytesPerPixel(format
)]),
21 // Overridden from gfx::GpuMemoryBuffer:
22 virtual void* Map() override
{
27 virtual void Unmap() override
{
31 virtual bool IsMapped() const override
{ return mapped_
; }
32 virtual Format
GetFormat() const override
{ return format_
; }
33 virtual uint32
GetStride() const override
{
34 return size_
.width() * BytesPerPixel(format_
);
36 virtual gfx::GpuMemoryBufferHandle
GetHandle() const override
{
38 return gfx::GpuMemoryBufferHandle();
40 virtual ClientBuffer
AsClientBuffer() override
{
41 return reinterpret_cast<ClientBuffer
>(this);
45 static size_t BytesPerPixel(Format format
) {
57 const gfx::Size size_
;
58 gfx::GpuMemoryBuffer::Format format_
;
59 scoped_ptr
<uint8
[]> pixels_
;
65 TestGpuMemoryBufferManager::TestGpuMemoryBufferManager() {
68 TestGpuMemoryBufferManager::~TestGpuMemoryBufferManager() {
71 scoped_ptr
<gfx::GpuMemoryBuffer
>
72 TestGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
73 const gfx::Size
& size
,
74 gfx::GpuMemoryBuffer::Format format
,
75 gfx::GpuMemoryBuffer::Usage usage
) {
76 return make_scoped_ptr
<gfx::GpuMemoryBuffer
>(
77 new GpuMemoryBufferImpl(size
, format
));
81 TestGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
82 ClientBuffer buffer
) {
83 return reinterpret_cast<gfx::GpuMemoryBuffer
*>(buffer
);