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

Side by Side 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, 2 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_io_surface.h"
6
7 #include <CoreFoundation/CoreFoundation.h>
8
9 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
10 #include "ui/gl/gl_image_io_surface.h"
11
12 namespace content {
13 namespace {
14
15 void AddBooleanValue(CFMutableDictionaryRef dictionary,
16 const CFStringRef key,
17 bool value) {
18 CFDictionaryAddValue(
19 dictionary, key, value ? kCFBooleanTrue : kCFBooleanFalse);
20 }
21
22 void AddIntegerValue(CFMutableDictionaryRef dictionary,
23 const CFStringRef key,
24 int32 value) {
25 base::ScopedCFTypeRef<CFNumberRef> number(
26 CFNumberCreate(NULL, kCFNumberSInt32Type, &value));
27 CFDictionaryAddValue(dictionary, key, number.get());
28 }
29
30 } // namespace
31
32 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() {
33 }
34
35 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() {
36 }
37
38 gfx::GpuMemoryBufferHandle
39 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer(
40 const gfx::GpuMemoryBufferId& id,
41 const gfx::Size& size,
42 unsigned internalformat) {
43 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties;
44 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault,
45 0,
46 &kCFTypeDictionaryKeyCallBacks,
47 &kCFTypeDictionaryValueCallBacks));
48 AddIntegerValue(properties, kIOSurfaceWidth, size.width());
49 AddIntegerValue(properties, kIOSurfaceHeight, size.height());
50 AddIntegerValue(properties,
51 kIOSurfaceBytesPerElement,
52 GpuMemoryBufferImpl::BytesPerPixel(internalformat));
53 AddIntegerValue(properties,
54 kIOSurfacePixelFormat,
55 GpuMemoryBufferImplIOSurface::PixelFormat(internalformat));
56 // TODO(reveman): Remove this when using a mach_port_t to transfer
57 // IOSurface to browser and renderer process. crbug.com/323304
58 AddBooleanValue(properties, kIOSurfaceIsGlobal, true);
59
60 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties));
61 if (!io_surface)
62 return gfx::GpuMemoryBufferHandle();
63
64 IOSurfaceMapKey key(id.primary_id, id.secondary_id);
65 DCHECK(io_surfaces_.find(key) == io_surfaces_.end());
66 io_surfaces_[key] = io_surface;
67
68 gfx::GpuMemoryBufferHandle handle;
69 handle.type = gfx::IO_SURFACE_BUFFER;
70 handle.global_id = id;
71 handle.io_surface_id = IOSurfaceGetID(io_surface);
72 return handle;
73 }
74
75 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer(
76 const gfx::GpuMemoryBufferId& id) {
77 IOSurfaceMapKey key(id.primary_id, id.secondary_id);
78 IOSurfaceMap::iterator it = io_surfaces_.find(key);
79 if (it != io_surfaces_.end())
80 io_surfaces_.erase(it);
81 }
82
83 scoped_refptr<gfx::GLImage>
84 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer(
85 const gfx::GpuMemoryBufferId& id,
86 const gfx::Size& size,
87 unsigned internalformat) {
88 IOSurfaceMapKey key(id.primary_id, id.secondary_id);
89 IOSurfaceMap::iterator it = io_surfaces_.find(key);
90 if (it == io_surfaces_.end())
91 return scoped_refptr<gfx::GLImage>();
92
93 scoped_refptr<gfx::GLImageIOSurface> image(new gfx::GLImageIOSurface(size));
94 if (!image->Initialize(it->second.get()))
95 return scoped_refptr<gfx::GLImage>();
96
97 return image;
98 }
99
100 } // namespace content
OLDNEW
« 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