// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/test/test_gpu_memory_buffer_manager.h"

#include "base/logging.h"
#include "ui/gfx/gpu_memory_buffer.h"

namespace cc {
namespace {

class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
 public:
  GpuMemoryBufferImpl(const gfx::Size& size, Format format)
      : size_(size),
        format_(format),
        pixels_(new uint8[size.GetArea() * BytesPerPixel(format)]),
        mapped_(false) {}

  // Overridden from gfx::GpuMemoryBuffer:
  virtual void* Map() override {
    DCHECK(!mapped_);
    mapped_ = true;
    return pixels_.get();
  }
  virtual void Unmap() override {
    DCHECK(mapped_);
    mapped_ = false;
  }
  virtual bool IsMapped() const override { return mapped_; }
  virtual Format GetFormat() const override { return format_; }
  virtual uint32 GetStride() const override {
    return size_.width() * BytesPerPixel(format_);
  }
  virtual gfx::GpuMemoryBufferHandle GetHandle() const override {
    NOTREACHED();
    return gfx::GpuMemoryBufferHandle();
  }
  virtual ClientBuffer AsClientBuffer() override {
    return reinterpret_cast<ClientBuffer>(this);
  }

 private:
  static size_t BytesPerPixel(Format format) {
    switch (format) {
      case RGBA_8888:
      case RGBX_8888:
      case BGRA_8888:
        return 4;
    }

    NOTREACHED();
    return 0;
  }

  const gfx::Size size_;
  gfx::GpuMemoryBuffer::Format format_;
  scoped_ptr<uint8[]> pixels_;
  bool mapped_;
};

}  // namespace

TestGpuMemoryBufferManager::TestGpuMemoryBufferManager() {
}

TestGpuMemoryBufferManager::~TestGpuMemoryBufferManager() {
}

scoped_ptr<gfx::GpuMemoryBuffer>
TestGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
    const gfx::Size& size,
    gfx::GpuMemoryBuffer::Format format,
    gfx::GpuMemoryBuffer::Usage usage) {
  return make_scoped_ptr<gfx::GpuMemoryBuffer>(
      new GpuMemoryBufferImpl(size, format));
}

gfx::GpuMemoryBuffer*
TestGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
    ClientBuffer buffer) {
  return reinterpret_cast<gfx::GpuMemoryBuffer*>(buffer);
}

}  // namespace cc
