Screen Orientation Controller allow rotation for some orientations
[chromium-blink-merge.git] / cc / test / test_gpu_memory_buffer_manager.cc
blob196922f2fc94858242f124d8175eb9ea3dd965b6
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 size_t StrideInBytes(size_t width, gfx::GpuMemoryBuffer::Format format) {
14 switch (format) {
15 case gfx::GpuMemoryBuffer::RGBA_8888:
16 case gfx::GpuMemoryBuffer::RGBX_8888:
17 case gfx::GpuMemoryBuffer::BGRA_8888:
18 return width * 4;
21 NOTREACHED();
22 return 0;
25 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
26 public:
27 GpuMemoryBufferImpl(const gfx::Size& size,
28 Format format,
29 scoped_ptr<base::SharedMemory> shared_memory)
30 : size_(size),
31 format_(format),
32 shared_memory_(shared_memory.Pass()),
33 mapped_(false) {}
35 // Overridden from gfx::GpuMemoryBuffer:
36 void* Map() override {
37 DCHECK(!mapped_);
38 if (!shared_memory_->Map(StrideInBytes(size_.width(), format_) *
39 size_.height()))
40 return NULL;
41 mapped_ = true;
42 return shared_memory_->memory();
44 void Unmap() override {
45 DCHECK(mapped_);
46 shared_memory_->Unmap();
47 mapped_ = false;
49 bool IsMapped() const override { return mapped_; }
50 Format GetFormat() const override { return format_; }
51 uint32 GetStride() const override {
52 return StrideInBytes(size_.width(), format_);
54 gfx::GpuMemoryBufferHandle GetHandle() const override {
55 gfx::GpuMemoryBufferHandle handle;
56 handle.type = gfx::SHARED_MEMORY_BUFFER;
57 handle.handle = shared_memory_->handle();
58 return handle;
60 ClientBuffer AsClientBuffer() override {
61 return reinterpret_cast<ClientBuffer>(this);
64 private:
65 const gfx::Size size_;
66 gfx::GpuMemoryBuffer::Format format_;
67 scoped_ptr<base::SharedMemory> shared_memory_;
68 bool mapped_;
71 } // namespace
73 TestGpuMemoryBufferManager::TestGpuMemoryBufferManager() {
76 TestGpuMemoryBufferManager::~TestGpuMemoryBufferManager() {
79 scoped_ptr<gfx::GpuMemoryBuffer>
80 TestGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
81 const gfx::Size& size,
82 gfx::GpuMemoryBuffer::Format format,
83 gfx::GpuMemoryBuffer::Usage usage) {
84 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory);
85 if (!shared_memory->CreateAnonymous(StrideInBytes(size.width(), format) *
86 size.height()))
87 return nullptr;
88 return make_scoped_ptr<gfx::GpuMemoryBuffer>(
89 new GpuMemoryBufferImpl(size, format, shared_memory.Pass()));
92 gfx::GpuMemoryBuffer*
93 TestGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
94 ClientBuffer buffer) {
95 return reinterpret_cast<gfx::GpuMemoryBuffer*>(buffer);
98 void TestGpuMemoryBufferManager::SetDestructionSyncPoint(
99 gfx::GpuMemoryBuffer* buffer,
100 uint32 sync_point) {
103 } // namespace cc