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

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

Issue 604903005: content: Move IOSurface backed GpuMemoryBuffer allocation to GPU process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: include CoreFoundation.h Created 6 years, 3 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_io_surface.cc
diff --git a/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc b/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8c9fee5cfb210d0a6a2a2765051161405f01b796
--- /dev/null
+++ b/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc
@@ -0,0 +1,100 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/gpu/gpu_memory_buffer_factory_io_surface.h"
+
+#include <CoreFoundation/CoreFoundation.h>
+
+#include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
+#include "ui/gl/gl_image_io_surface.h"
+
+namespace content {
+namespace {
+
+void AddBooleanValue(CFMutableDictionaryRef dictionary,
+ const CFStringRef key,
+ bool value) {
+ CFDictionaryAddValue(
+ dictionary, key, value ? kCFBooleanTrue : kCFBooleanFalse);
+}
+
+void AddIntegerValue(CFMutableDictionaryRef dictionary,
+ const CFStringRef key,
+ int32 value) {
+ base::ScopedCFTypeRef<CFNumberRef> number(
+ CFNumberCreate(NULL, kCFNumberSInt32Type, &value));
+ CFDictionaryAddValue(dictionary, key, number.get());
+}
+
+} // namespace
+
+GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() {
+}
+
+GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() {
+}
+
+gfx::GpuMemoryBufferHandle
+GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer(
+ const gfx::GpuMemoryBufferId& id,
+ const gfx::Size& size,
+ unsigned internalformat) {
+ base::ScopedCFTypeRef<CFMutableDictionaryRef> properties;
+ properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault,
+ 0,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks));
+ AddIntegerValue(properties, kIOSurfaceWidth, size.width());
+ AddIntegerValue(properties, kIOSurfaceHeight, size.height());
+ AddIntegerValue(properties,
+ kIOSurfaceBytesPerElement,
+ GpuMemoryBufferImpl::BytesPerPixel(internalformat));
+ AddIntegerValue(properties,
+ kIOSurfacePixelFormat,
+ GpuMemoryBufferImplIOSurface::PixelFormat(internalformat));
+ // TODO(reveman): Remove this when using a mach_port_t to transfer
+ // IOSurface to browser and renderer process. crbug.com/323304
+ AddBooleanValue(properties, kIOSurfaceIsGlobal, true);
+
+ base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties));
+ if (!io_surface)
+ return gfx::GpuMemoryBufferHandle();
+
+ IOSurfaceMapKey key(id.primary_id, id.secondary_id);
+ DCHECK(io_surfaces_.find(key) == io_surfaces_.end());
+ io_surfaces_[key] = io_surface;
+
+ gfx::GpuMemoryBufferHandle handle;
+ handle.type = gfx::IO_SURFACE_BUFFER;
+ handle.global_id = id;
+ handle.io_surface_id = IOSurfaceGetID(io_surface);
+ return handle;
+}
+
+void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer(
+ const gfx::GpuMemoryBufferId& id) {
+ IOSurfaceMapKey key(id.primary_id, id.secondary_id);
+ IOSurfaceMap::iterator it = io_surfaces_.find(key);
+ if (it != io_surfaces_.end())
+ io_surfaces_.erase(it);
+}
+
+scoped_refptr<gfx::GLImage>
+GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer(
+ const gfx::GpuMemoryBufferId& id,
+ const gfx::Size& size,
+ unsigned internalformat) {
+ IOSurfaceMapKey key(id.primary_id, id.secondary_id);
+ IOSurfaceMap::iterator it = io_surfaces_.find(key);
+ if (it == io_surfaces_.end())
+ return scoped_refptr<gfx::GLImage>();
+
+ scoped_refptr<gfx::GLImageIOSurface> image(new gfx::GLImageIOSurface(size));
+ if (!image->Initialize(it->second.get()))
+ return scoped_refptr<gfx::GLImage>();
+
+ return image;
+}
+
+} // namespace content
« no previous file with comments | « content/common/gpu/gpu_memory_buffer_factory_io_surface.h ('k') | content/common/gpu/gpu_memory_buffer_factory_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698