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

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

Issue 2037793002: Move GLContext creation from //ui/gl to //ui/gl/init. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gl_init
Patch Set: Change to scoped_refptr. Created 4 years, 6 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
« no previous file with comments | « ui/gl/gl_context.cc ('k') | ui/gl/gl_context_cgl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/gl/gl_context.h"
6
7 #include "base/logging.h"
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/sys_info.h"
11 #include "ui/gl/gl_bindings.h"
12 #include "ui/gl/gl_context_egl.h"
13 #include "ui/gl/gl_context_osmesa.h"
14 #include "ui/gl/gl_context_stub.h"
15 #include "ui/gl/gl_implementation.h"
16 #include "ui/gl/gl_surface.h"
17
18 namespace gl {
19
20 namespace {
21
22 // Used to render into an already current context+surface,
23 // that we do not have ownership of (draw callback).
24 // TODO(boliu): Make this inherit from GLContextEGL.
25 class GLNonOwnedContext : public GLContextReal {
26 public:
27 GLNonOwnedContext(GLShareGroup* share_group);
28
29 // Implement GLContext.
30 bool Initialize(GLSurface* compatible_surface,
31 GpuPreference gpu_preference) override;
32 bool MakeCurrent(GLSurface* surface) override;
33 void ReleaseCurrent(GLSurface* surface) override {}
34 bool IsCurrent(GLSurface* surface) override { return true; }
35 void* GetHandle() override { return nullptr; }
36 void OnSetSwapInterval(int interval) override {}
37 std::string GetExtensions() override;
38
39 protected:
40 ~GLNonOwnedContext() override {}
41
42 private:
43 EGLDisplay display_;
44
45 DISALLOW_COPY_AND_ASSIGN(GLNonOwnedContext);
46 };
47
48 GLNonOwnedContext::GLNonOwnedContext(GLShareGroup* share_group)
49 : GLContextReal(share_group), display_(nullptr) {}
50
51 bool GLNonOwnedContext::Initialize(GLSurface* compatible_surface,
52 GpuPreference gpu_preference) {
53 display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
54 return true;
55 }
56
57 bool GLNonOwnedContext::MakeCurrent(GLSurface* surface) {
58 SetCurrent(surface);
59 SetRealGLApi();
60 return true;
61 }
62
63 std::string GLNonOwnedContext::GetExtensions() {
64 const char* extensions = eglQueryString(display_, EGL_EXTENSIONS);
65 if (!extensions)
66 return GLContext::GetExtensions();
67
68 return GLContext::GetExtensions() + " " + extensions;
69 }
70
71 } // anonymous namespace
72
73 // static
74 scoped_refptr<GLContext> GLContext::CreateGLContext(
75 GLShareGroup* share_group,
76 GLSurface* compatible_surface,
77 GpuPreference gpu_preference) {
78 scoped_refptr<GLContext> context;
79 switch (GetGLImplementation()) {
80 case kGLImplementationMockGL:
81 return scoped_refptr<GLContext>(new GLContextStub(share_group));
82 case kGLImplementationOSMesaGL:
83 context = new GLContextOSMesa(share_group);
84 break;
85 default:
86 if (compatible_surface->GetHandle())
87 context = new GLContextEGL(share_group);
88 else
89 context = new GLNonOwnedContext(share_group);
90 break;
91 }
92
93 if (!context->Initialize(compatible_surface, gpu_preference))
94 return nullptr;
95
96 return context;
97 }
98
99 }
OLDNEW
« no previous file with comments | « ui/gl/gl_context.cc ('k') | ui/gl/gl_context_cgl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698