Chromium Code Reviews| Index: content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_pixmap.cc |
| diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_pixmap.cc b/content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_pixmap.cc |
| index 40500a604f8a10ed40790cccb67a61348d455023..c728adbfd808e2e53a8c9ae6b099e4d96f4d99bb 100644 |
| --- a/content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_pixmap.cc |
| +++ b/content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_pixmap.cc |
| @@ -5,7 +5,6 @@ |
| #include "content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_pixmap.h" |
|
reveman
2015/08/06 12:08:35
why do we need any of these changes to this file?
dshwang
2015/08/06 13:59:17
Done.
|
| #include "ui/ozone/public/client_native_pixmap_factory.h" |
| -#include "ui/ozone/public/surface_factory_ozone.h" |
| namespace content { |
| @@ -13,9 +12,12 @@ GpuMemoryBufferImplOzoneNativePixmap::GpuMemoryBufferImplOzoneNativePixmap( |
| gfx::GpuMemoryBufferId id, |
| const gfx::Size& size, |
| gfx::BufferFormat format, |
| + gfx::BufferUsage usage, |
| const DestructionCallback& callback, |
| scoped_ptr<ui::ClientNativePixmap> pixmap) |
| - : GpuMemoryBufferImpl(id, size, format, callback), pixmap_(pixmap.Pass()) {} |
| + : GpuMemoryBufferImpl(id, size, format, callback), |
| + usage_(usage), |
| + pixmap_(pixmap.Pass()) {} |
| GpuMemoryBufferImplOzoneNativePixmap::~GpuMemoryBufferImplOzoneNativePixmap() {} |
| @@ -27,23 +29,47 @@ GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle( |
| gfx::BufferFormat format, |
| gfx::BufferUsage usage, |
| const DestructionCallback& callback) { |
| - scoped_ptr<ui::ClientNativePixmap> native_pixmap = |
| - ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( |
| - handle.native_pixmap_handle, size, format, usage); |
| + scoped_ptr<ui::ClientNativePixmap> native_pixmap; |
| + switch (usage) { |
| + case gfx::BufferUsage::MAP: |
| + native_pixmap = ui::ClientNativePixmapFactory::GetInstance() |
| + ->ImportFromHandle(handle.native_pixmap_handle, size, |
| + format, usage) |
| + .Pass(); |
| + if (!native_pixmap) |
| + return nullptr; |
| + break; |
| + case gfx::BufferUsage::SCANOUT: |
| + break; |
| + case gfx::BufferUsage::PERSISTENT_MAP: |
| + NOTREACHED(); |
| + return nullptr; |
| + } |
| + |
| return make_scoped_ptr<GpuMemoryBufferImpl>( |
| - new GpuMemoryBufferImplOzoneNativePixmap(handle.id, size, format, |
| + new GpuMemoryBufferImplOzoneNativePixmap(handle.id, size, format, usage, |
| callback, native_pixmap.Pass())); |
| } |
| bool GpuMemoryBufferImplOzoneNativePixmap::Map(void** data) { |
| + DCHECK(!mapped_); |
| + DCHECK(usage_ == gfx::BufferUsage::MAP); |
| + DCHECK(pixmap_); |
| + mapped_ = true; |
| return pixmap_->Map(data); |
| } |
| void GpuMemoryBufferImplOzoneNativePixmap::Unmap() { |
| + DCHECK(mapped_); |
| + DCHECK(usage_ == gfx::BufferUsage::MAP); |
| + DCHECK(pixmap_); |
| pixmap_->Unmap(); |
| + mapped_ = false; |
| } |
| void GpuMemoryBufferImplOzoneNativePixmap::GetStride(int* stride) const { |
| + DCHECK(usage_ == gfx::BufferUsage::MAP); |
| + DCHECK(pixmap_); |
| pixmap_->GetStride(stride); |
| } |