OLD | NEW |
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 "gpu/ipc/client/gpu_memory_buffer_impl_ozone_native_pixmap.h" | 5 #include "gpu/ipc/client/gpu_memory_buffer_impl_ozone_native_pixmap.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "gpu/ipc/common/gpu_memory_buffer_support.h" | 10 #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 gfx::GpuMemoryBufferId id, | 28 gfx::GpuMemoryBufferId id, |
29 const gfx::Size& size, | 29 const gfx::Size& size, |
30 gfx::BufferFormat format, | 30 gfx::BufferFormat format, |
31 const DestructionCallback& callback, | 31 const DestructionCallback& callback, |
32 std::unique_ptr<ui::ClientNativePixmap> pixmap, | 32 std::unique_ptr<ui::ClientNativePixmap> pixmap, |
33 const std::vector<gfx::NativePixmapPlane>& planes, | 33 const std::vector<gfx::NativePixmapPlane>& planes, |
34 base::ScopedFD fd) | 34 base::ScopedFD fd) |
35 : GpuMemoryBufferImpl(id, size, format, callback), | 35 : GpuMemoryBufferImpl(id, size, format, callback), |
36 pixmap_(std::move(pixmap)), | 36 pixmap_(std::move(pixmap)), |
37 planes_(planes), | 37 planes_(planes), |
38 fd_(std::move(fd)) {} | 38 fd_(std::move(fd)), |
| 39 data_(nullptr) {} |
39 | 40 |
40 GpuMemoryBufferImplOzoneNativePixmap::~GpuMemoryBufferImplOzoneNativePixmap() {} | 41 GpuMemoryBufferImplOzoneNativePixmap::~GpuMemoryBufferImplOzoneNativePixmap() {} |
41 | 42 |
42 // static | 43 // static |
43 std::unique_ptr<GpuMemoryBufferImplOzoneNativePixmap> | 44 std::unique_ptr<GpuMemoryBufferImplOzoneNativePixmap> |
44 GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle( | 45 GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle( |
45 const gfx::GpuMemoryBufferHandle& handle, | 46 const gfx::GpuMemoryBufferHandle& handle, |
46 const gfx::Size& size, | 47 const gfx::Size& size, |
47 gfx::BufferFormat format, | 48 gfx::BufferFormat format, |
48 gfx::BufferUsage usage, | 49 gfx::BufferUsage usage, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 ->GetSurfaceFactoryOzone() | 94 ->GetSurfaceFactoryOzone() |
94 ->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, format, | 95 ->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, format, |
95 usage); | 96 usage); |
96 handle->type = gfx::OZONE_NATIVE_PIXMAP; | 97 handle->type = gfx::OZONE_NATIVE_PIXMAP; |
97 handle->native_pixmap_handle = pixmap->ExportHandle(); | 98 handle->native_pixmap_handle = pixmap->ExportHandle(); |
98 return base::Bind(&FreeNativePixmapForTesting, pixmap); | 99 return base::Bind(&FreeNativePixmapForTesting, pixmap); |
99 } | 100 } |
100 | 101 |
101 bool GpuMemoryBufferImplOzoneNativePixmap::Map() { | 102 bool GpuMemoryBufferImplOzoneNativePixmap::Map() { |
102 DCHECK(!mapped_); | 103 DCHECK(!mapped_); |
103 mapped_ = pixmap_->Map(); | 104 DCHECK(!data_); |
| 105 data_ = pixmap_->Map(); |
| 106 if (!data_) |
| 107 return false; |
| 108 mapped_ = true; |
104 return mapped_; | 109 return mapped_; |
105 } | 110 } |
106 | 111 |
107 void* GpuMemoryBufferImplOzoneNativePixmap::memory(size_t plane) { | 112 void* GpuMemoryBufferImplOzoneNativePixmap::memory(size_t plane) { |
108 DCHECK(mapped_); | 113 DCHECK(mapped_); |
109 return pixmap_->GetMemoryAddress(plane); | 114 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); |
| 115 return data_; |
110 } | 116 } |
111 | 117 |
112 void GpuMemoryBufferImplOzoneNativePixmap::Unmap() { | 118 void GpuMemoryBufferImplOzoneNativePixmap::Unmap() { |
113 DCHECK(mapped_); | 119 DCHECK(mapped_); |
| 120 DCHECK(data_); |
114 pixmap_->Unmap(); | 121 pixmap_->Unmap(); |
115 mapped_ = false; | 122 mapped_ = false; |
| 123 data_ = nullptr; |
116 } | 124 } |
117 | 125 |
118 int GpuMemoryBufferImplOzoneNativePixmap::stride(size_t plane) const { | 126 int GpuMemoryBufferImplOzoneNativePixmap::stride(size_t plane) const { |
119 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); | 127 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); |
120 return pixmap_->GetStride(plane); | 128 int stride; |
| 129 pixmap_->GetStride(&stride); |
| 130 return stride; |
121 } | 131 } |
122 | 132 |
123 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativePixmap::GetHandle() | 133 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativePixmap::GetHandle() |
124 const { | 134 const { |
125 gfx::GpuMemoryBufferHandle handle; | 135 gfx::GpuMemoryBufferHandle handle; |
126 handle.type = gfx::OZONE_NATIVE_PIXMAP; | 136 handle.type = gfx::OZONE_NATIVE_PIXMAP; |
127 handle.id = id_; | 137 handle.id = id_; |
128 handle.native_pixmap_handle.fds.emplace_back(fd_.get(), | 138 handle.native_pixmap_handle.fds.emplace_back(fd_.get(), |
129 false /* auto_close */); | 139 false /* auto_close */); |
130 handle.native_pixmap_handle.planes = planes_; | 140 handle.native_pixmap_handle.planes = planes_; |
131 return handle; | 141 return handle; |
132 } | 142 } |
133 | 143 |
134 } // namespace gpu | 144 } // namespace gpu |
OLD | NEW |