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

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

Issue 1281043006: Move NumberOfPlanesForGpuMemoryBufferFormat to gfx (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 4 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 | components/view_manager/gles2/mojo_gpu_memory_buffer.cc » ('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 "base/numerics/safe_conversions.h" 8 #include "base/numerics/safe_conversions.h"
9 #include "ui/gfx/buffer_format_util.h"
9 #include "ui/gfx/gpu_memory_buffer.h" 10 #include "ui/gfx/gpu_memory_buffer.h"
10 11
11 namespace cc { 12 namespace cc {
12 namespace { 13 namespace {
13 14
14 int NumberOfPlanesForGpuMemoryBufferFormat(gfx::BufferFormat format) {
15 switch (format) {
16 case gfx::BufferFormat::ATC:
17 case gfx::BufferFormat::ATCIA:
18 case gfx::BufferFormat::DXT1:
19 case gfx::BufferFormat::DXT5:
20 case gfx::BufferFormat::ETC1:
21 case gfx::BufferFormat::R_8:
22 case gfx::BufferFormat::RGBA_4444:
23 case gfx::BufferFormat::RGBA_8888:
24 case gfx::BufferFormat::RGBX_8888:
25 case gfx::BufferFormat::BGRA_8888:
26 return 1;
27 case gfx::BufferFormat::YUV_420:
28 return 3;
29 }
30 NOTREACHED();
31 return 0;
32 }
33
34 size_t SubsamplingFactor(gfx::BufferFormat format, int plane) { 15 size_t SubsamplingFactor(gfx::BufferFormat format, int plane) {
35 switch (format) { 16 switch (format) {
36 case gfx::BufferFormat::ATC: 17 case gfx::BufferFormat::ATC:
37 case gfx::BufferFormat::ATCIA: 18 case gfx::BufferFormat::ATCIA:
38 case gfx::BufferFormat::DXT1: 19 case gfx::BufferFormat::DXT1:
39 case gfx::BufferFormat::DXT5: 20 case gfx::BufferFormat::DXT5:
40 case gfx::BufferFormat::ETC1: 21 case gfx::BufferFormat::ETC1:
41 case gfx::BufferFormat::R_8: 22 case gfx::BufferFormat::R_8:
42 case gfx::BufferFormat::RGBA_4444: 23 case gfx::BufferFormat::RGBA_4444:
43 case gfx::BufferFormat::RGBA_8888: 24 case gfx::BufferFormat::RGBA_8888:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 return width * 4; 59 return width * 4;
79 case gfx::BufferFormat::YUV_420: 60 case gfx::BufferFormat::YUV_420:
80 return width / SubsamplingFactor(format, plane); 61 return width / SubsamplingFactor(format, plane);
81 } 62 }
82 NOTREACHED(); 63 NOTREACHED();
83 return 0; 64 return 0;
84 } 65 }
85 66
86 size_t BufferSizeInBytes(const gfx::Size& size, gfx::BufferFormat format) { 67 size_t BufferSizeInBytes(const gfx::Size& size, gfx::BufferFormat format) {
87 size_t size_in_bytes = 0; 68 size_t size_in_bytes = 0;
88 int num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format); 69 int num_planes = static_cast<int>(gfx::NumberOfPlanesForBufferFormat(format));
89 for (int i = 0; i < num_planes; ++i) { 70 for (int i = 0; i < num_planes; ++i) {
90 size_in_bytes += StrideInBytes(size.width(), format, i) * 71 size_in_bytes += StrideInBytes(size.width(), format, i) *
91 (size.height() / SubsamplingFactor(format, i)); 72 (size.height() / SubsamplingFactor(format, i));
92 } 73 }
93 return size_in_bytes; 74 return size_in_bytes;
94 } 75 }
95 76
96 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { 77 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
97 public: 78 public:
98 GpuMemoryBufferImpl(const gfx::Size& size, 79 GpuMemoryBufferImpl(const gfx::Size& size,
99 gfx::BufferFormat format, 80 gfx::BufferFormat format,
100 scoped_ptr<base::SharedMemory> shared_memory) 81 scoped_ptr<base::SharedMemory> shared_memory)
101 : size_(size), 82 : size_(size),
102 format_(format), 83 format_(format),
103 shared_memory_(shared_memory.Pass()), 84 shared_memory_(shared_memory.Pass()),
104 mapped_(false) {} 85 mapped_(false) {}
105 86
106 // Overridden from gfx::GpuMemoryBuffer: 87 // Overridden from gfx::GpuMemoryBuffer:
107 bool Map(void** data) override { 88 bool Map(void** data) override {
108 DCHECK(!mapped_); 89 DCHECK(!mapped_);
109 if (!shared_memory_->Map(BufferSizeInBytes(size_, format_))) 90 if (!shared_memory_->Map(BufferSizeInBytes(size_, format_)))
110 return false; 91 return false;
111 mapped_ = true; 92 mapped_ = true;
112 size_t offset = 0; 93 size_t offset = 0;
113 int num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_); 94 int num_planes =
95 static_cast<int>(gfx::NumberOfPlanesForBufferFormat(format_));
114 for (int i = 0; i < num_planes; ++i) { 96 for (int i = 0; i < num_planes; ++i) {
115 data[i] = reinterpret_cast<uint8*>(shared_memory_->memory()) + offset; 97 data[i] = reinterpret_cast<uint8*>(shared_memory_->memory()) + offset;
116 offset += StrideInBytes(size_.width(), format_, i) * 98 offset += StrideInBytes(size_.width(), format_, i) *
117 (size_.height() / SubsamplingFactor(format_, i)); 99 (size_.height() / SubsamplingFactor(format_, i));
118 } 100 }
119 return true; 101 return true;
120 } 102 }
121 void Unmap() override { 103 void Unmap() override {
122 DCHECK(mapped_); 104 DCHECK(mapped_);
123 shared_memory_->Unmap(); 105 shared_memory_->Unmap();
124 mapped_ = false; 106 mapped_ = false;
125 } 107 }
126 bool IsMapped() const override { return mapped_; } 108 bool IsMapped() const override { return mapped_; }
127 gfx::BufferFormat GetFormat() const override { return format_; } 109 gfx::BufferFormat GetFormat() const override { return format_; }
128 void GetStride(int* stride) const override { 110 void GetStride(int* stride) const override {
129 int num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_); 111 int num_planes =
112 static_cast<int>(gfx::NumberOfPlanesForBufferFormat(format_));
130 for (int i = 0; i < num_planes; ++i) 113 for (int i = 0; i < num_planes; ++i)
131 stride[i] = 114 stride[i] =
132 base::checked_cast<int>(StrideInBytes(size_.width(), format_, i)); 115 base::checked_cast<int>(StrideInBytes(size_.width(), format_, i));
133 } 116 }
134 gfx::GpuMemoryBufferId GetId() const override { 117 gfx::GpuMemoryBufferId GetId() const override {
135 NOTREACHED(); 118 NOTREACHED();
136 return 0; 119 return 0;
137 } 120 }
138 gfx::GpuMemoryBufferHandle GetHandle() const override { 121 gfx::GpuMemoryBufferHandle GetHandle() const override {
139 gfx::GpuMemoryBufferHandle handle; 122 gfx::GpuMemoryBufferHandle handle;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 ClientBuffer buffer) { 159 ClientBuffer buffer) {
177 return reinterpret_cast<gfx::GpuMemoryBuffer*>(buffer); 160 return reinterpret_cast<gfx::GpuMemoryBuffer*>(buffer);
178 } 161 }
179 162
180 void TestGpuMemoryBufferManager::SetDestructionSyncPoint( 163 void TestGpuMemoryBufferManager::SetDestructionSyncPoint(
181 gfx::GpuMemoryBuffer* buffer, 164 gfx::GpuMemoryBuffer* buffer,
182 uint32 sync_point) { 165 uint32 sync_point) {
183 } 166 }
184 167
185 } // namespace cc 168 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | components/view_manager/gles2/mojo_gpu_memory_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698