Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / gpu / command_buffer / service / async_pixel_transfer_manager_android.cc
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.
4
5 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
6
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"
15
16 namespace gpu {
17 namespace {
18
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;
24 }
25
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;
31 }
32
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;
39 }
40
41 }
42
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;
68       }
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;
77   }
78 }
79
80 }  // namespace gpu