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

Side by Side Diff: content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc

Issue 685983005: gpu: Associate all GpuMemoryBuffers with unique IDs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" 5 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
6 6
7 #include "base/atomic_sequence_num.h"
8 #include "base/bind.h" 7 #include "base/bind.h"
9 #include "base/logging.h" 8 #include "base/logging.h"
10 #include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" 9 #include "content/common/gpu/client/gpu_memory_buffer_factory_host.h"
11 #include "ui/gl/gl_bindings.h" 10 #include "ui/gl/gl_bindings.h"
12 11
13 namespace content { 12 namespace content {
14 namespace { 13 namespace {
15 14
16 base::StaticAtomicSequenceNumber g_next_buffer_id;
17
18 void Noop() { 15 void Noop() {
19 } 16 }
20 17
21 void GpuMemoryBufferCreated( 18 void GpuMemoryBufferCreated(
22 const gfx::Size& size, 19 const gfx::Size& size,
23 gfx::GpuMemoryBuffer::Format format, 20 gfx::GpuMemoryBuffer::Format format,
24 const GpuMemoryBufferImpl::CreationCallback& callback, 21 const GpuMemoryBufferImpl::CreationCallback& callback,
25 const gfx::GpuMemoryBufferHandle& handle) { 22 const gfx::GpuMemoryBufferHandle& handle) {
26 DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type); 23 DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type);
27 24
28 callback.Run(GpuMemoryBufferImplIOSurface::CreateFromHandle( 25 callback.Run(GpuMemoryBufferImplIOSurface::CreateFromHandle(
29 handle, size, format, base::Bind(&Noop))); 26 handle, size, format, base::Bind(&Noop)));
30 } 27 }
31 28
32 void GpuMemoryBufferCreatedForChildProcess( 29 void GpuMemoryBufferCreatedForChildProcess(
33 const GpuMemoryBufferImpl::AllocationCallback& callback, 30 const GpuMemoryBufferImpl::AllocationCallback& callback,
34 const gfx::GpuMemoryBufferHandle& handle) { 31 const gfx::GpuMemoryBufferHandle& handle) {
35 DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type); 32 DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type);
36 33
37 callback.Run(handle); 34 callback.Run(handle);
38 } 35 }
39 36
40 } // namespace 37 } // namespace
41 38
42 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( 39 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface(
40 gfx::GpuMemoryBufferId id,
43 const gfx::Size& size, 41 const gfx::Size& size,
44 Format format, 42 Format format,
45 const DestructionCallback& callback, 43 const DestructionCallback& callback,
46 IOSurfaceRef io_surface) 44 IOSurfaceRef io_surface)
47 : GpuMemoryBufferImpl(size, format, callback), io_surface_(io_surface) { 45 : GpuMemoryBufferImpl(id, size, format, callback), io_surface_(io_surface) {
48 } 46 }
49 47
50 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() { 48 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() {
51 } 49 }
52 50
53 // static 51 // static
54 void GpuMemoryBufferImplIOSurface::Create(const gfx::Size& size, 52 void GpuMemoryBufferImplIOSurface::Create(gfx::GpuMemoryBufferId id,
53 const gfx::Size& size,
55 Format format, 54 Format format,
56 int client_id, 55 int client_id,
57 const CreationCallback& callback) { 56 const CreationCallback& callback) {
58 gfx::GpuMemoryBufferHandle handle;
59 handle.type = gfx::IO_SURFACE_BUFFER;
60 handle.global_id.primary_id = g_next_buffer_id.GetNext();
61 handle.global_id.secondary_id = client_id;
62 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( 57 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer(
63 handle, 58 gfx::IO_SURFACE_BUFFER,
59 id,
64 size, 60 size,
65 format, 61 format,
66 MAP, 62 MAP,
63 client_id,
67 base::Bind(&GpuMemoryBufferCreated, size, format, callback)); 64 base::Bind(&GpuMemoryBufferCreated, size, format, callback));
68 } 65 }
69 66
70 // static 67 // static
71 void GpuMemoryBufferImplIOSurface::AllocateForChildProcess( 68 void GpuMemoryBufferImplIOSurface::AllocateForChildProcess(
69 gfx::GpuMemoryBufferId id,
72 const gfx::Size& size, 70 const gfx::Size& size,
73 Format format, 71 Format format,
74 int child_client_id, 72 int child_client_id,
75 const AllocationCallback& callback) { 73 const AllocationCallback& callback) {
76 gfx::GpuMemoryBufferHandle handle;
77 handle.type = gfx::IO_SURFACE_BUFFER;
78 handle.global_id.primary_id = g_next_buffer_id.GetNext();
79 handle.global_id.secondary_id = child_client_id;
80 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( 74 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer(
81 handle, 75 gfx::IO_SURFACE_BUFFER,
76 id,
82 size, 77 size,
83 format, 78 format,
84 MAP, 79 MAP,
80 child_client_id,
85 base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback)); 81 base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback));
86 } 82 }
87 83
88 // static 84 // static
89 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplIOSurface::CreateFromHandle( 85 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplIOSurface::CreateFromHandle(
90 const gfx::GpuMemoryBufferHandle& handle, 86 const gfx::GpuMemoryBufferHandle& handle,
91 const gfx::Size& size, 87 const gfx::Size& size,
92 Format format, 88 Format format,
93 const DestructionCallback& callback) { 89 const DestructionCallback& callback) {
94 DCHECK(IsFormatSupported(format)); 90 DCHECK(IsFormatSupported(format));
95 91
96 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( 92 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(
97 IOSurfaceLookup(handle.io_surface_id)); 93 IOSurfaceLookup(handle.io_surface_id));
98 if (!io_surface) 94 if (!io_surface)
99 return scoped_ptr<GpuMemoryBufferImpl>(); 95 return scoped_ptr<GpuMemoryBufferImpl>();
100 96
101 return make_scoped_ptr<GpuMemoryBufferImpl>(new GpuMemoryBufferImplIOSurface( 97 return make_scoped_ptr<GpuMemoryBufferImpl>(new GpuMemoryBufferImplIOSurface(
102 size, format, callback, io_surface.get())); 98 handle.id, size, format, callback, io_surface.get()));
103 } 99 }
104 100
105 // static 101 // static
106 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(Format format) { 102 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(Format format) {
107 switch (format) { 103 switch (format) {
108 case BGRA_8888: 104 case BGRA_8888:
109 return true; 105 return true;
110 case RGBA_8888: 106 case RGBA_8888:
111 case RGBX_8888: 107 case RGBX_8888:
112 return false; 108 return false;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 mapped_ = false; 159 mapped_ = false;
164 } 160 }
165 161
166 uint32 GpuMemoryBufferImplIOSurface::GetStride() const { 162 uint32 GpuMemoryBufferImplIOSurface::GetStride() const {
167 return IOSurfaceGetBytesPerRow(io_surface_); 163 return IOSurfaceGetBytesPerRow(io_surface_);
168 } 164 }
169 165
170 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { 166 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const {
171 gfx::GpuMemoryBufferHandle handle; 167 gfx::GpuMemoryBufferHandle handle;
172 handle.type = gfx::IO_SURFACE_BUFFER; 168 handle.type = gfx::IO_SURFACE_BUFFER;
169 handle.id = id_;
173 handle.io_surface_id = IOSurfaceGetID(io_surface_); 170 handle.io_surface_id = IOSurfaceGetID(io_surface_);
174 return handle; 171 return handle;
175 } 172 }
176 173
177 } // namespace content 174 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698