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

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

Issue 701033005: content: Move type selection logic out of GpuMemoryBufferImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove blank line and add missing CONTENT_EXPORT 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.h" 5 #include "content/common/gpu/client/gpu_memory_buffer_impl.h"
6 6
7 #include "base/logging.h"
7 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" 8 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h"
8 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h" 9 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h"
9 10
10 namespace content { 11 namespace content {
11 12
12 // static 13 // static
13 void GpuMemoryBufferImpl::Create(gfx::GpuMemoryBufferId id, 14 void GpuMemoryBufferImpl::GetSupportedTypes(
15 std::vector<gfx::GpuMemoryBufferType>* types) {
16 const gfx::GpuMemoryBufferType supported_types[] = {
17 gfx::SURFACE_TEXTURE_BUFFER,
18 gfx::SHARED_MEMORY_BUFFER
19 };
20 types->assign(supported_types, supported_types + arraysize(supported_types));
21 }
22
23 // static
24 bool GpuMemoryBufferImpl::IsConfigurationSupported(
25 gfx::GpuMemoryBufferType type,
26 Format format,
27 Usage usage) {
28 switch (type) {
29 case gfx::SHARED_MEMORY_BUFFER:
30 return GpuMemoryBufferImplSharedMemory::IsFormatSupported(format) &&
31 GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage);
32 case gfx::SURFACE_TEXTURE_BUFFER:
33 return GpuMemoryBufferImplSurfaceTexture::IsFormatSupported(format) &&
34 GpuMemoryBufferImplSurfaceTexture::IsUsageSupported(usage);
piman 2014/11/11 22:38:30 So, there's a lot of duplication between all the p
reveman 2014/11/12 05:09:20 I agree that we need a factory here. I don't think
35 default:
36 NOTREACHED();
37 return false;
38 }
39 }
40
41 // static
42 void GpuMemoryBufferImpl::Create(gfx::GpuMemoryBufferType type,
43 gfx::GpuMemoryBufferId id,
14 const gfx::Size& size, 44 const gfx::Size& size,
15 Format format, 45 Format format,
16 Usage usage, 46 Usage usage,
17 int client_id, 47 int client_id,
18 const CreationCallback& callback) { 48 const CreationCallback& callback) {
19 if (GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported(format, 49 switch (type) {
20 usage)) { 50 case gfx::SHARED_MEMORY_BUFFER:
21 GpuMemoryBufferImplSurfaceTexture::Create( 51 GpuMemoryBufferImplSharedMemory::Create(id, size, format, callback);
22 id, size, format, client_id, callback); 52 break;
23 return; 53 case gfx::SURFACE_TEXTURE_BUFFER:
54 GpuMemoryBufferImplSurfaceTexture::Create(
55 id, size, format, client_id, callback);
56 break;
57 default:
58 NOTREACHED();
59 break;
24 } 60 }
25
26 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
27 size, format, usage)) {
28 GpuMemoryBufferImplSharedMemory::Create(id, size, format, callback);
29 return;
30 }
31
32 callback.Run(scoped_ptr<GpuMemoryBufferImpl>());
33 } 61 }
34 62
35 // static 63 // static
36 void GpuMemoryBufferImpl::AllocateForChildProcess( 64 void GpuMemoryBufferImpl::AllocateForChildProcess(
65 gfx::GpuMemoryBufferType type,
37 gfx::GpuMemoryBufferId id, 66 gfx::GpuMemoryBufferId id,
38 const gfx::Size& size, 67 const gfx::Size& size,
39 Format format, 68 Format format,
40 Usage usage, 69 Usage usage,
41 base::ProcessHandle child_process, 70 base::ProcessHandle child_process,
42 int child_client_id, 71 int child_client_id,
43 const AllocationCallback& callback) { 72 const AllocationCallback& callback) {
44 if (GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported(format, 73 switch (type) {
45 usage)) { 74 case gfx::SHARED_MEMORY_BUFFER:
46 GpuMemoryBufferImplSurfaceTexture::AllocateForChildProcess( 75 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess(
47 id, size, format, child_client_id, callback); 76 id, size, format, child_process, callback);
48 return; 77 break;
78 case gfx::SURFACE_TEXTURE_BUFFER:
79 GpuMemoryBufferImplSurfaceTexture::AllocateForChildProcess(
80 id, size, format, child_client_id, callback);
81 break;
82 default:
83 NOTREACHED();
84 break;
49 } 85 }
50
51 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
52 size, format, usage)) {
53 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess(
54 id, size, format, child_process, callback);
55 return;
56 }
57
58 callback.Run(gfx::GpuMemoryBufferHandle());
59 } 86 }
60 87
61 // static 88 // static
62 void GpuMemoryBufferImpl::DeletedByChildProcess( 89 void GpuMemoryBufferImpl::DeletedByChildProcess(
63 gfx::GpuMemoryBufferType type, 90 gfx::GpuMemoryBufferType type,
64 gfx::GpuMemoryBufferId id, 91 gfx::GpuMemoryBufferId id,
65 base::ProcessHandle child_process, 92 base::ProcessHandle child_process,
66 int child_client_id, 93 int child_client_id,
67 uint32 sync_point) { 94 uint32 sync_point) {
68 switch (type) { 95 switch (type) {
(...skipping 16 matching lines...) Expand all
85 Format format, 112 Format format,
86 const DestructionCallback& callback) { 113 const DestructionCallback& callback) {
87 switch (handle.type) { 114 switch (handle.type) {
88 case gfx::SHARED_MEMORY_BUFFER: 115 case gfx::SHARED_MEMORY_BUFFER:
89 return GpuMemoryBufferImplSharedMemory::CreateFromHandle( 116 return GpuMemoryBufferImplSharedMemory::CreateFromHandle(
90 handle, size, format, callback); 117 handle, size, format, callback);
91 case gfx::SURFACE_TEXTURE_BUFFER: 118 case gfx::SURFACE_TEXTURE_BUFFER:
92 return GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( 119 return GpuMemoryBufferImplSurfaceTexture::CreateFromHandle(
93 handle, size, format, callback); 120 handle, size, format, callback);
94 default: 121 default:
122 NOTREACHED();
95 return scoped_ptr<GpuMemoryBufferImpl>(); 123 return scoped_ptr<GpuMemoryBufferImpl>();
96 } 124 }
97 } 125 }
98 126
99 } // namespace content 127 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698