57951063d8619bb1cf963f45b26fb620eeb0fcfb
[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/android/sys_utils.h"
8 #include "base/debug/trace_event.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 }
34
35 // We only used threaded uploads when we can:
36 // - Create EGLImages out of OpenGL textures (EGL_KHR_gl_texture_2D_image)
37 // - Bind EGLImages to OpenGL textures (GL_OES_EGL_image)
38 // - Use fences (to test for upload completion).
39 // - The heap size is large enough.
40 // TODO(kaanb|epenner): Remove the IsImagination() check pending the
41 // resolution of crbug.com/249147
42 // TODO(kaanb|epenner): Remove the IsLowEndDevice() check pending the
43 // resolution of crbug.com/271929
44 AsyncPixelTransferManager* AsyncPixelTransferManager::Create(
45     gfx::GLContext* context) {
46   TRACE_EVENT0("gpu", "AsyncPixelTransferManager::Create");
47   switch (gfx::GetGLImplementation()) {
48     case gfx::kGLImplementationEGLGLES2:
49       DCHECK(context);
50       if (context->HasExtension("EGL_KHR_fence_sync") &&
51           context->HasExtension("EGL_KHR_image") &&
52           context->HasExtension("EGL_KHR_image_base") &&
53           context->HasExtension("EGL_KHR_gl_texture_2D_image") &&
54           context->HasExtension("GL_OES_EGL_image") &&
55           !IsBroadcom() &&
56           !IsImagination() &&
57           !base::android::SysUtils::IsLowEndDevice()) {
58         return new AsyncPixelTransferManagerEGL;
59       }
60       return new AsyncPixelTransferManagerIdle;
61     case gfx::kGLImplementationOSMesaGL:
62       return new AsyncPixelTransferManagerIdle;
63     case gfx::kGLImplementationMockGL:
64       return new AsyncPixelTransferManagerStub;
65     default:
66       NOTREACHED();
67       return NULL;
68   }
69 }
70
71 }  // namespace gpu