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

Side by Side Diff: content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc

Issue 1024113003: Add multi-planar functions to GpuMemoryBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reveman@ comments. Created 5 years, 9 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
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 "content/common/gpu/client/gpu_memory_buffer_impl.h" 5 #include "content/common/gpu/client/gpu_memory_buffer_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/common/gpu/gpu_memory_buffer_factory.h" 8 #include "content/common/gpu/gpu_memory_buffer_factory.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 const int kBufferId = 1; 80 const int kBufferId = 1;
81 81
82 gfx::Size buffer_size(1, 1); 82 gfx::Size buffer_size(1, 1);
83 83
84 for (auto configuration : supported_configurations_) { 84 for (auto configuration : supported_configurations_) {
85 if (configuration.usage != gfx::GpuMemoryBuffer::MAP) 85 if (configuration.usage != gfx::GpuMemoryBuffer::MAP)
86 continue; 86 continue;
87 87
88 size_t width_in_bytes = 0; 88 size_t width_in_bytes = 0;
89 EXPECT_TRUE(GpuMemoryBufferImpl::StrideInBytes( 89 EXPECT_TRUE(GpuMemoryBufferImpl::StrideInBytes(
90 buffer_size.width(), configuration.format, &width_in_bytes)); 90 buffer_size.width(), configuration.format, &width_in_bytes));
reveman 2015/03/24 22:16:53 GpuMemoryBufferImpl::StrideInBytes doesn't support
emircan 2015/03/24 22:45:16 We can leave it to the follow up patch when new fo
91 EXPECT_GT(width_in_bytes, 0u); 91 EXPECT_GT(width_in_bytes, 0u);
92 scoped_ptr<char[]> data(new char[width_in_bytes]); 92 scoped_ptr<char[]> data(new char[width_in_bytes]);
93 memset(data.get(), 0x2a, width_in_bytes); 93 memset(data.get(), 0x2a, width_in_bytes);
94 94
95 scoped_ptr<GpuMemoryBufferImpl> buffer( 95 scoped_ptr<GpuMemoryBufferImpl> buffer(
96 GpuMemoryBufferImpl::CreateFromHandle( 96 GpuMemoryBufferImpl::CreateFromHandle(
97 CreateGpuMemoryBuffer(kBufferId, 97 CreateGpuMemoryBuffer(kBufferId,
98 buffer_size, 98 buffer_size,
99 configuration.format, 99 configuration.format,
100 configuration.usage), 100 configuration.usage),
101 buffer_size, 101 buffer_size,
102 configuration.format, 102 configuration.format,
103 base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer, 103 base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer,
104 base::Unretained(this), 104 base::Unretained(this),
105 kBufferId))); 105 kBufferId)));
106 ASSERT_TRUE(buffer); 106 ASSERT_TRUE(buffer);
107 EXPECT_FALSE(buffer->IsMapped()); 107 EXPECT_FALSE(buffer->IsMapped());
108 108
109 void* memory = buffer->Map(); 109 size_t num_buffers = buffer->GetNumberOfPlanes();
110 ASSERT_TRUE(memory); 110
111 // Map buffer into user space.
112 void* mapped_buffers[num_buffers];
113 bool map_completed = buffer->Map(mapped_buffers);
114 ASSERT_TRUE(map_completed);
111 EXPECT_TRUE(buffer->IsMapped()); 115 EXPECT_TRUE(buffer->IsMapped());
112 uint32 stride = buffer->GetStride(); 116
113 EXPECT_GE(stride, width_in_bytes); 117 // Get strides.
114 memcpy(memory, data.get(), width_in_bytes); 118 uint32 strides[num_buffers];
115 EXPECT_EQ(memcmp(memory, data.get(), width_in_bytes), 0); 119 bool getStride_completed = buffer->GetStride(strides);
120 DCHECK(getStride_completed);
121
122 // Copy and compare mapped buffers.
123 for (size_t i = 0; i < num_buffers; ++i) {
124 EXPECT_GE(strides[i], width_in_bytes);
125 memcpy(mapped_buffers[i], data.get(), width_in_bytes);
126 EXPECT_EQ(memcmp(mapped_buffers[i], data.get(), width_in_bytes), 0);
127 }
128
116 buffer->Unmap(); 129 buffer->Unmap();
117 EXPECT_FALSE(buffer->IsMapped()); 130 EXPECT_FALSE(buffer->IsMapped());
118 } 131 }
119 } 132 }
120 133
121 std::vector<gfx::GpuMemoryBufferType> GetSupportedGpuMemoryBufferTypes() { 134 std::vector<gfx::GpuMemoryBufferType> GetSupportedGpuMemoryBufferTypes() {
122 std::vector<gfx::GpuMemoryBufferType> supported_types; 135 std::vector<gfx::GpuMemoryBufferType> supported_types;
123 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); 136 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types);
124 return supported_types; 137 return supported_types;
125 } 138 }
126 139
127 INSTANTIATE_TEST_CASE_P( 140 INSTANTIATE_TEST_CASE_P(
128 GpuMemoryBufferImplTests, 141 GpuMemoryBufferImplTests,
129 GpuMemoryBufferImplTest, 142 GpuMemoryBufferImplTest,
130 ::testing::ValuesIn(GetSupportedGpuMemoryBufferTypes())); 143 ::testing::ValuesIn(GetSupportedGpuMemoryBufferTypes()));
131 144
132 } // namespace 145 } // namespace
133 } // namespace content 146 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698