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

Unified Diff: content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc

Issue 1258713002: ozone: unify GpuMemoryBufferFactoryOzoneNativePixmap in content/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix linux_chromium_gn_dgb build 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 side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc
diff --git a/content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc b/content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc
index e787be94aa3d27b6892d4428ceebdd83e8894e8d..2c69f5019613d216f6de429d031e40b50414b142 100644
--- a/content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc
+++ b/content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc
@@ -4,8 +4,7 @@
#include "content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.h"
-#include "base/logging.h"
-#include "ui/gl/gl_image.h"
+#include "ui/gl/gl_image_ozone_native_pixmap.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/surface_factory_ozone.h"
@@ -16,6 +15,45 @@ const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = {
{gfx::GpuMemoryBuffer::BGRA_8888, gfx::GpuMemoryBuffer::SCANOUT},
{gfx::GpuMemoryBuffer::RGBX_8888, gfx::GpuMemoryBuffer::SCANOUT}};
+ui::SurfaceFactoryOzone::BufferFormat GetOzoneFormatFor(
+ gfx::GpuMemoryBuffer::Format format) {
+ switch (format) {
+ case gfx::GpuMemoryBuffer::BGRA_8888:
+ return ui::SurfaceFactoryOzone::BGRA_8888;
+ case gfx::GpuMemoryBuffer::RGBX_8888:
+ return ui::SurfaceFactoryOzone::RGBX_8888;
+ case gfx::GpuMemoryBuffer::ATC:
+ case gfx::GpuMemoryBuffer::ATCIA:
+ case gfx::GpuMemoryBuffer::DXT1:
+ case gfx::GpuMemoryBuffer::DXT5:
+ case gfx::GpuMemoryBuffer::ETC1:
+ case gfx::GpuMemoryBuffer::R_8:
+ case gfx::GpuMemoryBuffer::RGBA_4444:
+ case gfx::GpuMemoryBuffer::RGBA_8888:
+ case gfx::GpuMemoryBuffer::YUV_420:
+ NOTREACHED();
+ return ui::SurfaceFactoryOzone::BGRA_8888;
+ }
+
+ NOTREACHED();
+ return ui::SurfaceFactoryOzone::BGRA_8888;
+}
+
+ui::SurfaceFactoryOzone::BufferUsage GetOzoneUsageFor(
+ gfx::GpuMemoryBuffer::Usage usage) {
+ switch (usage) {
+ case gfx::GpuMemoryBuffer::MAP:
+ return ui::SurfaceFactoryOzone::MAP;
+ case gfx::GpuMemoryBuffer::PERSISTENT_MAP:
+ return ui::SurfaceFactoryOzone::PERSISTENT_MAP;
+ case gfx::GpuMemoryBuffer::SCANOUT:
+ return ui::SurfaceFactoryOzone::SCANOUT;
+ }
+
+ NOTREACHED();
+ return ui::SurfaceFactoryOzone::MAP;
+}
+
} // namespace
GpuMemoryBufferFactoryOzoneNativePixmap::
@@ -57,10 +95,22 @@ GpuMemoryBufferFactoryOzoneNativePixmap::CreateGpuMemoryBuffer(
gfx::GpuMemoryBuffer::Usage usage,
int client_id,
gfx::PluginWindowHandle surface_handle) {
- if (!ozone_native_pixmap_factory_.CreateGpuMemoryBuffer(
- id, size, format, usage, client_id, surface_handle)) {
+ scoped_refptr<ui::NativePixmap> pixmap =
+ ui::OzonePlatform::GetInstance()
+ ->GetSurfaceFactoryOzone()
+ ->CreateNativePixmap(surface_handle, size, GetOzoneFormatFor(format),
+ GetOzoneUsageFor(usage));
+ if (!pixmap.get()) {
+ LOG(ERROR) << "Failed to create pixmap " << size.width() << "x"
+ << size.height() << " format " << format << ", usage " << usage;
return gfx::GpuMemoryBufferHandle();
}
+ base::AutoLock lock(native_pixmaps_lock_);
+ NativePixmapMapKey key(id, client_id);
+ DCHECK(native_pixmaps_.find(key) == native_pixmaps_.end())
+ << "pixmap with this key must not exist";
+ native_pixmaps_[key] = pixmap;
+
gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::OZONE_NATIVE_PIXMAP;
handle.id = id;
@@ -70,7 +120,10 @@ GpuMemoryBufferFactoryOzoneNativePixmap::CreateGpuMemoryBuffer(
void GpuMemoryBufferFactoryOzoneNativePixmap::DestroyGpuMemoryBuffer(
gfx::GpuMemoryBufferId id,
int client_id) {
- ozone_native_pixmap_factory_.DestroyGpuMemoryBuffer(id, client_id);
+ base::AutoLock lock(native_pixmaps_lock_);
+ auto it = native_pixmaps_.find(NativePixmapMapKey(id, client_id));
+ DCHECK(it != native_pixmaps_.end()) << "pixmap with this key must exist";
+ native_pixmaps_.erase(it);
}
gpu::ImageFactory* GpuMemoryBufferFactoryOzoneNativePixmap::AsImageFactory() {
@@ -85,8 +138,24 @@ GpuMemoryBufferFactoryOzoneNativePixmap::CreateImageForGpuMemoryBuffer(
unsigned internalformat,
int client_id) {
DCHECK_EQ(handle.type, gfx::OZONE_NATIVE_PIXMAP);
- return ozone_native_pixmap_factory_.CreateImageForGpuMemoryBuffer(
- handle.id, size, format, internalformat, client_id);
+ scoped_refptr<ui::NativePixmap> pixmap;
+ {
+ base::AutoLock lock(native_pixmaps_lock_);
+ NativePixmapMap::iterator it =
+ native_pixmaps_.find(NativePixmapMapKey(handle.id, client_id));
+ if (it == native_pixmaps_.end()) {
+ return nullptr;
+ }
+ pixmap = it->second;
+ }
+
+ scoped_refptr<gfx::GLImageOzoneNativePixmap> image(
+ new gfx::GLImageOzoneNativePixmap(size, internalformat));
+ if (!image->Initialize(pixmap.get(), format)) {
+ LOG(ERROR) << "Failed to create GLImage";
+ return nullptr;
+ }
+ return image;
}
} // namespace content
« no previous file with comments | « content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.h ('k') | content/common/gpu/media/vaapi_drm_picture.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698