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

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

Issue 2061743004: Implement native GMB backbuffers in the GLES2 Command Decoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from piman. Created 4 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 unified diff | Download patch
« no previous file with comments | « gpu/ipc/service/gpu_memory_buffer_factory_io_surface.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/ipc/service/gpu_memory_buffer_factory_io_surface.h" 5 #include "gpu/ipc/service/gpu_memory_buffer_factory_io_surface.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "gpu/GLES2/gl2extchromium.h"
10 #include "ui/gfx/buffer_format_util.h" 11 #include "ui/gfx/buffer_format_util.h"
11 #include "ui/gfx/mac/io_surface.h" 12 #include "ui/gfx/mac/io_surface.h"
12 #include "ui/gl/gl_image_io_surface.h" 13 #include "ui/gl/gl_image_io_surface.h"
13 14
14 namespace gpu { 15 namespace gpu {
15 16
16 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { 17 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() {
17 } 18 }
18 19
19 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { 20 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() {
20 } 21 }
21 22
22 gfx::GpuMemoryBufferHandle 23 gfx::GpuMemoryBufferHandle
23 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( 24 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer(
24 gfx::GpuMemoryBufferId id, 25 gfx::GpuMemoryBufferId id,
25 const gfx::Size& size, 26 const gfx::Size& size,
26 gfx::BufferFormat format, 27 gfx::BufferFormat format,
27 gfx::BufferUsage usage, 28 gfx::BufferUsage usage,
28 int client_id, 29 int client_id,
29 SurfaceHandle surface_handle) { 30 SurfaceHandle surface_handle) {
30 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( 31 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(
31 gfx::CreateIOSurface(size, format)); 32 gfx::CreateIOSurface(size, format));
32 if (!io_surface) 33 if (!io_surface)
33 return gfx::GpuMemoryBufferHandle(); 34 return gfx::GpuMemoryBufferHandle();
34 35
35 { 36 // A GpuMemoryBuffer with client_id = 0 behaves like anonymous shared memory.
37 if (client_id != 0) {
36 base::AutoLock lock(io_surfaces_lock_); 38 base::AutoLock lock(io_surfaces_lock_);
37 39
38 IOSurfaceMapKey key(id, client_id); 40 IOSurfaceMapKey key(id, client_id);
39 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); 41 DCHECK(io_surfaces_.find(key) == io_surfaces_.end());
40 io_surfaces_[key] = io_surface; 42 io_surfaces_[key] = io_surface;
41 } 43 }
42 44
43 gfx::GpuMemoryBufferHandle handle; 45 gfx::GpuMemoryBufferHandle handle;
44 handle.type = gfx::IO_SURFACE_BUFFER; 46 handle.type = gfx::IO_SURFACE_BUFFER;
45 handle.id = id; 47 handle.id = id;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 return scoped_refptr<gl::GLImage>(); 81 return scoped_refptr<gl::GLImage>();
80 82
81 scoped_refptr<gl::GLImageIOSurface> image( 83 scoped_refptr<gl::GLImageIOSurface> image(
82 new gl::GLImageIOSurface(size, internalformat)); 84 new gl::GLImageIOSurface(size, internalformat));
83 if (!image->Initialize(it->second.get(), handle.id, format)) 85 if (!image->Initialize(it->second.get(), handle.id, format))
84 return scoped_refptr<gl::GLImage>(); 86 return scoped_refptr<gl::GLImage>();
85 87
86 return image; 88 return image;
87 } 89 }
88 90
91 scoped_refptr<gl::GLImage>
92 GpuMemoryBufferFactoryIOSurface::CreateAnonymousImage(const gfx::Size& size,
93 gfx::BufferFormat format,
94 unsigned internalformat) {
95 // Note that the GpuMemoryBufferId and child id don't matter since the texture
96 // will never be directly exposed to other processes, only via a mailbox.
97 int gmb_id = 0;
98 int client_id = 0;
99 gfx::GpuMemoryBufferHandle handle = CreateGpuMemoryBuffer(
100 gfx::GpuMemoryBufferId(gmb_id), size, format, gfx::BufferUsage::SCANOUT,
101 client_id, gpu::kNullSurfaceHandle);
102
103 base::ScopedCFTypeRef<IOSurfaceRef> io_surface;
104 io_surface.reset(IOSurfaceLookupFromMachPort(handle.mach_port.get()));
105 DCHECK_NE(nullptr, io_surface.get());
106 scoped_refptr<gl::GLImageIOSurface> image(
107 new gl::GLImageIOSurface(size, internalformat));
108 if (!image->Initialize(io_surface.get(), handle.id, format))
109 return scoped_refptr<gl::GLImage>();
110 return image;
111 }
112
113 unsigned GpuMemoryBufferFactoryIOSurface::RequiredTextureType() {
114 return GL_TEXTURE_RECTANGLE_ARB;
115 }
116
117 bool GpuMemoryBufferFactoryIOSurface::SupportsFormatRGB() {
118 return false;
119 }
120
89 } // namespace gpu 121 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/ipc/service/gpu_memory_buffer_factory_io_surface.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698