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

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

Issue 806653006: Update GPU memory buffers to use StrideInBytes internally. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nit Created 5 years, 11 months 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 | « no previous file | content/common/gpu/client/gpu_memory_buffer_impl.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) { 13 size_t StrideInBytes(size_t width, gfx::GpuMemoryBuffer::Format format) {
14 switch (format) { 14 switch (format) {
15 case gfx::GpuMemoryBuffer::RGBA_8888: 15 case gfx::GpuMemoryBuffer::RGBA_8888:
16 case gfx::GpuMemoryBuffer::RGBX_8888: 16 case gfx::GpuMemoryBuffer::RGBX_8888:
17 case gfx::GpuMemoryBuffer::BGRA_8888: 17 case gfx::GpuMemoryBuffer::BGRA_8888:
18 return 4; 18 return width * 4;
19 } 19 }
20 20
21 NOTREACHED(); 21 NOTREACHED();
22 return 0; 22 return 0;
23 } 23 }
24 24
25 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { 25 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
26 public: 26 public:
27 GpuMemoryBufferImpl(const gfx::Size& size, 27 GpuMemoryBufferImpl(const gfx::Size& size,
28 Format format, 28 Format format,
29 scoped_ptr<base::SharedMemory> shared_memory) 29 scoped_ptr<base::SharedMemory> shared_memory)
30 : size_(size), 30 : size_(size),
31 format_(format), 31 format_(format),
32 shared_memory_(shared_memory.Pass()), 32 shared_memory_(shared_memory.Pass()),
33 mapped_(false) {} 33 mapped_(false) {}
34 34
35 // Overridden from gfx::GpuMemoryBuffer: 35 // Overridden from gfx::GpuMemoryBuffer:
36 void* Map() override { 36 void* Map() override {
37 DCHECK(!mapped_); 37 DCHECK(!mapped_);
38 if (!shared_memory_->Map(size_.GetArea() * BytesPerPixel(format_))) 38 if (!shared_memory_->Map(StrideInBytes(size_.width(), format_) *
39 size_.height()))
39 return NULL; 40 return NULL;
40 mapped_ = true; 41 mapped_ = true;
41 return shared_memory_->memory(); 42 return shared_memory_->memory();
42 } 43 }
43 void Unmap() override { 44 void Unmap() override {
44 DCHECK(mapped_); 45 DCHECK(mapped_);
45 shared_memory_->Unmap(); 46 shared_memory_->Unmap();
46 mapped_ = false; 47 mapped_ = false;
47 } 48 }
48 bool IsMapped() const override { return mapped_; } 49 bool IsMapped() const override { return mapped_; }
49 Format GetFormat() const override { return format_; } 50 Format GetFormat() const override { return format_; }
50 uint32 GetStride() const override { 51 uint32 GetStride() const override {
51 return size_.width() * BytesPerPixel(format_); 52 return StrideInBytes(size_.width(), format_);
52 } 53 }
53 gfx::GpuMemoryBufferHandle GetHandle() const override { 54 gfx::GpuMemoryBufferHandle GetHandle() const override {
54 gfx::GpuMemoryBufferHandle handle; 55 gfx::GpuMemoryBufferHandle handle;
55 handle.type = gfx::SHARED_MEMORY_BUFFER; 56 handle.type = gfx::SHARED_MEMORY_BUFFER;
56 handle.handle = shared_memory_->handle(); 57 handle.handle = shared_memory_->handle();
57 return handle; 58 return handle;
58 } 59 }
59 ClientBuffer AsClientBuffer() override { 60 ClientBuffer AsClientBuffer() override {
60 return reinterpret_cast<ClientBuffer>(this); 61 return reinterpret_cast<ClientBuffer>(this);
61 } 62 }
(...skipping 12 matching lines...) Expand all
74 75
75 TestGpuMemoryBufferManager::~TestGpuMemoryBufferManager() { 76 TestGpuMemoryBufferManager::~TestGpuMemoryBufferManager() {
76 } 77 }
77 78
78 scoped_ptr<gfx::GpuMemoryBuffer> 79 scoped_ptr<gfx::GpuMemoryBuffer>
79 TestGpuMemoryBufferManager::AllocateGpuMemoryBuffer( 80 TestGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
80 const gfx::Size& size, 81 const gfx::Size& size,
81 gfx::GpuMemoryBuffer::Format format, 82 gfx::GpuMemoryBuffer::Format format,
82 gfx::GpuMemoryBuffer::Usage usage) { 83 gfx::GpuMemoryBuffer::Usage usage) {
83 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); 84 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory);
84 if (!shared_memory->CreateAnonymous(size.GetArea() * BytesPerPixel(format))) 85 if (!shared_memory->CreateAnonymous(StrideInBytes(size.width(), format) *
86 size.height()))
85 return nullptr; 87 return nullptr;
86 return make_scoped_ptr<gfx::GpuMemoryBuffer>( 88 return make_scoped_ptr<gfx::GpuMemoryBuffer>(
87 new GpuMemoryBufferImpl(size, format, shared_memory.Pass())); 89 new GpuMemoryBufferImpl(size, format, shared_memory.Pass()));
88 } 90 }
89 91
90 gfx::GpuMemoryBuffer* 92 gfx::GpuMemoryBuffer*
91 TestGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer( 93 TestGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
92 ClientBuffer buffer) { 94 ClientBuffer buffer) {
93 return reinterpret_cast<gfx::GpuMemoryBuffer*>(buffer); 95 return reinterpret_cast<gfx::GpuMemoryBuffer*>(buffer);
94 } 96 }
95 97
96 void TestGpuMemoryBufferManager::SetDestructionSyncPoint( 98 void TestGpuMemoryBufferManager::SetDestructionSyncPoint(
97 gfx::GpuMemoryBuffer* buffer, 99 gfx::GpuMemoryBuffer* buffer,
98 uint32 sync_point) { 100 uint32 sync_point) {
99 } 101 }
100 102
101 } // namespace cc 103 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | content/common/gpu/client/gpu_memory_buffer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698