Sync: Avoid deadlock in SyncBackendRegistrar / ModelSafeWorker on sync backend shutdown.
[chromium-blink-merge.git] / cc / test / test_gpu_memory_buffer_manager.cc
blob855959e8d08a6a43b032669e067ba2eaf7f703dc
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"
10 namespace cc {
11 namespace {
13 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
14 public:
15 GpuMemoryBufferImpl(const gfx::Size& size, Format format)
16 : size_(size),
17 format_(format),
18 pixels_(new uint8[size.GetArea() * BytesPerPixel(format)]),
19 mapped_(false) {}
21 // Overridden from gfx::GpuMemoryBuffer:
22 virtual void* Map() override {
23 DCHECK(!mapped_);
24 mapped_ = true;
25 return pixels_.get();
27 virtual void Unmap() override {
28 DCHECK(mapped_);
29 mapped_ = false;
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 {
37 NOTREACHED();
38 return gfx::GpuMemoryBufferHandle();
40 virtual ClientBuffer AsClientBuffer() override {
41 return reinterpret_cast<ClientBuffer>(this);
44 private:
45 static size_t BytesPerPixel(Format format) {
46 switch (format) {
47 case RGBA_8888:
48 case RGBX_8888:
49 case BGRA_8888:
50 return 4;
53 NOTREACHED();
54 return 0;
57 const gfx::Size size_;
58 gfx::GpuMemoryBuffer::Format format_;
59 scoped_ptr<uint8[]> pixels_;
60 bool mapped_;
63 } // namespace
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));
80 gfx::GpuMemoryBuffer*
81 TestGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
82 ClientBuffer buffer) {
83 return reinterpret_cast<gfx::GpuMemoryBuffer*>(buffer);
86 } // namespace cc