| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/mus/gles2/ozone_gpu_memory_buffer.h" | 5 #include "components/mus/gles2/ozone_gpu_memory_buffer.h" |
| 6 | 6 |
| 7 #include "ui/gfx/buffer_format_util.h" | 7 #include "ui/gfx/buffer_format_util.h" |
| 8 #include "ui/ozone/public/client_native_pixmap.h" | 8 #include "ui/ozone/public/client_native_pixmap.h" |
| 9 #include "ui/ozone/public/client_native_pixmap_factory.h" | 9 #include "ui/ozone/public/client_native_pixmap_factory.h" |
| 10 #include "ui/ozone/public/native_pixmap.h" | 10 #include "ui/ozone/public/native_pixmap.h" |
| 11 #include "ui/ozone/public/ozone_platform.h" | 11 #include "ui/ozone/public/ozone_platform.h" |
| 12 #include "ui/ozone/public/surface_factory_ozone.h" | 12 #include "ui/ozone/public/surface_factory_ozone.h" |
| 13 | 13 |
| 14 namespace mus { | 14 namespace mus { |
| 15 | 15 |
| 16 OzoneGpuMemoryBuffer::OzoneGpuMemoryBuffer( | 16 OzoneGpuMemoryBuffer::OzoneGpuMemoryBuffer( |
| 17 gfx::GpuMemoryBufferId id, | 17 gfx::GpuMemoryBufferId id, |
| 18 const gfx::Size& size, | 18 const gfx::Size& size, |
| 19 gfx::BufferFormat format, | 19 gfx::BufferFormat format, |
| 20 scoped_ptr<ui::ClientNativePixmap> client_pixmap, | 20 std::unique_ptr<ui::ClientNativePixmap> client_pixmap, |
| 21 scoped_refptr<ui::NativePixmap> native_pixmap) | 21 scoped_refptr<ui::NativePixmap> native_pixmap) |
| 22 : GpuMemoryBufferImpl(id, size, format), | 22 : GpuMemoryBufferImpl(id, size, format), |
| 23 client_pixmap_(std::move(client_pixmap)), | 23 client_pixmap_(std::move(client_pixmap)), |
| 24 native_pixmap_(native_pixmap) {} | 24 native_pixmap_(native_pixmap) {} |
| 25 | 25 |
| 26 OzoneGpuMemoryBuffer::~OzoneGpuMemoryBuffer() { | 26 OzoneGpuMemoryBuffer::~OzoneGpuMemoryBuffer() { |
| 27 DCHECK(!mapped_); | 27 DCHECK(!mapped_); |
| 28 } | 28 } |
| 29 | 29 |
| 30 // static | 30 // static |
| 31 OzoneGpuMemoryBuffer* OzoneGpuMemoryBuffer::FromClientBuffer( | 31 OzoneGpuMemoryBuffer* OzoneGpuMemoryBuffer::FromClientBuffer( |
| 32 ClientBuffer buffer) { | 32 ClientBuffer buffer) { |
| 33 return reinterpret_cast<OzoneGpuMemoryBuffer*>(buffer); | 33 return reinterpret_cast<OzoneGpuMemoryBuffer*>(buffer); |
| 34 } | 34 } |
| 35 | 35 |
| 36 // static | 36 // static |
| 37 scoped_ptr<gfx::GpuMemoryBuffer> | 37 std::unique_ptr<gfx::GpuMemoryBuffer> |
| 38 OzoneGpuMemoryBuffer::CreateOzoneGpuMemoryBuffer( | 38 OzoneGpuMemoryBuffer::CreateOzoneGpuMemoryBuffer( |
| 39 const gfx::Size& size, | 39 const gfx::Size& size, |
| 40 gfx::BufferFormat format, | 40 gfx::BufferFormat format, |
| 41 gfx::BufferUsage usage, | 41 gfx::BufferUsage usage, |
| 42 gfx::AcceleratedWidget widget) { | 42 gfx::AcceleratedWidget widget) { |
| 43 scoped_refptr<ui::NativePixmap> pixmap = | 43 scoped_refptr<ui::NativePixmap> pixmap = |
| 44 ui::OzonePlatform::GetInstance() | 44 ui::OzonePlatform::GetInstance() |
| 45 ->GetSurfaceFactoryOzone() | 45 ->GetSurfaceFactoryOzone() |
| 46 ->CreateNativePixmap(widget, size, format, usage); | 46 ->CreateNativePixmap(widget, size, format, usage); |
| 47 | 47 |
| 48 DCHECK(pixmap) << "need pixmap to exist!"; | 48 DCHECK(pixmap) << "need pixmap to exist!"; |
| 49 | 49 |
| 50 if (!pixmap.get()) { | 50 if (!pixmap.get()) { |
| 51 DLOG(ERROR) << "Failed to create pixmap " << size.width() << "x" | 51 DLOG(ERROR) << "Failed to create pixmap " << size.width() << "x" |
| 52 << size.height() << " format " << static_cast<int>(format) | 52 << size.height() << " format " << static_cast<int>(format) |
| 53 << ", usage " << static_cast<int>(usage); | 53 << ", usage " << static_cast<int>(usage); |
| 54 return nullptr; | 54 return nullptr; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // We construct a ui::NativePixmapHandle | 57 // We construct a ui::NativePixmapHandle |
| 58 gfx::NativePixmapHandle native_pixmap_handle = pixmap->ExportHandle(); | 58 gfx::NativePixmapHandle native_pixmap_handle = pixmap->ExportHandle(); |
| 59 DCHECK(ui::ClientNativePixmapFactory::GetInstance()) | 59 DCHECK(ui::ClientNativePixmapFactory::GetInstance()) |
| 60 << "need me a ClientNativePixmapFactory"; | 60 << "need me a ClientNativePixmapFactory"; |
| 61 scoped_ptr<ui::ClientNativePixmap> client_native_pixmap = | 61 std::unique_ptr<ui::ClientNativePixmap> client_native_pixmap = |
| 62 ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( | 62 ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( |
| 63 native_pixmap_handle, size, usage); | 63 native_pixmap_handle, size, usage); |
| 64 | 64 |
| 65 scoped_ptr<OzoneGpuMemoryBuffer> nb( | 65 std::unique_ptr<OzoneGpuMemoryBuffer> nb( |
| 66 new OzoneGpuMemoryBuffer(gfx::GpuMemoryBufferId(0), size, format, | 66 new OzoneGpuMemoryBuffer(gfx::GpuMemoryBufferId(0), size, format, |
| 67 std::move(client_native_pixmap), pixmap)); | 67 std::move(client_native_pixmap), pixmap)); |
| 68 return std::move(nb); | 68 return std::move(nb); |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool OzoneGpuMemoryBuffer::Map() { | 71 bool OzoneGpuMemoryBuffer::Map() { |
| 72 DCHECK(!mapped_); | 72 DCHECK(!mapped_); |
| 73 if (!client_pixmap_->Map()) | 73 if (!client_pixmap_->Map()) |
| 74 return false; | 74 return false; |
| 75 mapped_ = true; | 75 mapped_ = true; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 106 return gfx::OZONE_NATIVE_PIXMAP; | 106 return gfx::OZONE_NATIVE_PIXMAP; |
| 107 } | 107 } |
| 108 | 108 |
| 109 #if defined(USE_OZONE) | 109 #if defined(USE_OZONE) |
| 110 scoped_refptr<ui::NativePixmap> OzoneGpuMemoryBuffer::GetNativePixmap() { | 110 scoped_refptr<ui::NativePixmap> OzoneGpuMemoryBuffer::GetNativePixmap() { |
| 111 return native_pixmap_; | 111 return native_pixmap_; |
| 112 } | 112 } |
| 113 #endif | 113 #endif |
| 114 | 114 |
| 115 } // namespace mus | 115 } // namespace mus |
| OLD | NEW |