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

Side by Side Diff: content/browser/gpu/browser_gpu_channel_host_factory.cc

Issue 1139903005: Add PERSISTENT_MAP usage for GpuMemoryBuffers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: persistentmap: rebase Created 5 years, 6 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/gpu/browser_gpu_channel_host_factory.h" 5 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/profiler/scoped_tracker.h" 10 #include "base/profiler/scoped_tracker.h"
(...skipping 25 matching lines...) Expand all
36 36
37 #if defined(USE_OZONE) 37 #if defined(USE_OZONE)
38 #include "content/common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" 38 #include "content/common/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h"
39 #endif 39 #endif
40 40
41 namespace content { 41 namespace content {
42 namespace { 42 namespace {
43 43
44 base::LazyInstance<std::set<gfx::GpuMemoryBuffer::Usage>> 44 base::LazyInstance<std::set<gfx::GpuMemoryBuffer::Usage>>
45 g_enabled_gpu_memory_buffer_usages; 45 g_enabled_gpu_memory_buffer_usages;
46
47 bool IsGpuMemoryBufferFactoryConfigurationSupported(
48 gfx::GpuMemoryBuffer::Format format,
49 gfx::GpuMemoryBuffer::Usage usage,
50 gfx::GpuMemoryBufferType type) {
51 switch (type) {
52 case gfx::SHARED_MEMORY_BUFFER:
53 // Shared memory buffers must be created in-process.
54 return false;
55 #if defined(OS_MACOSX)
56 case gfx::IO_SURFACE_BUFFER:
57 return GpuMemoryBufferFactoryIOSurface::
58 IsGpuMemoryBufferConfigurationSupported(format, usage);
59 #endif
60 #if defined(OS_ANDROID)
61 case gfx::SURFACE_TEXTURE_BUFFER:
62 return GpuMemoryBufferFactorySurfaceTexture::
63 IsGpuMemoryBufferConfigurationSupported(format, usage);
64 #endif
65 #if defined(USE_OZONE)
66 case gfx::OZONE_NATIVE_BUFFER:
67 return GpuMemoryBufferFactoryOzoneNativeBuffer::
68 IsGpuMemoryBufferConfigurationSupported(format, usage);
69 #endif
70 default:
71 NOTREACHED();
72 return false;
73 }
46 } 74 }
47 75
76 } // namespace
77
48 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; 78 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL;
49 79
50 struct BrowserGpuChannelHostFactory::CreateRequest { 80 struct BrowserGpuChannelHostFactory::CreateRequest {
51 CreateRequest(int32 route_id) 81 CreateRequest(int32 route_id)
52 : event(true, false), 82 : event(true, false),
53 gpu_host_id(0), 83 gpu_host_id(0),
54 route_id(route_id), 84 route_id(route_id),
55 result(CREATE_COMMAND_BUFFER_FAILED) {} 85 result(CREATE_COMMAND_BUFFER_FAILED) {}
56 ~CreateRequest() {} 86 ~CreateRequest() {}
57 base::WaitableEvent event; 87 base::WaitableEvent event;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 g_enabled_gpu_memory_buffer_usages.Get().insert(usage); 277 g_enabled_gpu_memory_buffer_usages.Get().insert(usage);
248 } 278 }
249 279
250 // static 280 // static
251 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferFactoryUsageEnabled( 281 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferFactoryUsageEnabled(
252 gfx::GpuMemoryBuffer::Usage usage) { 282 gfx::GpuMemoryBuffer::Usage usage) {
253 return g_enabled_gpu_memory_buffer_usages.Get().count(usage) != 0; 283 return g_enabled_gpu_memory_buffer_usages.Get().count(usage) != 0;
254 } 284 }
255 285
256 // static 286 // static
257 uint32 BrowserGpuChannelHostFactory::GetImageTextureTarget() { 287 uint32 BrowserGpuChannelHostFactory::GetImageTextureTarget(
258 if (!IsGpuMemoryBufferFactoryUsageEnabled(gfx::GpuMemoryBuffer::MAP)) 288 gfx::GpuMemoryBuffer::Format format,
289 gfx::GpuMemoryBuffer::Usage usage) {
290 if (!IsGpuMemoryBufferFactoryUsageEnabled(usage))
259 return GL_TEXTURE_2D; 291 return GL_TEXTURE_2D;
260 292
261 std::vector<gfx::GpuMemoryBufferType> supported_types; 293 std::vector<gfx::GpuMemoryBufferType> supported_types;
262 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); 294 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types);
263 DCHECK(!supported_types.empty()); 295 DCHECK(!supported_types.empty());
264 296
265 // The GPU service will always use the preferred type. 297 // The GPU service will always use the preferred type, if the |format| and
298 // |usage| allows.
266 gfx::GpuMemoryBufferType type = supported_types[0]; 299 gfx::GpuMemoryBufferType type = supported_types[0];
267 300
301 if (!IsGpuMemoryBufferFactoryConfigurationSupported(format, usage, type))
302 return GL_TEXTURE_2D;
303
268 switch (type) { 304 switch (type) {
269 case gfx::SURFACE_TEXTURE_BUFFER: 305 case gfx::SURFACE_TEXTURE_BUFFER:
270 case gfx::OZONE_NATIVE_BUFFER: 306 case gfx::OZONE_NATIVE_BUFFER:
271 // GPU memory buffers that are shared with the GL using EGLImages require 307 // GPU memory buffers that are shared with the GL using EGLImages require
272 // TEXTURE_EXTERNAL_OES. 308 // TEXTURE_EXTERNAL_OES.
273 return GL_TEXTURE_EXTERNAL_OES; 309 return GL_TEXTURE_EXTERNAL_OES;
274 case gfx::IO_SURFACE_BUFFER: 310 case gfx::IO_SURFACE_BUFFER:
275 // IOSurface backed images require GL_TEXTURE_RECTANGLE_ARB. 311 // IOSurface backed images require GL_TEXTURE_RECTANGLE_ARB.
276 return GL_TEXTURE_RECTANGLE_ARB; 312 return GL_TEXTURE_RECTANGLE_ARB;
277 default: 313 default:
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 host->AddFilter(filter.get()); 500 host->AddFilter(filter.get());
465 } 501 }
466 502
467 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferConfigurationSupported( 503 bool BrowserGpuChannelHostFactory::IsGpuMemoryBufferConfigurationSupported(
468 gfx::GpuMemoryBuffer::Format format, 504 gfx::GpuMemoryBuffer::Format format,
469 gfx::GpuMemoryBuffer::Usage usage) { 505 gfx::GpuMemoryBuffer::Usage usage) {
470 // Return early if usage is not enabled. 506 // Return early if usage is not enabled.
471 if (!IsGpuMemoryBufferFactoryUsageEnabled(usage)) 507 if (!IsGpuMemoryBufferFactoryUsageEnabled(usage))
472 return false; 508 return false;
473 509
474 // Preferred type is always used by factory.
475 std::vector<gfx::GpuMemoryBufferType> supported_types; 510 std::vector<gfx::GpuMemoryBufferType> supported_types;
476 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); 511 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types);
477 DCHECK(!supported_types.empty()); 512 DCHECK(!supported_types.empty());
478 switch (supported_types[0]) { 513
479 case gfx::SHARED_MEMORY_BUFFER: 514 // The GPU service will always use the preferred type, if the |format| and
480 // Shared memory buffers must be created in-process. 515 // |usage| allows.
481 return false; 516 gfx::GpuMemoryBufferType type = supported_types[0];
482 #if defined(OS_MACOSX) 517
483 case gfx::IO_SURFACE_BUFFER: 518 return IsGpuMemoryBufferFactoryConfigurationSupported(format, usage, type);
484 return GpuMemoryBufferFactoryIOSurface::
485 IsGpuMemoryBufferConfigurationSupported(format, usage);
486 #endif
487 #if defined(OS_ANDROID)
488 case gfx::SURFACE_TEXTURE_BUFFER:
489 return GpuMemoryBufferFactorySurfaceTexture::
490 IsGpuMemoryBufferConfigurationSupported(format, usage);
491 #endif
492 #if defined(USE_OZONE)
493 case gfx::OZONE_NATIVE_BUFFER:
494 return GpuMemoryBufferFactoryOzoneNativeBuffer::
495 IsGpuMemoryBufferConfigurationSupported(format, usage);
496 #endif
497 default:
498 NOTREACHED();
499 return false;
500 }
501 } 519 }
502 520
503 void BrowserGpuChannelHostFactory::CreateGpuMemoryBuffer( 521 void BrowserGpuChannelHostFactory::CreateGpuMemoryBuffer(
504 gfx::GpuMemoryBufferId id, 522 gfx::GpuMemoryBufferId id,
505 const gfx::Size& size, 523 const gfx::Size& size,
506 gfx::GpuMemoryBuffer::Format format, 524 gfx::GpuMemoryBuffer::Format format,
507 gfx::GpuMemoryBuffer::Usage usage, 525 gfx::GpuMemoryBuffer::Usage usage,
508 int client_id, 526 int client_id,
509 int32 surface_id, 527 int32 surface_id,
510 const CreateGpuMemoryBufferCallback& callback) { 528 const CreateGpuMemoryBufferCallback& callback) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 DCHECK_CURRENTLY_ON(BrowserThread::IO); 576 DCHECK_CURRENTLY_ON(BrowserThread::IO);
559 577
560 CreateGpuMemoryBufferCallbackMap::iterator iter = 578 CreateGpuMemoryBufferCallbackMap::iterator iter =
561 create_gpu_memory_buffer_requests_.find(request_id); 579 create_gpu_memory_buffer_requests_.find(request_id);
562 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); 580 DCHECK(iter != create_gpu_memory_buffer_requests_.end());
563 iter->second.Run(handle); 581 iter->second.Run(handle);
564 create_gpu_memory_buffer_requests_.erase(iter); 582 create_gpu_memory_buffer_requests_.erase(iter);
565 } 583 }
566 584
567 } // namespace content 585 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gpu/browser_gpu_channel_host_factory.h ('k') | content/browser/gpu/browser_gpu_memory_buffer_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698