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

Side by Side Diff: gpu/ipc/service/gpu_memory_buffer_factory_ozone_native_pixmap.cc

Issue 2709163004: Rename GpuMemoryBufferFactoryOzoneNativePixmap to GpuMemoryBufferFactoryNativePixmap (Closed)
Patch Set: Rebase and addressed reveman's remark. Created 3 years, 8 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
(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 "gpu/ipc/service/gpu_memory_buffer_factory_ozone_native_pixmap.h"
6
7 #include "ui/gfx/client_native_pixmap.h"
8 #include "ui/gfx/native_pixmap.h"
9 #include "ui/gl/gl_image_native_pixmap.h"
10 #include "ui/ozone/public/client_native_pixmap_factory_ozone.h"
11 #include "ui/ozone/public/ozone_platform.h"
12 #include "ui/ozone/public/surface_factory_ozone.h"
13
14 namespace gpu {
15
16 GpuMemoryBufferFactoryOzoneNativePixmap::
17 GpuMemoryBufferFactoryOzoneNativePixmap() {}
18
19 GpuMemoryBufferFactoryOzoneNativePixmap::
20 ~GpuMemoryBufferFactoryOzoneNativePixmap() {}
21
22 gfx::GpuMemoryBufferHandle
23 GpuMemoryBufferFactoryOzoneNativePixmap::CreateGpuMemoryBuffer(
24 gfx::GpuMemoryBufferId id,
25 const gfx::Size& size,
26 gfx::BufferFormat format,
27 gfx::BufferUsage usage,
28 int client_id,
29 SurfaceHandle surface_handle) {
30 scoped_refptr<gfx::NativePixmap> pixmap =
31 ui::OzonePlatform::GetInstance()
32 ->GetSurfaceFactoryOzone()
33 ->CreateNativePixmap(surface_handle, size, format, usage);
34 if (!pixmap.get()) {
35 DLOG(ERROR) << "Failed to create pixmap " << size.ToString() << " format "
36 << static_cast<int>(format) << ", usage "
37 << static_cast<int>(usage);
38 return gfx::GpuMemoryBufferHandle();
39 }
40
41 gfx::GpuMemoryBufferHandle new_handle;
42 new_handle.type = gfx::NATIVE_PIXMAP;
43 new_handle.id = id;
44 new_handle.native_pixmap_handle = pixmap->ExportHandle();
45
46 // TODO(reveman): Remove this once crbug.com/628334 has been fixed.
47 {
48 base::AutoLock lock(native_pixmaps_lock_);
49 NativePixmapMapKey key(id.id, client_id);
50 DCHECK(native_pixmaps_.find(key) == native_pixmaps_.end());
51 native_pixmaps_[key] = pixmap;
52 }
53
54 return new_handle;
55 }
56
57 void GpuMemoryBufferFactoryOzoneNativePixmap::DestroyGpuMemoryBuffer(
58 gfx::GpuMemoryBufferId id,
59 int client_id) {
60 base::AutoLock lock(native_pixmaps_lock_);
61 NativePixmapMapKey key(id.id, client_id);
62 native_pixmaps_.erase(key);
63 }
64
65 ImageFactory* GpuMemoryBufferFactoryOzoneNativePixmap::AsImageFactory() {
66 return this;
67 }
68
69 scoped_refptr<gl::GLImage>
70 GpuMemoryBufferFactoryOzoneNativePixmap::CreateImageForGpuMemoryBuffer(
71 const gfx::GpuMemoryBufferHandle& handle,
72 const gfx::Size& size,
73 gfx::BufferFormat format,
74 unsigned internalformat,
75 int client_id,
76 SurfaceHandle surface_handle) {
77 DCHECK_EQ(handle.type, gfx::NATIVE_PIXMAP);
78
79 scoped_refptr<gfx::NativePixmap> pixmap;
80
81 // If CreateGpuMemoryBuffer was used to allocate this buffer then avoid
82 // creating a new native pixmap for it.
83 {
84 base::AutoLock lock(native_pixmaps_lock_);
85 NativePixmapMapKey key(handle.id.id, client_id);
86 auto it = native_pixmaps_.find(key);
87 if (it != native_pixmaps_.end())
88 pixmap = it->second;
89 }
90
91 // Create new pixmap from handle if one doesn't already exist.
92 if (!pixmap) {
93 pixmap = ui::OzonePlatform::GetInstance()
94 ->GetSurfaceFactoryOzone()
95 ->CreateNativePixmapFromHandle(surface_handle, size, format,
96 handle.native_pixmap_handle);
97 if (!pixmap.get()) {
98 DLOG(ERROR) << "Failed to create pixmap from handle";
99 return nullptr;
100 }
101 } else {
102 for (const auto& fd : handle.native_pixmap_handle.fds) {
103 // Close the fd by wrapping it in a ScopedFD and letting it fall
104 // out of scope.
105 base::ScopedFD scoped_fd(fd.fd);
106 }
107 }
108
109 scoped_refptr<gl::GLImageNativePixmap> image(
110 new gl::GLImageNativePixmap(size, internalformat));
111 if (!image->Initialize(pixmap.get(), format)) {
112 LOG(ERROR) << "Failed to create GLImage " << size.ToString() << " format "
113 << static_cast<int>(format);
114 return nullptr;
115 }
116 return image;
117 }
118
119 scoped_refptr<gl::GLImage>
120 GpuMemoryBufferFactoryOzoneNativePixmap::CreateAnonymousImage(
121 const gfx::Size& size,
122 gfx::BufferFormat format,
123 unsigned internalformat) {
124 scoped_refptr<gfx::NativePixmap> pixmap =
125 ui::OzonePlatform::GetInstance()
126 ->GetSurfaceFactoryOzone()
127 ->CreateNativePixmap(gpu::kNullSurfaceHandle, size, format,
128 gfx::BufferUsage::SCANOUT);
129 if (!pixmap.get()) {
130 LOG(ERROR) << "Failed to create pixmap " << size.ToString() << " format "
131 << static_cast<int>(format);
132 return nullptr;
133 }
134 scoped_refptr<gl::GLImageNativePixmap> image(
135 new gl::GLImageNativePixmap(size, internalformat));
136 if (!image->Initialize(pixmap.get(), format)) {
137 LOG(ERROR) << "Failed to create GLImage " << size.ToString() << " format "
138 << static_cast<int>(format);
139 return nullptr;
140 }
141 return image;
142 }
143
144 unsigned GpuMemoryBufferFactoryOzoneNativePixmap::RequiredTextureType() {
145 return GL_TEXTURE_EXTERNAL_OES;
146 }
147
148 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698