Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(938)

Side by Side Diff: cc/test/test_gpu_memory_buffer_manager.cc

Issue 683113005: Update from chromium https://crrev.com/302282 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/test/test_gpu_memory_buffer_manager.h ('k') | cc/test/test_image_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/test/test_gpu_memory_buffer_manager.h" 5 #include "cc/test/test_gpu_memory_buffer_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/gfx/gpu_memory_buffer.h" 8 #include "ui/gfx/gpu_memory_buffer.h"
9 9
10 namespace cc { 10 namespace cc {
11 namespace { 11 namespace {
12 12
13 size_t BytesPerPixel(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 4;
19 }
20
21 NOTREACHED();
22 return 0;
23 }
24
13 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { 25 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
14 public: 26 public:
15 GpuMemoryBufferImpl(const gfx::Size& size, Format format) 27 GpuMemoryBufferImpl(const gfx::Size& size,
28 Format format,
29 scoped_ptr<base::SharedMemory> shared_memory)
16 : size_(size), 30 : size_(size),
17 format_(format), 31 format_(format),
18 pixels_(new uint8[size.GetArea() * BytesPerPixel(format)]), 32 shared_memory_(shared_memory.Pass()),
19 mapped_(false) {} 33 mapped_(false) {}
20 34
21 // Overridden from gfx::GpuMemoryBuffer: 35 // Overridden from gfx::GpuMemoryBuffer:
22 void* Map() override { 36 void* Map() override {
23 DCHECK(!mapped_); 37 DCHECK(!mapped_);
38 if (!shared_memory_->Map(size_.GetArea() * BytesPerPixel(format_)))
39 return NULL;
24 mapped_ = true; 40 mapped_ = true;
25 return pixels_.get(); 41 return shared_memory_->memory();
26 } 42 }
27 void Unmap() override { 43 void Unmap() override {
28 DCHECK(mapped_); 44 DCHECK(mapped_);
45 shared_memory_->Unmap();
29 mapped_ = false; 46 mapped_ = false;
30 } 47 }
31 bool IsMapped() const override { return mapped_; } 48 bool IsMapped() const override { return mapped_; }
32 Format GetFormat() const override { return format_; } 49 Format GetFormat() const override { return format_; }
33 uint32 GetStride() const override { 50 uint32 GetStride() const override {
34 return size_.width() * BytesPerPixel(format_); 51 return size_.width() * BytesPerPixel(format_);
35 } 52 }
36 gfx::GpuMemoryBufferHandle GetHandle() const override { 53 gfx::GpuMemoryBufferHandle GetHandle() const override {
37 NOTREACHED(); 54 gfx::GpuMemoryBufferHandle handle;
38 return gfx::GpuMemoryBufferHandle(); 55 handle.type = gfx::SHARED_MEMORY_BUFFER;
56 handle.handle = shared_memory_->handle();
57 return handle;
39 } 58 }
40 ClientBuffer AsClientBuffer() override { 59 ClientBuffer AsClientBuffer() override {
41 return reinterpret_cast<ClientBuffer>(this); 60 return reinterpret_cast<ClientBuffer>(this);
42 } 61 }
43 62
44 private: 63 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;
51 }
52
53 NOTREACHED();
54 return 0;
55 }
56
57 const gfx::Size size_; 64 const gfx::Size size_;
58 gfx::GpuMemoryBuffer::Format format_; 65 gfx::GpuMemoryBuffer::Format format_;
59 scoped_ptr<uint8[]> pixels_; 66 scoped_ptr<base::SharedMemory> shared_memory_;
60 bool mapped_; 67 bool mapped_;
61 }; 68 };
62 69
63 } // namespace 70 } // namespace
64 71
65 TestGpuMemoryBufferManager::TestGpuMemoryBufferManager() { 72 TestGpuMemoryBufferManager::TestGpuMemoryBufferManager() {
66 } 73 }
67 74
68 TestGpuMemoryBufferManager::~TestGpuMemoryBufferManager() { 75 TestGpuMemoryBufferManager::~TestGpuMemoryBufferManager() {
69 } 76 }
70 77
71 scoped_ptr<gfx::GpuMemoryBuffer> 78 scoped_ptr<gfx::GpuMemoryBuffer>
72 TestGpuMemoryBufferManager::AllocateGpuMemoryBuffer( 79 TestGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
73 const gfx::Size& size, 80 const gfx::Size& size,
74 gfx::GpuMemoryBuffer::Format format, 81 gfx::GpuMemoryBuffer::Format format,
75 gfx::GpuMemoryBuffer::Usage usage) { 82 gfx::GpuMemoryBuffer::Usage usage) {
83 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory);
84 if (!shared_memory->CreateAnonymous(size.GetArea() * BytesPerPixel(format)))
85 return nullptr;
76 return make_scoped_ptr<gfx::GpuMemoryBuffer>( 86 return make_scoped_ptr<gfx::GpuMemoryBuffer>(
77 new GpuMemoryBufferImpl(size, format)); 87 new GpuMemoryBufferImpl(size, format, shared_memory.Pass()));
78 } 88 }
79 89
80 gfx::GpuMemoryBuffer* 90 gfx::GpuMemoryBuffer*
81 TestGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer( 91 TestGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
82 ClientBuffer buffer) { 92 ClientBuffer buffer) {
83 return reinterpret_cast<gfx::GpuMemoryBuffer*>(buffer); 93 return reinterpret_cast<gfx::GpuMemoryBuffer*>(buffer);
84 } 94 }
85 95
86 } // namespace cc 96 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/test_gpu_memory_buffer_manager.h ('k') | cc/test/test_image_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698