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

Side by Side Diff: ui/gfx/gl/gl_context_egl.cc

Issue 7021014: GLContext no longer holds a pointer to a GLSurface. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/gfx/gl/gl_context_egl.h" 5 #include "ui/gfx/gl/gl_context_egl.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "third_party/angle/include/EGL/egl.h" 10 #include "third_party/angle/include/EGL/egl.h"
(...skipping 14 matching lines...) Expand all
25 25
26 std::string GLContextEGL::GetExtensions() { 26 std::string GLContextEGL::GetExtensions() {
27 const char* extensions = eglQueryString(GLSurfaceEGL::GetDisplay(), 27 const char* extensions = eglQueryString(GLSurfaceEGL::GetDisplay(),
28 EGL_EXTENSIONS); 28 EGL_EXTENSIONS);
29 if (!extensions) 29 if (!extensions)
30 return GLContext::GetExtensions(); 30 return GLContext::GetExtensions();
31 31
32 return GLContext::GetExtensions() + " " + extensions; 32 return GLContext::GetExtensions() + " " + extensions;
33 } 33 }
34 34
35 GLContextEGL::GLContextEGL(GLSurfaceEGL* surface) 35 GLContextEGL::GLContextEGL()
36 : surface_(surface), 36 : context_(NULL)
37 context_(NULL)
38 { 37 {
39 } 38 }
40 39
41 GLContextEGL::~GLContextEGL() { 40 GLContextEGL::~GLContextEGL() {
42 Destroy(); 41 Destroy();
43 } 42 }
44 43
45 bool GLContextEGL::Initialize(GLContext* shared_context) { 44 bool GLContextEGL::Initialize(GLContext* shared_context,
45 GLSurface* compatible_surface) {
46 DCHECK(compatible_surface);
46 DCHECK(!context_); 47 DCHECK(!context_);
47 48
48 static const EGLint kContextAttributes[] = { 49 static const EGLint kContextAttributes[] = {
49 EGL_CONTEXT_CLIENT_VERSION, 2, 50 EGL_CONTEXT_CLIENT_VERSION, 2,
50 EGL_NONE 51 EGL_NONE
51 }; 52 };
52 53
53 context_ = eglCreateContext( 54 context_ = eglCreateContext(
54 GLSurfaceEGL::GetDisplay(), 55 GLSurfaceEGL::GetDisplay(),
55 GLSurfaceEGL::GetConfig(), 56 GLSurfaceEGL::GetConfig(),
56 shared_context ? shared_context->GetHandle() : NULL, 57 shared_context ? shared_context->GetHandle() : NULL,
57 kContextAttributes); 58 kContextAttributes);
58 if (!context_) { 59 if (!context_) {
59 LOG(ERROR) << "eglCreateContext failed with error " 60 LOG(ERROR) << "eglCreateContext failed with error "
60 << GetLastEGLErrorString(); 61 << GetLastEGLErrorString();
61 Destroy(); 62 Destroy();
62 return false; 63 return false;
63 } 64 }
64 65
65 if (!MakeCurrent()) {
66 LOG(ERROR) << "MakeCurrent failed.";
67 Destroy();
68 return false;
69 }
70
71 if (!InitializeCommon()) {
72 LOG(ERROR) << "GLContext::InitializeCommon failed.";
73 Destroy();
74 return false;
75 }
76
77 return true; 66 return true;
78 } 67 }
79 68
80 void GLContextEGL::Destroy() { 69 void GLContextEGL::Destroy() {
81 if (context_) { 70 if (context_) {
82 if (!eglDestroyContext(GLSurfaceEGL::GetDisplay(), context_)) { 71 if (!eglDestroyContext(GLSurfaceEGL::GetDisplay(), context_)) {
83 LOG(ERROR) << "eglDestroyContext failed with error " 72 LOG(ERROR) << "eglDestroyContext failed with error "
84 << GetLastEGLErrorString(); 73 << GetLastEGLErrorString();
85 } 74 }
86 75
87 context_ = NULL; 76 context_ = NULL;
88 } 77 }
89
90 if (surface_.get()) {
91 surface_->Destroy();
92 surface_.reset();
93 }
94 } 78 }
95 79
96 bool GLContextEGL::MakeCurrent() { 80 bool GLContextEGL::MakeCurrent(GLSurface* surface) {
97 DCHECK(context_); 81 DCHECK(context_);
98 if (IsCurrent()) 82 if (IsCurrent(surface))
99 return true; 83 return true;
100 84
101 if (!eglMakeCurrent(GLSurfaceEGL::GetDisplay(), 85 if (!eglMakeCurrent(GLSurfaceEGL::GetDisplay(),
102 surface_->GetHandle(), 86 surface->GetHandle(),
103 surface_->GetHandle(), 87 surface->GetHandle(),
104 context_)) { 88 context_)) {
105 VLOG(1) << "eglMakeCurrent failed with error " 89 VLOG(1) << "eglMakeCurrent failed with error "
106 << GetLastEGLErrorString(); 90 << GetLastEGLErrorString();
107 return false; 91 return false;
108 } 92 }
109 93
110 return true; 94 return true;
111 } 95 }
112 96
113 void GLContextEGL::ReleaseCurrent() { 97 void GLContextEGL::ReleaseCurrent(GLSurface* surface) {
114 if (!IsCurrent()) 98 if (!IsCurrent(surface))
115 return; 99 return;
116 100
117 eglMakeCurrent(GLSurfaceEGL::GetDisplay(), 101 eglMakeCurrent(GLSurfaceEGL::GetDisplay(),
118 EGL_NO_SURFACE, 102 EGL_NO_SURFACE,
119 EGL_NO_SURFACE, 103 EGL_NO_SURFACE,
120 EGL_NO_CONTEXT); 104 EGL_NO_CONTEXT);
121 } 105 }
122 106
123 bool GLContextEGL::IsCurrent() { 107 bool GLContextEGL::IsCurrent(GLSurface* surface) {
124 DCHECK(context_); 108 DCHECK(context_);
125 return context_ == eglGetCurrentContext() && 109 if (context_ != eglGetCurrentContext())
126 surface_->GetHandle() == eglGetCurrentSurface(EGL_DRAW); 110 return false;
127 }
128 111
129 bool GLContextEGL::IsOffscreen() { 112 if (surface) {
130 // TODO(apatrick): remove this from GLContext interface. 113 if (surface->GetHandle() != eglGetCurrentSurface(EGL_DRAW))
131 return surface_->IsOffscreen(); 114 return false;
132 } 115 }
133 116
134 bool GLContextEGL::SwapBuffers() { 117 return true;
135 // TODO(apatrick): remove this from GLContext interface.
136 return surface_->SwapBuffers();
137 }
138
139 gfx::Size GLContextEGL::GetSize() {
140 // TODO(apatrick): remove this from GLContext interface.
141 return surface_->GetSize();
142 }
143
144 GLSurface* GLContextEGL::GetSurface() {
145 // TODO(apatrick): remove this from GLContext interface.
146 return surface_.get();
147 } 118 }
148 119
149 void* GLContextEGL::GetHandle() { 120 void* GLContextEGL::GetHandle() {
150 return context_; 121 return context_;
151 } 122 }
152 123
153 void GLContextEGL::SetSwapInterval(int interval) { 124 void GLContextEGL::SetSwapInterval(int interval) {
154 DCHECK(IsCurrent()); 125 DCHECK(IsCurrent(NULL));
155 if (!eglSwapInterval(GLSurfaceEGL::GetDisplay(), interval)) { 126 if (!eglSwapInterval(GLSurfaceEGL::GetDisplay(), interval)) {
156 LOG(ERROR) << "eglSwapInterval failed with error " 127 LOG(ERROR) << "eglSwapInterval failed with error "
157 << GetLastEGLErrorString(); 128 << GetLastEGLErrorString();
158 } 129 }
159 } 130 }
160 131
161 } // namespace gfx 132 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698