summaryrefslogtreecommitdiffstats
path: root/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'gpu')
-rw-r--r--gpu/command_buffer/tests/gl_gpu_memory_buffer_unittest.cc21
-rw-r--r--gpu/command_buffer/tests/gl_manager.cc33
2 files changed, 26 insertions, 28 deletions
diff --git a/gpu/command_buffer/tests/gl_gpu_memory_buffer_unittest.cc b/gpu/command_buffer/tests/gl_gpu_memory_buffer_unittest.cc
index 23fc468..280de5f 100644
--- a/gpu/command_buffer/tests/gl_gpu_memory_buffer_unittest.cc
+++ b/gpu/command_buffer/tests/gl_gpu_memory_buffer_unittest.cc
@@ -170,22 +170,17 @@ TEST_P(GpuMemoryBufferTest, Lifecycle) {
gfx::Size(kImageWidth, kImageHeight), GetParam()));
// Map buffer for writing.
- void* data;
- bool rv = buffer->Map(&data);
- DCHECK(rv);
-
- uint8_t* mapped_buffer = static_cast<uint8_t*>(data);
- ASSERT_TRUE(mapped_buffer != NULL);
-
+ ASSERT_TRUE(buffer->Map());
+ ASSERT_NE(nullptr, buffer->memory(0));
+ ASSERT_NE(0, buffer->stride(0));
uint8_t pixel[] = {255u, 0u, 0u, 255u};
// Assign a value to each pixel.
- int stride = 0;
- buffer->GetStride(&stride);
- ASSERT_NE(stride, 0);
- for (int y = 0; y < kImageHeight; ++y)
- SetRow(GetParam(), mapped_buffer + y * stride, kImageWidth, pixel);
-
+ for (int y = 0; y < kImageHeight; ++y) {
+ SetRow(GetParam(),
+ static_cast<uint8_t*>(buffer->memory(0)) + y * buffer->stride(0),
+ kImageWidth, pixel);
+ }
// Unmap the buffer.
buffer->Unmap();
diff --git a/gpu/command_buffer/tests/gl_manager.cc b/gpu/command_buffer/tests/gl_manager.cc
index bb803bb..2dbcfb93 100644
--- a/gpu/command_buffer/tests/gl_manager.cc
+++ b/gpu/command_buffer/tests/gl_manager.cc
@@ -49,31 +49,33 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
GpuMemoryBufferImpl(base::RefCountedBytes* bytes,
const gfx::Size& size,
gfx::BufferFormat format)
- : bytes_(bytes), size_(size), format_(format) {}
+ : mapped_(false), bytes_(bytes), size_(size), format_(format) {}
static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer) {
return reinterpret_cast<GpuMemoryBufferImpl*>(buffer);
}
// Overridden from gfx::GpuMemoryBuffer:
- bool Map(void** data) override {
- size_t offset = 0;
- size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format_);
- for (size_t i = 0; i < num_planes; ++i) {
- data[i] = reinterpret_cast<uint8*>(&bytes_->data().front()) + offset;
- offset +=
- gfx::RowSizeForBufferFormat(size_.width(), format_, i) *
- (size_.height() / gfx::SubsamplingFactorForBufferFormat(format_, i));
- }
+ bool Map() override {
+ DCHECK(!mapped_);
+ mapped_ = true;
return true;
}
- void Unmap() override {}
+ void* memory(size_t plane) override {
+ DCHECK(mapped_);
+ DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_));
+ return reinterpret_cast<uint8*>(&bytes_->data().front()) +
+ gfx::BufferOffsetForBufferFormat(size_, format_, plane);
+ }
+ void Unmap() override {
+ DCHECK(mapped_);
+ mapped_ = false;
+ }
gfx::Size GetSize() const override { return size_; }
gfx::BufferFormat GetFormat() const override { return format_; }
- void GetStride(int* stride) const override {
- size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format_);
- for (size_t i = 0; i < num_planes; ++i)
- stride[i] = gfx::RowSizeForBufferFormat(size_.width(), format_, i);
+ int stride(size_t plane) const override {
+ DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_));
+ return gfx::RowSizeForBufferFormat(size_.width(), format_, plane);
}
gfx::GpuMemoryBufferId GetId() const override {
NOTREACHED();
@@ -90,6 +92,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
base::RefCountedBytes* bytes() { return bytes_.get(); }
private:
+ bool mapped_;
scoped_refptr<base::RefCountedBytes> bytes_;
const gfx::Size size_;
gfx::BufferFormat format_;