OLD | NEW |
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 "ui/gl/gl_context.h" | 5 #include "ui/gl/gl_context.h" |
6 | 6 |
7 #include "base/android/sys_utils.h" | 7 #include "base/android/sys_utils.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
11 #include "ui/gl/gl_bindings.h" | 11 #include "ui/gl/gl_bindings.h" |
12 #include "ui/gl/gl_context_egl.h" | 12 #include "ui/gl/gl_context_egl.h" |
13 #include "ui/gl/gl_context_stub.h" | 13 #include "ui/gl/gl_context_stub.h" |
14 #include "ui/gl/gl_implementation.h" | 14 #include "ui/gl/gl_implementation.h" |
15 #include "ui/gl/gl_surface.h" | 15 #include "ui/gl/gl_surface.h" |
16 | 16 |
17 namespace gfx { | 17 namespace gfx { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // Used to render into an already current context+surface, | 21 // Used to render into an already current context+surface, |
22 // that we do not have ownership of (draw callback). | 22 // that we do not have ownership of (draw callback). |
| 23 // TODO(boliu): Make this inherit from GLContextEGL. |
23 class GLNonOwnedContext : public GLContextReal { | 24 class GLNonOwnedContext : public GLContextReal { |
24 public: | 25 public: |
25 GLNonOwnedContext(GLShareGroup* share_group); | 26 GLNonOwnedContext(GLShareGroup* share_group); |
26 | 27 |
27 // Implement GLContext. | 28 // Implement GLContext. |
28 virtual bool Initialize(GLSurface* compatible_surface, | 29 virtual bool Initialize(GLSurface* compatible_surface, |
29 GpuPreference gpu_preference) OVERRIDE { | 30 GpuPreference gpu_preference) OVERRIDE; |
30 return true; | |
31 } | |
32 virtual void Destroy() OVERRIDE {} | 31 virtual void Destroy() OVERRIDE {} |
33 virtual bool MakeCurrent(GLSurface* surface) OVERRIDE; | 32 virtual bool MakeCurrent(GLSurface* surface) OVERRIDE; |
34 virtual void ReleaseCurrent(GLSurface* surface) OVERRIDE {} | 33 virtual void ReleaseCurrent(GLSurface* surface) OVERRIDE {} |
35 virtual bool IsCurrent(GLSurface* surface) OVERRIDE { return true; } | 34 virtual bool IsCurrent(GLSurface* surface) OVERRIDE { return true; } |
36 virtual void* GetHandle() OVERRIDE { return NULL; } | 35 virtual void* GetHandle() OVERRIDE { return NULL; } |
37 virtual void SetSwapInterval(int interval) OVERRIDE {} | 36 virtual void SetSwapInterval(int interval) OVERRIDE {} |
38 virtual std::string GetExtensions() OVERRIDE; | 37 virtual std::string GetExtensions() OVERRIDE; |
39 | 38 |
40 protected: | 39 protected: |
41 virtual ~GLNonOwnedContext() {} | 40 virtual ~GLNonOwnedContext() {} |
42 | 41 |
43 private: | 42 private: |
44 DISALLOW_COPY_AND_ASSIGN(GLNonOwnedContext); | 43 DISALLOW_COPY_AND_ASSIGN(GLNonOwnedContext); |
| 44 |
| 45 EGLDisplay display_; |
45 }; | 46 }; |
46 | 47 |
47 GLNonOwnedContext::GLNonOwnedContext(GLShareGroup* share_group) | 48 GLNonOwnedContext::GLNonOwnedContext(GLShareGroup* share_group) |
48 : GLContextReal(share_group) {} | 49 : GLContextReal(share_group), display_(NULL) {} |
| 50 |
| 51 bool GLNonOwnedContext::Initialize(GLSurface* compatible_surface, |
| 52 GpuPreference gpu_preference) { |
| 53 display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 54 return true; |
| 55 } |
49 | 56 |
50 bool GLNonOwnedContext::MakeCurrent(GLSurface* surface) { | 57 bool GLNonOwnedContext::MakeCurrent(GLSurface* surface) { |
51 SetCurrent(surface); | 58 SetCurrent(surface); |
52 SetRealGLApi(); | 59 SetRealGLApi(); |
53 return true; | 60 return true; |
54 } | 61 } |
55 | 62 |
56 std::string GLNonOwnedContext::GetExtensions() { | 63 std::string GLNonOwnedContext::GetExtensions() { |
57 return GLContext::GetExtensions(); | 64 const char* extensions = eglQueryString(display_, EGL_EXTENSIONS); |
| 65 if (!extensions) |
| 66 return GLContext::GetExtensions(); |
| 67 |
| 68 return GLContext::GetExtensions() + " " + extensions; |
58 } | 69 } |
59 | 70 |
60 } // anonymous namespace | 71 } // anonymous namespace |
61 | 72 |
62 // static | 73 // static |
63 scoped_refptr<GLContext> GLContext::CreateGLContext( | 74 scoped_refptr<GLContext> GLContext::CreateGLContext( |
64 GLShareGroup* share_group, | 75 GLShareGroup* share_group, |
65 GLSurface* compatible_surface, | 76 GLSurface* compatible_surface, |
66 GpuPreference gpu_preference) { | 77 GpuPreference gpu_preference) { |
67 if (GetGLImplementation() == kGLImplementationMockGL) | 78 if (GetGLImplementation() == kGLImplementationMockGL) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 } else { | 127 } else { |
117 limit_bytes = physical_memory_mb / 32; | 128 limit_bytes = physical_memory_mb / 32; |
118 } | 129 } |
119 limit_bytes = limit_bytes * 1024 * 1024; | 130 limit_bytes = limit_bytes * 1024 * 1024; |
120 } | 131 } |
121 *bytes = limit_bytes; | 132 *bytes = limit_bytes; |
122 return true; | 133 return true; |
123 } | 134 } |
124 | 135 |
125 } | 136 } |
OLD | NEW |