Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.cc

Issue 1134993003: ozone: Implement zero/one-copy texture for Ozone GBM. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase to new crrev.com/1128113011 Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_buffer.h " 5 #include "content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h "
6 6
7 #include "ui/ozone/public/surface_factory_ozone.h" 7 namespace content {
8 8
9 namespace content { 9 namespace {
10
11 ui::SurfaceFactoryOzone::BufferFormat GetOzoneFormatFor(
12 gfx::GpuMemoryBuffer::Format format) {
13 switch (format) {
14 case gfx::GpuMemoryBuffer::BGRA_8888:
15 return ui::SurfaceFactoryOzone::BGRA_8888;
16 case gfx::GpuMemoryBuffer::RGBX_8888:
17 return ui::SurfaceFactoryOzone::RGBX_8888;
18 case gfx::GpuMemoryBuffer::ATC:
19 case gfx::GpuMemoryBuffer::ATCIA:
20 case gfx::GpuMemoryBuffer::DXT1:
21 case gfx::GpuMemoryBuffer::DXT5:
22 case gfx::GpuMemoryBuffer::ETC1:
23 case gfx::GpuMemoryBuffer::R_8:
24 case gfx::GpuMemoryBuffer::RGBA_4444:
25 case gfx::GpuMemoryBuffer::RGBA_8888:
26 case gfx::GpuMemoryBuffer::YUV_420:
27 NOTREACHED();
28 }
29 NOTREACHED();
30 return ui::SurfaceFactoryOzone::BGRA_8888;
31 }
32
33 ui::SurfaceFactoryOzone::BufferUsage GetOzoneUsageFor(
34 gfx::GpuMemoryBuffer::Usage usage) {
35 switch (usage) {
36 case gfx::GpuMemoryBuffer::MAP:
37 return ui::SurfaceFactoryOzone::MAP;
38 case gfx::GpuMemoryBuffer::PERSISTENT_MAP:
39 return ui::SurfaceFactoryOzone::PERSISTENT_MAP;
40 case gfx::GpuMemoryBuffer::SCANOUT:
41 return ui::SurfaceFactoryOzone::SCANOUT;
42 }
43 NOTREACHED();
44 return ui::SurfaceFactoryOzone::SCANOUT;
45 }
46
47 } // namespace
10 48
11 GpuMemoryBufferImplOzoneNativeBuffer::GpuMemoryBufferImplOzoneNativeBuffer( 49 GpuMemoryBufferImplOzoneNativeBuffer::GpuMemoryBufferImplOzoneNativeBuffer(
12 gfx::GpuMemoryBufferId id, 50 gfx::GpuMemoryBufferId id,
13 const gfx::Size& size, 51 const gfx::Size& size,
14 Format format, 52 Format format,
53 Usage usage,
15 const DestructionCallback& callback) 54 const DestructionCallback& callback)
16 : GpuMemoryBufferImpl(id, size, format, callback) { 55 : GpuMemoryBufferImpl(id, size, format, callback), usage_(usage) {
17 } 56 }
18 57
19 GpuMemoryBufferImplOzoneNativeBuffer::~GpuMemoryBufferImplOzoneNativeBuffer() { 58 GpuMemoryBufferImplOzoneNativeBuffer::~GpuMemoryBufferImplOzoneNativeBuffer() {
20 } 59 }
21 60
22 // static 61 // static
23 scoped_ptr<GpuMemoryBufferImpl> 62 scoped_ptr<GpuMemoryBufferImpl>
24 GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle( 63 GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle(
64 ui::NativePixmapManager* manager,
25 const gfx::GpuMemoryBufferHandle& handle, 65 const gfx::GpuMemoryBufferHandle& handle,
26 const gfx::Size& size, 66 const gfx::Size& size,
27 Format format, 67 Format format,
28 Usage usage, 68 Usage usage,
29 const DestructionCallback& callback) { 69 const DestructionCallback& callback) {
30 return make_scoped_ptr<GpuMemoryBufferImpl>( 70 scoped_ptr<GpuMemoryBufferImplOzoneNativeBuffer> buffer =
31 new GpuMemoryBufferImplOzoneNativeBuffer( 71 make_scoped_ptr(new GpuMemoryBufferImplOzoneNativeBuffer(
32 handle.id, size, format, callback)); 72 handle.id, size, format, usage, callback));
73
74 if (!buffer->Initialize(manager, handle))
75 return nullptr;
76 return buffer.Pass();
77 }
78
79 bool GpuMemoryBufferImplOzoneNativeBuffer::Initialize(
80 ui::NativePixmapManager* manager,
81 const gfx::GpuMemoryBufferHandle& handle) {
82 DCHECK(manager);
83 pixmap_ = manager->CreateFromFileDescriptor(handle.handle, size_,
84 GetOzoneFormatFor(format_),
85 GetOzoneUsageFor(usage_));
86 return !!pixmap_;
33 } 87 }
34 88
35 bool GpuMemoryBufferImplOzoneNativeBuffer::Map(void** data) { 89 bool GpuMemoryBufferImplOzoneNativeBuffer::Map(void** data) {
36 NOTREACHED(); 90 DCHECK(!mapped_);
37 return false; 91 DCHECK_EQ(usage_, MAP);
92 mapped_ = true;
93 void* buffer = pixmap_->Map();
94 if (!buffer)
95 return false;
96 *data = buffer;
97 return true;
38 } 98 }
39 99
40 void GpuMemoryBufferImplOzoneNativeBuffer::Unmap() { 100 void GpuMemoryBufferImplOzoneNativeBuffer::Unmap() {
41 NOTREACHED(); 101 DCHECK(mapped_);
102 DCHECK_EQ(usage_, MAP);
103 pixmap_->Unmap();
104 mapped_ = false;
42 } 105 }
43 106
44 void GpuMemoryBufferImplOzoneNativeBuffer::GetStride(int* stride) const { 107 void GpuMemoryBufferImplOzoneNativeBuffer::GetStride(int* stride) const {
45 NOTREACHED(); 108 *stride = pixmap_->GetDmaBufPitch();
46 } 109 }
47 110
48 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativeBuffer::GetHandle() 111 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativeBuffer::GetHandle()
49 const { 112 const {
50 gfx::GpuMemoryBufferHandle handle; 113 gfx::GpuMemoryBufferHandle handle;
51 handle.type = gfx::OZONE_NATIVE_BUFFER; 114 handle.type = gfx::OZONE_NATIVE_BUFFER;
52 handle.id = id_; 115 handle.id = id_;
53 return handle; 116 return handle;
54 } 117 }
55 118
56 } // namespace content 119 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698