OLD | NEW |
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 "gpu/command_buffer/service/async_pixel_transfer_manager.h" | 5 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/sys_info.h" | 8 #include "base/sys_info.h" |
9 #include "gpu/command_buffer/service/async_pixel_transfer_manager_egl.h" | 9 #include "gpu/command_buffer/service/async_pixel_transfer_manager_egl.h" |
10 #include "gpu/command_buffer/service/async_pixel_transfer_manager_idle.h" | 10 #include "gpu/command_buffer/service/async_pixel_transfer_manager_idle.h" |
11 #include "gpu/command_buffer/service/async_pixel_transfer_manager_stub.h" | 11 #include "gpu/command_buffer/service/async_pixel_transfer_manager_stub.h" |
12 #include "gpu/command_buffer/service/async_pixel_transfer_manager_sync.h" | 12 #include "gpu/command_buffer/service/async_pixel_transfer_manager_sync.h" |
13 #include "ui/gl/gl_context.h" | 13 #include "ui/gl/gl_context.h" |
14 #include "ui/gl/gl_implementation.h" | 14 #include "ui/gl/gl_implementation.h" |
15 | 15 |
16 namespace gpu { | 16 namespace gpu { |
17 namespace { | 17 namespace { |
18 | 18 |
19 bool IsBroadcom() { | 19 enum GpuType { |
20 const char* vendor = reinterpret_cast<const char*>(glGetString(GL_VENDOR)); | 20 GPU_BROADCOM, |
21 if (vendor) | 21 GPU_IMAGINATION, |
22 return std::string(vendor).find("Broadcom") != std::string::npos; | 22 GPU_NVIDIA_ES31, |
23 return false; | 23 GPU_ADRENO_420, |
| 24 GPU_OTHER, |
| 25 }; |
| 26 |
| 27 std::string MakeString(const char* s) { |
| 28 return std::string(s ? s : ""); |
24 } | 29 } |
25 | 30 |
26 bool IsImagination() { | 31 GpuType GetGpuType() { |
27 const char* vendor = reinterpret_cast<const char*>(glGetString(GL_VENDOR)); | 32 const std::string vendor = MakeString( |
28 if (vendor) | 33 reinterpret_cast<const char*>(glGetString(GL_VENDOR))); |
29 return std::string(vendor).find("Imagination") != std::string::npos; | 34 const std::string renderer = MakeString( |
30 return false; | 35 reinterpret_cast<const char*>(glGetString(GL_RENDERER))); |
| 36 const std::string version = MakeString( |
| 37 reinterpret_cast<const char*>(glGetString(GL_VERSION))); |
| 38 |
| 39 if (vendor.find("Broadcom") != std::string::npos) |
| 40 return GPU_BROADCOM; |
| 41 |
| 42 if (vendor.find("Imagination") != std::string::npos) |
| 43 return GPU_IMAGINATION; |
| 44 |
| 45 if (vendor.find("NVIDIA") != std::string::npos && |
| 46 version.find("OpenGL ES 3.1") != std::string::npos) { |
| 47 return GPU_NVIDIA_ES31; |
| 48 } |
| 49 |
| 50 if (vendor.find("Qualcomm") != std::string::npos && |
| 51 renderer.find("Adreno (TM) 420") != std::string::npos) { |
| 52 return GPU_ADRENO_420; |
| 53 } |
| 54 |
| 55 return GPU_OTHER; |
31 } | 56 } |
32 | 57 |
33 bool IsNvidia31() { | 58 bool AllowTransferThreadForGpu() { |
34 const char* vendor = reinterpret_cast<const char*>(glGetString(GL_VENDOR)); | 59 GpuType gpu = GetGpuType(); |
35 const char* version = reinterpret_cast<const char*>(glGetString(GL_VERSION)); | 60 return gpu != GPU_BROADCOM && gpu != GPU_IMAGINATION && |
36 return vendor && version && | 61 gpu != GPU_NVIDIA_ES31 && gpu != GPU_ADRENO_420; |
37 std::string(vendor).find("NVIDIA") != std::string::npos && | |
38 std::string(version).find("OpenGL ES 3.1") != std::string::npos; | |
39 } | 62 } |
40 | 63 |
41 } | 64 } |
42 | 65 |
43 // We only used threaded uploads when we can: | 66 // We only used threaded uploads when we can: |
44 // - Create EGLImages out of OpenGL textures (EGL_KHR_gl_texture_2D_image) | 67 // - Create EGLImages out of OpenGL textures (EGL_KHR_gl_texture_2D_image) |
45 // - Bind EGLImages to OpenGL textures (GL_OES_EGL_image) | 68 // - Bind EGLImages to OpenGL textures (GL_OES_EGL_image) |
46 // - Use fences (to test for upload completion). | 69 // - Use fences (to test for upload completion). |
47 // - The heap size is large enough. | 70 // - The heap size is large enough. |
48 // TODO(kaanb|epenner): Remove the IsImagination() check pending the | 71 // TODO(kaanb|epenner): Remove the IsImagination() check pending the |
49 // resolution of crbug.com/249147 | 72 // resolution of crbug.com/249147 |
50 // TODO(kaanb|epenner): Remove the IsLowEndDevice() check pending the | 73 // TODO(kaanb|epenner): Remove the IsLowEndDevice() check pending the |
51 // resolution of crbug.com/271929 | 74 // resolution of crbug.com/271929 |
52 AsyncPixelTransferManager* AsyncPixelTransferManager::Create( | 75 AsyncPixelTransferManager* AsyncPixelTransferManager::Create( |
53 gfx::GLContext* context) { | 76 gfx::GLContext* context) { |
54 TRACE_EVENT0("gpu", "AsyncPixelTransferManager::Create"); | 77 DCHECK(context->IsCurrent(NULL)); |
55 switch (gfx::GetGLImplementation()) { | 78 switch (gfx::GetGLImplementation()) { |
56 case gfx::kGLImplementationEGLGLES2: | 79 case gfx::kGLImplementationEGLGLES2: |
57 DCHECK(context); | 80 DCHECK(context); |
58 if (context->HasExtension("EGL_KHR_fence_sync") && | 81 if (!base::SysInfo::IsLowEndDevice() && |
| 82 context->HasExtension("EGL_KHR_fence_sync") && |
59 context->HasExtension("EGL_KHR_image") && | 83 context->HasExtension("EGL_KHR_image") && |
60 context->HasExtension("EGL_KHR_image_base") && | 84 context->HasExtension("EGL_KHR_image_base") && |
61 context->HasExtension("EGL_KHR_gl_texture_2D_image") && | 85 context->HasExtension("EGL_KHR_gl_texture_2D_image") && |
62 context->HasExtension("GL_OES_EGL_image") && | 86 context->HasExtension("GL_OES_EGL_image") && |
63 !IsBroadcom() && | 87 AllowTransferThreadForGpu()) { |
64 !IsImagination() && | 88 TRACE_EVENT0("gpu", "AsyncPixelTransferManager_CreateWithThread"); |
65 !IsNvidia31() && | |
66 !base::SysInfo::IsLowEndDevice()) { | |
67 return new AsyncPixelTransferManagerEGL; | 89 return new AsyncPixelTransferManagerEGL; |
68 } | 90 } |
69 return new AsyncPixelTransferManagerIdle; | 91 return new AsyncPixelTransferManagerIdle; |
70 case gfx::kGLImplementationOSMesaGL: | 92 case gfx::kGLImplementationOSMesaGL: { |
| 93 TRACE_EVENT0("gpu", "AsyncPixelTransferManager_CreateIdle"); |
71 return new AsyncPixelTransferManagerIdle; | 94 return new AsyncPixelTransferManagerIdle; |
| 95 } |
72 case gfx::kGLImplementationMockGL: | 96 case gfx::kGLImplementationMockGL: |
73 return new AsyncPixelTransferManagerStub; | 97 return new AsyncPixelTransferManagerStub; |
74 default: | 98 default: |
75 NOTREACHED(); | 99 NOTREACHED(); |
76 return NULL; | 100 return NULL; |
77 } | 101 } |
78 } | 102 } |
79 | 103 |
80 } // namespace gpu | 104 } // namespace gpu |
OLD | NEW |