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

Side by Side Diff: content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc

Issue 1845563005: Refactor content/common/gpu into gpu/ipc/service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Drop ref to deleted content_tests_gypi_values.content_unittests_ozone_sources Created 4 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 "content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.h"
6
7 #include "ui/gl/gl_image_ozone_native_pixmap.h"
8 #include "ui/ozone/public/client_native_pixmap.h"
9 #include "ui/ozone/public/client_native_pixmap_factory.h"
10 #include "ui/ozone/public/ozone_platform.h"
11 #include "ui/ozone/public/surface_factory_ozone.h"
12
13 namespace content {
14
15 GpuMemoryBufferFactoryOzoneNativePixmap::
16 GpuMemoryBufferFactoryOzoneNativePixmap() {}
17
18 GpuMemoryBufferFactoryOzoneNativePixmap::
19 ~GpuMemoryBufferFactoryOzoneNativePixmap() {}
20
21 gfx::GpuMemoryBufferHandle
22 GpuMemoryBufferFactoryOzoneNativePixmap::CreateGpuMemoryBuffer(
23 gfx::GpuMemoryBufferId id,
24 const gfx::Size& size,
25 gfx::BufferFormat format,
26 gfx::BufferUsage usage,
27 int client_id,
28 gpu::SurfaceHandle surface_handle) {
29 scoped_refptr<ui::NativePixmap> pixmap =
30 ui::OzonePlatform::GetInstance()
31 ->GetSurfaceFactoryOzone()
32 ->CreateNativePixmap(surface_handle, size, format, usage);
33 if (!pixmap.get()) {
34 DLOG(ERROR) << "Failed to create pixmap " << size.width() << "x"
35 << size.height() << " format " << static_cast<int>(format)
36 << ", usage " << static_cast<int>(usage);
37 return gfx::GpuMemoryBufferHandle();
38 }
39
40 gfx::GpuMemoryBufferHandle new_handle;
41 new_handle.type = gfx::OZONE_NATIVE_PIXMAP;
42 new_handle.id = id;
43 new_handle.native_pixmap_handle = pixmap->ExportHandle();
44
45 {
46 base::AutoLock lock(native_pixmaps_lock_);
47 NativePixmapMapKey key(id.id, client_id);
48 DCHECK(native_pixmaps_.find(key) == native_pixmaps_.end());
49 native_pixmaps_[key] = pixmap;
50 }
51
52 return new_handle;
53 }
54
55 gfx::GpuMemoryBufferHandle
56 GpuMemoryBufferFactoryOzoneNativePixmap::CreateGpuMemoryBufferFromHandle(
57 const gfx::GpuMemoryBufferHandle& handle,
58 gfx::GpuMemoryBufferId id,
59 const gfx::Size& size,
60 gfx::BufferFormat format,
61 int client_id) {
62 scoped_refptr<ui::NativePixmap> pixmap =
63 ui::OzonePlatform::GetInstance()
64 ->GetSurfaceFactoryOzone()
65 ->CreateNativePixmapFromHandle(size, format,
66 handle.native_pixmap_handle);
67 if (!pixmap.get()) {
68 DLOG(ERROR) << "Failed to create pixmap from handle";
69 return gfx::GpuMemoryBufferHandle();
70 }
71
72 gfx::GpuMemoryBufferHandle new_handle;
73 new_handle.type = gfx::OZONE_NATIVE_PIXMAP;
74 new_handle.id = id;
75 new_handle.native_pixmap_handle = pixmap->ExportHandle();
76
77 {
78 base::AutoLock lock(native_pixmaps_lock_);
79 NativePixmapMapKey key(id.id, client_id);
80 DCHECK(native_pixmaps_.find(key) == native_pixmaps_.end());
81 native_pixmaps_[key] = pixmap;
82 }
83
84 return new_handle;
85 }
86
87 void GpuMemoryBufferFactoryOzoneNativePixmap::DestroyGpuMemoryBuffer(
88 gfx::GpuMemoryBufferId id,
89 int client_id) {
90 base::AutoLock lock(native_pixmaps_lock_);
91 auto it = native_pixmaps_.find(NativePixmapMapKey(id.id, client_id));
92 DCHECK(it != native_pixmaps_.end());
93 native_pixmaps_.erase(it);
94 }
95
96 gpu::ImageFactory* GpuMemoryBufferFactoryOzoneNativePixmap::AsImageFactory() {
97 return this;
98 }
99
100 scoped_refptr<gl::GLImage>
101 GpuMemoryBufferFactoryOzoneNativePixmap::CreateImageForGpuMemoryBuffer(
102 const gfx::GpuMemoryBufferHandle& handle,
103 const gfx::Size& size,
104 gfx::BufferFormat format,
105 unsigned internalformat,
106 int client_id) {
107 DCHECK_EQ(handle.type, gfx::OZONE_NATIVE_PIXMAP);
108 scoped_refptr<ui::NativePixmap> pixmap;
109 {
110 base::AutoLock lock(native_pixmaps_lock_);
111 NativePixmapMap::iterator it =
112 native_pixmaps_.find(NativePixmapMapKey(handle.id.id, client_id));
113 if (it == native_pixmaps_.end()) {
114 return nullptr;
115 }
116 pixmap = it->second;
117 }
118
119 scoped_refptr<gfx::GLImageOzoneNativePixmap> image(
120 new gfx::GLImageOzoneNativePixmap(size, internalformat));
121 if (!image->Initialize(pixmap.get(), format)) {
122 LOG(ERROR) << "Failed to create GLImage";
123 return nullptr;
124 }
125 return image;
126 }
127
128 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698