OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_pixmap.h
" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "gpu/ipc/common/gpu_memory_buffer_support.h" | |
10 #include "ui/gfx/buffer_format_util.h" | |
11 #include "ui/ozone/public/client_native_pixmap_factory.h" | |
12 #include "ui/ozone/public/native_pixmap.h" | |
13 #include "ui/ozone/public/ozone_platform.h" | |
14 #include "ui/ozone/public/surface_factory_ozone.h" | |
15 | |
16 namespace content { | |
17 namespace { | |
18 | |
19 void FreeNativePixmapForTesting(scoped_refptr<ui::NativePixmap> native_pixmap) { | |
20 // Nothing to do here. |native_pixmap| will be freed when this function | |
21 // returns and reference count drops to 0. | |
22 } | |
23 | |
24 } // namespace | |
25 | |
26 GpuMemoryBufferImplOzoneNativePixmap::GpuMemoryBufferImplOzoneNativePixmap( | |
27 gfx::GpuMemoryBufferId id, | |
28 const gfx::Size& size, | |
29 gfx::BufferFormat format, | |
30 const DestructionCallback& callback, | |
31 scoped_ptr<ui::ClientNativePixmap> pixmap) | |
32 : GpuMemoryBufferImpl(id, size, format, callback), | |
33 pixmap_(std::move(pixmap)) {} | |
34 | |
35 GpuMemoryBufferImplOzoneNativePixmap::~GpuMemoryBufferImplOzoneNativePixmap() {} | |
36 | |
37 // static | |
38 scoped_ptr<GpuMemoryBufferImplOzoneNativePixmap> | |
39 GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle( | |
40 const gfx::GpuMemoryBufferHandle& handle, | |
41 const gfx::Size& size, | |
42 gfx::BufferFormat format, | |
43 gfx::BufferUsage usage, | |
44 const DestructionCallback& callback) { | |
45 scoped_ptr<ui::ClientNativePixmap> native_pixmap = | |
46 ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( | |
47 handle.native_pixmap_handle, size, usage); | |
48 DCHECK(native_pixmap); | |
49 return make_scoped_ptr(new GpuMemoryBufferImplOzoneNativePixmap( | |
50 handle.id, size, format, callback, std::move(native_pixmap))); | |
51 } | |
52 | |
53 // static | |
54 bool GpuMemoryBufferImplOzoneNativePixmap::IsConfigurationSupported( | |
55 gfx::BufferFormat format, | |
56 gfx::BufferUsage usage) { | |
57 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage); | |
58 } | |
59 | |
60 // static | |
61 base::Closure GpuMemoryBufferImplOzoneNativePixmap::AllocateForTesting( | |
62 const gfx::Size& size, | |
63 gfx::BufferFormat format, | |
64 gfx::BufferUsage usage, | |
65 gfx::GpuMemoryBufferHandle* handle) { | |
66 DCHECK(IsConfigurationSupported(format, usage)); | |
67 scoped_refptr<ui::NativePixmap> pixmap = | |
68 ui::OzonePlatform::GetInstance() | |
69 ->GetSurfaceFactoryOzone() | |
70 ->CreateNativePixmap(gfx::kNullPluginWindow, size, format, usage); | |
71 handle->type = gfx::OZONE_NATIVE_PIXMAP; | |
72 handle->native_pixmap_handle = pixmap->ExportHandle(); | |
73 return base::Bind(&FreeNativePixmapForTesting, pixmap); | |
74 } | |
75 | |
76 bool GpuMemoryBufferImplOzoneNativePixmap::Map() { | |
77 DCHECK(!mapped_); | |
78 if (!pixmap_->Map()) | |
79 return false; | |
80 mapped_ = true; | |
81 return mapped_; | |
82 } | |
83 | |
84 void* GpuMemoryBufferImplOzoneNativePixmap::memory(size_t plane) { | |
85 DCHECK(mapped_); | |
86 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); | |
87 return pixmap_->Map(); | |
88 } | |
89 | |
90 void GpuMemoryBufferImplOzoneNativePixmap::Unmap() { | |
91 DCHECK(mapped_); | |
92 pixmap_->Unmap(); | |
93 mapped_ = false; | |
94 } | |
95 | |
96 int GpuMemoryBufferImplOzoneNativePixmap::stride(size_t plane) const { | |
97 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); | |
98 int stride; | |
99 pixmap_->GetStride(&stride); | |
100 return stride; | |
101 } | |
102 | |
103 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativePixmap::GetHandle() | |
104 const { | |
105 gfx::GpuMemoryBufferHandle handle; | |
106 handle.type = gfx::OZONE_NATIVE_PIXMAP; | |
107 handle.id = id_; | |
108 return handle; | |
109 } | |
110 | |
111 } // namespace content | |
OLD | NEW |