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

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

Issue 15928002: GPU: Keep track of the last real context and real surface made current. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nix unnecessary changes. Created 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/gl/gl_context_osmesa.h ('k') | ui/gl/gl_context_stub.h » ('j') | 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_osmesa.h" 5 #include "ui/gl/gl_context_osmesa.h"
6 6
7 #include <GL/osmesa.h> 7 #include <GL/osmesa.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/gfx/size.h" 10 #include "ui/gfx/size.h"
11 #include "ui/gl/gl_bindings.h" 11 #include "ui/gl/gl_bindings.h"
12 #include "ui/gl/gl_surface.h" 12 #include "ui/gl/gl_surface.h"
13 13
14 namespace gfx { 14 namespace gfx {
15 15
16 GLContextOSMesa::GLContextOSMesa(GLShareGroup* share_group) 16 GLContextOSMesa::GLContextOSMesa(GLShareGroup* share_group)
17 : GLContext(share_group), 17 : GLContextReal(share_group),
18 context_(NULL) { 18 context_(NULL) {
19 } 19 }
20 20
21 bool GLContextOSMesa::Initialize(GLSurface* compatible_surface, 21 bool GLContextOSMesa::Initialize(GLSurface* compatible_surface,
22 GpuPreference gpu_preference) { 22 GpuPreference gpu_preference) {
23 DCHECK(!context_); 23 DCHECK(!context_);
24 24
25 OSMesaContext share_handle = static_cast<OSMesaContext>( 25 OSMesaContext share_handle = static_cast<OSMesaContext>(
26 share_group() ? share_group()->GetHandle() : NULL); 26 share_group() ? share_group()->GetHandle() : NULL);
27 27
(...skipping 30 matching lines...) Expand all
58 size.width(), 58 size.width(),
59 size.height())) { 59 size.height())) {
60 LOG(ERROR) << "OSMesaMakeCurrent failed."; 60 LOG(ERROR) << "OSMesaMakeCurrent failed.";
61 Destroy(); 61 Destroy();
62 return false; 62 return false;
63 } 63 }
64 64
65 // Row 0 is at the top. 65 // Row 0 is at the top.
66 OSMesaPixelStore(OSMESA_Y_UP, 0); 66 OSMesaPixelStore(OSMESA_Y_UP, 0);
67 67
68 SetCurrent(this, surface); 68 SetCurrent(surface);
69 if (!InitializeExtensionBindings()) { 69 if (!InitializeExtensionBindings()) {
70 ReleaseCurrent(surface); 70 ReleaseCurrent(surface);
71 return false; 71 return false;
72 } 72 }
73 73
74 if (!surface->OnMakeCurrent(this)) { 74 if (!surface->OnMakeCurrent(this)) {
75 LOG(ERROR) << "Could not make current."; 75 LOG(ERROR) << "Could not make current.";
76 return false; 76 return false;
77 } 77 }
78 78
79 SetRealGLApi(); 79 SetRealGLApi();
80 return true; 80 return true;
81 } 81 }
82 82
83 void GLContextOSMesa::ReleaseCurrent(GLSurface* surface) { 83 void GLContextOSMesa::ReleaseCurrent(GLSurface* surface) {
84 if (!IsCurrent(surface)) 84 if (!IsCurrent(surface))
85 return; 85 return;
86 86
87 SetCurrent(NULL, NULL); 87 SetCurrent(NULL);
88 OSMesaMakeCurrent(NULL, NULL, GL_UNSIGNED_BYTE, 0, 0); 88 OSMesaMakeCurrent(NULL, NULL, GL_UNSIGNED_BYTE, 0, 0);
89 } 89 }
90 90
91 bool GLContextOSMesa::IsCurrent(GLSurface* surface) { 91 bool GLContextOSMesa::IsCurrent(GLSurface* surface) {
92 DCHECK(context_); 92 DCHECK(context_);
93 93
94 bool native_context_is_current = 94 bool native_context_is_current =
95 context_ == OSMesaGetCurrentContext(); 95 context_ == OSMesaGetCurrentContext();
96 96
97 // If our context is current then our notion of which GLContext is 97 // If our context is current then our notion of which GLContext is
98 // current must be correct. On the other hand, third-party code 98 // current must be correct. On the other hand, third-party code
99 // using OpenGL might change the current context. 99 // using OpenGL might change the current context.
100 DCHECK(!native_context_is_current || (GetCurrent() == this)); 100 DCHECK(!native_context_is_current || (GetRealCurrent() == this));
101 101
102 if (!native_context_is_current) 102 if (!native_context_is_current)
103 return false; 103 return false;
104 104
105 if (surface) { 105 if (surface) {
106 GLint width; 106 GLint width;
107 GLint height; 107 GLint height;
108 GLint format; 108 GLint format;
109 void* buffer = NULL; 109 void* buffer = NULL;
110 OSMesaGetColorBuffer(context_, &width, &height, &format, &buffer); 110 OSMesaGetColorBuffer(context_, &width, &height, &format, &buffer);
(...skipping 11 matching lines...) Expand all
122 void GLContextOSMesa::SetSwapInterval(int interval) { 122 void GLContextOSMesa::SetSwapInterval(int interval) {
123 DCHECK(IsCurrent(NULL)); 123 DCHECK(IsCurrent(NULL));
124 DLOG(INFO) << "GLContextOSMesa::SetSwapInterval is ignored."; 124 DLOG(INFO) << "GLContextOSMesa::SetSwapInterval is ignored.";
125 } 125 }
126 126
127 GLContextOSMesa::~GLContextOSMesa() { 127 GLContextOSMesa::~GLContextOSMesa() {
128 Destroy(); 128 Destroy();
129 } 129 }
130 130
131 } // namespace gfx 131 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_context_osmesa.h ('k') | ui/gl/gl_context_stub.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698