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 "content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_pixmap.h " | 5 #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.
| |
6 | 6 |
7 #include "ui/ozone/public/client_native_pixmap_factory.h" | 7 #include "ui/ozone/public/client_native_pixmap_factory.h" |
8 #include "ui/ozone/public/surface_factory_ozone.h" | |
9 | 8 |
10 namespace content { | 9 namespace content { |
11 | 10 |
12 GpuMemoryBufferImplOzoneNativePixmap::GpuMemoryBufferImplOzoneNativePixmap( | 11 GpuMemoryBufferImplOzoneNativePixmap::GpuMemoryBufferImplOzoneNativePixmap( |
13 gfx::GpuMemoryBufferId id, | 12 gfx::GpuMemoryBufferId id, |
14 const gfx::Size& size, | 13 const gfx::Size& size, |
15 gfx::BufferFormat format, | 14 gfx::BufferFormat format, |
15 gfx::BufferUsage usage, | |
16 const DestructionCallback& callback, | 16 const DestructionCallback& callback, |
17 scoped_ptr<ui::ClientNativePixmap> pixmap) | 17 scoped_ptr<ui::ClientNativePixmap> pixmap) |
18 : GpuMemoryBufferImpl(id, size, format, callback), pixmap_(pixmap.Pass()) {} | 18 : GpuMemoryBufferImpl(id, size, format, callback), |
19 usage_(usage), | |
20 pixmap_(pixmap.Pass()) {} | |
19 | 21 |
20 GpuMemoryBufferImplOzoneNativePixmap::~GpuMemoryBufferImplOzoneNativePixmap() {} | 22 GpuMemoryBufferImplOzoneNativePixmap::~GpuMemoryBufferImplOzoneNativePixmap() {} |
21 | 23 |
22 // static | 24 // static |
23 scoped_ptr<GpuMemoryBufferImpl> | 25 scoped_ptr<GpuMemoryBufferImpl> |
24 GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle( | 26 GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle( |
25 const gfx::GpuMemoryBufferHandle& handle, | 27 const gfx::GpuMemoryBufferHandle& handle, |
26 const gfx::Size& size, | 28 const gfx::Size& size, |
27 gfx::BufferFormat format, | 29 gfx::BufferFormat format, |
28 gfx::BufferUsage usage, | 30 gfx::BufferUsage usage, |
29 const DestructionCallback& callback) { | 31 const DestructionCallback& callback) { |
30 scoped_ptr<ui::ClientNativePixmap> native_pixmap = | 32 scoped_ptr<ui::ClientNativePixmap> native_pixmap; |
31 ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( | 33 switch (usage) { |
32 handle.native_pixmap_handle, size, format, usage); | 34 case gfx::BufferUsage::MAP: |
35 native_pixmap = ui::ClientNativePixmapFactory::GetInstance() | |
36 ->ImportFromHandle(handle.native_pixmap_handle, size, | |
37 format, usage) | |
38 .Pass(); | |
39 if (!native_pixmap) | |
40 return nullptr; | |
41 break; | |
42 case gfx::BufferUsage::SCANOUT: | |
43 break; | |
44 case gfx::BufferUsage::PERSISTENT_MAP: | |
45 NOTREACHED(); | |
46 return nullptr; | |
47 } | |
48 | |
33 return make_scoped_ptr<GpuMemoryBufferImpl>( | 49 return make_scoped_ptr<GpuMemoryBufferImpl>( |
34 new GpuMemoryBufferImplOzoneNativePixmap(handle.id, size, format, | 50 new GpuMemoryBufferImplOzoneNativePixmap(handle.id, size, format, usage, |
35 callback, native_pixmap.Pass())); | 51 callback, native_pixmap.Pass())); |
36 } | 52 } |
37 | 53 |
38 bool GpuMemoryBufferImplOzoneNativePixmap::Map(void** data) { | 54 bool GpuMemoryBufferImplOzoneNativePixmap::Map(void** data) { |
55 DCHECK(!mapped_); | |
56 DCHECK(usage_ == gfx::BufferUsage::MAP); | |
57 DCHECK(pixmap_); | |
58 mapped_ = true; | |
39 return pixmap_->Map(data); | 59 return pixmap_->Map(data); |
40 } | 60 } |
41 | 61 |
42 void GpuMemoryBufferImplOzoneNativePixmap::Unmap() { | 62 void GpuMemoryBufferImplOzoneNativePixmap::Unmap() { |
63 DCHECK(mapped_); | |
64 DCHECK(usage_ == gfx::BufferUsage::MAP); | |
65 DCHECK(pixmap_); | |
43 pixmap_->Unmap(); | 66 pixmap_->Unmap(); |
67 mapped_ = false; | |
44 } | 68 } |
45 | 69 |
46 void GpuMemoryBufferImplOzoneNativePixmap::GetStride(int* stride) const { | 70 void GpuMemoryBufferImplOzoneNativePixmap::GetStride(int* stride) const { |
71 DCHECK(usage_ == gfx::BufferUsage::MAP); | |
72 DCHECK(pixmap_); | |
47 pixmap_->GetStride(stride); | 73 pixmap_->GetStride(stride); |
48 } | 74 } |
49 | 75 |
50 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativePixmap::GetHandle() | 76 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativePixmap::GetHandle() |
51 const { | 77 const { |
52 gfx::GpuMemoryBufferHandle handle; | 78 gfx::GpuMemoryBufferHandle handle; |
53 handle.type = gfx::OZONE_NATIVE_PIXMAP; | 79 handle.type = gfx::OZONE_NATIVE_PIXMAP; |
54 handle.id = id_; | 80 handle.id = id_; |
55 return handle; | 81 return handle; |
56 } | 82 } |
57 | 83 |
58 } // namespace content | 84 } // namespace content |
OLD | NEW |