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

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

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