Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / gpu / command_buffer / service / async_pixel_transfer_manager_android.cc
blobba1ad2e41936d65636c4801e5a86c8bf8c9644ff
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
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
7 #include "base/debug/trace_event.h"
8 #include "base/sys_info.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"
11 #include "gpu/command_buffer/service/async_pixel_transfer_manager_stub.h"
12 #include "gpu/command_buffer/service/async_pixel_transfer_manager_sync.h"
13 #include "ui/gl/gl_context.h"
14 #include "ui/gl/gl_implementation.h"
16 namespace gpu {
17 namespace {
19 bool IsBroadcom() {
20 const char* vendor = reinterpret_cast<const char*>(glGetString(GL_VENDOR));
21 if (vendor)
22 return std::string(vendor).find("Broadcom") != std::string::npos;
23 return false;
26 bool IsImagination() {
27 const char* vendor = reinterpret_cast<const char*>(glGetString(GL_VENDOR));
28 if (vendor)
29 return std::string(vendor).find("Imagination") != std::string::npos;
30 return false;
33 bool IsNvidia31() {
34 const char* vendor = reinterpret_cast<const char*>(glGetString(GL_VENDOR));
35 const char* version = reinterpret_cast<const char*>(glGetString(GL_VERSION));
36 return vendor && version &&
37 std::string(vendor).find("NVIDIA") != std::string::npos &&
38 std::string(version).find("OpenGL ES 3.1") != std::string::npos;
43 // We only used threaded uploads when we can:
44 // - Create EGLImages out of OpenGL textures (EGL_KHR_gl_texture_2D_image)
45 // - Bind EGLImages to OpenGL textures (GL_OES_EGL_image)
46 // - Use fences (to test for upload completion).
47 // - The heap size is large enough.
48 // TODO(kaanb|epenner): Remove the IsImagination() check pending the
49 // resolution of crbug.com/249147
50 // TODO(kaanb|epenner): Remove the IsLowEndDevice() check pending the
51 // resolution of crbug.com/271929
52 AsyncPixelTransferManager* AsyncPixelTransferManager::Create(
53 gfx::GLContext* context) {
54 TRACE_EVENT0("gpu", "AsyncPixelTransferManager::Create");
55 switch (gfx::GetGLImplementation()) {
56 case gfx::kGLImplementationEGLGLES2:
57 DCHECK(context);
58 if (context->HasExtension("EGL_KHR_fence_sync") &&
59 context->HasExtension("EGL_KHR_image") &&
60 context->HasExtension("EGL_KHR_image_base") &&
61 context->HasExtension("EGL_KHR_gl_texture_2D_image") &&
62 context->HasExtension("GL_OES_EGL_image") &&
63 !IsBroadcom() &&
64 !IsImagination() &&
65 !IsNvidia31() &&
66 !base::SysInfo::IsLowEndDevice()) {
67 return new AsyncPixelTransferManagerEGL;
69 return new AsyncPixelTransferManagerIdle;
70 case gfx::kGLImplementationOSMesaGL:
71 return new AsyncPixelTransferManagerIdle;
72 case gfx::kGLImplementationMockGL:
73 return new AsyncPixelTransferManagerStub;
74 default:
75 NOTREACHED();
76 return NULL;
80 } // namespace gpu