Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: ui/gl/gl_context_android.cc

Issue 14241033: Android GLNonOwnedContext support GLVirtualContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/sys_info.h" 9 #include "base/sys_info.h"
10 #include "ui/gl/gl_bindings.h" 10 #include "ui/gl/gl_bindings.h"
11 #include "ui/gl/gl_context_egl.h" 11 #include "ui/gl/gl_context_egl.h"
12 #include "ui/gl/gl_context_stub.h" 12 #include "ui/gl/gl_context_stub.h"
13 #include "ui/gl/gl_implementation.h" 13 #include "ui/gl/gl_implementation.h"
14 #include "ui/gl/gl_surface.h" 14 #include "ui/gl/gl_surface.h"
15 15
16 namespace gfx { 16 namespace gfx {
17 17
18 namespace { 18 namespace {
19 19
20 // Used to render into an already current context+surface, 20 // Used to render into an already current context+surface,
21 // that we do not have ownership of (draw callback). 21 // that we do not have ownership of (draw callback).
22 class GLNonOwnedContext : public GLContext { 22 class GLNonOwnedContext : public GLContext {
23 public: 23 public:
24 GLNonOwnedContext(); 24 GLNonOwnedContext(GLShareGroup* share_group);
25 25
26 // Implement GLContext. 26 // Implement GLContext.
27 virtual bool Initialize(GLSurface* compatible_surface, 27 virtual bool Initialize(GLSurface* compatible_surface,
28 GpuPreference gpu_preference) OVERRIDE { 28 GpuPreference gpu_preference) OVERRIDE {
29 return true; 29 return true;
30 } 30 }
31 virtual void Destroy() OVERRIDE {} 31 virtual void Destroy() OVERRIDE {}
32 virtual bool MakeCurrent(GLSurface* surface) OVERRIDE; 32 virtual bool MakeCurrent(GLSurface* surface) OVERRIDE;
33 virtual void ReleaseCurrent(GLSurface* surface) OVERRIDE {} 33 virtual void ReleaseCurrent(GLSurface* surface) OVERRIDE {}
34 virtual bool IsCurrent(GLSurface* surface) OVERRIDE { return true; } 34 virtual bool IsCurrent(GLSurface* surface) OVERRIDE { return true; }
35 virtual void* GetHandle() OVERRIDE { return NULL; } 35 virtual void* GetHandle() OVERRIDE { return NULL; }
36 virtual void SetSwapInterval(int interval) OVERRIDE {} 36 virtual void SetSwapInterval(int interval) OVERRIDE {}
37 virtual std::string GetExtensions() OVERRIDE; 37 virtual std::string GetExtensions() OVERRIDE;
38 38
39 protected: 39 protected:
40 virtual ~GLNonOwnedContext() {} 40 virtual ~GLNonOwnedContext() {}
41 41
42 private: 42 private:
43 DISALLOW_COPY_AND_ASSIGN(GLNonOwnedContext); 43 DISALLOW_COPY_AND_ASSIGN(GLNonOwnedContext);
44 }; 44 };
45 45
46 GLNonOwnedContext::GLNonOwnedContext() : GLContext(NULL) {} 46 GLNonOwnedContext::GLNonOwnedContext(GLShareGroup* share_group)
47 : GLContext(share_group) {}
47 48
48 bool GLNonOwnedContext::MakeCurrent(GLSurface* surface) { 49 bool GLNonOwnedContext::MakeCurrent(GLSurface* surface) {
49 SetCurrent(this, surface); 50 SetCurrent(this, surface);
50 SetRealGLApi(); 51 SetRealGLApi();
51 return true; 52 return true;
52 } 53 }
53 54
54 std::string GLNonOwnedContext::GetExtensions() { 55 std::string GLNonOwnedContext::GetExtensions() {
55 return GLContext::GetExtensions(); 56 return GLContext::GetExtensions();
56 } 57 }
57 58
58 } // anonymous namespace 59 } // anonymous namespace
59 60
60 // static 61 // static
61 scoped_refptr<GLContext> GLContext::CreateGLContext( 62 scoped_refptr<GLContext> GLContext::CreateGLContext(
62 GLShareGroup* share_group, 63 GLShareGroup* share_group,
63 GLSurface* compatible_surface, 64 GLSurface* compatible_surface,
64 GpuPreference gpu_preference) { 65 GpuPreference gpu_preference) {
65 if (GetGLImplementation() == kGLImplementationMockGL) 66 if (GetGLImplementation() == kGLImplementationMockGL)
66 return scoped_refptr<GLContext>(new GLContextStub()); 67 return scoped_refptr<GLContext>(new GLContextStub());
67 68
68 scoped_refptr<GLContext> context; 69 scoped_refptr<GLContext> context;
69 if (compatible_surface->GetHandle()) 70 if (compatible_surface->GetHandle())
70 context = new GLContextEGL(share_group); 71 context = new GLContextEGL(share_group);
71 else 72 else
72 context = new GLNonOwnedContext(); 73 context = new GLNonOwnedContext(share_group);
73 if (!context->Initialize(compatible_surface, gpu_preference)) 74 if (!context->Initialize(compatible_surface, gpu_preference))
74 return NULL; 75 return NULL;
75 return context; 76 return context;
76 } 77 }
77 78
78 bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) { 79 bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) {
79 DCHECK(bytes); 80 DCHECK(bytes);
80 *bytes = 0; 81 *bytes = 0;
81 // We can't query available GPU memory from the system on Android, 82 // We can't query available GPU memory from the system on Android,
82 // but the dalvik heap size give us a good estimate of available 83 // but the dalvik heap size give us a good estimate of available
(...skipping 22 matching lines...) Expand all
105 limit = heap_size / 2; 106 limit = heap_size / 2;
106 else 107 else
107 limit = (heap_size + (heap_growth * 2)) / 4; 108 limit = (heap_size + (heap_growth * 2)) / 4;
108 dalvik_limit = limit * 1024 * 1024; 109 dalvik_limit = limit * 1024 * 1024;
109 } 110 }
110 *bytes = dalvik_limit; 111 *bytes = dalvik_limit;
111 return true; 112 return true;
112 } 113 }
113 114
114 } 115 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698